Blame 0148-iscsiadm-param-parsing-for-advanced-node-creation.patch

c2d5d2
From b58f3b48a36821d10a3377acfcbf18113fba0c9d Mon Sep 17 00:00:00 2001
6bbb92
From: Chris Leech <cleech@redhat.com>
6bbb92
Date: Tue, 18 Dec 2012 11:27:00 -0800
c2d5d2
Subject: [PATCH 48/48] iscsiadm: --param parsing for advanced node creation
6bbb92
6bbb92
Share parse_param and apply_param code from iscsistart, allow using multiple
6bbb92
--param options to set arbitrary fields in node mode.
6bbb92
6bbb92
Signed-off-by: Chris Leech <cleech@redhat.com>
6bbb92
---
6bbb92
 usr/Makefile      |  2 +-
6bbb92
 usr/iscsi_param.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
6bbb92
 usr/iscsi_param.h |  7 ++++
6bbb92
 usr/iscsiadm.c    | 16 ++++++++--
6bbb92
 usr/iscsistart.c  | 91 ++--------------------------------------------------
6bbb92
 5 files changed, 120 insertions(+), 91 deletions(-)
6bbb92
 create mode 100644 usr/iscsi_param.c
6bbb92
 create mode 100644 usr/iscsi_param.h
6bbb92
6bbb92
diff --git a/usr/Makefile b/usr/Makefile
c2d5d2
index 3d8ee22..a7e80c0 100644
6bbb92
--- a/usr/Makefile
6bbb92
+++ b/usr/Makefile
6bbb92
@@ -40,7 +40,7 @@ SYSDEPS_SRCS = $(wildcard ../utils/sysdeps/*.o)
6bbb92
 ISCSI_LIB_SRCS = iscsi_util.o io.o auth.o iscsi_timer.o login.o log.o md5.o \
6bbb92
 	sha1.o iface.o idbm.o sysfs.o host.o session_info.o iscsi_sysfs.o \
6bbb92
 	iscsi_net_util.o iscsid_req.o transport.o iser.o cxgbi.o be2iscsi.o \
c2d5d2
-	initiator_common.o iscsi_err.o flashnode.o uip_mgmt_ipc.o \
c2d5d2
+	initiator_common.o iscsi_err.o iscsi_param.o flashnode.o uip_mgmt_ipc.o \
c2d5d2
 	$(IPC_OBJ)  $(SYSDEPS_SRCS)
6bbb92
 # core initiator files
6bbb92
 INITIATOR_SRCS = initiator.o scsi.o actor.o event_poll.o mgmt_ipc.o kern_err_table.o
6bbb92
diff --git a/usr/iscsi_param.c b/usr/iscsi_param.c
6bbb92
new file mode 100644
6bbb92
index 0000000..c075e8f
6bbb92
--- /dev/null
6bbb92
+++ b/usr/iscsi_param.c
6bbb92
@@ -0,0 +1,95 @@
6bbb92
+#include <string.h>
6bbb92
+#include "log.h"
6bbb92
+#include "config.h"
6bbb92
+#include "idbm.h"
6bbb92
+#include "list.h"
6bbb92
+#include "iface.h"
6bbb92
+#include "idbm_fields.h"
6bbb92
+#include "iscsi_err.h"
6bbb92
+
6bbb92
+int apply_params(struct list_head *user_params, struct node_rec *rec)
6bbb92
+{
6bbb92
+	struct user_param *param;
6bbb92
+	int rc;
6bbb92
+
6bbb92
+	/* Must init this so we can check if user overrode them */
6bbb92
+	rec->session.initial_login_retry_max = -1;
6bbb92
+	rec->conn[0].timeo.noop_out_interval = -1;
6bbb92
+	rec->conn[0].timeo.noop_out_timeout = -1;
6bbb92
+
6bbb92
+	list_for_each_entry(param, user_params, list) {
6bbb92
+		/*
6bbb92
+		 * user may not have passed in all params that were set by
6bbb92
+		 * ibft/iscsi_boot, so clear out values that might conflict
6bbb92
+		 * with user overrides
6bbb92
+		 */
6bbb92
+		if (!strcmp(param->name, IFACE_NETNAME)) {
6bbb92
+			/* overriding netname so MAC will be for old netdev */
6bbb92
+			memset(rec->iface.hwaddress, 0,
6bbb92
+				sizeof(rec->iface.hwaddress));
6bbb92
+		} else if (!strcmp(param->name, IFACE_HWADDR)) {
6bbb92
+			/* overriding MAC so netdev will be for old MAC */
6bbb92
+			memset(rec->iface.netdev, 0, sizeof(rec->iface.netdev));
6bbb92
+		} else if (!strcmp(param->name, IFACE_TRANSPORTNAME)) {
6bbb92
+			/*
6bbb92
+			 * switching drivers so all old binding info is no
6bbb92
+			 * longer valid. Old values were either for offload
6bbb92
+			 * and we are switching to software or the reverse,
6bbb92
+			 * or switching types of cards (bnx2i to cxgb3i).
6bbb92
+			 */
6bbb92
+			memset(&rec->iface, 0, sizeof(rec->iface));
6bbb92
+			iface_setup_defaults(&rec->iface);
6bbb92
+		}
6bbb92
+	}
6bbb92
+
6bbb92
+	rc = idbm_node_set_rec_from_param(user_params, rec, 0);
6bbb92
+	if (rc)
6bbb92
+		return rc;
6bbb92
+
6bbb92
+	/*
6bbb92
+	 * For root boot we could not change this in older versions so
6bbb92
+	 * if user did not override then use the defaults.
6bbb92
+	 *
6bbb92
+	 * Increase to account for boot using static setup.
6bbb92
+	 */
6bbb92
+	if (rec->session.initial_login_retry_max == -1)
6bbb92
+		rec->session.initial_login_retry_max = 30;
6bbb92
+	/* we used to not be able to answer so turn off */
6bbb92
+	if (rec->conn[0].timeo.noop_out_interval == -1)
6bbb92
+		rec->conn[0].timeo.noop_out_interval = 0;
6bbb92
+	if (rec->conn[0].timeo.noop_out_timeout == -1)
6bbb92
+		rec->conn[0].timeo.noop_out_timeout = 0;
6bbb92
+
6bbb92
+	return 0;
6bbb92
+}
6bbb92
+
6bbb92
+int parse_param(struct list_head *user_params, char *param_str)
6bbb92
+{
6bbb92
+	struct user_param *param;
6bbb92
+	char *name, *value;
6bbb92
+
6bbb92
+	name = param_str;
6bbb92
+
6bbb92
+	value = strchr(param_str, '=');
6bbb92
+	if (!value) {
6bbb92
+		log_error("Invalid --param %s. Missing value.", param_str);
6bbb92
+		return ISCSI_ERR_INVAL;
6bbb92
+	}
6bbb92
+	*value = '\0';
6bbb92
+
6bbb92
+	value++;
6bbb92
+	if (!strlen(value)) {
6bbb92
+		log_error("Invalid --param %s. Missing value.", param_str);
6bbb92
+		return ISCSI_ERR_INVAL;
6bbb92
+	}
6bbb92
+
6bbb92
+	param = idbm_alloc_user_param(name, value);
6bbb92
+	if (!param) {
6bbb92
+		log_error("Could not allocate memory for param.");
6bbb92
+		return ISCSI_ERR_NOMEM;
6bbb92
+	}
6bbb92
+
6bbb92
+	list_add(¶m->list, user_params);
6bbb92
+	return 0;
6bbb92
+}
6bbb92
+
6bbb92
diff --git a/usr/iscsi_param.h b/usr/iscsi_param.h
6bbb92
new file mode 100644
6bbb92
index 0000000..8b7956c
6bbb92
--- /dev/null
6bbb92
+++ b/usr/iscsi_param.h
6bbb92
@@ -0,0 +1,7 @@
6bbb92
+#ifndef ISCSI_PARAM_H
6bbb92
+#define ISCSI_PARAM_H
6bbb92
+
6bbb92
+extern int parse_param(struct list_head *user_params, char *param_str);
6bbb92
+extern int apply_params(struct list_head *user_params, struct node_rec *rec);
6bbb92
+
6bbb92
+#endif
6bbb92
diff --git a/usr/iscsiadm.c b/usr/iscsiadm.c
c2d5d2
index af6d607..2003d48 100644
6bbb92
--- a/usr/iscsiadm.c
6bbb92
+++ b/usr/iscsiadm.c
6bbb92
@@ -53,6 +53,7 @@
6bbb92
 #include "iscsi_err.h"
6bbb92
 #include "iscsi_ipc.h"
6bbb92
 #include "iscsi_timer.h"
6bbb92
+#include "iscsi_param.h"
c2d5d2
 #include "flashnode.h"
6bbb92
 
6bbb92
 static char program_name[] = "iscsiadm";
c2d5d2
@@ -118,6 +119,7 @@ static struct option const long_options[] =
c2d5d2
 	{"flashnode_idx", optional_argument, NULL, 'x'},
c2d5d2
 	{"portal_type", optional_argument, NULL, 'A'},
6bbb92
 	{"newroot", required_argument, NULL, 0},
6bbb92
+	{"param", required_argument, NULL, 0},
6bbb92
 	{NULL, 0, NULL, 0},
6bbb92
 };
c2d5d2
 static char *short_options = "RlDVhm:a:b:c:C:p:P:T:H:i:I:U:k:L:d:r:n:v:o:sSt:ux:A:";
c2d5d2
@@ -133,7 +135,7 @@ iscsiadm -m discoverydb [ -hV ] [ -d debug_level ] [-P printlevel] [ -t type -p
6bbb92
 [ -o operation ] [ -n name ] [ -v value ] [ -lD ] ] \n\
6bbb92
 iscsiadm -m discovery [ -hV ] [ -d debug_level ] [-P printlevel] [ -t type -p ip:port -I ifaceN ... [ -l ] ] | [ [ -p ip:port ] [ -l | -D ] ] \n\
6bbb92
 iscsiadm -m node [ -hV ] [ -d debug_level ] [ -P printlevel ] [ -L all,manual,automatic ] [ -U all,manual,automatic ] [ -S ] [ [ -T targetname -p ip:port -I ifaceN ] [ -l | -u | -R | -s] ] \
6bbb92
-[ [ -o  operation  ] [ -n name ] [ -v value ] ]\n\
6bbb92
+[ [ -o  operation  ] [ -n name ] [ -v value ] ] [ --param=NAME=VALUE ]\n\
6bbb92
 iscsiadm -m session [ -hV ] [ -d debug_level ] [ -P  printlevel] [ -r sessionid | sysfsdir [ -R | -u | -s ] [ -o operation ] [ -n name ] [ -v value ] ]\n\
6bbb92
 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\
c2d5d2
 iscsiadm -m fw [ -d debug_level ] [ -l ]\n\
c2d5d2
@@ -2834,9 +2836,11 @@ main(int argc, char **argv)
6bbb92
 	uint32_t host_no = -1;
6bbb92
 	struct user_param *param;
6bbb92
 	struct list_head params;
6bbb92
+	struct list_head user_params;
6bbb92
 
6bbb92
 	INIT_LIST_HEAD(¶ms);
6bbb92
 	INIT_LIST_HEAD(&ifaces);
6bbb92
+	INIT_LIST_HEAD(&user_params);
6bbb92
 	/* do not allow ctrl-c for now... */
6bbb92
 	memset(&sa_old, 0, sizeof(struct sigaction));
6bbb92
 	memset(&sa_new, 0, sizeof(struct sigaction));
c2d5d2
@@ -2859,8 +2863,14 @@ main(int argc, char **argv)
6bbb92
 		case 0:
6bbb92
 			if (long_options[longindex].flag != 0)
6bbb92
 				break;
6bbb92
-			if (!strcmp(long_options[longindex].name, "newroot"))
6bbb92
+			if (!strcmp(long_options[longindex].name, "newroot")) {
6bbb92
 				newroot = optarg;
6bbb92
+				break;
6bbb92
+			}
6bbb92
+			if (!strcmp(long_options[longindex].name, "param")) {
6bbb92
+				parse_param(&user_params, optarg);
6bbb92
+				break;
6bbb92
+			}
6bbb92
 			break;
6bbb92
 		case 'k':
6bbb92
 			killiscsid = atoi(optarg);
c2d5d2
@@ -3169,6 +3179,8 @@ main(int argc, char **argv)
6bbb92
 			goto out;
6bbb92
 		}
6bbb92
 
6bbb92
+		apply_params(&user_params, rec);
6bbb92
+
6bbb92
 		rc = exec_node_op(op, do_login, do_logout, do_show,
6bbb92
 				  do_rescan, do_stats, info_level, rec,
6bbb92
 				  ¶ms);
6bbb92
diff --git a/usr/iscsistart.c b/usr/iscsistart.c
6bbb92
index 6924d49..85be35b 100644
6bbb92
--- a/usr/iscsistart.c
6bbb92
+++ b/usr/iscsistart.c
6bbb92
@@ -50,6 +50,7 @@
6bbb92
 #include "iscsid_req.h"
6bbb92
 #include "iscsi_err.h"
6bbb92
 #include "iface.h"
6bbb92
+#include "iscsi_param.h"
6bbb92
 
6bbb92
 /* global config info */
6bbb92
 /* initiator needs initiator name/alias */
6bbb92
@@ -131,99 +132,13 @@ static int stop_event_loop(void)
6bbb92
 	return rc;
6bbb92
 }
6bbb92
 
6bbb92
-static int apply_params(struct node_rec *rec)
6bbb92
-{
6bbb92
-	struct user_param *param;
6bbb92
-	int rc;
6bbb92
-
6bbb92
-	/* Must init this so we can check if user overrode them */
6bbb92
-	rec->session.initial_login_retry_max = -1;
6bbb92
-	rec->conn[0].timeo.noop_out_interval = -1;
6bbb92
-	rec->conn[0].timeo.noop_out_timeout = -1;
6bbb92
-
6bbb92
-	list_for_each_entry(param, &user_params, list) {
6bbb92
-		/*
6bbb92
-		 * user may not have passed in all params that were set by
6bbb92
-		 * ibft/iscsi_boot, so clear out values that might conflict
6bbb92
-		 * with user overrides
6bbb92
-		 */
6bbb92
-		if (!strcmp(param->name, IFACE_NETNAME)) {
6bbb92
-			/* overriding netname so MAC will be for old netdev */
6bbb92
-			memset(rec->iface.hwaddress, 0,
6bbb92
-				sizeof(rec->iface.hwaddress));
6bbb92
-		} else if (!strcmp(param->name, IFACE_HWADDR)) {
6bbb92
-			/* overriding MAC so netdev will be for old MAC */
6bbb92
-			memset(rec->iface.netdev, 0, sizeof(rec->iface.netdev));
6bbb92
-		} else if (!strcmp(param->name, IFACE_TRANSPORTNAME)) {
6bbb92
-			/*
6bbb92
-			 * switching drivers so all old binding info is no
6bbb92
-			 * longer valid. Old values were either for offload
6bbb92
-			 * and we are switching to software or the reverse,
6bbb92
-			 * or switching types of cards (bnx2i to cxgb3i).
6bbb92
-			 */
6bbb92
-			memset(&rec->iface, 0, sizeof(rec->iface));
6bbb92
-			iface_setup_defaults(&rec->iface);
6bbb92
-		}
6bbb92
-	}
6bbb92
-
6bbb92
-	rc = idbm_node_set_rec_from_param(&user_params, rec, 0);
6bbb92
-	if (rc)
6bbb92
-		return rc;
6bbb92
-
6bbb92
-	/*
6bbb92
-	 * For root boot we could not change this in older versions so
6bbb92
-	 * if user did not override then use the defaults.
6bbb92
-	 *
6bbb92
-	 * Increase to account for boot using static setup.
6bbb92
-	 */
6bbb92
-	if (rec->session.initial_login_retry_max == -1)
6bbb92
-		rec->session.initial_login_retry_max = 30;
6bbb92
-	/* we used to not be able to answer so turn off */
6bbb92
-	if (rec->conn[0].timeo.noop_out_interval == -1)
6bbb92
-		rec->conn[0].timeo.noop_out_interval = 0;
6bbb92
-	if (rec->conn[0].timeo.noop_out_timeout == -1)
6bbb92
-		rec->conn[0].timeo.noop_out_timeout = 0;
6bbb92
-
6bbb92
-	return 0;
6bbb92
-}
6bbb92
-
6bbb92
-static int parse_param(char *param_str)
6bbb92
-{
6bbb92
-	struct user_param *param;
6bbb92
-	char *name, *value;
6bbb92
-
6bbb92
-	name = param_str;
6bbb92
-
6bbb92
-	value = strchr(param_str, '=');
6bbb92
-	if (!value) {
6bbb92
-		log_error("Invalid --param %s. Missing value.", param_str);
6bbb92
-		return ISCSI_ERR_INVAL;
6bbb92
-	}
6bbb92
-	*value = '\0';
6bbb92
-
6bbb92
-	value++;
6bbb92
-	if (!strlen(value)) {
6bbb92
-		log_error("Invalid --param %s. Missing value.", param_str);
6bbb92
-		return ISCSI_ERR_INVAL;
6bbb92
-	}
6bbb92
-
6bbb92
-	param = idbm_alloc_user_param(name, value);
6bbb92
-	if (!param) {
6bbb92
-		log_error("Could not allocate memory for param.");
6bbb92
-		return ISCSI_ERR_NOMEM;
6bbb92
-	}
6bbb92
-
6bbb92
-	list_add(¶m->list, &user_params);
6bbb92
-	return 0;
6bbb92
-}
6bbb92
-
6bbb92
 static int login_session(struct node_rec *rec)
6bbb92
 {
6bbb92
 	iscsiadm_req_t req;
6bbb92
 	iscsiadm_rsp_t rsp;
6bbb92
 	int rc, retries = 0;
6bbb92
 
6bbb92
-	rc = apply_params(rec);
6bbb92
+	rc = apply_params(&user_params, rec);
6bbb92
 	if (rc)
6bbb92
 		return rc;
6bbb92
 
6bbb92
@@ -426,7 +341,7 @@ int main(int argc, char *argv[])
6bbb92
 			fw_free_targets(&targets);
6bbb92
 			exit(0);
6bbb92
 		case 'P':
6bbb92
-			err = parse_param(optarg);
6bbb92
+			err = parse_param(&user_params, optarg);
6bbb92
 			if (err)
6bbb92
 				exit(err);
6bbb92
 			break;
6bbb92
-- 
c2d5d2
1.8.1.4
6bbb92