Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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