svn commit: r275404 - head/sys/cam/ctl

Alexander Motin mav at FreeBSD.org
Tue Dec 2 12:31:29 UTC 2014


Author: mav
Date: Tue Dec  2 12:31:28 2014
New Revision: 275404
URL: https://svnweb.freebsd.org/changeset/base/275404

Log:
  Reduce code duplication by creating ctl_set_res_ua() helper.

Modified:
  head/sys/cam/ctl/ctl.c

Modified: head/sys/cam/ctl/ctl.c
==============================================================================
--- head/sys/cam/ctl/ctl.c	Tue Dec  2 12:05:44 2014	(r275403)
+++ head/sys/cam/ctl/ctl.c	Tue Dec  2 12:31:28 2014	(r275404)
@@ -7867,6 +7867,15 @@ retry:
 	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,
 				if (i == residx || 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;
 			lun->res_type = type;
@@ -7999,12 +8001,7 @@ ctl_pro_preempt(struct ctl_softc *softc,
 			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,
 				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,
 				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 *lu
 				    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 *lu
 
 				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 *lu
 			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_sc
 
 		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 c
 		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;


More information about the svn-src-head mailing list