Skip to content

Commit bc118fe

Browse files
Andy GroverNicholas Bellinger
Andy Grover
authored and
Nicholas Bellinger
committed
target: Further refactoring of core_scsi3_emulate_pro_register()
Use bool params when appropriate. Eliminate unneeded pr_reg_e and type variables. Just one goto label, so rename to 'out' from 'out_put_pr_reg'. Signed-off-by: Andy Grover <[email protected]> Signed-off-by: Nicholas Bellinger <[email protected]>
1 parent 51d9c41 commit bc118fe

File tree

1 file changed

+20
-26
lines changed

1 file changed

+20
-26
lines changed

drivers/target/target_core_pr.c

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1995,18 +1995,18 @@ static int core_scsi3_update_and_write_aptpl(struct se_device *dev, bool aptpl)
19951995

19961996
static sense_reason_t
19971997
core_scsi3_emulate_pro_register(struct se_cmd *cmd, u64 res_key, u64 sa_res_key,
1998-
int aptpl, int all_tg_pt, int spec_i_pt, enum register_type register_type)
1998+
bool aptpl, bool all_tg_pt, bool spec_i_pt, enum register_type register_type)
19991999
{
20002000
struct se_session *se_sess = cmd->se_sess;
20012001
struct se_device *dev = cmd->se_dev;
20022002
struct se_dev_entry *se_deve;
20032003
struct se_lun *se_lun = cmd->se_lun;
20042004
struct se_portal_group *se_tpg;
2005-
struct t10_pr_registration *pr_reg, *pr_reg_p, *pr_reg_tmp, *pr_reg_e;
2005+
struct t10_pr_registration *pr_reg, *pr_reg_p, *pr_reg_tmp;
20062006
struct t10_reservation *pr_tmpl = &dev->t10_pr;
20072007
unsigned char isid_buf[PR_REG_ISID_LEN], *isid_ptr = NULL;
20082008
sense_reason_t ret = TCM_NO_SENSE;
2009-
int pr_holder = 0, type;
2009+
int pr_holder = 0;
20102010

20112011
if (!se_sess || !se_lun) {
20122012
pr_err("SPC-3 PR: se_sess || struct se_lun is NULL!\n");
@@ -2024,8 +2024,8 @@ core_scsi3_emulate_pro_register(struct se_cmd *cmd, u64 res_key, u64 sa_res_key,
20242024
/*
20252025
* Follow logic from spc4r17 Section 5.7.7, Register Behaviors Table 47
20262026
*/
2027-
pr_reg_e = core_scsi3_locate_pr_reg(dev, se_sess->se_node_acl, se_sess);
2028-
if (!pr_reg_e) {
2027+
pr_reg = core_scsi3_locate_pr_reg(dev, se_sess->se_node_acl, se_sess);
2028+
if (!pr_reg) {
20292029
if (res_key) {
20302030
pr_warn("SPC-3 PR: Reservation Key non-zero"
20312031
" for SA REGISTER, returning CONFLICT\n");
@@ -2069,29 +2069,23 @@ core_scsi3_emulate_pro_register(struct se_cmd *cmd, u64 res_key, u64 sa_res_key,
20692069
return core_scsi3_update_and_write_aptpl(dev, aptpl);
20702070
}
20712071

2072-
/*
2073-
* Locate the existing *pr_reg via struct se_node_acl pointers
2074-
*/
2075-
pr_reg = pr_reg_e;
2076-
type = pr_reg->pr_res_type;
2072+
/* ok, existing registration */
20772073

2078-
if (register_type == REGISTER) {
2079-
if (res_key != pr_reg->pr_res_key) {
2080-
pr_err("SPC-3 PR REGISTER: Received"
2081-
" res_key: 0x%016Lx does not match"
2082-
" existing SA REGISTER res_key:"
2083-
" 0x%016Lx\n", res_key,
2084-
pr_reg->pr_res_key);
2085-
ret = TCM_RESERVATION_CONFLICT;
2086-
goto out_put_pr_reg;
2087-
}
2074+
if ((register_type == REGISTER) && (res_key != pr_reg->pr_res_key)) {
2075+
pr_err("SPC-3 PR REGISTER: Received"
2076+
" res_key: 0x%016Lx does not match"
2077+
" existing SA REGISTER res_key:"
2078+
" 0x%016Lx\n", res_key,
2079+
pr_reg->pr_res_key);
2080+
ret = TCM_RESERVATION_CONFLICT;
2081+
goto out;
20882082
}
20892083

20902084
if (spec_i_pt) {
20912085
pr_err("SPC-3 PR REGISTER: SPEC_I_PT"
20922086
" set on a registered nexus\n");
20932087
ret = TCM_INVALID_PARAMETER_LIST;
2094-
goto out_put_pr_reg;
2088+
goto out;
20952089
}
20962090

20972091
/*
@@ -2103,7 +2097,7 @@ core_scsi3_emulate_pro_register(struct se_cmd *cmd, u64 res_key, u64 sa_res_key,
21032097
" registration exists, but ALL_TG_PT=1 bit not"
21042098
" present in received PROUT\n");
21052099
ret = TCM_INVALID_CDB_FIELD;
2106-
goto out_put_pr_reg;
2100+
goto out;
21072101
}
21082102

21092103
/*
@@ -2132,7 +2126,7 @@ core_scsi3_emulate_pro_register(struct se_cmd *cmd, u64 res_key, u64 sa_res_key,
21322126
cmd->se_dev, pr_reg);
21332127
if (pr_holder < 0) {
21342128
ret = TCM_RESERVATION_CONFLICT;
2135-
goto out_put_pr_reg;
2129+
goto out;
21362130
}
21372131

21382132
spin_lock(&pr_tmpl->registration_lock);
@@ -2177,8 +2171,8 @@ core_scsi3_emulate_pro_register(struct se_cmd *cmd, u64 res_key, u64 sa_res_key,
21772171
* RESERVATIONS RELEASED.
21782172
*/
21792173
if (pr_holder &&
2180-
(type == PR_TYPE_WRITE_EXCLUSIVE_REGONLY ||
2181-
type == PR_TYPE_EXCLUSIVE_ACCESS_REGONLY)) {
2174+
(pr_reg->pr_res_type == PR_TYPE_WRITE_EXCLUSIVE_REGONLY ||
2175+
pr_reg->pr_res_type == PR_TYPE_EXCLUSIVE_ACCESS_REGONLY)) {
21822176
list_for_each_entry(pr_reg_p,
21832177
&pr_tmpl->registration_list,
21842178
pr_reg_list) {
@@ -2196,7 +2190,7 @@ core_scsi3_emulate_pro_register(struct se_cmd *cmd, u64 res_key, u64 sa_res_key,
21962190

21972191
ret = core_scsi3_update_and_write_aptpl(dev, aptpl);
21982192

2199-
out_put_pr_reg:
2193+
out:
22002194
core_scsi3_put_pr_reg(pr_reg);
22012195
return ret;
22022196
}

0 commit comments

Comments
 (0)