4 #define DEBUG_SUBSYSTEM S_FILTER
8 #include <linux/module.h>
9 #include <linux/kmod.h>
10 #include <linux/slab.h>
11 #include <libcfs/kp30.h>
12 #include <lustre_fsfilt.h>
14 CFS_LIST_HEAD(fsfilt_types);
16 static struct fsfilt_operations *fsfilt_search_type(const char *type)
18 struct fsfilt_operations *found;
21 list_for_each(p, &fsfilt_types) {
22 found = list_entry(p, struct fsfilt_operations, fs_list);
23 if (!strcmp(found->fs_type, type)) {
30 int fsfilt_register_ops(struct fsfilt_operations *fs_ops)
32 struct fsfilt_operations *found;
34 /* lock fsfilt_types list */
35 if ((found = fsfilt_search_type(fs_ops->fs_type))) {
36 if (found != fs_ops) {
37 CERROR("different operations for type %s\n",
39 /* unlock fsfilt_types list */
44 list_add(&fs_ops->fs_list, &fsfilt_types);
47 /* unlock fsfilt_types list */
51 void fsfilt_unregister_ops(struct fsfilt_operations *fs_ops)
55 /* lock fsfilt_types list */
56 list_for_each(p, &fsfilt_types) {
57 struct fsfilt_operations *found;
59 found = list_entry(p, typeof(*found), fs_list);
60 if (found == fs_ops) {
66 /* unlock fsfilt_types list */
69 struct fsfilt_operations *fsfilt_get_ops(const char *type)
71 struct fsfilt_operations *fs_ops;
73 /* lock fsfilt_types list */
74 if (!(fs_ops = fsfilt_search_type(type))) {
78 snprintf(name, sizeof(name) - 1, "fsfilt_%s", type);
79 name[sizeof(name) - 1] = '\0';
81 if (!(rc = request_module(name))) {
82 fs_ops = fsfilt_search_type(type);
83 CDEBUG(D_INFO, "Loaded module '%s'\n", name);
89 CERROR("Can't find %s interface\n", name);
90 RETURN(ERR_PTR(rc < 0 ? rc : -rc));
91 /* unlock fsfilt_types list */
94 try_module_get(fs_ops->fs_owner);
95 /* unlock fsfilt_types list */
100 void fsfilt_put_ops(struct fsfilt_operations *fs_ops)
102 module_put(fs_ops->fs_owner);
106 EXPORT_SYMBOL(fsfilt_register_ops);
107 EXPORT_SYMBOL(fsfilt_unregister_ops);
108 EXPORT_SYMBOL(fsfilt_get_ops);
109 EXPORT_SYMBOL(fsfilt_put_ops);