From: Lucas De Marchi Date: Fri, 20 Sep 2013 06:30:07 +0000 (-0500) Subject: libkmod: always pass O_NONBLOCK to kernel X-Git-Tag: v16~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7ab8804448377fb6b8854f2dd288608db01bb43b;p=thirdparty%2Fkmod.git libkmod: always pass O_NONBLOCK to kernel Not passsing O_NONBLOCK to delete_module() is deprecated since kmod 11 and is being removed from the kernel. Force this flag in libkmod. --- diff --git a/NEWS b/NEWS index 8260183f..e028cff5 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,11 @@ +kmod 16 +======= + +- New features: + - Remove option from libkmod to allow waiting on module removal if + the module is being used. It's dangerous since it can block the + caller indefinitely. + kmod 15 ======= @@ -82,7 +90,7 @@ kmod 11 benefits. - Hide --wait option on rmmod. This feature is being targeted for removal from kernel. rmmod still accepts this option, but it's hidden - now: man page and usage() says nothing about it and if it's used, + now: man page and usage() say nothing about it and if it's used, user will get a 10s sleep. This way we can check and help if anyone is using this feature. - Refactor message logging on all tools, giving proper prefix, routing diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c index 38741941..3adbb69d 100644 --- a/libkmod/libkmod-module.c +++ b/libkmod/libkmod-module.c @@ -738,15 +738,11 @@ extern long delete_module(const char *name, unsigned int flags); /** * kmod_module_remove_module: * @mod: kmod module - * @flags: flags to pass to Linux kernel when removing the module, valid flags are + * @flags: flags to pass to Linux kernel when removing the module. The only valid flag is * KMOD_REMOVE_FORCE: force remove module regardless if it's still in * use by a kernel subsystem or other process; - * KMOD_REMOVE_NOWAIT: return immediately. It will fail if the module - * is in using and KMOD_REMOVE_FORCE is not specified. - * If this module is in use by any kernel subsystem or process, not using - * this flag will cause the call to block indefinitely, until the module - * is not in use anymore. Always use this flag, it's deprecated not using - * it and the default behavior might change in future to always set it. + * KMOD_REMOVE_NOWAIT is always enforced, causing us to pass O_NONBLOCK to + * delete_module(2). * * Remove a module from Linux kernel. * @@ -760,8 +756,9 @@ KMOD_EXPORT int kmod_module_remove_module(struct kmod_module *mod, if (mod == NULL) return -ENOENT; - /* Filter out other flags */ - flags &= (KMOD_REMOVE_FORCE | KMOD_REMOVE_NOWAIT); + /* Filter out other flags and force ONONBLOCK */ + flags &= KMOD_REMOVE_FORCE; + flags |= KMOD_REMOVE_NOWAIT; err = delete_module(mod->name, flags); if (err != 0) { diff --git a/libkmod/libkmod.h b/libkmod/libkmod.h index 3397f87e..a7ea2216 100644 --- a/libkmod/libkmod.h +++ b/libkmod/libkmod.h @@ -140,7 +140,7 @@ struct kmod_module *kmod_module_get_module(const struct kmod_list *entry); /* Removal flags */ enum kmod_remove { KMOD_REMOVE_FORCE = O_TRUNC, - KMOD_REMOVE_NOWAIT = O_NONBLOCK, + KMOD_REMOVE_NOWAIT = O_NONBLOCK, /* always set */ }; /* Insertion flags */