VisionFive2 Linux kernel

StarFive Tech Linux Kernel for VisionFive (JH7110) boards (mirror)

More than 9999 Commits   35 Branches   59 Tags
2522fe45a186e (Thomas Gleixner    2019-05-28 09:57:20 -0700   1) // SPDX-License-Identifier: GPL-2.0-only
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000   2) /******************************************************************************
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000   3) *******************************************************************************
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000   4) **
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000   5) **  Copyright (C) Sistina Software, Inc.  1997-2003  All rights reserved.
60f98d1839376 (David Teigland     2011-11-02 14:30:58 -0500   6) **  Copyright (C) 2004-2011 Red Hat, Inc.  All rights reserved.
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000   7) **
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000   8) **
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000   9) *******************************************************************************
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000  10) ******************************************************************************/
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000  11) 
7963b8a59845e (Paul Gortmaker     2016-09-19 16:44:50 -0400  12) #include <linux/module.h>
7963b8a59845e (Paul Gortmaker     2016-09-19 16:44:50 -0400  13) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000  14) #include "dlm_internal.h"
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000  15) #include "lockspace.h"
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000  16) #include "member.h"
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000  17) #include "recoverd.h"
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000  18) #include "dir.h"
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000  19) #include "lowcomms.h"
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000  20) #include "config.h"
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000  21) #include "memory.h"
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000  22) #include "lock.h"
c56b39cd2c55d (David Teigland     2006-04-28 10:51:53 -0400  23) #include "recover.h"
2896ee37ccc1f (David Teigland     2006-11-27 11:31:22 -0600  24) #include "requestqueue.h"
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500  25) #include "user.h"
23e8e1aaacb10 (David Teigland     2011-04-05 13:16:24 -0500  26) #include "ast.h"
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000  27) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000  28) static int			ls_count;
901359256b266 (David Teigland     2006-01-20 08:47:07 +0000  29) static struct mutex		ls_lock;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000  30) static struct list_head		lslist;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000  31) static spinlock_t		lslist_lock;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000  32) static struct task_struct *	scand_task;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000  33) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000  34) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000  35) static ssize_t dlm_control_store(struct dlm_ls *ls, const char *buf, size_t len)
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000  36) {
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000  37) 	ssize_t ret = len;
6edb56871a524 (Fabian Frederick   2014-06-06 14:38:25 -0700  38) 	int n;
6edb56871a524 (Fabian Frederick   2014-06-06 14:38:25 -0700  39) 	int rc = kstrtoint(buf, 0, &n);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000  40) 
6edb56871a524 (Fabian Frederick   2014-06-06 14:38:25 -0700  41) 	if (rc)
6edb56871a524 (Fabian Frederick   2014-06-06 14:38:25 -0700  42) 		return rc;
e2de7f565521a (Patrick Caulfield  2006-11-06 08:53:28 +0000  43) 	ls = dlm_find_lockspace_local(ls->ls_local_handle);
e2de7f565521a (Patrick Caulfield  2006-11-06 08:53:28 +0000  44) 	if (!ls)
e2de7f565521a (Patrick Caulfield  2006-11-06 08:53:28 +0000  45) 		return -EINVAL;
e2de7f565521a (Patrick Caulfield  2006-11-06 08:53:28 +0000  46) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000  47) 	switch (n) {
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000  48) 	case 0:
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000  49) 		dlm_ls_stop(ls);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000  50) 		break;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000  51) 	case 1:
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000  52) 		dlm_ls_start(ls);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000  53) 		break;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000  54) 	default:
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000  55) 		ret = -EINVAL;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000  56) 	}
e2de7f565521a (Patrick Caulfield  2006-11-06 08:53:28 +0000  57) 	dlm_put_lockspace(ls);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000  58) 	return ret;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000  59) }
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000  60) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000  61) static ssize_t dlm_event_store(struct dlm_ls *ls, const char *buf, size_t len)
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000  62) {
6edb56871a524 (Fabian Frederick   2014-06-06 14:38:25 -0700  63) 	int rc = kstrtoint(buf, 0, &ls->ls_uevent_result);
6edb56871a524 (Fabian Frederick   2014-06-06 14:38:25 -0700  64) 
6edb56871a524 (Fabian Frederick   2014-06-06 14:38:25 -0700  65) 	if (rc)
6edb56871a524 (Fabian Frederick   2014-06-06 14:38:25 -0700  66) 		return rc;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000  67) 	set_bit(LSFL_UEVENT_WAIT, &ls->ls_flags);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000  68) 	wake_up(&ls->ls_uevent_wait);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000  69) 	return len;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000  70) }
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000  71) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000  72) static ssize_t dlm_id_show(struct dlm_ls *ls, char *buf)
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000  73) {
a1d144c71ddc1 (David Teigland     2006-09-06 17:01:40 -0500  74) 	return snprintf(buf, PAGE_SIZE, "%u\n", ls->ls_global_id);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000  75) }
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000  76) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000  77) static ssize_t dlm_id_store(struct dlm_ls *ls, const char *buf, size_t len)
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000  78) {
6edb56871a524 (Fabian Frederick   2014-06-06 14:38:25 -0700  79) 	int rc = kstrtouint(buf, 0, &ls->ls_global_id);
6edb56871a524 (Fabian Frederick   2014-06-06 14:38:25 -0700  80) 
6edb56871a524 (Fabian Frederick   2014-06-06 14:38:25 -0700  81) 	if (rc)
6edb56871a524 (Fabian Frederick   2014-06-06 14:38:25 -0700  82) 		return rc;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000  83) 	return len;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000  84) }
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000  85) 
4875647a08e35 (David Teigland     2012-04-26 15:54:29 -0500  86) static ssize_t dlm_nodir_show(struct dlm_ls *ls, char *buf)
4875647a08e35 (David Teigland     2012-04-26 15:54:29 -0500  87) {
4875647a08e35 (David Teigland     2012-04-26 15:54:29 -0500  88) 	return snprintf(buf, PAGE_SIZE, "%u\n", dlm_no_directory(ls));
4875647a08e35 (David Teigland     2012-04-26 15:54:29 -0500  89) }
4875647a08e35 (David Teigland     2012-04-26 15:54:29 -0500  90) 
4875647a08e35 (David Teigland     2012-04-26 15:54:29 -0500  91) static ssize_t dlm_nodir_store(struct dlm_ls *ls, const char *buf, size_t len)
4875647a08e35 (David Teigland     2012-04-26 15:54:29 -0500  92) {
6edb56871a524 (Fabian Frederick   2014-06-06 14:38:25 -0700  93) 	int val;
6edb56871a524 (Fabian Frederick   2014-06-06 14:38:25 -0700  94) 	int rc = kstrtoint(buf, 0, &val);
6edb56871a524 (Fabian Frederick   2014-06-06 14:38:25 -0700  95) 
6edb56871a524 (Fabian Frederick   2014-06-06 14:38:25 -0700  96) 	if (rc)
6edb56871a524 (Fabian Frederick   2014-06-06 14:38:25 -0700  97) 		return rc;
4875647a08e35 (David Teigland     2012-04-26 15:54:29 -0500  98) 	if (val == 1)
4875647a08e35 (David Teigland     2012-04-26 15:54:29 -0500  99) 		set_bit(LSFL_NODIR, &ls->ls_flags);
4875647a08e35 (David Teigland     2012-04-26 15:54:29 -0500 100) 	return len;
4875647a08e35 (David Teigland     2012-04-26 15:54:29 -0500 101) }
4875647a08e35 (David Teigland     2012-04-26 15:54:29 -0500 102) 
c56b39cd2c55d (David Teigland     2006-04-28 10:51:53 -0400 103) static ssize_t dlm_recover_status_show(struct dlm_ls *ls, char *buf)
c56b39cd2c55d (David Teigland     2006-04-28 10:51:53 -0400 104) {
c56b39cd2c55d (David Teigland     2006-04-28 10:51:53 -0400 105) 	uint32_t status = dlm_recover_status(ls);
a1d144c71ddc1 (David Teigland     2006-09-06 17:01:40 -0500 106) 	return snprintf(buf, PAGE_SIZE, "%x\n", status);
c56b39cd2c55d (David Teigland     2006-04-28 10:51:53 -0400 107) }
c56b39cd2c55d (David Teigland     2006-04-28 10:51:53 -0400 108) 
faa0f2677287a (David Teigland     2006-08-08 17:08:42 -0500 109) static ssize_t dlm_recover_nodeid_show(struct dlm_ls *ls, char *buf)
faa0f2677287a (David Teigland     2006-08-08 17:08:42 -0500 110) {
a1d144c71ddc1 (David Teigland     2006-09-06 17:01:40 -0500 111) 	return snprintf(buf, PAGE_SIZE, "%d\n", ls->ls_recover_nodeid);
faa0f2677287a (David Teigland     2006-08-08 17:08:42 -0500 112) }
faa0f2677287a (David Teigland     2006-08-08 17:08:42 -0500 113) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 114) struct dlm_attr {
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 115) 	struct attribute attr;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 116) 	ssize_t (*show)(struct dlm_ls *, char *);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 117) 	ssize_t (*store)(struct dlm_ls *, const char *, size_t);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 118) };
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 119) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 120) static struct dlm_attr dlm_attr_control = {
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 121) 	.attr  = {.name = "control", .mode = S_IWUSR},
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 122) 	.store = dlm_control_store
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 123) };
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 124) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 125) static struct dlm_attr dlm_attr_event = {
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 126) 	.attr  = {.name = "event_done", .mode = S_IWUSR},
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 127) 	.store = dlm_event_store
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 128) };
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 129) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 130) static struct dlm_attr dlm_attr_id = {
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 131) 	.attr  = {.name = "id", .mode = S_IRUGO | S_IWUSR},
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 132) 	.show  = dlm_id_show,
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 133) 	.store = dlm_id_store
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 134) };
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 135) 
4875647a08e35 (David Teigland     2012-04-26 15:54:29 -0500 136) static struct dlm_attr dlm_attr_nodir = {
4875647a08e35 (David Teigland     2012-04-26 15:54:29 -0500 137) 	.attr  = {.name = "nodir", .mode = S_IRUGO | S_IWUSR},
4875647a08e35 (David Teigland     2012-04-26 15:54:29 -0500 138) 	.show  = dlm_nodir_show,
4875647a08e35 (David Teigland     2012-04-26 15:54:29 -0500 139) 	.store = dlm_nodir_store
4875647a08e35 (David Teigland     2012-04-26 15:54:29 -0500 140) };
4875647a08e35 (David Teigland     2012-04-26 15:54:29 -0500 141) 
c56b39cd2c55d (David Teigland     2006-04-28 10:51:53 -0400 142) static struct dlm_attr dlm_attr_recover_status = {
c56b39cd2c55d (David Teigland     2006-04-28 10:51:53 -0400 143) 	.attr  = {.name = "recover_status", .mode = S_IRUGO},
c56b39cd2c55d (David Teigland     2006-04-28 10:51:53 -0400 144) 	.show  = dlm_recover_status_show
c56b39cd2c55d (David Teigland     2006-04-28 10:51:53 -0400 145) };
c56b39cd2c55d (David Teigland     2006-04-28 10:51:53 -0400 146) 
faa0f2677287a (David Teigland     2006-08-08 17:08:42 -0500 147) static struct dlm_attr dlm_attr_recover_nodeid = {
faa0f2677287a (David Teigland     2006-08-08 17:08:42 -0500 148) 	.attr  = {.name = "recover_nodeid", .mode = S_IRUGO},
faa0f2677287a (David Teigland     2006-08-08 17:08:42 -0500 149) 	.show  = dlm_recover_nodeid_show
faa0f2677287a (David Teigland     2006-08-08 17:08:42 -0500 150) };
faa0f2677287a (David Teigland     2006-08-08 17:08:42 -0500 151) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 152) static struct attribute *dlm_attrs[] = {
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 153) 	&dlm_attr_control.attr,
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 154) 	&dlm_attr_event.attr,
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 155) 	&dlm_attr_id.attr,
4875647a08e35 (David Teigland     2012-04-26 15:54:29 -0500 156) 	&dlm_attr_nodir.attr,
c56b39cd2c55d (David Teigland     2006-04-28 10:51:53 -0400 157) 	&dlm_attr_recover_status.attr,
faa0f2677287a (David Teigland     2006-08-08 17:08:42 -0500 158) 	&dlm_attr_recover_nodeid.attr,
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 159) 	NULL,
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 160) };
c9c5b5e1565d6 (Kimberly Brown     2019-05-07 21:48:05 -0400 161) ATTRIBUTE_GROUPS(dlm);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 162) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 163) static ssize_t dlm_attr_show(struct kobject *kobj, struct attribute *attr,
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 164) 			     char *buf)
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 165) {
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 166) 	struct dlm_ls *ls  = container_of(kobj, struct dlm_ls, ls_kobj);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 167) 	struct dlm_attr *a = container_of(attr, struct dlm_attr, attr);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 168) 	return a->show ? a->show(ls, buf) : 0;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 169) }
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 170) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 171) static ssize_t dlm_attr_store(struct kobject *kobj, struct attribute *attr,
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 172) 			      const char *buf, size_t len)
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 173) {
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 174) 	struct dlm_ls *ls  = container_of(kobj, struct dlm_ls, ls_kobj);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 175) 	struct dlm_attr *a = container_of(attr, struct dlm_attr, attr);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 176) 	return a->store ? a->store(ls, buf, len) : len;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 177) }
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 178) 
ba542e3b92f9e (Patrick Caulfield  2006-11-02 14:41:23 +0000 179) static void lockspace_kobj_release(struct kobject *k)
ba542e3b92f9e (Patrick Caulfield  2006-11-02 14:41:23 +0000 180) {
ba542e3b92f9e (Patrick Caulfield  2006-11-02 14:41:23 +0000 181) 	struct dlm_ls *ls  = container_of(k, struct dlm_ls, ls_kobj);
ba542e3b92f9e (Patrick Caulfield  2006-11-02 14:41:23 +0000 182) 	kfree(ls);
ba542e3b92f9e (Patrick Caulfield  2006-11-02 14:41:23 +0000 183) }
ba542e3b92f9e (Patrick Caulfield  2006-11-02 14:41:23 +0000 184) 
52cf25d0ab7f7 (Emese Revfy        2010-01-19 02:58:23 +0100 185) static const struct sysfs_ops dlm_attr_ops = {
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 186) 	.show  = dlm_attr_show,
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 187) 	.store = dlm_attr_store,
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 188) };
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 189) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 190) static struct kobj_type dlm_ktype = {
c9c5b5e1565d6 (Kimberly Brown     2019-05-07 21:48:05 -0400 191) 	.default_groups = dlm_groups,
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 192) 	.sysfs_ops     = &dlm_attr_ops,
ba542e3b92f9e (Patrick Caulfield  2006-11-02 14:41:23 +0000 193) 	.release       = lockspace_kobj_release,
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 194) };
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 195) 
d405936b32222 (Greg Kroah-Hartman 2007-10-29 20:13:17 +0100 196) static struct kset *dlm_kset;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 197) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 198) static int do_uevent(struct dlm_ls *ls, int in)
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 199) {
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 200) 	if (in)
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 201) 		kobject_uevent(&ls->ls_kobj, KOBJ_ONLINE);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 202) 	else
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 203) 		kobject_uevent(&ls->ls_kobj, KOBJ_OFFLINE);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 204) 
075f01775f536 (David Teigland     2014-02-14 11:54:44 -0600 205) 	log_rinfo(ls, "%s the lockspace group...", in ? "joining" : "leaving");
8b0e7b2cf35aa (David Teigland     2007-05-18 09:03:35 -0500 206) 
8b0e7b2cf35aa (David Teigland     2007-05-18 09:03:35 -0500 207) 	/* dlm_controld will see the uevent, do the necessary group management
8b0e7b2cf35aa (David Teigland     2007-05-18 09:03:35 -0500 208) 	   and then write to sysfs to wake us */
8b0e7b2cf35aa (David Teigland     2007-05-18 09:03:35 -0500 209) 
f084a4f4a14b9 (Ross Lagerwall     2020-04-29 13:15:41 +0100 210) 	wait_event(ls->ls_uevent_wait,
f084a4f4a14b9 (Ross Lagerwall     2020-04-29 13:15:41 +0100 211) 		   test_and_clear_bit(LSFL_UEVENT_WAIT, &ls->ls_flags));
8b0e7b2cf35aa (David Teigland     2007-05-18 09:03:35 -0500 212) 
f084a4f4a14b9 (Ross Lagerwall     2020-04-29 13:15:41 +0100 213) 	log_rinfo(ls, "group event done %d", ls->ls_uevent_result);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 214) 
f084a4f4a14b9 (Ross Lagerwall     2020-04-29 13:15:41 +0100 215) 	return ls->ls_uevent_result;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 216) }
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 217) 
b4a5d4bc377e4 (Steven Whitehouse  2010-02-17 09:41:34 +0000 218) static int dlm_uevent(struct kset *kset, struct kobject *kobj,
b4a5d4bc377e4 (Steven Whitehouse  2010-02-17 09:41:34 +0000 219) 		      struct kobj_uevent_env *env)
b4a5d4bc377e4 (Steven Whitehouse  2010-02-17 09:41:34 +0000 220) {
b4a5d4bc377e4 (Steven Whitehouse  2010-02-17 09:41:34 +0000 221) 	struct dlm_ls *ls = container_of(kobj, struct dlm_ls, ls_kobj);
b4a5d4bc377e4 (Steven Whitehouse  2010-02-17 09:41:34 +0000 222) 
b4a5d4bc377e4 (Steven Whitehouse  2010-02-17 09:41:34 +0000 223) 	add_uevent_var(env, "LOCKSPACE=%s", ls->ls_name);
b4a5d4bc377e4 (Steven Whitehouse  2010-02-17 09:41:34 +0000 224) 	return 0;
b4a5d4bc377e4 (Steven Whitehouse  2010-02-17 09:41:34 +0000 225) }
b4a5d4bc377e4 (Steven Whitehouse  2010-02-17 09:41:34 +0000 226) 
417f7c59ed75b (Bhumika Goyal      2017-07-28 18:49:17 +0530 227) static const struct kset_uevent_ops dlm_uevent_ops = {
b4a5d4bc377e4 (Steven Whitehouse  2010-02-17 09:41:34 +0000 228) 	.uevent = dlm_uevent,
b4a5d4bc377e4 (Steven Whitehouse  2010-02-17 09:41:34 +0000 229) };
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 230) 
30727174b6273 (Denis Cheng        2008-02-02 01:53:46 +0800 231) int __init dlm_lockspace_init(void)
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 232) {
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 233) 	ls_count = 0;
901359256b266 (David Teigland     2006-01-20 08:47:07 +0000 234) 	mutex_init(&ls_lock);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 235) 	INIT_LIST_HEAD(&lslist);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 236) 	spin_lock_init(&lslist_lock);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 237) 
b4a5d4bc377e4 (Steven Whitehouse  2010-02-17 09:41:34 +0000 238) 	dlm_kset = kset_create_and_add("dlm", &dlm_uevent_ops, kernel_kobj);
d405936b32222 (Greg Kroah-Hartman 2007-10-29 20:13:17 +0100 239) 	if (!dlm_kset) {
8e24eea728068 (Harvey Harrison    2008-04-30 00:55:09 -0700 240) 		printk(KERN_WARNING "%s: can not create kset\n", __func__);
d405936b32222 (Greg Kroah-Hartman 2007-10-29 20:13:17 +0100 241) 		return -ENOMEM;
d405936b32222 (Greg Kroah-Hartman 2007-10-29 20:13:17 +0100 242) 	}
d405936b32222 (Greg Kroah-Hartman 2007-10-29 20:13:17 +0100 243) 	return 0;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 244) }
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 245) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 246) void dlm_lockspace_exit(void)
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 247) {
d405936b32222 (Greg Kroah-Hartman 2007-10-29 20:13:17 +0100 248) 	kset_unregister(dlm_kset);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 249) }
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 250) 
c1dcf65ffc579 (David Teigland     2008-08-18 14:03:25 -0500 251) static struct dlm_ls *find_ls_to_scan(void)
c1dcf65ffc579 (David Teigland     2008-08-18 14:03:25 -0500 252) {
c1dcf65ffc579 (David Teigland     2008-08-18 14:03:25 -0500 253) 	struct dlm_ls *ls;
c1dcf65ffc579 (David Teigland     2008-08-18 14:03:25 -0500 254) 
c1dcf65ffc579 (David Teigland     2008-08-18 14:03:25 -0500 255) 	spin_lock(&lslist_lock);
c1dcf65ffc579 (David Teigland     2008-08-18 14:03:25 -0500 256) 	list_for_each_entry(ls, &lslist, ls_list) {
c1dcf65ffc579 (David Teigland     2008-08-18 14:03:25 -0500 257) 		if (time_after_eq(jiffies, ls->ls_scan_time +
c1dcf65ffc579 (David Teigland     2008-08-18 14:03:25 -0500 258) 					    dlm_config.ci_scan_secs * HZ)) {
c1dcf65ffc579 (David Teigland     2008-08-18 14:03:25 -0500 259) 			spin_unlock(&lslist_lock);
c1dcf65ffc579 (David Teigland     2008-08-18 14:03:25 -0500 260) 			return ls;
c1dcf65ffc579 (David Teigland     2008-08-18 14:03:25 -0500 261) 		}
c1dcf65ffc579 (David Teigland     2008-08-18 14:03:25 -0500 262) 	}
c1dcf65ffc579 (David Teigland     2008-08-18 14:03:25 -0500 263) 	spin_unlock(&lslist_lock);
c1dcf65ffc579 (David Teigland     2008-08-18 14:03:25 -0500 264) 	return NULL;
c1dcf65ffc579 (David Teigland     2008-08-18 14:03:25 -0500 265) }
c1dcf65ffc579 (David Teigland     2008-08-18 14:03:25 -0500 266) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 267) static int dlm_scand(void *data)
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 268) {
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 269) 	struct dlm_ls *ls;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 270) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 271) 	while (!kthread_should_stop()) {
c1dcf65ffc579 (David Teigland     2008-08-18 14:03:25 -0500 272) 		ls = find_ls_to_scan();
c1dcf65ffc579 (David Teigland     2008-08-18 14:03:25 -0500 273) 		if (ls) {
85e86edf951a8 (David Teigland     2007-05-18 08:58:15 -0500 274) 			if (dlm_lock_recovery_try(ls)) {
c1dcf65ffc579 (David Teigland     2008-08-18 14:03:25 -0500 275) 				ls->ls_scan_time = jiffies;
85e86edf951a8 (David Teigland     2007-05-18 08:58:15 -0500 276) 				dlm_scan_rsbs(ls);
3ae1acf93a215 (David Teigland     2007-05-18 08:59:31 -0500 277) 				dlm_scan_timeout(ls);
c6ff669bac5c4 (David Teigland     2011-03-28 14:17:26 -0500 278) 				dlm_scan_waiters(ls);
85e86edf951a8 (David Teigland     2007-05-18 08:58:15 -0500 279) 				dlm_unlock_recovery(ls);
c1dcf65ffc579 (David Teigland     2008-08-18 14:03:25 -0500 280) 			} else {
c1dcf65ffc579 (David Teigland     2008-08-18 14:03:25 -0500 281) 				ls->ls_scan_time += HZ;
85e86edf951a8 (David Teigland     2007-05-18 08:58:15 -0500 282) 			}
c6ff669bac5c4 (David Teigland     2011-03-28 14:17:26 -0500 283) 			continue;
85e86edf951a8 (David Teigland     2007-05-18 08:58:15 -0500 284) 		}
c6ff669bac5c4 (David Teigland     2011-03-28 14:17:26 -0500 285) 		schedule_timeout_interruptible(dlm_config.ci_scan_secs * HZ);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 286) 	}
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 287) 	return 0;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 288) }
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 289) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 290) static int dlm_scand_start(void)
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 291) {
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 292) 	struct task_struct *p;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 293) 	int error = 0;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 294) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 295) 	p = kthread_run(dlm_scand, NULL, "dlm_scand");
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 296) 	if (IS_ERR(p))
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 297) 		error = PTR_ERR(p);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 298) 	else
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 299) 		scand_task = p;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 300) 	return error;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 301) }
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 302) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 303) static void dlm_scand_stop(void)
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 304) {
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 305) 	kthread_stop(scand_task);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 306) }
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 307) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 308) struct dlm_ls *dlm_find_lockspace_global(uint32_t id)
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 309) {
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 310) 	struct dlm_ls *ls;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 311) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 312) 	spin_lock(&lslist_lock);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 313) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 314) 	list_for_each_entry(ls, &lslist, ls_list) {
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 315) 		if (ls->ls_global_id == id) {
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 316) 			ls->ls_count++;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 317) 			goto out;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 318) 		}
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 319) 	}
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 320) 	ls = NULL;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 321)  out:
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 322) 	spin_unlock(&lslist_lock);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 323) 	return ls;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 324) }
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 325) 
597d0cae0f99f (David Teigland     2006-07-12 16:44:04 -0500 326) struct dlm_ls *dlm_find_lockspace_local(dlm_lockspace_t *lockspace)
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 327) {
597d0cae0f99f (David Teigland     2006-07-12 16:44:04 -0500 328) 	struct dlm_ls *ls;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 329) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 330) 	spin_lock(&lslist_lock);
597d0cae0f99f (David Teigland     2006-07-12 16:44:04 -0500 331) 	list_for_each_entry(ls, &lslist, ls_list) {
597d0cae0f99f (David Teigland     2006-07-12 16:44:04 -0500 332) 		if (ls->ls_local_handle == lockspace) {
597d0cae0f99f (David Teigland     2006-07-12 16:44:04 -0500 333) 			ls->ls_count++;
597d0cae0f99f (David Teigland     2006-07-12 16:44:04 -0500 334) 			goto out;
597d0cae0f99f (David Teigland     2006-07-12 16:44:04 -0500 335) 		}
597d0cae0f99f (David Teigland     2006-07-12 16:44:04 -0500 336) 	}
597d0cae0f99f (David Teigland     2006-07-12 16:44:04 -0500 337) 	ls = NULL;
597d0cae0f99f (David Teigland     2006-07-12 16:44:04 -0500 338)  out:
597d0cae0f99f (David Teigland     2006-07-12 16:44:04 -0500 339) 	spin_unlock(&lslist_lock);
597d0cae0f99f (David Teigland     2006-07-12 16:44:04 -0500 340) 	return ls;
597d0cae0f99f (David Teigland     2006-07-12 16:44:04 -0500 341) }
597d0cae0f99f (David Teigland     2006-07-12 16:44:04 -0500 342) 
597d0cae0f99f (David Teigland     2006-07-12 16:44:04 -0500 343) struct dlm_ls *dlm_find_lockspace_device(int minor)
597d0cae0f99f (David Teigland     2006-07-12 16:44:04 -0500 344) {
597d0cae0f99f (David Teigland     2006-07-12 16:44:04 -0500 345) 	struct dlm_ls *ls;
597d0cae0f99f (David Teigland     2006-07-12 16:44:04 -0500 346) 
597d0cae0f99f (David Teigland     2006-07-12 16:44:04 -0500 347) 	spin_lock(&lslist_lock);
597d0cae0f99f (David Teigland     2006-07-12 16:44:04 -0500 348) 	list_for_each_entry(ls, &lslist, ls_list) {
597d0cae0f99f (David Teigland     2006-07-12 16:44:04 -0500 349) 		if (ls->ls_device.minor == minor) {
597d0cae0f99f (David Teigland     2006-07-12 16:44:04 -0500 350) 			ls->ls_count++;
597d0cae0f99f (David Teigland     2006-07-12 16:44:04 -0500 351) 			goto out;
597d0cae0f99f (David Teigland     2006-07-12 16:44:04 -0500 352) 		}
597d0cae0f99f (David Teigland     2006-07-12 16:44:04 -0500 353) 	}
597d0cae0f99f (David Teigland     2006-07-12 16:44:04 -0500 354) 	ls = NULL;
597d0cae0f99f (David Teigland     2006-07-12 16:44:04 -0500 355)  out:
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 356) 	spin_unlock(&lslist_lock);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 357) 	return ls;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 358) }
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 359) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 360) void dlm_put_lockspace(struct dlm_ls *ls)
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 361) {
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 362) 	spin_lock(&lslist_lock);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 363) 	ls->ls_count--;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 364) 	spin_unlock(&lslist_lock);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 365) }
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 366) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 367) static void remove_lockspace(struct dlm_ls *ls)
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 368) {
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 369) 	for (;;) {
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 370) 		spin_lock(&lslist_lock);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 371) 		if (ls->ls_count == 0) {
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 372) 			WARN_ON(ls->ls_create_count != 0);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 373) 			list_del(&ls->ls_list);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 374) 			spin_unlock(&lslist_lock);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 375) 			return;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 376) 		}
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 377) 		spin_unlock(&lslist_lock);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 378) 		ssleep(1);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 379) 	}
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 380) }
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 381) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 382) static int threads_start(void)
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 383) {
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 384) 	int error;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 385) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 386) 	error = dlm_scand_start();
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 387) 	if (error) {
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 388) 		log_print("cannot start dlm_scand thread %d", error);
23e8e1aaacb10 (David Teigland     2011-04-05 13:16:24 -0500 389) 		goto fail;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 390) 	}
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 391) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 392) 	/* Thread for sending/receiving messages for all lockspace's */
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 393) 	error = dlm_lowcomms_start();
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 394) 	if (error) {
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 395) 		log_print("cannot start dlm lowcomms %d", error);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 396) 		goto scand_fail;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 397) 	}
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 398) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 399) 	return 0;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 400) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 401)  scand_fail:
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 402) 	dlm_scand_stop();
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 403)  fail:
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 404) 	return error;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 405) }
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 406) 
60f98d1839376 (David Teigland     2011-11-02 14:30:58 -0500 407) static int new_lockspace(const char *name, const char *cluster,
60f98d1839376 (David Teigland     2011-11-02 14:30:58 -0500 408) 			 uint32_t flags, int lvblen,
60f98d1839376 (David Teigland     2011-11-02 14:30:58 -0500 409) 			 const struct dlm_lockspace_ops *ops, void *ops_arg,
60f98d1839376 (David Teigland     2011-11-02 14:30:58 -0500 410) 			 int *ops_result, dlm_lockspace_t **lockspace)
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 411) {
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 412) 	struct dlm_ls *ls;
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 413) 	int i, size, error;
79d72b54483bf (David Teigland     2007-05-18 09:02:20 -0500 414) 	int do_unreg = 0;
60f98d1839376 (David Teigland     2011-11-02 14:30:58 -0500 415) 	int namelen = strlen(name);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 416) 
3f0806d2596de (Tycho Andersen     2018-11-02 14:18:21 -0600 417) 	if (namelen > DLM_LOCKSPACE_LEN || namelen == 0)
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 418) 		return -EINVAL;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 419) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 420) 	if (!lvblen || (lvblen % 8))
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 421) 		return -EINVAL;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 422) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 423) 	if (!try_module_get(THIS_MODULE))
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 424) 		return -EINVAL;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 425) 
dc68c7ed362a0 (David Teigland     2008-08-18 11:43:30 -0500 426) 	if (!dlm_user_daemon_available()) {
60f98d1839376 (David Teigland     2011-11-02 14:30:58 -0500 427) 		log_print("dlm user daemon not available");
60f98d1839376 (David Teigland     2011-11-02 14:30:58 -0500 428) 		error = -EUNATCH;
60f98d1839376 (David Teigland     2011-11-02 14:30:58 -0500 429) 		goto out;
60f98d1839376 (David Teigland     2011-11-02 14:30:58 -0500 430) 	}
60f98d1839376 (David Teigland     2011-11-02 14:30:58 -0500 431) 
60f98d1839376 (David Teigland     2011-11-02 14:30:58 -0500 432) 	if (ops && ops_result) {
60f98d1839376 (David Teigland     2011-11-02 14:30:58 -0500 433) 	       	if (!dlm_config.ci_recover_callbacks)
60f98d1839376 (David Teigland     2011-11-02 14:30:58 -0500 434) 			*ops_result = -EOPNOTSUPP;
60f98d1839376 (David Teigland     2011-11-02 14:30:58 -0500 435) 		else
60f98d1839376 (David Teigland     2011-11-02 14:30:58 -0500 436) 			*ops_result = 0;
60f98d1839376 (David Teigland     2011-11-02 14:30:58 -0500 437) 	}
60f98d1839376 (David Teigland     2011-11-02 14:30:58 -0500 438) 
3b0e761ba83cb (Zhu Lingshan       2017-07-11 09:26:55 -0500 439) 	if (!cluster)
3b0e761ba83cb (Zhu Lingshan       2017-07-11 09:26:55 -0500 440) 		log_print("dlm cluster name '%s' is being used without an application provided cluster name",
3b0e761ba83cb (Zhu Lingshan       2017-07-11 09:26:55 -0500 441) 			  dlm_config.ci_cluster_name);
3b0e761ba83cb (Zhu Lingshan       2017-07-11 09:26:55 -0500 442) 
60f98d1839376 (David Teigland     2011-11-02 14:30:58 -0500 443) 	if (dlm_config.ci_recover_callbacks && cluster &&
60f98d1839376 (David Teigland     2011-11-02 14:30:58 -0500 444) 	    strncmp(cluster, dlm_config.ci_cluster_name, DLM_LOCKSPACE_LEN)) {
8e1743748b7e9 (Gang He            2017-05-18 10:42:12 +0800 445) 		log_print("dlm cluster name '%s' does not match "
8e1743748b7e9 (Gang He            2017-05-18 10:42:12 +0800 446) 			  "the application cluster name '%s'",
60f98d1839376 (David Teigland     2011-11-02 14:30:58 -0500 447) 			  dlm_config.ci_cluster_name, cluster);
60f98d1839376 (David Teigland     2011-11-02 14:30:58 -0500 448) 		error = -EBADR;
60f98d1839376 (David Teigland     2011-11-02 14:30:58 -0500 449) 		goto out;
dc68c7ed362a0 (David Teigland     2008-08-18 11:43:30 -0500 450) 	}
dc68c7ed362a0 (David Teigland     2008-08-18 11:43:30 -0500 451) 
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 452) 	error = 0;
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 453) 
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 454) 	spin_lock(&lslist_lock);
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 455) 	list_for_each_entry(ls, &lslist, ls_list) {
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 456) 		WARN_ON(ls->ls_create_count <= 0);
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 457) 		if (ls->ls_namelen != namelen)
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 458) 			continue;
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 459) 		if (memcmp(ls->ls_name, name, namelen))
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 460) 			continue;
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 461) 		if (flags & DLM_LSFL_NEWEXCL) {
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 462) 			error = -EEXIST;
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 463) 			break;
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 464) 		}
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 465) 		ls->ls_create_count++;
8511a2728ab82 (David Teigland     2009-04-08 15:38:43 -0500 466) 		*lockspace = ls;
8511a2728ab82 (David Teigland     2009-04-08 15:38:43 -0500 467) 		error = 1;
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 468) 		break;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 469) 	}
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 470) 	spin_unlock(&lslist_lock);
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 471) 
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 472) 	if (error)
8511a2728ab82 (David Teigland     2009-04-08 15:38:43 -0500 473) 		goto out;
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 474) 
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 475) 	error = -ENOMEM;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 476) 
573c24c4af666 (David Teigland     2009-11-30 16:34:43 -0600 477) 	ls = kzalloc(sizeof(struct dlm_ls) + namelen, GFP_NOFS);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 478) 	if (!ls)
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 479) 		goto out;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 480) 	memcpy(ls->ls_name, name, namelen);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 481) 	ls->ls_namelen = namelen;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 482) 	ls->ls_lvblen = lvblen;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 483) 	ls->ls_count = 0;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 484) 	ls->ls_flags = 0;
c1dcf65ffc579 (David Teigland     2008-08-18 14:03:25 -0500 485) 	ls->ls_scan_time = jiffies;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 486) 
60f98d1839376 (David Teigland     2011-11-02 14:30:58 -0500 487) 	if (ops && dlm_config.ci_recover_callbacks) {
60f98d1839376 (David Teigland     2011-11-02 14:30:58 -0500 488) 		ls->ls_ops = ops;
60f98d1839376 (David Teigland     2011-11-02 14:30:58 -0500 489) 		ls->ls_ops_arg = ops_arg;
60f98d1839376 (David Teigland     2011-11-02 14:30:58 -0500 490) 	}
60f98d1839376 (David Teigland     2011-11-02 14:30:58 -0500 491) 
3ae1acf93a215 (David Teigland     2007-05-18 08:59:31 -0500 492) 	if (flags & DLM_LSFL_TIMEWARN)
3ae1acf93a215 (David Teigland     2007-05-18 08:59:31 -0500 493) 		set_bit(LSFL_TIMEWARN, &ls->ls_flags);
3ae1acf93a215 (David Teigland     2007-05-18 08:59:31 -0500 494) 
fad59c1390045 (David Teigland     2007-06-11 10:47:18 -0500 495) 	/* ls_exflags are forced to match among nodes, and we don't
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 496) 	   need to require all nodes to have some flags set */
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 497) 	ls->ls_exflags = (flags & ~(DLM_LSFL_TIMEWARN | DLM_LSFL_FS |
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 498) 				    DLM_LSFL_NEWEXCL));
fad59c1390045 (David Teigland     2007-06-11 10:47:18 -0500 499) 
68c817a1c4e21 (David Teigland     2007-01-09 09:41:48 -0600 500) 	size = dlm_config.ci_rsbtbl_size;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 501) 	ls->ls_rsbtbl_size = size;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 502) 
42bc47b35320e (Kees Cook          2018-06-12 14:27:11 -0700 503) 	ls->ls_rsbtbl = vmalloc(array_size(size, sizeof(struct dlm_rsbtable)));
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 504) 	if (!ls->ls_rsbtbl)
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 505) 		goto out_lsfree;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 506) 	for (i = 0; i < size; i++) {
9beb3bf5a92bb (Bob Peterson       2011-10-26 15:24:55 -0500 507) 		ls->ls_rsbtbl[i].keep.rb_node = NULL;
9beb3bf5a92bb (Bob Peterson       2011-10-26 15:24:55 -0500 508) 		ls->ls_rsbtbl[i].toss.rb_node = NULL;
c7be761a8163d (David Teigland     2009-01-07 16:50:41 -0600 509) 		spin_lock_init(&ls->ls_rsbtbl[i].lock);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 510) 	}
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 511) 
05c32f47bfae7 (David Teigland     2012-06-14 12:17:32 -0500 512) 	spin_lock_init(&ls->ls_remove_spin);
05c32f47bfae7 (David Teigland     2012-06-14 12:17:32 -0500 513) 
05c32f47bfae7 (David Teigland     2012-06-14 12:17:32 -0500 514) 	for (i = 0; i < DLM_REMOVE_NAMES_MAX; i++) {
05c32f47bfae7 (David Teigland     2012-06-14 12:17:32 -0500 515) 		ls->ls_remove_names[i] = kzalloc(DLM_RESNAME_MAXLEN+1,
05c32f47bfae7 (David Teigland     2012-06-14 12:17:32 -0500 516) 						 GFP_KERNEL);
05c32f47bfae7 (David Teigland     2012-06-14 12:17:32 -0500 517) 		if (!ls->ls_remove_names[i])
05c32f47bfae7 (David Teigland     2012-06-14 12:17:32 -0500 518) 			goto out_rsbtbl;
05c32f47bfae7 (David Teigland     2012-06-14 12:17:32 -0500 519) 	}
05c32f47bfae7 (David Teigland     2012-06-14 12:17:32 -0500 520) 
3d6aa675fff9e (David Teigland     2011-07-06 17:00:54 -0500 521) 	idr_init(&ls->ls_lkbidr);
3d6aa675fff9e (David Teigland     2011-07-06 17:00:54 -0500 522) 	spin_lock_init(&ls->ls_lkbidr_spin);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 523) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 524) 	INIT_LIST_HEAD(&ls->ls_waiters);
901359256b266 (David Teigland     2006-01-20 08:47:07 +0000 525) 	mutex_init(&ls->ls_waiters_mutex);
ef0c2bb05f40f (David Teigland     2007-03-28 09:56:46 -0500 526) 	INIT_LIST_HEAD(&ls->ls_orphans);
ef0c2bb05f40f (David Teigland     2007-03-28 09:56:46 -0500 527) 	mutex_init(&ls->ls_orphans_mutex);
3ae1acf93a215 (David Teigland     2007-05-18 08:59:31 -0500 528) 	INIT_LIST_HEAD(&ls->ls_timeout);
3ae1acf93a215 (David Teigland     2007-05-18 08:59:31 -0500 529) 	mutex_init(&ls->ls_timeout_mutex);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 530) 
3881ac04ebf94 (David Teigland     2011-07-07 14:05:03 -0500 531) 	INIT_LIST_HEAD(&ls->ls_new_rsb);
3881ac04ebf94 (David Teigland     2011-07-07 14:05:03 -0500 532) 	spin_lock_init(&ls->ls_new_rsb_spin);
3881ac04ebf94 (David Teigland     2011-07-07 14:05:03 -0500 533) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 534) 	INIT_LIST_HEAD(&ls->ls_nodes);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 535) 	INIT_LIST_HEAD(&ls->ls_nodes_gone);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 536) 	ls->ls_num_nodes = 0;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 537) 	ls->ls_low_nodeid = 0;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 538) 	ls->ls_total_weight = 0;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 539) 	ls->ls_node_array = NULL;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 540) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 541) 	memset(&ls->ls_stub_rsb, 0, sizeof(struct dlm_rsb));
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 542) 	ls->ls_stub_rsb.res_ls = ls;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 543) 
5de6319b18393 (David Teigland     2006-07-25 13:44:31 -0500 544) 	ls->ls_debug_rsb_dentry = NULL;
5de6319b18393 (David Teigland     2006-07-25 13:44:31 -0500 545) 	ls->ls_debug_waiters_dentry = NULL;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 546) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 547) 	init_waitqueue_head(&ls->ls_uevent_wait);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 548) 	ls->ls_uevent_result = 0;
8b0e7b2cf35aa (David Teigland     2007-05-18 09:03:35 -0500 549) 	init_completion(&ls->ls_members_done);
8b0e7b2cf35aa (David Teigland     2007-05-18 09:03:35 -0500 550) 	ls->ls_members_result = -1;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 551) 
23e8e1aaacb10 (David Teigland     2011-04-05 13:16:24 -0500 552) 	mutex_init(&ls->ls_cb_mutex);
23e8e1aaacb10 (David Teigland     2011-04-05 13:16:24 -0500 553) 	INIT_LIST_HEAD(&ls->ls_cb_delay);
23e8e1aaacb10 (David Teigland     2011-04-05 13:16:24 -0500 554) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 555) 	ls->ls_recoverd_task = NULL;
901359256b266 (David Teigland     2006-01-20 08:47:07 +0000 556) 	mutex_init(&ls->ls_recoverd_active);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 557) 	spin_lock_init(&ls->ls_recover_lock);
98f176fb32f33 (David Teigland     2006-11-27 13:19:28 -0600 558) 	spin_lock_init(&ls->ls_rcom_spin);
98f176fb32f33 (David Teigland     2006-11-27 13:19:28 -0600 559) 	get_random_bytes(&ls->ls_rcom_seq, sizeof(uint64_t));
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 560) 	ls->ls_recover_status = 0;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 561) 	ls->ls_recover_seq = 0;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 562) 	ls->ls_recover_args = NULL;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 563) 	init_rwsem(&ls->ls_in_recovery);
c36258b5925e6 (David Teigland     2007-09-27 15:53:38 -0500 564) 	init_rwsem(&ls->ls_recv_active);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 565) 	INIT_LIST_HEAD(&ls->ls_requestqueue);
901359256b266 (David Teigland     2006-01-20 08:47:07 +0000 566) 	mutex_init(&ls->ls_requestqueue_mutex);
597d0cae0f99f (David Teigland     2006-07-12 16:44:04 -0500 567) 	mutex_init(&ls->ls_clear_proc_locks);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 568) 
9f8f9c774ad10 (Alexander Aring    2020-11-02 20:04:17 -0500 569) 	ls->ls_recover_buf = kmalloc(LOWCOMMS_MAX_TX_BUFFER_LEN, GFP_NOFS);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 570) 	if (!ls->ls_recover_buf)
05c32f47bfae7 (David Teigland     2012-06-14 12:17:32 -0500 571) 		goto out_lkbidr;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 572) 
757a427196354 (David Teigland     2011-10-20 13:26:28 -0500 573) 	ls->ls_slot = 0;
757a427196354 (David Teigland     2011-10-20 13:26:28 -0500 574) 	ls->ls_num_slots = 0;
757a427196354 (David Teigland     2011-10-20 13:26:28 -0500 575) 	ls->ls_slots_size = 0;
757a427196354 (David Teigland     2011-10-20 13:26:28 -0500 576) 	ls->ls_slots = NULL;
757a427196354 (David Teigland     2011-10-20 13:26:28 -0500 577) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 578) 	INIT_LIST_HEAD(&ls->ls_recover_list);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 579) 	spin_lock_init(&ls->ls_recover_list_lock);
1d7c484eeb167 (David Teigland     2012-05-15 16:07:49 -0500 580) 	idr_init(&ls->ls_recover_idr);
1d7c484eeb167 (David Teigland     2012-05-15 16:07:49 -0500 581) 	spin_lock_init(&ls->ls_recover_idr_lock);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 582) 	ls->ls_recover_list_count = 0;
597d0cae0f99f (David Teigland     2006-07-12 16:44:04 -0500 583) 	ls->ls_local_handle = ls;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 584) 	init_waitqueue_head(&ls->ls_wait_general);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 585) 	INIT_LIST_HEAD(&ls->ls_root_list);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 586) 	init_rwsem(&ls->ls_root_sem);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 587) 
5f88f1ea16a2f (David Teigland     2006-08-24 14:47:20 -0500 588) 	spin_lock(&lslist_lock);
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 589) 	ls->ls_create_count = 1;
5f88f1ea16a2f (David Teigland     2006-08-24 14:47:20 -0500 590) 	list_add(&ls->ls_list, &lslist);
5f88f1ea16a2f (David Teigland     2006-08-24 14:47:20 -0500 591) 	spin_unlock(&lslist_lock);
5f88f1ea16a2f (David Teigland     2006-08-24 14:47:20 -0500 592) 
23e8e1aaacb10 (David Teigland     2011-04-05 13:16:24 -0500 593) 	if (flags & DLM_LSFL_FS) {
23e8e1aaacb10 (David Teigland     2011-04-05 13:16:24 -0500 594) 		error = dlm_callback_start(ls);
23e8e1aaacb10 (David Teigland     2011-04-05 13:16:24 -0500 595) 		if (error) {
23e8e1aaacb10 (David Teigland     2011-04-05 13:16:24 -0500 596) 			log_error(ls, "can't start dlm_callback %d", error);
23e8e1aaacb10 (David Teigland     2011-04-05 13:16:24 -0500 597) 			goto out_delist;
23e8e1aaacb10 (David Teigland     2011-04-05 13:16:24 -0500 598) 		}
23e8e1aaacb10 (David Teigland     2011-04-05 13:16:24 -0500 599) 	}
23e8e1aaacb10 (David Teigland     2011-04-05 13:16:24 -0500 600) 
475f230c6072f (David Teigland     2012-08-02 11:08:21 -0500 601) 	init_waitqueue_head(&ls->ls_recover_lock_wait);
475f230c6072f (David Teigland     2012-08-02 11:08:21 -0500 602) 
475f230c6072f (David Teigland     2012-08-02 11:08:21 -0500 603) 	/*
475f230c6072f (David Teigland     2012-08-02 11:08:21 -0500 604) 	 * Once started, dlm_recoverd first looks for ls in lslist, then
475f230c6072f (David Teigland     2012-08-02 11:08:21 -0500 605) 	 * initializes ls_in_recovery as locked in "down" mode.  We need
475f230c6072f (David Teigland     2012-08-02 11:08:21 -0500 606) 	 * to wait for the wakeup from dlm_recoverd because in_recovery
475f230c6072f (David Teigland     2012-08-02 11:08:21 -0500 607) 	 * has to start out in down mode.
475f230c6072f (David Teigland     2012-08-02 11:08:21 -0500 608) 	 */
475f230c6072f (David Teigland     2012-08-02 11:08:21 -0500 609) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 610) 	error = dlm_recoverd_start(ls);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 611) 	if (error) {
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 612) 		log_error(ls, "can't start dlm_recoverd %d", error);
23e8e1aaacb10 (David Teigland     2011-04-05 13:16:24 -0500 613) 		goto out_callback;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 614) 	}
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 615) 
475f230c6072f (David Teigland     2012-08-02 11:08:21 -0500 616) 	wait_event(ls->ls_recover_lock_wait,
475f230c6072f (David Teigland     2012-08-02 11:08:21 -0500 617) 		   test_bit(LSFL_RECOVER_LOCK, &ls->ls_flags));
475f230c6072f (David Teigland     2012-08-02 11:08:21 -0500 618) 
0ffddafc3a397 (Wang Hai           2020-06-15 11:25:33 +0800 619) 	/* let kobject handle freeing of ls if there's an error */
0ffddafc3a397 (Wang Hai           2020-06-15 11:25:33 +0800 620) 	do_unreg = 1;
0ffddafc3a397 (Wang Hai           2020-06-15 11:25:33 +0800 621) 
901195ed7f4b2 (Greg Kroah-Hartman 2007-12-17 15:54:39 -0400 622) 	ls->ls_kobj.kset = dlm_kset;
901195ed7f4b2 (Greg Kroah-Hartman 2007-12-17 15:54:39 -0400 623) 	error = kobject_init_and_add(&ls->ls_kobj, &dlm_ktype, NULL,
901195ed7f4b2 (Greg Kroah-Hartman 2007-12-17 15:54:39 -0400 624) 				     "%s", ls->ls_name);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 625) 	if (error)
23e8e1aaacb10 (David Teigland     2011-04-05 13:16:24 -0500 626) 		goto out_recoverd;
901195ed7f4b2 (Greg Kroah-Hartman 2007-12-17 15:54:39 -0400 627) 	kobject_uevent(&ls->ls_kobj, KOBJ_ADD);
79d72b54483bf (David Teigland     2007-05-18 09:02:20 -0500 628) 
8b0e7b2cf35aa (David Teigland     2007-05-18 09:03:35 -0500 629) 	/* This uevent triggers dlm_controld in userspace to add us to the
8b0e7b2cf35aa (David Teigland     2007-05-18 09:03:35 -0500 630) 	   group of nodes that are members of this lockspace (managed by the
8b0e7b2cf35aa (David Teigland     2007-05-18 09:03:35 -0500 631) 	   cluster infrastructure.)  Once it's done that, it tells us who the
8b0e7b2cf35aa (David Teigland     2007-05-18 09:03:35 -0500 632) 	   current lockspace members are (via configfs) and then tells the
8b0e7b2cf35aa (David Teigland     2007-05-18 09:03:35 -0500 633) 	   lockspace to start running (via sysfs) in dlm_ls_start(). */
8b0e7b2cf35aa (David Teigland     2007-05-18 09:03:35 -0500 634) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 635) 	error = do_uevent(ls, 1);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 636) 	if (error)
23e8e1aaacb10 (David Teigland     2011-04-05 13:16:24 -0500 637) 		goto out_recoverd;
79d72b54483bf (David Teigland     2007-05-18 09:02:20 -0500 638) 
8b0e7b2cf35aa (David Teigland     2007-05-18 09:03:35 -0500 639) 	wait_for_completion(&ls->ls_members_done);
8b0e7b2cf35aa (David Teigland     2007-05-18 09:03:35 -0500 640) 	error = ls->ls_members_result;
8b0e7b2cf35aa (David Teigland     2007-05-18 09:03:35 -0500 641) 	if (error)
8b0e7b2cf35aa (David Teigland     2007-05-18 09:03:35 -0500 642) 		goto out_members;
8b0e7b2cf35aa (David Teigland     2007-05-18 09:03:35 -0500 643) 
79d72b54483bf (David Teigland     2007-05-18 09:02:20 -0500 644) 	dlm_create_debug_file(ls);
79d72b54483bf (David Teigland     2007-05-18 09:02:20 -0500 645) 
075f01775f536 (David Teigland     2014-02-14 11:54:44 -0600 646) 	log_rinfo(ls, "join complete");
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 647) 	*lockspace = ls;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 648) 	return 0;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 649) 
8b0e7b2cf35aa (David Teigland     2007-05-18 09:03:35 -0500 650)  out_members:
8b0e7b2cf35aa (David Teigland     2007-05-18 09:03:35 -0500 651) 	do_uevent(ls, 0);
8b0e7b2cf35aa (David Teigland     2007-05-18 09:03:35 -0500 652) 	dlm_clear_members(ls);
8b0e7b2cf35aa (David Teigland     2007-05-18 09:03:35 -0500 653) 	kfree(ls->ls_node_array);
23e8e1aaacb10 (David Teigland     2011-04-05 13:16:24 -0500 654)  out_recoverd:
5f88f1ea16a2f (David Teigland     2006-08-24 14:47:20 -0500 655) 	dlm_recoverd_stop(ls);
23e8e1aaacb10 (David Teigland     2011-04-05 13:16:24 -0500 656)  out_callback:
23e8e1aaacb10 (David Teigland     2011-04-05 13:16:24 -0500 657) 	dlm_callback_stop(ls);
79d72b54483bf (David Teigland     2007-05-18 09:02:20 -0500 658)  out_delist:
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 659) 	spin_lock(&lslist_lock);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 660) 	list_del(&ls->ls_list);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 661) 	spin_unlock(&lslist_lock);
1d7c484eeb167 (David Teigland     2012-05-15 16:07:49 -0500 662) 	idr_destroy(&ls->ls_recover_idr);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 663) 	kfree(ls->ls_recover_buf);
05c32f47bfae7 (David Teigland     2012-06-14 12:17:32 -0500 664)  out_lkbidr:
3d6aa675fff9e (David Teigland     2011-07-06 17:00:54 -0500 665) 	idr_destroy(&ls->ls_lkbidr);
b982896cdb6e6 (Vasily Averin      2018-11-15 13:15:05 +0300 666)  out_rsbtbl:
3456880ff39f7 (Thomas Meyer       2018-12-03 10:02:01 -0600 667) 	for (i = 0; i < DLM_REMOVE_NAMES_MAX; i++)
3456880ff39f7 (Thomas Meyer       2018-12-03 10:02:01 -0600 668) 		kfree(ls->ls_remove_names[i]);
c282af4990167 (Bryn M. Reeves     2011-07-01 15:49:23 -0500 669) 	vfree(ls->ls_rsbtbl);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 670)  out_lsfree:
79d72b54483bf (David Teigland     2007-05-18 09:02:20 -0500 671) 	if (do_unreg)
197b12d6796a3 (Greg Kroah-Hartman 2007-12-20 08:13:05 -0800 672) 		kobject_put(&ls->ls_kobj);
79d72b54483bf (David Teigland     2007-05-18 09:02:20 -0500 673) 	else
79d72b54483bf (David Teigland     2007-05-18 09:02:20 -0500 674) 		kfree(ls);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 675)  out:
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 676) 	module_put(THIS_MODULE);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 677) 	return error;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 678) }
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 679) 
60f98d1839376 (David Teigland     2011-11-02 14:30:58 -0500 680) int dlm_new_lockspace(const char *name, const char *cluster,
60f98d1839376 (David Teigland     2011-11-02 14:30:58 -0500 681) 		      uint32_t flags, int lvblen,
60f98d1839376 (David Teigland     2011-11-02 14:30:58 -0500 682) 		      const struct dlm_lockspace_ops *ops, void *ops_arg,
60f98d1839376 (David Teigland     2011-11-02 14:30:58 -0500 683) 		      int *ops_result, dlm_lockspace_t **lockspace)
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 684) {
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 685) 	int error = 0;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 686) 
901359256b266 (David Teigland     2006-01-20 08:47:07 +0000 687) 	mutex_lock(&ls_lock);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 688) 	if (!ls_count)
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 689) 		error = threads_start();
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 690) 	if (error)
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 691) 		goto out;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 692) 
60f98d1839376 (David Teigland     2011-11-02 14:30:58 -0500 693) 	error = new_lockspace(name, cluster, flags, lvblen, ops, ops_arg,
60f98d1839376 (David Teigland     2011-11-02 14:30:58 -0500 694) 			      ops_result, lockspace);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 695) 	if (!error)
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 696) 		ls_count++;
8511a2728ab82 (David Teigland     2009-04-08 15:38:43 -0500 697) 	if (error > 0)
8511a2728ab82 (David Teigland     2009-04-08 15:38:43 -0500 698) 		error = 0;
9d232469bcd77 (Alexander Aring    2021-03-01 17:05:20 -0500 699) 	if (!ls_count) {
9d232469bcd77 (Alexander Aring    2021-03-01 17:05:20 -0500 700) 		dlm_scand_stop();
9d232469bcd77 (Alexander Aring    2021-03-01 17:05:20 -0500 701) 		dlm_lowcomms_shutdown();
9d232469bcd77 (Alexander Aring    2021-03-01 17:05:20 -0500 702) 		dlm_lowcomms_stop();
9d232469bcd77 (Alexander Aring    2021-03-01 17:05:20 -0500 703) 	}
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 704)  out:
901359256b266 (David Teigland     2006-01-20 08:47:07 +0000 705) 	mutex_unlock(&ls_lock);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 706) 	return error;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 707) }
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 708) 
3d6aa675fff9e (David Teigland     2011-07-06 17:00:54 -0500 709) static int lkb_idr_is_local(int id, void *p, void *data)
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 710) {
3d6aa675fff9e (David Teigland     2011-07-06 17:00:54 -0500 711) 	struct dlm_lkb *lkb = p;
3d6aa675fff9e (David Teigland     2011-07-06 17:00:54 -0500 712) 
a97f4a66d8ee4 (Bart Van Assche    2013-10-16 14:20:25 +0200 713) 	return lkb->lkb_nodeid == 0 && lkb->lkb_grmode != DLM_LOCK_IV;
3d6aa675fff9e (David Teigland     2011-07-06 17:00:54 -0500 714) }
3d6aa675fff9e (David Teigland     2011-07-06 17:00:54 -0500 715) 
3d6aa675fff9e (David Teigland     2011-07-06 17:00:54 -0500 716) static int lkb_idr_is_any(int id, void *p, void *data)
3d6aa675fff9e (David Teigland     2011-07-06 17:00:54 -0500 717) {
3d6aa675fff9e (David Teigland     2011-07-06 17:00:54 -0500 718) 	return 1;
3d6aa675fff9e (David Teigland     2011-07-06 17:00:54 -0500 719) }
3d6aa675fff9e (David Teigland     2011-07-06 17:00:54 -0500 720) 
3d6aa675fff9e (David Teigland     2011-07-06 17:00:54 -0500 721) static int lkb_idr_free(int id, void *p, void *data)
3d6aa675fff9e (David Teigland     2011-07-06 17:00:54 -0500 722) {
3d6aa675fff9e (David Teigland     2011-07-06 17:00:54 -0500 723) 	struct dlm_lkb *lkb = p;
3d6aa675fff9e (David Teigland     2011-07-06 17:00:54 -0500 724) 
3d6aa675fff9e (David Teigland     2011-07-06 17:00:54 -0500 725) 	if (lkb->lkb_lvbptr && lkb->lkb_flags & DLM_IFL_MSTCPY)
3d6aa675fff9e (David Teigland     2011-07-06 17:00:54 -0500 726) 		dlm_free_lvb(lkb->lkb_lvbptr);
3d6aa675fff9e (David Teigland     2011-07-06 17:00:54 -0500 727) 
3d6aa675fff9e (David Teigland     2011-07-06 17:00:54 -0500 728) 	dlm_free_lkb(lkb);
3d6aa675fff9e (David Teigland     2011-07-06 17:00:54 -0500 729) 	return 0;
3d6aa675fff9e (David Teigland     2011-07-06 17:00:54 -0500 730) }
3d6aa675fff9e (David Teigland     2011-07-06 17:00:54 -0500 731) 
3d6aa675fff9e (David Teigland     2011-07-06 17:00:54 -0500 732) /* NOTE: We check the lkbidr here rather than the resource table.
3d6aa675fff9e (David Teigland     2011-07-06 17:00:54 -0500 733)    This is because there may be LKBs queued as ASTs that have been unlinked
3d6aa675fff9e (David Teigland     2011-07-06 17:00:54 -0500 734)    from their RSBs and are pending deletion once the AST has been delivered */
3d6aa675fff9e (David Teigland     2011-07-06 17:00:54 -0500 735) 
3d6aa675fff9e (David Teigland     2011-07-06 17:00:54 -0500 736) static int lockspace_busy(struct dlm_ls *ls, int force)
3d6aa675fff9e (David Teigland     2011-07-06 17:00:54 -0500 737) {
3d6aa675fff9e (David Teigland     2011-07-06 17:00:54 -0500 738) 	int rv;
3d6aa675fff9e (David Teigland     2011-07-06 17:00:54 -0500 739) 
3d6aa675fff9e (David Teigland     2011-07-06 17:00:54 -0500 740) 	spin_lock(&ls->ls_lkbidr_spin);
3d6aa675fff9e (David Teigland     2011-07-06 17:00:54 -0500 741) 	if (force == 0) {
3d6aa675fff9e (David Teigland     2011-07-06 17:00:54 -0500 742) 		rv = idr_for_each(&ls->ls_lkbidr, lkb_idr_is_any, ls);
3d6aa675fff9e (David Teigland     2011-07-06 17:00:54 -0500 743) 	} else if (force == 1) {
3d6aa675fff9e (David Teigland     2011-07-06 17:00:54 -0500 744) 		rv = idr_for_each(&ls->ls_lkbidr, lkb_idr_is_local, ls);
3d6aa675fff9e (David Teigland     2011-07-06 17:00:54 -0500 745) 	} else {
3d6aa675fff9e (David Teigland     2011-07-06 17:00:54 -0500 746) 		rv = 0;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 747) 	}
3d6aa675fff9e (David Teigland     2011-07-06 17:00:54 -0500 748) 	spin_unlock(&ls->ls_lkbidr_spin);
3d6aa675fff9e (David Teigland     2011-07-06 17:00:54 -0500 749) 	return rv;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 750) }
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 751) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 752) static int release_lockspace(struct dlm_ls *ls, int force)
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 753) {
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 754) 	struct dlm_rsb *rsb;
9beb3bf5a92bb (Bob Peterson       2011-10-26 15:24:55 -0500 755) 	struct rb_node *n;
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 756) 	int i, busy, rv;
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 757) 
3d6aa675fff9e (David Teigland     2011-07-06 17:00:54 -0500 758) 	busy = lockspace_busy(ls, force);
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 759) 
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 760) 	spin_lock(&lslist_lock);
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 761) 	if (ls->ls_create_count == 1) {
3d6aa675fff9e (David Teigland     2011-07-06 17:00:54 -0500 762) 		if (busy) {
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 763) 			rv = -EBUSY;
3d6aa675fff9e (David Teigland     2011-07-06 17:00:54 -0500 764) 		} else {
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 765) 			/* remove_lockspace takes ls off lslist */
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 766) 			ls->ls_create_count = 0;
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 767) 			rv = 0;
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 768) 		}
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 769) 	} else if (ls->ls_create_count > 1) {
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 770) 		rv = --ls->ls_create_count;
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 771) 	} else {
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 772) 		rv = -EINVAL;
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 773) 	}
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 774) 	spin_unlock(&lslist_lock);
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 775) 
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 776) 	if (rv) {
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 777) 		log_debug(ls, "release_lockspace no remove %d", rv);
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 778) 		return rv;
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 779) 	}
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 780) 
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 781) 	dlm_device_deregister(ls);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 782) 
dc68c7ed362a0 (David Teigland     2008-08-18 11:43:30 -0500 783) 	if (force < 3 && dlm_user_daemon_available())
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 784) 		do_uevent(ls, 0);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 785) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 786) 	dlm_recoverd_stop(ls);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 787) 
9d232469bcd77 (Alexander Aring    2021-03-01 17:05:20 -0500 788) 	if (ls_count == 1) {
9d232469bcd77 (Alexander Aring    2021-03-01 17:05:20 -0500 789) 		dlm_scand_stop();
9d232469bcd77 (Alexander Aring    2021-03-01 17:05:20 -0500 790) 		dlm_lowcomms_shutdown();
9d232469bcd77 (Alexander Aring    2021-03-01 17:05:20 -0500 791) 	}
9d232469bcd77 (Alexander Aring    2021-03-01 17:05:20 -0500 792) 
23e8e1aaacb10 (David Teigland     2011-04-05 13:16:24 -0500 793) 	dlm_callback_stop(ls);
23e8e1aaacb10 (David Teigland     2011-04-05 13:16:24 -0500 794) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 795) 	remove_lockspace(ls);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 796) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 797) 	dlm_delete_debug_file(ls);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 798) 
8fc6ed9a3508a (David Teigland     2018-11-15 11:17:40 -0600 799) 	idr_destroy(&ls->ls_recover_idr);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 800) 	kfree(ls->ls_recover_buf);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 801) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 802) 	/*
3d6aa675fff9e (David Teigland     2011-07-06 17:00:54 -0500 803) 	 * Free all lkb's in idr
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 804) 	 */
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 805) 
3d6aa675fff9e (David Teigland     2011-07-06 17:00:54 -0500 806) 	idr_for_each(&ls->ls_lkbidr, lkb_idr_free, ls);
3d6aa675fff9e (David Teigland     2011-07-06 17:00:54 -0500 807) 	idr_destroy(&ls->ls_lkbidr);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 808) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 809) 	/*
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 810) 	 * Free all rsb's on rsbtbl[] lists
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 811) 	 */
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 812) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 813) 	for (i = 0; i < ls->ls_rsbtbl_size; i++) {
9beb3bf5a92bb (Bob Peterson       2011-10-26 15:24:55 -0500 814) 		while ((n = rb_first(&ls->ls_rsbtbl[i].keep))) {
9beb3bf5a92bb (Bob Peterson       2011-10-26 15:24:55 -0500 815) 			rsb = rb_entry(n, struct dlm_rsb, res_hashnode);
9beb3bf5a92bb (Bob Peterson       2011-10-26 15:24:55 -0500 816) 			rb_erase(n, &ls->ls_rsbtbl[i].keep);
52bda2b5bab87 (David Teigland     2007-11-07 09:06:49 -0600 817) 			dlm_free_rsb(rsb);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 818) 		}
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 819) 
9beb3bf5a92bb (Bob Peterson       2011-10-26 15:24:55 -0500 820) 		while ((n = rb_first(&ls->ls_rsbtbl[i].toss))) {
9beb3bf5a92bb (Bob Peterson       2011-10-26 15:24:55 -0500 821) 			rsb = rb_entry(n, struct dlm_rsb, res_hashnode);
9beb3bf5a92bb (Bob Peterson       2011-10-26 15:24:55 -0500 822) 			rb_erase(n, &ls->ls_rsbtbl[i].toss);
52bda2b5bab87 (David Teigland     2007-11-07 09:06:49 -0600 823) 			dlm_free_rsb(rsb);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 824) 		}
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 825) 	}
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 826) 
c282af4990167 (Bryn M. Reeves     2011-07-01 15:49:23 -0500 827) 	vfree(ls->ls_rsbtbl);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 828) 
05c32f47bfae7 (David Teigland     2012-06-14 12:17:32 -0500 829) 	for (i = 0; i < DLM_REMOVE_NAMES_MAX; i++)
05c32f47bfae7 (David Teigland     2012-06-14 12:17:32 -0500 830) 		kfree(ls->ls_remove_names[i]);
05c32f47bfae7 (David Teigland     2012-06-14 12:17:32 -0500 831) 
3881ac04ebf94 (David Teigland     2011-07-07 14:05:03 -0500 832) 	while (!list_empty(&ls->ls_new_rsb)) {
3881ac04ebf94 (David Teigland     2011-07-07 14:05:03 -0500 833) 		rsb = list_first_entry(&ls->ls_new_rsb, struct dlm_rsb,
3881ac04ebf94 (David Teigland     2011-07-07 14:05:03 -0500 834) 				       res_hashchain);
3881ac04ebf94 (David Teigland     2011-07-07 14:05:03 -0500 835) 		list_del(&rsb->res_hashchain);
3881ac04ebf94 (David Teigland     2011-07-07 14:05:03 -0500 836) 		dlm_free_rsb(rsb);
3881ac04ebf94 (David Teigland     2011-07-07 14:05:03 -0500 837) 	}
3881ac04ebf94 (David Teigland     2011-07-07 14:05:03 -0500 838) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 839) 	/*
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 840) 	 * Free structures on any other lists
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 841) 	 */
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 842) 
2896ee37ccc1f (David Teigland     2006-11-27 11:31:22 -0600 843) 	dlm_purge_requestqueue(ls);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 844) 	kfree(ls->ls_recover_args);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 845) 	dlm_clear_members(ls);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 846) 	dlm_clear_members_gone(ls);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 847) 	kfree(ls->ls_node_array);
075f01775f536 (David Teigland     2014-02-14 11:54:44 -0600 848) 	log_rinfo(ls, "release_lockspace final free");
197b12d6796a3 (Greg Kroah-Hartman 2007-12-20 08:13:05 -0800 849) 	kobject_put(&ls->ls_kobj);
79d72b54483bf (David Teigland     2007-05-18 09:02:20 -0500 850) 	/* The ls structure will be freed when the kobject is done with */
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 851) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 852) 	module_put(THIS_MODULE);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 853) 	return 0;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 854) }
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 855) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 856) /*
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 857)  * Called when a system has released all its locks and is not going to use the
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 858)  * lockspace any longer.  We free everything we're managing for this lockspace.
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 859)  * Remaining nodes will go through the recovery process as if we'd died.  The
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 860)  * lockspace must continue to function as usual, participating in recoveries,
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 861)  * until this returns.
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 862)  *
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 863)  * Force has 4 possible values:
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 864)  * 0 - don't destroy locksapce if it has any LKBs
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 865)  * 1 - destroy lockspace if it has remote LKBs but not if it has local LKBs
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 866)  * 2 - destroy lockspace regardless of LKBs
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 867)  * 3 - destroy lockspace as part of a forced shutdown
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 868)  */
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 869) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 870) int dlm_release_lockspace(void *lockspace, int force)
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 871) {
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 872) 	struct dlm_ls *ls;
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 873) 	int error;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 874) 
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 875) 	ls = dlm_find_lockspace_local(lockspace);
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 876) 	if (!ls)
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 877) 		return -EINVAL;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 878) 	dlm_put_lockspace(ls);
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 879) 
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 880) 	mutex_lock(&ls_lock);
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 881) 	error = release_lockspace(ls, force);
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 882) 	if (!error)
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 883) 		ls_count--;
278afcbf4fe96 (David Teigland     2008-11-13 13:22:34 -0600 884) 	if (!ls_count)
9d232469bcd77 (Alexander Aring    2021-03-01 17:05:20 -0500 885) 		dlm_lowcomms_stop();
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 886) 	mutex_unlock(&ls_lock);
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 887) 
0f8e0d9a31740 (David Teigland     2008-08-06 13:30:24 -0500 888) 	return error;
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 889) }
e7fd41792fc0e (David Teigland     2006-01-18 09:30:29 +0000 890) 
dc68c7ed362a0 (David Teigland     2008-08-18 11:43:30 -0500 891) void dlm_stop_lockspaces(void)
dc68c7ed362a0 (David Teigland     2008-08-18 11:43:30 -0500 892) {
dc68c7ed362a0 (David Teigland     2008-08-18 11:43:30 -0500 893) 	struct dlm_ls *ls;
696b3d84605e5 (David Teigland     2013-06-25 12:48:01 -0500 894) 	int count;
dc68c7ed362a0 (David Teigland     2008-08-18 11:43:30 -0500 895) 
dc68c7ed362a0 (David Teigland     2008-08-18 11:43:30 -0500 896)  restart:
696b3d84605e5 (David Teigland     2013-06-25 12:48:01 -0500 897) 	count = 0;
dc68c7ed362a0 (David Teigland     2008-08-18 11:43:30 -0500 898) 	spin_lock(&lslist_lock);
dc68c7ed362a0 (David Teigland     2008-08-18 11:43:30 -0500 899) 	list_for_each_entry(ls, &lslist, ls_list) {
696b3d84605e5 (David Teigland     2013-06-25 12:48:01 -0500 900) 		if (!test_bit(LSFL_RUNNING, &ls->ls_flags)) {
696b3d84605e5 (David Teigland     2013-06-25 12:48:01 -0500 901) 			count++;
dc68c7ed362a0 (David Teigland     2008-08-18 11:43:30 -0500 902) 			continue;
696b3d84605e5 (David Teigland     2013-06-25 12:48:01 -0500 903) 		}
dc68c7ed362a0 (David Teigland     2008-08-18 11:43:30 -0500 904) 		spin_unlock(&lslist_lock);
dc68c7ed362a0 (David Teigland     2008-08-18 11:43:30 -0500 905) 		log_error(ls, "no userland control daemon, stopping lockspace");
dc68c7ed362a0 (David Teigland     2008-08-18 11:43:30 -0500 906) 		dlm_ls_stop(ls);
dc68c7ed362a0 (David Teigland     2008-08-18 11:43:30 -0500 907) 		goto restart;
dc68c7ed362a0 (David Teigland     2008-08-18 11:43:30 -0500 908) 	}
dc68c7ed362a0 (David Teigland     2008-08-18 11:43:30 -0500 909) 	spin_unlock(&lslist_lock);
696b3d84605e5 (David Teigland     2013-06-25 12:48:01 -0500 910) 
696b3d84605e5 (David Teigland     2013-06-25 12:48:01 -0500 911) 	if (count)
696b3d84605e5 (David Teigland     2013-06-25 12:48:01 -0500 912) 		log_print("dlm user daemon left %d lockspaces", count);
dc68c7ed362a0 (David Teigland     2008-08-18 11:43:30 -0500 913) }
dc68c7ed362a0 (David Teigland     2008-08-18 11:43:30 -0500 914)