Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 2 Aug 2014 19:51:10 +0000 (UTC)
From:      Alexander Motin <mav@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r269441 - head/sys/cam/ctl
Message-ID:  <201408021951.s72JpAMo045742@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mav
Date: Sat Aug  2 19:51:10 2014
New Revision: 269441
URL: http://svnweb.freebsd.org/changeset/base/269441

Log:
  Add missing comparisons to make list IDs in EXTENDED COPY per-initiator,
  as they should be.  Wrap it into a function to not duplicate the code.
  
  MFC after:	3 days

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

Modified: head/sys/cam/ctl/ctl_tpc.c
==============================================================================
--- head/sys/cam/ctl/ctl_tpc.c	Sat Aug  2 18:37:22 2014	(r269440)
+++ head/sys/cam/ctl/ctl_tpc.c	Sat Aug  2 19:51:10 2014	(r269441)
@@ -327,6 +327,21 @@ ctl_receive_copy_operating_parameters(st
 	return (retval);
 }
 
+static struct tpc_list *
+tpc_find_list(struct ctl_lun *lun, uint32_t list_id, uint32_t init_idx)
+{
+	struct tpc_list *list;
+
+	mtx_assert(&lun->lun_lock, MA_OWNED);
+	TAILQ_FOREACH(list, &lun->tpc_lists, links) {
+		if ((list->flags & EC_LIST_ID_USAGE_MASK) !=
+		     EC_LIST_ID_USAGE_NONE && list->list_id == list_id &&
+		    list->init_idx == init_idx)
+			break;
+	}
+	return (list);
+}
+
 int
 ctl_receive_copy_status_lid1(struct ctl_scsiio *ctsio)
 {
@@ -348,11 +363,8 @@ ctl_receive_copy_status_lid1(struct ctl_
 
 	list_id = cdb->list_identifier;
 	mtx_lock(&lun->lun_lock);
-	TAILQ_FOREACH(list, &lun->tpc_lists, links) {
-		if ((list->flags & EC_LIST_ID_USAGE_MASK) !=
-		     EC_LIST_ID_USAGE_NONE && list->list_id == list_id)
-			break;
-	}
+	list = tpc_find_list(lun, list_id,
+	    ctl_get_resindex(&ctsio->io_hdr.nexus));
 	if (list == NULL) {
 		mtx_unlock(&lun->lun_lock);
 		ctl_set_invalid_field(ctsio, /*sks_valid*/ 1,
@@ -433,12 +445,9 @@ ctl_receive_copy_failure_details(struct 
 
 	list_id = cdb->list_identifier;
 	mtx_lock(&lun->lun_lock);
-	TAILQ_FOREACH(list, &lun->tpc_lists, links) {
-		if (list->completed && (list->flags & EC_LIST_ID_USAGE_MASK) !=
-		     EC_LIST_ID_USAGE_NONE && list->list_id == list_id)
-			break;
-	}
-	if (list == NULL) {
+	list = tpc_find_list(lun, list_id,
+	    ctl_get_resindex(&ctsio->io_hdr.nexus));
+	if (list == NULL || !list->completed) {
 		mtx_unlock(&lun->lun_lock);
 		ctl_set_invalid_field(ctsio, /*sks_valid*/ 1,
 		    /*command*/ 1, /*field*/ 2, /*bit_valid*/ 0,
@@ -507,11 +516,8 @@ ctl_receive_copy_status_lid4(struct ctl_
 
 	list_id = scsi_4btoul(cdb->list_identifier);
 	mtx_lock(&lun->lun_lock);
-	TAILQ_FOREACH(list, &lun->tpc_lists, links) {
-		if ((list->flags & EC_LIST_ID_USAGE_MASK) !=
-		     EC_LIST_ID_USAGE_NONE && list->list_id == list_id)
-			break;
-	}
+	list = tpc_find_list(lun, list_id,
+	    ctl_get_resindex(&ctsio->io_hdr.nexus));
 	if (list == NULL) {
 		mtx_unlock(&lun->lun_lock);
 		ctl_set_invalid_field(ctsio, /*sks_valid*/ 1,
@@ -596,11 +602,8 @@ ctl_copy_operation_abort(struct ctl_scsi
 
 	list_id = scsi_4btoul(cdb->list_identifier);
 	mtx_lock(&lun->lun_lock);
-	TAILQ_FOREACH(list, &lun->tpc_lists, links) {
-		if ((list->flags & EC_LIST_ID_USAGE_MASK) !=
-		     EC_LIST_ID_USAGE_NONE && list->list_id == list_id)
-			break;
-	}
+	list = tpc_find_list(lun, list_id,
+	    ctl_get_resindex(&ctsio->io_hdr.nexus));
 	if (list == NULL) {
 		mtx_unlock(&lun->lun_lock);
 		ctl_set_invalid_field(ctsio, /*sks_valid*/ 1,
@@ -1210,12 +1213,7 @@ ctl_extended_copy_lid1(struct ctl_scsiio
 	list->lun = lun;
 	mtx_lock(&lun->lun_lock);
 	if ((list->flags & EC_LIST_ID_USAGE_MASK) != EC_LIST_ID_USAGE_NONE) {
-		TAILQ_FOREACH(tlist, &lun->tpc_lists, links) {
-			if ((tlist->flags & EC_LIST_ID_USAGE_MASK) !=
-			     EC_LIST_ID_USAGE_NONE &&
-			    tlist->list_id == list->list_id)
-				break;
-		}
+		tlist = tpc_find_list(lun, list->list_id, list->init_idx);
 		if (tlist != NULL && !tlist->completed) {
 			mtx_unlock(&lun->lun_lock);
 			free(list, M_CTL);
@@ -1338,12 +1336,7 @@ ctl_extended_copy_lid4(struct ctl_scsiio
 	list->lun = lun;
 	mtx_lock(&lun->lun_lock);
 	if ((list->flags & EC_LIST_ID_USAGE_MASK) != EC_LIST_ID_USAGE_NONE) {
-		TAILQ_FOREACH(tlist, &lun->tpc_lists, links) {
-			if ((tlist->flags & EC_LIST_ID_USAGE_MASK) !=
-			     EC_LIST_ID_USAGE_NONE &&
-			    tlist->list_id == list->list_id)
-				break;
-		}
+		tlist = tpc_find_list(lun, list->list_id, list->init_idx);
 		if (tlist != NULL && !tlist->completed) {
 			mtx_unlock(&lun->lun_lock);
 			free(list, M_CTL);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201408021951.s72JpAMo045742>