userdlm.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. /* -*- mode: c; c-basic-offset: 8; -*-
  2. * vim: noexpandtab sw=8 ts=8 sts=0:
  3. *
  4. * userdlm.c
  5. *
  6. * Code which implements the kernel side of a minimal userspace
  7. * interface to our DLM.
  8. *
  9. * Many of the functions here are pared down versions of dlmglue.c
  10. * functions.
  11. *
  12. * Copyright (C) 2003, 2004 Oracle. All rights reserved.
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public
  16. * License as published by the Free Software Foundation; either
  17. * version 2 of the License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  22. * General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public
  25. * License along with this program; if not, write to the
  26. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  27. * Boston, MA 021110-1307, USA.
  28. */
  29. #include <linux/signal.h>
  30. #include <linux/module.h>
  31. #include <linux/fs.h>
  32. #include <linux/types.h>
  33. #include <linux/crc32.h>
  34. #include "cluster/nodemanager.h"
  35. #include "cluster/heartbeat.h"
  36. #include "cluster/tcp.h"
  37. #include "dlmapi.h"
  38. #include "userdlm.h"
  39. #define MLOG_MASK_PREFIX ML_DLMFS
  40. #include "cluster/masklog.h"
  41. static inline int user_check_wait_flag(struct user_lock_res *lockres,
  42. int flag)
  43. {
  44. int ret;
  45. spin_lock(&lockres->l_lock);
  46. ret = lockres->l_flags & flag;
  47. spin_unlock(&lockres->l_lock);
  48. return ret;
  49. }
  50. static inline void user_wait_on_busy_lock(struct user_lock_res *lockres)
  51. {
  52. wait_event(lockres->l_event,
  53. !user_check_wait_flag(lockres, USER_LOCK_BUSY));
  54. }
  55. static inline void user_wait_on_blocked_lock(struct user_lock_res *lockres)
  56. {
  57. wait_event(lockres->l_event,
  58. !user_check_wait_flag(lockres, USER_LOCK_BLOCKED));
  59. }
  60. /* I heart container_of... */
  61. static inline struct dlm_ctxt *
  62. dlm_ctxt_from_user_lockres(struct user_lock_res *lockres)
  63. {
  64. struct dlmfs_inode_private *ip;
  65. ip = container_of(lockres,
  66. struct dlmfs_inode_private,
  67. ip_lockres);
  68. return ip->ip_dlm;
  69. }
  70. static struct inode *
  71. user_dlm_inode_from_user_lockres(struct user_lock_res *lockres)
  72. {
  73. struct dlmfs_inode_private *ip;
  74. ip = container_of(lockres,
  75. struct dlmfs_inode_private,
  76. ip_lockres);
  77. return &ip->ip_vfs_inode;
  78. }
  79. static inline void user_recover_from_dlm_error(struct user_lock_res *lockres)
  80. {
  81. spin_lock(&lockres->l_lock);
  82. lockres->l_flags &= ~USER_LOCK_BUSY;
  83. spin_unlock(&lockres->l_lock);
  84. }
  85. #define user_log_dlm_error(_func, _stat, _lockres) do { \
  86. mlog(ML_ERROR, "Dlm error \"%s\" while calling %s on " \
  87. "resource %.*s: %s\n", dlm_errname(_stat), _func, \
  88. _lockres->l_namelen, _lockres->l_name, dlm_errmsg(_stat)); \
  89. } while (0)
  90. /* WARNING: This function lives in a world where the only three lock
  91. * levels are EX, PR, and NL. It *will* have to be adjusted when more
  92. * lock types are added. */
  93. static inline int user_highest_compat_lock_level(int level)
  94. {
  95. int new_level = LKM_EXMODE;
  96. if (level == LKM_EXMODE)
  97. new_level = LKM_NLMODE;
  98. else if (level == LKM_PRMODE)
  99. new_level = LKM_PRMODE;
  100. return new_level;
  101. }
  102. static void user_ast(void *opaque)
  103. {
  104. struct user_lock_res *lockres = opaque;
  105. struct dlm_lockstatus *lksb;
  106. mlog(0, "AST fired for lockres %.*s\n", lockres->l_namelen,
  107. lockres->l_name);
  108. spin_lock(&lockres->l_lock);
  109. lksb = &(lockres->l_lksb);
  110. if (lksb->status != DLM_NORMAL) {
  111. mlog(ML_ERROR, "lksb status value of %u on lockres %.*s\n",
  112. lksb->status, lockres->l_namelen, lockres->l_name);
  113. spin_unlock(&lockres->l_lock);
  114. return;
  115. }
  116. mlog_bug_on_msg(lockres->l_requested == LKM_IVMODE,
  117. "Lockres %.*s, requested ivmode. flags 0x%x\n",
  118. lockres->l_namelen, lockres->l_name, lockres->l_flags);
  119. /* we're downconverting. */
  120. if (lockres->l_requested < lockres->l_level) {
  121. if (lockres->l_requested <=
  122. user_highest_compat_lock_level(lockres->l_blocking)) {
  123. lockres->l_blocking = LKM_NLMODE;
  124. lockres->l_flags &= ~USER_LOCK_BLOCKED;
  125. }
  126. }
  127. lockres->l_level = lockres->l_requested;
  128. lockres->l_requested = LKM_IVMODE;
  129. lockres->l_flags |= USER_LOCK_ATTACHED;
  130. lockres->l_flags &= ~USER_LOCK_BUSY;
  131. spin_unlock(&lockres->l_lock);
  132. wake_up(&lockres->l_event);
  133. }
  134. static inline void user_dlm_grab_inode_ref(struct user_lock_res *lockres)
  135. {
  136. struct inode *inode;
  137. inode = user_dlm_inode_from_user_lockres(lockres);
  138. if (!igrab(inode))
  139. BUG();
  140. }
  141. static void user_dlm_unblock_lock(struct work_struct *work);
  142. static void __user_dlm_queue_lockres(struct user_lock_res *lockres)
  143. {
  144. if (!(lockres->l_flags & USER_LOCK_QUEUED)) {
  145. user_dlm_grab_inode_ref(lockres);
  146. INIT_WORK(&lockres->l_work, user_dlm_unblock_lock);
  147. queue_work(user_dlm_worker, &lockres->l_work);
  148. lockres->l_flags |= USER_LOCK_QUEUED;
  149. }
  150. }
  151. static void __user_dlm_cond_queue_lockres(struct user_lock_res *lockres)
  152. {
  153. int queue = 0;
  154. if (!(lockres->l_flags & USER_LOCK_BLOCKED))
  155. return;
  156. switch (lockres->l_blocking) {
  157. case LKM_EXMODE:
  158. if (!lockres->l_ex_holders && !lockres->l_ro_holders)
  159. queue = 1;
  160. break;
  161. case LKM_PRMODE:
  162. if (!lockres->l_ex_holders)
  163. queue = 1;
  164. break;
  165. default:
  166. BUG();
  167. }
  168. if (queue)
  169. __user_dlm_queue_lockres(lockres);
  170. }
  171. static void user_bast(void *opaque, int level)
  172. {
  173. struct user_lock_res *lockres = opaque;
  174. mlog(0, "Blocking AST fired for lockres %.*s. Blocking level %d\n",
  175. lockres->l_namelen, lockres->l_name, level);
  176. spin_lock(&lockres->l_lock);
  177. lockres->l_flags |= USER_LOCK_BLOCKED;
  178. if (level > lockres->l_blocking)
  179. lockres->l_blocking = level;
  180. __user_dlm_queue_lockres(lockres);
  181. spin_unlock(&lockres->l_lock);
  182. wake_up(&lockres->l_event);
  183. }
  184. static void user_unlock_ast(void *opaque, enum dlm_status status)
  185. {
  186. struct user_lock_res *lockres = opaque;
  187. mlog(0, "UNLOCK AST called on lock %.*s\n", lockres->l_namelen,
  188. lockres->l_name);
  189. if (status != DLM_NORMAL && status != DLM_CANCELGRANT)
  190. mlog(ML_ERROR, "Dlm returns status %d\n", status);
  191. spin_lock(&lockres->l_lock);
  192. /* The teardown flag gets set early during the unlock process,
  193. * so test the cancel flag to make sure that this ast isn't
  194. * for a concurrent cancel. */
  195. if (lockres->l_flags & USER_LOCK_IN_TEARDOWN
  196. && !(lockres->l_flags & USER_LOCK_IN_CANCEL)) {
  197. lockres->l_level = LKM_IVMODE;
  198. } else if (status == DLM_CANCELGRANT) {
  199. /* We tried to cancel a convert request, but it was
  200. * already granted. Don't clear the busy flag - the
  201. * ast should've done this already. */
  202. BUG_ON(!(lockres->l_flags & USER_LOCK_IN_CANCEL));
  203. lockres->l_flags &= ~USER_LOCK_IN_CANCEL;
  204. goto out_noclear;
  205. } else {
  206. BUG_ON(!(lockres->l_flags & USER_LOCK_IN_CANCEL));
  207. /* Cancel succeeded, we want to re-queue */
  208. lockres->l_requested = LKM_IVMODE; /* cancel an
  209. * upconvert
  210. * request. */
  211. lockres->l_flags &= ~USER_LOCK_IN_CANCEL;
  212. /* we want the unblock thread to look at it again
  213. * now. */
  214. if (lockres->l_flags & USER_LOCK_BLOCKED)
  215. __user_dlm_queue_lockres(lockres);
  216. }
  217. lockres->l_flags &= ~USER_LOCK_BUSY;
  218. out_noclear:
  219. spin_unlock(&lockres->l_lock);
  220. wake_up(&lockres->l_event);
  221. }
  222. static inline void user_dlm_drop_inode_ref(struct user_lock_res *lockres)
  223. {
  224. struct inode *inode;
  225. inode = user_dlm_inode_from_user_lockres(lockres);
  226. iput(inode);
  227. }
  228. static void user_dlm_unblock_lock(struct work_struct *work)
  229. {
  230. int new_level, status;
  231. struct user_lock_res *lockres =
  232. container_of(work, struct user_lock_res, l_work);
  233. struct dlm_ctxt *dlm = dlm_ctxt_from_user_lockres(lockres);
  234. mlog(0, "processing lockres %.*s\n", lockres->l_namelen,
  235. lockres->l_name);
  236. spin_lock(&lockres->l_lock);
  237. mlog_bug_on_msg(!(lockres->l_flags & USER_LOCK_QUEUED),
  238. "Lockres %.*s, flags 0x%x\n",
  239. lockres->l_namelen, lockres->l_name, lockres->l_flags);
  240. /* notice that we don't clear USER_LOCK_BLOCKED here. If it's
  241. * set, we want user_ast clear it. */
  242. lockres->l_flags &= ~USER_LOCK_QUEUED;
  243. /* It's valid to get here and no longer be blocked - if we get
  244. * several basts in a row, we might be queued by the first
  245. * one, the unblock thread might run and clear the queued
  246. * flag, and finally we might get another bast which re-queues
  247. * us before our ast for the downconvert is called. */
  248. if (!(lockres->l_flags & USER_LOCK_BLOCKED)) {
  249. spin_unlock(&lockres->l_lock);
  250. goto drop_ref;
  251. }
  252. if (lockres->l_flags & USER_LOCK_IN_TEARDOWN) {
  253. spin_unlock(&lockres->l_lock);
  254. goto drop_ref;
  255. }
  256. if (lockres->l_flags & USER_LOCK_BUSY) {
  257. if (lockres->l_flags & USER_LOCK_IN_CANCEL) {
  258. spin_unlock(&lockres->l_lock);
  259. goto drop_ref;
  260. }
  261. lockres->l_flags |= USER_LOCK_IN_CANCEL;
  262. spin_unlock(&lockres->l_lock);
  263. status = dlmunlock(dlm,
  264. &lockres->l_lksb,
  265. LKM_CANCEL,
  266. user_unlock_ast,
  267. lockres);
  268. if (status != DLM_NORMAL)
  269. user_log_dlm_error("dlmunlock", status, lockres);
  270. goto drop_ref;
  271. }
  272. /* If there are still incompat holders, we can exit safely
  273. * without worrying about re-queueing this lock as that will
  274. * happen on the last call to user_cluster_unlock. */
  275. if ((lockres->l_blocking == LKM_EXMODE)
  276. && (lockres->l_ex_holders || lockres->l_ro_holders)) {
  277. spin_unlock(&lockres->l_lock);
  278. mlog(0, "can't downconvert for ex: ro = %u, ex = %u\n",
  279. lockres->l_ro_holders, lockres->l_ex_holders);
  280. goto drop_ref;
  281. }
  282. if ((lockres->l_blocking == LKM_PRMODE)
  283. && lockres->l_ex_holders) {
  284. spin_unlock(&lockres->l_lock);
  285. mlog(0, "can't downconvert for pr: ex = %u\n",
  286. lockres->l_ex_holders);
  287. goto drop_ref;
  288. }
  289. /* yay, we can downconvert now. */
  290. new_level = user_highest_compat_lock_level(lockres->l_blocking);
  291. lockres->l_requested = new_level;
  292. lockres->l_flags |= USER_LOCK_BUSY;
  293. mlog(0, "Downconvert lock from %d to %d\n",
  294. lockres->l_level, new_level);
  295. spin_unlock(&lockres->l_lock);
  296. /* need lock downconvert request now... */
  297. status = dlmlock(dlm,
  298. new_level,
  299. &lockres->l_lksb,
  300. LKM_CONVERT|LKM_VALBLK,
  301. lockres->l_name,
  302. lockres->l_namelen,
  303. user_ast,
  304. lockres,
  305. user_bast);
  306. if (status != DLM_NORMAL) {
  307. user_log_dlm_error("dlmlock", status, lockres);
  308. user_recover_from_dlm_error(lockres);
  309. }
  310. drop_ref:
  311. user_dlm_drop_inode_ref(lockres);
  312. }
  313. static inline void user_dlm_inc_holders(struct user_lock_res *lockres,
  314. int level)
  315. {
  316. switch(level) {
  317. case LKM_EXMODE:
  318. lockres->l_ex_holders++;
  319. break;
  320. case LKM_PRMODE:
  321. lockres->l_ro_holders++;
  322. break;
  323. default:
  324. BUG();
  325. }
  326. }
  327. /* predict what lock level we'll be dropping down to on behalf
  328. * of another node, and return true if the currently wanted
  329. * level will be compatible with it. */
  330. static inline int
  331. user_may_continue_on_blocked_lock(struct user_lock_res *lockres,
  332. int wanted)
  333. {
  334. BUG_ON(!(lockres->l_flags & USER_LOCK_BLOCKED));
  335. return wanted <= user_highest_compat_lock_level(lockres->l_blocking);
  336. }
  337. int user_dlm_cluster_lock(struct user_lock_res *lockres,
  338. int level,
  339. int lkm_flags)
  340. {
  341. int status, local_flags;
  342. struct dlm_ctxt *dlm = dlm_ctxt_from_user_lockres(lockres);
  343. if (level != LKM_EXMODE &&
  344. level != LKM_PRMODE) {
  345. mlog(ML_ERROR, "lockres %.*s: invalid request!\n",
  346. lockres->l_namelen, lockres->l_name);
  347. status = -EINVAL;
  348. goto bail;
  349. }
  350. mlog(0, "lockres %.*s: asking for %s lock, passed flags = 0x%x\n",
  351. lockres->l_namelen, lockres->l_name,
  352. (level == LKM_EXMODE) ? "LKM_EXMODE" : "LKM_PRMODE",
  353. lkm_flags);
  354. again:
  355. if (signal_pending(current)) {
  356. status = -ERESTARTSYS;
  357. goto bail;
  358. }
  359. spin_lock(&lockres->l_lock);
  360. /* We only compare against the currently granted level
  361. * here. If the lock is blocked waiting on a downconvert,
  362. * we'll get caught below. */
  363. if ((lockres->l_flags & USER_LOCK_BUSY) &&
  364. (level > lockres->l_level)) {
  365. /* is someone sitting in dlm_lock? If so, wait on
  366. * them. */
  367. spin_unlock(&lockres->l_lock);
  368. user_wait_on_busy_lock(lockres);
  369. goto again;
  370. }
  371. if ((lockres->l_flags & USER_LOCK_BLOCKED) &&
  372. (!user_may_continue_on_blocked_lock(lockres, level))) {
  373. /* is the lock is currently blocked on behalf of
  374. * another node */
  375. spin_unlock(&lockres->l_lock);
  376. user_wait_on_blocked_lock(lockres);
  377. goto again;
  378. }
  379. if (level > lockres->l_level) {
  380. local_flags = lkm_flags | LKM_VALBLK;
  381. if (lockres->l_level != LKM_IVMODE)
  382. local_flags |= LKM_CONVERT;
  383. lockres->l_requested = level;
  384. lockres->l_flags |= USER_LOCK_BUSY;
  385. spin_unlock(&lockres->l_lock);
  386. BUG_ON(level == LKM_IVMODE);
  387. BUG_ON(level == LKM_NLMODE);
  388. /* call dlm_lock to upgrade lock now */
  389. status = dlmlock(dlm,
  390. level,
  391. &lockres->l_lksb,
  392. local_flags,
  393. lockres->l_name,
  394. lockres->l_namelen,
  395. user_ast,
  396. lockres,
  397. user_bast);
  398. if (status != DLM_NORMAL) {
  399. if ((lkm_flags & LKM_NOQUEUE) &&
  400. (status == DLM_NOTQUEUED))
  401. status = -EAGAIN;
  402. else {
  403. user_log_dlm_error("dlmlock", status, lockres);
  404. status = -EINVAL;
  405. }
  406. user_recover_from_dlm_error(lockres);
  407. goto bail;
  408. }
  409. user_wait_on_busy_lock(lockres);
  410. goto again;
  411. }
  412. user_dlm_inc_holders(lockres, level);
  413. spin_unlock(&lockres->l_lock);
  414. status = 0;
  415. bail:
  416. return status;
  417. }
  418. static inline void user_dlm_dec_holders(struct user_lock_res *lockres,
  419. int level)
  420. {
  421. switch(level) {
  422. case LKM_EXMODE:
  423. BUG_ON(!lockres->l_ex_holders);
  424. lockres->l_ex_holders--;
  425. break;
  426. case LKM_PRMODE:
  427. BUG_ON(!lockres->l_ro_holders);
  428. lockres->l_ro_holders--;
  429. break;
  430. default:
  431. BUG();
  432. }
  433. }
  434. void user_dlm_cluster_unlock(struct user_lock_res *lockres,
  435. int level)
  436. {
  437. if (level != LKM_EXMODE &&
  438. level != LKM_PRMODE) {
  439. mlog(ML_ERROR, "lockres %.*s: invalid request!\n",
  440. lockres->l_namelen, lockres->l_name);
  441. return;
  442. }
  443. spin_lock(&lockres->l_lock);
  444. user_dlm_dec_holders(lockres, level);
  445. __user_dlm_cond_queue_lockres(lockres);
  446. spin_unlock(&lockres->l_lock);
  447. }
  448. void user_dlm_write_lvb(struct inode *inode,
  449. const char *val,
  450. unsigned int len)
  451. {
  452. struct user_lock_res *lockres = &DLMFS_I(inode)->ip_lockres;
  453. char *lvb = lockres->l_lksb.lvb;
  454. BUG_ON(len > DLM_LVB_LEN);
  455. spin_lock(&lockres->l_lock);
  456. BUG_ON(lockres->l_level < LKM_EXMODE);
  457. memcpy(lvb, val, len);
  458. spin_unlock(&lockres->l_lock);
  459. }
  460. void user_dlm_read_lvb(struct inode *inode,
  461. char *val,
  462. unsigned int len)
  463. {
  464. struct user_lock_res *lockres = &DLMFS_I(inode)->ip_lockres;
  465. char *lvb = lockres->l_lksb.lvb;
  466. BUG_ON(len > DLM_LVB_LEN);
  467. spin_lock(&lockres->l_lock);
  468. BUG_ON(lockres->l_level < LKM_PRMODE);
  469. memcpy(val, lvb, len);
  470. spin_unlock(&lockres->l_lock);
  471. }
  472. void user_dlm_lock_res_init(struct user_lock_res *lockres,
  473. struct dentry *dentry)
  474. {
  475. memset(lockres, 0, sizeof(*lockres));
  476. spin_lock_init(&lockres->l_lock);
  477. init_waitqueue_head(&lockres->l_event);
  478. lockres->l_level = LKM_IVMODE;
  479. lockres->l_requested = LKM_IVMODE;
  480. lockres->l_blocking = LKM_IVMODE;
  481. /* should have been checked before getting here. */
  482. BUG_ON(dentry->d_name.len >= USER_DLM_LOCK_ID_MAX_LEN);
  483. memcpy(lockres->l_name,
  484. dentry->d_name.name,
  485. dentry->d_name.len);
  486. lockres->l_namelen = dentry->d_name.len;
  487. }
  488. int user_dlm_destroy_lock(struct user_lock_res *lockres)
  489. {
  490. int status = -EBUSY;
  491. struct dlm_ctxt *dlm = dlm_ctxt_from_user_lockres(lockres);
  492. mlog(0, "asked to destroy %.*s\n", lockres->l_namelen, lockres->l_name);
  493. spin_lock(&lockres->l_lock);
  494. if (lockres->l_flags & USER_LOCK_IN_TEARDOWN) {
  495. spin_unlock(&lockres->l_lock);
  496. return 0;
  497. }
  498. lockres->l_flags |= USER_LOCK_IN_TEARDOWN;
  499. while (lockres->l_flags & USER_LOCK_BUSY) {
  500. spin_unlock(&lockres->l_lock);
  501. user_wait_on_busy_lock(lockres);
  502. spin_lock(&lockres->l_lock);
  503. }
  504. if (lockres->l_ro_holders || lockres->l_ex_holders) {
  505. spin_unlock(&lockres->l_lock);
  506. goto bail;
  507. }
  508. status = 0;
  509. if (!(lockres->l_flags & USER_LOCK_ATTACHED)) {
  510. spin_unlock(&lockres->l_lock);
  511. goto bail;
  512. }
  513. lockres->l_flags &= ~USER_LOCK_ATTACHED;
  514. lockres->l_flags |= USER_LOCK_BUSY;
  515. spin_unlock(&lockres->l_lock);
  516. status = dlmunlock(dlm,
  517. &lockres->l_lksb,
  518. LKM_VALBLK,
  519. user_unlock_ast,
  520. lockres);
  521. if (status != DLM_NORMAL) {
  522. user_log_dlm_error("dlmunlock", status, lockres);
  523. status = -EINVAL;
  524. goto bail;
  525. }
  526. user_wait_on_busy_lock(lockres);
  527. status = 0;
  528. bail:
  529. return status;
  530. }
  531. struct dlm_ctxt *user_dlm_register_context(struct qstr *name,
  532. struct dlm_protocol_version *proto)
  533. {
  534. struct dlm_ctxt *dlm;
  535. u32 dlm_key;
  536. char *domain;
  537. domain = kmalloc(name->len + 1, GFP_NOFS);
  538. if (!domain) {
  539. mlog_errno(-ENOMEM);
  540. return ERR_PTR(-ENOMEM);
  541. }
  542. dlm_key = crc32_le(0, name->name, name->len);
  543. snprintf(domain, name->len + 1, "%.*s", name->len, name->name);
  544. dlm = dlm_register_domain(domain, dlm_key, proto);
  545. if (IS_ERR(dlm))
  546. mlog_errno(PTR_ERR(dlm));
  547. kfree(domain);
  548. return dlm;
  549. }
  550. void user_dlm_unregister_context(struct dlm_ctxt *dlm)
  551. {
  552. dlm_unregister_domain(dlm);
  553. }