From c76e8a9aa0eb154c782c2eb7a746d6a5b63a7d4c Mon Sep 17 00:00:00 2001 From: Edward Tomasz Napierala Date: Wed, 18 Sep 2013 08:37:14 +0000 Subject: [PATCH] Make iscsictl(8) automatically try to load the iscsi module. While here, improve module loading in iscsid(8) and ctld(8). Approved by: re (delphij) --- usr.bin/iscsictl/iscsictl.c | 12 +++++++++++- usr.sbin/ctld/kernel.c | 2 +- usr.sbin/iscsid/iscsid.c | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/usr.bin/iscsictl/iscsictl.c b/usr.bin/iscsictl/iscsictl.c index ff37c127ed7c..1088d69f03e7 100644 --- a/usr.bin/iscsictl/iscsictl.c +++ b/usr.bin/iscsictl/iscsictl.c @@ -30,6 +30,8 @@ */ #include +#include +#include #include #include #include @@ -512,7 +514,7 @@ main(int argc, char **argv) const char *conf_path = DEFAULT_CONFIG_PATH; char *nickname = NULL, *discovery_host = NULL, *host = NULL, *target = NULL, *user = NULL, *secret = NULL; - int ch, error, iscsi_fd; + int ch, error, iscsi_fd, retval, saved_errno; int failed = 0; struct conf *conf; struct target *targ; @@ -672,6 +674,14 @@ main(int argc, char **argv) } iscsi_fd = open(ISCSI_PATH, O_RDWR); + if (iscsi_fd < 0 && errno == ENOENT) { + saved_errno = errno; + retval = kldload("iscsi"); + if (retval != -1) + iscsi_fd = open(ISCSI_PATH, O_RDWR); + else + errno = saved_errno; + } if (iscsi_fd < 0) err(1, "failed to open %s", ISCSI_PATH); diff --git a/usr.sbin/ctld/kernel.c b/usr.sbin/ctld/kernel.c index 50ddc0c8387d..869d0a05804c 100644 --- a/usr.sbin/ctld/kernel.c +++ b/usr.sbin/ctld/kernel.c @@ -79,7 +79,7 @@ kernel_init(void) int retval, saved_errno; ctl_fd = open(CTL_DEFAULT_DEV, O_RDWR); - if (ctl_fd < 0) { + if (ctl_fd < 0 && errno == ENOENT) { saved_errno = errno; retval = kldload("ctl"); if (retval != -1) diff --git a/usr.sbin/iscsid/iscsid.c b/usr.sbin/iscsid/iscsid.c index 56733c1cfe03..0547465c2f8f 100644 --- a/usr.sbin/iscsid/iscsid.c +++ b/usr.sbin/iscsid/iscsid.c @@ -509,7 +509,7 @@ main(int argc, char **argv) } iscsi_fd = open(ISCSI_PATH, O_RDWR); - if (iscsi_fd < 0) { + if (iscsi_fd < 0 && errno == ENOENT) { saved_errno = errno; retval = kldload("iscsi"); if (retval != -1)