main.c 5.0 KB
Newer Older
1 2 3 4 5 6
/*
 * Copyright (C) Sistina Software, Inc.  1997-2003 All rights reserved.
 * Copyright (C) 2004-2005 Red Hat, Inc.  All rights reserved.
 *
 * This copyrighted material is made available to anyone wishing to use,
 * modify, copy, or redistribute it subject to the terms and conditions
7
 * of the GNU General Public License version 2.
8
 */
9 10 11 12 13 14

#include <linux/module.h>
#include <linux/slab.h>
#include <linux/init.h>
#include <linux/types.h>
#include <linux/fs.h>
15
#include <linux/lm_interface.h>
16 17 18 19 20

struct nolock_lockspace {
	unsigned int nl_lvb_size;
};

21
static const struct lm_lockops nolock_ops;
22 23

static int nolock_mount(char *table_name, char *host_data,
24
			lm_callback_t cb, void *cb_data,
25
			unsigned int min_lvb_size, int flags,
26 27
			struct lm_lockstruct *lockstruct,
			struct kobject *fskobj)
28 29 30 31 32 33 34 35 36 37 38 39 40
{
	char *c;
	unsigned int jid;
	struct nolock_lockspace *nl;

	c = strstr(host_data, "jid=");
	if (!c)
		jid = 0;
	else {
		c += 4;
		sscanf(c, "%u", &jid);
	}

41
	nl = kzalloc(sizeof(struct nolock_lockspace), GFP_KERNEL);
42 43 44 45 46 47 48 49
	if (!nl)
		return -ENOMEM;

	nl->nl_lvb_size = min_lvb_size;

	lockstruct->ls_jid = jid;
	lockstruct->ls_first = 1;
	lockstruct->ls_lvb_size = min_lvb_size;
50
	lockstruct->ls_lockspace = nl;
51 52 53 54 55 56
	lockstruct->ls_ops = &nolock_ops;
	lockstruct->ls_flags = LM_LSFLAG_LOCAL;

	return 0;
}

57
static void nolock_others_may_mount(void *lockspace)
58 59 60
{
}

61
static void nolock_unmount(void *lockspace)
62
{
63
	struct nolock_lockspace *nl = lockspace;
64 65 66
	kfree(nl);
}

67
static void nolock_withdraw(void *lockspace)
68 69 70 71 72 73 74 75 76 77 78 79
{
}

/**
 * nolock_get_lock - get a lm_lock_t given a descripton of the lock
 * @lockspace: the lockspace the lock lives in
 * @name: the name of the lock
 * @lockp: return the lm_lock_t here
 *
 * Returns: 0 on success, -EXXX on failure
 */

80 81
static int nolock_get_lock(void *lockspace, struct lm_lockname *name,
			   void **lockp)
82
{
83
	*lockp = lockspace;
84 85 86 87 88 89 90 91 92
	return 0;
}

/**
 * nolock_put_lock - get rid of a lock structure
 * @lock: the lock to throw away
 *
 */

93
static void nolock_put_lock(void *lock)
94 95 96 97 98 99 100 101 102 103 104 105 106
{
}

/**
 * nolock_lock - acquire a lock
 * @lock: the lock to manipulate
 * @cur_state: the current state
 * @req_state: the requested state
 * @flags: modifier flags
 *
 * Returns: A bitmap of LM_OUT_*
 */

107
static unsigned int nolock_lock(void *lock, unsigned int cur_state,
108 109
				unsigned int req_state, unsigned int flags)
{
110 111
	if (req_state == LM_ST_UNLOCKED)
		return 0;
112 113 114 115 116 117 118 119 120 121 122
	return req_state | LM_OUT_CACHEABLE;
}

/**
 * nolock_unlock - unlock a lock
 * @lock: the lock to manipulate
 * @cur_state: the current state
 *
 * Returns: 0
 */

123
static unsigned int nolock_unlock(void *lock, unsigned int cur_state)
124 125 126 127
{
	return 0;
}

128
static void nolock_cancel(void *lock)
129 130 131 132 133 134 135 136 137 138 139
{
}

/**
 * nolock_hold_lvb - hold on to a lock value block
 * @lock: the lock the LVB is associated with
 * @lvbp: return the lm_lvb_t here
 *
 * Returns: 0 on success, -EXXX on failure
 */

140
static int nolock_hold_lvb(void *lock, char **lvbp)
141
{
142
	struct nolock_lockspace *nl = lock;
143 144
	int error = 0;

J
Josef Bacik 已提交
145
	*lvbp = kzalloc(nl->nl_lvb_size, GFP_NOFS);
146
	if (!*lvbp)
147 148 149 150 151 152 153 154 155 156 157 158
		error = -ENOMEM;

	return error;
}

/**
 * nolock_unhold_lvb - release a LVB
 * @lock: the lock the LVB is associated with
 * @lvb: the lock value block
 *
 */

159
static void nolock_unhold_lvb(void *lock, char *lvb)
160 161 162 163
{
	kfree(lvb);
}

164
static int nolock_plock_get(void *lockspace, struct lm_lockname *name,
165 166
			    struct file *file, struct file_lock *fl)
{
167
	posix_test_lock(file, fl);
168 169 170 171

	return 0;
}

172
static int nolock_plock(void *lockspace, struct lm_lockname *name,
173 174 175 176 177 178 179
			struct file *file, int cmd, struct file_lock *fl)
{
	int error;
	error = posix_lock_file_wait(file, fl);
	return error;
}

180
static int nolock_punlock(void *lockspace, struct lm_lockname *name,
181 182 183 184 185 186 187
			  struct file *file, struct file_lock *fl)
{
	int error;
	error = posix_lock_file_wait(file, fl);
	return error;
}

188
static void nolock_recovery_done(void *lockspace, unsigned int jid,
189 190 191 192
				 unsigned int message)
{
}

193
static const struct lm_lockops nolock_ops = {
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
	.lm_proto_name = "lock_nolock",
	.lm_mount = nolock_mount,
	.lm_others_may_mount = nolock_others_may_mount,
	.lm_unmount = nolock_unmount,
	.lm_withdraw = nolock_withdraw,
	.lm_get_lock = nolock_get_lock,
	.lm_put_lock = nolock_put_lock,
	.lm_lock = nolock_lock,
	.lm_unlock = nolock_unlock,
	.lm_cancel = nolock_cancel,
	.lm_hold_lvb = nolock_hold_lvb,
	.lm_unhold_lvb = nolock_unhold_lvb,
	.lm_plock_get = nolock_plock_get,
	.lm_plock = nolock_plock,
	.lm_punlock = nolock_punlock,
	.lm_recovery_done = nolock_recovery_done,
	.lm_owner = THIS_MODULE,
};

213
static int __init init_nolock(void)
214 215 216
{
	int error;

D
David Teigland 已提交
217
	error = gfs2_register_lockproto(&nolock_ops);
218
	if (error) {
219 220
		printk(KERN_WARNING
		       "lock_nolock: can't register protocol: %d\n", error);
221 222 223
		return error;
	}

224 225
	printk(KERN_INFO
	       "Lock_Nolock (built %s %s) installed\n", __DATE__, __TIME__);
226 227 228
	return 0;
}

229
static void __exit exit_nolock(void)
230
{
D
David Teigland 已提交
231
	gfs2_unregister_lockproto(&nolock_ops);
232 233 234 235 236 237 238 239 240
}

module_init(init_nolock);
module_exit(exit_nolock);

MODULE_DESCRIPTION("GFS Nolock Locking Module");
MODULE_AUTHOR("Red Hat, Inc.");
MODULE_LICENSE("GPL");