lockspace.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  1. /******************************************************************************
  2. *******************************************************************************
  3. **
  4. ** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
  5. ** Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
  6. **
  7. ** This copyrighted material is made available to anyone wishing to use,
  8. ** modify, copy, or redistribute it subject to the terms and conditions
  9. ** of the GNU General Public License v.2.
  10. **
  11. *******************************************************************************
  12. ******************************************************************************/
  13. #include "dlm_internal.h"
  14. #include "lockspace.h"
  15. #include "member.h"
  16. #include "recoverd.h"
  17. #include "ast.h"
  18. #include "dir.h"
  19. #include "lowcomms.h"
  20. #include "config.h"
  21. #include "memory.h"
  22. #include "lock.h"
  23. #include "recover.h"
  24. #include "requestqueue.h"
  25. #ifdef CONFIG_DLM_DEBUG
  26. int dlm_create_debug_file(struct dlm_ls *ls);
  27. void dlm_delete_debug_file(struct dlm_ls *ls);
  28. #else
  29. static inline int dlm_create_debug_file(struct dlm_ls *ls) { return 0; }
  30. static inline void dlm_delete_debug_file(struct dlm_ls *ls) { }
  31. #endif
  32. static int ls_count;
  33. static struct mutex ls_lock;
  34. static struct list_head lslist;
  35. static spinlock_t lslist_lock;
  36. static struct task_struct * scand_task;
  37. static ssize_t dlm_control_store(struct dlm_ls *ls, const char *buf, size_t len)
  38. {
  39. ssize_t ret = len;
  40. int n = simple_strtol(buf, NULL, 0);
  41. ls = dlm_find_lockspace_local(ls->ls_local_handle);
  42. if (!ls)
  43. return -EINVAL;
  44. switch (n) {
  45. case 0:
  46. dlm_ls_stop(ls);
  47. break;
  48. case 1:
  49. dlm_ls_start(ls);
  50. break;
  51. default:
  52. ret = -EINVAL;
  53. }
  54. dlm_put_lockspace(ls);
  55. return ret;
  56. }
  57. static ssize_t dlm_event_store(struct dlm_ls *ls, const char *buf, size_t len)
  58. {
  59. ls->ls_uevent_result = simple_strtol(buf, NULL, 0);
  60. set_bit(LSFL_UEVENT_WAIT, &ls->ls_flags);
  61. wake_up(&ls->ls_uevent_wait);
  62. return len;
  63. }
  64. static ssize_t dlm_id_show(struct dlm_ls *ls, char *buf)
  65. {
  66. return snprintf(buf, PAGE_SIZE, "%u\n", ls->ls_global_id);
  67. }
  68. static ssize_t dlm_id_store(struct dlm_ls *ls, const char *buf, size_t len)
  69. {
  70. ls->ls_global_id = simple_strtoul(buf, NULL, 0);
  71. return len;
  72. }
  73. static ssize_t dlm_recover_status_show(struct dlm_ls *ls, char *buf)
  74. {
  75. uint32_t status = dlm_recover_status(ls);
  76. return snprintf(buf, PAGE_SIZE, "%x\n", status);
  77. }
  78. static ssize_t dlm_recover_nodeid_show(struct dlm_ls *ls, char *buf)
  79. {
  80. return snprintf(buf, PAGE_SIZE, "%d\n", ls->ls_recover_nodeid);
  81. }
  82. struct dlm_attr {
  83. struct attribute attr;
  84. ssize_t (*show)(struct dlm_ls *, char *);
  85. ssize_t (*store)(struct dlm_ls *, const char *, size_t);
  86. };
  87. static struct dlm_attr dlm_attr_control = {
  88. .attr = {.name = "control", .mode = S_IWUSR},
  89. .store = dlm_control_store
  90. };
  91. static struct dlm_attr dlm_attr_event = {
  92. .attr = {.name = "event_done", .mode = S_IWUSR},
  93. .store = dlm_event_store
  94. };
  95. static struct dlm_attr dlm_attr_id = {
  96. .attr = {.name = "id", .mode = S_IRUGO | S_IWUSR},
  97. .show = dlm_id_show,
  98. .store = dlm_id_store
  99. };
  100. static struct dlm_attr dlm_attr_recover_status = {
  101. .attr = {.name = "recover_status", .mode = S_IRUGO},
  102. .show = dlm_recover_status_show
  103. };
  104. static struct dlm_attr dlm_attr_recover_nodeid = {
  105. .attr = {.name = "recover_nodeid", .mode = S_IRUGO},
  106. .show = dlm_recover_nodeid_show
  107. };
  108. static struct attribute *dlm_attrs[] = {
  109. &dlm_attr_control.attr,
  110. &dlm_attr_event.attr,
  111. &dlm_attr_id.attr,
  112. &dlm_attr_recover_status.attr,
  113. &dlm_attr_recover_nodeid.attr,
  114. NULL,
  115. };
  116. static ssize_t dlm_attr_show(struct kobject *kobj, struct attribute *attr,
  117. char *buf)
  118. {
  119. struct dlm_ls *ls = container_of(kobj, struct dlm_ls, ls_kobj);
  120. struct dlm_attr *a = container_of(attr, struct dlm_attr, attr);
  121. return a->show ? a->show(ls, buf) : 0;
  122. }
  123. static ssize_t dlm_attr_store(struct kobject *kobj, struct attribute *attr,
  124. const char *buf, size_t len)
  125. {
  126. struct dlm_ls *ls = container_of(kobj, struct dlm_ls, ls_kobj);
  127. struct dlm_attr *a = container_of(attr, struct dlm_attr, attr);
  128. return a->store ? a->store(ls, buf, len) : len;
  129. }
  130. static void lockspace_kobj_release(struct kobject *k)
  131. {
  132. struct dlm_ls *ls = container_of(k, struct dlm_ls, ls_kobj);
  133. kfree(ls);
  134. }
  135. static struct sysfs_ops dlm_attr_ops = {
  136. .show = dlm_attr_show,
  137. .store = dlm_attr_store,
  138. };
  139. static struct kobj_type dlm_ktype = {
  140. .default_attrs = dlm_attrs,
  141. .sysfs_ops = &dlm_attr_ops,
  142. .release = lockspace_kobj_release,
  143. };
  144. static struct kset dlm_kset = {
  145. .ktype = &dlm_ktype,
  146. };
  147. static int kobject_setup(struct dlm_ls *ls)
  148. {
  149. char lsname[DLM_LOCKSPACE_LEN];
  150. int error;
  151. memset(lsname, 0, DLM_LOCKSPACE_LEN);
  152. snprintf(lsname, DLM_LOCKSPACE_LEN, "%s", ls->ls_name);
  153. error = kobject_set_name(&ls->ls_kobj, "%s", lsname);
  154. if (error)
  155. return error;
  156. ls->ls_kobj.kset = &dlm_kset;
  157. ls->ls_kobj.ktype = &dlm_ktype;
  158. return 0;
  159. }
  160. static int do_uevent(struct dlm_ls *ls, int in)
  161. {
  162. int error;
  163. if (in)
  164. kobject_uevent(&ls->ls_kobj, KOBJ_ONLINE);
  165. else
  166. kobject_uevent(&ls->ls_kobj, KOBJ_OFFLINE);
  167. log_debug(ls, "%s the lockspace group...", in ? "joining" : "leaving");
  168. /* dlm_controld will see the uevent, do the necessary group management
  169. and then write to sysfs to wake us */
  170. error = wait_event_interruptible(ls->ls_uevent_wait,
  171. test_and_clear_bit(LSFL_UEVENT_WAIT, &ls->ls_flags));
  172. log_debug(ls, "group event done %d %d", error, ls->ls_uevent_result);
  173. if (error)
  174. goto out;
  175. error = ls->ls_uevent_result;
  176. out:
  177. if (error)
  178. log_error(ls, "group %s failed %d %d", in ? "join" : "leave",
  179. error, ls->ls_uevent_result);
  180. return error;
  181. }
  182. int dlm_lockspace_init(void)
  183. {
  184. int error;
  185. ls_count = 0;
  186. mutex_init(&ls_lock);
  187. INIT_LIST_HEAD(&lslist);
  188. spin_lock_init(&lslist_lock);
  189. kobject_set_name(&dlm_kset.kobj, "dlm");
  190. kobj_set_kset_s(&dlm_kset, kernel_subsys);
  191. error = kset_register(&dlm_kset);
  192. if (error)
  193. printk("dlm_lockspace_init: cannot register kset %d\n", error);
  194. return error;
  195. }
  196. void dlm_lockspace_exit(void)
  197. {
  198. kset_unregister(&dlm_kset);
  199. }
  200. static int dlm_scand(void *data)
  201. {
  202. struct dlm_ls *ls;
  203. while (!kthread_should_stop()) {
  204. list_for_each_entry(ls, &lslist, ls_list) {
  205. if (dlm_lock_recovery_try(ls)) {
  206. dlm_scan_rsbs(ls);
  207. dlm_scan_timeout(ls);
  208. dlm_unlock_recovery(ls);
  209. }
  210. }
  211. schedule_timeout_interruptible(dlm_config.ci_scan_secs * HZ);
  212. }
  213. return 0;
  214. }
  215. static int dlm_scand_start(void)
  216. {
  217. struct task_struct *p;
  218. int error = 0;
  219. p = kthread_run(dlm_scand, NULL, "dlm_scand");
  220. if (IS_ERR(p))
  221. error = PTR_ERR(p);
  222. else
  223. scand_task = p;
  224. return error;
  225. }
  226. static void dlm_scand_stop(void)
  227. {
  228. kthread_stop(scand_task);
  229. }
  230. static struct dlm_ls *dlm_find_lockspace_name(char *name, int namelen)
  231. {
  232. struct dlm_ls *ls;
  233. spin_lock(&lslist_lock);
  234. list_for_each_entry(ls, &lslist, ls_list) {
  235. if (ls->ls_namelen == namelen &&
  236. memcmp(ls->ls_name, name, namelen) == 0)
  237. goto out;
  238. }
  239. ls = NULL;
  240. out:
  241. spin_unlock(&lslist_lock);
  242. return ls;
  243. }
  244. struct dlm_ls *dlm_find_lockspace_global(uint32_t id)
  245. {
  246. struct dlm_ls *ls;
  247. spin_lock(&lslist_lock);
  248. list_for_each_entry(ls, &lslist, ls_list) {
  249. if (ls->ls_global_id == id) {
  250. ls->ls_count++;
  251. goto out;
  252. }
  253. }
  254. ls = NULL;
  255. out:
  256. spin_unlock(&lslist_lock);
  257. return ls;
  258. }
  259. struct dlm_ls *dlm_find_lockspace_local(dlm_lockspace_t *lockspace)
  260. {
  261. struct dlm_ls *ls;
  262. spin_lock(&lslist_lock);
  263. list_for_each_entry(ls, &lslist, ls_list) {
  264. if (ls->ls_local_handle == lockspace) {
  265. ls->ls_count++;
  266. goto out;
  267. }
  268. }
  269. ls = NULL;
  270. out:
  271. spin_unlock(&lslist_lock);
  272. return ls;
  273. }
  274. struct dlm_ls *dlm_find_lockspace_device(int minor)
  275. {
  276. struct dlm_ls *ls;
  277. spin_lock(&lslist_lock);
  278. list_for_each_entry(ls, &lslist, ls_list) {
  279. if (ls->ls_device.minor == minor) {
  280. ls->ls_count++;
  281. goto out;
  282. }
  283. }
  284. ls = NULL;
  285. out:
  286. spin_unlock(&lslist_lock);
  287. return ls;
  288. }
  289. void dlm_put_lockspace(struct dlm_ls *ls)
  290. {
  291. spin_lock(&lslist_lock);
  292. ls->ls_count--;
  293. spin_unlock(&lslist_lock);
  294. }
  295. static void remove_lockspace(struct dlm_ls *ls)
  296. {
  297. for (;;) {
  298. spin_lock(&lslist_lock);
  299. if (ls->ls_count == 0) {
  300. list_del(&ls->ls_list);
  301. spin_unlock(&lslist_lock);
  302. return;
  303. }
  304. spin_unlock(&lslist_lock);
  305. ssleep(1);
  306. }
  307. }
  308. static int threads_start(void)
  309. {
  310. int error;
  311. /* Thread which process lock requests for all lockspace's */
  312. error = dlm_astd_start();
  313. if (error) {
  314. log_print("cannot start dlm_astd thread %d", error);
  315. goto fail;
  316. }
  317. error = dlm_scand_start();
  318. if (error) {
  319. log_print("cannot start dlm_scand thread %d", error);
  320. goto astd_fail;
  321. }
  322. /* Thread for sending/receiving messages for all lockspace's */
  323. error = dlm_lowcomms_start();
  324. if (error) {
  325. log_print("cannot start dlm lowcomms %d", error);
  326. goto scand_fail;
  327. }
  328. return 0;
  329. scand_fail:
  330. dlm_scand_stop();
  331. astd_fail:
  332. dlm_astd_stop();
  333. fail:
  334. return error;
  335. }
  336. static void threads_stop(void)
  337. {
  338. dlm_scand_stop();
  339. dlm_lowcomms_stop();
  340. dlm_astd_stop();
  341. }
  342. static int new_lockspace(char *name, int namelen, void **lockspace,
  343. uint32_t flags, int lvblen)
  344. {
  345. struct dlm_ls *ls;
  346. int i, size, error = -ENOMEM;
  347. int do_unreg = 0;
  348. if (namelen > DLM_LOCKSPACE_LEN)
  349. return -EINVAL;
  350. if (!lvblen || (lvblen % 8))
  351. return -EINVAL;
  352. if (!try_module_get(THIS_MODULE))
  353. return -EINVAL;
  354. ls = dlm_find_lockspace_name(name, namelen);
  355. if (ls) {
  356. *lockspace = ls;
  357. module_put(THIS_MODULE);
  358. return -EEXIST;
  359. }
  360. ls = kzalloc(sizeof(struct dlm_ls) + namelen, GFP_KERNEL);
  361. if (!ls)
  362. goto out;
  363. memcpy(ls->ls_name, name, namelen);
  364. ls->ls_namelen = namelen;
  365. ls->ls_lvblen = lvblen;
  366. ls->ls_count = 0;
  367. ls->ls_flags = 0;
  368. if (flags & DLM_LSFL_TIMEWARN)
  369. set_bit(LSFL_TIMEWARN, &ls->ls_flags);
  370. if (flags & DLM_LSFL_FS)
  371. ls->ls_allocation = GFP_NOFS;
  372. else
  373. ls->ls_allocation = GFP_KERNEL;
  374. /* ls_exflags are forced to match among nodes, and we don't
  375. need to require all nodes to have TIMEWARN or FS set */
  376. ls->ls_exflags = (flags & ~(DLM_LSFL_TIMEWARN | DLM_LSFL_FS));
  377. size = dlm_config.ci_rsbtbl_size;
  378. ls->ls_rsbtbl_size = size;
  379. ls->ls_rsbtbl = kmalloc(sizeof(struct dlm_rsbtable) * size, GFP_KERNEL);
  380. if (!ls->ls_rsbtbl)
  381. goto out_lsfree;
  382. for (i = 0; i < size; i++) {
  383. INIT_LIST_HEAD(&ls->ls_rsbtbl[i].list);
  384. INIT_LIST_HEAD(&ls->ls_rsbtbl[i].toss);
  385. rwlock_init(&ls->ls_rsbtbl[i].lock);
  386. }
  387. size = dlm_config.ci_lkbtbl_size;
  388. ls->ls_lkbtbl_size = size;
  389. ls->ls_lkbtbl = kmalloc(sizeof(struct dlm_lkbtable) * size, GFP_KERNEL);
  390. if (!ls->ls_lkbtbl)
  391. goto out_rsbfree;
  392. for (i = 0; i < size; i++) {
  393. INIT_LIST_HEAD(&ls->ls_lkbtbl[i].list);
  394. rwlock_init(&ls->ls_lkbtbl[i].lock);
  395. ls->ls_lkbtbl[i].counter = 1;
  396. }
  397. size = dlm_config.ci_dirtbl_size;
  398. ls->ls_dirtbl_size = size;
  399. ls->ls_dirtbl = kmalloc(sizeof(struct dlm_dirtable) * size, GFP_KERNEL);
  400. if (!ls->ls_dirtbl)
  401. goto out_lkbfree;
  402. for (i = 0; i < size; i++) {
  403. INIT_LIST_HEAD(&ls->ls_dirtbl[i].list);
  404. rwlock_init(&ls->ls_dirtbl[i].lock);
  405. }
  406. INIT_LIST_HEAD(&ls->ls_waiters);
  407. mutex_init(&ls->ls_waiters_mutex);
  408. INIT_LIST_HEAD(&ls->ls_orphans);
  409. mutex_init(&ls->ls_orphans_mutex);
  410. INIT_LIST_HEAD(&ls->ls_timeout);
  411. mutex_init(&ls->ls_timeout_mutex);
  412. INIT_LIST_HEAD(&ls->ls_nodes);
  413. INIT_LIST_HEAD(&ls->ls_nodes_gone);
  414. ls->ls_num_nodes = 0;
  415. ls->ls_low_nodeid = 0;
  416. ls->ls_total_weight = 0;
  417. ls->ls_node_array = NULL;
  418. memset(&ls->ls_stub_rsb, 0, sizeof(struct dlm_rsb));
  419. ls->ls_stub_rsb.res_ls = ls;
  420. ls->ls_debug_rsb_dentry = NULL;
  421. ls->ls_debug_waiters_dentry = NULL;
  422. init_waitqueue_head(&ls->ls_uevent_wait);
  423. ls->ls_uevent_result = 0;
  424. init_completion(&ls->ls_members_done);
  425. ls->ls_members_result = -1;
  426. ls->ls_recoverd_task = NULL;
  427. mutex_init(&ls->ls_recoverd_active);
  428. spin_lock_init(&ls->ls_recover_lock);
  429. spin_lock_init(&ls->ls_rcom_spin);
  430. get_random_bytes(&ls->ls_rcom_seq, sizeof(uint64_t));
  431. ls->ls_recover_status = 0;
  432. ls->ls_recover_seq = 0;
  433. ls->ls_recover_args = NULL;
  434. init_rwsem(&ls->ls_in_recovery);
  435. init_rwsem(&ls->ls_recv_active);
  436. INIT_LIST_HEAD(&ls->ls_requestqueue);
  437. mutex_init(&ls->ls_requestqueue_mutex);
  438. mutex_init(&ls->ls_clear_proc_locks);
  439. ls->ls_recover_buf = kmalloc(dlm_config.ci_buffer_size, GFP_KERNEL);
  440. if (!ls->ls_recover_buf)
  441. goto out_dirfree;
  442. INIT_LIST_HEAD(&ls->ls_recover_list);
  443. spin_lock_init(&ls->ls_recover_list_lock);
  444. ls->ls_recover_list_count = 0;
  445. ls->ls_local_handle = ls;
  446. init_waitqueue_head(&ls->ls_wait_general);
  447. INIT_LIST_HEAD(&ls->ls_root_list);
  448. init_rwsem(&ls->ls_root_sem);
  449. down_write(&ls->ls_in_recovery);
  450. spin_lock(&lslist_lock);
  451. list_add(&ls->ls_list, &lslist);
  452. spin_unlock(&lslist_lock);
  453. /* needs to find ls in lslist */
  454. error = dlm_recoverd_start(ls);
  455. if (error) {
  456. log_error(ls, "can't start dlm_recoverd %d", error);
  457. goto out_delist;
  458. }
  459. error = kobject_setup(ls);
  460. if (error)
  461. goto out_stop;
  462. error = kobject_register(&ls->ls_kobj);
  463. if (error)
  464. goto out_stop;
  465. /* let kobject handle freeing of ls if there's an error */
  466. do_unreg = 1;
  467. /* This uevent triggers dlm_controld in userspace to add us to the
  468. group of nodes that are members of this lockspace (managed by the
  469. cluster infrastructure.) Once it's done that, it tells us who the
  470. current lockspace members are (via configfs) and then tells the
  471. lockspace to start running (via sysfs) in dlm_ls_start(). */
  472. error = do_uevent(ls, 1);
  473. if (error)
  474. goto out_stop;
  475. wait_for_completion(&ls->ls_members_done);
  476. error = ls->ls_members_result;
  477. if (error)
  478. goto out_members;
  479. dlm_create_debug_file(ls);
  480. log_debug(ls, "join complete");
  481. *lockspace = ls;
  482. return 0;
  483. out_members:
  484. do_uevent(ls, 0);
  485. dlm_clear_members(ls);
  486. kfree(ls->ls_node_array);
  487. out_stop:
  488. dlm_recoverd_stop(ls);
  489. out_delist:
  490. spin_lock(&lslist_lock);
  491. list_del(&ls->ls_list);
  492. spin_unlock(&lslist_lock);
  493. kfree(ls->ls_recover_buf);
  494. out_dirfree:
  495. kfree(ls->ls_dirtbl);
  496. out_lkbfree:
  497. kfree(ls->ls_lkbtbl);
  498. out_rsbfree:
  499. kfree(ls->ls_rsbtbl);
  500. out_lsfree:
  501. if (do_unreg)
  502. kobject_unregister(&ls->ls_kobj);
  503. else
  504. kfree(ls);
  505. out:
  506. module_put(THIS_MODULE);
  507. return error;
  508. }
  509. int dlm_new_lockspace(char *name, int namelen, void **lockspace,
  510. uint32_t flags, int lvblen)
  511. {
  512. int error = 0;
  513. mutex_lock(&ls_lock);
  514. if (!ls_count)
  515. error = threads_start();
  516. if (error)
  517. goto out;
  518. error = new_lockspace(name, namelen, lockspace, flags, lvblen);
  519. if (!error)
  520. ls_count++;
  521. else if (!ls_count)
  522. threads_stop();
  523. out:
  524. mutex_unlock(&ls_lock);
  525. return error;
  526. }
  527. /* Return 1 if the lockspace still has active remote locks,
  528. * 2 if the lockspace still has active local locks.
  529. */
  530. static int lockspace_busy(struct dlm_ls *ls)
  531. {
  532. int i, lkb_found = 0;
  533. struct dlm_lkb *lkb;
  534. /* NOTE: We check the lockidtbl here rather than the resource table.
  535. This is because there may be LKBs queued as ASTs that have been
  536. unlinked from their RSBs and are pending deletion once the AST has
  537. been delivered */
  538. for (i = 0; i < ls->ls_lkbtbl_size; i++) {
  539. read_lock(&ls->ls_lkbtbl[i].lock);
  540. if (!list_empty(&ls->ls_lkbtbl[i].list)) {
  541. lkb_found = 1;
  542. list_for_each_entry(lkb, &ls->ls_lkbtbl[i].list,
  543. lkb_idtbl_list) {
  544. if (!lkb->lkb_nodeid) {
  545. read_unlock(&ls->ls_lkbtbl[i].lock);
  546. return 2;
  547. }
  548. }
  549. }
  550. read_unlock(&ls->ls_lkbtbl[i].lock);
  551. }
  552. return lkb_found;
  553. }
  554. static int release_lockspace(struct dlm_ls *ls, int force)
  555. {
  556. struct dlm_lkb *lkb;
  557. struct dlm_rsb *rsb;
  558. struct list_head *head;
  559. int i;
  560. int busy = lockspace_busy(ls);
  561. if (busy > force)
  562. return -EBUSY;
  563. if (force < 3)
  564. do_uevent(ls, 0);
  565. dlm_recoverd_stop(ls);
  566. remove_lockspace(ls);
  567. dlm_delete_debug_file(ls);
  568. dlm_astd_suspend();
  569. kfree(ls->ls_recover_buf);
  570. /*
  571. * Free direntry structs.
  572. */
  573. dlm_dir_clear(ls);
  574. kfree(ls->ls_dirtbl);
  575. /*
  576. * Free all lkb's on lkbtbl[] lists.
  577. */
  578. for (i = 0; i < ls->ls_lkbtbl_size; i++) {
  579. head = &ls->ls_lkbtbl[i].list;
  580. while (!list_empty(head)) {
  581. lkb = list_entry(head->next, struct dlm_lkb,
  582. lkb_idtbl_list);
  583. list_del(&lkb->lkb_idtbl_list);
  584. dlm_del_ast(lkb);
  585. if (lkb->lkb_lvbptr && lkb->lkb_flags & DLM_IFL_MSTCPY)
  586. free_lvb(lkb->lkb_lvbptr);
  587. free_lkb(lkb);
  588. }
  589. }
  590. dlm_astd_resume();
  591. kfree(ls->ls_lkbtbl);
  592. /*
  593. * Free all rsb's on rsbtbl[] lists
  594. */
  595. for (i = 0; i < ls->ls_rsbtbl_size; i++) {
  596. head = &ls->ls_rsbtbl[i].list;
  597. while (!list_empty(head)) {
  598. rsb = list_entry(head->next, struct dlm_rsb,
  599. res_hashchain);
  600. list_del(&rsb->res_hashchain);
  601. free_rsb(rsb);
  602. }
  603. head = &ls->ls_rsbtbl[i].toss;
  604. while (!list_empty(head)) {
  605. rsb = list_entry(head->next, struct dlm_rsb,
  606. res_hashchain);
  607. list_del(&rsb->res_hashchain);
  608. free_rsb(rsb);
  609. }
  610. }
  611. kfree(ls->ls_rsbtbl);
  612. /*
  613. * Free structures on any other lists
  614. */
  615. dlm_purge_requestqueue(ls);
  616. kfree(ls->ls_recover_args);
  617. dlm_clear_free_entries(ls);
  618. dlm_clear_members(ls);
  619. dlm_clear_members_gone(ls);
  620. kfree(ls->ls_node_array);
  621. kobject_unregister(&ls->ls_kobj);
  622. /* The ls structure will be freed when the kobject is done with */
  623. mutex_lock(&ls_lock);
  624. ls_count--;
  625. if (!ls_count)
  626. threads_stop();
  627. mutex_unlock(&ls_lock);
  628. module_put(THIS_MODULE);
  629. return 0;
  630. }
  631. /*
  632. * Called when a system has released all its locks and is not going to use the
  633. * lockspace any longer. We free everything we're managing for this lockspace.
  634. * Remaining nodes will go through the recovery process as if we'd died. The
  635. * lockspace must continue to function as usual, participating in recoveries,
  636. * until this returns.
  637. *
  638. * Force has 4 possible values:
  639. * 0 - don't destroy locksapce if it has any LKBs
  640. * 1 - destroy lockspace if it has remote LKBs but not if it has local LKBs
  641. * 2 - destroy lockspace regardless of LKBs
  642. * 3 - destroy lockspace as part of a forced shutdown
  643. */
  644. int dlm_release_lockspace(void *lockspace, int force)
  645. {
  646. struct dlm_ls *ls;
  647. ls = dlm_find_lockspace_local(lockspace);
  648. if (!ls)
  649. return -EINVAL;
  650. dlm_put_lockspace(ls);
  651. return release_lockspace(ls, force);
  652. }