[PATCH 6/7] change return value of slot_insert() to tgtadm_err and recover from errors properly in add_slt()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Alexander Nezhinsky <alexandern@xxxxxxxxxxxx>


Signed-off-by: Alexander Nezhinsky <alexandern@xxxxxxxxxxxx>
---
 usr/smc.c |   25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/usr/smc.c b/usr/smc.c
index 0034d0e..bbfbfcd 100644
--- a/usr/smc.c
+++ b/usr/smc.c
@@ -543,7 +543,7 @@ static void smc_lu_exit(struct scsi_lu *lu)
 	free(smc);
 }
 
-static int slot_insert(struct list_head *head, int element_type, int address)
+static tgtadm_err slot_insert(struct list_head *head, int element_type, int address)
 {
 	struct slot *s;
 
@@ -559,7 +559,13 @@ static int slot_insert(struct list_head *head, int element_type, int address)
 
 	list_add_tail(&s->slot_siblings, head);
 
-	return 0;
+	return TGTADM_SUCCESS;
+}
+
+static void slot_remove(struct slot *s)
+{
+	list_del(&s->slot_siblings);
+	free(s);
 }
 
 /**
@@ -658,9 +664,18 @@ static tgtadm_err add_slt(struct scsi_lu *lu, struct tmp_param *tmp)
 			goto dont_do_slots;
 
 		adm_err = TGTADM_SUCCESS;
-		for(i = tmp->start_addr; i < (tmp->start_addr + tmp->quantity); i++)
-			if (slot_insert(&smc->slots, tmp->element_type, i))
-				adm_err = TGTADM_INVALID_REQUEST;
+		for (i = tmp->start_addr; i < (tmp->start_addr + tmp->quantity); i++) {
+			adm_err = slot_insert(&smc->slots, tmp->element_type, i);
+			if (adm_err != TGTADM_SUCCESS) {
+				int j;
+				/* remove all slots added before error */
+				for (j = tmp->start_addr; j < i; j++) {
+					s = slot_lookup(&smc->slots, tmp->element_type, j);
+					slot_remove(s);
+				}
+				break;
+			}
+		}
 	}
 
 dont_do_slots:
-- 
1.7.9.6

--
To unsubscribe from this list: send the line "unsubscribe stgt" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux SCSI]     [Linux RAID]     [Linux Clusters]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]

  Powered by Linux