Skip to contentSkip to conversation

convert cisco driver to use transport class

PATCH In review Mike Christie 2 participants 2 messages Mar 26, 2004 – Mar 30, 2004 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 convert cisco driver to use transport class

And, here is the conversion patch.

 iscsi-attr.c      |  201 +++++++++++++++---------------------------------------
 iscsi-attr.h      |    2
 iscsi-initiator.c |   72 +++++++++++--------
 3 files changed, 97 insertions(+), 178 deletions(-)

Mike Christie

drivers/scsi/iscsi-sfnet/iscsi-attr.c +56 -145
diff -aurp linux-2.6.5-rc2/drivers/scsi/iscsi-sfnet/iscsi-attr.c linux-2.6.5-rc2-iscsi/drivers/scsi/iscsi-sfnet/iscsi-attr.c
@@ -20,6 +20,10 @@
  */
 
 #include <linux/device.h>
+#include <scsi/scsi_host.h>
+#include <scsi/scsi_device.h>
+#include <scsi/scsi_transport.h>
+#include <scsi/scsi_transport_iscsi.h>
 
 #include "iscsi-protocol.h"
 #include "iscsi-session.h"
@@ -597,143 +601,6 @@ iscsi_change_disk_command_timeout(struct
 	}
 }
 
-static int
-add_lun_line_info(struct iscsi_session *session, int lun, char **buffer)
-{
-	DEBUG_FLOW("iSCSI: add_lun_line iscsi bus %d target id %d, %d \n",
-		session->iscsi_bus, session->target_id, lun);
-
-	/* 2 spaces + (4 * (3-digit field + space)) + 4 spaces = 22 chars */
-	if (lun >= 0)
-		*buffer += sprintf(*buffer, " %3.1u %3.1u %3.1u    ",
-			session->iscsi_bus, session->target_id, lun);
-	else
-		*buffer += sprintf(*buffer, " %3.1u %3.1u   ?    ",
-			session->iscsi_bus, session->target_id);
-
-	if (test_bit(SESSION_ESTABLISHED, &session->control_bits)) {
-		/* up to 15 char IP address + 2 spaces = 17 chars */
-		*buffer += sprintf(*buffer, "   %u.%u.%u.%u  ",
-			session->ip_address[0], session->ip_address[1],
-			session->ip_address[2], session->ip_address[3]);
-		/* right_justify(*buffer, 17); */
-
-		/* 5-digit port + 2 spaces = 7 chars */
-		*buffer += sprintf(*buffer, " %d  ", session->port);
-
-	} else {
-		/* fill in '?' for each empty field, so that
-		 * it is easier for processing by tools such as awk and perl.
-		 */
-		*buffer += sprintf(*buffer, "              ?      ?  ");
-
-	}
-	*buffer += sprintf(*buffer, "%s ", session->TargetName);
-	 /* and a newline */
-	*buffer += sprintf(*buffer, "\n");
-	return 1;
-}
-
-static int
-show_session_lun_info(struct iscsi_session *session, char **buffer)
-{
-	/* if we've already found LUNs, show them all */
-	int lfound = 0;
-	int l;
-
-	/* FIXME: IPv6 */
-	if (session->ip_length != 4)
-		return 1;
-
-	for (l = 0; l < ISCSI_MAX_LUN; l++) {
-		if (test_bit(l, session->luns_activated)) {
-			lfound += 1;
-			if (!add_lun_line_info(session, l, buffer)) {
-				DEBUG_FLOW("iSCSI: show session luns"
-					" returning 0 ");
-				return 0;
-			}
-		}
-	}
-
-	/* if we haven't found any LUNs, use ? for a LUN number */
-	if (!lfound) {
-		if (!add_lun_line_info(session, -1, buffer)) {
-			DEBUG_FLOW("iSCSI: show session luns returning 0 \n");
-			return 0;
-		}
-	} else {
-		DEBUG_FLOW("iSCSI: show session luns returning 1 ");
-	}
-	return 1;
-}
-
-static ssize_t
-iscsi_print_info(struct class_device *class_dev, char *buf)
-{
-	struct Scsi_Host *host = class_to_shost(class_dev);
-	struct iscsi_session *session;
-	unsigned long noqueue_flags_;
-	char *build_str = BUILD_STR;
-	char *bp;
-
-	bp = buf;
-
-	/* comment header with version number */
-	/* FIXME: we assume the buffer length is always large 
-	 * enough for our header 
-	 */
-	if (build_str) {
-		/* developer-built variant of a 4-digit internal 
-		 * release 
-		 */
-		bp +=
-		    sprintf(bp,
-			    "# iSCSI driver version: %d.%d.%d.%d%s "
-			    "variant (%s)\n#\n",
-			    DRIVER_MAJOR_VERSION, DRIVER_MINOR_VERSION,
-			    DRIVER_PATCH_VERSION,
-			    DRIVER_INTERNAL_VERSION,
-			    DRIVER_EXTRAVERSION, ISCSI_DATE);
-	} else if (DRIVER_INTERNAL_VERSION > 0) {
-		/* 4-digit release */
-		bp +=
-		    sprintf(bp,
-			    "# iSCSI driver version: %d.%d.%d.%d%s "
-			    "(%s)\n#\n",
-			    DRIVER_MAJOR_VERSION, DRIVER_MINOR_VERSION,
-			    DRIVER_PATCH_VERSION,
-			    DRIVER_INTERNAL_VERSION,
-			    DRIVER_EXTRAVERSION, ISCSI_DATE);
-	} else {
-		/* 3-digit release */
-		bp +=
-		    sprintf(bp,
-			    "# iSCSI driver version: %d.%d.%d%s "
-			    "(%s)\n#\n",
-			    DRIVER_MAJOR_VERSION, DRIVER_MINOR_VERSION,
-			    DRIVER_PATCH_VERSION, DRIVER_EXTRAVERSION,
-			    ISCSI_DATE);
-	}
-	bp += sprintf(bp, "# SCSI:               iSCSI:\n");
-	bp += sprintf(bp, "# Bus Tgt LUN         IP address   Port  "
-		    "TargetName\n");
-
-	if (iscsi_hba) {
-		spin_lock_irqsave(&iscsi_hba->session_lock, noqueue_flags_);
-		list_for_each_entry(session, &iscsi_hba->session_head,
-				    session_link) {
-			if (!show_session_lun_info(session, &bp))
-				break;
-		}
-		spin_unlock_irqrestore(&iscsi_hba->session_lock,
-					noqueue_flags_);
-	} else {
-		printk("iSCSI: couldn't find HBA %p\n", host);
-	}
-	return (bp - buf);
-}
-
 static ssize_t 
 iscsi_host_id(struct class_device *class_dev, char *buf)
 {
@@ -802,14 +669,6 @@ struct class_device_attribute shutdown =
 	.store = do_iscsi_shutdown,
 };
 
-struct class_device_attribute print_info = {
-	.attr = {
-		.name =		"print_info",
-		.mode =		S_IRUGO,
-	},
-	.show = iscsi_print_info,
-};
-
 struct class_device_attribute host_id = {
 	.attr = {
 		.name = "host_no",
@@ -825,3 +684,55 @@ struct class_device_attribute network_bo
 	},
 	.show = iscsi_network_boot,
 };
+
+static ssize_t iscsi_get_tgt_port(struct scsi_device *sdev, char *buf)
+{
+	struct iscsi_session *session;
+
+	if (!sdev->hostdata)
+		return 0;
+
+	session = ((struct iscsi_dev_data *)sdev->hostdata)->session;
+	if (!test_bit(SESSION_ESTABLISHED, &session->control_bits))
+		return 0;
+
+	return sprintf(buf, "%d\n", session->port);
+}
+
+static ssize_t iscsi_get_tgt_addr(struct scsi_device *sdev, char *buf)
+{
+	struct iscsi_session *session;
+
+	if (!sdev->hostdata)
+		return 0;
+
+	session = ((struct iscsi_dev_data *)sdev->hostdata)->session;
+	if (!test_bit(SESSION_ESTABLISHED, &session->control_bits))
+		return 0;
+
+	if (session->ip_length == 4)
+		return sprintf(buf, "%u.%u.%u.%u",
+			       NIPQUAD(session->ip_address));
+	else
+		return 0;
+}
+
+static ssize_t iscsi_get_tgt_name(struct scsi_device *sdev, char *buf)
+{
+	struct iscsi_session *session;
+
+	if (!sdev->hostdata)
+		return 0;
+
+	session = ((struct iscsi_dev_data *)sdev->hostdata)->session;
+	if (!test_bit(SESSION_ESTABLISHED, &session->control_bits))
+		return 0;
+
+	return snprintf(buf, PAGE_SIZE, "%s\n", session->TargetName);
+}
+
+struct iscsi_function_template iscsi_transport_functions = {
+	.get_target_port = iscsi_get_tgt_port,
+	.get_target_addr = iscsi_get_tgt_addr,
+	.get_target_name = iscsi_get_tgt_name,
+};
drivers/scsi/iscsi-sfnet/iscsi-attr.h +0 -2
diff -aurp linux-2.6.5-rc2/drivers/scsi/iscsi-sfnet/iscsi-attr.h linux-2.6.5-rc2-iscsi/drivers/scsi/iscsi-sfnet/iscsi-attr.h
@@ -67,7 +67,6 @@ extern struct class_device_attribute tar
 extern struct class_device_attribute log_status;
 extern struct class_device_attribute shutdown;
 extern struct class_device_attribute change_portal;
-extern struct class_device_attribute print_info;
 extern struct class_device_attribute host_id;
 extern struct class_device_attribute network_boot;
 extern struct class_device_attribute connfailtimeout;
@@ -77,7 +76,6 @@ struct class_device_attribute *iscsi_hos
 	&log_status,
 	&shutdown,
 	&change_portal,
-	&print_info,
 	&host_id,
 	&network_boot,
 	&connfailtimeout,
drivers/scsi/iscsi-sfnet/iscsi-initiator.c +41 -31

123 lines not on this page · raw message

#1 lore raw

Hi Mike,

I reviewed your patch. The changes look fine.

Thanks,
surekha

Quoted 21 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Mike Christie
Sent: Saturday, March 27, 2004 2:21 AM
To: SCSI Mailing List; [email protected]
Subject: [linux-iscsi-devel] [PATCH] convert cisco driver to use transport class

And, here is the conversion patch.

  iscsi-attr.c      |  201 
+++++++++++++++---------------------------------------
  iscsi-attr.h      |    2
  iscsi-initiator.c |   72 +++++++++++--------
  3 files changed, 97 insertions(+), 178 deletions(-)

Mike Christie