xref: /openbmc/linux/fs/ocfs2/dlmglue.h (revision 4cff79e9)
1 /* -*- mode: c; c-basic-offset: 8; -*-
2  * vim: noexpandtab sw=8 ts=8 sts=0:
3  *
4  * dlmglue.h
5  *
6  * description here
7  *
8  * Copyright (C) 2002, 2004 Oracle.  All rights reserved.
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public
12  * License as published by the Free Software Foundation; either
13  * version 2 of the License, or (at your option) any later version.
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  * You should have received a copy of the GNU General Public
21  * License along with this program; if not, write to the
22  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23  * Boston, MA 021110-1307, USA.
24  */
25 
26 
27 #ifndef DLMGLUE_H
28 #define DLMGLUE_H
29 
30 #include "dcache.h"
31 
32 #define OCFS2_LVB_VERSION 5
33 
34 struct ocfs2_meta_lvb {
35 	__u8         lvb_version;
36 	__u8         lvb_reserved0;
37 	__be16       lvb_idynfeatures;
38 	__be32       lvb_iclusters;
39 	__be32       lvb_iuid;
40 	__be32       lvb_igid;
41 	__be64       lvb_iatime_packed;
42 	__be64       lvb_ictime_packed;
43 	__be64       lvb_imtime_packed;
44 	__be64       lvb_isize;
45 	__be16       lvb_imode;
46 	__be16       lvb_inlink;
47 	__be32       lvb_iattr;
48 	__be32       lvb_igeneration;
49 	__be32       lvb_reserved2;
50 };
51 
52 #define OCFS2_QINFO_LVB_VERSION 1
53 
54 struct ocfs2_qinfo_lvb {
55 	__u8	lvb_version;
56 	__u8	lvb_reserved[3];
57 	__be32	lvb_bgrace;
58 	__be32	lvb_igrace;
59 	__be32	lvb_syncms;
60 	__be32	lvb_blocks;
61 	__be32	lvb_free_blk;
62 	__be32	lvb_free_entry;
63 };
64 
65 #define OCFS2_ORPHAN_LVB_VERSION 1
66 
67 struct ocfs2_orphan_scan_lvb {
68 	__u8	lvb_version;
69 	__u8	lvb_reserved[3];
70 	__be32	lvb_os_seqno;
71 };
72 
73 #define OCFS2_TRIMFS_LVB_VERSION 1
74 
75 struct ocfs2_trim_fs_lvb {
76 	__u8	lvb_version;
77 	__u8	lvb_success;
78 	__u8	lvb_reserved[2];
79 	__be32	lvb_nodenum;
80 	__be64	lvb_start;
81 	__be64	lvb_len;
82 	__be64	lvb_minlen;
83 	__be64	lvb_trimlen;
84 };
85 
86 struct ocfs2_trim_fs_info {
87 	u8	tf_valid;	/* lvb is valid, or not */
88 	u8	tf_success;	/* trim is successful, or not */
89 	u32	tf_nodenum;	/* osb node number */
90 	u64	tf_start;	/* trim start offset in clusters */
91 	u64	tf_len;		/* trim end offset in clusters */
92 	u64	tf_minlen;	/* trim minimum contiguous free clusters */
93 	u64	tf_trimlen;	/* trimmed length in bytes */
94 };
95 
96 struct ocfs2_lock_holder {
97 	struct list_head oh_list;
98 	struct pid *oh_owner_pid;
99 };
100 
101 /* ocfs2_inode_lock_full() 'arg_flags' flags */
102 /* don't wait on recovery. */
103 #define OCFS2_META_LOCK_RECOVERY	(0x01)
104 /* Instruct the dlm not to queue ourselves on the other node. */
105 #define OCFS2_META_LOCK_NOQUEUE		(0x02)
106 /* don't block waiting for the downconvert thread, instead return -EAGAIN */
107 #define OCFS2_LOCK_NONBLOCK		(0x04)
108 /* just get back disk inode bh if we've got cluster lock. */
109 #define OCFS2_META_LOCK_GETBH		(0x08)
110 
111 /* Locking subclasses of inode cluster lock */
112 enum {
113 	OI_LS_NORMAL = 0,
114 	OI_LS_PARENT,
115 	OI_LS_RENAME1,
116 	OI_LS_RENAME2,
117 	OI_LS_REFLINK_TARGET,
118 };
119 
120 int ocfs2_dlm_init(struct ocfs2_super *osb);
121 void ocfs2_dlm_shutdown(struct ocfs2_super *osb, int hangup_pending);
122 void ocfs2_lock_res_init_once(struct ocfs2_lock_res *res);
123 void ocfs2_inode_lock_res_init(struct ocfs2_lock_res *res,
124 			       enum ocfs2_lock_type type,
125 			       unsigned int generation,
126 			       struct inode *inode);
127 void ocfs2_dentry_lock_res_init(struct ocfs2_dentry_lock *dl,
128 				u64 parent, struct inode *inode);
129 struct ocfs2_file_private;
130 void ocfs2_file_lock_res_init(struct ocfs2_lock_res *lockres,
131 			      struct ocfs2_file_private *fp);
132 struct ocfs2_mem_dqinfo;
133 void ocfs2_qinfo_lock_res_init(struct ocfs2_lock_res *lockres,
134                                struct ocfs2_mem_dqinfo *info);
135 void ocfs2_refcount_lock_res_init(struct ocfs2_lock_res *lockres,
136 				  struct ocfs2_super *osb, u64 ref_blkno,
137 				  unsigned int generation);
138 void ocfs2_lock_res_free(struct ocfs2_lock_res *res);
139 int ocfs2_create_new_inode_locks(struct inode *inode);
140 int ocfs2_drop_inode_locks(struct inode *inode);
141 int ocfs2_rw_lock(struct inode *inode, int write);
142 int ocfs2_try_rw_lock(struct inode *inode, int write);
143 void ocfs2_rw_unlock(struct inode *inode, int write);
144 int ocfs2_open_lock(struct inode *inode);
145 int ocfs2_try_open_lock(struct inode *inode, int write);
146 void ocfs2_open_unlock(struct inode *inode);
147 int ocfs2_inode_lock_atime(struct inode *inode,
148 			  struct vfsmount *vfsmnt,
149 			  int *level, int wait);
150 int ocfs2_inode_lock_full_nested(struct inode *inode,
151 			 struct buffer_head **ret_bh,
152 			 int ex,
153 			 int arg_flags,
154 			 int subclass);
155 int ocfs2_inode_lock_with_page(struct inode *inode,
156 			      struct buffer_head **ret_bh,
157 			      int ex,
158 			      struct page *page);
159 /* Variants without special locking class or flags */
160 #define ocfs2_inode_lock_full(i, r, e, f)\
161 		ocfs2_inode_lock_full_nested(i, r, e, f, OI_LS_NORMAL)
162 #define ocfs2_inode_lock_nested(i, b, e, s)\
163 		ocfs2_inode_lock_full_nested(i, b, e, 0, s)
164 /* 99% of the time we don't want to supply any additional flags --
165  * those are for very specific cases only. */
166 #define ocfs2_inode_lock(i, b, e) ocfs2_inode_lock_full_nested(i, b, e, 0, OI_LS_NORMAL)
167 #define ocfs2_try_inode_lock(i, b, e)\
168 		ocfs2_inode_lock_full_nested(i, b, e, OCFS2_META_LOCK_NOQUEUE,\
169 		OI_LS_NORMAL)
170 void ocfs2_inode_unlock(struct inode *inode,
171 		       int ex);
172 int ocfs2_super_lock(struct ocfs2_super *osb,
173 		     int ex);
174 void ocfs2_super_unlock(struct ocfs2_super *osb,
175 			int ex);
176 int ocfs2_orphan_scan_lock(struct ocfs2_super *osb, u32 *seqno);
177 void ocfs2_orphan_scan_unlock(struct ocfs2_super *osb, u32 seqno);
178 
179 int ocfs2_rename_lock(struct ocfs2_super *osb);
180 void ocfs2_rename_unlock(struct ocfs2_super *osb);
181 int ocfs2_nfs_sync_lock(struct ocfs2_super *osb, int ex);
182 void ocfs2_nfs_sync_unlock(struct ocfs2_super *osb, int ex);
183 void ocfs2_trim_fs_lock_res_init(struct ocfs2_super *osb);
184 void ocfs2_trim_fs_lock_res_uninit(struct ocfs2_super *osb);
185 int ocfs2_trim_fs_lock(struct ocfs2_super *osb,
186 		       struct ocfs2_trim_fs_info *info, int trylock);
187 void ocfs2_trim_fs_unlock(struct ocfs2_super *osb,
188 			  struct ocfs2_trim_fs_info *info);
189 int ocfs2_dentry_lock(struct dentry *dentry, int ex);
190 void ocfs2_dentry_unlock(struct dentry *dentry, int ex);
191 int ocfs2_file_lock(struct file *file, int ex, int trylock);
192 void ocfs2_file_unlock(struct file *file);
193 int ocfs2_qinfo_lock(struct ocfs2_mem_dqinfo *oinfo, int ex);
194 void ocfs2_qinfo_unlock(struct ocfs2_mem_dqinfo *oinfo, int ex);
195 struct ocfs2_refcount_tree;
196 int ocfs2_refcount_lock(struct ocfs2_refcount_tree *ref_tree, int ex);
197 void ocfs2_refcount_unlock(struct ocfs2_refcount_tree *ref_tree, int ex);
198 
199 
200 void ocfs2_mark_lockres_freeing(struct ocfs2_super *osb,
201 				struct ocfs2_lock_res *lockres);
202 void ocfs2_simple_drop_lockres(struct ocfs2_super *osb,
203 			       struct ocfs2_lock_res *lockres);
204 
205 /* for the downconvert thread */
206 void ocfs2_wake_downconvert_thread(struct ocfs2_super *osb);
207 
208 struct ocfs2_dlm_debug *ocfs2_new_dlm_debug(void);
209 void ocfs2_put_dlm_debug(struct ocfs2_dlm_debug *dlm_debug);
210 
211 /* To set the locking protocol on module initialization */
212 void ocfs2_set_locking_protocol(void);
213 
214 /* The _tracker pair is used to avoid cluster recursive locking */
215 int ocfs2_inode_lock_tracker(struct inode *inode,
216 			     struct buffer_head **ret_bh,
217 			     int ex,
218 			     struct ocfs2_lock_holder *oh);
219 void ocfs2_inode_unlock_tracker(struct inode *inode,
220 				int ex,
221 				struct ocfs2_lock_holder *oh,
222 				int had_lock);
223 
224 #endif	/* DLMGLUE_H */
225