ocfs2: Use global DLM_ constants in generic code.
[deliverable/linux.git] / fs / ocfs2 / stackglue.c
CommitLineData
24ef1815
JB
1/* -*- mode: c; c-basic-offset: 8; -*-
2 * vim: noexpandtab sw=8 ts=8 sts=0:
3 *
4 * stackglue.c
5 *
6 * Code which implements an OCFS2 specific interface to underlying
7 * cluster stacks.
8 *
9 * Copyright (C) 2007 Oracle. All rights reserved.
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public
13 * License as published by the Free Software Foundation, version 2.
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
24ef1815
JB
21#include "stackglue.h"
22
23static struct ocfs2_locking_protocol *lproto;
24
bd3e7610
JB
25/* These should be identical */
26#if (DLM_LOCK_IV != LKM_IVMODE)
27# error Lock modes do not match
28#endif
29#if (DLM_LOCK_NL != LKM_NLMODE)
30# error Lock modes do not match
31#endif
32#if (DLM_LOCK_CR != LKM_CRMODE)
33# error Lock modes do not match
34#endif
35#if (DLM_LOCK_CW != LKM_CWMODE)
36# error Lock modes do not match
37#endif
38#if (DLM_LOCK_PR != LKM_PRMODE)
39# error Lock modes do not match
40#endif
41#if (DLM_LOCK_PW != LKM_PWMODE)
42# error Lock modes do not match
43#endif
44#if (DLM_LOCK_EX != LKM_EXMODE)
45# error Lock modes do not match
46#endif
47static inline int mode_to_o2dlm(int mode)
48{
49 BUG_ON(mode > LKM_MAXMODE);
50
51 return mode;
52}
53
54#define map_flag(_generic, _o2dlm) \
55 if (flags & (_generic)) { \
56 flags &= ~(_generic); \
57 o2dlm_flags |= (_o2dlm); \
58 }
59static int flags_to_o2dlm(u32 flags)
60{
61 int o2dlm_flags = 0;
62
63 map_flag(DLM_LKF_NOQUEUE, LKM_NOQUEUE);
64 map_flag(DLM_LKF_CANCEL, LKM_CANCEL);
65 map_flag(DLM_LKF_CONVERT, LKM_CONVERT);
66 map_flag(DLM_LKF_VALBLK, LKM_VALBLK);
67 map_flag(DLM_LKF_IVVALBLK, LKM_INVVALBLK);
68 map_flag(DLM_LKF_ORPHAN, LKM_ORPHAN);
69 map_flag(DLM_LKF_FORCEUNLOCK, LKM_FORCE);
70 map_flag(DLM_LKF_TIMEOUT, LKM_TIMEOUT);
71 map_flag(DLM_LKF_LOCAL, LKM_LOCAL);
72
73 /* map_flag() should have cleared every flag passed in */
74 BUG_ON(flags != 0);
75
76 return o2dlm_flags;
77}
78#undef map_flag
79
24ef1815
JB
80enum dlm_status ocfs2_dlm_lock(struct dlm_ctxt *dlm,
81 int mode,
82 struct dlm_lockstatus *lksb,
83 u32 flags,
84 void *name,
85 unsigned int namelen,
86 void *astarg)
87{
bd3e7610
JB
88 int o2dlm_mode = mode_to_o2dlm(mode);
89 int o2dlm_flags = flags_to_o2dlm(flags);
90
24ef1815 91 BUG_ON(lproto == NULL);
bd3e7610
JB
92
93 return dlmlock(dlm, o2dlm_mode, lksb, o2dlm_flags, name, namelen,
24ef1815
JB
94 lproto->lp_lock_ast, astarg,
95 lproto->lp_blocking_ast);
96}
97
98enum dlm_status ocfs2_dlm_unlock(struct dlm_ctxt *dlm,
99 struct dlm_lockstatus *lksb,
100 u32 flags,
101 void *astarg)
102{
bd3e7610
JB
103 int o2dlm_flags = flags_to_o2dlm(flags);
104
24ef1815
JB
105 BUG_ON(lproto == NULL);
106
bd3e7610
JB
107 return dlmunlock(dlm, lksb, o2dlm_flags,
108 lproto->lp_unlock_ast, astarg);
24ef1815
JB
109}
110
111
112void o2cb_get_stack(struct ocfs2_locking_protocol *proto)
113{
114 BUG_ON(proto == NULL);
115
116 lproto = proto;
117}
118
119void o2cb_put_stack(void)
120{
121 lproto = NULL;
122}
This page took 0.03285 seconds and 5 git commands to generate.