staging: lustre: remove top level ccflags variable
[deliverable/linux.git] / drivers / staging / lustre / lustre / lvfs / fsfilt.c
CommitLineData
d7e09d03
PT
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#define DEBUG_SUBSYSTEM S_FILTER
36
37#include <linux/fs.h>
d7e09d03
PT
38#include <linux/module.h>
39#include <linux/kmod.h>
40#include <linux/slab.h>
9fdaf8c0 41#include "../../include/linux/libcfs/libcfs.h"
d7e09d03
PT
42#include <lustre_fsfilt.h>
43
44LIST_HEAD(fsfilt_types);
45
46static struct fsfilt_operations *fsfilt_search_type(const char *type)
47{
48 struct fsfilt_operations *found;
49 struct list_head *p;
50
51 list_for_each(p, &fsfilt_types) {
52 found = list_entry(p, struct fsfilt_operations, fs_list);
497aaa5c 53 if (!strcmp(found->fs_type, type))
d7e09d03 54 return found;
d7e09d03
PT
55 }
56 return NULL;
57}
58
59int fsfilt_register_ops(struct fsfilt_operations *fs_ops)
60{
61 struct fsfilt_operations *found;
62
63 /* lock fsfilt_types list */
3e67cdf5
JB
64 found = fsfilt_search_type(fs_ops->fs_type);
65 if (found) {
d7e09d03
PT
66 if (found != fs_ops) {
67 CERROR("different operations for type %s\n",
68 fs_ops->fs_type);
69 /* unlock fsfilt_types list */
0a3bdb00 70 return -EEXIST;
d7e09d03
PT
71 }
72 } else {
73 try_module_get(THIS_MODULE);
74 list_add(&fs_ops->fs_list, &fsfilt_types);
75 }
76
77 /* unlock fsfilt_types list */
78 return 0;
79}
80EXPORT_SYMBOL(fsfilt_register_ops);
81
82void fsfilt_unregister_ops(struct fsfilt_operations *fs_ops)
83{
84 struct list_head *p;
85
86 /* lock fsfilt_types list */
87 list_for_each(p, &fsfilt_types) {
88 struct fsfilt_operations *found;
89
90 found = list_entry(p, typeof(*found), fs_list);
91 if (found == fs_ops) {
92 list_del(p);
93 module_put(THIS_MODULE);
94 break;
95 }
96 }
97 /* unlock fsfilt_types list */
98}
99EXPORT_SYMBOL(fsfilt_unregister_ops);
100
101struct fsfilt_operations *fsfilt_get_ops(const char *type)
102{
103 struct fsfilt_operations *fs_ops;
104
105 /* lock fsfilt_types list */
3e67cdf5
JB
106 fs_ops = fsfilt_search_type(type);
107 if (!fs_ops) {
d7e09d03
PT
108 char name[32];
109 int rc;
110
111 snprintf(name, sizeof(name) - 1, "fsfilt_%s", type);
112 name[sizeof(name) - 1] = '\0';
113
3e67cdf5
JB
114 rc = request_module("%s", name);
115 if (!rc) {
d7e09d03
PT
116 fs_ops = fsfilt_search_type(type);
117 CDEBUG(D_INFO, "Loaded module '%s'\n", name);
118 if (!fs_ops)
119 rc = -ENOENT;
120 }
121
122 if (rc) {
123 CERROR("Can't find %s interface\n", name);
0a3bdb00 124 return ERR_PTR(rc < 0 ? rc : -rc);
d7e09d03
PT
125 /* unlock fsfilt_types list */
126 }
127 }
128 try_module_get(fs_ops->fs_owner);
129 /* unlock fsfilt_types list */
130
131 return fs_ops;
132}
133EXPORT_SYMBOL(fsfilt_get_ops);
134
135void fsfilt_put_ops(struct fsfilt_operations *fs_ops)
136{
137 module_put(fs_ops->fs_owner);
138}
139EXPORT_SYMBOL(fsfilt_put_ops);
This page took 0.163745 seconds and 5 git commands to generate.