xref: /linux/fs/gfs2/glock.h (revision fe1bdedc6c16adedc6fd3636185ea91596b1d6eb)
1b3b94faaSDavid Teigland /*
2b3b94faaSDavid Teigland  * Copyright (C) Sistina Software, Inc.  1997-2003 All rights reserved.
3b3b94faaSDavid Teigland  * Copyright (C) 2004-2005 Red Hat, Inc.  All rights reserved.
4b3b94faaSDavid Teigland  *
5b3b94faaSDavid Teigland  * This copyrighted material is made available to anyone wishing to use,
6b3b94faaSDavid Teigland  * modify, copy, or redistribute it subject to the terms and conditions
7b3b94faaSDavid Teigland  * of the GNU General Public License v.2.
8b3b94faaSDavid Teigland  */
9b3b94faaSDavid Teigland 
10b3b94faaSDavid Teigland #ifndef __GLOCK_DOT_H__
11b3b94faaSDavid Teigland #define __GLOCK_DOT_H__
12b3b94faaSDavid Teigland 
13b3b94faaSDavid Teigland /* Flags for lock requests; used in gfs2_holder gh_flag field.
14b3b94faaSDavid Teigland    From lm_interface.h:
15b3b94faaSDavid Teigland #define LM_FLAG_TRY		0x00000001
16b3b94faaSDavid Teigland #define LM_FLAG_TRY_1CB		0x00000002
17b3b94faaSDavid Teigland #define LM_FLAG_NOEXP		0x00000004
18b3b94faaSDavid Teigland #define LM_FLAG_ANY		0x00000008
19b3b94faaSDavid Teigland #define LM_FLAG_PRIORITY	0x00000010 */
20b3b94faaSDavid Teigland 
21b3b94faaSDavid Teigland #define GL_LOCAL_EXCL		0x00000020
22b3b94faaSDavid Teigland #define GL_ASYNC		0x00000040
23b3b94faaSDavid Teigland #define GL_EXACT		0x00000080
24b3b94faaSDavid Teigland #define GL_SKIP			0x00000100
25b3b94faaSDavid Teigland #define GL_ATIME		0x00000200
26b3b94faaSDavid Teigland #define GL_NOCACHE		0x00000400
27b3b94faaSDavid Teigland #define GL_SYNC			0x00000800
28b3b94faaSDavid Teigland #define GL_NOCANCEL		0x00001000
29b3b94faaSDavid Teigland #define GL_NEVER_RECURSE	0x00002000
30*fe1bdedcSSteven Whitehouse #define GL_AOP			0x00004000
31b3b94faaSDavid Teigland 
32b3b94faaSDavid Teigland #define GLR_TRYFAILED		13
33b3b94faaSDavid Teigland #define GLR_CANCELED		14
34b3b94faaSDavid Teigland 
35b3b94faaSDavid Teigland static inline int gfs2_glock_is_locked_by_me(struct gfs2_glock *gl)
36b3b94faaSDavid Teigland {
37b3b94faaSDavid Teigland 	struct gfs2_holder *gh;
38b3b94faaSDavid Teigland 	int locked = 0;
39b3b94faaSDavid Teigland 
40b3b94faaSDavid Teigland 	/* Look in glock's list of holders for one with current task as owner */
41b3b94faaSDavid Teigland 	spin_lock(&gl->gl_spin);
42b3b94faaSDavid Teigland 	list_for_each_entry(gh, &gl->gl_holders, gh_list) {
43b3b94faaSDavid Teigland 		if (gh->gh_owner == current) {
44b3b94faaSDavid Teigland 			locked = 1;
45b3b94faaSDavid Teigland 			break;
46b3b94faaSDavid Teigland 		}
47b3b94faaSDavid Teigland 	}
48b3b94faaSDavid Teigland 	spin_unlock(&gl->gl_spin);
49b3b94faaSDavid Teigland 
50b3b94faaSDavid Teigland 	return locked;
51b3b94faaSDavid Teigland }
52b3b94faaSDavid Teigland 
53b3b94faaSDavid Teigland static inline int gfs2_glock_is_held_excl(struct gfs2_glock *gl)
54b3b94faaSDavid Teigland {
55b3b94faaSDavid Teigland 	return (gl->gl_state == LM_ST_EXCLUSIVE);
56b3b94faaSDavid Teigland }
57b3b94faaSDavid Teigland 
58b3b94faaSDavid Teigland static inline int gfs2_glock_is_held_dfrd(struct gfs2_glock *gl)
59b3b94faaSDavid Teigland {
60b3b94faaSDavid Teigland 	return (gl->gl_state == LM_ST_DEFERRED);
61b3b94faaSDavid Teigland }
62b3b94faaSDavid Teigland 
63b3b94faaSDavid Teigland static inline int gfs2_glock_is_held_shrd(struct gfs2_glock *gl)
64b3b94faaSDavid Teigland {
65b3b94faaSDavid Teigland 	return (gl->gl_state == LM_ST_SHARED);
66b3b94faaSDavid Teigland }
67b3b94faaSDavid Teigland 
68b3b94faaSDavid Teigland static inline int gfs2_glock_is_blocking(struct gfs2_glock *gl)
69b3b94faaSDavid Teigland {
70b3b94faaSDavid Teigland 	int ret;
71b3b94faaSDavid Teigland 	spin_lock(&gl->gl_spin);
72b3b94faaSDavid Teigland 	ret = !list_empty(&gl->gl_waiters2) || !list_empty(&gl->gl_waiters3);
73b3b94faaSDavid Teigland 	spin_unlock(&gl->gl_spin);
74b3b94faaSDavid Teigland 	return ret;
75b3b94faaSDavid Teigland }
76b3b94faaSDavid Teigland 
77b3b94faaSDavid Teigland struct gfs2_glock *gfs2_glock_find(struct gfs2_sbd *sdp,
78b3b94faaSDavid Teigland 				   struct lm_lockname *name);
79b3b94faaSDavid Teigland int gfs2_glock_get(struct gfs2_sbd *sdp,
80b3b94faaSDavid Teigland 		   uint64_t number, struct gfs2_glock_operations *glops,
81b3b94faaSDavid Teigland 		   int create, struct gfs2_glock **glp);
82b3b94faaSDavid Teigland void gfs2_glock_hold(struct gfs2_glock *gl);
83b3b94faaSDavid Teigland int gfs2_glock_put(struct gfs2_glock *gl);
84b3b94faaSDavid Teigland 
85b3b94faaSDavid Teigland void gfs2_holder_init(struct gfs2_glock *gl, unsigned int state, int flags,
86b3b94faaSDavid Teigland 		      struct gfs2_holder *gh);
87b3b94faaSDavid Teigland void gfs2_holder_reinit(unsigned int state, int flags, struct gfs2_holder *gh);
88b3b94faaSDavid Teigland void gfs2_holder_uninit(struct gfs2_holder *gh);
89b3b94faaSDavid Teigland struct gfs2_holder *gfs2_holder_get(struct gfs2_glock *gl, unsigned int state,
90b3b94faaSDavid Teigland 				    int flags, gfp_t gfp_flags);
91b3b94faaSDavid Teigland void gfs2_holder_put(struct gfs2_holder *gh);
92b3b94faaSDavid Teigland 
93b3b94faaSDavid Teigland void gfs2_glock_xmote_th(struct gfs2_glock *gl, unsigned int state, int flags);
94b3b94faaSDavid Teigland void gfs2_glock_drop_th(struct gfs2_glock *gl);
95b3b94faaSDavid Teigland 
96b3b94faaSDavid Teigland void gfs2_glmutex_lock(struct gfs2_glock *gl);
97b3b94faaSDavid Teigland int gfs2_glmutex_trylock(struct gfs2_glock *gl);
98b3b94faaSDavid Teigland void gfs2_glmutex_unlock(struct gfs2_glock *gl);
99b3b94faaSDavid Teigland 
100b3b94faaSDavid Teigland int gfs2_glock_nq(struct gfs2_holder *gh);
101b3b94faaSDavid Teigland int gfs2_glock_poll(struct gfs2_holder *gh);
102b3b94faaSDavid Teigland int gfs2_glock_wait(struct gfs2_holder *gh);
103b3b94faaSDavid Teigland void gfs2_glock_dq(struct gfs2_holder *gh);
104b3b94faaSDavid Teigland 
105b3b94faaSDavid Teigland void gfs2_glock_prefetch(struct gfs2_glock *gl, unsigned int state, int flags);
106b3b94faaSDavid Teigland void gfs2_glock_force_drop(struct gfs2_glock *gl);
107b3b94faaSDavid Teigland 
108b3b94faaSDavid Teigland int gfs2_glock_be_greedy(struct gfs2_glock *gl, unsigned int time);
109b3b94faaSDavid Teigland 
110b3b94faaSDavid Teigland void gfs2_glock_dq_uninit(struct gfs2_holder *gh);
111b3b94faaSDavid Teigland int gfs2_glock_nq_num(struct gfs2_sbd *sdp,
112b3b94faaSDavid Teigland 		      uint64_t number, struct gfs2_glock_operations *glops,
113b3b94faaSDavid Teigland 		      unsigned int state, int flags, struct gfs2_holder *gh);
114b3b94faaSDavid Teigland 
115b3b94faaSDavid Teigland int gfs2_glock_nq_m(unsigned int num_gh, struct gfs2_holder *ghs);
116b3b94faaSDavid Teigland void gfs2_glock_dq_m(unsigned int num_gh, struct gfs2_holder *ghs);
117b3b94faaSDavid Teigland void gfs2_glock_dq_uninit_m(unsigned int num_gh, struct gfs2_holder *ghs);
118b3b94faaSDavid Teigland 
119b3b94faaSDavid Teigland void gfs2_glock_prefetch_num(struct gfs2_sbd *sdp, uint64_t number,
120b3b94faaSDavid Teigland 			     struct gfs2_glock_operations *glops,
121b3b94faaSDavid Teigland 			     unsigned int state, int flags);
122b3b94faaSDavid Teigland 
123d0dc80dbSSteven Whitehouse /**
124d0dc80dbSSteven Whitehouse  * gfs2_glock_nq_init - intialize a holder and enqueue it on a glock
125d0dc80dbSSteven Whitehouse  * @gl: the glock
126d0dc80dbSSteven Whitehouse  * @state: the state we're requesting
127d0dc80dbSSteven Whitehouse  * @flags: the modifier flags
128d0dc80dbSSteven Whitehouse  * @gh: the holder structure
129d0dc80dbSSteven Whitehouse  *
130d0dc80dbSSteven Whitehouse  * Returns: 0, GLR_*, or errno
131d0dc80dbSSteven Whitehouse  */
132d0dc80dbSSteven Whitehouse 
133d0dc80dbSSteven Whitehouse static inline int gfs2_glock_nq_init(struct gfs2_glock *gl,
134d0dc80dbSSteven Whitehouse 				     unsigned int state, int flags,
135d0dc80dbSSteven Whitehouse 				     struct gfs2_holder *gh)
136d0dc80dbSSteven Whitehouse {
137d0dc80dbSSteven Whitehouse 	int error;
138d0dc80dbSSteven Whitehouse 
139d0dc80dbSSteven Whitehouse 	gfs2_holder_init(gl, state, flags, gh);
140d0dc80dbSSteven Whitehouse 
141d0dc80dbSSteven Whitehouse 	error = gfs2_glock_nq(gh);
142d0dc80dbSSteven Whitehouse 	if (error)
143d0dc80dbSSteven Whitehouse 		gfs2_holder_uninit(gh);
144d0dc80dbSSteven Whitehouse 
145d0dc80dbSSteven Whitehouse 	return error;
146d0dc80dbSSteven Whitehouse }
147d0dc80dbSSteven Whitehouse 
148b3b94faaSDavid Teigland /*  Lock Value Block functions  */
149b3b94faaSDavid Teigland 
150b3b94faaSDavid Teigland int gfs2_lvb_hold(struct gfs2_glock *gl);
151b3b94faaSDavid Teigland void gfs2_lvb_unhold(struct gfs2_glock *gl);
152b3b94faaSDavid Teigland void gfs2_lvb_sync(struct gfs2_glock *gl);
153b3b94faaSDavid Teigland 
154b3b94faaSDavid Teigland void gfs2_glock_cb(lm_fsdata_t *fsdata, unsigned int type, void *data);
155b3b94faaSDavid Teigland 
156b3b94faaSDavid Teigland void gfs2_try_toss_inode(struct gfs2_sbd *sdp, struct gfs2_inum *inum);
157b3b94faaSDavid Teigland void gfs2_iopen_go_callback(struct gfs2_glock *gl, unsigned int state);
158b3b94faaSDavid Teigland 
159b3b94faaSDavid Teigland void gfs2_glock_schedule_for_reclaim(struct gfs2_glock *gl);
160b3b94faaSDavid Teigland void gfs2_reclaim_glock(struct gfs2_sbd *sdp);
161b3b94faaSDavid Teigland 
162b3b94faaSDavid Teigland void gfs2_scand_internal(struct gfs2_sbd *sdp);
163b3b94faaSDavid Teigland void gfs2_gl_hash_clear(struct gfs2_sbd *sdp, int wait);
164b3b94faaSDavid Teigland 
165b3b94faaSDavid Teigland int gfs2_dump_lockstate(struct gfs2_sbd *sdp);
166b3b94faaSDavid Teigland 
167b3b94faaSDavid Teigland #endif /* __GLOCK_DOT_H__ */
168