dlmlock.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. /* -*- mode: c; c-basic-offset: 8; -*-
  2. * vim: noexpandtab sw=8 ts=8 sts=0:
  3. *
  4. * dlmlock.c
  5. *
  6. * underlying calls for lock creation
  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/spinlock.h>
  39. #include <linux/delay.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 "dlmconvert.h"
  46. #define MLOG_MASK_PREFIX ML_DLM
  47. #include "cluster/masklog.h"
  48. static spinlock_t dlm_cookie_lock = SPIN_LOCK_UNLOCKED;
  49. static u64 dlm_next_cookie = 1;
  50. static enum dlm_status dlm_send_remote_lock_request(struct dlm_ctxt *dlm,
  51. struct dlm_lock_resource *res,
  52. struct dlm_lock *lock, int flags);
  53. static void dlm_init_lock(struct dlm_lock *newlock, int type,
  54. u8 node, u64 cookie);
  55. static void dlm_lock_release(struct kref *kref);
  56. static void dlm_lock_detach_lockres(struct dlm_lock *lock);
  57. /* Tell us whether we can grant a new lock request.
  58. * locking:
  59. * caller needs: res->spinlock
  60. * taken: none
  61. * held on exit: none
  62. * returns: 1 if the lock can be granted, 0 otherwise.
  63. */
  64. static int dlm_can_grant_new_lock(struct dlm_lock_resource *res,
  65. struct dlm_lock *lock)
  66. {
  67. struct list_head *iter;
  68. struct dlm_lock *tmplock;
  69. list_for_each(iter, &res->granted) {
  70. tmplock = list_entry(iter, struct dlm_lock, list);
  71. if (!dlm_lock_compatible(tmplock->ml.type, lock->ml.type))
  72. return 0;
  73. }
  74. list_for_each(iter, &res->converting) {
  75. tmplock = list_entry(iter, struct dlm_lock, list);
  76. if (!dlm_lock_compatible(tmplock->ml.type, lock->ml.type))
  77. return 0;
  78. }
  79. return 1;
  80. }
  81. /* performs lock creation at the lockres master site
  82. * locking:
  83. * caller needs: none
  84. * taken: takes and drops res->spinlock
  85. * held on exit: none
  86. * returns: DLM_NORMAL, DLM_NOTQUEUED
  87. */
  88. static enum dlm_status dlmlock_master(struct dlm_ctxt *dlm,
  89. struct dlm_lock_resource *res,
  90. struct dlm_lock *lock, int flags)
  91. {
  92. int call_ast = 0, kick_thread = 0;
  93. enum dlm_status status = DLM_NORMAL;
  94. mlog_entry("type=%d\n", lock->ml.type);
  95. spin_lock(&res->spinlock);
  96. /* if called from dlm_create_lock_handler, need to
  97. * ensure it will not sleep in dlm_wait_on_lockres */
  98. status = __dlm_lockres_state_to_status(res);
  99. if (status != DLM_NORMAL &&
  100. lock->ml.node != dlm->node_num) {
  101. /* erf. state changed after lock was dropped. */
  102. spin_unlock(&res->spinlock);
  103. dlm_error(status);
  104. return status;
  105. }
  106. __dlm_wait_on_lockres(res);
  107. __dlm_lockres_reserve_ast(res);
  108. if (dlm_can_grant_new_lock(res, lock)) {
  109. mlog(0, "I can grant this lock right away\n");
  110. /* got it right away */
  111. lock->lksb->status = DLM_NORMAL;
  112. status = DLM_NORMAL;
  113. dlm_lock_get(lock);
  114. list_add_tail(&lock->list, &res->granted);
  115. /* for the recovery lock, we can't allow the ast
  116. * to be queued since the dlmthread is already
  117. * frozen. but the recovery lock is always locked
  118. * with LKM_NOQUEUE so we do not need the ast in
  119. * this special case */
  120. if (!dlm_is_recovery_lock(res->lockname.name,
  121. res->lockname.len)) {
  122. kick_thread = 1;
  123. call_ast = 1;
  124. }
  125. } else {
  126. /* for NOQUEUE request, unless we get the
  127. * lock right away, return DLM_NOTQUEUED */
  128. if (flags & LKM_NOQUEUE)
  129. status = DLM_NOTQUEUED;
  130. else {
  131. dlm_lock_get(lock);
  132. list_add_tail(&lock->list, &res->blocked);
  133. kick_thread = 1;
  134. }
  135. }
  136. spin_unlock(&res->spinlock);
  137. wake_up(&res->wq);
  138. /* either queue the ast or release it */
  139. if (call_ast)
  140. dlm_queue_ast(dlm, lock);
  141. else
  142. dlm_lockres_release_ast(dlm, res);
  143. dlm_lockres_calc_usage(dlm, res);
  144. if (kick_thread)
  145. dlm_kick_thread(dlm, res);
  146. return status;
  147. }
  148. void dlm_revert_pending_lock(struct dlm_lock_resource *res,
  149. struct dlm_lock *lock)
  150. {
  151. /* remove from local queue if it failed */
  152. list_del_init(&lock->list);
  153. lock->lksb->flags &= ~DLM_LKSB_GET_LVB;
  154. }
  155. /*
  156. * locking:
  157. * caller needs: none
  158. * taken: takes and drops res->spinlock
  159. * held on exit: none
  160. * returns: DLM_DENIED, DLM_RECOVERING, or net status
  161. */
  162. static enum dlm_status dlmlock_remote(struct dlm_ctxt *dlm,
  163. struct dlm_lock_resource *res,
  164. struct dlm_lock *lock, int flags)
  165. {
  166. enum dlm_status status = DLM_DENIED;
  167. mlog_entry("type=%d\n", lock->ml.type);
  168. mlog(0, "lockres %.*s, flags = 0x%x\n", res->lockname.len,
  169. res->lockname.name, flags);
  170. spin_lock(&res->spinlock);
  171. /* will exit this call with spinlock held */
  172. __dlm_wait_on_lockres(res);
  173. res->state |= DLM_LOCK_RES_IN_PROGRESS;
  174. /* add lock to local (secondary) queue */
  175. dlm_lock_get(lock);
  176. list_add_tail(&lock->list, &res->blocked);
  177. lock->lock_pending = 1;
  178. spin_unlock(&res->spinlock);
  179. /* spec seems to say that you will get DLM_NORMAL when the lock
  180. * has been queued, meaning we need to wait for a reply here. */
  181. status = dlm_send_remote_lock_request(dlm, res, lock, flags);
  182. spin_lock(&res->spinlock);
  183. res->state &= ~DLM_LOCK_RES_IN_PROGRESS;
  184. lock->lock_pending = 0;
  185. if (status != DLM_NORMAL) {
  186. if (status != DLM_NOTQUEUED)
  187. dlm_error(status);
  188. dlm_revert_pending_lock(res, lock);
  189. dlm_lock_put(lock);
  190. }
  191. spin_unlock(&res->spinlock);
  192. dlm_lockres_calc_usage(dlm, res);
  193. wake_up(&res->wq);
  194. return status;
  195. }
  196. /* for remote lock creation.
  197. * locking:
  198. * caller needs: none, but need res->state & DLM_LOCK_RES_IN_PROGRESS
  199. * taken: none
  200. * held on exit: none
  201. * returns: DLM_NOLOCKMGR, or net status
  202. */
  203. static enum dlm_status dlm_send_remote_lock_request(struct dlm_ctxt *dlm,
  204. struct dlm_lock_resource *res,
  205. struct dlm_lock *lock, int flags)
  206. {
  207. struct dlm_create_lock create;
  208. int tmpret, status = 0;
  209. enum dlm_status ret;
  210. mlog_entry_void();
  211. memset(&create, 0, sizeof(create));
  212. create.node_idx = dlm->node_num;
  213. create.requested_type = lock->ml.type;
  214. create.cookie = lock->ml.cookie;
  215. create.namelen = res->lockname.len;
  216. create.flags = cpu_to_be32(flags);
  217. memcpy(create.name, res->lockname.name, create.namelen);
  218. tmpret = o2net_send_message(DLM_CREATE_LOCK_MSG, dlm->key, &create,
  219. sizeof(create), res->owner, &status);
  220. if (tmpret >= 0) {
  221. // successfully sent and received
  222. ret = status; // this is already a dlm_status
  223. } else {
  224. mlog_errno(tmpret);
  225. if (dlm_is_host_down(tmpret)) {
  226. ret = DLM_RECOVERING;
  227. mlog(0, "node %u died so returning DLM_RECOVERING "
  228. "from lock message!\n", res->owner);
  229. } else {
  230. ret = dlm_err_to_dlm_status(tmpret);
  231. }
  232. }
  233. return ret;
  234. }
  235. void dlm_lock_get(struct dlm_lock *lock)
  236. {
  237. kref_get(&lock->lock_refs);
  238. }
  239. void dlm_lock_put(struct dlm_lock *lock)
  240. {
  241. kref_put(&lock->lock_refs, dlm_lock_release);
  242. }
  243. static void dlm_lock_release(struct kref *kref)
  244. {
  245. struct dlm_lock *lock;
  246. lock = container_of(kref, struct dlm_lock, lock_refs);
  247. BUG_ON(!list_empty(&lock->list));
  248. BUG_ON(!list_empty(&lock->ast_list));
  249. BUG_ON(!list_empty(&lock->bast_list));
  250. BUG_ON(lock->ast_pending);
  251. BUG_ON(lock->bast_pending);
  252. dlm_lock_detach_lockres(lock);
  253. if (lock->lksb_kernel_allocated) {
  254. mlog(0, "freeing kernel-allocated lksb\n");
  255. kfree(lock->lksb);
  256. }
  257. kfree(lock);
  258. }
  259. /* associate a lock with it's lockres, getting a ref on the lockres */
  260. void dlm_lock_attach_lockres(struct dlm_lock *lock,
  261. struct dlm_lock_resource *res)
  262. {
  263. dlm_lockres_get(res);
  264. lock->lockres = res;
  265. }
  266. /* drop ref on lockres, if there is still one associated with lock */
  267. static void dlm_lock_detach_lockres(struct dlm_lock *lock)
  268. {
  269. struct dlm_lock_resource *res;
  270. res = lock->lockres;
  271. if (res) {
  272. lock->lockres = NULL;
  273. mlog(0, "removing lock's lockres reference\n");
  274. dlm_lockres_put(res);
  275. }
  276. }
  277. static void dlm_init_lock(struct dlm_lock *newlock, int type,
  278. u8 node, u64 cookie)
  279. {
  280. INIT_LIST_HEAD(&newlock->list);
  281. INIT_LIST_HEAD(&newlock->ast_list);
  282. INIT_LIST_HEAD(&newlock->bast_list);
  283. spin_lock_init(&newlock->spinlock);
  284. newlock->ml.type = type;
  285. newlock->ml.convert_type = LKM_IVMODE;
  286. newlock->ml.highest_blocked = LKM_IVMODE;
  287. newlock->ml.node = node;
  288. newlock->ml.pad1 = 0;
  289. newlock->ml.list = 0;
  290. newlock->ml.flags = 0;
  291. newlock->ast = NULL;
  292. newlock->bast = NULL;
  293. newlock->astdata = NULL;
  294. newlock->ml.cookie = cpu_to_be64(cookie);
  295. newlock->ast_pending = 0;
  296. newlock->bast_pending = 0;
  297. newlock->convert_pending = 0;
  298. newlock->lock_pending = 0;
  299. newlock->unlock_pending = 0;
  300. newlock->cancel_pending = 0;
  301. newlock->lksb_kernel_allocated = 0;
  302. kref_init(&newlock->lock_refs);
  303. }
  304. struct dlm_lock * dlm_new_lock(int type, u8 node, u64 cookie,
  305. struct dlm_lockstatus *lksb)
  306. {
  307. struct dlm_lock *lock;
  308. int kernel_allocated = 0;
  309. lock = kcalloc(1, sizeof(*lock), GFP_KERNEL);
  310. if (!lock)
  311. return NULL;
  312. if (!lksb) {
  313. /* zero memory only if kernel-allocated */
  314. lksb = kcalloc(1, sizeof(*lksb), GFP_KERNEL);
  315. if (!lksb) {
  316. kfree(lock);
  317. return NULL;
  318. }
  319. kernel_allocated = 1;
  320. }
  321. dlm_init_lock(lock, type, node, cookie);
  322. if (kernel_allocated)
  323. lock->lksb_kernel_allocated = 1;
  324. lock->lksb = lksb;
  325. lksb->lockid = lock;
  326. return lock;
  327. }
  328. /* handler for lock creation net message
  329. * locking:
  330. * caller needs: none
  331. * taken: takes and drops res->spinlock
  332. * held on exit: none
  333. * returns: DLM_NORMAL, DLM_SYSERR, DLM_IVLOCKID, DLM_NOTQUEUED
  334. */
  335. int dlm_create_lock_handler(struct o2net_msg *msg, u32 len, void *data)
  336. {
  337. struct dlm_ctxt *dlm = data;
  338. struct dlm_create_lock *create = (struct dlm_create_lock *)msg->buf;
  339. struct dlm_lock_resource *res = NULL;
  340. struct dlm_lock *newlock = NULL;
  341. struct dlm_lockstatus *lksb = NULL;
  342. enum dlm_status status = DLM_NORMAL;
  343. char *name;
  344. unsigned int namelen;
  345. BUG_ON(!dlm);
  346. mlog_entry_void();
  347. if (!dlm_grab(dlm))
  348. return DLM_REJECTED;
  349. mlog_bug_on_msg(!dlm_domain_fully_joined(dlm),
  350. "Domain %s not fully joined!\n", dlm->name);
  351. name = create->name;
  352. namelen = create->namelen;
  353. status = DLM_IVBUFLEN;
  354. if (namelen > DLM_LOCKID_NAME_MAX) {
  355. dlm_error(status);
  356. goto leave;
  357. }
  358. status = DLM_SYSERR;
  359. newlock = dlm_new_lock(create->requested_type,
  360. create->node_idx,
  361. be64_to_cpu(create->cookie), NULL);
  362. if (!newlock) {
  363. dlm_error(status);
  364. goto leave;
  365. }
  366. lksb = newlock->lksb;
  367. if (be32_to_cpu(create->flags) & LKM_GET_LVB) {
  368. lksb->flags |= DLM_LKSB_GET_LVB;
  369. mlog(0, "set DLM_LKSB_GET_LVB flag\n");
  370. }
  371. status = DLM_IVLOCKID;
  372. res = dlm_lookup_lockres(dlm, name, namelen);
  373. if (!res) {
  374. dlm_error(status);
  375. goto leave;
  376. }
  377. spin_lock(&res->spinlock);
  378. status = __dlm_lockres_state_to_status(res);
  379. spin_unlock(&res->spinlock);
  380. if (status != DLM_NORMAL) {
  381. mlog(0, "lockres recovering/migrating/in-progress\n");
  382. goto leave;
  383. }
  384. dlm_lock_attach_lockres(newlock, res);
  385. status = dlmlock_master(dlm, res, newlock, be32_to_cpu(create->flags));
  386. leave:
  387. if (status != DLM_NORMAL)
  388. if (newlock)
  389. dlm_lock_put(newlock);
  390. if (res)
  391. dlm_lockres_put(res);
  392. dlm_put(dlm);
  393. return status;
  394. }
  395. /* fetch next node-local (u8 nodenum + u56 cookie) into u64 */
  396. static inline void dlm_get_next_cookie(u8 node_num, u64 *cookie)
  397. {
  398. u64 tmpnode = node_num;
  399. /* shift single byte of node num into top 8 bits */
  400. tmpnode <<= 56;
  401. spin_lock(&dlm_cookie_lock);
  402. *cookie = (dlm_next_cookie | tmpnode);
  403. if (++dlm_next_cookie & 0xff00000000000000ull) {
  404. mlog(0, "This node's cookie will now wrap!\n");
  405. dlm_next_cookie = 1;
  406. }
  407. spin_unlock(&dlm_cookie_lock);
  408. }
  409. enum dlm_status dlmlock(struct dlm_ctxt *dlm, int mode,
  410. struct dlm_lockstatus *lksb, int flags,
  411. const char *name, dlm_astlockfunc_t *ast, void *data,
  412. dlm_bastlockfunc_t *bast)
  413. {
  414. enum dlm_status status;
  415. struct dlm_lock_resource *res = NULL;
  416. struct dlm_lock *lock = NULL;
  417. int convert = 0, recovery = 0;
  418. /* yes this function is a mess.
  419. * TODO: clean this up. lots of common code in the
  420. * lock and convert paths, especially in the retry blocks */
  421. if (!lksb) {
  422. dlm_error(DLM_BADARGS);
  423. return DLM_BADARGS;
  424. }
  425. status = DLM_BADPARAM;
  426. if (mode != LKM_EXMODE && mode != LKM_PRMODE && mode != LKM_NLMODE) {
  427. dlm_error(status);
  428. goto error;
  429. }
  430. if (flags & ~LKM_VALID_FLAGS) {
  431. dlm_error(status);
  432. goto error;
  433. }
  434. convert = (flags & LKM_CONVERT);
  435. recovery = (flags & LKM_RECOVERY);
  436. if (recovery &&
  437. (!dlm_is_recovery_lock(name, strlen(name)) || convert) ) {
  438. dlm_error(status);
  439. goto error;
  440. }
  441. if (convert && (flags & LKM_LOCAL)) {
  442. mlog(ML_ERROR, "strange LOCAL convert request!\n");
  443. goto error;
  444. }
  445. if (convert) {
  446. /* CONVERT request */
  447. /* if converting, must pass in a valid dlm_lock */
  448. lock = lksb->lockid;
  449. if (!lock) {
  450. mlog(ML_ERROR, "NULL lock pointer in convert "
  451. "request\n");
  452. goto error;
  453. }
  454. res = lock->lockres;
  455. if (!res) {
  456. mlog(ML_ERROR, "NULL lockres pointer in convert "
  457. "request\n");
  458. goto error;
  459. }
  460. dlm_lockres_get(res);
  461. /* XXX: for ocfs2 purposes, the ast/bast/astdata/lksb are
  462. * static after the original lock call. convert requests will
  463. * ensure that everything is the same, or return DLM_BADARGS.
  464. * this means that DLM_DENIED_NOASTS will never be returned.
  465. */
  466. if (lock->lksb != lksb || lock->ast != ast ||
  467. lock->bast != bast || lock->astdata != data) {
  468. status = DLM_BADARGS;
  469. mlog(ML_ERROR, "new args: lksb=%p, ast=%p, bast=%p, "
  470. "astdata=%p\n", lksb, ast, bast, data);
  471. mlog(ML_ERROR, "orig args: lksb=%p, ast=%p, bast=%p, "
  472. "astdata=%p\n", lock->lksb, lock->ast,
  473. lock->bast, lock->astdata);
  474. goto error;
  475. }
  476. retry_convert:
  477. dlm_wait_for_recovery(dlm);
  478. if (res->owner == dlm->node_num)
  479. status = dlmconvert_master(dlm, res, lock, flags, mode);
  480. else
  481. status = dlmconvert_remote(dlm, res, lock, flags, mode);
  482. if (status == DLM_RECOVERING || status == DLM_MIGRATING ||
  483. status == DLM_FORWARD) {
  484. /* for now, see how this works without sleeping
  485. * and just retry right away. I suspect the reco
  486. * or migration will complete fast enough that
  487. * no waiting will be necessary */
  488. mlog(0, "retrying convert with migration/recovery/"
  489. "in-progress\n");
  490. msleep(100);
  491. goto retry_convert;
  492. }
  493. } else {
  494. u64 tmpcookie;
  495. /* LOCK request */
  496. status = DLM_BADARGS;
  497. if (!name) {
  498. dlm_error(status);
  499. goto error;
  500. }
  501. status = DLM_IVBUFLEN;
  502. if (strlen(name) > DLM_LOCKID_NAME_MAX || strlen(name) < 1) {
  503. dlm_error(status);
  504. goto error;
  505. }
  506. dlm_get_next_cookie(dlm->node_num, &tmpcookie);
  507. lock = dlm_new_lock(mode, dlm->node_num, tmpcookie, lksb);
  508. if (!lock) {
  509. dlm_error(status);
  510. goto error;
  511. }
  512. if (!recovery)
  513. dlm_wait_for_recovery(dlm);
  514. /* find or create the lock resource */
  515. res = dlm_get_lock_resource(dlm, name, flags);
  516. if (!res) {
  517. status = DLM_IVLOCKID;
  518. dlm_error(status);
  519. goto error;
  520. }
  521. mlog(0, "type=%d, flags = 0x%x\n", mode, flags);
  522. mlog(0, "creating lock: lock=%p res=%p\n", lock, res);
  523. dlm_lock_attach_lockres(lock, res);
  524. lock->ast = ast;
  525. lock->bast = bast;
  526. lock->astdata = data;
  527. retry_lock:
  528. if (flags & LKM_VALBLK) {
  529. mlog(0, "LKM_VALBLK passed by caller\n");
  530. /* LVB requests for non PR, PW or EX locks are
  531. * ignored. */
  532. if (mode < LKM_PRMODE)
  533. flags &= ~LKM_VALBLK;
  534. else {
  535. flags |= LKM_GET_LVB;
  536. lock->lksb->flags |= DLM_LKSB_GET_LVB;
  537. }
  538. }
  539. if (res->owner == dlm->node_num)
  540. status = dlmlock_master(dlm, res, lock, flags);
  541. else
  542. status = dlmlock_remote(dlm, res, lock, flags);
  543. if (status == DLM_RECOVERING || status == DLM_MIGRATING ||
  544. status == DLM_FORWARD) {
  545. mlog(0, "retrying lock with migration/"
  546. "recovery/in progress\n");
  547. msleep(100);
  548. dlm_wait_for_recovery(dlm);
  549. goto retry_lock;
  550. }
  551. if (status != DLM_NORMAL) {
  552. lock->lksb->flags &= ~DLM_LKSB_GET_LVB;
  553. if (status != DLM_NOTQUEUED)
  554. dlm_error(status);
  555. goto error;
  556. }
  557. }
  558. error:
  559. if (status != DLM_NORMAL) {
  560. if (lock && !convert)
  561. dlm_lock_put(lock);
  562. // this is kind of unnecessary
  563. lksb->status = status;
  564. }
  565. /* put lockres ref from the convert path
  566. * or from dlm_get_lock_resource */
  567. if (res)
  568. dlm_lockres_put(res);
  569. return status;
  570. }
  571. EXPORT_SYMBOL_GPL(dlmlock);