summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Mackay <eric.mackay@oracle.com>2022-05-06 18:00:08 -0700
committerEric Mackay <eric.mackay@oracle.com>2022-05-18 17:41:42 -0700
commit10e3bf175bd8b1ad7f9c9900644a674b317e6428 (patch)
tree62a6f2a22008f29f1a9c07874c1be7b046abd1f5
parent433fad9ddadd62e5edf9597493f32a3b9443cc59 (diff)
downloadopen-iscsi-10e3bf175bd8b1ad7f9c9900644a674b317e6428.tar.gz
Use config for iscsistart and iscsiadm fw login
Specifying name-value pairs as arguments to iscsistart or iscsiadm can become unwieldy very quickly, and is less flexible than using a config file. If a user desires to update settings, modifying a config file and rebuilding initramfs can be simpler than modifying arguments directly in initramfs code or scripts. Node records created from boot context are populated with defaults, then any settings specified in a config file are applied (if config is present). FW and user-specified params are still applicable. User-specified name-value arguments are applied after config settings, so they can serve as a safeguard against config file changes if desired. Added -c|--config options for iscsistart to specify the config Updated iscsistart man page Signed-off-by: Eric Mackay <eric.mackay@oracle.com> Reviewed-by: Mike Christie <michael.christie@oracle.com>
-rw-r--r--doc/Makefile6
-rw-r--r--doc/iscsistart.8.template (renamed from doc/iscsistart.8)4
-rw-r--r--usr/idbm.c65
-rw-r--r--usr/iscsiadm.c8
-rw-r--r--usr/iscsistart.c23
5 files changed, 75 insertions, 31 deletions
diff --git a/doc/Makefile b/doc/Makefile
index 7267dfc..47e14a9 100644
--- a/doc/Makefile
+++ b/doc/Makefile
@@ -22,11 +22,11 @@ MAN8DIR = $(DESTDIR)$(mandir)/man8
MANPAGES_SOURCES = iscsi_discovery.8 \
iscsi_fw_login.8 \
- iscsi-iname.8 \
- iscsistart.8
+ iscsi-iname.8
MANPAGES_TEMPLATES = iscsid.8.template \
iscsiadm.8.template \
- iscsi-gen-initiatorname.8
+ iscsi-gen-initiatorname.8 \
+ iscsistart.8.template
MANPAGES_GENERATED = $(MANPAGES_TEMPLATES:.template=)
MANPAGES_DEST = $(addprefix $(MAN8DIR)/,$(MANPAGES_GENERATED)) \
$(addprefix $(MAN8DIR)/,$(MANPAGES_SOURCES))
diff --git a/doc/iscsistart.8 b/doc/iscsistart.8.template
index 5aa7dd4..62fae4d 100644
--- a/doc/iscsistart.8
+++ b/doc/iscsistart.8.template
@@ -12,6 +12,10 @@ not be run to manage sessions. Its primary use is to start
sessions used for iSCSI root boot.
.SH OPTIONS
.TP
+.BI [-c|--config=]\fIconfig\-file\fP
+Read configuration from \fIconfig\-file\fR rather than the default
+\fI@HOMEDIR@/iscsid.conf\fR file.
+.TP
.BI [-i|--initiatorname=]\fIname\fP
Set InitiatorName to name (Required if not using iBFT or OF)
.TP
diff --git a/usr/idbm.c b/usr/idbm.c
index 921dcad..90bc142 100644
--- a/usr/idbm.c
+++ b/usr/idbm.c
@@ -3055,6 +3055,32 @@ void idbm_terminate(void)
free(db);
}
+static bool idbm_populate_rec(struct node_rec *rec,
+ char *targetname, int tpgt, char *ip,
+ int port, struct iface_rec *iface,
+ int verbose)
+{
+ if (targetname)
+ strlcpy(rec->name, targetname, TARGET_NAME_MAXLEN);
+ rec->tpgt = tpgt;
+ rec->conn[0].port = port;
+ if (ip)
+ strlcpy(rec->conn[0].address, ip, NI_MAXHOST);
+ memset(&rec->iface, 0, sizeof(struct iface_rec));
+ if (iface) {
+ iface_copy(&rec->iface, iface);
+ if (strlen(iface->name)) {
+ if (iface_conf_read(&rec->iface)) {
+ if (verbose)
+ log_error("Could not read iface info "
+ "for %s.", iface->name);
+ return false;
+ }
+ }
+ }
+ return true;
+}
+
/**
* idbm_create_rec - allocate and setup a node record
* @targetname: target name
@@ -3081,23 +3107,9 @@ struct node_rec *idbm_create_rec(char *targetname, int tpgt, char *ip,
}
idbm_node_setup_defaults(rec);
- if (targetname)
- strlcpy(rec->name, targetname, TARGET_NAME_MAXLEN);
- rec->tpgt = tpgt;
- rec->conn[0].port = port;
- if (ip)
- strlcpy(rec->conn[0].address, ip, NI_MAXHOST);
- memset(&rec->iface, 0, sizeof(struct iface_rec));
- if (iface) {
- iface_copy(&rec->iface, iface);
- if (strlen(iface->name)) {
- if (iface_conf_read(&rec->iface)) {
- if (verbose)
- log_error("Could not read iface info "
- "for %s.", iface->name);
- goto free_rec;
- }
- }
+
+ if (!idbm_populate_rec(rec, targetname, tpgt, ip, port, iface, verbose)) {
+ goto free_rec;
}
return rec;
free_rec:
@@ -3107,14 +3119,23 @@ free_rec:
struct node_rec *idbm_create_rec_from_boot_context(struct boot_context *context)
{
- struct node_rec *rec;
+ node_rec_t *rec;
- /* tpgt hard coded to 1 ??? */
- rec = idbm_create_rec(context->targetname, 1,
- context->target_ipaddr, context->target_port,
- NULL, 1);
+ rec = malloc(sizeof(*rec));
if (!rec) {
+ log_error("Could not not allocate memory to create node "
+ "record.");
+ return NULL;
+ }
+
+ idbm_node_setup_from_conf(rec);
+
+ /* tpgt hard coded to 1 ??? */
+ if (!idbm_populate_rec(rec, context->targetname, 1,
+ context->target_ipaddr, context->target_port,
+ NULL, 1)) {
log_error("Could not setup rec for fw discovery login.");
+ free(rec);
return NULL;
}
diff --git a/usr/iscsiadm.c b/usr/iscsiadm.c
index 2a86068..11dea31 100644
--- a/usr/iscsiadm.c
+++ b/usr/iscsiadm.c
@@ -3864,11 +3864,6 @@ main(int argc, char **argv)
if (mode < 0)
usage(ISCSI_ERR_INVAL);
- if (mode == MODE_FW) {
- rc = exec_fw_op(NULL, NULL, info_level, do_login, op, wait, &params);
- goto out;
- }
-
increase_max_files();
if (idbm_init(get_config_file)) {
log_warning("exiting due to idbm configuration error");
@@ -3877,6 +3872,9 @@ main(int argc, char **argv)
}
switch (mode) {
+ case MODE_FW:
+ rc = exec_fw_op(NULL, NULL, info_level, do_login, op, wait, &params);
+ break;
case MODE_HOST:
if (sub_mode != -1) {
switch (sub_mode) {
diff --git a/usr/iscsistart.c b/usr/iscsistart.c
index 0fb1f56..546840f 100644
--- a/usr/iscsistart.c
+++ b/usr/iscsistart.c
@@ -61,11 +61,13 @@ static LIST_HEAD(targets);
static LIST_HEAD(user_params);
static char program_name[] = "iscsistart";
+static char config_file[TARGET_NAME_MAXLEN];
/* used by initiator */
extern struct iscsi_ipc *ipc;
static struct option const long_options[] = {
+ {"config", required_argument, NULL, 'c'},
{"initiatorname", required_argument, NULL, 'i'},
{"targetname", required_argument, NULL, 't'},
{"tgpt", required_argument, NULL, 'g'},
@@ -94,6 +96,7 @@ static void usage(int status)
printf("Usage: %s [OPTION]\n", program_name);
printf("\
Open-iSCSI initiator.\n\
+ -c, --config=[path] set config file (default " CONFIG_FILE ").\n\
-i, --initiatorname=name set InitiatorName to name (Required)\n\
-t, --targetname=name set TargetName to name (Required)\n\
-g, --tgpt=N set target portal group tag to N (Required)\n\
@@ -270,6 +273,11 @@ static int login_session(struct node_rec *rec)
return rc;
}
+static char *get_config_file(void)
+{
+ return config_file;
+}
+
static int setup_session(void)
{
struct boot_context *context;
@@ -278,6 +286,13 @@ static int setup_session(void)
if (list_empty(&targets))
return login_session(&config_rec);
+ increase_max_files();
+ if (idbm_init(get_config_file)) {
+ log_warning("exiting due to idbm configuration error");
+ rc = ISCSI_ERR_IDBM;
+ goto out;
+ }
+
list_for_each_entry(context, &targets, list) {
struct node_rec *rec;
@@ -297,6 +312,7 @@ static int setup_session(void)
free(rec);
}
fw_free_targets(&targets);
+out:
return rc;
}
@@ -357,6 +373,7 @@ int main(int argc, char *argv[])
int control_fd, mgmt_ipc_fd, err;
pid_t pid;
+ strcpy(config_file, CONFIG_FILE);
idbm_node_setup_defaults(&config_rec);
config_rec.name[0] = '\0';
config_rec.conn[0].address[0] = '\0';
@@ -373,9 +390,13 @@ int main(int argc, char *argv[])
sysfs_init();
- while ((ch = getopt_long(argc, argv, "P:i:t:g:a:p:d:u:w:U:W:bNfvh",
+ while ((ch = getopt_long(argc, argv, "c:P:i:t:g:a:p:d:u:w:U:W:bNfvh",
long_options, &longindex)) >= 0) {
switch (ch) {
+ case 'c':
+ strncpy(config_file, optarg, TARGET_NAME_MAXLEN);
+ config_file[TARGET_NAME_MAXLEN-1] = 0;
+ break;
case 'i':
initiatorname = optarg;
break;