[Stgt-devel] [PATCH 1/2] bstype before lu alloc

Pete Wyckoff pw
Sun Jan 27 21:46:16 CET 2008


Set the specified bstype before allocating space for the lu, because
the allocation must include space required by the particular bstype.

Signed-off-by: Pete Wyckoff <pw at osc.edu>
---
 usr/target.c |   26 ++++++++++++--------------
 1 files changed, 12 insertions(+), 14 deletions(-)

diff --git a/usr/target.c b/usr/target.c
index 8c870ff..b8e25a4 100644
--- a/usr/target.c
+++ b/usr/target.c
@@ -242,6 +242,7 @@ int tgt_device_create(int tid, int dev_type, uint64_t lun, char *params,
 	struct target *target;
 	struct scsi_lu *lu, *pos;
 	struct device_type_template *t;
+	struct backingstore_template *bst;
 
 	dprintf("%d %" PRIu64 "\n", tid, lun);
 
@@ -273,14 +274,23 @@ int tgt_device_create(int tid, int dev_type, uint64_t lun, char *params,
 		return TGTADM_LUN_EXIST;
 	}
 
-	lu = zalloc(sizeof(*lu) + target->bst->bs_datasize);
+	bst = target->bst;
+	if (backing && bstype) {
+		bst = get_backingstore_template(bstype);
+		if (!bst) {
+			eprintf("failed to find bstype, %s\n", bstype);
+			goto out;
+		}
+	}
+
+	lu = zalloc(sizeof(*lu) + bst->bs_datasize);
 	if (!lu)
 		return TGTADM_NOMEM;
 
 	t = device_type_lookup(dev_type);
 	if (t) {
 		lu->dev_type_template = *t;
-		lu->bst = target->bst;
+		lu->bst = bst;
 	} else {
 		eprintf("Unknown device type %d\n", dev_type);
 		ret = TGTADM_INVALID_REQUEST;
@@ -300,21 +310,9 @@ int tgt_device_create(int tid, int dev_type, uint64_t lun, char *params,
 	}
 
 	if (backing) {
-		struct backingstore_template *bst;
-
 		if (!path)
 			return TGTADM_INVALID_REQUEST;
 
-		if (bstype) {
-			bst = get_backingstore_template(bstype);
-			if (bst)
-				lu->bst = bst;
-			else {
-				eprintf("failed to find bstype, %s\n", bstype);
-				goto free_lu;
-			}
-		}
-
 		ret = tgt_device_path_update(target, lu, path);
 		if (ret)
 			goto free_lu;
-- 
1.5.3.7




More information about the stgt mailing list