Reduce code duplication by creating ctl_set_res_ua() helper.

This commit is contained in:
Alexander Motin 2014-12-02 12:31:28 +00:00
parent 1e8607769f
commit 40103f1ec4

View File

@ -7867,6 +7867,15 @@ ctl_persistent_reserve_in(struct ctl_scsiio *ctsio)
return (CTL_RETVAL_COMPLETE); return (CTL_RETVAL_COMPLETE);
} }
static void
ctl_set_res_ua(struct ctl_lun *lun, uint32_t residx, ctl_ua_type ua)
{
if (residx >= persis_offset &&
residx < persis_offset + CTL_MAX_INITIATORS)
lun->pending_ua[residx - persis_offset] |= ua;
}
/* /*
* Returns 0 if ctl_persistent_reserve_out() should continue, non-zero if * Returns 0 if ctl_persistent_reserve_out() should continue, non-zero if
* it should return. * it should return.
@ -7920,15 +7929,8 @@ ctl_pro_preempt(struct ctl_softc *softc, struct ctl_lun *lun, uint64_t res_key,
if (i == residx || lun->pr_keys[i] == 0) if (i == residx || lun->pr_keys[i] == 0)
continue; continue;
if (!persis_offset
&& i <CTL_MAX_INITIATORS)
lun->pending_ua[i] |=
CTL_UA_REG_PREEMPT;
else if (persis_offset
&& i >= persis_offset)
lun->pending_ua[i-persis_offset] |=
CTL_UA_REG_PREEMPT;
lun->pr_keys[i] = 0; lun->pr_keys[i] = 0;
ctl_set_res_ua(lun, i, CTL_UA_REG_PREEMPT);
} }
lun->pr_key_count = 1; lun->pr_key_count = 1;
lun->res_type = type; lun->res_type = type;
@ -7999,12 +8001,7 @@ ctl_pro_preempt(struct ctl_softc *softc, struct ctl_lun *lun, uint64_t res_key,
found = 1; found = 1;
lun->pr_keys[i] = 0; lun->pr_keys[i] = 0;
lun->pr_key_count--; lun->pr_key_count--;
ctl_set_res_ua(lun, i, CTL_UA_REG_PREEMPT);
if (!persis_offset && i < CTL_MAX_INITIATORS)
lun->pending_ua[i] |= CTL_UA_REG_PREEMPT;
else if (persis_offset && i >= persis_offset)
lun->pending_ua[i-persis_offset] |=
CTL_UA_REG_PREEMPT;
} }
if (!found) { if (!found) {
mtx_unlock(&lun->lun_lock); mtx_unlock(&lun->lun_lock);
@ -8079,27 +8076,11 @@ ctl_pro_preempt(struct ctl_softc *softc, struct ctl_lun *lun, uint64_t res_key,
if (sa_res_key == lun->pr_keys[i]) { if (sa_res_key == lun->pr_keys[i]) {
lun->pr_keys[i] = 0; lun->pr_keys[i] = 0;
lun->pr_key_count--; lun->pr_key_count--;
ctl_set_res_ua(lun, i, CTL_UA_REG_PREEMPT);
if (!persis_offset
&& i < CTL_MAX_INITIATORS)
lun->pending_ua[i] |=
CTL_UA_REG_PREEMPT;
else if (persis_offset
&& i >= persis_offset)
lun->pending_ua[i-persis_offset] |=
CTL_UA_REG_PREEMPT;
} else if (type != lun->res_type } else if (type != lun->res_type
&& (lun->res_type == SPR_TYPE_WR_EX_RO && (lun->res_type == SPR_TYPE_WR_EX_RO
|| lun->res_type ==SPR_TYPE_EX_AC_RO)){ || lun->res_type ==SPR_TYPE_EX_AC_RO)){
if (!persis_offset ctl_set_res_ua(lun, i, CTL_UA_RES_RELEASE);
&& i < CTL_MAX_INITIATORS)
lun->pending_ua[i] |=
CTL_UA_RES_RELEASE;
else if (persis_offset
&& i >= persis_offset)
lun->pending_ua[
i-persis_offset] |=
CTL_UA_RES_RELEASE;
} }
} }
lun->res_type = type; lun->res_type = type;
@ -8138,15 +8119,7 @@ ctl_pro_preempt(struct ctl_softc *softc, struct ctl_lun *lun, uint64_t res_key,
found = 1; found = 1;
lun->pr_keys[i] = 0; lun->pr_keys[i] = 0;
lun->pr_key_count--; lun->pr_key_count--;
ctl_set_res_ua(lun, i, CTL_UA_REG_PREEMPT);
if (!persis_offset
&& i < CTL_MAX_INITIATORS)
lun->pending_ua[i] |=
CTL_UA_REG_PREEMPT;
else if (persis_offset
&& i >= persis_offset)
lun->pending_ua[i-persis_offset] |=
CTL_UA_REG_PREEMPT;
} }
if (!found) { if (!found) {
@ -8201,14 +8174,8 @@ ctl_pro_preempt_other(struct ctl_lun *lun, union ctl_ha_msg *msg)
lun->pr_keys[i] == 0) lun->pr_keys[i] == 0)
continue; continue;
if (!persis_offset
&& i < CTL_MAX_INITIATORS)
lun->pending_ua[i] |=
CTL_UA_REG_PREEMPT;
else if (persis_offset && i >= persis_offset)
lun->pending_ua[i - persis_offset] |=
CTL_UA_REG_PREEMPT;
lun->pr_keys[i] = 0; lun->pr_keys[i] = 0;
ctl_set_res_ua(lun, i, CTL_UA_REG_PREEMPT);
} }
lun->pr_key_count = 1; lun->pr_key_count = 1;
@ -8223,15 +8190,7 @@ ctl_pro_preempt_other(struct ctl_lun *lun, union ctl_ha_msg *msg)
lun->pr_keys[i] = 0; lun->pr_keys[i] = 0;
lun->pr_key_count--; lun->pr_key_count--;
ctl_set_res_ua(lun, i, CTL_UA_REG_PREEMPT);
if (!persis_offset
&& i < persis_offset)
lun->pending_ua[i] |=
CTL_UA_REG_PREEMPT;
else if (persis_offset
&& i >= persis_offset)
lun->pending_ua[i - persis_offset] |=
CTL_UA_REG_PREEMPT;
} }
} }
} else { } else {
@ -8243,25 +8202,11 @@ ctl_pro_preempt_other(struct ctl_lun *lun, union ctl_ha_msg *msg)
if (sa_res_key == lun->pr_keys[i]) { if (sa_res_key == lun->pr_keys[i]) {
lun->pr_keys[i] = 0; lun->pr_keys[i] = 0;
lun->pr_key_count--; lun->pr_key_count--;
if (!persis_offset ctl_set_res_ua(lun, i, CTL_UA_REG_PREEMPT);
&& i < CTL_MAX_INITIATORS)
lun->pending_ua[i] |=
CTL_UA_REG_PREEMPT;
else if (persis_offset
&& i >= persis_offset)
lun->pending_ua[i - persis_offset] |=
CTL_UA_REG_PREEMPT;
} else if (msg->pr.pr_info.res_type != lun->res_type } else if (msg->pr.pr_info.res_type != lun->res_type
&& (lun->res_type == SPR_TYPE_WR_EX_RO && (lun->res_type == SPR_TYPE_WR_EX_RO
|| lun->res_type == SPR_TYPE_EX_AC_RO)) { || lun->res_type == SPR_TYPE_EX_AC_RO)) {
if (!persis_offset ctl_set_res_ua(lun, i, CTL_UA_RES_RELEASE);
&& i < persis_offset)
lun->pending_ua[i] |=
CTL_UA_RES_RELEASE;
else if (persis_offset
&& i >= persis_offset)
lun->pending_ua[i - persis_offset] |=
CTL_UA_RES_RELEASE;
} }
} }
lun->res_type = msg->pr.pr_info.res_type; lun->res_type = msg->pr.pr_info.res_type;
@ -8645,14 +8590,8 @@ ctl_persistent_reserve_out(struct ctl_scsiio *ctsio)
for (i=0; i < 2*CTL_MAX_INITIATORS; i++) for (i=0; i < 2*CTL_MAX_INITIATORS; i++)
if (lun->pr_keys[i] != 0) { if (lun->pr_keys[i] != 0) {
if (!persis_offset && i < CTL_MAX_INITIATORS)
lun->pending_ua[i] |=
CTL_UA_RES_PREEMPT;
else if (persis_offset && i >= persis_offset)
lun->pending_ua[i-persis_offset] |=
CTL_UA_RES_PREEMPT;
lun->pr_keys[i] = 0; lun->pr_keys[i] = 0;
ctl_set_res_ua(lun, i, CTL_UA_REG_PREEMPT);
} }
lun->PRGeneration++; lun->PRGeneration++;
mtx_unlock(&lun->lun_lock); mtx_unlock(&lun->lun_lock);
@ -8794,14 +8733,8 @@ ctl_hndl_per_res_out_on_other_sc(union ctl_ha_msg *msg)
for (i=0; i < 2*CTL_MAX_INITIATORS; i++) { for (i=0; i < 2*CTL_MAX_INITIATORS; i++) {
if (lun->pr_keys[i] == 0) if (lun->pr_keys[i] == 0)
continue; continue;
if (!persis_offset
&& i < CTL_MAX_INITIATORS)
lun->pending_ua[i] |= CTL_UA_RES_PREEMPT;
else if (persis_offset
&& i >= persis_offset)
lun->pending_ua[i-persis_offset] |=
CTL_UA_RES_PREEMPT;
lun->pr_keys[i] = 0; lun->pr_keys[i] = 0;
ctl_set_res_ua(lun, i, CTL_UA_REG_PREEMPT);
} }
lun->PRGeneration++; lun->PRGeneration++;
break; break;