[stgt] [PATCH] release backing store when offline

James R. Leu jleu at inoc.com
Wed Jul 13 18:12:26 CEST 2011


Hello,

We have the need to be able to release the backing
store device when a target or LUN is marked as offline.
I have included my simplistic patch to accomplish this.
If I am overlooking something, please let me know and
I will do my best to incorporate it into the patch.

Thank you
-- 
James R. Leu
Software Architect
INOC
608.204.0203
608.663.4555 fax
jleu at inoc.com
www.inoc.com

*** DELIVERING UPTIME ***
-------------- next part --------------
diff -uNr tgt-1.0.18/usr/spc.c tgt-1.0.18-inoc/usr/spc.c
--- tgt-1.0.18/usr/spc.c	2011-06-29 17:54:02.000000000 -0500
+++ tgt-1.0.18-inoc/usr/spc.c	2011-07-13 10:09:23.341135538 -0500
@@ -1687,10 +1687,20 @@
 			break;
 		case Opt_online:
 			match_strncpy(buf, &args[0], sizeof(buf));
-			if (atoi(buf))
-				lu->dev_type_template.lu_online(lu);
-			else
+			switch (atoi(buf)) {
+			    case 1:
+				err = lu->bst->bs_open(lu, lu->path, &lu->fd, &lu->size);
+				if (!err) {
+				    lu->dev_type_template.lu_online(lu);
+				}
+				break;
+			    case 0:
+				lu->bst->bs_close(lu);
 				lu->dev_type_template.lu_offline(lu);
+				break;
+			    default:
+				break;
+			}
 			break;
 		case Opt_mode_page:
 			match_strncpy(buf, &args[0], sizeof(buf));
diff -uNr tgt-1.0.18/usr/target.c tgt-1.0.18-inoc/usr/target.c
--- tgt-1.0.18/usr/target.c	2011-06-29 17:54:02.000000000 -0500
+++ tgt-1.0.18-inoc/usr/target.c	2011-07-13 09:39:50.955594499 -0500
@@ -1740,12 +1740,15 @@
 int tgt_set_target_state(int tid, char *str)
 {
 	int i, err = TGTADM_INVALID_REQUEST;
+	struct scsi_lu *lu;
 	struct target *target;
+	int prev = 0;
 
 	target = target_lookup(tid);
 	if (!target)
 		return TGTADM_NO_TARGET;
 
+	prev = target->target_state;
 	for (i = 0; i < ARRAY_SIZE(target_state); i++) {
 		if (!strcmp(target_state[i].name, str)) {
 			target->target_state = target_state[i].value;
@@ -1754,6 +1757,22 @@
 		}
 	}
 
+	if (err == 0 && prev != target->target_state) {
+	    list_for_each_entry(lu, &target->device_list, device_siblings) {
+		if (target->target_state == SCSI_TARGET_OFFLINE) {
+		    lu->bst->bs_close(lu);
+		    lu->dev_type_template.lu_offline(lu);
+		} else {
+		    err = lu->bst->bs_open(lu, lu->path, &lu->fd, &lu->size);
+		    if (err) {
+			target->target_state = prev;
+		    } else {
+			lu->dev_type_template.lu_online(lu);
+		    }
+		}
+	    }
+	}
+
 	return err;
 }
 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.wpkg.org/pipermail/stgt/attachments/20110713/89a1a5ac/attachment.sig>


More information about the stgt mailing list