2006-01-17 01:47:12 -07:00
|
|
|
/*
|
|
|
|
* 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
|
2006-09-01 09:05:15 -06:00
|
|
|
* of the GNU General Public License version 2.
|
2006-01-17 01:47:12 -07:00
|
|
|
*/
|
2006-01-16 09:52:38 -07:00
|
|
|
|
|
|
|
#include "lock_dlm.h"
|
|
|
|
|
2006-09-08 08:17:58 -06:00
|
|
|
const struct lm_lockops gdlm_ops;
|
2006-01-16 09:52:38 -07:00
|
|
|
|
|
|
|
|
2006-09-07 13:50:20 -06:00
|
|
|
static struct gdlm_ls *init_gdlm(lm_callback_t cb, struct gfs2_sbd *sdp,
|
2006-01-16 09:52:38 -07:00
|
|
|
int flags, char *table_name)
|
|
|
|
{
|
|
|
|
struct gdlm_ls *ls;
|
|
|
|
char buf[256], *p;
|
|
|
|
|
2006-01-17 01:47:12 -07:00
|
|
|
ls = kzalloc(sizeof(struct gdlm_ls), GFP_KERNEL);
|
2006-01-16 09:52:38 -07:00
|
|
|
if (!ls)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
ls->fscb = cb;
|
2006-09-07 13:50:20 -06:00
|
|
|
ls->sdp = sdp;
|
2006-01-16 09:52:38 -07:00
|
|
|
ls->fsflags = flags;
|
|
|
|
spin_lock_init(&ls->async_lock);
|
|
|
|
INIT_LIST_HEAD(&ls->delayed);
|
|
|
|
INIT_LIST_HEAD(&ls->submit);
|
|
|
|
init_waitqueue_head(&ls->thread_wait);
|
|
|
|
init_waitqueue_head(&ls->wait_control);
|
|
|
|
ls->jid = -1;
|
|
|
|
|
|
|
|
strncpy(buf, table_name, 256);
|
|
|
|
buf[255] = '\0';
|
|
|
|
|
2006-10-11 10:25:45 -06:00
|
|
|
p = strchr(buf, ':');
|
2006-01-16 09:52:38 -07:00
|
|
|
if (!p) {
|
2006-01-17 01:47:12 -07:00
|
|
|
log_info("invalid table_name \"%s\"", table_name);
|
2006-01-16 09:52:38 -07:00
|
|
|
kfree(ls);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
*p = '\0';
|
|
|
|
p++;
|
|
|
|
|
2006-01-17 01:47:12 -07:00
|
|
|
strncpy(ls->clustername, buf, GDLM_NAME_LEN);
|
|
|
|
strncpy(ls->fsname, p, GDLM_NAME_LEN);
|
2006-01-16 09:52:38 -07:00
|
|
|
|
|
|
|
return ls;
|
|
|
|
}
|
|
|
|
|
2006-03-28 12:20:58 -07:00
|
|
|
static int make_args(struct gdlm_ls *ls, char *data_arg, int *nodir)
|
2006-01-17 01:47:12 -07:00
|
|
|
{
|
|
|
|
char data[256];
|
|
|
|
char *options, *x, *y;
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
memset(data, 0, 256);
|
|
|
|
strncpy(data, data_arg, 255);
|
|
|
|
|
2007-11-15 06:48:52 -07:00
|
|
|
if (!strlen(data)) {
|
2007-11-15 08:01:13 -07:00
|
|
|
log_error("no mount options, (u)mount helpers not installed");
|
2007-11-15 06:48:52 -07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2006-01-17 01:47:12 -07:00
|
|
|
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);
|
|
|
|
|
2006-03-28 12:20:58 -07:00
|
|
|
} else if (!strcmp(x, "nodir")) {
|
|
|
|
if (!y) {
|
|
|
|
log_error("need argument to nodir");
|
|
|
|
error = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sscanf(y, "%u", nodir);
|
|
|
|
|
2006-01-17 01:47:12 -07:00
|
|
|
} else {
|
|
|
|
log_error("unkonwn option: %s", x);
|
|
|
|
error = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2006-01-16 09:52:38 -07:00
|
|
|
static int gdlm_mount(char *table_name, char *host_data,
|
2006-09-08 08:17:58 -06:00
|
|
|
lm_callback_t cb, void *cb_data,
|
2006-01-16 09:52:38 -07:00
|
|
|
unsigned int min_lvb_size, int flags,
|
2006-01-17 01:47:12 -07:00
|
|
|
struct lm_lockstruct *lockstruct,
|
|
|
|
struct kobject *fskobj)
|
2006-01-16 09:52:38 -07:00
|
|
|
{
|
|
|
|
struct gdlm_ls *ls;
|
2006-03-28 12:20:58 -07:00
|
|
|
int error = -ENOMEM, nodir = 0;
|
2006-01-16 09:52:38 -07:00
|
|
|
|
|
|
|
if (min_lvb_size > GDLM_LVB_SIZE)
|
|
|
|
goto out;
|
|
|
|
|
2006-09-08 08:17:58 -06:00
|
|
|
ls = init_gdlm(cb, cb_data, flags, table_name);
|
2006-01-16 09:52:38 -07:00
|
|
|
if (!ls)
|
|
|
|
goto out;
|
|
|
|
|
2006-03-28 12:20:58 -07:00
|
|
|
error = make_args(ls, host_data, &nodir);
|
|
|
|
if (error)
|
|
|
|
goto out;
|
|
|
|
|
2006-01-16 09:52:38 -07:00
|
|
|
error = gdlm_init_threads(ls);
|
|
|
|
if (error)
|
|
|
|
goto out_free;
|
|
|
|
|
2006-05-19 06:24:02 -06:00
|
|
|
error = gdlm_kobject_setup(ls, fskobj);
|
|
|
|
if (error)
|
|
|
|
goto out_thread;
|
|
|
|
|
2006-01-16 09:52:38 -07:00
|
|
|
error = dlm_new_lockspace(ls->fsname, strlen(ls->fsname),
|
2006-03-28 12:20:58 -07:00
|
|
|
&ls->dlm_lockspace,
|
2007-06-06 08:21:22 -06:00
|
|
|
DLM_LSFL_FS | (nodir ? DLM_LSFL_NODIR : 0),
|
2006-03-28 12:20:58 -07:00
|
|
|
GDLM_LVB_SIZE);
|
2006-01-16 09:52:38 -07:00
|
|
|
if (error) {
|
2006-01-17 01:47:12 -07:00
|
|
|
log_error("dlm_new_lockspace error %d", error);
|
2006-05-19 06:24:02 -06:00
|
|
|
goto out_kobj;
|
2006-01-16 09:52:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2006-09-04 10:04:26 -06:00
|
|
|
out_kobj:
|
2006-05-19 06:24:02 -06:00
|
|
|
gdlm_kobject_release(ls);
|
2006-09-04 10:04:26 -06:00
|
|
|
out_thread:
|
2006-01-16 09:52:38 -07:00
|
|
|
gdlm_release_threads(ls);
|
2006-09-04 10:04:26 -06:00
|
|
|
out_free:
|
2006-01-16 09:52:38 -07:00
|
|
|
kfree(ls);
|
2006-09-04 10:04:26 -06:00
|
|
|
out:
|
2006-01-16 09:52:38 -07:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2006-09-08 08:17:58 -06:00
|
|
|
static void gdlm_unmount(void *lockspace)
|
2006-01-16 09:52:38 -07:00
|
|
|
{
|
2006-09-08 08:17:58 -06:00
|
|
|
struct gdlm_ls *ls = lockspace;
|
2006-01-16 09:52:38 -07:00
|
|
|
|
|
|
|
log_debug("unmount flags %lx", ls->flags);
|
|
|
|
|
2006-01-17 01:47:12 -07:00
|
|
|
/* FIXME: serialize unmount and withdraw in case they
|
|
|
|
happen at once. Also, if unmount follows withdraw,
|
|
|
|
wait for withdraw to finish. */
|
2006-01-16 09:52:38 -07:00
|
|
|
|
2006-01-17 01:47:12 -07:00
|
|
|
if (test_bit(DFL_WITHDRAW, &ls->flags))
|
|
|
|
goto out;
|
2006-01-16 09:52:38 -07:00
|
|
|
|
|
|
|
gdlm_kobject_release(ls);
|
|
|
|
dlm_release_lockspace(ls->dlm_lockspace, 2);
|
|
|
|
gdlm_release_threads(ls);
|
2008-06-04 08:06:21 -06:00
|
|
|
BUG_ON(ls->all_locks_count);
|
2006-09-04 10:04:26 -06:00
|
|
|
out:
|
2006-01-16 09:52:38 -07:00
|
|
|
kfree(ls);
|
|
|
|
}
|
|
|
|
|
2006-09-08 08:17:58 -06:00
|
|
|
static void gdlm_recovery_done(void *lockspace, unsigned int jid,
|
2006-01-16 09:52:38 -07:00
|
|
|
unsigned int message)
|
|
|
|
{
|
2006-09-08 08:17:58 -06:00
|
|
|
struct gdlm_ls *ls = lockspace;
|
2006-01-17 01:47:12 -07:00
|
|
|
ls->recover_jid_done = jid;
|
2006-04-26 13:56:35 -06:00
|
|
|
ls->recover_jid_status = message;
|
2006-01-18 02:34:14 -07:00
|
|
|
kobject_uevent(&ls->kobj, KOBJ_CHANGE);
|
2006-01-16 09:52:38 -07:00
|
|
|
}
|
|
|
|
|
2006-09-08 08:17:58 -06:00
|
|
|
static void gdlm_others_may_mount(void *lockspace)
|
2006-01-16 09:52:38 -07:00
|
|
|
{
|
2006-09-08 08:17:58 -06:00
|
|
|
struct gdlm_ls *ls = lockspace;
|
2006-01-16 09:52:38 -07:00
|
|
|
ls->first_done = 1;
|
2006-01-18 02:34:14 -07:00
|
|
|
kobject_uevent(&ls->kobj, KOBJ_CHANGE);
|
2006-01-16 09:52:38 -07:00
|
|
|
}
|
|
|
|
|
2006-01-17 01:47:12 -07:00
|
|
|
/* 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. */
|
|
|
|
|
2006-09-08 08:17:58 -06:00
|
|
|
static void gdlm_withdraw(void *lockspace)
|
2006-01-16 09:52:38 -07:00
|
|
|
{
|
2006-09-08 08:17:58 -06:00
|
|
|
struct gdlm_ls *ls = lockspace;
|
2006-01-16 09:52:38 -07:00
|
|
|
|
2006-01-18 02:34:14 -07:00
|
|
|
kobject_uevent(&ls->kobj, KOBJ_OFFLINE);
|
2006-01-16 09:52:38 -07:00
|
|
|
|
|
|
|
wait_event_interruptible(ls->wait_control,
|
|
|
|
test_bit(DFL_WITHDRAW, &ls->flags));
|
|
|
|
|
|
|
|
dlm_release_lockspace(ls->dlm_lockspace, 2);
|
|
|
|
gdlm_release_threads(ls);
|
2006-01-17 01:47:12 -07:00
|
|
|
gdlm_kobject_release(ls);
|
2006-01-16 09:52:38 -07:00
|
|
|
}
|
|
|
|
|
2008-03-14 14:09:15 -06:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2006-09-08 08:17:58 -06:00
|
|
|
const struct lm_lockops gdlm_ops = {
|
2006-01-17 01:47:12 -07:00
|
|
|
.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,
|
2006-01-16 09:52:38 -07:00
|
|
|
};
|
|
|
|
|