recover.c 18 KB

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