2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
7 * of the GNU General Public License v.2.
10 #include <linux/module.h>
11 #include <linux/init.h>
12 #include <linux/string.h>
13 #include <linux/slab.h>
14 #include <linux/wait.h>
15 #include <linux/sched.h>
16 #include <linux/kmod.h>
18 #include <linux/delay.h>
20 #include "lm_interface.h"
23 struct list_head lw_list;
24 struct lm_lockops *lw_ops;
27 /* List of registered low-level locking protocols. A file system selects one
28 of them by name at mount time, e.g. lock_nolock, lock_dlm. */
30 static struct list_head lmh_list;
31 static struct semaphore lmh_lock;
34 * gfs_register_lockproto - Register a low-level locking protocol
35 * @proto: the protocol definition
37 * Returns: 0 on success, -EXXX on failure
40 int gfs_register_lockproto(struct lm_lockops *proto)
42 struct lmh_wrapper *lw;
46 list_for_each_entry(lw, &lmh_list, lw_list) {
47 if (!strcmp(lw->lw_ops->lm_proto_name, proto->lm_proto_name)) {
49 printk("GFS2: protocol %s already exists\n",
50 proto->lm_proto_name);
55 lw = kmalloc(sizeof(struct lmh_wrapper), GFP_KERNEL);
60 memset(lw, 0, sizeof(struct lmh_wrapper));
63 list_add(&lw->lw_list, &lmh_list);
71 * gfs_unregister_lockproto - Unregister a low-level locking protocol
72 * @proto: the protocol definition
76 void gfs_unregister_lockproto(struct lm_lockops *proto)
78 struct lmh_wrapper *lw;
82 list_for_each_entry(lw, &lmh_list, lw_list) {
83 if (!strcmp(lw->lw_ops->lm_proto_name, proto->lm_proto_name)) {
84 list_del(&lw->lw_list);
93 printk("GFS2: can't unregister lock protocol %s\n",
94 proto->lm_proto_name);
98 * gfs2_mount_lockproto - Mount a lock protocol
99 * @proto_name - the name of the protocol
100 * @table_name - the name of the lock space
101 * @host_data - data specific to this host
102 * @cb - the callback to the code using the lock module
103 * @fsdata - data to pass back with the callback
104 * @min_lvb_size - the mininum LVB size that the caller can deal with
105 * @flags - LM_MFLAG_*
106 * @lockstruct - a structure returned describing the mount
108 * Returns: 0 on success, -EXXX on failure
111 int gfs2_mount_lockproto(char *proto_name, char *table_name, char *host_data,
112 lm_callback_t cb, lm_fsdata_t *fsdata,
113 unsigned int min_lvb_size, int flags,
114 struct lm_lockstruct *lockstruct,
115 struct kobject *fskobj)
117 struct lmh_wrapper *lw = NULL;
125 list_for_each_entry(lw, &lmh_list, lw_list) {
126 if (!strcmp(lw->lw_ops->lm_proto_name, proto_name)) {
133 if (!try && capable(CAP_SYS_MODULE)) {
136 request_module(proto_name);
139 printk("GFS2: can't find protocol %s\n", proto_name);
144 if (!try_module_get(lw->lw_ops->lm_owner)) {
151 error = lw->lw_ops->lm_mount(table_name, host_data, cb, fsdata,
152 min_lvb_size, flags, lockstruct, fskobj);
154 module_put(lw->lw_ops->lm_owner);
160 void gfs2_unmount_lockproto(struct lm_lockstruct *lockstruct)
163 lockstruct->ls_ops->lm_unmount(lockstruct->ls_lockspace);
164 if (lockstruct->ls_ops->lm_owner)
165 module_put(lockstruct->ls_ops->lm_owner);
170 * gfs2_withdraw_lockproto - abnormally unmount a lock module
171 * @lockstruct: the lockstruct passed into mount
175 void gfs2_withdraw_lockproto(struct lm_lockstruct *lockstruct)
178 lockstruct->ls_ops->lm_withdraw(lockstruct->ls_lockspace);
179 if (lockstruct->ls_ops->lm_owner)
180 module_put(lockstruct->ls_ops->lm_owner);
184 void __init gfs2_init_lmh(void)
186 init_MUTEX(&lmh_lock);
187 INIT_LIST_HEAD(&lmh_list);
190 EXPORT_SYMBOL_GPL(gfs_register_lockproto);
191 EXPORT_SYMBOL_GPL(gfs_unregister_lockproto);