diff options
author | Lucas De Marchi <lucas.de.marchi@gmail.com> | 2022-06-03 14:50:41 -0700 |
---|---|---|
committer | Lucas De Marchi <lucas.de.marchi@gmail.com> | 2022-06-26 23:23:46 -0700 |
commit | 3a92fc63098571bcf259ffe37cd1fdf69429e4af (patch) | |
tree | 253cc99ea02f82e116edf5cf51c239c1e7f36350 | |
parent | 081fff2c678cc1b1da1034f638bf5373b35188d5 (diff) | |
download | kmod-3a92fc63098571bcf259ffe37cd1fdf69429e4af.tar.gz kmod-3a92fc63098571bcf259ffe37cd1fdf69429e4af.tar.bz2 kmod-3a92fc63098571bcf259ffe37cd1fdf69429e4af.zip |
libkmod: Allow to ignore log message on module removal
Caller may want to handle retries, in which case the log message is not
appropriate.
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
-rw-r--r-- | libkmod/libkmod-module.c | 13 | ||||
-rw-r--r-- | libkmod/libkmod.h | 2 |
2 files changed, 11 insertions, 4 deletions
diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c index efdd679..12d8ed1 100644 --- a/libkmod/libkmod-module.c +++ b/libkmod/libkmod-module.c @@ -823,11 +823,13 @@ 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. The only valid flag is + * @flags: flags used when removing the module. * KMOD_REMOVE_FORCE: force remove module regardless if it's still in - * use by a kernel subsystem or other process; - * KMOD_REMOVE_NOWAIT is always enforced, causing us to pass O_NONBLOCK to + * use by a kernel subsystem or other process; passed directly to Linux kernel + * KMOD_REMOVE_NOWAIT: is always enforced, causing us to pass O_NONBLOCK to * delete_module(2). + * KMOD_REMOVE_NOLOG: when module removal fails, do not log anything as the + * caller may want to handle retries and log when appropriate. * * Remove a module from Linux kernel. * @@ -836,6 +838,8 @@ extern long delete_module(const char *name, unsigned int flags); KMOD_EXPORT int kmod_module_remove_module(struct kmod_module *mod, unsigned int flags) { + unsigned int libkmod_flags = flags & 0xff; + int err; if (mod == NULL) @@ -848,7 +852,8 @@ KMOD_EXPORT int kmod_module_remove_module(struct kmod_module *mod, err = delete_module(mod->name, flags); if (err != 0) { err = -errno; - ERR(mod->ctx, "could not remove '%s': %m\n", mod->name); + if (!(libkmod_flags & KMOD_REMOVE_NOLOG)) + ERR(mod->ctx, "could not remove '%s': %m\n", mod->name); } return err; diff --git a/libkmod/libkmod.h b/libkmod/libkmod.h index fed216b..7251aa7 100644 --- a/libkmod/libkmod.h +++ b/libkmod/libkmod.h @@ -145,6 +145,8 @@ struct kmod_module *kmod_module_get_module(const struct kmod_list *entry); enum kmod_remove { KMOD_REMOVE_FORCE = O_TRUNC, KMOD_REMOVE_NOWAIT = O_NONBLOCK, /* always set */ + /* libkmod-only defines, not passed to kernel */ + KMOD_REMOVE_NOLOG = 1, }; /* Insertion flags */ |