From: Lucas De Marchi Date: Mon, 30 Jan 2012 18:26:52 +0000 (-0200) Subject: libkmod-module: probe: add flag to stop loading on already loaded X-Git-Tag: v5~36 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5f3514731ef82084c1a24b15445e0f1352681a19;p=thirdparty%2Fkmod.git 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. --- diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c index e1a04ba9..ff01cd89 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 b3771500..1873f1cc 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, }; /*