target: Fix target_core_register_fabric() for built-in fabric modules
authorRoland Dreier <roland@purestorage.com>
Fri, 14 Nov 2014 20:54:36 +0000 (12:54 -0800)
committerNicholas Bellinger <nab@linux-iscsi.org>
Tue, 2 Dec 2014 05:35:13 +0000 (21:35 -0800)
If we try to create a fabric directory in configfs for one of the
default hard-coded fabric modules (iscsi and loopback), and that
fabric is actually built into the kernel, then the operation will
spuriously fail because request_module() (for the code that's already
linked into the kernel) fails.

Fix this by running the autoprobing code only if an initial
target_core_get_fabric() fails.

Signed-off-by: Roland Dreier <roland@purestorage.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
drivers/target/target_core_configfs.c

index 79f9296..41498b6 100644 (file)
@@ -126,48 +126,57 @@ static struct config_group *target_core_register_fabric(
 
        pr_debug("Target_Core_ConfigFS: REGISTER -> group: %p name:"
                        " %s\n", group, name);
-       /*
-        * Below are some hardcoded request_module() calls to automatically
-        * local fabric modules when the following is called:
-        *
-        * mkdir -p /sys/kernel/config/target/$MODULE_NAME
-        *
-        * Note that this does not limit which TCM fabric module can be
-        * registered, but simply provids auto loading logic for modules with
-        * mkdir(2) system calls with known TCM fabric modules.
-        */
-       if (!strncmp(name, "iscsi", 5)) {
+
+       tf = target_core_get_fabric(name);
+       if (!tf) {
+               pr_err("target_core_register_fabric() trying autoload for %s\n",
+                       name);
+
                /*
-                * Automatically load the LIO Target fabric module when the
-                * following is called:
+                * Below are some hardcoded request_module() calls to automatically
+                * local fabric modules when the following is called:
                 *
-                * mkdir -p $CONFIGFS/target/iscsi
-                */
-               ret = request_module("iscsi_target_mod");
-               if (ret < 0) {
-                       pr_err("request_module() failed for"
-                               " iscsi_target_mod.ko: %d\n", ret);
-                       return ERR_PTR(-EINVAL);
-               }
-       } else if (!strncmp(name, "loopback", 8)) {
-               /*
-                * Automatically load the tcm_loop fabric module when the
-                * following is called:
+                * mkdir -p /sys/kernel/config/target/$MODULE_NAME
                 *
-                * mkdir -p $CONFIGFS/target/loopback
+                * Note that this does not limit which TCM fabric module can be
+                * registered, but simply provids auto loading logic for modules with
+                * mkdir(2) system calls with known TCM fabric modules.
                 */
-               ret = request_module("tcm_loop");
-               if (ret < 0) {
-                       pr_err("request_module() failed for"
-                               " tcm_loop.ko: %d\n", ret);
-                       return ERR_PTR(-EINVAL);
+
+               if (!strncmp(name, "iscsi", 5)) {
+                       /*
+                        * Automatically load the LIO Target fabric module when the
+                        * following is called:
+                        *
+                        * mkdir -p $CONFIGFS/target/iscsi
+                        */
+                       ret = request_module("iscsi_target_mod");
+                       if (ret < 0) {
+                               pr_err("request_module() failed for"
+                                      " iscsi_target_mod.ko: %d\n", ret);
+                               return ERR_PTR(-EINVAL);
+                       }
+               } else if (!strncmp(name, "loopback", 8)) {
+                       /*
+                        * Automatically load the tcm_loop fabric module when the
+                        * following is called:
+                        *
+                        * mkdir -p $CONFIGFS/target/loopback
+                        */
+                       ret = request_module("tcm_loop");
+                       if (ret < 0) {
+                               pr_err("request_module() failed for"
+                                      " tcm_loop.ko: %d\n", ret);
+                               return ERR_PTR(-EINVAL);
+                       }
                }
+
+               tf = target_core_get_fabric(name);
        }
 
-       tf = target_core_get_fabric(name);
        if (!tf) {
                pr_err("target_core_get_fabric() failed for %s\n",
-                       name);
+                      name);
                return ERR_PTR(-EINVAL);
        }
        pr_debug("Target_Core_ConfigFS: REGISTER -> Located fabric:"