recover.c 18 KB

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