PageRenderTime 37ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/fs/dlm/recover.c

https://github.com/mstsirkin/linux
C | 789 lines | 525 code | 135 blank | 129 comment | 86 complexity | 5ee27a71cbf48e30b06d3cc0cb60fb4b MD5 | raw file
  1. /******************************************************************************
  2. *******************************************************************************
  3. **
  4. ** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
  5. ** Copyright (C) 2004-2005 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 "dir.h"
  16. #include "config.h"
  17. #include "ast.h"
  18. #include "memory.h"
  19. #include "rcom.h"
  20. #include "lock.h"
  21. #include "lowcomms.h"
  22. #include "member.h"
  23. #include "recover.h"
  24. /*
  25. * Recovery waiting routines: these functions wait for a particular reply from
  26. * a remote node, or for the remote node to report a certain status. They need
  27. * to abort if the lockspace is stopped indicating a node has failed (perhaps
  28. * the one being waited for).
  29. */
  30. /*
  31. * Wait until given function returns non-zero or lockspace is stopped
  32. * (LS_RECOVERY_STOP set due to failure of a node in ls_nodes). When another
  33. * function thinks it could have completed the waited-on task, they should wake
  34. * up ls_wait_general to get an immediate response rather than waiting for the
  35. * timer to detect the result. A timer wakes us up periodically while waiting
  36. * to see if we should abort due to a node failure. This should only be called
  37. * by the dlm_recoverd thread.
  38. */
  39. static void dlm_wait_timer_fn(unsigned long data)
  40. {
  41. struct dlm_ls *ls = (struct dlm_ls *) data;
  42. mod_timer(&ls->ls_timer, jiffies + (dlm_config.ci_recover_timer * HZ));
  43. wake_up(&ls->ls_wait_general);
  44. }
  45. int dlm_wait_function(struct dlm_ls *ls, int (*testfn) (struct dlm_ls *ls))
  46. {
  47. int error = 0;
  48. init_timer(&ls->ls_timer);
  49. ls->ls_timer.function = dlm_wait_timer_fn;
  50. ls->ls_timer.data = (long) ls;
  51. ls->ls_timer.expires = jiffies + (dlm_config.ci_recover_timer * HZ);
  52. add_timer(&ls->ls_timer);
  53. wait_event(ls->ls_wait_general, testfn(ls) || dlm_recovery_stopped(ls));
  54. del_timer_sync(&ls->ls_timer);
  55. if (dlm_recovery_stopped(ls)) {
  56. log_debug(ls, "dlm_wait_function aborted");
  57. error = -EINTR;
  58. }
  59. return error;
  60. }
  61. /*
  62. * An efficient way for all nodes to wait for all others to have a certain
  63. * status. The node with the lowest nodeid polls all the others for their
  64. * status (wait_status_all) and all the others poll the node with the low id
  65. * for its accumulated result (wait_status_low). When all nodes have set
  66. * status flag X, then status flag X_ALL will be set on the low nodeid.
  67. */
  68. uint32_t dlm_recover_status(struct dlm_ls *ls)
  69. {
  70. uint32_t status;
  71. spin_lock(&ls->ls_recover_lock);
  72. status = ls->ls_recover_status;
  73. spin_unlock(&ls->ls_recover_lock);
  74. return status;
  75. }
  76. void dlm_set_recover_status(struct dlm_ls *ls, uint32_t status)
  77. {
  78. spin_lock(&ls->ls_recover_lock);
  79. ls->ls_recover_status |= status;
  80. spin_unlock(&ls->ls_recover_lock);
  81. }
  82. static int wait_status_all(struct dlm_ls *ls, uint32_t wait_status)
  83. {
  84. struct dlm_rcom *rc = ls->ls_recover_buf;
  85. struct dlm_member *memb;
  86. int error = 0, delay;
  87. list_for_each_entry(memb, &ls->ls_nodes, list) {
  88. delay = 0;
  89. for (;;) {
  90. if (dlm_recovery_stopped(ls)) {
  91. error = -EINTR;
  92. goto out;
  93. }
  94. error = dlm_rcom_status(ls, memb->nodeid);
  95. if (error)
  96. goto out;
  97. if (rc->rc_result & wait_status)
  98. break;
  99. if (delay < 1000)
  100. delay += 20;
  101. msleep(delay);
  102. }
  103. }
  104. out:
  105. return error;
  106. }
  107. static int wait_status_low(struct dlm_ls *ls, uint32_t wait_status)
  108. {
  109. struct dlm_rcom *rc = ls->ls_recover_buf;
  110. int error = 0, delay = 0, nodeid = ls->ls_low_nodeid;
  111. for (;;) {
  112. if (dlm_recovery_stopped(ls)) {
  113. error = -EINTR;
  114. goto out;
  115. }
  116. error = dlm_rcom_status(ls, nodeid);
  117. if (error)
  118. break;
  119. if (rc->rc_result & wait_status)
  120. break;
  121. if (delay < 1000)
  122. delay += 20;
  123. msleep(delay);
  124. }
  125. out:
  126. return error;
  127. }
  128. static int wait_status(struct dlm_ls *ls, uint32_t status)
  129. {
  130. uint32_t status_all = status << 1;
  131. int error;
  132. if (ls->ls_low_nodeid == dlm_our_nodeid()) {
  133. error = wait_status_all(ls, status);
  134. if (!error)
  135. dlm_set_recover_status(ls, status_all);
  136. } else
  137. error = wait_status_low(ls, status_all);
  138. return error;
  139. }
  140. int dlm_recover_members_wait(struct dlm_ls *ls)
  141. {
  142. return wait_status(ls, DLM_RS_NODES);
  143. }
  144. int dlm_recover_directory_wait(struct dlm_ls *ls)
  145. {
  146. return wait_status(ls, DLM_RS_DIR);
  147. }
  148. int dlm_recover_locks_wait(struct dlm_ls *ls)
  149. {
  150. return wait_status(ls, DLM_RS_LOCKS);
  151. }
  152. int dlm_recover_done_wait(struct dlm_ls *ls)
  153. {
  154. return wait_status(ls, DLM_RS_DONE);
  155. }
  156. /*
  157. * The recover_list contains all the rsb's for which we've requested the new
  158. * master nodeid. As replies are returned from the resource directories the
  159. * rsb's are removed from the list. When the list is empty we're done.
  160. *
  161. * The recover_list is later similarly used for all rsb's for which we've sent
  162. * new lkb's and need to receive new corresponding lkid's.
  163. *
  164. * We use the address of the rsb struct as a simple local identifier for the
  165. * rsb so we can match an rcom reply with the rsb it was sent for.
  166. */
  167. static int recover_list_empty(struct dlm_ls *ls)
  168. {
  169. int empty;
  170. spin_lock(&ls->ls_recover_list_lock);
  171. empty = list_empty(&ls->ls_recover_list);
  172. spin_unlock(&ls->ls_recover_list_lock);
  173. return empty;
  174. }
  175. static void recover_list_add(struct dlm_rsb *r)
  176. {
  177. struct dlm_ls *ls = r->res_ls;
  178. spin_lock(&ls->ls_recover_list_lock);
  179. if (list_empty(&r->res_recover_list)) {
  180. list_add_tail(&r->res_recover_list, &ls->ls_recover_list);
  181. ls->ls_recover_list_count++;
  182. dlm_hold_rsb(r);
  183. }
  184. spin_unlock(&ls->ls_recover_list_lock);
  185. }
  186. static void recover_list_del(struct dlm_rsb *r)
  187. {
  188. struct dlm_ls *ls = r->res_ls;
  189. spin_lock(&ls->ls_recover_list_lock);
  190. list_del_init(&r->res_recover_list);
  191. ls->ls_recover_list_count--;
  192. spin_unlock(&ls->ls_recover_list_lock);
  193. dlm_put_rsb(r);
  194. }
  195. static struct dlm_rsb *recover_list_find(struct dlm_ls *ls, uint64_t id)
  196. {
  197. struct dlm_rsb *r = NULL;
  198. spin_lock(&ls->ls_recover_list_lock);
  199. list_for_each_entry(r, &ls->ls_recover_list, res_recover_list) {
  200. if (id == (unsigned long) r)
  201. goto out;
  202. }
  203. r = NULL;
  204. out:
  205. spin_unlock(&ls->ls_recover_list_lock);
  206. return r;
  207. }
  208. static void recover_list_clear(struct dlm_ls *ls)
  209. {
  210. struct dlm_rsb *r, *s;
  211. spin_lock(&ls->ls_recover_list_lock);
  212. list_for_each_entry_safe(r, s, &ls->ls_recover_list, res_recover_list) {
  213. list_del_init(&r->res_recover_list);
  214. r->res_recover_locks_count = 0;
  215. dlm_put_rsb(r);
  216. ls->ls_recover_list_count--;
  217. }
  218. if (ls->ls_recover_list_count != 0) {
  219. log_error(ls, "warning: recover_list_count %d",
  220. ls->ls_recover_list_count);
  221. ls->ls_recover_list_count = 0;
  222. }
  223. spin_unlock(&ls->ls_recover_list_lock);
  224. }
  225. /* Master recovery: find new master node for rsb's that were
  226. mastered on nodes that have been removed.
  227. dlm_recover_masters
  228. recover_master
  229. dlm_send_rcom_lookup -> receive_rcom_lookup
  230. dlm_dir_lookup
  231. receive_rcom_lookup_reply <-
  232. dlm_recover_master_reply
  233. set_new_master
  234. set_master_lkbs
  235. set_lock_master
  236. */
  237. /*
  238. * Set the lock master for all LKBs in a lock queue
  239. * If we are the new master of the rsb, we may have received new
  240. * MSTCPY locks from other nodes already which we need to ignore
  241. * when setting the new nodeid.
  242. */
  243. static void set_lock_master(struct list_head *queue, int nodeid)
  244. {
  245. struct dlm_lkb *lkb;
  246. list_for_each_entry(lkb, queue, lkb_statequeue)
  247. if (!(lkb->lkb_flags & DLM_IFL_MSTCPY))
  248. lkb->lkb_nodeid = nodeid;
  249. }
  250. static void set_master_lkbs(struct dlm_rsb *r)
  251. {
  252. set_lock_master(&r->res_grantqueue, r->res_nodeid);
  253. set_lock_master(&r->res_convertqueue, r->res_nodeid);
  254. set_lock_master(&r->res_waitqueue, r->res_nodeid);
  255. }
  256. /*
  257. * Propagate the new master nodeid to locks
  258. * The NEW_MASTER flag tells dlm_recover_locks() which rsb's to consider.
  259. * The NEW_MASTER2 flag tells recover_lvb() and set_locks_purged() which
  260. * rsb's to consider.
  261. */
  262. static void set_new_master(struct dlm_rsb *r, int nodeid)
  263. {
  264. lock_rsb(r);
  265. r->res_nodeid = nodeid;
  266. set_master_lkbs(r);
  267. rsb_set_flag(r, RSB_NEW_MASTER);
  268. rsb_set_flag(r, RSB_NEW_MASTER2);
  269. unlock_rsb(r);
  270. }
  271. /*
  272. * We do async lookups on rsb's that need new masters. The rsb's
  273. * waiting for a lookup reply are kept on the recover_list.
  274. */
  275. static int recover_master(struct dlm_rsb *r)
  276. {
  277. struct dlm_ls *ls = r->res_ls;
  278. int error, dir_nodeid, ret_nodeid, our_nodeid = dlm_our_nodeid();
  279. dir_nodeid = dlm_dir_nodeid(r);
  280. if (dir_nodeid == our_nodeid) {
  281. error = dlm_dir_lookup(ls, our_nodeid, r->res_name,
  282. r->res_length, &ret_nodeid);
  283. if (error)
  284. log_error(ls, "recover dir lookup error %d", error);
  285. if (ret_nodeid == our_nodeid)
  286. ret_nodeid = 0;
  287. set_new_master(r, ret_nodeid);
  288. } else {
  289. recover_list_add(r);
  290. error = dlm_send_rcom_lookup(r, dir_nodeid);
  291. }
  292. return error;
  293. }
  294. /*
  295. * When not using a directory, most resource names will hash to a new static
  296. * master nodeid and the resource will need to be remastered.
  297. */
  298. static int recover_master_static(struct dlm_rsb *r)
  299. {
  300. int master = dlm_dir_nodeid(r);
  301. if (master == dlm_our_nodeid())
  302. master = 0;
  303. if (r->res_nodeid != master) {
  304. if (is_master(r))
  305. dlm_purge_mstcpy_locks(r);
  306. set_new_master(r, master);
  307. return 1;
  308. }
  309. return 0;
  310. }
  311. /*
  312. * Go through local root resources and for each rsb which has a master which
  313. * has departed, get the new master nodeid from the directory. The dir will
  314. * assign mastery to the first node to look up the new master. That means
  315. * we'll discover in this lookup if we're the new master of any rsb's.
  316. *
  317. * We fire off all the dir lookup requests individually and asynchronously to
  318. * the correct dir node.
  319. */
  320. int dlm_recover_masters(struct dlm_ls *ls)
  321. {
  322. struct dlm_rsb *r;
  323. int error = 0, count = 0;
  324. log_debug(ls, "dlm_recover_masters");
  325. down_read(&ls->ls_root_sem);
  326. list_for_each_entry(r, &ls->ls_root_list, res_root_list) {
  327. if (dlm_recovery_stopped(ls)) {
  328. up_read(&ls->ls_root_sem);
  329. error = -EINTR;
  330. goto out;
  331. }
  332. if (dlm_no_directory(ls))
  333. count += recover_master_static(r);
  334. else if (!is_master(r) &&
  335. (dlm_is_removed(ls, r->res_nodeid) ||
  336. rsb_flag(r, RSB_NEW_MASTER))) {
  337. recover_master(r);
  338. count++;
  339. }
  340. schedule();
  341. }
  342. up_read(&ls->ls_root_sem);
  343. log_debug(ls, "dlm_recover_masters %d resources", count);
  344. error = dlm_wait_function(ls, &recover_list_empty);
  345. out:
  346. if (error)
  347. recover_list_clear(ls);
  348. return error;
  349. }
  350. int dlm_recover_master_reply(struct dlm_ls *ls, struct dlm_rcom *rc)
  351. {
  352. struct dlm_rsb *r;
  353. int nodeid;
  354. r = recover_list_find(ls, rc->rc_id);
  355. if (!r) {
  356. log_error(ls, "dlm_recover_master_reply no id %llx",
  357. (unsigned long long)rc->rc_id);
  358. goto out;
  359. }
  360. nodeid = rc->rc_result;
  361. if (nodeid == dlm_our_nodeid())
  362. nodeid = 0;
  363. set_new_master(r, nodeid);
  364. recover_list_del(r);
  365. if (recover_list_empty(ls))
  366. wake_up(&ls->ls_wait_general);
  367. out:
  368. return 0;
  369. }
  370. /* Lock recovery: rebuild the process-copy locks we hold on a
  371. remastered rsb on the new rsb master.
  372. dlm_recover_locks
  373. recover_locks
  374. recover_locks_queue
  375. dlm_send_rcom_lock -> receive_rcom_lock
  376. dlm_recover_master_copy
  377. receive_rcom_lock_reply <-
  378. dlm_recover_process_copy
  379. */
  380. /*
  381. * keep a count of the number of lkb's we send to the new master; when we get
  382. * an equal number of replies then recovery for the rsb is done
  383. */
  384. static int recover_locks_queue(struct dlm_rsb *r, struct list_head *head)
  385. {
  386. struct dlm_lkb *lkb;
  387. int error = 0;
  388. list_for_each_entry(lkb, head, lkb_statequeue) {
  389. error = dlm_send_rcom_lock(r, lkb);
  390. if (error)
  391. break;
  392. r->res_recover_locks_count++;
  393. }
  394. return error;
  395. }
  396. static int recover_locks(struct dlm_rsb *r)
  397. {
  398. int error = 0;
  399. lock_rsb(r);
  400. DLM_ASSERT(!r->res_recover_locks_count, dlm_dump_rsb(r););
  401. error = recover_locks_queue(r, &r->res_grantqueue);
  402. if (error)
  403. goto out;
  404. error = recover_locks_queue(r, &r->res_convertqueue);
  405. if (error)
  406. goto out;
  407. error = recover_locks_queue(r, &r->res_waitqueue);
  408. if (error)
  409. goto out;
  410. if (r->res_recover_locks_count)
  411. recover_list_add(r);
  412. else
  413. rsb_clear_flag(r, RSB_NEW_MASTER);
  414. out:
  415. unlock_rsb(r);
  416. return error;
  417. }
  418. int dlm_recover_locks(struct dlm_ls *ls)
  419. {
  420. struct dlm_rsb *r;
  421. int error, count = 0;
  422. log_debug(ls, "dlm_recover_locks");
  423. down_read(&ls->ls_root_sem);
  424. list_for_each_entry(r, &ls->ls_root_list, res_root_list) {
  425. if (is_master(r)) {
  426. rsb_clear_flag(r, RSB_NEW_MASTER);
  427. continue;
  428. }
  429. if (!rsb_flag(r, RSB_NEW_MASTER))
  430. continue;
  431. if (dlm_recovery_stopped(ls)) {
  432. error = -EINTR;
  433. up_read(&ls->ls_root_sem);
  434. goto out;
  435. }
  436. error = recover_locks(r);
  437. if (error) {
  438. up_read(&ls->ls_root_sem);
  439. goto out;
  440. }
  441. count += r->res_recover_locks_count;
  442. }
  443. up_read(&ls->ls_root_sem);
  444. log_debug(ls, "dlm_recover_locks %d locks", count);
  445. error = dlm_wait_function(ls, &recover_list_empty);
  446. out:
  447. if (error)
  448. recover_list_clear(ls);
  449. else
  450. dlm_set_recover_status(ls, DLM_RS_LOCKS);
  451. return error;
  452. }
  453. void dlm_recovered_lock(struct dlm_rsb *r)
  454. {
  455. DLM_ASSERT(rsb_flag(r, RSB_NEW_MASTER), dlm_dump_rsb(r););
  456. r->res_recover_locks_count--;
  457. if (!r->res_recover_locks_count) {
  458. rsb_clear_flag(r, RSB_NEW_MASTER);
  459. recover_list_del(r);
  460. }
  461. if (recover_list_empty(r->res_ls))
  462. wake_up(&r->res_ls->ls_wait_general);
  463. }
  464. /*
  465. * The lvb needs to be recovered on all master rsb's. This includes setting
  466. * the VALNOTVALID flag if necessary, and determining the correct lvb contents
  467. * based on the lvb's of the locks held on the rsb.
  468. *
  469. * RSB_VALNOTVALID is set if there are only NL/CR locks on the rsb. If it
  470. * was already set prior to recovery, it's not cleared, regardless of locks.
  471. *
  472. * The LVB contents are only considered for changing when this is a new master
  473. * of the rsb (NEW_MASTER2). Then, the rsb's lvb is taken from any lkb with
  474. * mode > CR. If no lkb's exist with mode above CR, the lvb contents are taken
  475. * from the lkb with the largest lvb sequence number.
  476. */
  477. static void recover_lvb(struct dlm_rsb *r)
  478. {
  479. struct dlm_lkb *lkb, *high_lkb = NULL;
  480. uint32_t high_seq = 0;
  481. int lock_lvb_exists = 0;
  482. int big_lock_exists = 0;
  483. int lvblen = r->res_ls->ls_lvblen;
  484. list_for_each_entry(lkb, &r->res_grantqueue, lkb_statequeue) {
  485. if (!(lkb->lkb_exflags & DLM_LKF_VALBLK))
  486. continue;
  487. lock_lvb_exists = 1;
  488. if (lkb->lkb_grmode > DLM_LOCK_CR) {
  489. big_lock_exists = 1;
  490. goto setflag;
  491. }
  492. if (((int)lkb->lkb_lvbseq - (int)high_seq) >= 0) {
  493. high_lkb = lkb;
  494. high_seq = lkb->lkb_lvbseq;
  495. }
  496. }
  497. list_for_each_entry(lkb, &r->res_convertqueue, lkb_statequeue) {
  498. if (!(lkb->lkb_exflags & DLM_LKF_VALBLK))
  499. continue;
  500. lock_lvb_exists = 1;
  501. if (lkb->lkb_grmode > DLM_LOCK_CR) {
  502. big_lock_exists = 1;
  503. goto setflag;
  504. }
  505. if (((int)lkb->lkb_lvbseq - (int)high_seq) >= 0) {
  506. high_lkb = lkb;
  507. high_seq = lkb->lkb_lvbseq;
  508. }
  509. }
  510. setflag:
  511. if (!lock_lvb_exists)
  512. goto out;
  513. if (!big_lock_exists)
  514. rsb_set_flag(r, RSB_VALNOTVALID);
  515. /* don't mess with the lvb unless we're the new master */
  516. if (!rsb_flag(r, RSB_NEW_MASTER2))
  517. goto out;
  518. if (!r->res_lvbptr) {
  519. r->res_lvbptr = dlm_allocate_lvb(r->res_ls);
  520. if (!r->res_lvbptr)
  521. goto out;
  522. }
  523. if (big_lock_exists) {
  524. r->res_lvbseq = lkb->lkb_lvbseq;
  525. memcpy(r->res_lvbptr, lkb->lkb_lvbptr, lvblen);
  526. } else if (high_lkb) {
  527. r->res_lvbseq = high_lkb->lkb_lvbseq;
  528. memcpy(r->res_lvbptr, high_lkb->lkb_lvbptr, lvblen);
  529. } else {
  530. r->res_lvbseq = 0;
  531. memset(r->res_lvbptr, 0, lvblen);
  532. }
  533. out:
  534. return;
  535. }
  536. /* All master rsb's flagged RECOVER_CONVERT need to be looked at. The locks
  537. converting PR->CW or CW->PR need to have their lkb_grmode set. */
  538. static void recover_conversion(struct dlm_rsb *r)
  539. {
  540. struct dlm_lkb *lkb;
  541. int grmode = -1;
  542. list_for_each_entry(lkb, &r->res_grantqueue, lkb_statequeue) {
  543. if (lkb->lkb_grmode == DLM_LOCK_PR ||
  544. lkb->lkb_grmode == DLM_LOCK_CW) {
  545. grmode = lkb->lkb_grmode;
  546. break;
  547. }
  548. }
  549. list_for_each_entry(lkb, &r->res_convertqueue, lkb_statequeue) {
  550. if (lkb->lkb_grmode != DLM_LOCK_IV)
  551. continue;
  552. if (grmode == -1)
  553. lkb->lkb_grmode = lkb->lkb_rqmode;
  554. else
  555. lkb->lkb_grmode = grmode;
  556. }
  557. }
  558. /* We've become the new master for this rsb and waiting/converting locks may
  559. need to be granted in dlm_grant_after_purge() due to locks that may have
  560. existed from a removed node. */
  561. static void set_locks_purged(struct dlm_rsb *r)
  562. {
  563. if (!list_empty(&r->res_waitqueue) || !list_empty(&r->res_convertqueue))
  564. rsb_set_flag(r, RSB_LOCKS_PURGED);
  565. }
  566. void dlm_recover_rsbs(struct dlm_ls *ls)
  567. {
  568. struct dlm_rsb *r;
  569. int count = 0;
  570. log_debug(ls, "dlm_recover_rsbs");
  571. down_read(&ls->ls_root_sem);
  572. list_for_each_entry(r, &ls->ls_root_list, res_root_list) {
  573. lock_rsb(r);
  574. if (is_master(r)) {
  575. if (rsb_flag(r, RSB_RECOVER_CONVERT))
  576. recover_conversion(r);
  577. if (rsb_flag(r, RSB_NEW_MASTER2))
  578. set_locks_purged(r);
  579. recover_lvb(r);
  580. count++;
  581. }
  582. rsb_clear_flag(r, RSB_RECOVER_CONVERT);
  583. rsb_clear_flag(r, RSB_NEW_MASTER2);
  584. unlock_rsb(r);
  585. }
  586. up_read(&ls->ls_root_sem);
  587. log_debug(ls, "dlm_recover_rsbs %d rsbs", count);
  588. }
  589. /* Create a single list of all root rsb's to be used during recovery */
  590. int dlm_create_root_list(struct dlm_ls *ls)
  591. {
  592. struct dlm_rsb *r;
  593. int i, error = 0;
  594. down_write(&ls->ls_root_sem);
  595. if (!list_empty(&ls->ls_root_list)) {
  596. log_error(ls, "root list not empty");
  597. error = -EINVAL;
  598. goto out;
  599. }
  600. for (i = 0; i < ls->ls_rsbtbl_size; i++) {
  601. spin_lock(&ls->ls_rsbtbl[i].lock);
  602. list_for_each_entry(r, &ls->ls_rsbtbl[i].list, res_hashchain) {
  603. list_add(&r->res_root_list, &ls->ls_root_list);
  604. dlm_hold_rsb(r);
  605. }
  606. /* If we're using a directory, add tossed rsbs to the root
  607. list; they'll have entries created in the new directory,
  608. but no other recovery steps should do anything with them. */
  609. if (dlm_no_directory(ls)) {
  610. spin_unlock(&ls->ls_rsbtbl[i].lock);
  611. continue;
  612. }
  613. list_for_each_entry(r, &ls->ls_rsbtbl[i].toss, res_hashchain) {
  614. list_add(&r->res_root_list, &ls->ls_root_list);
  615. dlm_hold_rsb(r);
  616. }
  617. spin_unlock(&ls->ls_rsbtbl[i].lock);
  618. }
  619. out:
  620. up_write(&ls->ls_root_sem);
  621. return error;
  622. }
  623. void dlm_release_root_list(struct dlm_ls *ls)
  624. {
  625. struct dlm_rsb *r, *safe;
  626. down_write(&ls->ls_root_sem);
  627. list_for_each_entry_safe(r, safe, &ls->ls_root_list, res_root_list) {
  628. list_del_init(&r->res_root_list);
  629. dlm_put_rsb(r);
  630. }
  631. up_write(&ls->ls_root_sem);
  632. }
  633. /* If not using a directory, clear the entire toss list, there's no benefit to
  634. caching the master value since it's fixed. If we are using a dir, keep the
  635. rsb's we're the master of. Recovery will add them to the root list and from
  636. there they'll be entered in the rebuilt directory. */
  637. void dlm_clear_toss_list(struct dlm_ls *ls)
  638. {
  639. struct dlm_rsb *r, *safe;
  640. int i;
  641. for (i = 0; i < ls->ls_rsbtbl_size; i++) {
  642. spin_lock(&ls->ls_rsbtbl[i].lock);
  643. list_for_each_entry_safe(r, safe, &ls->ls_rsbtbl[i].toss,
  644. res_hashchain) {
  645. if (dlm_no_directory(ls) || !is_master(r)) {
  646. list_del(&r->res_hashchain);
  647. dlm_free_rsb(r);
  648. }
  649. }
  650. spin_unlock(&ls->ls_rsbtbl[i].lock);
  651. }
  652. }