1 /* -*- mode: c; c-basic-offset: 8; -*-
2 * vim: noexpandtab sw=8 ts=8 sts=0:
6 * Code which implements an OCFS2 specific interface to underlying
9 * Copyright (C) 2007 Oracle. All rights reserved.
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.
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.
21 #include "stackglue.h"
23 static struct ocfs2_locking_protocol *lproto;
25 /* These should be identical */
26 #if (DLM_LOCK_IV != LKM_IVMODE)
27 # error Lock modes do not match
29 #if (DLM_LOCK_NL != LKM_NLMODE)
30 # error Lock modes do not match
32 #if (DLM_LOCK_CR != LKM_CRMODE)
33 # error Lock modes do not match
35 #if (DLM_LOCK_CW != LKM_CWMODE)
36 # error Lock modes do not match
38 #if (DLM_LOCK_PR != LKM_PRMODE)
39 # error Lock modes do not match
41 #if (DLM_LOCK_PW != LKM_PWMODE)
42 # error Lock modes do not match
44 #if (DLM_LOCK_EX != LKM_EXMODE)
45 # error Lock modes do not match
47 static inline int mode_to_o2dlm(int mode)
49 BUG_ON(mode > LKM_MAXMODE);
54 #define map_flag(_generic, _o2dlm) \
55 if (flags & (_generic)) { \
56 flags &= ~(_generic); \
57 o2dlm_flags |= (_o2dlm); \
59 static int flags_to_o2dlm(u32 flags)
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);
73 /* map_flag() should have cleared every flag passed in */
80 enum dlm_status ocfs2_dlm_lock(struct dlm_ctxt *dlm,
82 struct dlm_lockstatus *lksb,
88 int o2dlm_mode = mode_to_o2dlm(mode);
89 int o2dlm_flags = flags_to_o2dlm(flags);
91 BUG_ON(lproto == NULL);
93 return dlmlock(dlm, o2dlm_mode, lksb, o2dlm_flags, name, namelen,
94 lproto->lp_lock_ast, astarg,
95 lproto->lp_blocking_ast);
98 enum dlm_status ocfs2_dlm_unlock(struct dlm_ctxt *dlm,
99 struct dlm_lockstatus *lksb,
103 int o2dlm_flags = flags_to_o2dlm(flags);
105 BUG_ON(lproto == NULL);
107 return dlmunlock(dlm, lksb, o2dlm_flags,
108 lproto->lp_unlock_ast, astarg);
112 void o2cb_get_stack(struct ocfs2_locking_protocol *proto)
114 BUG_ON(proto == NULL);
119 void o2cb_put_stack(void)