[Stgt-devel] [Patch 1/2] Merge lu_phy_attr struct into scsi_lu

Mark Harvey markh794
Fri Jun 15 09:55:11 CEST 2007


>From de670fc4dc5d67584b7a84841df6a01443f23e48 Mon Sep 17 00:00:00 2001
From: Mark Harvey <markh794 at gmail.com>
Date: Fri, 15 Jun 2007 17:20:34 +1000
Subject: Merge lu_phy_attr struct into scsi_lu struct

Included lu_phy_attr struct 'in line' with scsi_lu structure.
 - It is a static structure and works just as well inside
   the scsi_lu struct.

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    |   52 ++++++++++++++++++++++++----------------------------
 usr/target.c |    8 ++++----
 usr/tgtd.h   |    6 +++---
 7 files changed, 46 insertions(+), 50 deletions(-)

diff --git a/usr/mmc.c b/usr/mmc.c
index a8aced5..0ac5f72 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 */
+	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 */
 
 	return 0;
 }
diff --git a/usr/osd.c b/usr/osd.c
index ac33168..33d6455 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 */
+	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 */
 
 	return 0;
 }
diff --git a/usr/sbc.c b/usr/sbc.c
index 2924cc6..8fe39e7 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 */
+	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 */
 
 	return 0;
 }
diff --git a/usr/scsi.c b/usr/scsi.c
index 50e2080..c9fb7b6 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->attrs.sense_format) {
 		/* descriptor format */
 
 		cmd->sense_buffer[0] = 0x72;  /* current, not deferred */
diff --git a/usr/spc.c b/usr/spc.c
index 99a7df3..602af5d 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->is_removable) ? 0x80 : 0;
+		data[1] = (cmd->dev->attrs.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->attrs.vendor_id, 8);
+		strncpy((char *)data + 16, cmd->dev->attrs.product_id, 16);
+		strncpy((char *)data + 32, cmd->dev->attrs.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->attrs.version_desc); i++)
+			*desc++ = __cpu_to_be16(cmd->dev->attrs.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->attrs.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->attrs.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->attrs.scsi_id, SCSI_ID_LEN);
 
 			len = tmp + 8;
 			ret = SAM_STAT_GOOD;
@@ -286,12 +286,12 @@ int spc_illegal_op(int host_no, struct scsi_cmd *cmd)
 }
 
 enum {
-	Opt_scsiid, Opt_scsisn, Opt_err,
+	Opt_scsi_id, Opt_scsi_sn, Opt_err,
 };
 
 static match_table_t tokens = {
-	{Opt_scsiid, "scsi_id=%s"},
-	{Opt_scsisn, "scsi_sn=%s"},
+	{Opt_scsi_id, "scsi_id=%s"},
+	{Opt_scsi_sn, "scsi_sn=%s"},
 	{Opt_err, NULL},
 };
 
@@ -310,13 +310,13 @@ int spc_lu_config(struct scsi_lu *lu, char *params) {
 		dprintf("*p : %s\n", p);
 		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);
+		case Opt_scsi_id:
+			match_strncpy(lu->attrs.scsi_id, &args[0],
+				      sizeof(lu->attrs.scsi_id) - 1);
 			break;
-		case Opt_scsisn:
-			match_strncpy(lu->attrs->scsi_sn, &args[0],
-				      sizeof(lu->attrs->scsi_sn) - 1);
+		case Opt_scsi_sn:
+			match_strncpy(lu->attrs.scsi_sn, &args[0],
+				      sizeof(lu->attrs.scsi_sn) - 1);
 			break;
 		default:
 			err = TGTADM_INVALID_REQUEST;
@@ -327,16 +327,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->is_removable = 0;
-	lu->attrs->sense_format = 0;
-	lu->attrs->online = 0;
-	lu->attrs->reset = 1;
+	strncpy(lu->attrs.vendor_id, VENDOR_ID, strlen(VENDOR_ID));
+	memcpy(lu->attrs.product_rev, "0001", 4);
+	lu->attrs.removable = 0;
+	lu->attrs.sense_format = 0;
+	lu->attrs.online = 0;
+	lu->attrs.reset = 1;
 
 	return 0;
 }
diff --git a/usr/target.c b/usr/target.c
index 5b74be1..9170310 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->attrs.scsi_id, sizeof(lu->attrs.scsi_id),
 			 "deadbeaf%d:%" PRIu64, tid, lun);
-		snprintf(lu->attrs->scsi_sn, sizeof(lu->attrs->scsi_sn),
+		snprintf(lu->attrs.scsi_sn, sizeof(lu->attrs.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->attrs.scsi_id,
+				 lu->attrs.scsi_sn,
 				 print_disksize(lu->size),
 				 lu->path);
 
diff --git a/usr/tgtd.h b/usr/tgtd.h
index 7b64655..e214fbb 100644
--- a/usr/tgtd.h
+++ b/usr/tgtd.h
@@ -40,8 +40,8 @@ struct lu_phy_attr {
 	char product_rev[5];
 	uint16_t version_desc[VERSION_DESCRIPTOR_LEN];
 
-	char is_removable;	/* Removable media */
-	char online;		/* Logical Unit online ? */
+	char removable;		/* Removable media */
+	char online;		/* Logical Unit online */
 	char reset;		/* Power-on or reset has occured */
 	char sense_format;	/* Descrptor format sense data supported */
 };
@@ -63,7 +63,7 @@ struct scsi_lu {
 	uint64_t reserve_id;
 
 	/* TODO: needs a structure for lots of device parameters */
-	struct lu_phy_attr *attrs;
+	struct lu_phy_attr attrs;
 };
 
 struct scsi_cmd {
-- 
1.5.2.1








More information about the stgt mailing list