2019-05-28 16:57:20 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2006-01-18 09:30:29 +00:00
|
|
|
/******************************************************************************
|
|
|
|
*******************************************************************************
|
|
|
|
**
|
|
|
|
** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
|
2011-11-02 19:30:58 +00:00
|
|
|
** Copyright (C) 2004-2011 Red Hat, Inc. All rights reserved.
|
2006-01-18 09:30:29 +00:00
|
|
|
**
|
|
|
|
**
|
|
|
|
*******************************************************************************
|
|
|
|
******************************************************************************/
|
|
|
|
|
2016-09-19 20:44:50 +00:00
|
|
|
#include <linux/module.h>
|
|
|
|
|
2006-01-18 09:30:29 +00:00
|
|
|
#include "dlm_internal.h"
|
|
|
|
#include "lockspace.h"
|
|
|
|
#include "member.h"
|
|
|
|
#include "recoverd.h"
|
|
|
|
#include "dir.h"
|
2021-05-21 19:08:41 +00:00
|
|
|
#include "midcomms.h"
|
2006-01-18 09:30:29 +00:00
|
|
|
#include "lowcomms.h"
|
|
|
|
#include "config.h"
|
|
|
|
#include "memory.h"
|
|
|
|
#include "lock.h"
|
2006-04-28 14:51:53 +00:00
|
|
|
#include "recover.h"
|
2006-11-27 17:31:22 +00:00
|
|
|
#include "requestqueue.h"
|
2008-08-06 18:30:24 +00:00
|
|
|
#include "user.h"
|
2011-04-05 18:16:24 +00:00
|
|
|
#include "ast.h"
|
2006-01-18 09:30:29 +00:00
|
|
|
|
|
|
|
static int ls_count;
|
2006-01-20 08:47:07 +00:00
|
|
|
static struct mutex ls_lock;
|
2006-01-18 09:30:29 +00:00
|
|
|
static struct list_head lslist;
|
|
|
|
static spinlock_t lslist_lock;
|
|
|
|
static struct task_struct * scand_task;
|
|
|
|
|
|
|
|
|
|
|
|
static ssize_t dlm_control_store(struct dlm_ls *ls, const char *buf, size_t len)
|
|
|
|
{
|
|
|
|
ssize_t ret = len;
|
2014-06-06 21:38:25 +00:00
|
|
|
int n;
|
|
|
|
int rc = kstrtoint(buf, 0, &n);
|
2006-01-18 09:30:29 +00:00
|
|
|
|
2014-06-06 21:38:25 +00:00
|
|
|
if (rc)
|
|
|
|
return rc;
|
2006-11-06 08:53:28 +00:00
|
|
|
ls = dlm_find_lockspace_local(ls->ls_local_handle);
|
|
|
|
if (!ls)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2006-01-18 09:30:29 +00:00
|
|
|
switch (n) {
|
|
|
|
case 0:
|
|
|
|
dlm_ls_stop(ls);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
dlm_ls_start(ls);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = -EINVAL;
|
|
|
|
}
|
2006-11-06 08:53:28 +00:00
|
|
|
dlm_put_lockspace(ls);
|
2006-01-18 09:30:29 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t dlm_event_store(struct dlm_ls *ls, const char *buf, size_t len)
|
|
|
|
{
|
2014-06-06 21:38:25 +00:00
|
|
|
int rc = kstrtoint(buf, 0, &ls->ls_uevent_result);
|
|
|
|
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
2006-01-18 09:30:29 +00:00
|
|
|
set_bit(LSFL_UEVENT_WAIT, &ls->ls_flags);
|
|
|
|
wake_up(&ls->ls_uevent_wait);
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t dlm_id_show(struct dlm_ls *ls, char *buf)
|
|
|
|
{
|
2006-09-06 22:01:40 +00:00
|
|
|
return snprintf(buf, PAGE_SIZE, "%u\n", ls->ls_global_id);
|
2006-01-18 09:30:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t dlm_id_store(struct dlm_ls *ls, const char *buf, size_t len)
|
|
|
|
{
|
2014-06-06 21:38:25 +00:00
|
|
|
int rc = kstrtouint(buf, 0, &ls->ls_global_id);
|
|
|
|
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
2006-01-18 09:30:29 +00:00
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
dlm: fixes for nodir mode
The "nodir" mode (statically assign master nodes instead
of using the resource directory) has always been highly
experimental, and never seriously used. This commit
fixes a number of problems, making nodir much more usable.
- Major change to recovery: recover all locks and restart
all in-progress operations after recovery. In some
cases it's not possible to know which in-progess locks
to recover, so recover all. (Most require recovery
in nodir mode anyway since rehashing changes most
master nodes.)
- Change the way nodir mode is enabled, from a command
line mount arg passed through gfs2, into a sysfs
file managed by dlm_controld, consistent with the
other config settings.
- Allow recovering MSTCPY locks on an rsb that has not
yet been turned into a master copy.
- Ignore RCOM_LOCK and RCOM_LOCK_REPLY recovery messages
from a previous, aborted recovery cycle. Base this
on the local recovery status not being in the state
where any nodes should be sending LOCK messages for the
current recovery cycle.
- Hold rsb lock around dlm_purge_mstcpy_locks() because it
may run concurrently with dlm_recover_master_copy().
- Maintain highbast on process-copy lkb's (in addition to
the master as is usual), because the lkb can switch
back and forth between being a master and being a
process copy as the master node changes in recovery.
- When recovering MSTCPY locks, flag rsb's that have
non-empty convert or waiting queues for granting
at the end of recovery. (Rename flag from LOCKS_PURGED
to RECOVER_GRANT and similar for the recovery function,
because it's not only resources with purged locks
that need grant a grant attempt.)
- Replace a couple of unnecessary assertion panics with
error messages.
Signed-off-by: David Teigland <teigland@redhat.com>
2012-04-26 20:54:29 +00:00
|
|
|
static ssize_t dlm_nodir_show(struct dlm_ls *ls, char *buf)
|
|
|
|
{
|
|
|
|
return snprintf(buf, PAGE_SIZE, "%u\n", dlm_no_directory(ls));
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t dlm_nodir_store(struct dlm_ls *ls, const char *buf, size_t len)
|
|
|
|
{
|
2014-06-06 21:38:25 +00:00
|
|
|
int val;
|
|
|
|
int rc = kstrtoint(buf, 0, &val);
|
|
|
|
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
dlm: fixes for nodir mode
The "nodir" mode (statically assign master nodes instead
of using the resource directory) has always been highly
experimental, and never seriously used. This commit
fixes a number of problems, making nodir much more usable.
- Major change to recovery: recover all locks and restart
all in-progress operations after recovery. In some
cases it's not possible to know which in-progess locks
to recover, so recover all. (Most require recovery
in nodir mode anyway since rehashing changes most
master nodes.)
- Change the way nodir mode is enabled, from a command
line mount arg passed through gfs2, into a sysfs
file managed by dlm_controld, consistent with the
other config settings.
- Allow recovering MSTCPY locks on an rsb that has not
yet been turned into a master copy.
- Ignore RCOM_LOCK and RCOM_LOCK_REPLY recovery messages
from a previous, aborted recovery cycle. Base this
on the local recovery status not being in the state
where any nodes should be sending LOCK messages for the
current recovery cycle.
- Hold rsb lock around dlm_purge_mstcpy_locks() because it
may run concurrently with dlm_recover_master_copy().
- Maintain highbast on process-copy lkb's (in addition to
the master as is usual), because the lkb can switch
back and forth between being a master and being a
process copy as the master node changes in recovery.
- When recovering MSTCPY locks, flag rsb's that have
non-empty convert or waiting queues for granting
at the end of recovery. (Rename flag from LOCKS_PURGED
to RECOVER_GRANT and similar for the recovery function,
because it's not only resources with purged locks
that need grant a grant attempt.)
- Replace a couple of unnecessary assertion panics with
error messages.
Signed-off-by: David Teigland <teigland@redhat.com>
2012-04-26 20:54:29 +00:00
|
|
|
if (val == 1)
|
|
|
|
set_bit(LSFL_NODIR, &ls->ls_flags);
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2006-04-28 14:51:53 +00:00
|
|
|
static ssize_t dlm_recover_status_show(struct dlm_ls *ls, char *buf)
|
|
|
|
{
|
|
|
|
uint32_t status = dlm_recover_status(ls);
|
2006-09-06 22:01:40 +00:00
|
|
|
return snprintf(buf, PAGE_SIZE, "%x\n", status);
|
2006-04-28 14:51:53 +00:00
|
|
|
}
|
|
|
|
|
2006-08-08 22:08:42 +00:00
|
|
|
static ssize_t dlm_recover_nodeid_show(struct dlm_ls *ls, char *buf)
|
|
|
|
{
|
2006-09-06 22:01:40 +00:00
|
|
|
return snprintf(buf, PAGE_SIZE, "%d\n", ls->ls_recover_nodeid);
|
2006-08-08 22:08:42 +00:00
|
|
|
}
|
|
|
|
|
2006-01-18 09:30:29 +00:00
|
|
|
struct dlm_attr {
|
|
|
|
struct attribute attr;
|
|
|
|
ssize_t (*show)(struct dlm_ls *, char *);
|
|
|
|
ssize_t (*store)(struct dlm_ls *, const char *, size_t);
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct dlm_attr dlm_attr_control = {
|
|
|
|
.attr = {.name = "control", .mode = S_IWUSR},
|
|
|
|
.store = dlm_control_store
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct dlm_attr dlm_attr_event = {
|
|
|
|
.attr = {.name = "event_done", .mode = S_IWUSR},
|
|
|
|
.store = dlm_event_store
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct dlm_attr dlm_attr_id = {
|
|
|
|
.attr = {.name = "id", .mode = S_IRUGO | S_IWUSR},
|
|
|
|
.show = dlm_id_show,
|
|
|
|
.store = dlm_id_store
|
|
|
|
};
|
|
|
|
|
dlm: fixes for nodir mode
The "nodir" mode (statically assign master nodes instead
of using the resource directory) has always been highly
experimental, and never seriously used. This commit
fixes a number of problems, making nodir much more usable.
- Major change to recovery: recover all locks and restart
all in-progress operations after recovery. In some
cases it's not possible to know which in-progess locks
to recover, so recover all. (Most require recovery
in nodir mode anyway since rehashing changes most
master nodes.)
- Change the way nodir mode is enabled, from a command
line mount arg passed through gfs2, into a sysfs
file managed by dlm_controld, consistent with the
other config settings.
- Allow recovering MSTCPY locks on an rsb that has not
yet been turned into a master copy.
- Ignore RCOM_LOCK and RCOM_LOCK_REPLY recovery messages
from a previous, aborted recovery cycle. Base this
on the local recovery status not being in the state
where any nodes should be sending LOCK messages for the
current recovery cycle.
- Hold rsb lock around dlm_purge_mstcpy_locks() because it
may run concurrently with dlm_recover_master_copy().
- Maintain highbast on process-copy lkb's (in addition to
the master as is usual), because the lkb can switch
back and forth between being a master and being a
process copy as the master node changes in recovery.
- When recovering MSTCPY locks, flag rsb's that have
non-empty convert or waiting queues for granting
at the end of recovery. (Rename flag from LOCKS_PURGED
to RECOVER_GRANT and similar for the recovery function,
because it's not only resources with purged locks
that need grant a grant attempt.)
- Replace a couple of unnecessary assertion panics with
error messages.
Signed-off-by: David Teigland <teigland@redhat.com>
2012-04-26 20:54:29 +00:00
|
|
|
static struct dlm_attr dlm_attr_nodir = {
|
|
|
|
.attr = {.name = "nodir", .mode = S_IRUGO | S_IWUSR},
|
|
|
|
.show = dlm_nodir_show,
|
|
|
|
.store = dlm_nodir_store
|
|
|
|
};
|
|
|
|
|
2006-04-28 14:51:53 +00:00
|
|
|
static struct dlm_attr dlm_attr_recover_status = {
|
|
|
|
.attr = {.name = "recover_status", .mode = S_IRUGO},
|
|
|
|
.show = dlm_recover_status_show
|
|
|
|
};
|
|
|
|
|
2006-08-08 22:08:42 +00:00
|
|
|
static struct dlm_attr dlm_attr_recover_nodeid = {
|
|
|
|
.attr = {.name = "recover_nodeid", .mode = S_IRUGO},
|
|
|
|
.show = dlm_recover_nodeid_show
|
|
|
|
};
|
|
|
|
|
2006-01-18 09:30:29 +00:00
|
|
|
static struct attribute *dlm_attrs[] = {
|
|
|
|
&dlm_attr_control.attr,
|
|
|
|
&dlm_attr_event.attr,
|
|
|
|
&dlm_attr_id.attr,
|
dlm: fixes for nodir mode
The "nodir" mode (statically assign master nodes instead
of using the resource directory) has always been highly
experimental, and never seriously used. This commit
fixes a number of problems, making nodir much more usable.
- Major change to recovery: recover all locks and restart
all in-progress operations after recovery. In some
cases it's not possible to know which in-progess locks
to recover, so recover all. (Most require recovery
in nodir mode anyway since rehashing changes most
master nodes.)
- Change the way nodir mode is enabled, from a command
line mount arg passed through gfs2, into a sysfs
file managed by dlm_controld, consistent with the
other config settings.
- Allow recovering MSTCPY locks on an rsb that has not
yet been turned into a master copy.
- Ignore RCOM_LOCK and RCOM_LOCK_REPLY recovery messages
from a previous, aborted recovery cycle. Base this
on the local recovery status not being in the state
where any nodes should be sending LOCK messages for the
current recovery cycle.
- Hold rsb lock around dlm_purge_mstcpy_locks() because it
may run concurrently with dlm_recover_master_copy().
- Maintain highbast on process-copy lkb's (in addition to
the master as is usual), because the lkb can switch
back and forth between being a master and being a
process copy as the master node changes in recovery.
- When recovering MSTCPY locks, flag rsb's that have
non-empty convert or waiting queues for granting
at the end of recovery. (Rename flag from LOCKS_PURGED
to RECOVER_GRANT and similar for the recovery function,
because it's not only resources with purged locks
that need grant a grant attempt.)
- Replace a couple of unnecessary assertion panics with
error messages.
Signed-off-by: David Teigland <teigland@redhat.com>
2012-04-26 20:54:29 +00:00
|
|
|
&dlm_attr_nodir.attr,
|
2006-04-28 14:51:53 +00:00
|
|
|
&dlm_attr_recover_status.attr,
|
2006-08-08 22:08:42 +00:00
|
|
|
&dlm_attr_recover_nodeid.attr,
|
2006-01-18 09:30:29 +00:00
|
|
|
NULL,
|
|
|
|
};
|
2019-05-08 01:48:05 +00:00
|
|
|
ATTRIBUTE_GROUPS(dlm);
|
2006-01-18 09:30:29 +00:00
|
|
|
|
|
|
|
static ssize_t dlm_attr_show(struct kobject *kobj, struct attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct dlm_ls *ls = container_of(kobj, struct dlm_ls, ls_kobj);
|
|
|
|
struct dlm_attr *a = container_of(attr, struct dlm_attr, attr);
|
|
|
|
return a->show ? a->show(ls, buf) : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t dlm_attr_store(struct kobject *kobj, struct attribute *attr,
|
|
|
|
const char *buf, size_t len)
|
|
|
|
{
|
|
|
|
struct dlm_ls *ls = container_of(kobj, struct dlm_ls, ls_kobj);
|
|
|
|
struct dlm_attr *a = container_of(attr, struct dlm_attr, attr);
|
|
|
|
return a->store ? a->store(ls, buf, len) : len;
|
|
|
|
}
|
|
|
|
|
2006-11-02 14:41:23 +00:00
|
|
|
static void lockspace_kobj_release(struct kobject *k)
|
|
|
|
{
|
|
|
|
struct dlm_ls *ls = container_of(k, struct dlm_ls, ls_kobj);
|
|
|
|
kfree(ls);
|
|
|
|
}
|
|
|
|
|
2010-01-19 01:58:23 +00:00
|
|
|
static const struct sysfs_ops dlm_attr_ops = {
|
2006-01-18 09:30:29 +00:00
|
|
|
.show = dlm_attr_show,
|
|
|
|
.store = dlm_attr_store,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct kobj_type dlm_ktype = {
|
2019-05-08 01:48:05 +00:00
|
|
|
.default_groups = dlm_groups,
|
2006-01-18 09:30:29 +00:00
|
|
|
.sysfs_ops = &dlm_attr_ops,
|
2006-11-02 14:41:23 +00:00
|
|
|
.release = lockspace_kobj_release,
|
2006-01-18 09:30:29 +00:00
|
|
|
};
|
|
|
|
|
2007-10-29 19:13:17 +00:00
|
|
|
static struct kset *dlm_kset;
|
2006-01-18 09:30:29 +00:00
|
|
|
|
|
|
|
static int do_uevent(struct dlm_ls *ls, int in)
|
|
|
|
{
|
|
|
|
if (in)
|
|
|
|
kobject_uevent(&ls->ls_kobj, KOBJ_ONLINE);
|
|
|
|
else
|
|
|
|
kobject_uevent(&ls->ls_kobj, KOBJ_OFFLINE);
|
|
|
|
|
2014-02-14 17:54:44 +00:00
|
|
|
log_rinfo(ls, "%s the lockspace group...", in ? "joining" : "leaving");
|
2007-05-18 14:03:35 +00:00
|
|
|
|
|
|
|
/* dlm_controld will see the uevent, do the necessary group management
|
|
|
|
and then write to sysfs to wake us */
|
|
|
|
|
2020-04-29 12:15:41 +00:00
|
|
|
wait_event(ls->ls_uevent_wait,
|
|
|
|
test_and_clear_bit(LSFL_UEVENT_WAIT, &ls->ls_flags));
|
2007-05-18 14:03:35 +00:00
|
|
|
|
2020-04-29 12:15:41 +00:00
|
|
|
log_rinfo(ls, "group event done %d", ls->ls_uevent_result);
|
2006-01-18 09:30:29 +00:00
|
|
|
|
2020-04-29 12:15:41 +00:00
|
|
|
return ls->ls_uevent_result;
|
2006-01-18 09:30:29 +00:00
|
|
|
}
|
|
|
|
|
2010-02-17 09:41:34 +00:00
|
|
|
static int dlm_uevent(struct kset *kset, struct kobject *kobj,
|
|
|
|
struct kobj_uevent_env *env)
|
|
|
|
{
|
|
|
|
struct dlm_ls *ls = container_of(kobj, struct dlm_ls, ls_kobj);
|
|
|
|
|
|
|
|
add_uevent_var(env, "LOCKSPACE=%s", ls->ls_name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-07-28 13:19:17 +00:00
|
|
|
static const struct kset_uevent_ops dlm_uevent_ops = {
|
2010-02-17 09:41:34 +00:00
|
|
|
.uevent = dlm_uevent,
|
|
|
|
};
|
2006-01-18 09:30:29 +00:00
|
|
|
|
2008-02-01 17:53:46 +00:00
|
|
|
int __init dlm_lockspace_init(void)
|
2006-01-18 09:30:29 +00:00
|
|
|
{
|
|
|
|
ls_count = 0;
|
2006-01-20 08:47:07 +00:00
|
|
|
mutex_init(&ls_lock);
|
2006-01-18 09:30:29 +00:00
|
|
|
INIT_LIST_HEAD(&lslist);
|
|
|
|
spin_lock_init(&lslist_lock);
|
|
|
|
|
2010-02-17 09:41:34 +00:00
|
|
|
dlm_kset = kset_create_and_add("dlm", &dlm_uevent_ops, kernel_kobj);
|
2007-10-29 19:13:17 +00:00
|
|
|
if (!dlm_kset) {
|
2008-04-30 07:55:09 +00:00
|
|
|
printk(KERN_WARNING "%s: can not create kset\n", __func__);
|
2007-10-29 19:13:17 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
return 0;
|
2006-01-18 09:30:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void dlm_lockspace_exit(void)
|
|
|
|
{
|
2007-10-29 19:13:17 +00:00
|
|
|
kset_unregister(dlm_kset);
|
2006-01-18 09:30:29 +00:00
|
|
|
}
|
|
|
|
|
2008-08-18 19:03:25 +00:00
|
|
|
static struct dlm_ls *find_ls_to_scan(void)
|
|
|
|
{
|
|
|
|
struct dlm_ls *ls;
|
|
|
|
|
|
|
|
spin_lock(&lslist_lock);
|
|
|
|
list_for_each_entry(ls, &lslist, ls_list) {
|
|
|
|
if (time_after_eq(jiffies, ls->ls_scan_time +
|
|
|
|
dlm_config.ci_scan_secs * HZ)) {
|
|
|
|
spin_unlock(&lslist_lock);
|
|
|
|
return ls;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
spin_unlock(&lslist_lock);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-01-18 09:30:29 +00:00
|
|
|
static int dlm_scand(void *data)
|
|
|
|
{
|
|
|
|
struct dlm_ls *ls;
|
|
|
|
|
|
|
|
while (!kthread_should_stop()) {
|
2008-08-18 19:03:25 +00:00
|
|
|
ls = find_ls_to_scan();
|
|
|
|
if (ls) {
|
2007-05-18 13:58:15 +00:00
|
|
|
if (dlm_lock_recovery_try(ls)) {
|
2008-08-18 19:03:25 +00:00
|
|
|
ls->ls_scan_time = jiffies;
|
2007-05-18 13:58:15 +00:00
|
|
|
dlm_scan_rsbs(ls);
|
2007-05-18 13:59:31 +00:00
|
|
|
dlm_scan_timeout(ls);
|
2011-03-28 19:17:26 +00:00
|
|
|
dlm_scan_waiters(ls);
|
2007-05-18 13:58:15 +00:00
|
|
|
dlm_unlock_recovery(ls);
|
2008-08-18 19:03:25 +00:00
|
|
|
} else {
|
|
|
|
ls->ls_scan_time += HZ;
|
2007-05-18 13:58:15 +00:00
|
|
|
}
|
2011-03-28 19:17:26 +00:00
|
|
|
continue;
|
2007-05-18 13:58:15 +00:00
|
|
|
}
|
2011-03-28 19:17:26 +00:00
|
|
|
schedule_timeout_interruptible(dlm_config.ci_scan_secs * HZ);
|
2006-01-18 09:30:29 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dlm_scand_start(void)
|
|
|
|
{
|
|
|
|
struct task_struct *p;
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
p = kthread_run(dlm_scand, NULL, "dlm_scand");
|
|
|
|
if (IS_ERR(p))
|
|
|
|
error = PTR_ERR(p);
|
|
|
|
else
|
|
|
|
scand_task = p;
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dlm_scand_stop(void)
|
|
|
|
{
|
|
|
|
kthread_stop(scand_task);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct dlm_ls *dlm_find_lockspace_global(uint32_t id)
|
|
|
|
{
|
|
|
|
struct dlm_ls *ls;
|
|
|
|
|
|
|
|
spin_lock(&lslist_lock);
|
|
|
|
|
|
|
|
list_for_each_entry(ls, &lslist, ls_list) {
|
|
|
|
if (ls->ls_global_id == id) {
|
|
|
|
ls->ls_count++;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ls = NULL;
|
|
|
|
out:
|
|
|
|
spin_unlock(&lslist_lock);
|
|
|
|
return ls;
|
|
|
|
}
|
|
|
|
|
2006-07-12 21:44:04 +00:00
|
|
|
struct dlm_ls *dlm_find_lockspace_local(dlm_lockspace_t *lockspace)
|
2006-01-18 09:30:29 +00:00
|
|
|
{
|
2006-07-12 21:44:04 +00:00
|
|
|
struct dlm_ls *ls;
|
2006-01-18 09:30:29 +00:00
|
|
|
|
|
|
|
spin_lock(&lslist_lock);
|
2006-07-12 21:44:04 +00:00
|
|
|
list_for_each_entry(ls, &lslist, ls_list) {
|
|
|
|
if (ls->ls_local_handle == lockspace) {
|
|
|
|
ls->ls_count++;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ls = NULL;
|
|
|
|
out:
|
|
|
|
spin_unlock(&lslist_lock);
|
|
|
|
return ls;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct dlm_ls *dlm_find_lockspace_device(int minor)
|
|
|
|
{
|
|
|
|
struct dlm_ls *ls;
|
|
|
|
|
|
|
|
spin_lock(&lslist_lock);
|
|
|
|
list_for_each_entry(ls, &lslist, ls_list) {
|
|
|
|
if (ls->ls_device.minor == minor) {
|
|
|
|
ls->ls_count++;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ls = NULL;
|
|
|
|
out:
|
2006-01-18 09:30:29 +00:00
|
|
|
spin_unlock(&lslist_lock);
|
|
|
|
return ls;
|
|
|
|
}
|
|
|
|
|
|
|
|
void dlm_put_lockspace(struct dlm_ls *ls)
|
|
|
|
{
|
|
|
|
spin_lock(&lslist_lock);
|
|
|
|
ls->ls_count--;
|
|
|
|
spin_unlock(&lslist_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void remove_lockspace(struct dlm_ls *ls)
|
|
|
|
{
|
|
|
|
for (;;) {
|
|
|
|
spin_lock(&lslist_lock);
|
|
|
|
if (ls->ls_count == 0) {
|
2008-08-06 18:30:24 +00:00
|
|
|
WARN_ON(ls->ls_create_count != 0);
|
2006-01-18 09:30:29 +00:00
|
|
|
list_del(&ls->ls_list);
|
|
|
|
spin_unlock(&lslist_lock);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
spin_unlock(&lslist_lock);
|
|
|
|
ssleep(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int threads_start(void)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = dlm_scand_start();
|
|
|
|
if (error) {
|
|
|
|
log_print("cannot start dlm_scand thread %d", error);
|
2011-04-05 18:16:24 +00:00
|
|
|
goto fail;
|
2006-01-18 09:30:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Thread for sending/receiving messages for all lockspace's */
|
2021-05-21 19:08:41 +00:00
|
|
|
error = dlm_midcomms_start();
|
2006-01-18 09:30:29 +00:00
|
|
|
if (error) {
|
|
|
|
log_print("cannot start dlm lowcomms %d", error);
|
|
|
|
goto scand_fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
scand_fail:
|
|
|
|
dlm_scand_stop();
|
|
|
|
fail:
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2011-11-02 19:30:58 +00:00
|
|
|
static int new_lockspace(const char *name, const char *cluster,
|
|
|
|
uint32_t flags, int lvblen,
|
|
|
|
const struct dlm_lockspace_ops *ops, void *ops_arg,
|
|
|
|
int *ops_result, dlm_lockspace_t **lockspace)
|
2006-01-18 09:30:29 +00:00
|
|
|
{
|
|
|
|
struct dlm_ls *ls;
|
2008-08-06 18:30:24 +00:00
|
|
|
int i, size, error;
|
2007-05-18 14:02:20 +00:00
|
|
|
int do_unreg = 0;
|
2011-11-02 19:30:58 +00:00
|
|
|
int namelen = strlen(name);
|
2006-01-18 09:30:29 +00:00
|
|
|
|
2018-11-02 20:18:21 +00:00
|
|
|
if (namelen > DLM_LOCKSPACE_LEN || namelen == 0)
|
2006-01-18 09:30:29 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (!lvblen || (lvblen % 8))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (!try_module_get(THIS_MODULE))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2008-08-18 16:43:30 +00:00
|
|
|
if (!dlm_user_daemon_available()) {
|
2011-11-02 19:30:58 +00:00
|
|
|
log_print("dlm user daemon not available");
|
|
|
|
error = -EUNATCH;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ops && ops_result) {
|
|
|
|
if (!dlm_config.ci_recover_callbacks)
|
|
|
|
*ops_result = -EOPNOTSUPP;
|
|
|
|
else
|
|
|
|
*ops_result = 0;
|
|
|
|
}
|
|
|
|
|
2017-07-11 14:26:55 +00:00
|
|
|
if (!cluster)
|
|
|
|
log_print("dlm cluster name '%s' is being used without an application provided cluster name",
|
|
|
|
dlm_config.ci_cluster_name);
|
|
|
|
|
2011-11-02 19:30:58 +00:00
|
|
|
if (dlm_config.ci_recover_callbacks && cluster &&
|
|
|
|
strncmp(cluster, dlm_config.ci_cluster_name, DLM_LOCKSPACE_LEN)) {
|
2017-05-18 02:42:12 +00:00
|
|
|
log_print("dlm cluster name '%s' does not match "
|
|
|
|
"the application cluster name '%s'",
|
2011-11-02 19:30:58 +00:00
|
|
|
dlm_config.ci_cluster_name, cluster);
|
|
|
|
error = -EBADR;
|
|
|
|
goto out;
|
2008-08-18 16:43:30 +00:00
|
|
|
}
|
|
|
|
|
2008-08-06 18:30:24 +00:00
|
|
|
error = 0;
|
|
|
|
|
|
|
|
spin_lock(&lslist_lock);
|
|
|
|
list_for_each_entry(ls, &lslist, ls_list) {
|
|
|
|
WARN_ON(ls->ls_create_count <= 0);
|
|
|
|
if (ls->ls_namelen != namelen)
|
|
|
|
continue;
|
|
|
|
if (memcmp(ls->ls_name, name, namelen))
|
|
|
|
continue;
|
|
|
|
if (flags & DLM_LSFL_NEWEXCL) {
|
|
|
|
error = -EEXIST;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ls->ls_create_count++;
|
2009-04-08 20:38:43 +00:00
|
|
|
*lockspace = ls;
|
|
|
|
error = 1;
|
2008-08-06 18:30:24 +00:00
|
|
|
break;
|
2006-01-18 09:30:29 +00:00
|
|
|
}
|
2008-08-06 18:30:24 +00:00
|
|
|
spin_unlock(&lslist_lock);
|
|
|
|
|
|
|
|
if (error)
|
2009-04-08 20:38:43 +00:00
|
|
|
goto out;
|
2008-08-06 18:30:24 +00:00
|
|
|
|
|
|
|
error = -ENOMEM;
|
2006-01-18 09:30:29 +00:00
|
|
|
|
2009-11-30 22:34:43 +00:00
|
|
|
ls = kzalloc(sizeof(struct dlm_ls) + namelen, GFP_NOFS);
|
2006-01-18 09:30:29 +00:00
|
|
|
if (!ls)
|
|
|
|
goto out;
|
|
|
|
memcpy(ls->ls_name, name, namelen);
|
|
|
|
ls->ls_namelen = namelen;
|
|
|
|
ls->ls_lvblen = lvblen;
|
|
|
|
ls->ls_count = 0;
|
|
|
|
ls->ls_flags = 0;
|
2008-08-18 19:03:25 +00:00
|
|
|
ls->ls_scan_time = jiffies;
|
2006-01-18 09:30:29 +00:00
|
|
|
|
2011-11-02 19:30:58 +00:00
|
|
|
if (ops && dlm_config.ci_recover_callbacks) {
|
|
|
|
ls->ls_ops = ops;
|
|
|
|
ls->ls_ops_arg = ops_arg;
|
|
|
|
}
|
|
|
|
|
2007-05-18 13:59:31 +00:00
|
|
|
if (flags & DLM_LSFL_TIMEWARN)
|
|
|
|
set_bit(LSFL_TIMEWARN, &ls->ls_flags);
|
|
|
|
|
2007-06-11 15:47:18 +00:00
|
|
|
/* ls_exflags are forced to match among nodes, and we don't
|
2008-08-06 18:30:24 +00:00
|
|
|
need to require all nodes to have some flags set */
|
|
|
|
ls->ls_exflags = (flags & ~(DLM_LSFL_TIMEWARN | DLM_LSFL_FS |
|
|
|
|
DLM_LSFL_NEWEXCL));
|
2007-06-11 15:47:18 +00:00
|
|
|
|
2021-07-16 20:22:35 +00:00
|
|
|
size = READ_ONCE(dlm_config.ci_rsbtbl_size);
|
2006-01-18 09:30:29 +00:00
|
|
|
ls->ls_rsbtbl_size = size;
|
|
|
|
|
treewide: Use array_size() in vmalloc()
The vmalloc() function has no 2-factor argument form, so multiplication
factors need to be wrapped in array_size(). This patch replaces cases of:
vmalloc(a * b)
with:
vmalloc(array_size(a, b))
as well as handling cases of:
vmalloc(a * b * c)
with:
vmalloc(array3_size(a, b, c))
This does, however, attempt to ignore constant size factors like:
vmalloc(4 * 1024)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@
(
vmalloc(
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
vmalloc(
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@
(
vmalloc(
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
vmalloc(
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
vmalloc(
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
vmalloc(
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
vmalloc(
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
vmalloc(
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
vmalloc(
- sizeof(char) * COUNT
+ COUNT
, ...)
|
vmalloc(
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
vmalloc(
- sizeof(TYPE) * (COUNT_ID)
+ array_size(COUNT_ID, sizeof(TYPE))
, ...)
|
vmalloc(
- sizeof(TYPE) * COUNT_ID
+ array_size(COUNT_ID, sizeof(TYPE))
, ...)
|
vmalloc(
- sizeof(TYPE) * (COUNT_CONST)
+ array_size(COUNT_CONST, sizeof(TYPE))
, ...)
|
vmalloc(
- sizeof(TYPE) * COUNT_CONST
+ array_size(COUNT_CONST, sizeof(TYPE))
, ...)
|
vmalloc(
- sizeof(THING) * (COUNT_ID)
+ array_size(COUNT_ID, sizeof(THING))
, ...)
|
vmalloc(
- sizeof(THING) * COUNT_ID
+ array_size(COUNT_ID, sizeof(THING))
, ...)
|
vmalloc(
- sizeof(THING) * (COUNT_CONST)
+ array_size(COUNT_CONST, sizeof(THING))
, ...)
|
vmalloc(
- sizeof(THING) * COUNT_CONST
+ array_size(COUNT_CONST, sizeof(THING))
, ...)
)
// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@
vmalloc(
- SIZE * COUNT
+ array_size(COUNT, SIZE)
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
vmalloc(
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
vmalloc(
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
vmalloc(
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
vmalloc(
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
vmalloc(
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
vmalloc(
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
vmalloc(
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
vmalloc(
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
vmalloc(
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
vmalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
vmalloc(
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
vmalloc(
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
vmalloc(
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
vmalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@
(
vmalloc(
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
vmalloc(
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
vmalloc(
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
vmalloc(
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
vmalloc(
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
vmalloc(
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
vmalloc(
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
vmalloc(
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
vmalloc(C1 * C2 * C3, ...)
|
vmalloc(
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants.
@@
expression E1, E2;
constant C1, C2;
@@
(
vmalloc(C1 * C2, ...)
|
vmalloc(
- E1 * E2
+ array_size(E1, E2)
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-12 21:27:11 +00:00
|
|
|
ls->ls_rsbtbl = vmalloc(array_size(size, sizeof(struct dlm_rsbtable)));
|
2006-01-18 09:30:29 +00:00
|
|
|
if (!ls->ls_rsbtbl)
|
|
|
|
goto out_lsfree;
|
|
|
|
for (i = 0; i < size; i++) {
|
2011-10-26 20:24:55 +00:00
|
|
|
ls->ls_rsbtbl[i].keep.rb_node = NULL;
|
|
|
|
ls->ls_rsbtbl[i].toss.rb_node = NULL;
|
2009-01-07 22:50:41 +00:00
|
|
|
spin_lock_init(&ls->ls_rsbtbl[i].lock);
|
2006-01-18 09:30:29 +00:00
|
|
|
}
|
|
|
|
|
2012-06-14 17:17:32 +00:00
|
|
|
spin_lock_init(&ls->ls_remove_spin);
|
|
|
|
|
|
|
|
for (i = 0; i < DLM_REMOVE_NAMES_MAX; i++) {
|
|
|
|
ls->ls_remove_names[i] = kzalloc(DLM_RESNAME_MAXLEN+1,
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!ls->ls_remove_names[i])
|
|
|
|
goto out_rsbtbl;
|
|
|
|
}
|
|
|
|
|
2011-07-06 22:00:54 +00:00
|
|
|
idr_init(&ls->ls_lkbidr);
|
|
|
|
spin_lock_init(&ls->ls_lkbidr_spin);
|
2006-01-18 09:30:29 +00:00
|
|
|
|
|
|
|
INIT_LIST_HEAD(&ls->ls_waiters);
|
2006-01-20 08:47:07 +00:00
|
|
|
mutex_init(&ls->ls_waiters_mutex);
|
2007-03-28 14:56:46 +00:00
|
|
|
INIT_LIST_HEAD(&ls->ls_orphans);
|
|
|
|
mutex_init(&ls->ls_orphans_mutex);
|
2007-05-18 13:59:31 +00:00
|
|
|
INIT_LIST_HEAD(&ls->ls_timeout);
|
|
|
|
mutex_init(&ls->ls_timeout_mutex);
|
2006-01-18 09:30:29 +00:00
|
|
|
|
2011-07-07 19:05:03 +00:00
|
|
|
INIT_LIST_HEAD(&ls->ls_new_rsb);
|
|
|
|
spin_lock_init(&ls->ls_new_rsb_spin);
|
|
|
|
|
2006-01-18 09:30:29 +00:00
|
|
|
INIT_LIST_HEAD(&ls->ls_nodes);
|
|
|
|
INIT_LIST_HEAD(&ls->ls_nodes_gone);
|
|
|
|
ls->ls_num_nodes = 0;
|
|
|
|
ls->ls_low_nodeid = 0;
|
|
|
|
ls->ls_total_weight = 0;
|
|
|
|
ls->ls_node_array = NULL;
|
|
|
|
|
|
|
|
memset(&ls->ls_stub_rsb, 0, sizeof(struct dlm_rsb));
|
|
|
|
ls->ls_stub_rsb.res_ls = ls;
|
|
|
|
|
2006-07-25 18:44:31 +00:00
|
|
|
ls->ls_debug_rsb_dentry = NULL;
|
|
|
|
ls->ls_debug_waiters_dentry = NULL;
|
2006-01-18 09:30:29 +00:00
|
|
|
|
|
|
|
init_waitqueue_head(&ls->ls_uevent_wait);
|
|
|
|
ls->ls_uevent_result = 0;
|
2007-05-18 14:03:35 +00:00
|
|
|
init_completion(&ls->ls_members_done);
|
|
|
|
ls->ls_members_result = -1;
|
2006-01-18 09:30:29 +00:00
|
|
|
|
2011-04-05 18:16:24 +00:00
|
|
|
mutex_init(&ls->ls_cb_mutex);
|
|
|
|
INIT_LIST_HEAD(&ls->ls_cb_delay);
|
|
|
|
|
2006-01-18 09:30:29 +00:00
|
|
|
ls->ls_recoverd_task = NULL;
|
2006-01-20 08:47:07 +00:00
|
|
|
mutex_init(&ls->ls_recoverd_active);
|
2006-01-18 09:30:29 +00:00
|
|
|
spin_lock_init(&ls->ls_recover_lock);
|
2006-11-27 19:19:28 +00:00
|
|
|
spin_lock_init(&ls->ls_rcom_spin);
|
|
|
|
get_random_bytes(&ls->ls_rcom_seq, sizeof(uint64_t));
|
2006-01-18 09:30:29 +00:00
|
|
|
ls->ls_recover_status = 0;
|
|
|
|
ls->ls_recover_seq = 0;
|
|
|
|
ls->ls_recover_args = NULL;
|
|
|
|
init_rwsem(&ls->ls_in_recovery);
|
2007-09-27 20:53:38 +00:00
|
|
|
init_rwsem(&ls->ls_recv_active);
|
2006-01-18 09:30:29 +00:00
|
|
|
INIT_LIST_HEAD(&ls->ls_requestqueue);
|
2006-01-20 08:47:07 +00:00
|
|
|
mutex_init(&ls->ls_requestqueue_mutex);
|
2006-07-12 21:44:04 +00:00
|
|
|
mutex_init(&ls->ls_clear_proc_locks);
|
2006-01-18 09:30:29 +00:00
|
|
|
|
2021-05-21 19:08:46 +00:00
|
|
|
/* Due backwards compatibility with 3.1 we need to use maximum
|
|
|
|
* possible dlm message size to be sure the message will fit and
|
|
|
|
* not having out of bounds issues. However on sending side 3.2
|
|
|
|
* might send less.
|
|
|
|
*/
|
2021-06-02 13:45:20 +00:00
|
|
|
ls->ls_recover_buf = kmalloc(DLM_MAX_SOCKET_BUFSIZE, GFP_NOFS);
|
2006-01-18 09:30:29 +00:00
|
|
|
if (!ls->ls_recover_buf)
|
2012-06-14 17:17:32 +00:00
|
|
|
goto out_lkbidr;
|
2006-01-18 09:30:29 +00:00
|
|
|
|
2011-10-20 18:26:28 +00:00
|
|
|
ls->ls_slot = 0;
|
|
|
|
ls->ls_num_slots = 0;
|
|
|
|
ls->ls_slots_size = 0;
|
|
|
|
ls->ls_slots = NULL;
|
|
|
|
|
2006-01-18 09:30:29 +00:00
|
|
|
INIT_LIST_HEAD(&ls->ls_recover_list);
|
|
|
|
spin_lock_init(&ls->ls_recover_list_lock);
|
2012-05-15 21:07:49 +00:00
|
|
|
idr_init(&ls->ls_recover_idr);
|
|
|
|
spin_lock_init(&ls->ls_recover_idr_lock);
|
2006-01-18 09:30:29 +00:00
|
|
|
ls->ls_recover_list_count = 0;
|
2006-07-12 21:44:04 +00:00
|
|
|
ls->ls_local_handle = ls;
|
2006-01-18 09:30:29 +00:00
|
|
|
init_waitqueue_head(&ls->ls_wait_general);
|
|
|
|
INIT_LIST_HEAD(&ls->ls_root_list);
|
|
|
|
init_rwsem(&ls->ls_root_sem);
|
|
|
|
|
2006-08-24 19:47:20 +00:00
|
|
|
spin_lock(&lslist_lock);
|
2008-08-06 18:30:24 +00:00
|
|
|
ls->ls_create_count = 1;
|
2006-08-24 19:47:20 +00:00
|
|
|
list_add(&ls->ls_list, &lslist);
|
|
|
|
spin_unlock(&lslist_lock);
|
|
|
|
|
2011-04-05 18:16:24 +00:00
|
|
|
if (flags & DLM_LSFL_FS) {
|
|
|
|
error = dlm_callback_start(ls);
|
|
|
|
if (error) {
|
|
|
|
log_error(ls, "can't start dlm_callback %d", error);
|
|
|
|
goto out_delist;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-02 16:08:21 +00:00
|
|
|
init_waitqueue_head(&ls->ls_recover_lock_wait);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Once started, dlm_recoverd first looks for ls in lslist, then
|
|
|
|
* initializes ls_in_recovery as locked in "down" mode. We need
|
|
|
|
* to wait for the wakeup from dlm_recoverd because in_recovery
|
|
|
|
* has to start out in down mode.
|
|
|
|
*/
|
|
|
|
|
2006-01-18 09:30:29 +00:00
|
|
|
error = dlm_recoverd_start(ls);
|
|
|
|
if (error) {
|
|
|
|
log_error(ls, "can't start dlm_recoverd %d", error);
|
2011-04-05 18:16:24 +00:00
|
|
|
goto out_callback;
|
2006-01-18 09:30:29 +00:00
|
|
|
}
|
|
|
|
|
2012-08-02 16:08:21 +00:00
|
|
|
wait_event(ls->ls_recover_lock_wait,
|
|
|
|
test_bit(LSFL_RECOVER_LOCK, &ls->ls_flags));
|
|
|
|
|
2020-06-15 03:25:33 +00:00
|
|
|
/* let kobject handle freeing of ls if there's an error */
|
|
|
|
do_unreg = 1;
|
|
|
|
|
2007-12-17 19:54:39 +00:00
|
|
|
ls->ls_kobj.kset = dlm_kset;
|
|
|
|
error = kobject_init_and_add(&ls->ls_kobj, &dlm_ktype, NULL,
|
|
|
|
"%s", ls->ls_name);
|
2006-01-18 09:30:29 +00:00
|
|
|
if (error)
|
2011-04-05 18:16:24 +00:00
|
|
|
goto out_recoverd;
|
2007-12-17 19:54:39 +00:00
|
|
|
kobject_uevent(&ls->ls_kobj, KOBJ_ADD);
|
2007-05-18 14:02:20 +00:00
|
|
|
|
2007-05-18 14:03:35 +00:00
|
|
|
/* This uevent triggers dlm_controld in userspace to add us to the
|
|
|
|
group of nodes that are members of this lockspace (managed by the
|
|
|
|
cluster infrastructure.) Once it's done that, it tells us who the
|
|
|
|
current lockspace members are (via configfs) and then tells the
|
|
|
|
lockspace to start running (via sysfs) in dlm_ls_start(). */
|
|
|
|
|
2006-01-18 09:30:29 +00:00
|
|
|
error = do_uevent(ls, 1);
|
|
|
|
if (error)
|
2011-04-05 18:16:24 +00:00
|
|
|
goto out_recoverd;
|
2007-05-18 14:02:20 +00:00
|
|
|
|
2007-05-18 14:03:35 +00:00
|
|
|
wait_for_completion(&ls->ls_members_done);
|
|
|
|
error = ls->ls_members_result;
|
|
|
|
if (error)
|
|
|
|
goto out_members;
|
|
|
|
|
2007-05-18 14:02:20 +00:00
|
|
|
dlm_create_debug_file(ls);
|
|
|
|
|
2014-02-14 17:54:44 +00:00
|
|
|
log_rinfo(ls, "join complete");
|
2006-01-18 09:30:29 +00:00
|
|
|
*lockspace = ls;
|
|
|
|
return 0;
|
|
|
|
|
2007-05-18 14:03:35 +00:00
|
|
|
out_members:
|
|
|
|
do_uevent(ls, 0);
|
|
|
|
dlm_clear_members(ls);
|
|
|
|
kfree(ls->ls_node_array);
|
2011-04-05 18:16:24 +00:00
|
|
|
out_recoverd:
|
2006-08-24 19:47:20 +00:00
|
|
|
dlm_recoverd_stop(ls);
|
2011-04-05 18:16:24 +00:00
|
|
|
out_callback:
|
|
|
|
dlm_callback_stop(ls);
|
2007-05-18 14:02:20 +00:00
|
|
|
out_delist:
|
2006-01-18 09:30:29 +00:00
|
|
|
spin_lock(&lslist_lock);
|
|
|
|
list_del(&ls->ls_list);
|
|
|
|
spin_unlock(&lslist_lock);
|
2012-05-15 21:07:49 +00:00
|
|
|
idr_destroy(&ls->ls_recover_idr);
|
2006-01-18 09:30:29 +00:00
|
|
|
kfree(ls->ls_recover_buf);
|
2012-06-14 17:17:32 +00:00
|
|
|
out_lkbidr:
|
2011-07-06 22:00:54 +00:00
|
|
|
idr_destroy(&ls->ls_lkbidr);
|
2018-11-15 10:15:05 +00:00
|
|
|
out_rsbtbl:
|
2018-12-03 16:02:01 +00:00
|
|
|
for (i = 0; i < DLM_REMOVE_NAMES_MAX; i++)
|
|
|
|
kfree(ls->ls_remove_names[i]);
|
2011-07-01 20:49:23 +00:00
|
|
|
vfree(ls->ls_rsbtbl);
|
2006-01-18 09:30:29 +00:00
|
|
|
out_lsfree:
|
2007-05-18 14:02:20 +00:00
|
|
|
if (do_unreg)
|
2007-12-20 16:13:05 +00:00
|
|
|
kobject_put(&ls->ls_kobj);
|
2007-05-18 14:02:20 +00:00
|
|
|
else
|
|
|
|
kfree(ls);
|
2006-01-18 09:30:29 +00:00
|
|
|
out:
|
|
|
|
module_put(THIS_MODULE);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2011-11-02 19:30:58 +00:00
|
|
|
int dlm_new_lockspace(const char *name, const char *cluster,
|
|
|
|
uint32_t flags, int lvblen,
|
|
|
|
const struct dlm_lockspace_ops *ops, void *ops_arg,
|
|
|
|
int *ops_result, dlm_lockspace_t **lockspace)
|
2006-01-18 09:30:29 +00:00
|
|
|
{
|
|
|
|
int error = 0;
|
|
|
|
|
2006-01-20 08:47:07 +00:00
|
|
|
mutex_lock(&ls_lock);
|
2006-01-18 09:30:29 +00:00
|
|
|
if (!ls_count)
|
|
|
|
error = threads_start();
|
|
|
|
if (error)
|
|
|
|
goto out;
|
|
|
|
|
2011-11-02 19:30:58 +00:00
|
|
|
error = new_lockspace(name, cluster, flags, lvblen, ops, ops_arg,
|
|
|
|
ops_result, lockspace);
|
2006-01-18 09:30:29 +00:00
|
|
|
if (!error)
|
|
|
|
ls_count++;
|
2009-04-08 20:38:43 +00:00
|
|
|
if (error > 0)
|
|
|
|
error = 0;
|
2021-03-01 22:05:20 +00:00
|
|
|
if (!ls_count) {
|
|
|
|
dlm_scand_stop();
|
2021-05-21 19:08:41 +00:00
|
|
|
dlm_midcomms_shutdown();
|
2021-03-01 22:05:20 +00:00
|
|
|
dlm_lowcomms_stop();
|
|
|
|
}
|
2006-01-18 09:30:29 +00:00
|
|
|
out:
|
2006-01-20 08:47:07 +00:00
|
|
|
mutex_unlock(&ls_lock);
|
2006-01-18 09:30:29 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2011-07-06 22:00:54 +00:00
|
|
|
static int lkb_idr_is_local(int id, void *p, void *data)
|
2006-01-18 09:30:29 +00:00
|
|
|
{
|
2011-07-06 22:00:54 +00:00
|
|
|
struct dlm_lkb *lkb = p;
|
|
|
|
|
2013-10-16 12:20:25 +00:00
|
|
|
return lkb->lkb_nodeid == 0 && lkb->lkb_grmode != DLM_LOCK_IV;
|
2011-07-06 22:00:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int lkb_idr_is_any(int id, void *p, void *data)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int lkb_idr_free(int id, void *p, void *data)
|
|
|
|
{
|
|
|
|
struct dlm_lkb *lkb = p;
|
|
|
|
|
|
|
|
if (lkb->lkb_lvbptr && lkb->lkb_flags & DLM_IFL_MSTCPY)
|
|
|
|
dlm_free_lvb(lkb->lkb_lvbptr);
|
|
|
|
|
|
|
|
dlm_free_lkb(lkb);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* NOTE: We check the lkbidr here rather than the resource table.
|
|
|
|
This is because there may be LKBs queued as ASTs that have been unlinked
|
|
|
|
from their RSBs and are pending deletion once the AST has been delivered */
|
|
|
|
|
|
|
|
static int lockspace_busy(struct dlm_ls *ls, int force)
|
|
|
|
{
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
spin_lock(&ls->ls_lkbidr_spin);
|
|
|
|
if (force == 0) {
|
|
|
|
rv = idr_for_each(&ls->ls_lkbidr, lkb_idr_is_any, ls);
|
|
|
|
} else if (force == 1) {
|
|
|
|
rv = idr_for_each(&ls->ls_lkbidr, lkb_idr_is_local, ls);
|
|
|
|
} else {
|
|
|
|
rv = 0;
|
2006-01-18 09:30:29 +00:00
|
|
|
}
|
2011-07-06 22:00:54 +00:00
|
|
|
spin_unlock(&ls->ls_lkbidr_spin);
|
|
|
|
return rv;
|
2006-01-18 09:30:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int release_lockspace(struct dlm_ls *ls, int force)
|
|
|
|
{
|
|
|
|
struct dlm_rsb *rsb;
|
2011-10-26 20:24:55 +00:00
|
|
|
struct rb_node *n;
|
2008-08-06 18:30:24 +00:00
|
|
|
int i, busy, rv;
|
|
|
|
|
2011-07-06 22:00:54 +00:00
|
|
|
busy = lockspace_busy(ls, force);
|
2008-08-06 18:30:24 +00:00
|
|
|
|
|
|
|
spin_lock(&lslist_lock);
|
|
|
|
if (ls->ls_create_count == 1) {
|
2011-07-06 22:00:54 +00:00
|
|
|
if (busy) {
|
2008-08-06 18:30:24 +00:00
|
|
|
rv = -EBUSY;
|
2011-07-06 22:00:54 +00:00
|
|
|
} else {
|
2008-08-06 18:30:24 +00:00
|
|
|
/* remove_lockspace takes ls off lslist */
|
|
|
|
ls->ls_create_count = 0;
|
|
|
|
rv = 0;
|
|
|
|
}
|
|
|
|
} else if (ls->ls_create_count > 1) {
|
|
|
|
rv = --ls->ls_create_count;
|
|
|
|
} else {
|
|
|
|
rv = -EINVAL;
|
|
|
|
}
|
|
|
|
spin_unlock(&lslist_lock);
|
|
|
|
|
|
|
|
if (rv) {
|
|
|
|
log_debug(ls, "release_lockspace no remove %d", rv);
|
|
|
|
return rv;
|
|
|
|
}
|
2006-01-18 09:30:29 +00:00
|
|
|
|
2008-08-06 18:30:24 +00:00
|
|
|
dlm_device_deregister(ls);
|
2006-01-18 09:30:29 +00:00
|
|
|
|
2008-08-18 16:43:30 +00:00
|
|
|
if (force < 3 && dlm_user_daemon_available())
|
2006-01-18 09:30:29 +00:00
|
|
|
do_uevent(ls, 0);
|
|
|
|
|
|
|
|
dlm_recoverd_stop(ls);
|
|
|
|
|
2021-03-01 22:05:20 +00:00
|
|
|
if (ls_count == 1) {
|
|
|
|
dlm_scand_stop();
|
2021-08-26 14:06:31 +00:00
|
|
|
dlm_clear_members(ls);
|
2021-05-21 19:08:41 +00:00
|
|
|
dlm_midcomms_shutdown();
|
2021-03-01 22:05:20 +00:00
|
|
|
}
|
|
|
|
|
2011-04-05 18:16:24 +00:00
|
|
|
dlm_callback_stop(ls);
|
|
|
|
|
2006-01-18 09:30:29 +00:00
|
|
|
remove_lockspace(ls);
|
|
|
|
|
|
|
|
dlm_delete_debug_file(ls);
|
|
|
|
|
2018-11-15 17:17:40 +00:00
|
|
|
idr_destroy(&ls->ls_recover_idr);
|
2006-01-18 09:30:29 +00:00
|
|
|
kfree(ls->ls_recover_buf);
|
|
|
|
|
|
|
|
/*
|
2011-07-06 22:00:54 +00:00
|
|
|
* Free all lkb's in idr
|
2006-01-18 09:30:29 +00:00
|
|
|
*/
|
|
|
|
|
2011-07-06 22:00:54 +00:00
|
|
|
idr_for_each(&ls->ls_lkbidr, lkb_idr_free, ls);
|
|
|
|
idr_destroy(&ls->ls_lkbidr);
|
2006-01-18 09:30:29 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Free all rsb's on rsbtbl[] lists
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (i = 0; i < ls->ls_rsbtbl_size; i++) {
|
2011-10-26 20:24:55 +00:00
|
|
|
while ((n = rb_first(&ls->ls_rsbtbl[i].keep))) {
|
|
|
|
rsb = rb_entry(n, struct dlm_rsb, res_hashnode);
|
|
|
|
rb_erase(n, &ls->ls_rsbtbl[i].keep);
|
2007-11-07 15:06:49 +00:00
|
|
|
dlm_free_rsb(rsb);
|
2006-01-18 09:30:29 +00:00
|
|
|
}
|
|
|
|
|
2011-10-26 20:24:55 +00:00
|
|
|
while ((n = rb_first(&ls->ls_rsbtbl[i].toss))) {
|
|
|
|
rsb = rb_entry(n, struct dlm_rsb, res_hashnode);
|
|
|
|
rb_erase(n, &ls->ls_rsbtbl[i].toss);
|
2007-11-07 15:06:49 +00:00
|
|
|
dlm_free_rsb(rsb);
|
2006-01-18 09:30:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-01 20:49:23 +00:00
|
|
|
vfree(ls->ls_rsbtbl);
|
2006-01-18 09:30:29 +00:00
|
|
|
|
2012-06-14 17:17:32 +00:00
|
|
|
for (i = 0; i < DLM_REMOVE_NAMES_MAX; i++)
|
|
|
|
kfree(ls->ls_remove_names[i]);
|
|
|
|
|
2011-07-07 19:05:03 +00:00
|
|
|
while (!list_empty(&ls->ls_new_rsb)) {
|
|
|
|
rsb = list_first_entry(&ls->ls_new_rsb, struct dlm_rsb,
|
|
|
|
res_hashchain);
|
|
|
|
list_del(&rsb->res_hashchain);
|
|
|
|
dlm_free_rsb(rsb);
|
|
|
|
}
|
|
|
|
|
2006-01-18 09:30:29 +00:00
|
|
|
/*
|
|
|
|
* Free structures on any other lists
|
|
|
|
*/
|
|
|
|
|
2006-11-27 17:31:22 +00:00
|
|
|
dlm_purge_requestqueue(ls);
|
2006-01-18 09:30:29 +00:00
|
|
|
kfree(ls->ls_recover_args);
|
|
|
|
dlm_clear_members(ls);
|
|
|
|
dlm_clear_members_gone(ls);
|
|
|
|
kfree(ls->ls_node_array);
|
2014-02-14 17:54:44 +00:00
|
|
|
log_rinfo(ls, "release_lockspace final free");
|
2007-12-20 16:13:05 +00:00
|
|
|
kobject_put(&ls->ls_kobj);
|
2007-05-18 14:02:20 +00:00
|
|
|
/* The ls structure will be freed when the kobject is done with */
|
2006-01-18 09:30:29 +00:00
|
|
|
|
|
|
|
module_put(THIS_MODULE);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called when a system has released all its locks and is not going to use the
|
|
|
|
* lockspace any longer. We free everything we're managing for this lockspace.
|
|
|
|
* Remaining nodes will go through the recovery process as if we'd died. The
|
|
|
|
* lockspace must continue to function as usual, participating in recoveries,
|
|
|
|
* until this returns.
|
|
|
|
*
|
|
|
|
* Force has 4 possible values:
|
|
|
|
* 0 - don't destroy locksapce if it has any LKBs
|
|
|
|
* 1 - destroy lockspace if it has remote LKBs but not if it has local LKBs
|
|
|
|
* 2 - destroy lockspace regardless of LKBs
|
|
|
|
* 3 - destroy lockspace as part of a forced shutdown
|
|
|
|
*/
|
|
|
|
|
|
|
|
int dlm_release_lockspace(void *lockspace, int force)
|
|
|
|
{
|
|
|
|
struct dlm_ls *ls;
|
2008-08-06 18:30:24 +00:00
|
|
|
int error;
|
2006-01-18 09:30:29 +00:00
|
|
|
|
|
|
|
ls = dlm_find_lockspace_local(lockspace);
|
|
|
|
if (!ls)
|
|
|
|
return -EINVAL;
|
|
|
|
dlm_put_lockspace(ls);
|
2008-08-06 18:30:24 +00:00
|
|
|
|
|
|
|
mutex_lock(&ls_lock);
|
|
|
|
error = release_lockspace(ls, force);
|
|
|
|
if (!error)
|
|
|
|
ls_count--;
|
2008-11-13 19:22:34 +00:00
|
|
|
if (!ls_count)
|
2021-03-01 22:05:20 +00:00
|
|
|
dlm_lowcomms_stop();
|
2008-08-06 18:30:24 +00:00
|
|
|
mutex_unlock(&ls_lock);
|
|
|
|
|
|
|
|
return error;
|
2006-01-18 09:30:29 +00:00
|
|
|
}
|
|
|
|
|
2008-08-18 16:43:30 +00:00
|
|
|
void dlm_stop_lockspaces(void)
|
|
|
|
{
|
|
|
|
struct dlm_ls *ls;
|
2013-06-25 17:48:01 +00:00
|
|
|
int count;
|
2008-08-18 16:43:30 +00:00
|
|
|
|
|
|
|
restart:
|
2013-06-25 17:48:01 +00:00
|
|
|
count = 0;
|
2008-08-18 16:43:30 +00:00
|
|
|
spin_lock(&lslist_lock);
|
|
|
|
list_for_each_entry(ls, &lslist, ls_list) {
|
2013-06-25 17:48:01 +00:00
|
|
|
if (!test_bit(LSFL_RUNNING, &ls->ls_flags)) {
|
|
|
|
count++;
|
2008-08-18 16:43:30 +00:00
|
|
|
continue;
|
2013-06-25 17:48:01 +00:00
|
|
|
}
|
2008-08-18 16:43:30 +00:00
|
|
|
spin_unlock(&lslist_lock);
|
|
|
|
log_error(ls, "no userland control daemon, stopping lockspace");
|
|
|
|
dlm_ls_stop(ls);
|
|
|
|
goto restart;
|
|
|
|
}
|
|
|
|
spin_unlock(&lslist_lock);
|
2013-06-25 17:48:01 +00:00
|
|
|
|
|
|
|
if (count)
|
|
|
|
log_print("dlm user daemon left %d lockspaces", count);
|
2008-08-18 16:43:30 +00:00
|
|
|
}
|
|
|
|
|