dlmthread.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. /* -*- mode: c; c-basic-offset: 8; -*-
  2. * vim: noexpandtab sw=8 ts=8 sts=0:
  3. *
  4. * dlmthread.c
  5. *
  6. * standalone DLM module
  7. *
  8. * Copyright (C) 2004 Oracle. All rights reserved.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public
  12. * License as published by the Free Software Foundation; either
  13. * version 2 of the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public
  21. * License along with this program; if not, write to the
  22. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  23. * Boston, MA 021110-1307, USA.
  24. *
  25. */
  26. #include <linux/module.h>
  27. #include <linux/fs.h>
  28. #include <linux/types.h>
  29. #include <linux/slab.h>
  30. #include <linux/highmem.h>
  31. #include <linux/utsname.h>
  32. #include <linux/init.h>
  33. #include <linux/sysctl.h>
  34. #include <linux/random.h>
  35. #include <linux/blkdev.h>
  36. #include <linux/socket.h>
  37. #include <linux/inet.h>
  38. #include <linux/timer.h>
  39. #include <linux/kthread.h>
  40. #include "cluster/heartbeat.h"
  41. #include "cluster/nodemanager.h"
  42. #include "cluster/tcp.h"
  43. #include "dlmapi.h"
  44. #include "dlmcommon.h"
  45. #include "dlmdomain.h"
  46. #define MLOG_MASK_PREFIX (ML_DLM|ML_DLM_THREAD)
  47. #include "cluster/masklog.h"
  48. static int dlm_thread(void *data);
  49. static void dlm_flush_asts(struct dlm_ctxt *dlm);
  50. #define dlm_lock_is_remote(dlm, lock) ((lock)->ml.node != (dlm)->node_num)
  51. /* will exit holding res->spinlock, but may drop in function */
  52. /* waits until flags are cleared on res->state */
  53. void __dlm_wait_on_lockres_flags(struct dlm_lock_resource *res, int flags)
  54. {
  55. DECLARE_WAITQUEUE(wait, current);
  56. assert_spin_locked(&res->spinlock);
  57. add_wait_queue(&res->wq, &wait);
  58. repeat:
  59. set_current_state(TASK_UNINTERRUPTIBLE);
  60. if (res->state & flags) {
  61. spin_unlock(&res->spinlock);
  62. schedule();
  63. spin_lock(&res->spinlock);
  64. goto repeat;
  65. }
  66. remove_wait_queue(&res->wq, &wait);
  67. current->state = TASK_RUNNING;
  68. }
  69. static int __dlm_lockres_unused(struct dlm_lock_resource *res)
  70. {
  71. if (list_empty(&res->granted) &&
  72. list_empty(&res->converting) &&
  73. list_empty(&res->blocked) &&
  74. list_empty(&res->dirty))
  75. return 1;
  76. return 0;
  77. }
  78. /* Call whenever you may have added or deleted something from one of
  79. * the lockres queue's. This will figure out whether it belongs on the
  80. * unused list or not and does the appropriate thing. */
  81. void __dlm_lockres_calc_usage(struct dlm_ctxt *dlm,
  82. struct dlm_lock_resource *res)
  83. {
  84. mlog_entry("%.*s\n", res->lockname.len, res->lockname.name);
  85. assert_spin_locked(&dlm->spinlock);
  86. assert_spin_locked(&res->spinlock);
  87. if (__dlm_lockres_unused(res)){
  88. if (list_empty(&res->purge)) {
  89. mlog(0, "putting lockres %.*s from purge list\n",
  90. res->lockname.len, res->lockname.name);
  91. res->last_used = jiffies;
  92. list_add_tail(&res->purge, &dlm->purge_list);
  93. dlm->purge_count++;
  94. }
  95. } else if (!list_empty(&res->purge)) {
  96. mlog(0, "removing lockres %.*s from purge list\n",
  97. res->lockname.len, res->lockname.name);
  98. list_del_init(&res->purge);
  99. dlm->purge_count--;
  100. }
  101. }
  102. void dlm_lockres_calc_usage(struct dlm_ctxt *dlm,
  103. struct dlm_lock_resource *res)
  104. {
  105. mlog_entry("%.*s\n", res->lockname.len, res->lockname.name);
  106. spin_lock(&dlm->spinlock);
  107. spin_lock(&res->spinlock);
  108. __dlm_lockres_calc_usage(dlm, res);
  109. spin_unlock(&res->spinlock);
  110. spin_unlock(&dlm->spinlock);
  111. }
  112. /* TODO: Eventual API: Called with the dlm spinlock held, may drop it
  113. * to do migration, but will re-acquire before exit. */
  114. void dlm_purge_lockres(struct dlm_ctxt *dlm, struct dlm_lock_resource *lockres)
  115. {
  116. int master;
  117. int ret;
  118. spin_lock(&lockres->spinlock);
  119. master = lockres->owner == dlm->node_num;
  120. spin_unlock(&lockres->spinlock);
  121. mlog(0, "purging lockres %.*s, master = %d\n", lockres->lockname.len,
  122. lockres->lockname.name, master);
  123. /* Non master is the easy case -- no migration required, just
  124. * quit. */
  125. if (!master)
  126. goto finish;
  127. /* Wheee! Migrate lockres here! */
  128. spin_unlock(&dlm->spinlock);
  129. again:
  130. ret = dlm_migrate_lockres(dlm, lockres, O2NM_MAX_NODES);
  131. if (ret == -ENOTEMPTY) {
  132. mlog(ML_ERROR, "lockres %.*s still has local locks!\n",
  133. lockres->lockname.len, lockres->lockname.name);
  134. BUG();
  135. } else if (ret < 0) {
  136. mlog(ML_NOTICE, "lockres %.*s: migrate failed, retrying\n",
  137. lockres->lockname.len, lockres->lockname.name);
  138. goto again;
  139. }
  140. spin_lock(&dlm->spinlock);
  141. finish:
  142. if (!list_empty(&lockres->purge)) {
  143. list_del_init(&lockres->purge);
  144. dlm->purge_count--;
  145. }
  146. __dlm_unhash_lockres(lockres);
  147. }
  148. static void dlm_run_purge_list(struct dlm_ctxt *dlm,
  149. int purge_now)
  150. {
  151. unsigned int run_max, unused;
  152. unsigned long purge_jiffies;
  153. struct dlm_lock_resource *lockres;
  154. spin_lock(&dlm->spinlock);
  155. run_max = dlm->purge_count;
  156. while(run_max && !list_empty(&dlm->purge_list)) {
  157. run_max--;
  158. lockres = list_entry(dlm->purge_list.next,
  159. struct dlm_lock_resource, purge);
  160. /* Status of the lockres *might* change so double
  161. * check. If the lockres is unused, holding the dlm
  162. * spinlock will prevent people from getting and more
  163. * refs on it -- there's no need to keep the lockres
  164. * spinlock. */
  165. spin_lock(&lockres->spinlock);
  166. unused = __dlm_lockres_unused(lockres);
  167. spin_unlock(&lockres->spinlock);
  168. if (!unused)
  169. continue;
  170. purge_jiffies = lockres->last_used +
  171. msecs_to_jiffies(DLM_PURGE_INTERVAL_MS);
  172. /* Make sure that we want to be processing this guy at
  173. * this time. */
  174. if (!purge_now && time_after(purge_jiffies, jiffies)) {
  175. /* Since resources are added to the purge list
  176. * in tail order, we can stop at the first
  177. * unpurgable resource -- anyone added after
  178. * him will have a greater last_used value */
  179. break;
  180. }
  181. list_del_init(&lockres->purge);
  182. dlm->purge_count--;
  183. /* This may drop and reacquire the dlm spinlock if it
  184. * has to do migration. */
  185. mlog(0, "calling dlm_purge_lockres!\n");
  186. dlm_purge_lockres(dlm, lockres);
  187. mlog(0, "DONE calling dlm_purge_lockres!\n");
  188. /* Avoid adding any scheduling latencies */
  189. cond_resched_lock(&dlm->spinlock);
  190. }
  191. spin_unlock(&dlm->spinlock);
  192. }
  193. static void dlm_shuffle_lists(struct dlm_ctxt *dlm,
  194. struct dlm_lock_resource *res)
  195. {
  196. struct dlm_lock *lock, *target;
  197. struct list_head *iter;
  198. struct list_head *head;
  199. int can_grant = 1;
  200. //mlog(0, "res->lockname.len=%d\n", res->lockname.len);
  201. //mlog(0, "res->lockname.name=%p\n", res->lockname.name);
  202. //mlog(0, "shuffle res %.*s\n", res->lockname.len,
  203. // res->lockname.name);
  204. /* because this function is called with the lockres
  205. * spinlock, and because we know that it is not migrating/
  206. * recovering/in-progress, it is fine to reserve asts and
  207. * basts right before queueing them all throughout */
  208. assert_spin_locked(&res->spinlock);
  209. BUG_ON((res->state & (DLM_LOCK_RES_MIGRATING|
  210. DLM_LOCK_RES_RECOVERING|
  211. DLM_LOCK_RES_IN_PROGRESS)));
  212. converting:
  213. if (list_empty(&res->converting))
  214. goto blocked;
  215. mlog(0, "res %.*s has locks on a convert queue\n", res->lockname.len,
  216. res->lockname.name);
  217. target = list_entry(res->converting.next, struct dlm_lock, list);
  218. if (target->ml.convert_type == LKM_IVMODE) {
  219. mlog(ML_ERROR, "%.*s: converting a lock with no "
  220. "convert_type!\n", res->lockname.len, res->lockname.name);
  221. BUG();
  222. }
  223. head = &res->granted;
  224. list_for_each(iter, head) {
  225. lock = list_entry(iter, struct dlm_lock, list);
  226. if (lock==target)
  227. continue;
  228. if (!dlm_lock_compatible(lock->ml.type,
  229. target->ml.convert_type)) {
  230. can_grant = 0;
  231. /* queue the BAST if not already */
  232. if (lock->ml.highest_blocked == LKM_IVMODE) {
  233. __dlm_lockres_reserve_ast(res);
  234. dlm_queue_bast(dlm, lock);
  235. }
  236. /* update the highest_blocked if needed */
  237. if (lock->ml.highest_blocked < target->ml.convert_type)
  238. lock->ml.highest_blocked =
  239. target->ml.convert_type;
  240. }
  241. }
  242. head = &res->converting;
  243. list_for_each(iter, head) {
  244. lock = list_entry(iter, struct dlm_lock, list);
  245. if (lock==target)
  246. continue;
  247. if (!dlm_lock_compatible(lock->ml.type,
  248. target->ml.convert_type)) {
  249. can_grant = 0;
  250. if (lock->ml.highest_blocked == LKM_IVMODE) {
  251. __dlm_lockres_reserve_ast(res);
  252. dlm_queue_bast(dlm, lock);
  253. }
  254. if (lock->ml.highest_blocked < target->ml.convert_type)
  255. lock->ml.highest_blocked =
  256. target->ml.convert_type;
  257. }
  258. }
  259. /* we can convert the lock */
  260. if (can_grant) {
  261. spin_lock(&target->spinlock);
  262. BUG_ON(target->ml.highest_blocked != LKM_IVMODE);
  263. mlog(0, "calling ast for converting lock: %.*s, have: %d, "
  264. "granting: %d, node: %u\n", res->lockname.len,
  265. res->lockname.name, target->ml.type,
  266. target->ml.convert_type, target->ml.node);
  267. target->ml.type = target->ml.convert_type;
  268. target->ml.convert_type = LKM_IVMODE;
  269. list_move_tail(&target->list, &res->granted);
  270. BUG_ON(!target->lksb);
  271. target->lksb->status = DLM_NORMAL;
  272. spin_unlock(&target->spinlock);
  273. __dlm_lockres_reserve_ast(res);
  274. dlm_queue_ast(dlm, target);
  275. /* go back and check for more */
  276. goto converting;
  277. }
  278. blocked:
  279. if (list_empty(&res->blocked))
  280. goto leave;
  281. target = list_entry(res->blocked.next, struct dlm_lock, list);
  282. head = &res->granted;
  283. list_for_each(iter, head) {
  284. lock = list_entry(iter, struct dlm_lock, list);
  285. if (lock==target)
  286. continue;
  287. if (!dlm_lock_compatible(lock->ml.type, target->ml.type)) {
  288. can_grant = 0;
  289. if (lock->ml.highest_blocked == LKM_IVMODE) {
  290. __dlm_lockres_reserve_ast(res);
  291. dlm_queue_bast(dlm, lock);
  292. }
  293. if (lock->ml.highest_blocked < target->ml.type)
  294. lock->ml.highest_blocked = target->ml.type;
  295. }
  296. }
  297. head = &res->converting;
  298. list_for_each(iter, head) {
  299. lock = list_entry(iter, struct dlm_lock, list);
  300. if (lock==target)
  301. continue;
  302. if (!dlm_lock_compatible(lock->ml.type, target->ml.type)) {
  303. can_grant = 0;
  304. if (lock->ml.highest_blocked == LKM_IVMODE) {
  305. __dlm_lockres_reserve_ast(res);
  306. dlm_queue_bast(dlm, lock);
  307. }
  308. if (lock->ml.highest_blocked < target->ml.type)
  309. lock->ml.highest_blocked = target->ml.type;
  310. }
  311. }
  312. /* we can grant the blocked lock (only
  313. * possible if converting list empty) */
  314. if (can_grant) {
  315. spin_lock(&target->spinlock);
  316. BUG_ON(target->ml.highest_blocked != LKM_IVMODE);
  317. mlog(0, "calling ast for blocked lock: %.*s, granting: %d, "
  318. "node: %u\n", res->lockname.len, res->lockname.name,
  319. target->ml.type, target->ml.node);
  320. // target->ml.type is already correct
  321. list_move_tail(&target->list, &res->granted);
  322. BUG_ON(!target->lksb);
  323. target->lksb->status = DLM_NORMAL;
  324. spin_unlock(&target->spinlock);
  325. __dlm_lockres_reserve_ast(res);
  326. dlm_queue_ast(dlm, target);
  327. /* go back and check for more */
  328. goto converting;
  329. }
  330. leave:
  331. return;
  332. }
  333. /* must have NO locks when calling this with res !=NULL * */
  334. void dlm_kick_thread(struct dlm_ctxt *dlm, struct dlm_lock_resource *res)
  335. {
  336. mlog_entry("dlm=%p, res=%p\n", dlm, res);
  337. if (res) {
  338. spin_lock(&dlm->spinlock);
  339. spin_lock(&res->spinlock);
  340. __dlm_dirty_lockres(dlm, res);
  341. spin_unlock(&res->spinlock);
  342. spin_unlock(&dlm->spinlock);
  343. }
  344. wake_up(&dlm->dlm_thread_wq);
  345. }
  346. void __dlm_dirty_lockres(struct dlm_ctxt *dlm, struct dlm_lock_resource *res)
  347. {
  348. mlog_entry("dlm=%p, res=%p\n", dlm, res);
  349. assert_spin_locked(&dlm->spinlock);
  350. assert_spin_locked(&res->spinlock);
  351. /* don't shuffle secondary queues */
  352. if ((res->owner == dlm->node_num) &&
  353. !(res->state & DLM_LOCK_RES_DIRTY)) {
  354. list_add_tail(&res->dirty, &dlm->dirty_list);
  355. res->state |= DLM_LOCK_RES_DIRTY;
  356. }
  357. }
  358. /* Launch the NM thread for the mounted volume */
  359. int dlm_launch_thread(struct dlm_ctxt *dlm)
  360. {
  361. mlog(0, "starting dlm thread...\n");
  362. dlm->dlm_thread_task = kthread_run(dlm_thread, dlm, "dlm_thread");
  363. if (IS_ERR(dlm->dlm_thread_task)) {
  364. mlog_errno(PTR_ERR(dlm->dlm_thread_task));
  365. dlm->dlm_thread_task = NULL;
  366. return -EINVAL;
  367. }
  368. return 0;
  369. }
  370. void dlm_complete_thread(struct dlm_ctxt *dlm)
  371. {
  372. if (dlm->dlm_thread_task) {
  373. mlog(ML_KTHREAD, "waiting for dlm thread to exit\n");
  374. kthread_stop(dlm->dlm_thread_task);
  375. dlm->dlm_thread_task = NULL;
  376. }
  377. }
  378. static int dlm_dirty_list_empty(struct dlm_ctxt *dlm)
  379. {
  380. int empty;
  381. spin_lock(&dlm->spinlock);
  382. empty = list_empty(&dlm->dirty_list);
  383. spin_unlock(&dlm->spinlock);
  384. return empty;
  385. }
  386. static void dlm_flush_asts(struct dlm_ctxt *dlm)
  387. {
  388. int ret;
  389. struct dlm_lock *lock;
  390. struct dlm_lock_resource *res;
  391. u8 hi;
  392. spin_lock(&dlm->ast_lock);
  393. while (!list_empty(&dlm->pending_asts)) {
  394. lock = list_entry(dlm->pending_asts.next,
  395. struct dlm_lock, ast_list);
  396. /* get an extra ref on lock */
  397. dlm_lock_get(lock);
  398. res = lock->lockres;
  399. mlog(0, "delivering an ast for this lockres\n");
  400. BUG_ON(!lock->ast_pending);
  401. /* remove from list (including ref) */
  402. list_del_init(&lock->ast_list);
  403. dlm_lock_put(lock);
  404. spin_unlock(&dlm->ast_lock);
  405. if (lock->ml.node != dlm->node_num) {
  406. ret = dlm_do_remote_ast(dlm, res, lock);
  407. if (ret < 0)
  408. mlog_errno(ret);
  409. } else
  410. dlm_do_local_ast(dlm, res, lock);
  411. spin_lock(&dlm->ast_lock);
  412. /* possible that another ast was queued while
  413. * we were delivering the last one */
  414. if (!list_empty(&lock->ast_list)) {
  415. mlog(0, "aha another ast got queued while "
  416. "we were finishing the last one. will "
  417. "keep the ast_pending flag set.\n");
  418. } else
  419. lock->ast_pending = 0;
  420. /* drop the extra ref.
  421. * this may drop it completely. */
  422. dlm_lock_put(lock);
  423. dlm_lockres_release_ast(dlm, res);
  424. }
  425. while (!list_empty(&dlm->pending_basts)) {
  426. lock = list_entry(dlm->pending_basts.next,
  427. struct dlm_lock, bast_list);
  428. /* get an extra ref on lock */
  429. dlm_lock_get(lock);
  430. res = lock->lockres;
  431. BUG_ON(!lock->bast_pending);
  432. /* get the highest blocked lock, and reset */
  433. spin_lock(&lock->spinlock);
  434. BUG_ON(lock->ml.highest_blocked <= LKM_IVMODE);
  435. hi = lock->ml.highest_blocked;
  436. lock->ml.highest_blocked = LKM_IVMODE;
  437. spin_unlock(&lock->spinlock);
  438. /* remove from list (including ref) */
  439. list_del_init(&lock->bast_list);
  440. dlm_lock_put(lock);
  441. spin_unlock(&dlm->ast_lock);
  442. mlog(0, "delivering a bast for this lockres "
  443. "(blocked = %d\n", hi);
  444. if (lock->ml.node != dlm->node_num) {
  445. ret = dlm_send_proxy_bast(dlm, res, lock, hi);
  446. if (ret < 0)
  447. mlog_errno(ret);
  448. } else
  449. dlm_do_local_bast(dlm, res, lock, hi);
  450. spin_lock(&dlm->ast_lock);
  451. /* possible that another bast was queued while
  452. * we were delivering the last one */
  453. if (!list_empty(&lock->bast_list)) {
  454. mlog(0, "aha another bast got queued while "
  455. "we were finishing the last one. will "
  456. "keep the bast_pending flag set.\n");
  457. } else
  458. lock->bast_pending = 0;
  459. /* drop the extra ref.
  460. * this may drop it completely. */
  461. dlm_lock_put(lock);
  462. dlm_lockres_release_ast(dlm, res);
  463. }
  464. wake_up(&dlm->ast_wq);
  465. spin_unlock(&dlm->ast_lock);
  466. }
  467. #define DLM_THREAD_TIMEOUT_MS (4 * 1000)
  468. #define DLM_THREAD_MAX_DIRTY 100
  469. #define DLM_THREAD_MAX_ASTS 10
  470. static int dlm_thread(void *data)
  471. {
  472. struct dlm_lock_resource *res;
  473. struct dlm_ctxt *dlm = data;
  474. unsigned long timeout = msecs_to_jiffies(DLM_THREAD_TIMEOUT_MS);
  475. mlog(0, "dlm thread running for %s...\n", dlm->name);
  476. while (!kthread_should_stop()) {
  477. int n = DLM_THREAD_MAX_DIRTY;
  478. /* dlm_shutting_down is very point-in-time, but that
  479. * doesn't matter as we'll just loop back around if we
  480. * get false on the leading edge of a state
  481. * transition. */
  482. dlm_run_purge_list(dlm, dlm_shutting_down(dlm));
  483. /* We really don't want to hold dlm->spinlock while
  484. * calling dlm_shuffle_lists on each lockres that
  485. * needs to have its queues adjusted and AST/BASTs
  486. * run. So let's pull each entry off the dirty_list
  487. * and drop dlm->spinlock ASAP. Once off the list,
  488. * res->spinlock needs to be taken again to protect
  489. * the queues while calling dlm_shuffle_lists. */
  490. spin_lock(&dlm->spinlock);
  491. while (!list_empty(&dlm->dirty_list)) {
  492. int delay = 0;
  493. res = list_entry(dlm->dirty_list.next,
  494. struct dlm_lock_resource, dirty);
  495. /* peel a lockres off, remove it from the list,
  496. * unset the dirty flag and drop the dlm lock */
  497. BUG_ON(!res);
  498. dlm_lockres_get(res);
  499. spin_lock(&res->spinlock);
  500. res->state &= ~DLM_LOCK_RES_DIRTY;
  501. list_del_init(&res->dirty);
  502. spin_unlock(&res->spinlock);
  503. spin_unlock(&dlm->spinlock);
  504. /* lockres can be re-dirtied/re-added to the
  505. * dirty_list in this gap, but that is ok */
  506. spin_lock(&res->spinlock);
  507. if (res->owner != dlm->node_num) {
  508. __dlm_print_one_lock_resource(res);
  509. mlog(ML_ERROR, "inprog:%s, mig:%s, reco:%s, dirty:%s\n",
  510. res->state & DLM_LOCK_RES_IN_PROGRESS ? "yes" : "no",
  511. res->state & DLM_LOCK_RES_MIGRATING ? "yes" : "no",
  512. res->state & DLM_LOCK_RES_RECOVERING ? "yes" : "no",
  513. res->state & DLM_LOCK_RES_DIRTY ? "yes" : "no");
  514. }
  515. BUG_ON(res->owner != dlm->node_num);
  516. /* it is now ok to move lockreses in these states
  517. * to the dirty list, assuming that they will only be
  518. * dirty for a short while. */
  519. if (res->state & (DLM_LOCK_RES_IN_PROGRESS |
  520. DLM_LOCK_RES_MIGRATING |
  521. DLM_LOCK_RES_RECOVERING)) {
  522. /* move it to the tail and keep going */
  523. spin_unlock(&res->spinlock);
  524. mlog(0, "delaying list shuffling for in-"
  525. "progress lockres %.*s, state=%d\n",
  526. res->lockname.len, res->lockname.name,
  527. res->state);
  528. delay = 1;
  529. goto in_progress;
  530. }
  531. /* at this point the lockres is not migrating/
  532. * recovering/in-progress. we have the lockres
  533. * spinlock and do NOT have the dlm lock.
  534. * safe to reserve/queue asts and run the lists. */
  535. mlog(0, "calling dlm_shuffle_lists with dlm=%p, "
  536. "res=%p\n", dlm, res);
  537. /* called while holding lockres lock */
  538. dlm_shuffle_lists(dlm, res);
  539. spin_unlock(&res->spinlock);
  540. dlm_lockres_calc_usage(dlm, res);
  541. in_progress:
  542. spin_lock(&dlm->spinlock);
  543. /* if the lock was in-progress, stick
  544. * it on the back of the list */
  545. if (delay) {
  546. spin_lock(&res->spinlock);
  547. list_add_tail(&res->dirty, &dlm->dirty_list);
  548. res->state |= DLM_LOCK_RES_DIRTY;
  549. spin_unlock(&res->spinlock);
  550. }
  551. dlm_lockres_put(res);
  552. /* unlikely, but we may need to give time to
  553. * other tasks */
  554. if (!--n) {
  555. mlog(0, "throttling dlm_thread\n");
  556. break;
  557. }
  558. }
  559. spin_unlock(&dlm->spinlock);
  560. dlm_flush_asts(dlm);
  561. /* yield and continue right away if there is more work to do */
  562. if (!n) {
  563. yield();
  564. continue;
  565. }
  566. wait_event_interruptible_timeout(dlm->dlm_thread_wq,
  567. !dlm_dirty_list_empty(dlm) ||
  568. kthread_should_stop(),
  569. timeout);
  570. }
  571. mlog(0, "quitting DLM thread\n");
  572. return 0;
  573. }