diff --git a/sys/cam/ctl/ctl.c b/sys/cam/ctl/ctl.c index bd61d8779aa4..2a4ae73e6d86 100644 --- a/sys/cam/ctl/ctl.c +++ b/sys/cam/ctl/ctl.c @@ -7867,6 +7867,15 @@ ctl_persistent_reserve_in(struct ctl_scsiio *ctsio) 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 * 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) continue; - if (!persis_offset - && i 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; + ctl_set_res_ua(lun, i, CTL_UA_REG_PREEMPT); } lun->pr_key_count = 1; 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; lun->pr_keys[i] = 0; lun->pr_key_count--; - - 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; + ctl_set_res_ua(lun, i, CTL_UA_REG_PREEMPT); } if (!found) { 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]) { lun->pr_keys[i] = 0; lun->pr_key_count--; - - 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; + ctl_set_res_ua(lun, i, CTL_UA_REG_PREEMPT); } else if (type != lun->res_type && (lun->res_type == SPR_TYPE_WR_EX_RO || lun->res_type ==SPR_TYPE_EX_AC_RO)){ - if (!persis_offset - && 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; + ctl_set_res_ua(lun, i, CTL_UA_RES_RELEASE); } } 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; lun->pr_keys[i] = 0; lun->pr_key_count--; - - 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; + ctl_set_res_ua(lun, i, CTL_UA_REG_PREEMPT); } if (!found) { @@ -8201,14 +8174,8 @@ ctl_pro_preempt_other(struct ctl_lun *lun, union ctl_ha_msg *msg) lun->pr_keys[i] == 0) 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; + ctl_set_res_ua(lun, i, CTL_UA_REG_PREEMPT); } 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_key_count--; - - 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; + ctl_set_res_ua(lun, i, CTL_UA_REG_PREEMPT); } } } 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]) { lun->pr_keys[i] = 0; lun->pr_key_count--; - 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; + ctl_set_res_ua(lun, i, CTL_UA_REG_PREEMPT); } else if (msg->pr.pr_info.res_type != lun->res_type && (lun->res_type == SPR_TYPE_WR_EX_RO || lun->res_type == SPR_TYPE_EX_AC_RO)) { - if (!persis_offset - && 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; + ctl_set_res_ua(lun, i, CTL_UA_RES_RELEASE); } } 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++) 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; + ctl_set_res_ua(lun, i, CTL_UA_REG_PREEMPT); } lun->PRGeneration++; 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++) { if (lun->pr_keys[i] == 0) 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; + ctl_set_res_ua(lun, i, CTL_UA_REG_PREEMPT); } lun->PRGeneration++; break;