summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Christie <michaelc@cs.wisc.edu>2012-03-21 03:24:09 -0500
committerMike Christie <michaelc@cs.wisc.edu>2012-03-22 00:02:33 -0400
commite37940f9fc21d745cfad8be6a727532b94b028ef (patch)
treed2a14c16ec7ba2be168086c986e837efd18ae8d1
parent4e8da605ea7855709b964dcbd72c6a39bd6cc8ec (diff)
downloadopen-iscsi-e37940f9fc21d745cfad8be6a727532b94b028ef.tar.gz
iscsi tools: check for loaded module before loading
No need to run modprobe if the module is already loaded.
-rw-r--r--usr/iscsi_sysfs.c20
-rw-r--r--usr/iscsi_sysfs.h1
-rw-r--r--usr/transport.c3
3 files changed, 22 insertions, 2 deletions
diff --git a/usr/iscsi_sysfs.c b/usr/iscsi_sysfs.c
index f56554e..123dde3 100644
--- a/usr/iscsi_sysfs.c
+++ b/usr/iscsi_sysfs.c
@@ -1150,6 +1150,23 @@ static uint32_t get_target_no_from_sid(uint32_t sid, int *err)
}
+int iscsi_sysfs_is_transport_loaded(char *transport_name)
+{
+ struct iscsi_transport *t;
+
+ /* sync up kernel and userspace */
+ read_transports();
+
+ /* check if the transport is loaded and matches */
+ list_for_each_entry(t, &transports, list) {
+ if (t->handle && !strncmp(t->name, transport_name,
+ ISCSI_TRANSPORT_NAME_MAXLEN))
+ return 1;
+ }
+
+ return 0;
+}
+
struct iscsi_transport *iscsi_sysfs_get_transport_by_name(char *transport_name)
{
struct iscsi_transport *t;
@@ -1157,8 +1174,7 @@ struct iscsi_transport *iscsi_sysfs_get_transport_by_name(char *transport_name)
retry:
/* sync up kernel and userspace */
- if (read_transports())
- return NULL;
+ read_transports();
/* check if the transport is loaded and matches */
list_for_each_entry(t, &transports, list) {
diff --git a/usr/iscsi_sysfs.h b/usr/iscsi_sysfs.h
index bae52b0..2b15d78 100644
--- a/usr/iscsi_sysfs.h
+++ b/usr/iscsi_sysfs.h
@@ -88,6 +88,7 @@ extern struct iscsi_transport *iscsi_sysfs_get_transport_by_hba(uint32_t host_no
extern struct iscsi_transport *iscsi_sysfs_get_transport_by_session(char *sys_session);
extern struct iscsi_transport *iscsi_sysfs_get_transport_by_sid(uint32_t sid);
extern struct iscsi_transport *iscsi_sysfs_get_transport_by_name(char *transport_name);
+extern int iscsi_sysfs_is_transport_loaded(char *transport_name);
extern int iscsi_sysfs_session_supports_nop(int sid);
extern int iscsi_sysfs_session_user_created(int sid);
diff --git a/usr/transport.c b/usr/transport.c
index 80216a2..236ce2b 100644
--- a/usr/transport.c
+++ b/usr/transport.c
@@ -226,6 +226,9 @@ int transport_load_kmod(char *transport_name)
else
cmdline[2] = transport_name;
+ if (iscsi_sysfs_is_transport_loaded(cmdline[2]))
+ return 0;
+
pid = fork();
if (pid == 0) {
if (execv("/sbin/modprobe", cmdline) < 0) {