]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
Implement function to remove module
authorLucas De Marchi <lucas.demarchi@profusion.mobi>
Wed, 23 Nov 2011 18:10:58 +0000 (16:10 -0200)
committerLucas De Marchi <lucas.demarchi@profusion.mobi>
Wed, 23 Nov 2011 19:14:22 +0000 (17:14 -0200)
libkmod/libkmod-loaded.c
libkmod/libkmod.h
libkmod/libkmod.sym

index 7d0e963b1da67464d1f5fa37156c5408d46ba397..af55386f3051e0e1d5da4dc4592f19c7163c7916 100644 (file)
@@ -226,3 +226,36 @@ KMOD_EXPORT int kmod_loaded_get_module_info(const struct kmod_list *entry,
 
        return 0;
 }
+
+extern long delete_module(const char *name, unsigned int flags);
+
+KMOD_EXPORT int kmod_loaded_remove_module(struct kmod_loaded *mod,
+                                               struct kmod_list *entry,
+                                               unsigned int flags)
+{
+       struct kmod_loaded_module *m;
+       int err;
+
+       if (mod == NULL)
+               return -ENOSYS;
+
+       if (entry == NULL)
+               return -ENOENT;
+
+       m = entry->data;
+
+       /* Filter out other flags */
+       flags &= (KMOD_REMOVE_FORCE | KMOD_REMOVE_NOWAIT);
+
+       err = delete_module(m->name, flags);
+       if (err != 0) {
+               err(mod->ctx, "Removing '%s': %s\n", m->name,
+                                                       strerror(-err));
+               return err;
+       }
+
+       loaded_modules_free_module(m);
+       kmod_list_remove(entry);
+
+       return 0;
+}
index f31820d52ddd9c4cf85d22b660f38f476d7f72d5..3f0b7920a46f7d459433e017b8d93cef367b1b40 100644 (file)
@@ -21,6 +21,7 @@
 #ifndef _LIBKMOD_H_
 #define _LIBKMOD_H_
 
+#include <fcntl.h>
 #include <stdarg.h>
 #include <inttypes.h>
 
@@ -74,4 +75,11 @@ int kmod_loaded_get_module_info(const struct kmod_list *entry,
                                const char **name, long *size, int *use_count,
                                const char **deps, uintptr_t *addr);
 
+enum KMOD_REMOVE {
+       KMOD_REMOVE_FORCE = O_TRUNC,
+       KMOD_REMOVE_NOWAIT = O_NONBLOCK,
+};
+
+int kmod_loaded_remove_module(struct kmod_loaded *kmod,
+                               struct kmod_list *entry, unsigned int flags);
 #endif
index 0482adafebfe4e6ecb138da9054de5450d5cc945..b22312d84d59ddb3c08ead0cda73829ee6aa8043 100644 (file)
@@ -15,6 +15,7 @@ global:
        kmod_loaded_unref;
        kmod_loaded_get_list;
        kmod_loaded_get_module_info;
+       kmod_loaded_remove_module;
 local:
         *;
 };