1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
38 # define EXPORT_SYMTAB
40 #define DEBUG_SUBSYSTEM S_FILTER
43 #include <linux/module.h>
44 #include <linux/kmod.h>
45 #include <linux/slab.h>
46 #include <libcfs/kp30.h>
47 #include <lustre_fsfilt.h>
49 LIST_HEAD(fsfilt_types);
51 static struct fsfilt_operations *fsfilt_search_type(const char *type)
53 struct fsfilt_operations *found;
56 list_for_each(p, &fsfilt_types) {
57 found = list_entry(p, struct fsfilt_operations, fs_list);
58 if (!strcmp(found->fs_type, type)) {
65 int fsfilt_register_ops(struct fsfilt_operations *fs_ops)
67 struct fsfilt_operations *found;
69 /* lock fsfilt_types list */
70 if ((found = fsfilt_search_type(fs_ops->fs_type))) {
71 if (found != fs_ops) {
72 CERROR("different operations for type %s\n",
74 /* unlock fsfilt_types list */
79 list_add(&fs_ops->fs_list, &fsfilt_types);
82 /* unlock fsfilt_types list */
86 void fsfilt_unregister_ops(struct fsfilt_operations *fs_ops)
90 /* lock fsfilt_types list */
91 list_for_each(p, &fsfilt_types) {
92 struct fsfilt_operations *found;
94 found = list_entry(p, typeof(*found), fs_list);
95 if (found == fs_ops) {
101 /* unlock fsfilt_types list */
104 struct fsfilt_operations *fsfilt_get_ops(const char *type)
106 struct fsfilt_operations *fs_ops;
108 /* lock fsfilt_types list */
109 if (!(fs_ops = fsfilt_search_type(type))) {
113 snprintf(name, sizeof(name) - 1, "fsfilt_%s", type);
114 name[sizeof(name) - 1] = '\0';
116 if (!(rc = request_module("%s", name))) {
117 fs_ops = fsfilt_search_type(type);
118 CDEBUG(D_INFO, "Loaded module '%s'\n", name);
124 CERROR("Can't find %s interface\n", name);
125 RETURN(ERR_PTR(rc < 0 ? rc : -rc));
126 /* unlock fsfilt_types list */
129 try_module_get(fs_ops->fs_owner);
130 /* unlock fsfilt_types list */
135 void fsfilt_put_ops(struct fsfilt_operations *fs_ops)
137 module_put(fs_ops->fs_owner);
141 EXPORT_SYMBOL(fsfilt_register_ops);
142 EXPORT_SYMBOL(fsfilt_unregister_ops);
143 EXPORT_SYMBOL(fsfilt_get_ops);
144 EXPORT_SYMBOL(fsfilt_put_ops);