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