Implement function to remove module

This commit is contained in:
Lucas De Marchi 2011-11-23 16:10:58 -02:00
parent 6ad9830731
commit 6806a0437f
3 changed files with 42 additions and 0 deletions

View 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;
}

View 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

View File

@ -15,6 +15,7 @@ global:
kmod_loaded_unref;
kmod_loaded_get_list;
kmod_loaded_get_module_info;
kmod_loaded_remove_module;
local:
*;
};