Blame 0036-iscsiadm-Use-x-option-instead-of-v-to-specify-chap_t.patch

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