[Stgt-devel] [Patch] Merge lu_phy_attr struct into scsi_lu struct

Mark Harvey markh794
Thu Jun 14 10:25:15 CEST 2007


Re-work previous [Patch 2/2]


>From ddd8aa4cdb2696f07c793b96d7e86ce002c7a4db Mon Sep 17 00:00:00 2001
From: Mark Harvey <markh794 at gmail.com>
Date: Thu, 14 Jun 2007 17:00:44 +1000
Subject: Merge lu_phy_attr struct into scsi_lu struct

No advantage of having the lu_phy_attr structure. Moved all
fields into the scsi_lu structure.

Signed-off-by: Mark Harvey <markh794 at gmail.com>
---
 usr/mmc.c    |   10 ++++----
 usr/osd.c    |   10 ++++----
 usr/sbc.c    |    8 +++---
 usr/scsi.c   |    2 +-
 usr/spc.c    |   60 +++++++++++++++++++++++++++------------------------------
 usr/target.c |    8 +++---
 usr/tgtd.h   |   17 ++++++---------
 7 files changed, 54 insertions(+), 61 deletions(-)

diff --git a/usr/mmc.c b/usr/mmc.c
index a8aced5..79db47c 100644
--- a/usr/mmc.c
+++ b/usr/mmc.c
@@ -126,11 +126,11 @@ static int mmc_lu_init(struct scsi_lu *lu)
 	if (spc_lu_init(lu))
 		return -ENOMEM;
 
-	memcpy(lu->attrs->product_id, "VIRTUAL-CDROM", 16);
-	lu->attrs->sense_format = 0;
-	lu->attrs->version_desc[0] = 0x02A0; /* MMC3, no version claimed */
-	lu->attrs->version_desc[1] = 0x0960; /* iSCSI */
-	lu->attrs->version_desc[2] = 0x0300; /* SPC-3 */
+	strncpy(lu->product_id, "VIRTUAL-CDROM", sizeof(lu->product_id) - 1);
+	lu->sense_format = 0;
+	lu->version_desc[0] = 0x02A0; /* MMC3, no version claimed */
+	lu->version_desc[1] = 0x0960; /* iSCSI */
+	lu->version_desc[2] = 0x0300; /* SPC-3 */
 
 	return 0;
 }
diff --git a/usr/osd.c b/usr/osd.c
index ac33168..8af72f3 100644
--- a/usr/osd.c
+++ b/usr/osd.c
@@ -56,11 +56,11 @@ static int osd_lu_init(struct scsi_lu *lu)
 	if (spc_lu_init(lu))
 		return -ENOMEM;
 
-	memcpy(lu->attrs->product_id, "OSD", 16);
-	lu->attrs->sense_format = 1;
-	lu->attrs->version_desc[0] = 0x0340; /* OSD */
-	lu->attrs->version_desc[1] = 0x0960; /* iSCSI */
-	lu->attrs->version_desc[2] = 0x0300; /* SPC-3 */
+	strncpy(lu->product_id, "OSD", sizeof(lu->product_id) - 1);
+	lu->sense_format = 1;
+	lu->version_desc[0] = 0x0340; /* OSD */
+	lu->version_desc[1] = 0x0960; /* iSCSI */
+	lu->version_desc[2] = 0x0300; /* SPC-3 */
 
 	return 0;
 }
diff --git a/usr/sbc.c b/usr/sbc.c
index 2924cc6..c172e8f 100644
--- a/usr/sbc.c
+++ b/usr/sbc.c
@@ -342,10 +342,10 @@ static int sbc_lu_init(struct scsi_lu *lu)
 	if (spc_lu_init(lu))
 		return -ENOMEM;
 
-	memcpy(lu->attrs->product_id, "VIRTUAL-DISK", 16);
-	lu->attrs->version_desc[0] = 0x04C0; /* SBC-3 no version claimed */
-	lu->attrs->version_desc[1] = 0x0960; /* iSCSI */
-	lu->attrs->version_desc[2] = 0x0300; /* SPC-3 */
+	strncpy(lu->product_id, "VIRTUAL-DISK", sizeof(lu->product_id) - 1);
+	lu->version_desc[0] = 0x04C0; /* SBC-3 no version claimed */
+	lu->version_desc[1] = 0x0960; /* iSCSI */
+	lu->version_desc[2] = 0x0300; /* SPC-3 */
 
 	return 0;
 }
diff --git a/usr/scsi.c b/usr/scsi.c
index 50e2080..ebd7067 100644
--- a/usr/scsi.c
+++ b/usr/scsi.c
@@ -40,7 +40,7 @@
 
 void sense_data_build(struct scsi_cmd *cmd, uint8_t key, uint8_t asc, uint8_t asq)
 {
-	if (cmd->dev && cmd->dev->attrs->sense_format) {
+	if (cmd->dev && cmd->dev->sense_format) {
 		/* descriptor format */
 
 		cmd->sense_buffer[0] = 0x72;  /* current, not deferred */
diff --git a/usr/spc.c b/usr/spc.c
index b9f4e16..2aefd4d 100644
--- a/usr/spc.c
+++ b/usr/spc.c
@@ -64,19 +64,19 @@ int spc_inquiry(int host_no, struct scsi_cmd *cmd)
 		uint16_t *desc;
 
 		data[0] = device_type;
-		data[1] = (cmd->dev->attrs->removable) ? 0x80 : 0;
+		data[1] = (cmd->dev->removable) ? 0x80 : 0;
 		data[2] = 5;	/* SPC-3 */
 		data[3] = 0x42;
 		data[7] = 0x02;
 
 		memset(data + 8, 0x20, 28);
-		strncpy((char *)data + 8, cmd->dev->attrs->vendor_id, 8);
-		strncpy((char *)data + 16, cmd->dev->attrs->product_id, 16);
-		strncpy((char *)data + 32, cmd->dev->attrs->product_rev, 4);
+		strncpy((char *)data + 8, cmd->dev->vendor_id, 8);
+		strncpy((char *)data + 16, cmd->dev->product_id, 16);
+		strncpy((char *)data + 32, cmd->dev->product_rev, 4);
 
 		desc = (uint16_t *)(data + 58);
-		for (i = 0; i < ARRAY_SIZE(cmd->dev->attrs->version_desc); i++)
-			*desc++ = __cpu_to_be16(cmd->dev->attrs->version_desc[i]);
+		for (i = 0; i < ARRAY_SIZE(cmd->dev->version_desc); i++)
+			*desc++ = __cpu_to_be16(cmd->dev->version_desc[i]);
 
 		len = 66;
 		data[4] = len - 5;	/* Additional Length */
@@ -108,12 +108,12 @@ int spc_inquiry(int host_no, struct scsi_cmd *cmd)
 			len = 4 + SCSI_SN_LEN;
 			ret = SAM_STAT_GOOD;
 
-			if (cmd->dev && strlen(cmd->dev->attrs->scsi_sn)) {
+			if (cmd->dev && strlen(cmd->dev->scsi_sn)) {
 				uint8_t *p;
 				char *q;
 
 				p = data + 4 + tmp - 1;
-				q = cmd->dev->attrs->scsi_sn + SCSI_SN_LEN - 1;
+				q = cmd->dev->scsi_sn + SCSI_SN_LEN - 1;
 				for (; tmp > 0; tmp--, q)
 					*(p--) = *(q--);
 			}
@@ -127,7 +127,7 @@ int spc_inquiry(int host_no, struct scsi_cmd *cmd)
 			data[7] = tmp;
 			if (cmd->dev)
 				strncpy((char *) data + 8,
-					cmd->dev->attrs->scsi_id, SCSI_ID_LEN);
+					cmd->dev->scsi_id, SCSI_ID_LEN);
 
 			len = tmp + 8;
 			ret = SAM_STAT_GOOD;
@@ -322,36 +322,36 @@ int spc_lu_config(struct scsi_lu *lu, char *params) {
 		token = match_token(p, tokens, args);
 		switch (token) {
 		case Opt_scsiid:
-			match_strncpy(lu->attrs->scsi_id, &args[0],
-				      sizeof(lu->attrs->scsi_id) - 1);
+			match_strncpy(lu->scsi_id, &args[0],
+				      sizeof(lu->scsi_id) - 1);
 			break;
 		case Opt_scsisn:
-			match_strncpy(lu->attrs->scsi_sn, &args[0],
-				      sizeof(lu->attrs->scsi_sn) - 1);
+			match_strncpy(lu->scsi_sn, &args[0],
+				      sizeof(lu->scsi_sn) - 1);
 			break;
 		case Opt_vendorid:
-			match_strncpy(lu->attrs->vendor_id, &args[0],
-					sizeof(lu->attrs->vendor_id));
+			match_strncpy(lu->vendor_id, &args[0],
+					sizeof(lu->vendor_id));
 			break;
 		case Opt_productid:
-			match_strncpy(lu->attrs->product_id, &args[0],
-					sizeof(lu->attrs->product_id));
+			match_strncpy(lu->product_id, &args[0],
+					sizeof(lu->product_id));
 			break;
 		case Opt_productrev:
-			match_strncpy(lu->attrs->product_rev, &args[0],
-					sizeof(lu->attrs->product_rev));
+			match_strncpy(lu->product_rev, &args[0],
+					sizeof(lu->product_rev));
 			break;
 		case Opt_sense_format:
 			match_strncpy(buf, &args[0],  sizeof(buf));
-			lu->attrs->sense_format = atoi(buf);
+			lu->sense_format = atoi(buf);
 			break;
 		case Opt_removable:
 			match_strncpy(buf, &args[0],  sizeof(buf));
-			lu->attrs->removable = atoi(buf);
+			lu->removable = atoi(buf);
 			break;
 		case Opt_online:
 			match_strncpy(buf, &args[0],  sizeof(buf));
-			lu->attrs->online = atoi(buf);
+			lu->online = atoi(buf);
 			break;
 		default:
 			err = TGTADM_INVALID_REQUEST;
@@ -362,16 +362,12 @@ int spc_lu_config(struct scsi_lu *lu, char *params) {
 
 int spc_lu_init(struct scsi_lu *lu)
 {
-	lu->attrs = zalloc(sizeof(struct lu_phy_attr));
-	if (!lu->attrs)
-		return -ENOMEM;
-
-	memcpy(lu->attrs->vendor_id, VENDOR_ID, 8);
-	memcpy(lu->attrs->product_rev, "0001", 4);
-	lu->attrs->removable = 0;
-	lu->attrs->sense_format = 0;
-	lu->attrs->online = 0;
-	lu->attrs->reset = 1;
+	memcpy(lu->vendor_id, VENDOR_ID, 8);
+	memcpy(lu->product_rev, "0001", 4);
+	lu->removable = 0;
+	lu->sense_format = 0;
+	lu->online = 0;
+	lu->reset = 1;
 
 	return 0;
 }
diff --git a/usr/target.c b/usr/target.c
index 5b74be1..2474f5a 100644
--- a/usr/target.c
+++ b/usr/target.c
@@ -252,9 +252,9 @@ int tgt_device_create(int tid, uint64_t lun, char *args)
 		err = target->dev_type_template.lu_init(lu);
 
 	if (!err) {
-		snprintf(lu->attrs->scsi_id, sizeof(lu->attrs->scsi_id),
+		snprintf(lu->scsi_id, sizeof(lu->scsi_id),
 			 "deadbeaf%d:%" PRIu64, tid, lun);
-		snprintf(lu->attrs->scsi_sn, sizeof(lu->attrs->scsi_sn),
+		snprintf(lu->scsi_sn, sizeof(lu->scsi_sn),
 			 "beaf%d%" PRIu64, tid, lun);
 	}
 
@@ -1126,8 +1126,8 @@ int tgt_target_show_all(char *buf, int rest)
 				 _TAB3 "Size: %s\n"
 				 _TAB3 "Backing store: %s\n",
 				 lu->lun,
-				 lu->attrs->scsi_id,
-				 lu->attrs->scsi_sn,
+				 lu->scsi_id,
+				 lu->scsi_sn,
 				 print_disksize(lu->size),
 				 lu->path);
 
diff --git a/usr/tgtd.h b/usr/tgtd.h
index 35645b1..a4c787b 100644
--- a/usr/tgtd.h
+++ b/usr/tgtd.h
@@ -30,7 +30,13 @@ struct tgt_cmd_queue {
 	struct list_head queue;
 };
 
-struct lu_phy_attr {
+struct scsi_lu {
+	int fd;
+	uint64_t addr; /* persistent mapped address */
+	uint64_t size;
+	uint64_t lun;
+	char *path;
+
 	char scsi_id[SCSI_ID_LEN];
 	char scsi_sn[SCSI_SN_LEN];
 
@@ -44,14 +50,6 @@ struct lu_phy_attr {
 	char online;		/* Logical Unit online ? */
 	char reset;		/* Power-on or reset has occured */
 	char sense_format;	/* Descrptor format sense data supported */
-};
-
-struct scsi_lu {
-	int fd;
-	uint64_t addr; /* persistent mapped address */
-	uint64_t size;
-	uint64_t lun;
-	char *path;
 
 	/* the list of devices belonging to a target */
 	struct list_head device_siblings;
@@ -63,7 +61,6 @@ struct scsi_lu {
 	uint64_t reserve_id;
 
 	/* TODO: needs a structure for lots of device parameters */
-	struct lu_phy_attr *attrs;
 };
 
 struct scsi_cmd {
-- 
1.5.2.1







More information about the stgt mailing list