recover.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765
  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.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.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 = (struct dlm_rcom *) 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 = (struct dlm_rcom *) 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. dlm_put_rsb(r);
  215. ls->ls_recover_list_count--;
  216. }
  217. if (ls->ls_recover_list_count != 0) {
  218. log_error(ls, "warning: recover_list_count %d",
  219. ls->ls_recover_list_count);
  220. ls->ls_recover_list_count = 0;
  221. }
  222. spin_unlock(&ls->ls_recover_list_lock);
  223. }
  224. /* Master recovery: find new master node for rsb's that were
  225. mastered on nodes that have been removed.
  226. dlm_recover_masters
  227. recover_master
  228. dlm_send_rcom_lookup -> receive_rcom_lookup
  229. dlm_dir_lookup
  230. receive_rcom_lookup_reply <-
  231. dlm_recover_master_reply
  232. set_new_master
  233. set_master_lkbs
  234. set_lock_master
  235. */
  236. /*
  237. * Set the lock master for all LKBs in a lock queue
  238. * If we are the new master of the rsb, we may have received new
  239. * MSTCPY locks from other nodes already which we need to ignore
  240. * when setting the new nodeid.
  241. */
  242. static void set_lock_master(struct list_head *queue, int nodeid)
  243. {
  244. struct dlm_lkb *lkb;
  245. list_for_each_entry(lkb, queue, lkb_statequeue)
  246. if (!(lkb->lkb_flags & DLM_IFL_MSTCPY))
  247. lkb->lkb_nodeid = nodeid;
  248. }
  249. static void set_master_lkbs(struct dlm_rsb *r)
  250. {
  251. set_lock_master(&r->res_grantqueue, r->res_nodeid);
  252. set_lock_master(&r->res_convertqueue, r->res_nodeid);
  253. set_lock_master(&r->res_waitqueue, r->res_nodeid);
  254. }
  255. /*
  256. * Propogate the new master nodeid to locks
  257. * The NEW_MASTER flag tells dlm_recover_locks() which rsb's to consider.
  258. * The NEW_MASTER2 flag tells recover_lvb() and set_locks_purged() which
  259. * rsb's to consider.
  260. */
  261. static void set_new_master(struct dlm_rsb *r, int nodeid)
  262. {
  263. lock_rsb(r);
  264. r->res_nodeid = nodeid;
  265. set_master_lkbs(r);
  266. rsb_set_flag(r, RSB_NEW_MASTER);
  267. rsb_set_flag(r, RSB_NEW_MASTER2);
  268. unlock_rsb(r);
  269. }
  270. /*
  271. * We do async lookups on rsb's that need new masters. The rsb's
  272. * waiting for a lookup reply are kept on the recover_list.
  273. */
  274. static int recover_master(struct dlm_rsb *r)
  275. {
  276. struct dlm_ls *ls = r->res_ls;
  277. int error, dir_nodeid, ret_nodeid, our_nodeid = dlm_our_nodeid();
  278. dir_nodeid = dlm_dir_nodeid(r);
  279. if (dir_nodeid == our_nodeid) {
  280. error = dlm_dir_lookup(ls, our_nodeid, r->res_name,
  281. r->res_length, &ret_nodeid);
  282. if (error)
  283. log_error(ls, "recover dir lookup error %d", error);
  284. if (ret_nodeid == our_nodeid)
  285. ret_nodeid = 0;
  286. set_new_master(r, ret_nodeid);
  287. } else {
  288. recover_list_add(r);
  289. error = dlm_send_rcom_lookup(r, dir_nodeid);
  290. }
  291. return error;
  292. }
  293. /*
  294. * When not using a directory, most resource names will hash to a new static
  295. * master nodeid and the resource will need to be remastered.
  296. */
  297. static int recover_master_static(struct dlm_rsb *r)
  298. {
  299. int master = dlm_dir_nodeid(r);
  300. if (master == dlm_our_nodeid())
  301. master = 0;
  302. if (r->res_nodeid != master) {
  303. if (is_master(r))
  304. dlm_purge_mstcpy_locks(r);
  305. set_new_master(r, master);
  306. return 1;
  307. }
  308. return 0;
  309. }
  310. /*
  311. * Go through local root resources and for each rsb which has a master which
  312. * has departed, get the new master nodeid from the directory. The dir will
  313. * assign mastery to the first node to look up the new master. That means
  314. * we'll discover in this lookup if we're the new master of any rsb's.
  315. *
  316. * We fire off all the dir lookup requests individually and asynchronously to
  317. * the correct dir node.
  318. */
  319. int dlm_recover_masters(struct dlm_ls *ls)
  320. {
  321. struct dlm_rsb *r;
  322. int error = 0, count = 0;
  323. log_debug(ls, "dlm_recover_masters");
  324. down_read(&ls->ls_root_sem);
  325. list_for_each_entry(r, &ls->ls_root_list, res_root_list) {
  326. if (dlm_recovery_stopped(ls)) {
  327. up_read(&ls->ls_root_sem);
  328. error = -EINTR;
  329. goto out;
  330. }
  331. if (dlm_no_directory(ls))
  332. count += recover_master_static(r);
  333. else if (!is_master(r) && dlm_is_removed(ls, r->res_nodeid)) {
  334. recover_master(r);
  335. count++;
  336. }
  337. schedule();
  338. }
  339. up_read(&ls->ls_root_sem);
  340. log_debug(ls, "dlm_recover_masters %d resources", count);
  341. error = dlm_wait_function(ls, &recover_list_empty);
  342. out:
  343. if (error)
  344. recover_list_clear(ls);
  345. return error;
  346. }
  347. int dlm_recover_master_reply(struct dlm_ls *ls, struct dlm_rcom *rc)
  348. {
  349. struct dlm_rsb *r;
  350. int nodeid;
  351. r = recover_list_find(ls, rc->rc_id);
  352. if (!r) {
  353. log_error(ls, "dlm_recover_master_reply no id %llx",
  354. (unsigned long long)rc->rc_id);
  355. goto out;
  356. }
  357. nodeid = rc->rc_result;
  358. if (nodeid == dlm_our_nodeid())
  359. nodeid = 0;
  360. set_new_master(r, nodeid);
  361. recover_list_del(r);
  362. if (recover_list_empty(ls))
  363. wake_up(&ls->ls_wait_general);
  364. out:
  365. return 0;
  366. }
  367. /* Lock recovery: rebuild the process-copy locks we hold on a
  368. remastered rsb on the new rsb master.
  369. dlm_recover_locks
  370. recover_locks
  371. recover_locks_queue
  372. dlm_send_rcom_lock -> receive_rcom_lock
  373. dlm_recover_master_copy
  374. receive_rcom_lock_reply <-
  375. dlm_recover_process_copy
  376. */
  377. /*
  378. * keep a count of the number of lkb's we send to the new master; when we get
  379. * an equal number of replies then recovery for the rsb is done
  380. */
  381. static int recover_locks_queue(struct dlm_rsb *r, struct list_head *head)
  382. {
  383. struct dlm_lkb *lkb;
  384. int error = 0;
  385. list_for_each_entry(lkb, head, lkb_statequeue) {
  386. error = dlm_send_rcom_lock(r, lkb);
  387. if (error)
  388. break;
  389. r->res_recover_locks_count++;
  390. }
  391. return error;
  392. }
  393. static int recover_locks(struct dlm_rsb *r)
  394. {
  395. int error = 0;
  396. lock_rsb(r);
  397. DLM_ASSERT(!r->res_recover_locks_count, dlm_dump_rsb(r););
  398. error = recover_locks_queue(r, &r->res_grantqueue);
  399. if (error)
  400. goto out;
  401. error = recover_locks_queue(r, &r->res_convertqueue);
  402. if (error)
  403. goto out;
  404. error = recover_locks_queue(r, &r->res_waitqueue);
  405. if (error)
  406. goto out;
  407. if (r->res_recover_locks_count)
  408. recover_list_add(r);
  409. else
  410. rsb_clear_flag(r, RSB_NEW_MASTER);
  411. out:
  412. unlock_rsb(r);
  413. return error;
  414. }
  415. int dlm_recover_locks(struct dlm_ls *ls)
  416. {
  417. struct dlm_rsb *r;
  418. int error, count = 0;
  419. log_debug(ls, "dlm_recover_locks");
  420. down_read(&ls->ls_root_sem);
  421. list_for_each_entry(r, &ls->ls_root_list, res_root_list) {
  422. if (is_master(r)) {
  423. rsb_clear_flag(r, RSB_NEW_MASTER);
  424. continue;
  425. }
  426. if (!rsb_flag(r, RSB_NEW_MASTER))
  427. continue;
  428. if (dlm_recovery_stopped(ls)) {
  429. error = -EINTR;
  430. up_read(&ls->ls_root_sem);
  431. goto out;
  432. }
  433. error = recover_locks(r);
  434. if (error) {
  435. up_read(&ls->ls_root_sem);
  436. goto out;
  437. }
  438. count += r->res_recover_locks_count;
  439. }
  440. up_read(&ls->ls_root_sem);
  441. log_debug(ls, "dlm_recover_locks %d locks", count);
  442. error = dlm_wait_function(ls, &recover_list_empty);
  443. out:
  444. if (error)
  445. recover_list_clear(ls);
  446. else
  447. dlm_set_recover_status(ls, DLM_RS_LOCKS);
  448. return error;
  449. }
  450. void dlm_recovered_lock(struct dlm_rsb *r)
  451. {
  452. DLM_ASSERT(rsb_flag(r, RSB_NEW_MASTER), dlm_dump_rsb(r););
  453. r->res_recover_locks_count--;
  454. if (!r->res_recover_locks_count) {
  455. rsb_clear_flag(r, RSB_NEW_MASTER);
  456. recover_list_del(r);
  457. }
  458. if (recover_list_empty(r->res_ls))
  459. wake_up(&r->res_ls->ls_wait_general);
  460. }
  461. /*
  462. * The lvb needs to be recovered on all master rsb's. This includes setting
  463. * the VALNOTVALID flag if necessary, and determining the correct lvb contents
  464. * based on the lvb's of the locks held on the rsb.
  465. *
  466. * RSB_VALNOTVALID is set if there are only NL/CR locks on the rsb. If it
  467. * was already set prior to recovery, it's not cleared, regardless of locks.
  468. *
  469. * The LVB contents are only considered for changing when this is a new master
  470. * of the rsb (NEW_MASTER2). Then, the rsb's lvb is taken from any lkb with
  471. * mode > CR. If no lkb's exist with mode above CR, the lvb contents are taken
  472. * from the lkb with the largest lvb sequence number.
  473. */
  474. static void recover_lvb(struct dlm_rsb *r)
  475. {
  476. struct dlm_lkb *lkb, *high_lkb = NULL;
  477. uint32_t high_seq = 0;
  478. int lock_lvb_exists = 0;
  479. int big_lock_exists = 0;
  480. int lvblen = r->res_ls->ls_lvblen;
  481. list_for_each_entry(lkb, &r->res_grantqueue, lkb_statequeue) {
  482. if (!(lkb->lkb_exflags & DLM_LKF_VALBLK))
  483. continue;
  484. lock_lvb_exists = 1;
  485. if (lkb->lkb_grmode > DLM_LOCK_CR) {
  486. big_lock_exists = 1;
  487. goto setflag;
  488. }
  489. if (((int)lkb->lkb_lvbseq - (int)high_seq) >= 0) {
  490. high_lkb = lkb;
  491. high_seq = lkb->lkb_lvbseq;
  492. }
  493. }
  494. list_for_each_entry(lkb, &r->res_convertqueue, lkb_statequeue) {
  495. if (!(lkb->lkb_exflags & DLM_LKF_VALBLK))
  496. continue;
  497. lock_lvb_exists = 1;
  498. if (lkb->lkb_grmode > DLM_LOCK_CR) {
  499. big_lock_exists = 1;
  500. goto setflag;
  501. }
  502. if (((int)lkb->lkb_lvbseq - (int)high_seq) >= 0) {
  503. high_lkb = lkb;
  504. high_seq = lkb->lkb_lvbseq;
  505. }
  506. }
  507. setflag:
  508. if (!lock_lvb_exists)
  509. goto out;
  510. if (!big_lock_exists)
  511. rsb_set_flag(r, RSB_VALNOTVALID);
  512. /* don't mess with the lvb unless we're the new master */
  513. if (!rsb_flag(r, RSB_NEW_MASTER2))
  514. goto out;
  515. if (!r->res_lvbptr) {
  516. r->res_lvbptr = allocate_lvb(r->res_ls);
  517. if (!r->res_lvbptr)
  518. goto out;
  519. }
  520. if (big_lock_exists) {
  521. r->res_lvbseq = lkb->lkb_lvbseq;
  522. memcpy(r->res_lvbptr, lkb->lkb_lvbptr, lvblen);
  523. } else if (high_lkb) {
  524. r->res_lvbseq = high_lkb->lkb_lvbseq;
  525. memcpy(r->res_lvbptr, high_lkb->lkb_lvbptr, lvblen);
  526. } else {
  527. r->res_lvbseq = 0;
  528. memset(r->res_lvbptr, 0, lvblen);
  529. }
  530. out:
  531. return;
  532. }
  533. /* All master rsb's flagged RECOVER_CONVERT need to be looked at. The locks
  534. converting PR->CW or CW->PR need to have their lkb_grmode set. */
  535. static void recover_conversion(struct dlm_rsb *r)
  536. {
  537. struct dlm_lkb *lkb;
  538. int grmode = -1;
  539. list_for_each_entry(lkb, &r->res_grantqueue, lkb_statequeue) {
  540. if (lkb->lkb_grmode == DLM_LOCK_PR ||
  541. lkb->lkb_grmode == DLM_LOCK_CW) {
  542. grmode = lkb->lkb_grmode;
  543. break;
  544. }
  545. }
  546. list_for_each_entry(lkb, &r->res_convertqueue, lkb_statequeue) {
  547. if (lkb->lkb_grmode != DLM_LOCK_IV)
  548. continue;
  549. if (grmode == -1)
  550. lkb->lkb_grmode = lkb->lkb_rqmode;
  551. else
  552. lkb->lkb_grmode = grmode;
  553. }
  554. }
  555. /* We've become the new master for this rsb and waiting/converting locks may
  556. need to be granted in dlm_grant_after_purge() due to locks that may have
  557. existed from a removed node. */
  558. static void set_locks_purged(struct dlm_rsb *r)
  559. {
  560. if (!list_empty(&r->res_waitqueue) || !list_empty(&r->res_convertqueue))
  561. rsb_set_flag(r, RSB_LOCKS_PURGED);
  562. }
  563. void dlm_recover_rsbs(struct dlm_ls *ls)
  564. {
  565. struct dlm_rsb *r;
  566. int count = 0;
  567. log_debug(ls, "dlm_recover_rsbs");
  568. down_read(&ls->ls_root_sem);
  569. list_for_each_entry(r, &ls->ls_root_list, res_root_list) {
  570. lock_rsb(r);
  571. if (is_master(r)) {
  572. if (rsb_flag(r, RSB_RECOVER_CONVERT))
  573. recover_conversion(r);
  574. if (rsb_flag(r, RSB_NEW_MASTER2))
  575. set_locks_purged(r);
  576. recover_lvb(r);
  577. count++;
  578. }
  579. rsb_clear_flag(r, RSB_RECOVER_CONVERT);
  580. rsb_clear_flag(r, RSB_NEW_MASTER2);
  581. unlock_rsb(r);
  582. }
  583. up_read(&ls->ls_root_sem);
  584. log_debug(ls, "dlm_recover_rsbs %d rsbs", count);
  585. }
  586. /* Create a single list of all root rsb's to be used during recovery */
  587. int dlm_create_root_list(struct dlm_ls *ls)
  588. {
  589. struct dlm_rsb *r;
  590. int i, error = 0;
  591. down_write(&ls->ls_root_sem);
  592. if (!list_empty(&ls->ls_root_list)) {
  593. log_error(ls, "root list not empty");
  594. error = -EINVAL;
  595. goto out;
  596. }
  597. for (i = 0; i < ls->ls_rsbtbl_size; i++) {
  598. read_lock(&ls->ls_rsbtbl[i].lock);
  599. list_for_each_entry(r, &ls->ls_rsbtbl[i].list, res_hashchain) {
  600. list_add(&r->res_root_list, &ls->ls_root_list);
  601. dlm_hold_rsb(r);
  602. }
  603. read_unlock(&ls->ls_rsbtbl[i].lock);
  604. }
  605. out:
  606. up_write(&ls->ls_root_sem);
  607. return error;
  608. }
  609. void dlm_release_root_list(struct dlm_ls *ls)
  610. {
  611. struct dlm_rsb *r, *safe;
  612. down_write(&ls->ls_root_sem);
  613. list_for_each_entry_safe(r, safe, &ls->ls_root_list, res_root_list) {
  614. list_del_init(&r->res_root_list);
  615. dlm_put_rsb(r);
  616. }
  617. up_write(&ls->ls_root_sem);
  618. }
  619. void dlm_clear_toss_list(struct dlm_ls *ls)
  620. {
  621. struct dlm_rsb *r, *safe;
  622. int i;
  623. for (i = 0; i < ls->ls_rsbtbl_size; i++) {
  624. write_lock(&ls->ls_rsbtbl[i].lock);
  625. list_for_each_entry_safe(r, safe, &ls->ls_rsbtbl[i].toss,
  626. res_hashchain) {
  627. list_del(&r->res_hashchain);
  628. free_rsb(r);
  629. }
  630. write_unlock(&ls->ls_rsbtbl[i].lock);
  631. }
  632. }