374005
From b3913c5943b6e908a1bb8ce83a2e79200d0ceed9 Mon Sep 17 00:00:00 2001
374005
From: Adheer Chandravanshi <adheer.chandravanshi@qlogic.com>
374005
Date: Tue, 17 Sep 2013 08:07:29 -0400
374005
Subject: [PATCH] iscsiadm: Use '-x' option instead of '-v' to specify
374005
 chap_tbl_idx
374005
374005
Make appropriate changes to use -x option for chap_tbl_idx cmdline
374005
param. This is done because -v option is used along with -n option
374005
to get the name/value pair.
374005
374005
Signed-off-by: Adheer Chandravanshi <adheer.chandravanshi@qlogic.com>
374005
Signed-off-by: Vikas Chaudhary <vikas.chaudhary@qlogic.com>
374005
---
374005
 usr/host.h     |  1 +
374005
 usr/iscsiadm.c | 36 +++++++++++++++++-------------------
374005
 2 files changed, 18 insertions(+), 19 deletions(-)
374005
374005
diff --git a/usr/host.h b/usr/host.h
374005
index db44cfa..52e5b9e 100644
374005
--- a/usr/host.h
374005
+++ b/usr/host.h
374005
@@ -7,6 +7,7 @@
374005
 
374005
 #define MAX_HOST_NO UINT_MAX
374005
 
374005
+#define MAX_CHAP_ENTRIES 2048
374005
 #define MAX_CHAP_BUF_SZ 4096
374005
 #define REQ_CHAP_BUF_SZ (MAX_CHAP_BUF_SZ + sizeof(struct iscsi_uevent))
374005
 
374005
diff --git a/usr/iscsiadm.c b/usr/iscsiadm.c
374005
index c7337ae..beabdf0 100644
374005
--- a/usr/iscsiadm.c
374005
+++ b/usr/iscsiadm.c
374005
@@ -115,7 +115,7 @@ static struct option const long_options[] =
374005
 	{"packetsize", required_argument, NULL, 'b'},
374005
 	{"count", required_argument, NULL, 'c'},
374005
 	{"interval", required_argument, NULL, 'i'},
374005
-	{"flashnode_idx", optional_argument, NULL, 'x'},
374005
+	{"index", optional_argument, NULL, 'x'},
374005
 	{"portal_type", optional_argument, NULL, 'A'},
374005
 	{NULL, 0, NULL, 0},
374005
 };
374005
@@ -136,7 +136,7 @@ iscsiadm -m node [ -hV ] [ -d debug_level ] [ -P printlevel ] [ -L all,manual,au
374005
 iscsiadm -m session [ -hV ] [ -d debug_level ] [ -P  printlevel] [ -r sessionid | sysfsdir [ -R | -u | -s ] [ -o operation ] [ -n name ] [ -v value ] ]\n\
374005
 iscsiadm -m iface [ -hV ] [ -d debug_level ] [ -P printlevel ] [ -I ifacename | -H hostno|MAC ] [ [ -o  operation  ] [ -n name ] [ -v value ] ] [ -C ping [ -a ip ] [ -b packetsize ] [ -c count ] [ -i interval ] ]\n\
374005
 iscsiadm -m fw [ -d debug_level ] [ -l ]\n\
374005
-iscsiadm -m host [ -P printlevel ] [ -H hostno|MAC ] [ [ -C chap [ -o operation ] [ -v chap_tbl_idx ] ] | [ -C flashnode [ -o operation ] [ -A portal_type ] [ -x flashnode_idx ] [ -n name ] [ -v value ] ] ]\n\
374005
+iscsiadm -m host [ -P printlevel ] [ -H hostno|MAC ] [ [ -C chap [ -x chap_tbl_idx ] ] | [ -C flashnode [ -A portal_type ] [ -x flashnode_idx ] ] ] [ [ -o operation ] [ -n name ] [ -v value ] ] \n\
374005
 iscsiadm -k priority\n");
374005
 	}
374005
 	exit(status);
374005
@@ -1426,18 +1426,10 @@ exit_chap_info:
374005
 	return rc;
374005
 }
374005
 
374005
-static int delete_host_chap_info(uint32_t host_no, char *value)
374005
+static int delete_host_chap_info(uint32_t host_no, uint16_t chap_tbl_idx)
374005
 {
374005
 	struct iscsi_transport *t = NULL;
374005
 	int fd, rc = 0;
374005
-	uint16_t chap_tbl_idx;
374005
-
374005
-	if (!value) {
374005
-		log_error("CHAP deletion requires --value=table_index.");
374005
-		return ISCSI_ERR_INVAL;
374005
-	}
374005
-
374005
-	chap_tbl_idx = (uint16_t)atoi(value);
374005
 
374005
 	t = iscsi_sysfs_get_transport_by_hba(host_no);
374005
 	if (!t) {
374005
@@ -1472,22 +1464,28 @@ exit_delete_chap:
374005
 }
374005
 
374005
 static int exec_host_chap_op(int op, int info_level, uint32_t host_no,
374005
-			     char *value)
374005
+			     uint64_t chap_index)
374005
 {
374005
 	int rc = ISCSI_ERR_INVAL;
374005
 
374005
+	if (op != OP_SHOW && (chap_index > (uint64_t)MAX_CHAP_ENTRIES)) {
374005
+		log_error("Invalid chap table index.");
374005
+		goto exit_chap_op;
374005
+	}
374005
+
374005
 	switch (op) {
374005
 	case OP_SHOW:
374005
 		rc = get_host_chap_info(host_no);
374005
 		break;
374005
 	case OP_DELETE:
374005
-		rc = delete_host_chap_info(host_no, value);
374005
+		rc = delete_host_chap_info(host_no, chap_index);
374005
 		break;
374005
 	default:
374005
 		log_error("Invalid operation.");
374005
 		break;
374005
 	}
374005
 
374005
+exit_chap_op:
374005
 	return rc;
374005
 }
374005
 
374005
@@ -2818,7 +2816,7 @@ main(int argc, char **argv)
374005
 	struct iface_rec *iface = NULL, *tmp;
374005
 	struct node_rec *rec = NULL;
374005
 	uint64_t host_no =  (uint64_t)MAX_HOST_NO + 1;
374005
-	uint64_t flashnode_idx = (uint64_t)MAX_FLASHNODE_IDX + 1;
374005
+	uint64_t index = (uint64_t)MAX_FLASHNODE_IDX + 1;
374005
 	struct user_param *param;
374005
 	struct list_head params;
374005
 
374005
@@ -2962,9 +2960,9 @@ main(int argc, char **argv)
374005
 				ISCSI_VERSION_STR);
374005
 			return 0;
374005
 		case 'x':
374005
-			flashnode_idx = strtoull(optarg, NULL, 10);
374005
+			index = strtoull(optarg, NULL, 10);
374005
 			if (errno) {
374005
-				log_error("Invalid flashnode index %s. %s.",
374005
+				log_error("Invalid index %s. %s.",
374005
 					  optarg, strerror(errno));
374005
 				rc = ISCSI_ERR_INVAL;
374005
 				goto free_ifaces;
374005
@@ -3041,7 +3039,7 @@ main(int argc, char **argv)
374005
 					break;
374005
 				}
374005
 				rc = exec_host_chap_op(op, info_level, host_no,
374005
-						       value);
374005
+						       index);
374005
 				break;
374005
 			case MODE_FLASHNODE:
374005
 				if (host_no > MAX_HOST_NO) {
374005
@@ -3051,8 +3049,8 @@ main(int argc, char **argv)
374005
 				}
374005
 
374005
 				rc = exec_flashnode_op(op, info_level, host_no,
374005
-						       flashnode_idx,
374005
-						       portal_type, ¶ms);
374005
+						       index, portal_type,
374005
+						       ¶ms);
374005
 				break;
374005
 			default:
374005
 				log_error("Invalid Sub Mode");
374005
-- 
374005
1.8.3.1
374005