dlmthread.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  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_del_init(&target->list);
  270. list_add_tail(&target->list, &res->granted);
  271. BUG_ON(!target->lksb);
  272. target->lksb->status = DLM_NORMAL;
  273. spin_unlock(&target->spinlock);
  274. __dlm_lockres_reserve_ast(res);
  275. dlm_queue_ast(dlm, target);
  276. /* go back and check for more */
  277. goto converting;
  278. }
  279. blocked:
  280. if (list_empty(&res->blocked))
  281. goto leave;
  282. target = list_entry(res->blocked.next, struct dlm_lock, list);
  283. head = &res->granted;
  284. list_for_each(iter, head) {
  285. lock = list_entry(iter, struct dlm_lock, list);
  286. if (lock==target)
  287. continue;
  288. if (!dlm_lock_compatible(lock->ml.type, target->ml.type)) {
  289. can_grant = 0;
  290. if (lock->ml.highest_blocked == LKM_IVMODE) {
  291. __dlm_lockres_reserve_ast(res);
  292. dlm_queue_bast(dlm, lock);
  293. }
  294. if (lock->ml.highest_blocked < target->ml.type)
  295. lock->ml.highest_blocked = target->ml.type;
  296. }
  297. }
  298. head = &res->converting;
  299. list_for_each(iter, head) {
  300. lock = list_entry(iter, struct dlm_lock, list);
  301. if (lock==target)
  302. continue;
  303. if (!dlm_lock_compatible(lock->ml.type, target->ml.type)) {
  304. can_grant = 0;
  305. if (lock->ml.highest_blocked == LKM_IVMODE) {
  306. __dlm_lockres_reserve_ast(res);
  307. dlm_queue_bast(dlm, lock);
  308. }
  309. if (lock->ml.highest_blocked < target->ml.type)
  310. lock->ml.highest_blocked = target->ml.type;
  311. }
  312. }
  313. /* we can grant the blocked lock (only
  314. * possible if converting list empty) */
  315. if (can_grant) {
  316. spin_lock(&target->spinlock);
  317. BUG_ON(target->ml.highest_blocked != LKM_IVMODE);
  318. mlog(0, "calling ast for blocked lock: %.*s, granting: %d, "
  319. "node: %u\n", res->lockname.len, res->lockname.name,
  320. target->ml.type, target->ml.node);
  321. // target->ml.type is already correct
  322. list_del_init(&target->list);
  323. list_add_tail(&target->list, &res->granted);
  324. BUG_ON(!target->lksb);
  325. target->lksb->status = DLM_NORMAL;
  326. spin_unlock(&target->spinlock);
  327. __dlm_lockres_reserve_ast(res);
  328. dlm_queue_ast(dlm, target);
  329. /* go back and check for more */
  330. goto converting;
  331. }
  332. leave:
  333. return;
  334. }
  335. /* must have NO locks when calling this with res !=NULL * */
  336. void dlm_kick_thread(struct dlm_ctxt *dlm, struct dlm_lock_resource *res)
  337. {
  338. mlog_entry("dlm=%p, res=%p\n", dlm, res);
  339. if (res) {
  340. spin_lock(&dlm->spinlock);
  341. spin_lock(&res->spinlock);
  342. __dlm_dirty_lockres(dlm, res);
  343. spin_unlock(&res->spinlock);
  344. spin_unlock(&dlm->spinlock);
  345. }
  346. wake_up(&dlm->dlm_thread_wq);
  347. }
  348. void __dlm_dirty_lockres(struct dlm_ctxt *dlm, struct dlm_lock_resource *res)
  349. {
  350. mlog_entry("dlm=%p, res=%p\n", dlm, res);
  351. assert_spin_locked(&dlm->spinlock);
  352. assert_spin_locked(&res->spinlock);
  353. /* don't shuffle secondary queues */
  354. if ((res->owner == dlm->node_num) &&
  355. !(res->state & DLM_LOCK_RES_DIRTY)) {
  356. list_add_tail(&res->dirty, &dlm->dirty_list);
  357. res->state |= DLM_LOCK_RES_DIRTY;
  358. }
  359. }
  360. /* Launch the NM thread for the mounted volume */
  361. int dlm_launch_thread(struct dlm_ctxt *dlm)
  362. {
  363. mlog(0, "starting dlm thread...\n");
  364. dlm->dlm_thread_task = kthread_run(dlm_thread, dlm, "dlm_thread");
  365. if (IS_ERR(dlm->dlm_thread_task)) {
  366. mlog_errno(PTR_ERR(dlm->dlm_thread_task));
  367. dlm->dlm_thread_task = NULL;
  368. return -EINVAL;
  369. }
  370. return 0;
  371. }
  372. void dlm_complete_thread(struct dlm_ctxt *dlm)
  373. {
  374. if (dlm->dlm_thread_task) {
  375. mlog(ML_KTHREAD, "waiting for dlm thread to exit\n");
  376. kthread_stop(dlm->dlm_thread_task);
  377. dlm->dlm_thread_task = NULL;
  378. }
  379. }
  380. static int dlm_dirty_list_empty(struct dlm_ctxt *dlm)
  381. {
  382. int empty;
  383. spin_lock(&dlm->spinlock);
  384. empty = list_empty(&dlm->dirty_list);
  385. spin_unlock(&dlm->spinlock);
  386. return empty;
  387. }
  388. static void dlm_flush_asts(struct dlm_ctxt *dlm)
  389. {
  390. int ret;
  391. struct dlm_lock *lock;
  392. struct dlm_lock_resource *res;
  393. u8 hi;
  394. spin_lock(&dlm->ast_lock);
  395. while (!list_empty(&dlm->pending_asts)) {
  396. lock = list_entry(dlm->pending_asts.next,
  397. struct dlm_lock, ast_list);
  398. /* get an extra ref on lock */
  399. dlm_lock_get(lock);
  400. res = lock->lockres;
  401. mlog(0, "delivering an ast for this lockres\n");
  402. BUG_ON(!lock->ast_pending);
  403. /* remove from list (including ref) */
  404. list_del_init(&lock->ast_list);
  405. dlm_lock_put(lock);
  406. spin_unlock(&dlm->ast_lock);
  407. if (lock->ml.node != dlm->node_num) {
  408. ret = dlm_do_remote_ast(dlm, res, lock);
  409. if (ret < 0)
  410. mlog_errno(ret);
  411. } else
  412. dlm_do_local_ast(dlm, res, lock);
  413. spin_lock(&dlm->ast_lock);
  414. /* possible that another ast was queued while
  415. * we were delivering the last one */
  416. if (!list_empty(&lock->ast_list)) {
  417. mlog(0, "aha another ast got queued while "
  418. "we were finishing the last one. will "
  419. "keep the ast_pending flag set.\n");
  420. } else
  421. lock->ast_pending = 0;
  422. /* drop the extra ref.
  423. * this may drop it completely. */
  424. dlm_lock_put(lock);
  425. dlm_lockres_release_ast(dlm, res);
  426. }
  427. while (!list_empty(&dlm->pending_basts)) {
  428. lock = list_entry(dlm->pending_basts.next,
  429. struct dlm_lock, bast_list);
  430. /* get an extra ref on lock */
  431. dlm_lock_get(lock);
  432. res = lock->lockres;
  433. BUG_ON(!lock->bast_pending);
  434. /* get the highest blocked lock, and reset */
  435. spin_lock(&lock->spinlock);
  436. BUG_ON(lock->ml.highest_blocked <= LKM_IVMODE);
  437. hi = lock->ml.highest_blocked;
  438. lock->ml.highest_blocked = LKM_IVMODE;
  439. spin_unlock(&lock->spinlock);
  440. /* remove from list (including ref) */
  441. list_del_init(&lock->bast_list);
  442. dlm_lock_put(lock);
  443. spin_unlock(&dlm->ast_lock);
  444. mlog(0, "delivering a bast for this lockres "
  445. "(blocked = %d\n", hi);
  446. if (lock->ml.node != dlm->node_num) {
  447. ret = dlm_send_proxy_bast(dlm, res, lock, hi);
  448. if (ret < 0)
  449. mlog_errno(ret);
  450. } else
  451. dlm_do_local_bast(dlm, res, lock, hi);
  452. spin_lock(&dlm->ast_lock);
  453. /* possible that another bast was queued while
  454. * we were delivering the last one */
  455. if (!list_empty(&lock->bast_list)) {
  456. mlog(0, "aha another bast got queued while "
  457. "we were finishing the last one. will "
  458. "keep the bast_pending flag set.\n");
  459. } else
  460. lock->bast_pending = 0;
  461. /* drop the extra ref.
  462. * this may drop it completely. */
  463. dlm_lock_put(lock);
  464. dlm_lockres_release_ast(dlm, res);
  465. }
  466. wake_up(&dlm->ast_wq);
  467. spin_unlock(&dlm->ast_lock);
  468. }
  469. #define DLM_THREAD_TIMEOUT_MS (4 * 1000)
  470. #define DLM_THREAD_MAX_DIRTY 100
  471. #define DLM_THREAD_MAX_ASTS 10
  472. static int dlm_thread(void *data)
  473. {
  474. struct dlm_lock_resource *res;
  475. struct dlm_ctxt *dlm = data;
  476. unsigned long timeout = msecs_to_jiffies(DLM_THREAD_TIMEOUT_MS);
  477. mlog(0, "dlm thread running for %s...\n", dlm->name);
  478. while (!kthread_should_stop()) {
  479. int n = DLM_THREAD_MAX_DIRTY;
  480. /* dlm_shutting_down is very point-in-time, but that
  481. * doesn't matter as we'll just loop back around if we
  482. * get false on the leading edge of a state
  483. * transition. */
  484. dlm_run_purge_list(dlm, dlm_shutting_down(dlm));
  485. /* We really don't want to hold dlm->spinlock while
  486. * calling dlm_shuffle_lists on each lockres that
  487. * needs to have its queues adjusted and AST/BASTs
  488. * run. So let's pull each entry off the dirty_list
  489. * and drop dlm->spinlock ASAP. Once off the list,
  490. * res->spinlock needs to be taken again to protect
  491. * the queues while calling dlm_shuffle_lists. */
  492. spin_lock(&dlm->spinlock);
  493. while (!list_empty(&dlm->dirty_list)) {
  494. int delay = 0;
  495. res = list_entry(dlm->dirty_list.next,
  496. struct dlm_lock_resource, dirty);
  497. /* peel a lockres off, remove it from the list,
  498. * unset the dirty flag and drop the dlm lock */
  499. BUG_ON(!res);
  500. dlm_lockres_get(res);
  501. spin_lock(&res->spinlock);
  502. res->state &= ~DLM_LOCK_RES_DIRTY;
  503. list_del_init(&res->dirty);
  504. spin_unlock(&res->spinlock);
  505. spin_unlock(&dlm->spinlock);
  506. /* lockres can be re-dirtied/re-added to the
  507. * dirty_list in this gap, but that is ok */
  508. spin_lock(&res->spinlock);
  509. if (res->owner != dlm->node_num) {
  510. __dlm_print_one_lock_resource(res);
  511. mlog(ML_ERROR, "inprog:%s, mig:%s, reco:%s, dirty:%s\n",
  512. res->state & DLM_LOCK_RES_IN_PROGRESS ? "yes" : "no",
  513. res->state & DLM_LOCK_RES_MIGRATING ? "yes" : "no",
  514. res->state & DLM_LOCK_RES_RECOVERING ? "yes" : "no",
  515. res->state & DLM_LOCK_RES_DIRTY ? "yes" : "no");
  516. }
  517. BUG_ON(res->owner != dlm->node_num);
  518. /* it is now ok to move lockreses in these states
  519. * to the dirty list, assuming that they will only be
  520. * dirty for a short while. */
  521. if (res->state & (DLM_LOCK_RES_IN_PROGRESS |
  522. DLM_LOCK_RES_MIGRATING |
  523. DLM_LOCK_RES_RECOVERING)) {
  524. /* move it to the tail and keep going */
  525. spin_unlock(&res->spinlock);
  526. mlog(0, "delaying list shuffling for in-"
  527. "progress lockres %.*s, state=%d\n",
  528. res->lockname.len, res->lockname.name,
  529. res->state);
  530. delay = 1;
  531. goto in_progress;
  532. }
  533. /* at this point the lockres is not migrating/
  534. * recovering/in-progress. we have the lockres
  535. * spinlock and do NOT have the dlm lock.
  536. * safe to reserve/queue asts and run the lists. */
  537. mlog(0, "calling dlm_shuffle_lists with dlm=%p, "
  538. "res=%p\n", dlm, res);
  539. /* called while holding lockres lock */
  540. dlm_shuffle_lists(dlm, res);
  541. spin_unlock(&res->spinlock);
  542. dlm_lockres_calc_usage(dlm, res);
  543. in_progress:
  544. spin_lock(&dlm->spinlock);
  545. /* if the lock was in-progress, stick
  546. * it on the back of the list */
  547. if (delay) {
  548. spin_lock(&res->spinlock);
  549. list_add_tail(&res->dirty, &dlm->dirty_list);
  550. res->state |= DLM_LOCK_RES_DIRTY;
  551. spin_unlock(&res->spinlock);
  552. }
  553. dlm_lockres_put(res);
  554. /* unlikely, but we may need to give time to
  555. * other tasks */
  556. if (!--n) {
  557. mlog(0, "throttling dlm_thread\n");
  558. break;
  559. }
  560. }
  561. spin_unlock(&dlm->spinlock);
  562. dlm_flush_asts(dlm);
  563. /* yield and continue right away if there is more work to do */
  564. if (!n) {
  565. yield();
  566. continue;
  567. }
  568. wait_event_interruptible_timeout(dlm->dlm_thread_wq,
  569. !dlm_dirty_list_empty(dlm) ||
  570. kthread_should_stop(),
  571. timeout);
  572. }
  573. mlog(0, "quitting DLM thread\n");
  574. return 0;
  575. }