Whamcloud - gitweb
LU-1347 lvfs: makes EXPORT_SYMBOL follows function body
[fs/lustre-release.git] / lustre / lvfs / fsfilt.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  */
30 /*
31  * This file is part of Lustre, http://www.lustre.org/
32  * Lustre is a trademark of Sun Microsystems, Inc.
33  */
34
35 #ifndef EXPORT_SYMTAB
36 # define EXPORT_SYMTAB
37 #endif
38 #define DEBUG_SUBSYSTEM S_FILTER
39
40 #include <linux/fs.h>
41 #include <linux/jbd.h>
42 #include <linux/module.h>
43 #include <linux/kmod.h>
44 #include <linux/slab.h>
45 #include <libcfs/libcfs.h>
46 #include <lustre_fsfilt.h>
47
48 CFS_LIST_HEAD(fsfilt_types);
49
50 static struct fsfilt_operations *fsfilt_search_type(const char *type)
51 {
52         struct fsfilt_operations *found;
53         cfs_list_t *p;
54
55         cfs_list_for_each(p, &fsfilt_types) {
56                 found = cfs_list_entry(p, struct fsfilt_operations, fs_list);
57                 if (!strcmp(found->fs_type, type)) {
58                         return found;
59                 }
60         }
61         return NULL;
62 }
63
64 int fsfilt_register_ops(struct fsfilt_operations *fs_ops)
65 {
66         struct fsfilt_operations *found;
67
68         /* lock fsfilt_types list */
69         if ((found = fsfilt_search_type(fs_ops->fs_type))) {
70                 if (found != fs_ops) {
71                         CERROR("different operations for type %s\n",
72                                fs_ops->fs_type);
73                         /* unlock fsfilt_types list */
74                         RETURN(-EEXIST);
75                 }
76         } else {
77                 PORTAL_MODULE_USE;
78                 cfs_list_add(&fs_ops->fs_list, &fsfilt_types);
79         }
80
81         /* unlock fsfilt_types list */
82         return 0;
83 }
84 EXPORT_SYMBOL(fsfilt_register_ops);
85
86 void fsfilt_unregister_ops(struct fsfilt_operations *fs_ops)
87 {
88         cfs_list_t *p;
89
90         /* lock fsfilt_types list */
91         cfs_list_for_each(p, &fsfilt_types) {
92                 struct fsfilt_operations *found;
93
94                 found = cfs_list_entry(p, typeof(*found), fs_list);
95                 if (found == fs_ops) {
96                         cfs_list_del(p);
97                         PORTAL_MODULE_UNUSE;
98                         break;
99                 }
100         }
101         /* unlock fsfilt_types list */
102 }
103 EXPORT_SYMBOL(fsfilt_unregister_ops);
104
105 struct fsfilt_operations *fsfilt_get_ops(const char *type)
106 {
107         struct fsfilt_operations *fs_ops;
108
109         /* lock fsfilt_types list */
110         if (!(fs_ops = fsfilt_search_type(type))) {
111                 char name[32];
112                 int rc;
113
114                 snprintf(name, sizeof(name) - 1, "fsfilt_%s", type);
115                 name[sizeof(name) - 1] = '\0';
116
117                 if (!(rc = cfs_request_module("%s", name))) {
118                         fs_ops = fsfilt_search_type(type);
119                         CDEBUG(D_INFO, "Loaded module '%s'\n", name);
120                         if (!fs_ops)
121                                 rc = -ENOENT;
122                 }
123
124                 if (rc) {
125                         CERROR("Can't find %s interface\n", name);
126                         RETURN(ERR_PTR(rc < 0 ? rc : -rc));
127                         /* unlock fsfilt_types list */
128                 }
129         }
130         cfs_try_module_get(fs_ops->fs_owner);
131         /* unlock fsfilt_types list */
132
133         return fs_ops;
134 }
135 EXPORT_SYMBOL(fsfilt_get_ops);
136
137 void fsfilt_put_ops(struct fsfilt_operations *fs_ops)
138 {
139         cfs_module_put(fs_ops->fs_owner);
140 }
141 EXPORT_SYMBOL(fsfilt_put_ops);