target: add sense code INSUFFICIENT REGISTRATION RESOURCES
authortangwenji <tang.wenji@zte.com.cn>
Mon, 21 Aug 2017 12:55:41 +0000 (20:55 +0800)
committerNicholas Bellinger <nab@linux-iscsi.org>
Sat, 4 Nov 2017 21:45:23 +0000 (14:45 -0700)
If a PERSISTENT RESERVE OUT command with a REGISTER service action or a
REGISTER AND IGNORE EXISTING KEY service action or REGISTER AND MOVE
service action is attempted, but there are insufficient device server
resources to complete the operation, then the command shall be terminated
with CHECK CONDITION status, with the sense key set to ILLEGAL REQUEST,and
the additonal sense code set to INSUFFICIENT REGISTRATION RESOURCES.

Signed-off-by: tangwenji <tang.wenji@zte.com.cn>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
drivers/target/target_core_pr.c
drivers/target/target_core_transport.c
include/target/target_core_base.h

index dbf572e..871ae21 100644 (file)
@@ -1521,7 +1521,7 @@ core_scsi3_decode_spec_i_port(
        tidh_new = kzalloc(sizeof(struct pr_transport_id_holder), GFP_KERNEL);
        if (!tidh_new) {
                pr_err("Unable to allocate tidh_new\n");
-               return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
+               return TCM_INSUFFICIENT_REGISTRATION_RESOURCES;
        }
        INIT_LIST_HEAD(&tidh_new->dest_list);
        tidh_new->dest_tpg = tpg;
@@ -1533,7 +1533,7 @@ core_scsi3_decode_spec_i_port(
                                sa_res_key, all_tg_pt, aptpl);
        if (!local_pr_reg) {
                kfree(tidh_new);
-               return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
+               return TCM_INSUFFICIENT_REGISTRATION_RESOURCES;
        }
        tidh_new->dest_pr_reg = local_pr_reg;
        /*
@@ -1553,7 +1553,7 @@ core_scsi3_decode_spec_i_port(
 
        buf = transport_kmap_data_sg(cmd);
        if (!buf) {
-               ret = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
+               ret = TCM_INSUFFICIENT_REGISTRATION_RESOURCES;
                goto out;
        }
 
@@ -1767,7 +1767,7 @@ core_scsi3_decode_spec_i_port(
                        core_scsi3_nodeacl_undepend_item(dest_node_acl);
                        core_scsi3_tpg_undepend_item(dest_tpg);
                        kfree(tidh_new);
-                       ret = TCM_INVALID_PARAMETER_LIST;
+                       ret = TCM_INSUFFICIENT_REGISTRATION_RESOURCES;
                        goto out_unmap;
                }
                tidh_new->dest_pr_reg = dest_pr_reg;
@@ -2103,7 +2103,7 @@ core_scsi3_emulate_pro_register(struct se_cmd *cmd, u64 res_key, u64 sa_res_key,
                                        register_type, 0)) {
                                pr_err("Unable to allocate"
                                        " struct t10_pr_registration\n");
-                               return TCM_INVALID_PARAMETER_LIST;
+                               return TCM_INSUFFICIENT_REGISTRATION_RESOURCES;
                        }
                } else {
                        /*
@@ -3215,7 +3215,7 @@ core_scsi3_emulate_pro_register_and_move(struct se_cmd *cmd, u64 res_key,
         */
        buf = transport_kmap_data_sg(cmd);
        if (!buf) {
-               ret = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
+               ret = TCM_INSUFFICIENT_REGISTRATION_RESOURCES;
                goto out_put_pr_reg;
        }
 
@@ -3267,7 +3267,7 @@ core_scsi3_emulate_pro_register_and_move(struct se_cmd *cmd, u64 res_key,
 
        buf = transport_kmap_data_sg(cmd);
        if (!buf) {
-               ret = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
+               ret = TCM_INSUFFICIENT_REGISTRATION_RESOURCES;
                goto out_put_pr_reg;
        }
        proto_ident = (buf[24] & 0x0f);
@@ -3466,7 +3466,7 @@ after_iport_check:
                if (core_scsi3_alloc_registration(cmd->se_dev, dest_node_acl,
                                        dest_lun, dest_se_deve, dest_se_deve->mapped_lun,
                                        iport_ptr, sa_res_key, 0, aptpl, 2, 1)) {
-                       ret = TCM_INVALID_PARAMETER_LIST;
+                       ret = TCM_INSUFFICIENT_REGISTRATION_RESOURCES;
                        goto out;
                }
                spin_lock(&dev->dev_reservation_lock);
index 836d552..190f3ba 100644 (file)
@@ -3145,6 +3145,21 @@ static const struct sense_info sense_info_table[] = {
                .key = NOT_READY,
                .asc = 0x08, /* LOGICAL UNIT COMMUNICATION FAILURE */
        },
+       [TCM_INSUFFICIENT_REGISTRATION_RESOURCES] = {
+               /*
+                * From spc4r22 section5.7.7,5.7.8
+                * If a PERSISTENT RESERVE OUT command with a REGISTER service action
+                * or a REGISTER AND IGNORE EXISTING KEY service action or
+                * REGISTER AND MOVE service actionis attempted,
+                * but there are insufficient device server resources to complete the
+                * operation, then the command shall be terminated with CHECK CONDITION
+                * status, with the sense key set to ILLEGAL REQUEST,and the additonal
+                * sense code set to INSUFFICIENT REGISTRATION RESOURCES.
+                */
+               .key = ILLEGAL_REQUEST,
+               .asc = 0x55,
+               .ascq = 0x04, /* INSUFFICIENT REGISTRATION RESOURCES */
+       },
 };
 
 static int translate_sense_reason(struct se_cmd *cmd, sense_reason_t reason)
index 516764f..d3139a9 100644 (file)
@@ -181,6 +181,7 @@ enum tcm_sense_reason_table {
        TCM_UNSUPPORTED_TARGET_DESC_TYPE_CODE   = R(0x1a),
        TCM_TOO_MANY_SEGMENT_DESCS              = R(0x1b),
        TCM_UNSUPPORTED_SEGMENT_DESC_TYPE_CODE  = R(0x1c),
+       TCM_INSUFFICIENT_REGISTRATION_RESOURCES = R(0x1d),
 #undef R
 };