lock.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  1. /*
  2. * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
  3. * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
  4. *
  5. * This copyrighted material is made available to anyone wishing to use,
  6. * modify, copy, or redistribute it subject to the terms and conditions
  7. * of the GNU General Public License version 2.
  8. */
  9. #include "lock_dlm.h"
  10. static char junk_lvb[GDLM_LVB_SIZE];
  11. /* convert dlm lock-mode to gfs lock-state */
  12. static s16 gdlm_make_lmstate(s16 dlmmode)
  13. {
  14. switch (dlmmode) {
  15. case DLM_LOCK_IV:
  16. case DLM_LOCK_NL:
  17. return LM_ST_UNLOCKED;
  18. case DLM_LOCK_EX:
  19. return LM_ST_EXCLUSIVE;
  20. case DLM_LOCK_CW:
  21. return LM_ST_DEFERRED;
  22. case DLM_LOCK_PR:
  23. return LM_ST_SHARED;
  24. }
  25. gdlm_assert(0, "unknown DLM mode %d", dlmmode);
  26. return -1;
  27. }
  28. /* A lock placed on this queue is re-submitted to DLM as soon as the lock_dlm
  29. thread gets to it. */
  30. static void queue_submit(struct gdlm_lock *lp)
  31. {
  32. struct gdlm_ls *ls = lp->ls;
  33. spin_lock(&ls->async_lock);
  34. list_add_tail(&lp->delay_list, &ls->submit);
  35. spin_unlock(&ls->async_lock);
  36. wake_up(&ls->thread_wait);
  37. }
  38. static void wake_up_ast(struct gdlm_lock *lp)
  39. {
  40. clear_bit(LFL_AST_WAIT, &lp->flags);
  41. smp_mb__after_clear_bit();
  42. wake_up_bit(&lp->flags, LFL_AST_WAIT);
  43. }
  44. static void gdlm_delete_lp(struct gdlm_lock *lp)
  45. {
  46. struct gdlm_ls *ls = lp->ls;
  47. spin_lock(&ls->async_lock);
  48. if (!list_empty(&lp->delay_list))
  49. list_del_init(&lp->delay_list);
  50. ls->all_locks_count--;
  51. spin_unlock(&ls->async_lock);
  52. kfree(lp);
  53. }
  54. static void gdlm_queue_delayed(struct gdlm_lock *lp)
  55. {
  56. struct gdlm_ls *ls = lp->ls;
  57. spin_lock(&ls->async_lock);
  58. list_add_tail(&lp->delay_list, &ls->delayed);
  59. spin_unlock(&ls->async_lock);
  60. }
  61. static void process_complete(struct gdlm_lock *lp)
  62. {
  63. struct gdlm_ls *ls = lp->ls;
  64. struct lm_async_cb acb;
  65. memset(&acb, 0, sizeof(acb));
  66. if (lp->lksb.sb_status == -DLM_ECANCEL) {
  67. log_info("complete dlm cancel %x,%llx flags %lx",
  68. lp->lockname.ln_type,
  69. (unsigned long long)lp->lockname.ln_number,
  70. lp->flags);
  71. lp->req = lp->cur;
  72. acb.lc_ret |= LM_OUT_CANCELED;
  73. if (lp->cur == DLM_LOCK_IV)
  74. lp->lksb.sb_lkid = 0;
  75. goto out;
  76. }
  77. if (test_and_clear_bit(LFL_DLM_UNLOCK, &lp->flags)) {
  78. if (lp->lksb.sb_status != -DLM_EUNLOCK) {
  79. log_info("unlock sb_status %d %x,%llx flags %lx",
  80. lp->lksb.sb_status, lp->lockname.ln_type,
  81. (unsigned long long)lp->lockname.ln_number,
  82. lp->flags);
  83. return;
  84. }
  85. lp->cur = DLM_LOCK_IV;
  86. lp->req = DLM_LOCK_IV;
  87. lp->lksb.sb_lkid = 0;
  88. if (test_and_clear_bit(LFL_UNLOCK_DELETE, &lp->flags)) {
  89. gdlm_delete_lp(lp);
  90. return;
  91. }
  92. goto out;
  93. }
  94. if (lp->lksb.sb_flags & DLM_SBF_VALNOTVALID)
  95. memset(lp->lksb.sb_lvbptr, 0, GDLM_LVB_SIZE);
  96. if (lp->lksb.sb_flags & DLM_SBF_ALTMODE) {
  97. if (lp->req == DLM_LOCK_PR)
  98. lp->req = DLM_LOCK_CW;
  99. else if (lp->req == DLM_LOCK_CW)
  100. lp->req = DLM_LOCK_PR;
  101. }
  102. /*
  103. * A canceled lock request. The lock was just taken off the delayed
  104. * list and was never even submitted to dlm.
  105. */
  106. if (test_and_clear_bit(LFL_CANCEL, &lp->flags)) {
  107. log_info("complete internal cancel %x,%llx",
  108. lp->lockname.ln_type,
  109. (unsigned long long)lp->lockname.ln_number);
  110. lp->req = lp->cur;
  111. acb.lc_ret |= LM_OUT_CANCELED;
  112. goto out;
  113. }
  114. /*
  115. * An error occured.
  116. */
  117. if (lp->lksb.sb_status) {
  118. /* a "normal" error */
  119. if ((lp->lksb.sb_status == -EAGAIN) &&
  120. (lp->lkf & DLM_LKF_NOQUEUE)) {
  121. lp->req = lp->cur;
  122. if (lp->cur == DLM_LOCK_IV)
  123. lp->lksb.sb_lkid = 0;
  124. goto out;
  125. }
  126. /* this could only happen with cancels I think */
  127. log_info("ast sb_status %d %x,%llx flags %lx",
  128. lp->lksb.sb_status, lp->lockname.ln_type,
  129. (unsigned long long)lp->lockname.ln_number,
  130. lp->flags);
  131. return;
  132. }
  133. /*
  134. * This is an AST for an EX->EX conversion for sync_lvb from GFS.
  135. */
  136. if (test_and_clear_bit(LFL_SYNC_LVB, &lp->flags)) {
  137. wake_up_ast(lp);
  138. return;
  139. }
  140. /*
  141. * A lock has been demoted to NL because it initially completed during
  142. * BLOCK_LOCKS. Now it must be requested in the originally requested
  143. * mode.
  144. */
  145. if (test_and_clear_bit(LFL_REREQUEST, &lp->flags)) {
  146. gdlm_assert(lp->req == DLM_LOCK_NL, "%x,%llx",
  147. lp->lockname.ln_type,
  148. (unsigned long long)lp->lockname.ln_number);
  149. gdlm_assert(lp->prev_req > DLM_LOCK_NL, "%x,%llx",
  150. lp->lockname.ln_type,
  151. (unsigned long long)lp->lockname.ln_number);
  152. lp->cur = DLM_LOCK_NL;
  153. lp->req = lp->prev_req;
  154. lp->prev_req = DLM_LOCK_IV;
  155. lp->lkf &= ~DLM_LKF_CONVDEADLK;
  156. set_bit(LFL_NOCACHE, &lp->flags);
  157. if (test_bit(DFL_BLOCK_LOCKS, &ls->flags) &&
  158. !test_bit(LFL_NOBLOCK, &lp->flags))
  159. gdlm_queue_delayed(lp);
  160. else
  161. queue_submit(lp);
  162. return;
  163. }
  164. /*
  165. * A request is granted during dlm recovery. It may be granted
  166. * because the locks of a failed node were cleared. In that case,
  167. * there may be inconsistent data beneath this lock and we must wait
  168. * for recovery to complete to use it. When gfs recovery is done this
  169. * granted lock will be converted to NL and then reacquired in this
  170. * granted state.
  171. */
  172. if (test_bit(DFL_BLOCK_LOCKS, &ls->flags) &&
  173. !test_bit(LFL_NOBLOCK, &lp->flags) &&
  174. lp->req != DLM_LOCK_NL) {
  175. lp->cur = lp->req;
  176. lp->prev_req = lp->req;
  177. lp->req = DLM_LOCK_NL;
  178. lp->lkf |= DLM_LKF_CONVERT;
  179. lp->lkf &= ~DLM_LKF_CONVDEADLK;
  180. log_debug("rereq %x,%llx id %x %d,%d",
  181. lp->lockname.ln_type,
  182. (unsigned long long)lp->lockname.ln_number,
  183. lp->lksb.sb_lkid, lp->cur, lp->req);
  184. set_bit(LFL_REREQUEST, &lp->flags);
  185. queue_submit(lp);
  186. return;
  187. }
  188. /*
  189. * DLM demoted the lock to NL before it was granted so GFS must be
  190. * told it cannot cache data for this lock.
  191. */
  192. if (lp->lksb.sb_flags & DLM_SBF_DEMOTED)
  193. set_bit(LFL_NOCACHE, &lp->flags);
  194. out:
  195. /*
  196. * This is an internal lock_dlm lock
  197. */
  198. if (test_bit(LFL_INLOCK, &lp->flags)) {
  199. clear_bit(LFL_NOBLOCK, &lp->flags);
  200. lp->cur = lp->req;
  201. wake_up_ast(lp);
  202. return;
  203. }
  204. /*
  205. * Normal completion of a lock request. Tell GFS it now has the lock.
  206. */
  207. clear_bit(LFL_NOBLOCK, &lp->flags);
  208. lp->cur = lp->req;
  209. acb.lc_name = lp->lockname;
  210. acb.lc_ret |= gdlm_make_lmstate(lp->cur);
  211. ls->fscb(ls->sdp, LM_CB_ASYNC, &acb);
  212. }
  213. static void gdlm_ast(void *astarg)
  214. {
  215. struct gdlm_lock *lp = astarg;
  216. clear_bit(LFL_ACTIVE, &lp->flags);
  217. process_complete(lp);
  218. }
  219. static void process_blocking(struct gdlm_lock *lp, int bast_mode)
  220. {
  221. struct gdlm_ls *ls = lp->ls;
  222. unsigned int cb = 0;
  223. switch (gdlm_make_lmstate(bast_mode)) {
  224. case LM_ST_EXCLUSIVE:
  225. cb = LM_CB_NEED_E;
  226. break;
  227. case LM_ST_DEFERRED:
  228. cb = LM_CB_NEED_D;
  229. break;
  230. case LM_ST_SHARED:
  231. cb = LM_CB_NEED_S;
  232. break;
  233. default:
  234. gdlm_assert(0, "unknown bast mode %u", bast_mode);
  235. }
  236. ls->fscb(ls->sdp, cb, &lp->lockname);
  237. }
  238. static void gdlm_bast(void *astarg, int mode)
  239. {
  240. struct gdlm_lock *lp = astarg;
  241. if (!mode) {
  242. printk(KERN_INFO "lock_dlm: bast mode zero %x,%llx\n",
  243. lp->lockname.ln_type,
  244. (unsigned long long)lp->lockname.ln_number);
  245. return;
  246. }
  247. process_blocking(lp, mode);
  248. }
  249. /* convert gfs lock-state to dlm lock-mode */
  250. static s16 make_mode(s16 lmstate)
  251. {
  252. switch (lmstate) {
  253. case LM_ST_UNLOCKED:
  254. return DLM_LOCK_NL;
  255. case LM_ST_EXCLUSIVE:
  256. return DLM_LOCK_EX;
  257. case LM_ST_DEFERRED:
  258. return DLM_LOCK_CW;
  259. case LM_ST_SHARED:
  260. return DLM_LOCK_PR;
  261. }
  262. gdlm_assert(0, "unknown LM state %d", lmstate);
  263. return -1;
  264. }
  265. /* verify agreement with GFS on the current lock state, NB: DLM_LOCK_NL and
  266. DLM_LOCK_IV are both considered LM_ST_UNLOCKED by GFS. */
  267. static void check_cur_state(struct gdlm_lock *lp, unsigned int cur_state)
  268. {
  269. s16 cur = make_mode(cur_state);
  270. if (lp->cur != DLM_LOCK_IV)
  271. gdlm_assert(lp->cur == cur, "%d, %d", lp->cur, cur);
  272. }
  273. static inline unsigned int make_flags(struct gdlm_lock *lp,
  274. unsigned int gfs_flags,
  275. s16 cur, s16 req)
  276. {
  277. unsigned int lkf = 0;
  278. if (gfs_flags & LM_FLAG_TRY)
  279. lkf |= DLM_LKF_NOQUEUE;
  280. if (gfs_flags & LM_FLAG_TRY_1CB) {
  281. lkf |= DLM_LKF_NOQUEUE;
  282. lkf |= DLM_LKF_NOQUEUEBAST;
  283. }
  284. if (gfs_flags & LM_FLAG_PRIORITY) {
  285. lkf |= DLM_LKF_NOORDER;
  286. lkf |= DLM_LKF_HEADQUE;
  287. }
  288. if (gfs_flags & LM_FLAG_ANY) {
  289. if (req == DLM_LOCK_PR)
  290. lkf |= DLM_LKF_ALTCW;
  291. else if (req == DLM_LOCK_CW)
  292. lkf |= DLM_LKF_ALTPR;
  293. }
  294. if (lp->lksb.sb_lkid != 0) {
  295. lkf |= DLM_LKF_CONVERT;
  296. }
  297. if (lp->lvb)
  298. lkf |= DLM_LKF_VALBLK;
  299. return lkf;
  300. }
  301. /* make_strname - convert GFS lock numbers to a string */
  302. static inline void make_strname(const struct lm_lockname *lockname,
  303. struct gdlm_strname *str)
  304. {
  305. sprintf(str->name, "%8x%16llx", lockname->ln_type,
  306. (unsigned long long)lockname->ln_number);
  307. str->namelen = GDLM_STRNAME_BYTES;
  308. }
  309. static int gdlm_create_lp(struct gdlm_ls *ls, struct lm_lockname *name,
  310. struct gdlm_lock **lpp)
  311. {
  312. struct gdlm_lock *lp;
  313. lp = kzalloc(sizeof(struct gdlm_lock), GFP_NOFS);
  314. if (!lp)
  315. return -ENOMEM;
  316. lp->lockname = *name;
  317. make_strname(name, &lp->strname);
  318. lp->ls = ls;
  319. lp->cur = DLM_LOCK_IV;
  320. INIT_LIST_HEAD(&lp->delay_list);
  321. spin_lock(&ls->async_lock);
  322. ls->all_locks_count++;
  323. spin_unlock(&ls->async_lock);
  324. *lpp = lp;
  325. return 0;
  326. }
  327. int gdlm_get_lock(void *lockspace, struct lm_lockname *name,
  328. void **lockp)
  329. {
  330. struct gdlm_lock *lp;
  331. int error;
  332. error = gdlm_create_lp(lockspace, name, &lp);
  333. *lockp = lp;
  334. return error;
  335. }
  336. void gdlm_put_lock(void *lock)
  337. {
  338. gdlm_delete_lp(lock);
  339. }
  340. unsigned int gdlm_do_lock(struct gdlm_lock *lp)
  341. {
  342. struct gdlm_ls *ls = lp->ls;
  343. int error, bast = 1;
  344. /*
  345. * When recovery is in progress, delay lock requests for submission
  346. * once recovery is done. Requests for recovery (NOEXP) and unlocks
  347. * can pass.
  348. */
  349. if (test_bit(DFL_BLOCK_LOCKS, &ls->flags) &&
  350. !test_bit(LFL_NOBLOCK, &lp->flags) && lp->req != DLM_LOCK_NL) {
  351. gdlm_queue_delayed(lp);
  352. return LM_OUT_ASYNC;
  353. }
  354. /*
  355. * Submit the actual lock request.
  356. */
  357. if (test_bit(LFL_NOBAST, &lp->flags))
  358. bast = 0;
  359. set_bit(LFL_ACTIVE, &lp->flags);
  360. log_debug("lk %x,%llx id %x %d,%d %x", lp->lockname.ln_type,
  361. (unsigned long long)lp->lockname.ln_number, lp->lksb.sb_lkid,
  362. lp->cur, lp->req, lp->lkf);
  363. error = dlm_lock(ls->dlm_lockspace, lp->req, &lp->lksb, lp->lkf,
  364. lp->strname.name, lp->strname.namelen, 0, gdlm_ast,
  365. lp, bast ? gdlm_bast : NULL);
  366. if ((error == -EAGAIN) && (lp->lkf & DLM_LKF_NOQUEUE)) {
  367. lp->lksb.sb_status = -EAGAIN;
  368. gdlm_ast(lp);
  369. error = 0;
  370. }
  371. if (error) {
  372. log_error("%s: gdlm_lock %x,%llx err=%d cur=%d req=%d lkf=%x "
  373. "flags=%lx", ls->fsname, lp->lockname.ln_type,
  374. (unsigned long long)lp->lockname.ln_number, error,
  375. lp->cur, lp->req, lp->lkf, lp->flags);
  376. return LM_OUT_ERROR;
  377. }
  378. return LM_OUT_ASYNC;
  379. }
  380. static unsigned int gdlm_do_unlock(struct gdlm_lock *lp)
  381. {
  382. struct gdlm_ls *ls = lp->ls;
  383. unsigned int lkf = 0;
  384. int error;
  385. set_bit(LFL_DLM_UNLOCK, &lp->flags);
  386. set_bit(LFL_ACTIVE, &lp->flags);
  387. if (lp->lvb)
  388. lkf = DLM_LKF_VALBLK;
  389. log_debug("un %x,%llx %x %d %x", lp->lockname.ln_type,
  390. (unsigned long long)lp->lockname.ln_number,
  391. lp->lksb.sb_lkid, lp->cur, lkf);
  392. error = dlm_unlock(ls->dlm_lockspace, lp->lksb.sb_lkid, lkf, NULL, lp);
  393. if (error) {
  394. log_error("%s: gdlm_unlock %x,%llx err=%d cur=%d req=%d lkf=%x "
  395. "flags=%lx", ls->fsname, lp->lockname.ln_type,
  396. (unsigned long long)lp->lockname.ln_number, error,
  397. lp->cur, lp->req, lp->lkf, lp->flags);
  398. return LM_OUT_ERROR;
  399. }
  400. return LM_OUT_ASYNC;
  401. }
  402. unsigned int gdlm_lock(void *lock, unsigned int cur_state,
  403. unsigned int req_state, unsigned int flags)
  404. {
  405. struct gdlm_lock *lp = lock;
  406. if (req_state == LM_ST_UNLOCKED)
  407. return gdlm_unlock(lock, cur_state);
  408. if (req_state == LM_ST_UNLOCKED)
  409. return gdlm_unlock(lock, cur_state);
  410. clear_bit(LFL_DLM_CANCEL, &lp->flags);
  411. if (flags & LM_FLAG_NOEXP)
  412. set_bit(LFL_NOBLOCK, &lp->flags);
  413. check_cur_state(lp, cur_state);
  414. lp->req = make_mode(req_state);
  415. lp->lkf = make_flags(lp, flags, lp->cur, lp->req);
  416. return gdlm_do_lock(lp);
  417. }
  418. unsigned int gdlm_unlock(void *lock, unsigned int cur_state)
  419. {
  420. struct gdlm_lock *lp = lock;
  421. clear_bit(LFL_DLM_CANCEL, &lp->flags);
  422. if (lp->cur == DLM_LOCK_IV)
  423. return 0;
  424. return gdlm_do_unlock(lp);
  425. }
  426. void gdlm_cancel(void *lock)
  427. {
  428. struct gdlm_lock *lp = lock;
  429. struct gdlm_ls *ls = lp->ls;
  430. int error, delay_list = 0;
  431. if (test_bit(LFL_DLM_CANCEL, &lp->flags))
  432. return;
  433. log_info("gdlm_cancel %x,%llx flags %lx", lp->lockname.ln_type,
  434. (unsigned long long)lp->lockname.ln_number, lp->flags);
  435. spin_lock(&ls->async_lock);
  436. if (!list_empty(&lp->delay_list)) {
  437. list_del_init(&lp->delay_list);
  438. delay_list = 1;
  439. }
  440. spin_unlock(&ls->async_lock);
  441. if (delay_list) {
  442. set_bit(LFL_CANCEL, &lp->flags);
  443. set_bit(LFL_ACTIVE, &lp->flags);
  444. gdlm_ast(lp);
  445. return;
  446. }
  447. if (!test_bit(LFL_ACTIVE, &lp->flags) ||
  448. test_bit(LFL_DLM_UNLOCK, &lp->flags)) {
  449. log_info("gdlm_cancel skip %x,%llx flags %lx",
  450. lp->lockname.ln_type,
  451. (unsigned long long)lp->lockname.ln_number, lp->flags);
  452. return;
  453. }
  454. /* the lock is blocked in the dlm */
  455. set_bit(LFL_DLM_CANCEL, &lp->flags);
  456. set_bit(LFL_ACTIVE, &lp->flags);
  457. error = dlm_unlock(ls->dlm_lockspace, lp->lksb.sb_lkid, DLM_LKF_CANCEL,
  458. NULL, lp);
  459. log_info("gdlm_cancel rv %d %x,%llx flags %lx", error,
  460. lp->lockname.ln_type,
  461. (unsigned long long)lp->lockname.ln_number, lp->flags);
  462. if (error == -EBUSY)
  463. clear_bit(LFL_DLM_CANCEL, &lp->flags);
  464. }
  465. static int gdlm_add_lvb(struct gdlm_lock *lp)
  466. {
  467. char *lvb;
  468. lvb = kzalloc(GDLM_LVB_SIZE, GFP_NOFS);
  469. if (!lvb)
  470. return -ENOMEM;
  471. lp->lksb.sb_lvbptr = lvb;
  472. lp->lvb = lvb;
  473. return 0;
  474. }
  475. static void gdlm_del_lvb(struct gdlm_lock *lp)
  476. {
  477. kfree(lp->lvb);
  478. lp->lvb = NULL;
  479. lp->lksb.sb_lvbptr = NULL;
  480. }
  481. static int gdlm_ast_wait(void *word)
  482. {
  483. schedule();
  484. return 0;
  485. }
  486. /* This can do a synchronous dlm request (requiring a lock_dlm thread to get
  487. the completion) because gfs won't call hold_lvb() during a callback (from
  488. the context of a lock_dlm thread). */
  489. static int hold_null_lock(struct gdlm_lock *lp)
  490. {
  491. struct gdlm_lock *lpn = NULL;
  492. int error;
  493. if (lp->hold_null) {
  494. printk(KERN_INFO "lock_dlm: lvb already held\n");
  495. return 0;
  496. }
  497. error = gdlm_create_lp(lp->ls, &lp->lockname, &lpn);
  498. if (error)
  499. goto out;
  500. lpn->lksb.sb_lvbptr = junk_lvb;
  501. lpn->lvb = junk_lvb;
  502. lpn->req = DLM_LOCK_NL;
  503. lpn->lkf = DLM_LKF_VALBLK | DLM_LKF_EXPEDITE;
  504. set_bit(LFL_NOBAST, &lpn->flags);
  505. set_bit(LFL_INLOCK, &lpn->flags);
  506. set_bit(LFL_AST_WAIT, &lpn->flags);
  507. gdlm_do_lock(lpn);
  508. wait_on_bit(&lpn->flags, LFL_AST_WAIT, gdlm_ast_wait, TASK_UNINTERRUPTIBLE);
  509. error = lpn->lksb.sb_status;
  510. if (error) {
  511. printk(KERN_INFO "lock_dlm: hold_null_lock dlm error %d\n",
  512. error);
  513. gdlm_delete_lp(lpn);
  514. lpn = NULL;
  515. }
  516. out:
  517. lp->hold_null = lpn;
  518. return error;
  519. }
  520. /* This cannot do a synchronous dlm request (requiring a lock_dlm thread to get
  521. the completion) because gfs may call unhold_lvb() during a callback (from
  522. the context of a lock_dlm thread) which could cause a deadlock since the
  523. other lock_dlm thread could be engaged in recovery. */
  524. static void unhold_null_lock(struct gdlm_lock *lp)
  525. {
  526. struct gdlm_lock *lpn = lp->hold_null;
  527. gdlm_assert(lpn, "%x,%llx", lp->lockname.ln_type,
  528. (unsigned long long)lp->lockname.ln_number);
  529. lpn->lksb.sb_lvbptr = NULL;
  530. lpn->lvb = NULL;
  531. set_bit(LFL_UNLOCK_DELETE, &lpn->flags);
  532. gdlm_do_unlock(lpn);
  533. lp->hold_null = NULL;
  534. }
  535. /* Acquire a NL lock because gfs requires the value block to remain
  536. intact on the resource while the lvb is "held" even if it's holding no locks
  537. on the resource. */
  538. int gdlm_hold_lvb(void *lock, char **lvbp)
  539. {
  540. struct gdlm_lock *lp = lock;
  541. int error;
  542. error = gdlm_add_lvb(lp);
  543. if (error)
  544. return error;
  545. *lvbp = lp->lvb;
  546. error = hold_null_lock(lp);
  547. if (error)
  548. gdlm_del_lvb(lp);
  549. return error;
  550. }
  551. void gdlm_unhold_lvb(void *lock, char *lvb)
  552. {
  553. struct gdlm_lock *lp = lock;
  554. unhold_null_lock(lp);
  555. gdlm_del_lvb(lp);
  556. }
  557. void gdlm_submit_delayed(struct gdlm_ls *ls)
  558. {
  559. struct gdlm_lock *lp, *safe;
  560. spin_lock(&ls->async_lock);
  561. list_for_each_entry_safe(lp, safe, &ls->delayed, delay_list) {
  562. list_del_init(&lp->delay_list);
  563. list_add_tail(&lp->delay_list, &ls->submit);
  564. }
  565. spin_unlock(&ls->async_lock);
  566. wake_up(&ls->thread_wait);
  567. }