recover.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766
  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. 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. * Propogate 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) && dlm_is_removed(ls, r->res_nodeid)) {
  335. recover_master(r);
  336. count++;
  337. }
  338. schedule();
  339. }
  340. up_read(&ls->ls_root_sem);
  341. log_debug(ls, "dlm_recover_masters %d resources", count);
  342. error = dlm_wait_function(ls, &recover_list_empty);
  343. out:
  344. if (error)
  345. recover_list_clear(ls);
  346. return error;
  347. }
  348. int dlm_recover_master_reply(struct dlm_ls *ls, struct dlm_rcom *rc)
  349. {
  350. struct dlm_rsb *r;
  351. int nodeid;
  352. r = recover_list_find(ls, rc->rc_id);
  353. if (!r) {
  354. log_error(ls, "dlm_recover_master_reply no id %llx",
  355. (unsigned long long)rc->rc_id);
  356. goto out;
  357. }
  358. nodeid = rc->rc_result;
  359. if (nodeid == dlm_our_nodeid())
  360. nodeid = 0;
  361. set_new_master(r, nodeid);
  362. recover_list_del(r);
  363. if (recover_list_empty(ls))
  364. wake_up(&ls->ls_wait_general);
  365. out:
  366. return 0;
  367. }
  368. /* Lock recovery: rebuild the process-copy locks we hold on a
  369. remastered rsb on the new rsb master.
  370. dlm_recover_locks
  371. recover_locks
  372. recover_locks_queue
  373. dlm_send_rcom_lock -> receive_rcom_lock
  374. dlm_recover_master_copy
  375. receive_rcom_lock_reply <-
  376. dlm_recover_process_copy
  377. */
  378. /*
  379. * keep a count of the number of lkb's we send to the new master; when we get
  380. * an equal number of replies then recovery for the rsb is done
  381. */
  382. static int recover_locks_queue(struct dlm_rsb *r, struct list_head *head)
  383. {
  384. struct dlm_lkb *lkb;
  385. int error = 0;
  386. list_for_each_entry(lkb, head, lkb_statequeue) {
  387. error = dlm_send_rcom_lock(r, lkb);
  388. if (error)
  389. break;
  390. r->res_recover_locks_count++;
  391. }
  392. return error;
  393. }
  394. static int recover_locks(struct dlm_rsb *r)
  395. {
  396. int error = 0;
  397. lock_rsb(r);
  398. DLM_ASSERT(!r->res_recover_locks_count, dlm_dump_rsb(r););
  399. error = recover_locks_queue(r, &r->res_grantqueue);
  400. if (error)
  401. goto out;
  402. error = recover_locks_queue(r, &r->res_convertqueue);
  403. if (error)
  404. goto out;
  405. error = recover_locks_queue(r, &r->res_waitqueue);
  406. if (error)
  407. goto out;
  408. if (r->res_recover_locks_count)
  409. recover_list_add(r);
  410. else
  411. rsb_clear_flag(r, RSB_NEW_MASTER);
  412. out:
  413. unlock_rsb(r);
  414. return error;
  415. }
  416. int dlm_recover_locks(struct dlm_ls *ls)
  417. {
  418. struct dlm_rsb *r;
  419. int error, count = 0;
  420. log_debug(ls, "dlm_recover_locks");
  421. down_read(&ls->ls_root_sem);
  422. list_for_each_entry(r, &ls->ls_root_list, res_root_list) {
  423. if (is_master(r)) {
  424. rsb_clear_flag(r, RSB_NEW_MASTER);
  425. continue;
  426. }
  427. if (!rsb_flag(r, RSB_NEW_MASTER))
  428. continue;
  429. if (dlm_recovery_stopped(ls)) {
  430. error = -EINTR;
  431. up_read(&ls->ls_root_sem);
  432. goto out;
  433. }
  434. error = recover_locks(r);
  435. if (error) {
  436. up_read(&ls->ls_root_sem);
  437. goto out;
  438. }
  439. count += r->res_recover_locks_count;
  440. }
  441. up_read(&ls->ls_root_sem);
  442. log_debug(ls, "dlm_recover_locks %d locks", count);
  443. error = dlm_wait_function(ls, &recover_list_empty);
  444. out:
  445. if (error)
  446. recover_list_clear(ls);
  447. else
  448. dlm_set_recover_status(ls, DLM_RS_LOCKS);
  449. return error;
  450. }
  451. void dlm_recovered_lock(struct dlm_rsb *r)
  452. {
  453. DLM_ASSERT(rsb_flag(r, RSB_NEW_MASTER), dlm_dump_rsb(r););
  454. r->res_recover_locks_count--;
  455. if (!r->res_recover_locks_count) {
  456. rsb_clear_flag(r, RSB_NEW_MASTER);
  457. recover_list_del(r);
  458. }
  459. if (recover_list_empty(r->res_ls))
  460. wake_up(&r->res_ls->ls_wait_general);
  461. }
  462. /*
  463. * The lvb needs to be recovered on all master rsb's. This includes setting
  464. * the VALNOTVALID flag if necessary, and determining the correct lvb contents
  465. * based on the lvb's of the locks held on the rsb.
  466. *
  467. * RSB_VALNOTVALID is set if there are only NL/CR locks on the rsb. If it
  468. * was already set prior to recovery, it's not cleared, regardless of locks.
  469. *
  470. * The LVB contents are only considered for changing when this is a new master
  471. * of the rsb (NEW_MASTER2). Then, the rsb's lvb is taken from any lkb with
  472. * mode > CR. If no lkb's exist with mode above CR, the lvb contents are taken
  473. * from the lkb with the largest lvb sequence number.
  474. */
  475. static void recover_lvb(struct dlm_rsb *r)
  476. {
  477. struct dlm_lkb *lkb, *high_lkb = NULL;
  478. uint32_t high_seq = 0;
  479. int lock_lvb_exists = 0;
  480. int big_lock_exists = 0;
  481. int lvblen = r->res_ls->ls_lvblen;
  482. list_for_each_entry(lkb, &r->res_grantqueue, lkb_statequeue) {
  483. if (!(lkb->lkb_exflags & DLM_LKF_VALBLK))
  484. continue;
  485. lock_lvb_exists = 1;
  486. if (lkb->lkb_grmode > DLM_LOCK_CR) {
  487. big_lock_exists = 1;
  488. goto setflag;
  489. }
  490. if (((int)lkb->lkb_lvbseq - (int)high_seq) >= 0) {
  491. high_lkb = lkb;
  492. high_seq = lkb->lkb_lvbseq;
  493. }
  494. }
  495. list_for_each_entry(lkb, &r->res_convertqueue, lkb_statequeue) {
  496. if (!(lkb->lkb_exflags & DLM_LKF_VALBLK))
  497. continue;
  498. lock_lvb_exists = 1;
  499. if (lkb->lkb_grmode > DLM_LOCK_CR) {
  500. big_lock_exists = 1;
  501. goto setflag;
  502. }
  503. if (((int)lkb->lkb_lvbseq - (int)high_seq) >= 0) {
  504. high_lkb = lkb;
  505. high_seq = lkb->lkb_lvbseq;
  506. }
  507. }
  508. setflag:
  509. if (!lock_lvb_exists)
  510. goto out;
  511. if (!big_lock_exists)
  512. rsb_set_flag(r, RSB_VALNOTVALID);
  513. /* don't mess with the lvb unless we're the new master */
  514. if (!rsb_flag(r, RSB_NEW_MASTER2))
  515. goto out;
  516. if (!r->res_lvbptr) {
  517. r->res_lvbptr = allocate_lvb(r->res_ls);
  518. if (!r->res_lvbptr)
  519. goto out;
  520. }
  521. if (big_lock_exists) {
  522. r->res_lvbseq = lkb->lkb_lvbseq;
  523. memcpy(r->res_lvbptr, lkb->lkb_lvbptr, lvblen);
  524. } else if (high_lkb) {
  525. r->res_lvbseq = high_lkb->lkb_lvbseq;
  526. memcpy(r->res_lvbptr, high_lkb->lkb_lvbptr, lvblen);
  527. } else {
  528. r->res_lvbseq = 0;
  529. memset(r->res_lvbptr, 0, lvblen);
  530. }
  531. out:
  532. return;
  533. }
  534. /* All master rsb's flagged RECOVER_CONVERT need to be looked at. The locks
  535. converting PR->CW or CW->PR need to have their lkb_grmode set. */
  536. static void recover_conversion(struct dlm_rsb *r)
  537. {
  538. struct dlm_lkb *lkb;
  539. int grmode = -1;
  540. list_for_each_entry(lkb, &r->res_grantqueue, lkb_statequeue) {
  541. if (lkb->lkb_grmode == DLM_LOCK_PR ||
  542. lkb->lkb_grmode == DLM_LOCK_CW) {
  543. grmode = lkb->lkb_grmode;
  544. break;
  545. }
  546. }
  547. list_for_each_entry(lkb, &r->res_convertqueue, lkb_statequeue) {
  548. if (lkb->lkb_grmode != DLM_LOCK_IV)
  549. continue;
  550. if (grmode == -1)
  551. lkb->lkb_grmode = lkb->lkb_rqmode;
  552. else
  553. lkb->lkb_grmode = grmode;
  554. }
  555. }
  556. /* We've become the new master for this rsb and waiting/converting locks may
  557. need to be granted in dlm_grant_after_purge() due to locks that may have
  558. existed from a removed node. */
  559. static void set_locks_purged(struct dlm_rsb *r)
  560. {
  561. if (!list_empty(&r->res_waitqueue) || !list_empty(&r->res_convertqueue))
  562. rsb_set_flag(r, RSB_LOCKS_PURGED);
  563. }
  564. void dlm_recover_rsbs(struct dlm_ls *ls)
  565. {
  566. struct dlm_rsb *r;
  567. int count = 0;
  568. log_debug(ls, "dlm_recover_rsbs");
  569. down_read(&ls->ls_root_sem);
  570. list_for_each_entry(r, &ls->ls_root_list, res_root_list) {
  571. lock_rsb(r);
  572. if (is_master(r)) {
  573. if (rsb_flag(r, RSB_RECOVER_CONVERT))
  574. recover_conversion(r);
  575. if (rsb_flag(r, RSB_NEW_MASTER2))
  576. set_locks_purged(r);
  577. recover_lvb(r);
  578. count++;
  579. }
  580. rsb_clear_flag(r, RSB_RECOVER_CONVERT);
  581. rsb_clear_flag(r, RSB_NEW_MASTER2);
  582. unlock_rsb(r);
  583. }
  584. up_read(&ls->ls_root_sem);
  585. log_debug(ls, "dlm_recover_rsbs %d rsbs", count);
  586. }
  587. /* Create a single list of all root rsb's to be used during recovery */
  588. int dlm_create_root_list(struct dlm_ls *ls)
  589. {
  590. struct dlm_rsb *r;
  591. int i, error = 0;
  592. down_write(&ls->ls_root_sem);
  593. if (!list_empty(&ls->ls_root_list)) {
  594. log_error(ls, "root list not empty");
  595. error = -EINVAL;
  596. goto out;
  597. }
  598. for (i = 0; i < ls->ls_rsbtbl_size; i++) {
  599. read_lock(&ls->ls_rsbtbl[i].lock);
  600. list_for_each_entry(r, &ls->ls_rsbtbl[i].list, res_hashchain) {
  601. list_add(&r->res_root_list, &ls->ls_root_list);
  602. dlm_hold_rsb(r);
  603. }
  604. read_unlock(&ls->ls_rsbtbl[i].lock);
  605. }
  606. out:
  607. up_write(&ls->ls_root_sem);
  608. return error;
  609. }
  610. void dlm_release_root_list(struct dlm_ls *ls)
  611. {
  612. struct dlm_rsb *r, *safe;
  613. down_write(&ls->ls_root_sem);
  614. list_for_each_entry_safe(r, safe, &ls->ls_root_list, res_root_list) {
  615. list_del_init(&r->res_root_list);
  616. dlm_put_rsb(r);
  617. }
  618. up_write(&ls->ls_root_sem);
  619. }
  620. void dlm_clear_toss_list(struct dlm_ls *ls)
  621. {
  622. struct dlm_rsb *r, *safe;
  623. int i;
  624. for (i = 0; i < ls->ls_rsbtbl_size; i++) {
  625. write_lock(&ls->ls_rsbtbl[i].lock);
  626. list_for_each_entry_safe(r, safe, &ls->ls_rsbtbl[i].toss,
  627. res_hashchain) {
  628. list_del(&r->res_hashchain);
  629. free_rsb(r);
  630. }
  631. write_unlock(&ls->ls_rsbtbl[i].lock);
  632. }
  633. }