| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | /******************************************************************************
 | 
					
						
							|  |  |  | ******************************************************************************* | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | **  Copyright (C) Sistina Software, Inc.  1997-2003  All rights reserved. | 
					
						
							| 
									
										
										
										
											2008-08-06 13:30:24 -05:00
										 |  |  | **  Copyright (C) 2004-2008 Red Hat, Inc.  All rights reserved. | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | ** | 
					
						
							|  |  |  | **  This copyrighted material is made available to anyone wishing to use, | 
					
						
							|  |  |  | **  modify, copy, or redistribute it subject to the terms and conditions | 
					
						
							|  |  |  | **  of the GNU General Public License v.2. | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ******************************************************************************* | 
					
						
							|  |  |  | ******************************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "dlm_internal.h"
 | 
					
						
							|  |  |  | #include "lockspace.h"
 | 
					
						
							|  |  |  | #include "member.h"
 | 
					
						
							|  |  |  | #include "recoverd.h"
 | 
					
						
							|  |  |  | #include "ast.h"
 | 
					
						
							|  |  |  | #include "dir.h"
 | 
					
						
							|  |  |  | #include "lowcomms.h"
 | 
					
						
							|  |  |  | #include "config.h"
 | 
					
						
							|  |  |  | #include "memory.h"
 | 
					
						
							|  |  |  | #include "lock.h"
 | 
					
						
							| 
									
										
										
										
											2006-04-28 10:51:53 -04:00
										 |  |  | #include "recover.h"
 | 
					
						
							| 
									
										
										
										
											2006-11-27 11:31:22 -06:00
										 |  |  | #include "requestqueue.h"
 | 
					
						
							| 
									
										
										
										
											2008-08-06 13:30:24 -05:00
										 |  |  | #include "user.h"
 | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static int			ls_count; | 
					
						
							| 
									
										
										
										
											2006-01-20 08:47:07 +00:00
										 |  |  | static struct mutex		ls_lock; | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | static struct list_head		lslist; | 
					
						
							|  |  |  | static spinlock_t		lslist_lock; | 
					
						
							|  |  |  | static struct task_struct *	scand_task; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static ssize_t dlm_control_store(struct dlm_ls *ls, const char *buf, size_t len) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ssize_t ret = len; | 
					
						
							|  |  |  | 	int n = simple_strtol(buf, NULL, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-11-06 08:53:28 +00:00
										 |  |  | 	ls = dlm_find_lockspace_local(ls->ls_local_handle); | 
					
						
							|  |  |  | 	if (!ls) | 
					
						
							|  |  |  | 		return -EINVAL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 	switch (n) { | 
					
						
							|  |  |  | 	case 0: | 
					
						
							|  |  |  | 		dlm_ls_stop(ls); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case 1: | 
					
						
							|  |  |  | 		dlm_ls_start(ls); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		ret = -EINVAL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2006-11-06 08:53:28 +00:00
										 |  |  | 	dlm_put_lockspace(ls); | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static ssize_t dlm_event_store(struct dlm_ls *ls, const char *buf, size_t len) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ls->ls_uevent_result = simple_strtol(buf, NULL, 0); | 
					
						
							|  |  |  | 	set_bit(LSFL_UEVENT_WAIT, &ls->ls_flags); | 
					
						
							|  |  |  | 	wake_up(&ls->ls_uevent_wait); | 
					
						
							|  |  |  | 	return len; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static ssize_t dlm_id_show(struct dlm_ls *ls, char *buf) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2006-09-06 17:01:40 -05:00
										 |  |  | 	return snprintf(buf, PAGE_SIZE, "%u\n", ls->ls_global_id); | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static ssize_t dlm_id_store(struct dlm_ls *ls, const char *buf, size_t len) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ls->ls_global_id = simple_strtoul(buf, NULL, 0); | 
					
						
							|  |  |  | 	return len; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-28 10:51:53 -04:00
										 |  |  | static ssize_t dlm_recover_status_show(struct dlm_ls *ls, char *buf) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	uint32_t status = dlm_recover_status(ls); | 
					
						
							| 
									
										
										
										
											2006-09-06 17:01:40 -05:00
										 |  |  | 	return snprintf(buf, PAGE_SIZE, "%x\n", status); | 
					
						
							| 
									
										
										
										
											2006-04-28 10:51:53 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-08 17:08:42 -05:00
										 |  |  | static ssize_t dlm_recover_nodeid_show(struct dlm_ls *ls, char *buf) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2006-09-06 17:01:40 -05:00
										 |  |  | 	return snprintf(buf, PAGE_SIZE, "%d\n", ls->ls_recover_nodeid); | 
					
						
							| 
									
										
										
										
											2006-08-08 17:08:42 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | struct dlm_attr { | 
					
						
							|  |  |  | 	struct attribute attr; | 
					
						
							|  |  |  | 	ssize_t (*show)(struct dlm_ls *, char *); | 
					
						
							|  |  |  | 	ssize_t (*store)(struct dlm_ls *, const char *, size_t); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct dlm_attr dlm_attr_control = { | 
					
						
							|  |  |  | 	.attr  = {.name = "control", .mode = S_IWUSR}, | 
					
						
							|  |  |  | 	.store = dlm_control_store | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct dlm_attr dlm_attr_event = { | 
					
						
							|  |  |  | 	.attr  = {.name = "event_done", .mode = S_IWUSR}, | 
					
						
							|  |  |  | 	.store = dlm_event_store | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct dlm_attr dlm_attr_id = { | 
					
						
							|  |  |  | 	.attr  = {.name = "id", .mode = S_IRUGO | S_IWUSR}, | 
					
						
							|  |  |  | 	.show  = dlm_id_show, | 
					
						
							|  |  |  | 	.store = dlm_id_store | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-28 10:51:53 -04:00
										 |  |  | static struct dlm_attr dlm_attr_recover_status = { | 
					
						
							|  |  |  | 	.attr  = {.name = "recover_status", .mode = S_IRUGO}, | 
					
						
							|  |  |  | 	.show  = dlm_recover_status_show | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-08 17:08:42 -05:00
										 |  |  | static struct dlm_attr dlm_attr_recover_nodeid = { | 
					
						
							|  |  |  | 	.attr  = {.name = "recover_nodeid", .mode = S_IRUGO}, | 
					
						
							|  |  |  | 	.show  = dlm_recover_nodeid_show | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | static struct attribute *dlm_attrs[] = { | 
					
						
							|  |  |  | 	&dlm_attr_control.attr, | 
					
						
							|  |  |  | 	&dlm_attr_event.attr, | 
					
						
							|  |  |  | 	&dlm_attr_id.attr, | 
					
						
							| 
									
										
										
										
											2006-04-28 10:51:53 -04:00
										 |  |  | 	&dlm_attr_recover_status.attr, | 
					
						
							| 
									
										
										
										
											2006-08-08 17:08:42 -05:00
										 |  |  | 	&dlm_attr_recover_nodeid.attr, | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 	NULL, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static ssize_t dlm_attr_show(struct kobject *kobj, struct attribute *attr, | 
					
						
							|  |  |  | 			     char *buf) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct dlm_ls *ls  = container_of(kobj, struct dlm_ls, ls_kobj); | 
					
						
							|  |  |  | 	struct dlm_attr *a = container_of(attr, struct dlm_attr, attr); | 
					
						
							|  |  |  | 	return a->show ? a->show(ls, buf) : 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static ssize_t dlm_attr_store(struct kobject *kobj, struct attribute *attr, | 
					
						
							|  |  |  | 			      const char *buf, size_t len) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct dlm_ls *ls  = container_of(kobj, struct dlm_ls, ls_kobj); | 
					
						
							|  |  |  | 	struct dlm_attr *a = container_of(attr, struct dlm_attr, attr); | 
					
						
							|  |  |  | 	return a->store ? a->store(ls, buf, len) : len; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-11-02 14:41:23 +00:00
										 |  |  | static void lockspace_kobj_release(struct kobject *k) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct dlm_ls *ls  = container_of(k, struct dlm_ls, ls_kobj); | 
					
						
							|  |  |  | 	kfree(ls); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | static struct sysfs_ops dlm_attr_ops = { | 
					
						
							|  |  |  | 	.show  = dlm_attr_show, | 
					
						
							|  |  |  | 	.store = dlm_attr_store, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct kobj_type dlm_ktype = { | 
					
						
							|  |  |  | 	.default_attrs = dlm_attrs, | 
					
						
							|  |  |  | 	.sysfs_ops     = &dlm_attr_ops, | 
					
						
							| 
									
										
										
										
											2006-11-02 14:41:23 +00:00
										 |  |  | 	.release       = lockspace_kobj_release, | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-10-29 20:13:17 +01:00
										 |  |  | static struct kset *dlm_kset; | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static int do_uevent(struct dlm_ls *ls, int in) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int error; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (in) | 
					
						
							|  |  |  | 		kobject_uevent(&ls->ls_kobj, KOBJ_ONLINE); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		kobject_uevent(&ls->ls_kobj, KOBJ_OFFLINE); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-05-18 09:03:35 -05:00
										 |  |  | 	log_debug(ls, "%s the lockspace group...", in ? "joining" : "leaving"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* dlm_controld will see the uevent, do the necessary group management
 | 
					
						
							|  |  |  | 	   and then write to sysfs to wake us */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 	error = wait_event_interruptible(ls->ls_uevent_wait, | 
					
						
							|  |  |  | 			test_and_clear_bit(LSFL_UEVENT_WAIT, &ls->ls_flags)); | 
					
						
							| 
									
										
										
										
											2007-05-18 09:03:35 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	log_debug(ls, "group event done %d %d", error, ls->ls_uevent_result); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 	if (error) | 
					
						
							|  |  |  | 		goto out; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	error = ls->ls_uevent_result; | 
					
						
							|  |  |  |  out: | 
					
						
							| 
									
										
										
										
											2007-05-18 09:03:35 -05:00
										 |  |  | 	if (error) | 
					
						
							|  |  |  | 		log_error(ls, "group %s failed %d %d", in ? "join" : "leave", | 
					
						
							|  |  |  | 			  error, ls->ls_uevent_result); | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 	return error; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-02 01:53:46 +08:00
										 |  |  | int __init dlm_lockspace_init(void) | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	ls_count = 0; | 
					
						
							| 
									
										
										
										
											2006-01-20 08:47:07 +00:00
										 |  |  | 	mutex_init(&ls_lock); | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 	INIT_LIST_HEAD(&lslist); | 
					
						
							|  |  |  | 	spin_lock_init(&lslist_lock); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-06 10:36:58 -08:00
										 |  |  | 	dlm_kset = kset_create_and_add("dlm", NULL, kernel_kobj); | 
					
						
							| 
									
										
										
										
											2007-10-29 20:13:17 +01:00
										 |  |  | 	if (!dlm_kset) { | 
					
						
							| 
									
										
										
										
											2008-04-30 00:55:09 -07:00
										 |  |  | 		printk(KERN_WARNING "%s: can not create kset\n", __func__); | 
					
						
							| 
									
										
										
										
											2007-10-29 20:13:17 +01:00
										 |  |  | 		return -ENOMEM; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void dlm_lockspace_exit(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2007-10-29 20:13:17 +01:00
										 |  |  | 	kset_unregister(dlm_kset); | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-18 14:03:25 -05:00
										 |  |  | static struct dlm_ls *find_ls_to_scan(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct dlm_ls *ls; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spin_lock(&lslist_lock); | 
					
						
							|  |  |  | 	list_for_each_entry(ls, &lslist, ls_list) { | 
					
						
							|  |  |  | 		if (time_after_eq(jiffies, ls->ls_scan_time + | 
					
						
							|  |  |  | 					    dlm_config.ci_scan_secs * HZ)) { | 
					
						
							|  |  |  | 			spin_unlock(&lslist_lock); | 
					
						
							|  |  |  | 			return ls; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	spin_unlock(&lslist_lock); | 
					
						
							|  |  |  | 	return NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | static int dlm_scand(void *data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct dlm_ls *ls; | 
					
						
							| 
									
										
										
										
											2008-08-18 14:03:25 -05:00
										 |  |  | 	int timeout_jiffies = dlm_config.ci_scan_secs * HZ; | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	while (!kthread_should_stop()) { | 
					
						
							| 
									
										
										
										
											2008-08-18 14:03:25 -05:00
										 |  |  | 		ls = find_ls_to_scan(); | 
					
						
							|  |  |  | 		if (ls) { | 
					
						
							| 
									
										
										
										
											2007-05-18 08:58:15 -05:00
										 |  |  | 			if (dlm_lock_recovery_try(ls)) { | 
					
						
							| 
									
										
										
										
											2008-08-18 14:03:25 -05:00
										 |  |  | 				ls->ls_scan_time = jiffies; | 
					
						
							| 
									
										
										
										
											2007-05-18 08:58:15 -05:00
										 |  |  | 				dlm_scan_rsbs(ls); | 
					
						
							| 
									
										
										
										
											2007-05-18 08:59:31 -05:00
										 |  |  | 				dlm_scan_timeout(ls); | 
					
						
							| 
									
										
										
										
											2007-05-18 08:58:15 -05:00
										 |  |  | 				dlm_unlock_recovery(ls); | 
					
						
							| 
									
										
										
										
											2008-08-18 14:03:25 -05:00
										 |  |  | 			} else { | 
					
						
							|  |  |  | 				ls->ls_scan_time += HZ; | 
					
						
							| 
									
										
										
										
											2007-05-18 08:58:15 -05:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2008-08-18 14:03:25 -05:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			schedule_timeout_interruptible(timeout_jiffies); | 
					
						
							| 
									
										
										
										
											2007-05-18 08:58:15 -05:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int dlm_scand_start(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct task_struct *p; | 
					
						
							|  |  |  | 	int error = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	p = kthread_run(dlm_scand, NULL, "dlm_scand"); | 
					
						
							|  |  |  | 	if (IS_ERR(p)) | 
					
						
							|  |  |  | 		error = PTR_ERR(p); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		scand_task = p; | 
					
						
							|  |  |  | 	return error; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void dlm_scand_stop(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	kthread_stop(scand_task); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct dlm_ls *dlm_find_lockspace_global(uint32_t id) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct dlm_ls *ls; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spin_lock(&lslist_lock); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	list_for_each_entry(ls, &lslist, ls_list) { | 
					
						
							|  |  |  | 		if (ls->ls_global_id == id) { | 
					
						
							|  |  |  | 			ls->ls_count++; | 
					
						
							|  |  |  | 			goto out; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	ls = NULL; | 
					
						
							|  |  |  |  out: | 
					
						
							|  |  |  | 	spin_unlock(&lslist_lock); | 
					
						
							|  |  |  | 	return ls; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-07-12 16:44:04 -05:00
										 |  |  | struct dlm_ls *dlm_find_lockspace_local(dlm_lockspace_t *lockspace) | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2006-07-12 16:44:04 -05:00
										 |  |  | 	struct dlm_ls *ls; | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	spin_lock(&lslist_lock); | 
					
						
							| 
									
										
										
										
											2006-07-12 16:44:04 -05:00
										 |  |  | 	list_for_each_entry(ls, &lslist, ls_list) { | 
					
						
							|  |  |  | 		if (ls->ls_local_handle == lockspace) { | 
					
						
							|  |  |  | 			ls->ls_count++; | 
					
						
							|  |  |  | 			goto out; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	ls = NULL; | 
					
						
							|  |  |  |  out: | 
					
						
							|  |  |  | 	spin_unlock(&lslist_lock); | 
					
						
							|  |  |  | 	return ls; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct dlm_ls *dlm_find_lockspace_device(int minor) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct dlm_ls *ls; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spin_lock(&lslist_lock); | 
					
						
							|  |  |  | 	list_for_each_entry(ls, &lslist, ls_list) { | 
					
						
							|  |  |  | 		if (ls->ls_device.minor == minor) { | 
					
						
							|  |  |  | 			ls->ls_count++; | 
					
						
							|  |  |  | 			goto out; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	ls = NULL; | 
					
						
							|  |  |  |  out: | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 	spin_unlock(&lslist_lock); | 
					
						
							|  |  |  | 	return ls; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void dlm_put_lockspace(struct dlm_ls *ls) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	spin_lock(&lslist_lock); | 
					
						
							|  |  |  | 	ls->ls_count--; | 
					
						
							|  |  |  | 	spin_unlock(&lslist_lock); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void remove_lockspace(struct dlm_ls *ls) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	for (;;) { | 
					
						
							|  |  |  | 		spin_lock(&lslist_lock); | 
					
						
							|  |  |  | 		if (ls->ls_count == 0) { | 
					
						
							| 
									
										
										
										
											2008-08-06 13:30:24 -05:00
										 |  |  | 			WARN_ON(ls->ls_create_count != 0); | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 			list_del(&ls->ls_list); | 
					
						
							|  |  |  | 			spin_unlock(&lslist_lock); | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		spin_unlock(&lslist_lock); | 
					
						
							|  |  |  | 		ssleep(1); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int threads_start(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int error; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Thread which process lock requests for all lockspace's */ | 
					
						
							|  |  |  | 	error = dlm_astd_start(); | 
					
						
							|  |  |  | 	if (error) { | 
					
						
							|  |  |  | 		log_print("cannot start dlm_astd thread %d", error); | 
					
						
							|  |  |  | 		goto fail; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	error = dlm_scand_start(); | 
					
						
							|  |  |  | 	if (error) { | 
					
						
							|  |  |  | 		log_print("cannot start dlm_scand thread %d", error); | 
					
						
							|  |  |  | 		goto astd_fail; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Thread for sending/receiving messages for all lockspace's */ | 
					
						
							|  |  |  | 	error = dlm_lowcomms_start(); | 
					
						
							|  |  |  | 	if (error) { | 
					
						
							|  |  |  | 		log_print("cannot start dlm lowcomms %d", error); | 
					
						
							|  |  |  | 		goto scand_fail; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  scand_fail: | 
					
						
							|  |  |  | 	dlm_scand_stop(); | 
					
						
							|  |  |  |  astd_fail: | 
					
						
							|  |  |  | 	dlm_astd_stop(); | 
					
						
							|  |  |  |  fail: | 
					
						
							|  |  |  | 	return error; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void threads_stop(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	dlm_scand_stop(); | 
					
						
							|  |  |  | 	dlm_lowcomms_stop(); | 
					
						
							|  |  |  | 	dlm_astd_stop(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int new_lockspace(char *name, int namelen, void **lockspace, | 
					
						
							|  |  |  | 			 uint32_t flags, int lvblen) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct dlm_ls *ls; | 
					
						
							| 
									
										
										
										
											2008-08-06 13:30:24 -05:00
										 |  |  | 	int i, size, error; | 
					
						
							| 
									
										
										
										
											2007-05-18 09:02:20 -05:00
										 |  |  | 	int do_unreg = 0; | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (namelen > DLM_LOCKSPACE_LEN) | 
					
						
							|  |  |  | 		return -EINVAL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!lvblen || (lvblen % 8)) | 
					
						
							|  |  |  | 		return -EINVAL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!try_module_get(THIS_MODULE)) | 
					
						
							|  |  |  | 		return -EINVAL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-18 11:43:30 -05:00
										 |  |  | 	if (!dlm_user_daemon_available()) { | 
					
						
							|  |  |  | 		module_put(THIS_MODULE); | 
					
						
							|  |  |  | 		return -EUNATCH; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-06 13:30:24 -05:00
										 |  |  | 	error = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spin_lock(&lslist_lock); | 
					
						
							|  |  |  | 	list_for_each_entry(ls, &lslist, ls_list) { | 
					
						
							|  |  |  | 		WARN_ON(ls->ls_create_count <= 0); | 
					
						
							|  |  |  | 		if (ls->ls_namelen != namelen) | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		if (memcmp(ls->ls_name, name, namelen)) | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		if (flags & DLM_LSFL_NEWEXCL) { | 
					
						
							|  |  |  | 			error = -EEXIST; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		ls->ls_create_count++; | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 		module_put(THIS_MODULE); | 
					
						
							| 
									
										
										
										
											2008-08-06 13:30:24 -05:00
										 |  |  | 		error = 1; /* not an error, return 0 */ | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-08-06 13:30:24 -05:00
										 |  |  | 	spin_unlock(&lslist_lock); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (error < 0) | 
					
						
							|  |  |  | 		goto out; | 
					
						
							|  |  |  | 	if (error) | 
					
						
							|  |  |  | 		goto ret_zero; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	error = -ENOMEM; | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-20 08:47:07 +00:00
										 |  |  | 	ls = kzalloc(sizeof(struct dlm_ls) + namelen, GFP_KERNEL); | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 	if (!ls) | 
					
						
							|  |  |  | 		goto out; | 
					
						
							|  |  |  | 	memcpy(ls->ls_name, name, namelen); | 
					
						
							|  |  |  | 	ls->ls_namelen = namelen; | 
					
						
							|  |  |  | 	ls->ls_lvblen = lvblen; | 
					
						
							|  |  |  | 	ls->ls_count = 0; | 
					
						
							|  |  |  | 	ls->ls_flags = 0; | 
					
						
							| 
									
										
										
										
											2008-08-18 14:03:25 -05:00
										 |  |  | 	ls->ls_scan_time = jiffies; | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-05-18 08:59:31 -05:00
										 |  |  | 	if (flags & DLM_LSFL_TIMEWARN) | 
					
						
							|  |  |  | 		set_bit(LSFL_TIMEWARN, &ls->ls_flags); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-06-06 09:21:22 -05:00
										 |  |  | 	if (flags & DLM_LSFL_FS) | 
					
						
							|  |  |  | 		ls->ls_allocation = GFP_NOFS; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		ls->ls_allocation = GFP_KERNEL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-06-11 10:47:18 -05:00
										 |  |  | 	/* ls_exflags are forced to match among nodes, and we don't
 | 
					
						
							| 
									
										
										
										
											2008-08-06 13:30:24 -05:00
										 |  |  | 	   need to require all nodes to have some flags set */ | 
					
						
							|  |  |  | 	ls->ls_exflags = (flags & ~(DLM_LSFL_TIMEWARN | DLM_LSFL_FS | | 
					
						
							|  |  |  | 				    DLM_LSFL_NEWEXCL)); | 
					
						
							| 
									
										
										
										
											2007-06-11 10:47:18 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-01-09 09:41:48 -06:00
										 |  |  | 	size = dlm_config.ci_rsbtbl_size; | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 	ls->ls_rsbtbl_size = size; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ls->ls_rsbtbl = kmalloc(sizeof(struct dlm_rsbtable) * size, GFP_KERNEL); | 
					
						
							|  |  |  | 	if (!ls->ls_rsbtbl) | 
					
						
							|  |  |  | 		goto out_lsfree; | 
					
						
							|  |  |  | 	for (i = 0; i < size; i++) { | 
					
						
							|  |  |  | 		INIT_LIST_HEAD(&ls->ls_rsbtbl[i].list); | 
					
						
							|  |  |  | 		INIT_LIST_HEAD(&ls->ls_rsbtbl[i].toss); | 
					
						
							| 
									
										
										
										
											2009-01-07 16:50:41 -06:00
										 |  |  | 		spin_lock_init(&ls->ls_rsbtbl[i].lock); | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-01-09 09:41:48 -06:00
										 |  |  | 	size = dlm_config.ci_lkbtbl_size; | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 	ls->ls_lkbtbl_size = size; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ls->ls_lkbtbl = kmalloc(sizeof(struct dlm_lkbtable) * size, GFP_KERNEL); | 
					
						
							|  |  |  | 	if (!ls->ls_lkbtbl) | 
					
						
							|  |  |  | 		goto out_rsbfree; | 
					
						
							|  |  |  | 	for (i = 0; i < size; i++) { | 
					
						
							|  |  |  | 		INIT_LIST_HEAD(&ls->ls_lkbtbl[i].list); | 
					
						
							|  |  |  | 		rwlock_init(&ls->ls_lkbtbl[i].lock); | 
					
						
							|  |  |  | 		ls->ls_lkbtbl[i].counter = 1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-01-09 09:41:48 -06:00
										 |  |  | 	size = dlm_config.ci_dirtbl_size; | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 	ls->ls_dirtbl_size = size; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ls->ls_dirtbl = kmalloc(sizeof(struct dlm_dirtable) * size, GFP_KERNEL); | 
					
						
							|  |  |  | 	if (!ls->ls_dirtbl) | 
					
						
							|  |  |  | 		goto out_lkbfree; | 
					
						
							|  |  |  | 	for (i = 0; i < size; i++) { | 
					
						
							|  |  |  | 		INIT_LIST_HEAD(&ls->ls_dirtbl[i].list); | 
					
						
							| 
									
										
										
										
											2009-01-16 16:21:12 +00:00
										 |  |  | 		spin_lock_init(&ls->ls_dirtbl[i].lock); | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	INIT_LIST_HEAD(&ls->ls_waiters); | 
					
						
							| 
									
										
										
										
											2006-01-20 08:47:07 +00:00
										 |  |  | 	mutex_init(&ls->ls_waiters_mutex); | 
					
						
							| 
									
										
										
										
											2007-03-28 09:56:46 -05:00
										 |  |  | 	INIT_LIST_HEAD(&ls->ls_orphans); | 
					
						
							|  |  |  | 	mutex_init(&ls->ls_orphans_mutex); | 
					
						
							| 
									
										
										
										
											2007-05-18 08:59:31 -05:00
										 |  |  | 	INIT_LIST_HEAD(&ls->ls_timeout); | 
					
						
							|  |  |  | 	mutex_init(&ls->ls_timeout_mutex); | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	INIT_LIST_HEAD(&ls->ls_nodes); | 
					
						
							|  |  |  | 	INIT_LIST_HEAD(&ls->ls_nodes_gone); | 
					
						
							|  |  |  | 	ls->ls_num_nodes = 0; | 
					
						
							|  |  |  | 	ls->ls_low_nodeid = 0; | 
					
						
							|  |  |  | 	ls->ls_total_weight = 0; | 
					
						
							|  |  |  | 	ls->ls_node_array = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	memset(&ls->ls_stub_rsb, 0, sizeof(struct dlm_rsb)); | 
					
						
							|  |  |  | 	ls->ls_stub_rsb.res_ls = ls; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-07-25 13:44:31 -05:00
										 |  |  | 	ls->ls_debug_rsb_dentry = NULL; | 
					
						
							|  |  |  | 	ls->ls_debug_waiters_dentry = NULL; | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	init_waitqueue_head(&ls->ls_uevent_wait); | 
					
						
							|  |  |  | 	ls->ls_uevent_result = 0; | 
					
						
							| 
									
										
										
										
											2007-05-18 09:03:35 -05:00
										 |  |  | 	init_completion(&ls->ls_members_done); | 
					
						
							|  |  |  | 	ls->ls_members_result = -1; | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	ls->ls_recoverd_task = NULL; | 
					
						
							| 
									
										
										
										
											2006-01-20 08:47:07 +00:00
										 |  |  | 	mutex_init(&ls->ls_recoverd_active); | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 	spin_lock_init(&ls->ls_recover_lock); | 
					
						
							| 
									
										
										
										
											2006-11-27 13:19:28 -06:00
										 |  |  | 	spin_lock_init(&ls->ls_rcom_spin); | 
					
						
							|  |  |  | 	get_random_bytes(&ls->ls_rcom_seq, sizeof(uint64_t)); | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 	ls->ls_recover_status = 0; | 
					
						
							|  |  |  | 	ls->ls_recover_seq = 0; | 
					
						
							|  |  |  | 	ls->ls_recover_args = NULL; | 
					
						
							|  |  |  | 	init_rwsem(&ls->ls_in_recovery); | 
					
						
							| 
									
										
										
										
											2007-09-27 15:53:38 -05:00
										 |  |  | 	init_rwsem(&ls->ls_recv_active); | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 	INIT_LIST_HEAD(&ls->ls_requestqueue); | 
					
						
							| 
									
										
										
										
											2006-01-20 08:47:07 +00:00
										 |  |  | 	mutex_init(&ls->ls_requestqueue_mutex); | 
					
						
							| 
									
										
										
										
											2006-07-12 16:44:04 -05:00
										 |  |  | 	mutex_init(&ls->ls_clear_proc_locks); | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-01-09 09:41:48 -06:00
										 |  |  | 	ls->ls_recover_buf = kmalloc(dlm_config.ci_buffer_size, GFP_KERNEL); | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 	if (!ls->ls_recover_buf) | 
					
						
							|  |  |  | 		goto out_dirfree; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	INIT_LIST_HEAD(&ls->ls_recover_list); | 
					
						
							|  |  |  | 	spin_lock_init(&ls->ls_recover_list_lock); | 
					
						
							|  |  |  | 	ls->ls_recover_list_count = 0; | 
					
						
							| 
									
										
										
										
											2006-07-12 16:44:04 -05:00
										 |  |  | 	ls->ls_local_handle = ls; | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 	init_waitqueue_head(&ls->ls_wait_general); | 
					
						
							|  |  |  | 	INIT_LIST_HEAD(&ls->ls_root_list); | 
					
						
							|  |  |  | 	init_rwsem(&ls->ls_root_sem); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	down_write(&ls->ls_in_recovery); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-24 14:47:20 -05:00
										 |  |  | 	spin_lock(&lslist_lock); | 
					
						
							| 
									
										
										
										
											2008-08-06 13:30:24 -05:00
										 |  |  | 	ls->ls_create_count = 1; | 
					
						
							| 
									
										
										
										
											2006-08-24 14:47:20 -05:00
										 |  |  | 	list_add(&ls->ls_list, &lslist); | 
					
						
							|  |  |  | 	spin_unlock(&lslist_lock); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* needs to find ls in lslist */ | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 	error = dlm_recoverd_start(ls); | 
					
						
							|  |  |  | 	if (error) { | 
					
						
							|  |  |  | 		log_error(ls, "can't start dlm_recoverd %d", error); | 
					
						
							| 
									
										
										
										
											2007-05-18 09:02:20 -05:00
										 |  |  | 		goto out_delist; | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-12-17 15:54:39 -04:00
										 |  |  | 	ls->ls_kobj.kset = dlm_kset; | 
					
						
							|  |  |  | 	error = kobject_init_and_add(&ls->ls_kobj, &dlm_ktype, NULL, | 
					
						
							|  |  |  | 				     "%s", ls->ls_name); | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 	if (error) | 
					
						
							| 
									
										
										
										
											2007-05-18 09:02:20 -05:00
										 |  |  | 		goto out_stop; | 
					
						
							| 
									
										
										
										
											2007-12-17 15:54:39 -04:00
										 |  |  | 	kobject_uevent(&ls->ls_kobj, KOBJ_ADD); | 
					
						
							| 
									
										
										
										
											2007-05-18 09:02:20 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* let kobject handle freeing of ls if there's an error */ | 
					
						
							|  |  |  | 	do_unreg = 1; | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-05-18 09:03:35 -05:00
										 |  |  | 	/* This uevent triggers dlm_controld in userspace to add us to the
 | 
					
						
							|  |  |  | 	   group of nodes that are members of this lockspace (managed by the | 
					
						
							|  |  |  | 	   cluster infrastructure.)  Once it's done that, it tells us who the | 
					
						
							|  |  |  | 	   current lockspace members are (via configfs) and then tells the | 
					
						
							|  |  |  | 	   lockspace to start running (via sysfs) in dlm_ls_start(). */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 	error = do_uevent(ls, 1); | 
					
						
							|  |  |  | 	if (error) | 
					
						
							| 
									
										
										
										
											2007-05-18 09:02:20 -05:00
										 |  |  | 		goto out_stop; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-05-18 09:03:35 -05:00
										 |  |  | 	wait_for_completion(&ls->ls_members_done); | 
					
						
							|  |  |  | 	error = ls->ls_members_result; | 
					
						
							|  |  |  | 	if (error) | 
					
						
							|  |  |  | 		goto out_members; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-05-18 09:02:20 -05:00
										 |  |  | 	dlm_create_debug_file(ls); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	log_debug(ls, "join complete"); | 
					
						
							| 
									
										
										
										
											2008-08-06 13:30:24 -05:00
										 |  |  |  ret_zero: | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 	*lockspace = ls; | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-05-18 09:03:35 -05:00
										 |  |  |  out_members: | 
					
						
							|  |  |  | 	do_uevent(ls, 0); | 
					
						
							|  |  |  | 	dlm_clear_members(ls); | 
					
						
							|  |  |  | 	kfree(ls->ls_node_array); | 
					
						
							| 
									
										
										
										
											2007-05-18 09:02:20 -05:00
										 |  |  |  out_stop: | 
					
						
							| 
									
										
										
										
											2006-08-24 14:47:20 -05:00
										 |  |  | 	dlm_recoverd_stop(ls); | 
					
						
							| 
									
										
										
										
											2007-05-18 09:02:20 -05:00
										 |  |  |  out_delist: | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 	spin_lock(&lslist_lock); | 
					
						
							|  |  |  | 	list_del(&ls->ls_list); | 
					
						
							|  |  |  | 	spin_unlock(&lslist_lock); | 
					
						
							|  |  |  | 	kfree(ls->ls_recover_buf); | 
					
						
							|  |  |  |  out_dirfree: | 
					
						
							|  |  |  | 	kfree(ls->ls_dirtbl); | 
					
						
							|  |  |  |  out_lkbfree: | 
					
						
							|  |  |  | 	kfree(ls->ls_lkbtbl); | 
					
						
							|  |  |  |  out_rsbfree: | 
					
						
							|  |  |  | 	kfree(ls->ls_rsbtbl); | 
					
						
							|  |  |  |  out_lsfree: | 
					
						
							| 
									
										
										
										
											2007-05-18 09:02:20 -05:00
										 |  |  | 	if (do_unreg) | 
					
						
							| 
									
										
										
										
											2007-12-20 08:13:05 -08:00
										 |  |  | 		kobject_put(&ls->ls_kobj); | 
					
						
							| 
									
										
										
										
											2007-05-18 09:02:20 -05:00
										 |  |  | 	else | 
					
						
							|  |  |  | 		kfree(ls); | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  |  out: | 
					
						
							|  |  |  | 	module_put(THIS_MODULE); | 
					
						
							|  |  |  | 	return error; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int dlm_new_lockspace(char *name, int namelen, void **lockspace, | 
					
						
							|  |  |  | 		      uint32_t flags, int lvblen) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int error = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-20 08:47:07 +00:00
										 |  |  | 	mutex_lock(&ls_lock); | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 	if (!ls_count) | 
					
						
							|  |  |  | 		error = threads_start(); | 
					
						
							|  |  |  | 	if (error) | 
					
						
							|  |  |  | 		goto out; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	error = new_lockspace(name, namelen, lockspace, flags, lvblen); | 
					
						
							|  |  |  | 	if (!error) | 
					
						
							|  |  |  | 		ls_count++; | 
					
						
							| 
									
										
										
										
											2007-05-18 09:03:35 -05:00
										 |  |  | 	else if (!ls_count) | 
					
						
							|  |  |  | 		threads_stop(); | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  |  out: | 
					
						
							| 
									
										
										
										
											2006-01-20 08:47:07 +00:00
										 |  |  | 	mutex_unlock(&ls_lock); | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 	return error; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Return 1 if the lockspace still has active remote locks,
 | 
					
						
							|  |  |  |  *        2 if the lockspace still has active local locks. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static int lockspace_busy(struct dlm_ls *ls) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int i, lkb_found = 0; | 
					
						
							|  |  |  | 	struct dlm_lkb *lkb; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* NOTE: We check the lockidtbl here rather than the resource table.
 | 
					
						
							|  |  |  | 	   This is because there may be LKBs queued as ASTs that have been | 
					
						
							|  |  |  | 	   unlinked from their RSBs and are pending deletion once the AST has | 
					
						
							|  |  |  | 	   been delivered */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < ls->ls_lkbtbl_size; i++) { | 
					
						
							|  |  |  | 		read_lock(&ls->ls_lkbtbl[i].lock); | 
					
						
							|  |  |  | 		if (!list_empty(&ls->ls_lkbtbl[i].list)) { | 
					
						
							|  |  |  | 			lkb_found = 1; | 
					
						
							|  |  |  | 			list_for_each_entry(lkb, &ls->ls_lkbtbl[i].list, | 
					
						
							|  |  |  | 					    lkb_idtbl_list) { | 
					
						
							|  |  |  | 				if (!lkb->lkb_nodeid) { | 
					
						
							|  |  |  | 					read_unlock(&ls->ls_lkbtbl[i].lock); | 
					
						
							|  |  |  | 					return 2; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		read_unlock(&ls->ls_lkbtbl[i].lock); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return lkb_found; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int release_lockspace(struct dlm_ls *ls, int force) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct dlm_lkb *lkb; | 
					
						
							|  |  |  | 	struct dlm_rsb *rsb; | 
					
						
							|  |  |  | 	struct list_head *head; | 
					
						
							| 
									
										
										
										
											2008-08-06 13:30:24 -05:00
										 |  |  | 	int i, busy, rv; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	busy = lockspace_busy(ls); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spin_lock(&lslist_lock); | 
					
						
							|  |  |  | 	if (ls->ls_create_count == 1) { | 
					
						
							|  |  |  | 		if (busy > force) | 
					
						
							|  |  |  | 			rv = -EBUSY; | 
					
						
							|  |  |  | 		else { | 
					
						
							|  |  |  | 			/* remove_lockspace takes ls off lslist */ | 
					
						
							|  |  |  | 			ls->ls_create_count = 0; | 
					
						
							|  |  |  | 			rv = 0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} else if (ls->ls_create_count > 1) { | 
					
						
							|  |  |  | 		rv = --ls->ls_create_count; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		rv = -EINVAL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	spin_unlock(&lslist_lock); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (rv) { | 
					
						
							|  |  |  | 		log_debug(ls, "release_lockspace no remove %d", rv); | 
					
						
							|  |  |  | 		return rv; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-06 13:30:24 -05:00
										 |  |  | 	dlm_device_deregister(ls); | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-18 11:43:30 -05:00
										 |  |  | 	if (force < 3 && dlm_user_daemon_available()) | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 		do_uevent(ls, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	dlm_recoverd_stop(ls); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	remove_lockspace(ls); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	dlm_delete_debug_file(ls); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	dlm_astd_suspend(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	kfree(ls->ls_recover_buf); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Free direntry structs. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	dlm_dir_clear(ls); | 
					
						
							|  |  |  | 	kfree(ls->ls_dirtbl); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Free all lkb's on lkbtbl[] lists. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < ls->ls_lkbtbl_size; i++) { | 
					
						
							|  |  |  | 		head = &ls->ls_lkbtbl[i].list; | 
					
						
							|  |  |  | 		while (!list_empty(head)) { | 
					
						
							|  |  |  | 			lkb = list_entry(head->next, struct dlm_lkb, | 
					
						
							|  |  |  | 					 lkb_idtbl_list); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			list_del(&lkb->lkb_idtbl_list); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			dlm_del_ast(lkb); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (lkb->lkb_lvbptr && lkb->lkb_flags & DLM_IFL_MSTCPY) | 
					
						
							| 
									
										
										
										
											2007-11-07 09:06:49 -06:00
										 |  |  | 				dlm_free_lvb(lkb->lkb_lvbptr); | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-07 09:06:49 -06:00
										 |  |  | 			dlm_free_lkb(lkb); | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	dlm_astd_resume(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	kfree(ls->ls_lkbtbl); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Free all rsb's on rsbtbl[] lists | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < ls->ls_rsbtbl_size; i++) { | 
					
						
							|  |  |  | 		head = &ls->ls_rsbtbl[i].list; | 
					
						
							|  |  |  | 		while (!list_empty(head)) { | 
					
						
							|  |  |  | 			rsb = list_entry(head->next, struct dlm_rsb, | 
					
						
							|  |  |  | 					 res_hashchain); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			list_del(&rsb->res_hashchain); | 
					
						
							| 
									
										
										
										
											2007-11-07 09:06:49 -06:00
										 |  |  | 			dlm_free_rsb(rsb); | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		head = &ls->ls_rsbtbl[i].toss; | 
					
						
							|  |  |  | 		while (!list_empty(head)) { | 
					
						
							|  |  |  | 			rsb = list_entry(head->next, struct dlm_rsb, | 
					
						
							|  |  |  | 					 res_hashchain); | 
					
						
							|  |  |  | 			list_del(&rsb->res_hashchain); | 
					
						
							| 
									
										
										
										
											2007-11-07 09:06:49 -06:00
										 |  |  | 			dlm_free_rsb(rsb); | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	kfree(ls->ls_rsbtbl); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Free structures on any other lists | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-11-27 11:31:22 -06:00
										 |  |  | 	dlm_purge_requestqueue(ls); | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 	kfree(ls->ls_recover_args); | 
					
						
							|  |  |  | 	dlm_clear_free_entries(ls); | 
					
						
							|  |  |  | 	dlm_clear_members(ls); | 
					
						
							|  |  |  | 	dlm_clear_members_gone(ls); | 
					
						
							|  |  |  | 	kfree(ls->ls_node_array); | 
					
						
							| 
									
										
										
										
											2008-08-06 13:30:24 -05:00
										 |  |  | 	log_debug(ls, "release_lockspace final free"); | 
					
						
							| 
									
										
										
										
											2007-12-20 08:13:05 -08:00
										 |  |  | 	kobject_put(&ls->ls_kobj); | 
					
						
							| 
									
										
										
										
											2007-05-18 09:02:20 -05:00
										 |  |  | 	/* The ls structure will be freed when the kobject is done with */ | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	module_put(THIS_MODULE); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * Called when a system has released all its locks and is not going to use the | 
					
						
							|  |  |  |  * lockspace any longer.  We free everything we're managing for this lockspace. | 
					
						
							|  |  |  |  * Remaining nodes will go through the recovery process as if we'd died.  The | 
					
						
							|  |  |  |  * lockspace must continue to function as usual, participating in recoveries, | 
					
						
							|  |  |  |  * until this returns. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Force has 4 possible values: | 
					
						
							|  |  |  |  * 0 - don't destroy locksapce if it has any LKBs | 
					
						
							|  |  |  |  * 1 - destroy lockspace if it has remote LKBs but not if it has local LKBs | 
					
						
							|  |  |  |  * 2 - destroy lockspace regardless of LKBs | 
					
						
							|  |  |  |  * 3 - destroy lockspace as part of a forced shutdown | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int dlm_release_lockspace(void *lockspace, int force) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct dlm_ls *ls; | 
					
						
							| 
									
										
										
										
											2008-08-06 13:30:24 -05:00
										 |  |  | 	int error; | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	ls = dlm_find_lockspace_local(lockspace); | 
					
						
							|  |  |  | 	if (!ls) | 
					
						
							|  |  |  | 		return -EINVAL; | 
					
						
							|  |  |  | 	dlm_put_lockspace(ls); | 
					
						
							| 
									
										
										
										
											2008-08-06 13:30:24 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	mutex_lock(&ls_lock); | 
					
						
							|  |  |  | 	error = release_lockspace(ls, force); | 
					
						
							|  |  |  | 	if (!error) | 
					
						
							|  |  |  | 		ls_count--; | 
					
						
							| 
									
										
										
										
											2008-11-13 13:22:34 -06:00
										 |  |  | 	if (!ls_count) | 
					
						
							| 
									
										
										
										
											2008-08-06 13:30:24 -05:00
										 |  |  | 		threads_stop(); | 
					
						
							|  |  |  | 	mutex_unlock(&ls_lock); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return error; | 
					
						
							| 
									
										
										
										
											2006-01-18 09:30:29 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-18 11:43:30 -05:00
										 |  |  | void dlm_stop_lockspaces(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct dlm_ls *ls; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  restart: | 
					
						
							|  |  |  | 	spin_lock(&lslist_lock); | 
					
						
							|  |  |  | 	list_for_each_entry(ls, &lslist, ls_list) { | 
					
						
							|  |  |  | 		if (!test_bit(LSFL_RUNNING, &ls->ls_flags)) | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		spin_unlock(&lslist_lock); | 
					
						
							|  |  |  | 		log_error(ls, "no userland control daemon, stopping lockspace"); | 
					
						
							|  |  |  | 		dlm_ls_stop(ls); | 
					
						
							|  |  |  | 		goto restart; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	spin_unlock(&lslist_lock); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 |