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 (c) 2002, 2010, Oracle and/or its affiliates. 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/jbd.h>
44 #include <linux/module.h>
45 #include <linux/kmod.h>
46 #include <linux/slab.h>
47 #include <libcfs/libcfs.h>
48 #include <lustre_fsfilt.h>
50 CFS_LIST_HEAD(fsfilt_types);
52 static struct fsfilt_operations *fsfilt_search_type(const char *type)
54 struct fsfilt_operations *found;
57 cfs_list_for_each(p, &fsfilt_types) {
58 found = cfs_list_entry(p, struct fsfilt_operations, fs_list);
59 if (!strcmp(found->fs_type, type)) {
66 int fsfilt_register_ops(struct fsfilt_operations *fs_ops)
68 struct fsfilt_operations *found;
70 /* lock fsfilt_types list */
71 if ((found = fsfilt_search_type(fs_ops->fs_type))) {
72 if (found != fs_ops) {
73 CERROR("different operations for type %s\n",
75 /* unlock fsfilt_types list */
80 cfs_list_add(&fs_ops->fs_list, &fsfilt_types);
83 /* unlock fsfilt_types list */
87 void fsfilt_unregister_ops(struct fsfilt_operations *fs_ops)
91 /* lock fsfilt_types list */
92 cfs_list_for_each(p, &fsfilt_types) {
93 struct fsfilt_operations *found;
95 found = cfs_list_entry(p, typeof(*found), fs_list);
96 if (found == fs_ops) {
102 /* unlock fsfilt_types list */
105 struct fsfilt_operations *fsfilt_get_ops(const char *type)
107 struct fsfilt_operations *fs_ops;
109 /* lock fsfilt_types list */
110 if (!(fs_ops = fsfilt_search_type(type))) {
114 snprintf(name, sizeof(name) - 1, "fsfilt_%s", type);
115 name[sizeof(name) - 1] = '\0';
117 if (!(rc = cfs_request_module("%s", name))) {
118 fs_ops = fsfilt_search_type(type);
119 CDEBUG(D_INFO, "Loaded module '%s'\n", name);
125 CERROR("Can't find %s interface\n", name);
126 RETURN(ERR_PTR(rc < 0 ? rc : -rc));
127 /* unlock fsfilt_types list */
130 cfs_try_module_get(fs_ops->fs_owner);
131 /* unlock fsfilt_types list */
136 void fsfilt_put_ops(struct fsfilt_operations *fs_ops)
138 cfs_module_put(fs_ops->fs_owner);
142 EXPORT_SYMBOL(fsfilt_register_ops);
143 EXPORT_SYMBOL(fsfilt_unregister_ops);
144 EXPORT_SYMBOL(fsfilt_get_ops);
145 EXPORT_SYMBOL(fsfilt_put_ops);