xref: /openbmc/linux/fs/gfs2/glock.h (revision cbe6d257)
17336d0e6SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
2b3b94faaSDavid Teigland /*
3b3b94faaSDavid Teigland  * Copyright (C) Sistina Software, Inc.  1997-2003 All rights reserved.
43a8a9a10SSteven Whitehouse  * Copyright (C) 2004-2006 Red Hat, Inc.  All rights reserved.
5b3b94faaSDavid Teigland  */
6b3b94faaSDavid Teigland 
7b3b94faaSDavid Teigland #ifndef __GLOCK_DOT_H__
8b3b94faaSDavid Teigland #define __GLOCK_DOT_H__
9b3b94faaSDavid Teigland 
10e8edc6e0SAlexey Dobriyan #include <linux/sched.h>
11f057f6cdSSteven Whitehouse #include <linux/parser.h>
12f2f7ba52SSteven Whitehouse #include "incore.h"
13df3d87bdSBob Peterson #include "util.h"
14f2f7ba52SSteven Whitehouse 
15f057f6cdSSteven Whitehouse /* Options for hostdata parser */
16f057f6cdSSteven Whitehouse 
17f057f6cdSSteven Whitehouse enum {
18f057f6cdSSteven Whitehouse 	Opt_jid,
19f057f6cdSSteven Whitehouse 	Opt_id,
20f057f6cdSSteven Whitehouse 	Opt_first,
21f057f6cdSSteven Whitehouse 	Opt_nodir,
22f057f6cdSSteven Whitehouse 	Opt_err,
23f057f6cdSSteven Whitehouse };
24f057f6cdSSteven Whitehouse 
25f057f6cdSSteven Whitehouse /*
26f057f6cdSSteven Whitehouse  * lm_lockname types
27f057f6cdSSteven Whitehouse  */
28f057f6cdSSteven Whitehouse 
29f057f6cdSSteven Whitehouse #define LM_TYPE_RESERVED	0x00
30f057f6cdSSteven Whitehouse #define LM_TYPE_NONDISK		0x01
31f057f6cdSSteven Whitehouse #define LM_TYPE_INODE		0x02
32f057f6cdSSteven Whitehouse #define LM_TYPE_RGRP		0x03
33f057f6cdSSteven Whitehouse #define LM_TYPE_META		0x04
34f057f6cdSSteven Whitehouse #define LM_TYPE_IOPEN		0x05
35f057f6cdSSteven Whitehouse #define LM_TYPE_FLOCK		0x06
36f057f6cdSSteven Whitehouse #define LM_TYPE_PLOCK		0x07
37f057f6cdSSteven Whitehouse #define LM_TYPE_QUOTA		0x08
38f057f6cdSSteven Whitehouse #define LM_TYPE_JOURNAL		0x09
39f057f6cdSSteven Whitehouse 
40f057f6cdSSteven Whitehouse /*
41f057f6cdSSteven Whitehouse  * lm_lock() states
42f057f6cdSSteven Whitehouse  *
43f057f6cdSSteven Whitehouse  * SHARED is compatible with SHARED, not with DEFERRED or EX.
44f057f6cdSSteven Whitehouse  * DEFERRED is compatible with DEFERRED, not with SHARED or EX.
45f057f6cdSSteven Whitehouse  */
46f057f6cdSSteven Whitehouse 
47f057f6cdSSteven Whitehouse #define LM_ST_UNLOCKED		0
48f057f6cdSSteven Whitehouse #define LM_ST_EXCLUSIVE		1
49f057f6cdSSteven Whitehouse #define LM_ST_DEFERRED		2
50f057f6cdSSteven Whitehouse #define LM_ST_SHARED		3
51f057f6cdSSteven Whitehouse 
52f057f6cdSSteven Whitehouse /*
53f057f6cdSSteven Whitehouse  * lm_lock() flags
54f057f6cdSSteven Whitehouse  *
55f057f6cdSSteven Whitehouse  * LM_FLAG_TRY
56f057f6cdSSteven Whitehouse  * Don't wait to acquire the lock if it can't be granted immediately.
57f057f6cdSSteven Whitehouse  *
58f057f6cdSSteven Whitehouse  * LM_FLAG_TRY_1CB
59f057f6cdSSteven Whitehouse  * Send one blocking callback if TRY is set and the lock is not granted.
60f057f6cdSSteven Whitehouse  *
61f057f6cdSSteven Whitehouse  * LM_FLAG_NOEXP
62f057f6cdSSteven Whitehouse  * GFS sets this flag on lock requests it makes while doing journal recovery.
63f057f6cdSSteven Whitehouse  * These special requests should not be blocked due to the recovery like
64f057f6cdSSteven Whitehouse  * ordinary locks would be.
65f057f6cdSSteven Whitehouse  *
66f057f6cdSSteven Whitehouse  * LM_FLAG_ANY
67f057f6cdSSteven Whitehouse  * A SHARED request may also be granted in DEFERRED, or a DEFERRED request may
68f057f6cdSSteven Whitehouse  * also be granted in SHARED.  The preferred state is whichever is compatible
69f057f6cdSSteven Whitehouse  * with other granted locks, or the specified state if no other locks exist.
70f057f6cdSSteven Whitehouse  *
71f057f6cdSSteven Whitehouse  * LM_FLAG_PRIORITY
72f057f6cdSSteven Whitehouse  * Override fairness considerations.  Suppose a lock is held in a shared state
73f057f6cdSSteven Whitehouse  * and there is a pending request for the deferred state.  A shared lock
74f057f6cdSSteven Whitehouse  * request with the priority flag would be allowed to bypass the deferred
75f057f6cdSSteven Whitehouse  * request and directly join the other shared lock.  A shared lock request
76f057f6cdSSteven Whitehouse  * without the priority flag might be forced to wait until the deferred
77f057f6cdSSteven Whitehouse  * requested had acquired and released the lock.
7806e908cdSBob Peterson  *
7906e908cdSBob Peterson  * LM_FLAG_NODE_SCOPE
8006e908cdSBob Peterson  * This holder agrees to share the lock within this node. In other words,
8106e908cdSBob Peterson  * the glock is held in EX mode according to DLM, but local holders on the
8206e908cdSBob Peterson  * same node can share it.
83f057f6cdSSteven Whitehouse  */
84f057f6cdSSteven Whitehouse 
85b58bf407SBob Peterson #define LM_FLAG_TRY		0x0001
86b58bf407SBob Peterson #define LM_FLAG_TRY_1CB		0x0002
87b58bf407SBob Peterson #define LM_FLAG_NOEXP		0x0004
88b58bf407SBob Peterson #define LM_FLAG_ANY		0x0008
89b58bf407SBob Peterson #define LM_FLAG_PRIORITY	0x0010
9006e908cdSBob Peterson #define LM_FLAG_NODE_SCOPE	0x0020
91b58bf407SBob Peterson #define GL_ASYNC		0x0040
92b58bf407SBob Peterson #define GL_EXACT		0x0080
93b58bf407SBob Peterson #define GL_SKIP			0x0100
94*cbe6d257SAndreas Gruenbacher #define GL_NOPID		0x0200
95b58bf407SBob Peterson #define GL_NOCACHE		0x0400
96f057f6cdSSteven Whitehouse 
97f057f6cdSSteven Whitehouse /*
98921169caSSteven Whitehouse  * lm_async_cb return flags
99f057f6cdSSteven Whitehouse  *
100f057f6cdSSteven Whitehouse  * LM_OUT_ST_MASK
101f057f6cdSSteven Whitehouse  * Masks the lower two bits of lock state in the returned value.
102f057f6cdSSteven Whitehouse  *
103f057f6cdSSteven Whitehouse  * LM_OUT_CANCELED
104f057f6cdSSteven Whitehouse  * The lock request was canceled.
105f057f6cdSSteven Whitehouse  *
106f057f6cdSSteven Whitehouse  */
107f057f6cdSSteven Whitehouse 
108f057f6cdSSteven Whitehouse #define LM_OUT_ST_MASK		0x00000003
109f057f6cdSSteven Whitehouse #define LM_OUT_CANCELED		0x00000008
110921169caSSteven Whitehouse #define LM_OUT_ERROR		0x00000004
111f057f6cdSSteven Whitehouse 
112f057f6cdSSteven Whitehouse /*
113f057f6cdSSteven Whitehouse  * lm_recovery_done() messages
114f057f6cdSSteven Whitehouse  */
115f057f6cdSSteven Whitehouse 
116f057f6cdSSteven Whitehouse #define LM_RD_GAVEUP		308
117f057f6cdSSteven Whitehouse #define LM_RD_SUCCESS		309
118f057f6cdSSteven Whitehouse 
119f057f6cdSSteven Whitehouse #define GLR_TRYFAILED		13
120f057f6cdSSteven Whitehouse 
1217cf8dcd3SBob Peterson #define GL_GLOCK_MAX_HOLD        (long)(HZ / 5)
1227cf8dcd3SBob Peterson #define GL_GLOCK_DFT_HOLD        (long)(HZ / 5)
1237cf8dcd3SBob Peterson #define GL_GLOCK_MIN_HOLD        (long)(10)
1247cf8dcd3SBob Peterson #define GL_GLOCK_HOLD_INCR       (long)(HZ / 20)
1257cf8dcd3SBob Peterson #define GL_GLOCK_HOLD_DECR       (long)(HZ / 40)
1267cf8dcd3SBob Peterson 
127f057f6cdSSteven Whitehouse struct lm_lockops {
128f057f6cdSSteven Whitehouse 	const char *lm_proto_name;
129e0c2a9aaSDavid Teigland 	int (*lm_mount) (struct gfs2_sbd *sdp, const char *table);
130e0c2a9aaSDavid Teigland 	void (*lm_first_done) (struct gfs2_sbd *sdp);
131e0c2a9aaSDavid Teigland 	void (*lm_recovery_result) (struct gfs2_sbd *sdp, unsigned int jid,
132e0c2a9aaSDavid Teigland 				    unsigned int result);
133f057f6cdSSteven Whitehouse 	void (*lm_unmount) (struct gfs2_sbd *sdp);
134f057f6cdSSteven Whitehouse 	void (*lm_withdraw) (struct gfs2_sbd *sdp);
135bc015cb8SSteven Whitehouse 	void (*lm_put_lock) (struct gfs2_glock *gl);
136921169caSSteven Whitehouse 	int (*lm_lock) (struct gfs2_glock *gl, unsigned int req_state,
137921169caSSteven Whitehouse 			unsigned int flags);
138f057f6cdSSteven Whitehouse 	void (*lm_cancel) (struct gfs2_glock *gl);
139f057f6cdSSteven Whitehouse 	const match_table_t *lm_tokens;
140f057f6cdSSteven Whitehouse };
141f057f6cdSSteven Whitehouse 
14211d8b79eSKees Cook struct gfs2_glock_aspace {
14311d8b79eSKees Cook 	struct gfs2_glock glock;
14411d8b79eSKees Cook 	struct address_space mapping;
14511d8b79eSKees Cook };
14611d8b79eSKees Cook 
147b94a170eSBenjamin Marzinski extern struct workqueue_struct *gfs2_delete_workqueue;
1487afd88d9SSteven Whitehouse static inline struct gfs2_holder *gfs2_glock_is_locked_by_me(struct gfs2_glock *gl)
149b3b94faaSDavid Teigland {
150b3b94faaSDavid Teigland 	struct gfs2_holder *gh;
151b1e058daSPavel Emelyanov 	struct pid *pid;
152b3b94faaSDavid Teigland 
153b3b94faaSDavid Teigland 	/* Look in glock's list of holders for one with current task as owner */
154f3dd1649SAndreas Gruenbacher 	spin_lock(&gl->gl_lockref.lock);
155b1e058daSPavel Emelyanov 	pid = task_pid(current);
156b3b94faaSDavid Teigland 	list_for_each_entry(gh, &gl->gl_holders, gh_list) {
1576802e340SSteven Whitehouse 		if (!test_bit(HIF_HOLDER, &gh->gh_iflags))
1586802e340SSteven Whitehouse 			break;
159dc732906SBob Peterson 		if (test_bit(HIF_MAY_DEMOTE, &gh->gh_iflags))
160dc732906SBob Peterson 			continue;
1617afd88d9SSteven Whitehouse 		if (gh->gh_owner_pid == pid)
1627afd88d9SSteven Whitehouse 			goto out;
163b3b94faaSDavid Teigland 	}
1647afd88d9SSteven Whitehouse 	gh = NULL;
1657afd88d9SSteven Whitehouse out:
166f3dd1649SAndreas Gruenbacher 	spin_unlock(&gl->gl_lockref.lock);
167b3b94faaSDavid Teigland 
1687afd88d9SSteven Whitehouse 	return gh;
169b3b94faaSDavid Teigland }
170b3b94faaSDavid Teigland 
171b3b94faaSDavid Teigland static inline int gfs2_glock_is_held_excl(struct gfs2_glock *gl)
172b3b94faaSDavid Teigland {
17350299965SSteven Whitehouse 	return gl->gl_state == LM_ST_EXCLUSIVE;
174b3b94faaSDavid Teigland }
175b3b94faaSDavid Teigland 
176b3b94faaSDavid Teigland static inline int gfs2_glock_is_held_dfrd(struct gfs2_glock *gl)
177b3b94faaSDavid Teigland {
17850299965SSteven Whitehouse 	return gl->gl_state == LM_ST_DEFERRED;
179b3b94faaSDavid Teigland }
180b3b94faaSDavid Teigland 
181b3b94faaSDavid Teigland static inline int gfs2_glock_is_held_shrd(struct gfs2_glock *gl)
182b3b94faaSDavid Teigland {
18350299965SSteven Whitehouse 	return gl->gl_state == LM_ST_SHARED;
184b3b94faaSDavid Teigland }
185b3b94faaSDavid Teigland 
186009d8518SSteven Whitehouse static inline struct address_space *gfs2_glock2aspace(struct gfs2_glock *gl)
187009d8518SSteven Whitehouse {
18811d8b79eSKees Cook 	if (gl->gl_ops->go_flags & GLOF_ASPACE) {
18911d8b79eSKees Cook 		struct gfs2_glock_aspace *gla =
19011d8b79eSKees Cook 			container_of(gl, struct gfs2_glock_aspace, glock);
19111d8b79eSKees Cook 		return &gla->mapping;
19211d8b79eSKees Cook 	}
193009d8518SSteven Whitehouse 	return NULL;
194009d8518SSteven Whitehouse }
195009d8518SSteven Whitehouse 
1968eae1ca0SSteven Whitehouse extern int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number,
1978eae1ca0SSteven Whitehouse 			  const struct gfs2_glock_operations *glops,
198b3b94faaSDavid Teigland 			  int create, struct gfs2_glock **glp);
19971c1b213SAndreas Gruenbacher extern void gfs2_glock_hold(struct gfs2_glock *gl);
2008eae1ca0SSteven Whitehouse extern void gfs2_glock_put(struct gfs2_glock *gl);
20171c1b213SAndreas Gruenbacher extern void gfs2_glock_queue_put(struct gfs2_glock *gl);
202b016d9a8SAndreas Gruenbacher 
203b016d9a8SAndreas Gruenbacher extern void __gfs2_holder_init(struct gfs2_glock *gl, unsigned int state,
204b016d9a8SAndreas Gruenbacher 			       u16 flags, struct gfs2_holder *gh,
205b016d9a8SAndreas Gruenbacher 			       unsigned long ip);
206b016d9a8SAndreas Gruenbacher static inline void gfs2_holder_init(struct gfs2_glock *gl, unsigned int state,
207b016d9a8SAndreas Gruenbacher 				    u16 flags, struct gfs2_holder *gh) {
208b016d9a8SAndreas Gruenbacher 	__gfs2_holder_init(gl, state, flags, gh, _RET_IP_);
209b016d9a8SAndreas Gruenbacher }
210b016d9a8SAndreas Gruenbacher 
211b58bf407SBob Peterson extern void gfs2_holder_reinit(unsigned int state, u16 flags,
212b3b94faaSDavid Teigland 			       struct gfs2_holder *gh);
2138eae1ca0SSteven Whitehouse extern void gfs2_holder_uninit(struct gfs2_holder *gh);
2148eae1ca0SSteven Whitehouse extern int gfs2_glock_nq(struct gfs2_holder *gh);
2158eae1ca0SSteven Whitehouse extern int gfs2_glock_poll(struct gfs2_holder *gh);
216f2e70d8fSBob Peterson extern int gfs2_instantiate(struct gfs2_holder *gh);
2178eae1ca0SSteven Whitehouse extern int gfs2_glock_wait(struct gfs2_holder *gh);
218ad26967bSBob Peterson extern int gfs2_glock_async_wait(unsigned int num_gh, struct gfs2_holder *ghs);
2198eae1ca0SSteven Whitehouse extern void gfs2_glock_dq(struct gfs2_holder *gh);
2208eae1ca0SSteven Whitehouse extern void gfs2_glock_dq_wait(struct gfs2_holder *gh);
2218eae1ca0SSteven Whitehouse extern void gfs2_glock_dq_uninit(struct gfs2_holder *gh);
2228eae1ca0SSteven Whitehouse extern int gfs2_glock_nq_num(struct gfs2_sbd *sdp, u64 number,
2238eae1ca0SSteven Whitehouse 			     const struct gfs2_glock_operations *glops,
224b58bf407SBob Peterson 			     unsigned int state, u16 flags,
225190562bdSSteven Whitehouse 			     struct gfs2_holder *gh);
2268eae1ca0SSteven Whitehouse extern int gfs2_glock_nq_m(unsigned int num_gh, struct gfs2_holder *ghs);
2278eae1ca0SSteven Whitehouse extern void gfs2_glock_dq_m(unsigned int num_gh, struct gfs2_holder *ghs);
2283792ce97SBob Peterson extern void gfs2_dump_glock(struct seq_file *seq, struct gfs2_glock *gl,
2293792ce97SBob Peterson 			    bool fsid);
2303792ce97SBob Peterson #define GLOCK_BUG_ON(gl,x) do { if (unlikely(x)) {		\
2313792ce97SBob Peterson 			gfs2_dump_glock(NULL, gl, true);	\
2323792ce97SBob Peterson 			BUG(); } } while(0)
233ea4e61c7SBob Peterson #define gfs2_glock_assert_warn(gl, x) do { if (unlikely(!(x))) {	\
234ea4e61c7SBob Peterson 			gfs2_dump_glock(NULL, gl, true);		\
235ea4e61c7SBob Peterson 			gfs2_assert_warn((gl)->gl_name.ln_sbd, (x)); } } \
236ea4e61c7SBob Peterson 	while (0)
237ea4e61c7SBob Peterson #define gfs2_glock_assert_withdraw(gl, x) do { if (unlikely(!(x))) {	\
238ea4e61c7SBob Peterson 			gfs2_dump_glock(NULL, gl, true);		\
239ea4e61c7SBob Peterson 			gfs2_assert_withdraw((gl)->gl_name.ln_sbd, (x)); } } \
240ea4e61c7SBob Peterson 	while (0)
241ea4e61c7SBob Peterson 
2428eae1ca0SSteven Whitehouse extern __printf(2, 3)
2436802e340SSteven Whitehouse void gfs2_print_dbg(struct seq_file *seq, const char *fmt, ...);
244b3b94faaSDavid Teigland 
245d0dc80dbSSteven Whitehouse /**
24633027af6SAndrea Gelmini  * gfs2_glock_nq_init - initialize a holder and enqueue it on a glock
247d0dc80dbSSteven Whitehouse  * @gl: the glock
248d0dc80dbSSteven Whitehouse  * @state: the state we're requesting
249d0dc80dbSSteven Whitehouse  * @flags: the modifier flags
250d0dc80dbSSteven Whitehouse  * @gh: the holder structure
251d0dc80dbSSteven Whitehouse  *
252d0dc80dbSSteven Whitehouse  * Returns: 0, GLR_*, or errno
253d0dc80dbSSteven Whitehouse  */
254d0dc80dbSSteven Whitehouse 
255d0dc80dbSSteven Whitehouse static inline int gfs2_glock_nq_init(struct gfs2_glock *gl,
256b58bf407SBob Peterson 				     unsigned int state, u16 flags,
257d0dc80dbSSteven Whitehouse 				     struct gfs2_holder *gh)
258d0dc80dbSSteven Whitehouse {
259d0dc80dbSSteven Whitehouse 	int error;
260d0dc80dbSSteven Whitehouse 
261b016d9a8SAndreas Gruenbacher 	__gfs2_holder_init(gl, state, flags, gh, _RET_IP_);
262d0dc80dbSSteven Whitehouse 
263d0dc80dbSSteven Whitehouse 	error = gfs2_glock_nq(gh);
264d0dc80dbSSteven Whitehouse 	if (error)
265d0dc80dbSSteven Whitehouse 		gfs2_holder_uninit(gh);
266d0dc80dbSSteven Whitehouse 
267d0dc80dbSSteven Whitehouse 	return error;
268d0dc80dbSSteven Whitehouse }
269d0dc80dbSSteven Whitehouse 
270bc015cb8SSteven Whitehouse extern void gfs2_glock_cb(struct gfs2_glock *gl, unsigned int state);
271bc015cb8SSteven Whitehouse extern void gfs2_glock_complete(struct gfs2_glock *gl, int ret);
272a0e3cc65SAndreas Gruenbacher extern bool gfs2_queue_delete_work(struct gfs2_glock *gl, unsigned long delay);
273a0e3cc65SAndreas Gruenbacher extern void gfs2_cancel_delete_work(struct gfs2_glock *gl);
274a0e3cc65SAndreas Gruenbacher extern bool gfs2_delete_work_queued(const struct gfs2_glock *gl);
275a0e3cc65SAndreas Gruenbacher extern void gfs2_flush_delete_work(struct gfs2_sbd *sdp);
276bc015cb8SSteven Whitehouse extern void gfs2_gl_hash_clear(struct gfs2_sbd *sdp);
277bc015cb8SSteven Whitehouse extern void gfs2_glock_finish_truncate(struct gfs2_inode *ip);
278bc015cb8SSteven Whitehouse extern void gfs2_glock_thaw(struct gfs2_sbd *sdp);
27929687a2aSSteven Whitehouse extern void gfs2_glock_add_to_lru(struct gfs2_glock *gl);
280fc0e38daSSteven Whitehouse extern void gfs2_glock_free(struct gfs2_glock *gl);
281b3b94faaSDavid Teigland 
282bc015cb8SSteven Whitehouse extern int __init gfs2_glock_init(void);
283bc015cb8SSteven Whitehouse extern void gfs2_glock_exit(void);
284b3b94faaSDavid Teigland 
2852abbf9a4SGreg Kroah-Hartman extern void gfs2_create_debugfs_file(struct gfs2_sbd *sdp);
286bc015cb8SSteven Whitehouse extern void gfs2_delete_debugfs_file(struct gfs2_sbd *sdp);
2872abbf9a4SGreg Kroah-Hartman extern void gfs2_register_debugfs(void);
288bc015cb8SSteven Whitehouse extern void gfs2_unregister_debugfs(void);
28985d1da67SSteven Whitehouse 
290f057f6cdSSteven Whitehouse extern const struct lm_lockops gfs2_dlm_ops;
291f057f6cdSSteven Whitehouse 
2926df9f9a2SAndreas Gruenbacher static inline void gfs2_holder_mark_uninitialized(struct gfs2_holder *gh)
2936df9f9a2SAndreas Gruenbacher {
2946df9f9a2SAndreas Gruenbacher 	gh->gh_gl = NULL;
2956df9f9a2SAndreas Gruenbacher }
2966df9f9a2SAndreas Gruenbacher 
2976df9f9a2SAndreas Gruenbacher static inline bool gfs2_holder_initialized(struct gfs2_holder *gh)
2986df9f9a2SAndreas Gruenbacher {
2996df9f9a2SAndreas Gruenbacher 	return gh->gh_gl;
3006df9f9a2SAndreas Gruenbacher }
3016df9f9a2SAndreas Gruenbacher 
302ad26967bSBob Peterson static inline bool gfs2_holder_queued(struct gfs2_holder *gh)
303ad26967bSBob Peterson {
304ad26967bSBob Peterson 	return !list_empty(&gh->gh_list);
305ad26967bSBob Peterson }
306ad26967bSBob Peterson 
307df3d87bdSBob Peterson /**
308df3d87bdSBob Peterson  * glock_set_object - set the gl_object field of a glock
309df3d87bdSBob Peterson  * @gl: the glock
310df3d87bdSBob Peterson  * @object: the object
311df3d87bdSBob Peterson  */
3124fd1a579SAndreas Gruenbacher static inline void glock_set_object(struct gfs2_glock *gl, void *object)
3134fd1a579SAndreas Gruenbacher {
3144fd1a579SAndreas Gruenbacher 	spin_lock(&gl->gl_lockref.lock);
315df3d87bdSBob Peterson 	if (gfs2_assert_warn(gl->gl_name.ln_sbd, gl->gl_object == NULL))
3163792ce97SBob Peterson 		gfs2_dump_glock(NULL, gl, true);
3174fd1a579SAndreas Gruenbacher 	gl->gl_object = object;
3184fd1a579SAndreas Gruenbacher 	spin_unlock(&gl->gl_lockref.lock);
3194fd1a579SAndreas Gruenbacher }
3204fd1a579SAndreas Gruenbacher 
321df3d87bdSBob Peterson /**
322df3d87bdSBob Peterson  * glock_clear_object - clear the gl_object field of a glock
323df3d87bdSBob Peterson  * @gl: the glock
324df3d87bdSBob Peterson  * @object: the object
325df3d87bdSBob Peterson  *
326df3d87bdSBob Peterson  * I'd love to similarly add this:
327df3d87bdSBob Peterson  *	else if (gfs2_assert_warn(gl->gl_sbd, gl->gl_object == object))
3283792ce97SBob Peterson  *		gfs2_dump_glock(NULL, gl, true);
329df3d87bdSBob Peterson  * Unfortunately, that's not possible because as soon as gfs2_delete_inode
330df3d87bdSBob Peterson  * frees the block in the rgrp, another process can reassign it for an I_NEW
331df3d87bdSBob Peterson  * inode in gfs2_create_inode because that calls new_inode, not gfs2_iget.
332df3d87bdSBob Peterson  * That means gfs2_delete_inode may subsequently try to call this function
333df3d87bdSBob Peterson  * for a glock that's already pointing to a brand new inode. If we clear the
334df3d87bdSBob Peterson  * new inode's gl_object, we'll introduce metadata corruption. Function
335df3d87bdSBob Peterson  * gfs2_delete_inode calls clear_inode which calls gfs2_clear_inode which also
336df3d87bdSBob Peterson  * tries to clear gl_object, so it's more than just gfs2_delete_inode.
337df3d87bdSBob Peterson  *
338df3d87bdSBob Peterson  */
339df3d87bdSBob Peterson static inline void glock_clear_object(struct gfs2_glock *gl, void *object)
340df3d87bdSBob Peterson {
341df3d87bdSBob Peterson 	spin_lock(&gl->gl_lockref.lock);
342df3d87bdSBob Peterson 	if (gl->gl_object == object)
343df3d87bdSBob Peterson 		gl->gl_object = NULL;
344df3d87bdSBob Peterson 	spin_unlock(&gl->gl_lockref.lock);
345df3d87bdSBob Peterson }
346df3d87bdSBob Peterson 
347dc732906SBob Peterson static inline void gfs2_holder_allow_demote(struct gfs2_holder *gh)
348dc732906SBob Peterson {
349dc732906SBob Peterson 	struct gfs2_glock *gl = gh->gh_gl;
350dc732906SBob Peterson 
351dc732906SBob Peterson 	spin_lock(&gl->gl_lockref.lock);
352dc732906SBob Peterson 	set_bit(HIF_MAY_DEMOTE, &gh->gh_iflags);
353dc732906SBob Peterson 	spin_unlock(&gl->gl_lockref.lock);
354dc732906SBob Peterson }
355dc732906SBob Peterson 
356dc732906SBob Peterson static inline void gfs2_holder_disallow_demote(struct gfs2_holder *gh)
357dc732906SBob Peterson {
358dc732906SBob Peterson 	struct gfs2_glock *gl = gh->gh_gl;
359dc732906SBob Peterson 
360dc732906SBob Peterson 	spin_lock(&gl->gl_lockref.lock);
361dc732906SBob Peterson 	clear_bit(HIF_MAY_DEMOTE, &gh->gh_iflags);
362dc732906SBob Peterson 	spin_unlock(&gl->gl_lockref.lock);
363dc732906SBob Peterson }
364dc732906SBob Peterson 
365f286d627SAndreas Gruenbacher extern void gfs2_inode_remember_delete(struct gfs2_glock *gl, u64 generation);
366f286d627SAndreas Gruenbacher extern bool gfs2_inode_already_deleted(struct gfs2_glock *gl, u64 generation);
367f286d627SAndreas Gruenbacher 
368b3b94faaSDavid Teigland #endif /* __GLOCK_DOT_H__ */
369