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