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