Skip to contentSkip to conversation

master - modprobe: check /sys/module entry first

PATCH Zdenek Kabelac 1 participant 1 message Apr 26, 2016

lore
Share & tools
lore
#0 lore raw
Gitweb:        http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=aa91fe3d3c3e6c2d8d96f5c0766b58375a44daa9
Commit:        aa91fe3d3c3e6c2d8d96f5c0766b58375a44daa9
Parent:        ecae76c713bd4fa6c9d8f2a2c990625e4f38b504
Author:        Zdenek Kabelac <[email protected]>
AuthorDate:    Tue Apr 26 21:41:04 2016 +0200
Committer:     Zdenek Kabelac <[email protected]>
CommitterDate: Tue Apr 26 23:23:03 2016 +0200

modprobe: check /sys/module entry first

Before executing modprobe for given module name, just check if the module is not already present in /sys/module.

Useful when checking dm-cache-policy modules as we do not having matching interface like for targets.

---
 WHATS_NEW               |    1 +
 lib/activate/activate.c |   17 +++++++++++++++++
 2 files changed, 18 insertions(+), 0 deletions(-)
WHATS_NEW +1 -0
index 1aa335e..2a4fdd5 100644
@@ -1,5 +1,6 @@
 Version 2.02.152 - 
 ==================================
+  Check first /sys/module/dm_* dir existance before using modprobe.
   Remove mpath from 10-dm.rules, superseded by 11-dm-mpath.rules (mpath>=0.6.0).
 
 Version 2.02.151 - 23rd April 2016
lib/activate/activate.c +17 -0
index 76afc3d..f554f19 100644
@@ -603,7 +603,24 @@ int module_present(struct cmd_context *cmd, const char *target_name)
 #ifdef MODPROBE_CMD
 	char module[128];
 	const char *argv[] = { MODPROBE_CMD, module, NULL };
+#endif
+	struct stat st;
+	char path[PATH_MAX];
+	int i = dm_snprintf(path, (sizeof(path) - 1), "%smodule/dm_%s",
+			    dm_sysfs_dir(), target_name);
+
+	if (i > 0) {
+		while (path[--i] != '/')  /* stop on dm_ */
+			if (path[i] == '-')
+				path[i] = '_'; /* replace '-' with '_' */
+
+		if ((lstat(path, &st) == 0) && S_ISDIR(st.st_mode)) {
+			log_debug("Module directory %s exists.", path);
+			return 1;
+		}
+	}
 
+#ifdef MODPROBE_CMD
 	if (dm_snprintf(module, sizeof(module), "dm-%s", target_name) < 0) {
 		log_error("module_present module name too long: %s",
 			  target_name);