summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLucas De Marchi <lucas.demarchi@profusion.mobi>2012-01-30 16:26:52 -0200
committerLucas De Marchi <lucas.demarchi@profusion.mobi>2012-01-30 20:05:34 -0200
commit5f3514731ef82084c1a24b15445e0f1352681a19 (patch)
tree4e1542cb7b5bec139718abe1888ef74b824c6bf7
parentdfdfb962d3e204972facc8439239e258b7d59420 (diff)
downloadkmod-5f3514731ef82084c1a24b15445e0f1352681a19.tar.gz
kmod-5f3514731ef82084c1a24b15445e0f1352681a19.zip
libkmod-module: probe: add flag to stop loading on already loaded
It's not as simple as tell user to check if the module is loaded before calling this function. Due to race conditions, module might not be loaded before the function call, but fail later because another process inserted it.
-rw-r--r--libkmod/libkmod-module.c23
-rw-r--r--libkmod/libkmod.h1
2 files changed, 20 insertions, 4 deletions
diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c
index e1a04ba..ff01cd8 100644
--- a/libkmod/libkmod-module.c
+++ b/libkmod/libkmod-module.c
@@ -1168,6 +1168,11 @@ KMOD_EXPORT int kmod_module_probe_insert_module(struct kmod_module *mod,
if (state == KMOD_MODULE_LIVE ||
state == KMOD_MODULE_COMING ||
state == KMOD_MODULE_BUILTIN) {
+ if (m == mod && (flags & KMOD_PROBE_STOP_ON_ALREADY_LOADED)) {
+ err = KMOD_PROBE_STOP_ON_ALREADY_LOADED;
+ break;
+ }
+
DBG(mod->ctx, "Ignoring '%s': "
"module already loaded\n", m->name);
free(options);
@@ -1179,11 +1184,21 @@ KMOD_EXPORT int kmod_module_probe_insert_module(struct kmod_module *mod,
free(options);
/*
- * Ignore "already loaded" error. We need to check here
- * because of race conditions. We checked first if module was
- * already loaded but it may have been loaded between the
- * check and the moment we try to insert it.
+ * Treat "already loaded" error. If we were told to stop on
+ * already loaded and the module being loaded is not a
+ * softdep, bail out. Otherwise, just ignore and continue.
+ *
+ * We need to check here because of race conditions. We
+ * checked first if module was already loaded but it may have
+ * been loaded between the check and the moment we try to
+ * insert it.
*/
+ if (err == -EEXIST && m == mod &&
+ (flags & KMOD_PROBE_STOP_ON_ALREADY_LOADED)) {
+ err = KMOD_PROBE_STOP_ON_ALREADY_LOADED;
+ break;
+ }
+
if (err < 0 && err != -EEXIST &&
(flags & KMOD_PROBE_STOP_ON_DEP_FAILURE))
break;
diff --git a/libkmod/libkmod.h b/libkmod/libkmod.h
index b377150..1873f1c 100644
--- a/libkmod/libkmod.h
+++ b/libkmod/libkmod.h
@@ -134,6 +134,7 @@ enum kmod_probe {
KMOD_PROBE_STOP_ON_DEP_FAILURE = 0x0F,
KMOD_PROBE_STOP_ON_COMMAND = 0x10,
KMOD_PROBE_IGNORE_COMMAND = 0x20,
+ KMOD_PROBE_STOP_ON_ALREADY_LOADED = 0x30,
};
/*