162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * dlmglue.h
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * description here
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci * Copyright (C) 2002, 2004 Oracle.  All rights reserved.
862306a36Sopenharmony_ci */
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#ifndef DLMGLUE_H
1262306a36Sopenharmony_ci#define DLMGLUE_H
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci#include "dcache.h"
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci#define OCFS2_LVB_VERSION 5
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_cistruct ocfs2_meta_lvb {
1962306a36Sopenharmony_ci	__u8         lvb_version;
2062306a36Sopenharmony_ci	__u8         lvb_reserved0;
2162306a36Sopenharmony_ci	__be16       lvb_idynfeatures;
2262306a36Sopenharmony_ci	__be32       lvb_iclusters;
2362306a36Sopenharmony_ci	__be32       lvb_iuid;
2462306a36Sopenharmony_ci	__be32       lvb_igid;
2562306a36Sopenharmony_ci	__be64       lvb_iatime_packed;
2662306a36Sopenharmony_ci	__be64       lvb_ictime_packed;
2762306a36Sopenharmony_ci	__be64       lvb_imtime_packed;
2862306a36Sopenharmony_ci	__be64       lvb_isize;
2962306a36Sopenharmony_ci	__be16       lvb_imode;
3062306a36Sopenharmony_ci	__be16       lvb_inlink;
3162306a36Sopenharmony_ci	__be32       lvb_iattr;
3262306a36Sopenharmony_ci	__be32       lvb_igeneration;
3362306a36Sopenharmony_ci	__be32       lvb_reserved2;
3462306a36Sopenharmony_ci};
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_ci#define OCFS2_QINFO_LVB_VERSION 1
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_cistruct ocfs2_qinfo_lvb {
3962306a36Sopenharmony_ci	__u8	lvb_version;
4062306a36Sopenharmony_ci	__u8	lvb_reserved[3];
4162306a36Sopenharmony_ci	__be32	lvb_bgrace;
4262306a36Sopenharmony_ci	__be32	lvb_igrace;
4362306a36Sopenharmony_ci	__be32	lvb_syncms;
4462306a36Sopenharmony_ci	__be32	lvb_blocks;
4562306a36Sopenharmony_ci	__be32	lvb_free_blk;
4662306a36Sopenharmony_ci	__be32	lvb_free_entry;
4762306a36Sopenharmony_ci};
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_ci#define OCFS2_ORPHAN_LVB_VERSION 1
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_cistruct ocfs2_orphan_scan_lvb {
5262306a36Sopenharmony_ci	__u8	lvb_version;
5362306a36Sopenharmony_ci	__u8	lvb_reserved[3];
5462306a36Sopenharmony_ci	__be32	lvb_os_seqno;
5562306a36Sopenharmony_ci};
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_ci#define OCFS2_TRIMFS_LVB_VERSION 1
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_cistruct ocfs2_trim_fs_lvb {
6062306a36Sopenharmony_ci	__u8	lvb_version;
6162306a36Sopenharmony_ci	__u8	lvb_success;
6262306a36Sopenharmony_ci	__u8	lvb_reserved[2];
6362306a36Sopenharmony_ci	__be32	lvb_nodenum;
6462306a36Sopenharmony_ci	__be64	lvb_start;
6562306a36Sopenharmony_ci	__be64	lvb_len;
6662306a36Sopenharmony_ci	__be64	lvb_minlen;
6762306a36Sopenharmony_ci	__be64	lvb_trimlen;
6862306a36Sopenharmony_ci};
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_cistruct ocfs2_trim_fs_info {
7162306a36Sopenharmony_ci	u8	tf_valid;	/* lvb is valid, or not */
7262306a36Sopenharmony_ci	u8	tf_success;	/* trim is successful, or not */
7362306a36Sopenharmony_ci	u32	tf_nodenum;	/* osb node number */
7462306a36Sopenharmony_ci	u64	tf_start;	/* trim start offset in clusters */
7562306a36Sopenharmony_ci	u64	tf_len;		/* trim end offset in clusters */
7662306a36Sopenharmony_ci	u64	tf_minlen;	/* trim minimum contiguous free clusters */
7762306a36Sopenharmony_ci	u64	tf_trimlen;	/* trimmed length in bytes */
7862306a36Sopenharmony_ci};
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_cistruct ocfs2_lock_holder {
8162306a36Sopenharmony_ci	struct list_head oh_list;
8262306a36Sopenharmony_ci	struct pid *oh_owner_pid;
8362306a36Sopenharmony_ci	int oh_ex;
8462306a36Sopenharmony_ci};
8562306a36Sopenharmony_ci
8662306a36Sopenharmony_ci/* ocfs2_inode_lock_full() 'arg_flags' flags */
8762306a36Sopenharmony_ci/* don't wait on recovery. */
8862306a36Sopenharmony_ci#define OCFS2_META_LOCK_RECOVERY	(0x01)
8962306a36Sopenharmony_ci/* Instruct the dlm not to queue ourselves on the other node. */
9062306a36Sopenharmony_ci#define OCFS2_META_LOCK_NOQUEUE		(0x02)
9162306a36Sopenharmony_ci/* don't block waiting for the downconvert thread, instead return -EAGAIN */
9262306a36Sopenharmony_ci#define OCFS2_LOCK_NONBLOCK		(0x04)
9362306a36Sopenharmony_ci/* just get back disk inode bh if we've got cluster lock. */
9462306a36Sopenharmony_ci#define OCFS2_META_LOCK_GETBH		(0x08)
9562306a36Sopenharmony_ci
9662306a36Sopenharmony_ci/* Locking subclasses of inode cluster lock */
9762306a36Sopenharmony_cienum {
9862306a36Sopenharmony_ci	OI_LS_NORMAL = 0,
9962306a36Sopenharmony_ci	OI_LS_PARENT,
10062306a36Sopenharmony_ci	OI_LS_RENAME1,
10162306a36Sopenharmony_ci	OI_LS_RENAME2,
10262306a36Sopenharmony_ci	OI_LS_REFLINK_TARGET,
10362306a36Sopenharmony_ci};
10462306a36Sopenharmony_ci
10562306a36Sopenharmony_ciint ocfs2_dlm_init(struct ocfs2_super *osb);
10662306a36Sopenharmony_civoid ocfs2_dlm_shutdown(struct ocfs2_super *osb, int hangup_pending);
10762306a36Sopenharmony_civoid ocfs2_lock_res_init_once(struct ocfs2_lock_res *res);
10862306a36Sopenharmony_civoid ocfs2_inode_lock_res_init(struct ocfs2_lock_res *res,
10962306a36Sopenharmony_ci			       enum ocfs2_lock_type type,
11062306a36Sopenharmony_ci			       unsigned int generation,
11162306a36Sopenharmony_ci			       struct inode *inode);
11262306a36Sopenharmony_civoid ocfs2_dentry_lock_res_init(struct ocfs2_dentry_lock *dl,
11362306a36Sopenharmony_ci				u64 parent, struct inode *inode);
11462306a36Sopenharmony_cistruct ocfs2_file_private;
11562306a36Sopenharmony_civoid ocfs2_file_lock_res_init(struct ocfs2_lock_res *lockres,
11662306a36Sopenharmony_ci			      struct ocfs2_file_private *fp);
11762306a36Sopenharmony_cistruct ocfs2_mem_dqinfo;
11862306a36Sopenharmony_civoid ocfs2_qinfo_lock_res_init(struct ocfs2_lock_res *lockres,
11962306a36Sopenharmony_ci                               struct ocfs2_mem_dqinfo *info);
12062306a36Sopenharmony_civoid ocfs2_refcount_lock_res_init(struct ocfs2_lock_res *lockres,
12162306a36Sopenharmony_ci				  struct ocfs2_super *osb, u64 ref_blkno,
12262306a36Sopenharmony_ci				  unsigned int generation);
12362306a36Sopenharmony_civoid ocfs2_lock_res_free(struct ocfs2_lock_res *res);
12462306a36Sopenharmony_ciint ocfs2_create_new_inode_locks(struct inode *inode);
12562306a36Sopenharmony_ciint ocfs2_drop_inode_locks(struct inode *inode);
12662306a36Sopenharmony_ciint ocfs2_rw_lock(struct inode *inode, int write);
12762306a36Sopenharmony_ciint ocfs2_try_rw_lock(struct inode *inode, int write);
12862306a36Sopenharmony_civoid ocfs2_rw_unlock(struct inode *inode, int write);
12962306a36Sopenharmony_ciint ocfs2_open_lock(struct inode *inode);
13062306a36Sopenharmony_ciint ocfs2_try_open_lock(struct inode *inode, int write);
13162306a36Sopenharmony_civoid ocfs2_open_unlock(struct inode *inode);
13262306a36Sopenharmony_ciint ocfs2_inode_lock_atime(struct inode *inode,
13362306a36Sopenharmony_ci			  struct vfsmount *vfsmnt,
13462306a36Sopenharmony_ci			  int *level, int wait);
13562306a36Sopenharmony_ciint ocfs2_inode_lock_full_nested(struct inode *inode,
13662306a36Sopenharmony_ci			 struct buffer_head **ret_bh,
13762306a36Sopenharmony_ci			 int ex,
13862306a36Sopenharmony_ci			 int arg_flags,
13962306a36Sopenharmony_ci			 int subclass);
14062306a36Sopenharmony_ciint ocfs2_inode_lock_with_page(struct inode *inode,
14162306a36Sopenharmony_ci			      struct buffer_head **ret_bh,
14262306a36Sopenharmony_ci			      int ex,
14362306a36Sopenharmony_ci			      struct page *page);
14462306a36Sopenharmony_ci/* Variants without special locking class or flags */
14562306a36Sopenharmony_ci#define ocfs2_inode_lock_full(i, r, e, f)\
14662306a36Sopenharmony_ci		ocfs2_inode_lock_full_nested(i, r, e, f, OI_LS_NORMAL)
14762306a36Sopenharmony_ci#define ocfs2_inode_lock_nested(i, b, e, s)\
14862306a36Sopenharmony_ci		ocfs2_inode_lock_full_nested(i, b, e, 0, s)
14962306a36Sopenharmony_ci/* 99% of the time we don't want to supply any additional flags --
15062306a36Sopenharmony_ci * those are for very specific cases only. */
15162306a36Sopenharmony_ci#define ocfs2_inode_lock(i, b, e) ocfs2_inode_lock_full_nested(i, b, e, 0, OI_LS_NORMAL)
15262306a36Sopenharmony_ci#define ocfs2_try_inode_lock(i, b, e)\
15362306a36Sopenharmony_ci		ocfs2_inode_lock_full_nested(i, b, e, OCFS2_META_LOCK_NOQUEUE,\
15462306a36Sopenharmony_ci		OI_LS_NORMAL)
15562306a36Sopenharmony_civoid ocfs2_inode_unlock(struct inode *inode,
15662306a36Sopenharmony_ci		       int ex);
15762306a36Sopenharmony_ciint ocfs2_super_lock(struct ocfs2_super *osb,
15862306a36Sopenharmony_ci		     int ex);
15962306a36Sopenharmony_civoid ocfs2_super_unlock(struct ocfs2_super *osb,
16062306a36Sopenharmony_ci			int ex);
16162306a36Sopenharmony_ciint ocfs2_orphan_scan_lock(struct ocfs2_super *osb, u32 *seqno);
16262306a36Sopenharmony_civoid ocfs2_orphan_scan_unlock(struct ocfs2_super *osb, u32 seqno);
16362306a36Sopenharmony_ci
16462306a36Sopenharmony_ciint ocfs2_rename_lock(struct ocfs2_super *osb);
16562306a36Sopenharmony_civoid ocfs2_rename_unlock(struct ocfs2_super *osb);
16662306a36Sopenharmony_ciint ocfs2_nfs_sync_lock(struct ocfs2_super *osb, int ex);
16762306a36Sopenharmony_civoid ocfs2_nfs_sync_unlock(struct ocfs2_super *osb, int ex);
16862306a36Sopenharmony_civoid ocfs2_trim_fs_lock_res_init(struct ocfs2_super *osb);
16962306a36Sopenharmony_civoid ocfs2_trim_fs_lock_res_uninit(struct ocfs2_super *osb);
17062306a36Sopenharmony_ciint ocfs2_trim_fs_lock(struct ocfs2_super *osb,
17162306a36Sopenharmony_ci		       struct ocfs2_trim_fs_info *info, int trylock);
17262306a36Sopenharmony_civoid ocfs2_trim_fs_unlock(struct ocfs2_super *osb,
17362306a36Sopenharmony_ci			  struct ocfs2_trim_fs_info *info);
17462306a36Sopenharmony_ciint ocfs2_dentry_lock(struct dentry *dentry, int ex);
17562306a36Sopenharmony_civoid ocfs2_dentry_unlock(struct dentry *dentry, int ex);
17662306a36Sopenharmony_ciint ocfs2_file_lock(struct file *file, int ex, int trylock);
17762306a36Sopenharmony_civoid ocfs2_file_unlock(struct file *file);
17862306a36Sopenharmony_ciint ocfs2_qinfo_lock(struct ocfs2_mem_dqinfo *oinfo, int ex);
17962306a36Sopenharmony_civoid ocfs2_qinfo_unlock(struct ocfs2_mem_dqinfo *oinfo, int ex);
18062306a36Sopenharmony_cistruct ocfs2_refcount_tree;
18162306a36Sopenharmony_ciint ocfs2_refcount_lock(struct ocfs2_refcount_tree *ref_tree, int ex);
18262306a36Sopenharmony_civoid ocfs2_refcount_unlock(struct ocfs2_refcount_tree *ref_tree, int ex);
18362306a36Sopenharmony_ci
18462306a36Sopenharmony_ci
18562306a36Sopenharmony_civoid ocfs2_mark_lockres_freeing(struct ocfs2_super *osb,
18662306a36Sopenharmony_ci				struct ocfs2_lock_res *lockres);
18762306a36Sopenharmony_civoid ocfs2_simple_drop_lockres(struct ocfs2_super *osb,
18862306a36Sopenharmony_ci			       struct ocfs2_lock_res *lockres);
18962306a36Sopenharmony_ci
19062306a36Sopenharmony_ci/* for the downconvert thread */
19162306a36Sopenharmony_civoid ocfs2_wake_downconvert_thread(struct ocfs2_super *osb);
19262306a36Sopenharmony_ci
19362306a36Sopenharmony_cistruct ocfs2_dlm_debug *ocfs2_new_dlm_debug(void);
19462306a36Sopenharmony_civoid ocfs2_put_dlm_debug(struct ocfs2_dlm_debug *dlm_debug);
19562306a36Sopenharmony_ci
19662306a36Sopenharmony_ci/* To set the locking protocol on module initialization */
19762306a36Sopenharmony_civoid ocfs2_set_locking_protocol(void);
19862306a36Sopenharmony_ci
19962306a36Sopenharmony_ci/* The _tracker pair is used to avoid cluster recursive locking */
20062306a36Sopenharmony_ciint ocfs2_inode_lock_tracker(struct inode *inode,
20162306a36Sopenharmony_ci			     struct buffer_head **ret_bh,
20262306a36Sopenharmony_ci			     int ex,
20362306a36Sopenharmony_ci			     struct ocfs2_lock_holder *oh);
20462306a36Sopenharmony_civoid ocfs2_inode_unlock_tracker(struct inode *inode,
20562306a36Sopenharmony_ci				int ex,
20662306a36Sopenharmony_ci				struct ocfs2_lock_holder *oh,
20762306a36Sopenharmony_ci				int had_lock);
20862306a36Sopenharmony_ci
20962306a36Sopenharmony_ci#endif	/* DLMGLUE_H */
210