mount.c 6.19 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

#include "lock_dlm.h"

12
const struct lm_lockops gdlm_ops;
13 14


Steven Whitehouse's avatar
Steven Whitehouse committed
15
static struct gdlm_ls *init_gdlm(lm_callback_t cb, struct gfs2_sbd *sdp,
16 17 18 19 20
				 int flags, char *table_name)
{
	struct gdlm_ls *ls;
	char buf[256], *p;

21
	ls = kzalloc(sizeof(struct gdlm_ls), GFP_KERNEL);
22 23 24
	if (!ls)
		return NULL;

25 26
	ls->drop_locks_count = GDLM_DROP_COUNT;
	ls->drop_locks_period = GDLM_DROP_PERIOD;
27
	ls->fscb = cb;
Steven Whitehouse's avatar
Steven Whitehouse committed
28
	ls->sdp = sdp;
29 30 31 32 33 34 35 36 37 38 39 40 41
	ls->fsflags = flags;
	spin_lock_init(&ls->async_lock);
	INIT_LIST_HEAD(&ls->delayed);
	INIT_LIST_HEAD(&ls->submit);
	INIT_LIST_HEAD(&ls->all_locks);
	init_waitqueue_head(&ls->thread_wait);
	init_waitqueue_head(&ls->wait_control);
	ls->drop_time = jiffies;
	ls->jid = -1;

	strncpy(buf, table_name, 256);
	buf[255] = '\0';

Al Viro's avatar
Al Viro committed
42
	p = strchr(buf, ':');
43
	if (!p) {
44
		log_info("invalid table_name \"%s\"", table_name);
45 46 47 48 49 50
		kfree(ls);
		return NULL;
	}
	*p = '\0';
	p++;

51 52
	strncpy(ls->clustername, buf, GDLM_NAME_LEN);
	strncpy(ls->fsname, p, GDLM_NAME_LEN);
53 54 55 56

	return ls;
}

57
static int make_args(struct gdlm_ls *ls, char *data_arg, int *nodir)
58 59 60 61 62 63 64 65
{
	char data[256];
	char *options, *x, *y;
	int error = 0;

	memset(data, 0, 256);
	strncpy(data, data_arg, 255);

66
	if (!strlen(data)) {
David Teigland's avatar
David Teigland committed
67
		log_error("no mount options, (u)mount helpers not installed");
68 69 70
		return -EINVAL;
	}

71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
	for (options = data; (x = strsep(&options, ":")); ) {
		if (!*x)
			continue;

		y = strchr(x, '=');
		if (y)
			*y++ = 0;

		if (!strcmp(x, "jid")) {
			if (!y) {
				log_error("need argument to jid");
				error = -EINVAL;
				break;
			}
			sscanf(y, "%u", &ls->jid);

		} else if (!strcmp(x, "first")) {
			if (!y) {
				log_error("need argument to first");
				error = -EINVAL;
				break;
			}
			sscanf(y, "%u", &ls->first);

		} else if (!strcmp(x, "id")) {
			if (!y) {
				log_error("need argument to id");
				error = -EINVAL;
				break;
			}
			sscanf(y, "%u", &ls->id);

103 104 105 106 107 108 109 110
		} else if (!strcmp(x, "nodir")) {
			if (!y) {
				log_error("need argument to nodir");
				error = -EINVAL;
				break;
			}
			sscanf(y, "%u", nodir);

111 112 113 114 115 116 117 118 119 120
		} else {
			log_error("unkonwn option: %s", x);
			error = -EINVAL;
			break;
		}
	}

	return error;
}

121
static int gdlm_mount(char *table_name, char *host_data,
122
			lm_callback_t cb, void *cb_data,
123
			unsigned int min_lvb_size, int flags,
124 125
			struct lm_lockstruct *lockstruct,
			struct kobject *fskobj)
126 127
{
	struct gdlm_ls *ls;
128
	int error = -ENOMEM, nodir = 0;
129 130 131 132

	if (min_lvb_size > GDLM_LVB_SIZE)
		goto out;

133
	ls = init_gdlm(cb, cb_data, flags, table_name);
134 135 136
	if (!ls)
		goto out;

137 138 139 140
	error = make_args(ls, host_data, &nodir);
	if (error)
		goto out;

141 142 143 144
	error = gdlm_init_threads(ls);
	if (error)
		goto out_free;

145 146 147 148
	error = gdlm_kobject_setup(ls, fskobj);
	if (error)
		goto out_thread;

149
	error = dlm_new_lockspace(ls->fsname, strlen(ls->fsname),
150
				  &ls->dlm_lockspace,
Patrick Caulfield's avatar
Patrick Caulfield committed
151
				  DLM_LSFL_FS | (nodir ? DLM_LSFL_NODIR : 0),
152
				  GDLM_LVB_SIZE);
153
	if (error) {
154
		log_error("dlm_new_lockspace error %d", error);
155
		goto out_kobj;
156 157 158 159 160 161 162 163 164 165
	}

	lockstruct->ls_jid = ls->jid;
	lockstruct->ls_first = ls->first;
	lockstruct->ls_lockspace = ls;
	lockstruct->ls_ops = &gdlm_ops;
	lockstruct->ls_flags = 0;
	lockstruct->ls_lvb_size = GDLM_LVB_SIZE;
	return 0;

166
out_kobj:
167
	gdlm_kobject_release(ls);
168
out_thread:
169
	gdlm_release_threads(ls);
170
out_free:
171
	kfree(ls);
172
out:
173 174 175
	return error;
}

176
static void gdlm_unmount(void *lockspace)
177
{
178
	struct gdlm_ls *ls = lockspace;
179 180 181 182
	int rv;

	log_debug("unmount flags %lx", ls->flags);

183 184 185
	/* FIXME: serialize unmount and withdraw in case they
	   happen at once.  Also, if unmount follows withdraw,
	   wait for withdraw to finish. */
186

187 188
	if (test_bit(DFL_WITHDRAW, &ls->flags))
		goto out;
189 190 191 192 193 194

	gdlm_kobject_release(ls);
	dlm_release_lockspace(ls->dlm_lockspace, 2);
	gdlm_release_threads(ls);
	rv = gdlm_release_all_locks(ls);
	if (rv)
195
		log_info("gdlm_unmount: %d stray locks freed", rv);
196
out:
197 198 199
	kfree(ls);
}

200
static void gdlm_recovery_done(void *lockspace, unsigned int jid,
201 202
                               unsigned int message)
{
203
	struct gdlm_ls *ls = lockspace;
204
	ls->recover_jid_done = jid;
205
	ls->recover_jid_status = message;
206
	kobject_uevent(&ls->kobj, KOBJ_CHANGE);
207 208
}

209
static void gdlm_others_may_mount(void *lockspace)
210
{
211
	struct gdlm_ls *ls = lockspace;
212
	ls->first_done = 1;
213
	kobject_uevent(&ls->kobj, KOBJ_CHANGE);
214 215
}

216 217 218 219
/* Userspace gets the offline uevent, blocks new gfs locks on
   other mounters, and lets us know (sets WITHDRAW flag).  Then,
   userspace leaves the mount group while we leave the lockspace. */

220
static void gdlm_withdraw(void *lockspace)
221
{
222
	struct gdlm_ls *ls = lockspace;
223

224
	kobject_uevent(&ls->kobj, KOBJ_OFFLINE);
225 226 227 228 229 230 231

	wait_event_interruptible(ls->wait_control,
				 test_bit(DFL_WITHDRAW, &ls->flags));

	dlm_release_lockspace(ls->dlm_lockspace, 2);
	gdlm_release_threads(ls);
	gdlm_release_all_locks(ls);
232
	gdlm_kobject_release(ls);
233 234
}

235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
static int gdlm_plock(void *lockspace, struct lm_lockname *name,
	       struct file *file, int cmd, struct file_lock *fl)
{
	struct gdlm_ls *ls = lockspace;
	return dlm_posix_lock(ls->dlm_lockspace, name->ln_number, file, cmd, fl);
}

static int gdlm_punlock(void *lockspace, struct lm_lockname *name,
		 struct file *file, struct file_lock *fl)
{
	struct gdlm_ls *ls = lockspace;
	return dlm_posix_unlock(ls->dlm_lockspace, name->ln_number, file, fl);
}

static int gdlm_plock_get(void *lockspace, struct lm_lockname *name,
		   struct file *file, struct file_lock *fl)
{
	struct gdlm_ls *ls = lockspace;
	return dlm_posix_get(ls->dlm_lockspace, name->ln_number, file, fl);
}

256
const struct lm_lockops gdlm_ops = {
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
	.lm_proto_name = "lock_dlm",
	.lm_mount = gdlm_mount,
	.lm_others_may_mount = gdlm_others_may_mount,
	.lm_unmount = gdlm_unmount,
	.lm_withdraw = gdlm_withdraw,
	.lm_get_lock = gdlm_get_lock,
	.lm_put_lock = gdlm_put_lock,
	.lm_lock = gdlm_lock,
	.lm_unlock = gdlm_unlock,
	.lm_plock = gdlm_plock,
	.lm_punlock = gdlm_punlock,
	.lm_plock_get = gdlm_plock_get,
	.lm_cancel = gdlm_cancel,
	.lm_hold_lvb = gdlm_hold_lvb,
	.lm_unhold_lvb = gdlm_unhold_lvb,
	.lm_recovery_done = gdlm_recovery_done,
	.lm_owner = THIS_MODULE,
274 275
};