18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/* -*- mode: c; c-basic-offset: 8; -*-
38c2ecf20Sopenharmony_ci * vim: noexpandtab sw=8 ts=8 sts=0:
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * dlmglue.h
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * description here
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * Copyright (C) 2002, 2004 Oracle.  All rights reserved.
108c2ecf20Sopenharmony_ci */
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#ifndef DLMGLUE_H
148c2ecf20Sopenharmony_ci#define DLMGLUE_H
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#include "dcache.h"
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci#define OCFS2_LVB_VERSION 5
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_cistruct ocfs2_meta_lvb {
218c2ecf20Sopenharmony_ci	__u8         lvb_version;
228c2ecf20Sopenharmony_ci	__u8         lvb_reserved0;
238c2ecf20Sopenharmony_ci	__be16       lvb_idynfeatures;
248c2ecf20Sopenharmony_ci	__be32       lvb_iclusters;
258c2ecf20Sopenharmony_ci	__be32       lvb_iuid;
268c2ecf20Sopenharmony_ci	__be32       lvb_igid;
278c2ecf20Sopenharmony_ci	__be64       lvb_iatime_packed;
288c2ecf20Sopenharmony_ci	__be64       lvb_ictime_packed;
298c2ecf20Sopenharmony_ci	__be64       lvb_imtime_packed;
308c2ecf20Sopenharmony_ci	__be64       lvb_isize;
318c2ecf20Sopenharmony_ci	__be16       lvb_imode;
328c2ecf20Sopenharmony_ci	__be16       lvb_inlink;
338c2ecf20Sopenharmony_ci	__be32       lvb_iattr;
348c2ecf20Sopenharmony_ci	__be32       lvb_igeneration;
358c2ecf20Sopenharmony_ci	__be32       lvb_reserved2;
368c2ecf20Sopenharmony_ci};
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci#define OCFS2_QINFO_LVB_VERSION 1
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_cistruct ocfs2_qinfo_lvb {
418c2ecf20Sopenharmony_ci	__u8	lvb_version;
428c2ecf20Sopenharmony_ci	__u8	lvb_reserved[3];
438c2ecf20Sopenharmony_ci	__be32	lvb_bgrace;
448c2ecf20Sopenharmony_ci	__be32	lvb_igrace;
458c2ecf20Sopenharmony_ci	__be32	lvb_syncms;
468c2ecf20Sopenharmony_ci	__be32	lvb_blocks;
478c2ecf20Sopenharmony_ci	__be32	lvb_free_blk;
488c2ecf20Sopenharmony_ci	__be32	lvb_free_entry;
498c2ecf20Sopenharmony_ci};
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci#define OCFS2_ORPHAN_LVB_VERSION 1
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_cistruct ocfs2_orphan_scan_lvb {
548c2ecf20Sopenharmony_ci	__u8	lvb_version;
558c2ecf20Sopenharmony_ci	__u8	lvb_reserved[3];
568c2ecf20Sopenharmony_ci	__be32	lvb_os_seqno;
578c2ecf20Sopenharmony_ci};
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci#define OCFS2_TRIMFS_LVB_VERSION 1
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_cistruct ocfs2_trim_fs_lvb {
628c2ecf20Sopenharmony_ci	__u8	lvb_version;
638c2ecf20Sopenharmony_ci	__u8	lvb_success;
648c2ecf20Sopenharmony_ci	__u8	lvb_reserved[2];
658c2ecf20Sopenharmony_ci	__be32	lvb_nodenum;
668c2ecf20Sopenharmony_ci	__be64	lvb_start;
678c2ecf20Sopenharmony_ci	__be64	lvb_len;
688c2ecf20Sopenharmony_ci	__be64	lvb_minlen;
698c2ecf20Sopenharmony_ci	__be64	lvb_trimlen;
708c2ecf20Sopenharmony_ci};
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_cistruct ocfs2_trim_fs_info {
738c2ecf20Sopenharmony_ci	u8	tf_valid;	/* lvb is valid, or not */
748c2ecf20Sopenharmony_ci	u8	tf_success;	/* trim is successful, or not */
758c2ecf20Sopenharmony_ci	u32	tf_nodenum;	/* osb node number */
768c2ecf20Sopenharmony_ci	u64	tf_start;	/* trim start offset in clusters */
778c2ecf20Sopenharmony_ci	u64	tf_len;		/* trim end offset in clusters */
788c2ecf20Sopenharmony_ci	u64	tf_minlen;	/* trim minimum contiguous free clusters */
798c2ecf20Sopenharmony_ci	u64	tf_trimlen;	/* trimmed length in bytes */
808c2ecf20Sopenharmony_ci};
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_cistruct ocfs2_lock_holder {
838c2ecf20Sopenharmony_ci	struct list_head oh_list;
848c2ecf20Sopenharmony_ci	struct pid *oh_owner_pid;
858c2ecf20Sopenharmony_ci	int oh_ex;
868c2ecf20Sopenharmony_ci};
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci/* ocfs2_inode_lock_full() 'arg_flags' flags */
898c2ecf20Sopenharmony_ci/* don't wait on recovery. */
908c2ecf20Sopenharmony_ci#define OCFS2_META_LOCK_RECOVERY	(0x01)
918c2ecf20Sopenharmony_ci/* Instruct the dlm not to queue ourselves on the other node. */
928c2ecf20Sopenharmony_ci#define OCFS2_META_LOCK_NOQUEUE		(0x02)
938c2ecf20Sopenharmony_ci/* don't block waiting for the downconvert thread, instead return -EAGAIN */
948c2ecf20Sopenharmony_ci#define OCFS2_LOCK_NONBLOCK		(0x04)
958c2ecf20Sopenharmony_ci/* just get back disk inode bh if we've got cluster lock. */
968c2ecf20Sopenharmony_ci#define OCFS2_META_LOCK_GETBH		(0x08)
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci/* Locking subclasses of inode cluster lock */
998c2ecf20Sopenharmony_cienum {
1008c2ecf20Sopenharmony_ci	OI_LS_NORMAL = 0,
1018c2ecf20Sopenharmony_ci	OI_LS_PARENT,
1028c2ecf20Sopenharmony_ci	OI_LS_RENAME1,
1038c2ecf20Sopenharmony_ci	OI_LS_RENAME2,
1048c2ecf20Sopenharmony_ci	OI_LS_REFLINK_TARGET,
1058c2ecf20Sopenharmony_ci};
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ciint ocfs2_dlm_init(struct ocfs2_super *osb);
1088c2ecf20Sopenharmony_civoid ocfs2_dlm_shutdown(struct ocfs2_super *osb, int hangup_pending);
1098c2ecf20Sopenharmony_civoid ocfs2_lock_res_init_once(struct ocfs2_lock_res *res);
1108c2ecf20Sopenharmony_civoid ocfs2_inode_lock_res_init(struct ocfs2_lock_res *res,
1118c2ecf20Sopenharmony_ci			       enum ocfs2_lock_type type,
1128c2ecf20Sopenharmony_ci			       unsigned int generation,
1138c2ecf20Sopenharmony_ci			       struct inode *inode);
1148c2ecf20Sopenharmony_civoid ocfs2_dentry_lock_res_init(struct ocfs2_dentry_lock *dl,
1158c2ecf20Sopenharmony_ci				u64 parent, struct inode *inode);
1168c2ecf20Sopenharmony_cistruct ocfs2_file_private;
1178c2ecf20Sopenharmony_civoid ocfs2_file_lock_res_init(struct ocfs2_lock_res *lockres,
1188c2ecf20Sopenharmony_ci			      struct ocfs2_file_private *fp);
1198c2ecf20Sopenharmony_cistruct ocfs2_mem_dqinfo;
1208c2ecf20Sopenharmony_civoid ocfs2_qinfo_lock_res_init(struct ocfs2_lock_res *lockres,
1218c2ecf20Sopenharmony_ci                               struct ocfs2_mem_dqinfo *info);
1228c2ecf20Sopenharmony_civoid ocfs2_refcount_lock_res_init(struct ocfs2_lock_res *lockres,
1238c2ecf20Sopenharmony_ci				  struct ocfs2_super *osb, u64 ref_blkno,
1248c2ecf20Sopenharmony_ci				  unsigned int generation);
1258c2ecf20Sopenharmony_civoid ocfs2_lock_res_free(struct ocfs2_lock_res *res);
1268c2ecf20Sopenharmony_ciint ocfs2_create_new_inode_locks(struct inode *inode);
1278c2ecf20Sopenharmony_ciint ocfs2_drop_inode_locks(struct inode *inode);
1288c2ecf20Sopenharmony_ciint ocfs2_rw_lock(struct inode *inode, int write);
1298c2ecf20Sopenharmony_ciint ocfs2_try_rw_lock(struct inode *inode, int write);
1308c2ecf20Sopenharmony_civoid ocfs2_rw_unlock(struct inode *inode, int write);
1318c2ecf20Sopenharmony_ciint ocfs2_open_lock(struct inode *inode);
1328c2ecf20Sopenharmony_ciint ocfs2_try_open_lock(struct inode *inode, int write);
1338c2ecf20Sopenharmony_civoid ocfs2_open_unlock(struct inode *inode);
1348c2ecf20Sopenharmony_ciint ocfs2_inode_lock_atime(struct inode *inode,
1358c2ecf20Sopenharmony_ci			  struct vfsmount *vfsmnt,
1368c2ecf20Sopenharmony_ci			  int *level, int wait);
1378c2ecf20Sopenharmony_ciint ocfs2_inode_lock_full_nested(struct inode *inode,
1388c2ecf20Sopenharmony_ci			 struct buffer_head **ret_bh,
1398c2ecf20Sopenharmony_ci			 int ex,
1408c2ecf20Sopenharmony_ci			 int arg_flags,
1418c2ecf20Sopenharmony_ci			 int subclass);
1428c2ecf20Sopenharmony_ciint ocfs2_inode_lock_with_page(struct inode *inode,
1438c2ecf20Sopenharmony_ci			      struct buffer_head **ret_bh,
1448c2ecf20Sopenharmony_ci			      int ex,
1458c2ecf20Sopenharmony_ci			      struct page *page);
1468c2ecf20Sopenharmony_ci/* Variants without special locking class or flags */
1478c2ecf20Sopenharmony_ci#define ocfs2_inode_lock_full(i, r, e, f)\
1488c2ecf20Sopenharmony_ci		ocfs2_inode_lock_full_nested(i, r, e, f, OI_LS_NORMAL)
1498c2ecf20Sopenharmony_ci#define ocfs2_inode_lock_nested(i, b, e, s)\
1508c2ecf20Sopenharmony_ci		ocfs2_inode_lock_full_nested(i, b, e, 0, s)
1518c2ecf20Sopenharmony_ci/* 99% of the time we don't want to supply any additional flags --
1528c2ecf20Sopenharmony_ci * those are for very specific cases only. */
1538c2ecf20Sopenharmony_ci#define ocfs2_inode_lock(i, b, e) ocfs2_inode_lock_full_nested(i, b, e, 0, OI_LS_NORMAL)
1548c2ecf20Sopenharmony_ci#define ocfs2_try_inode_lock(i, b, e)\
1558c2ecf20Sopenharmony_ci		ocfs2_inode_lock_full_nested(i, b, e, OCFS2_META_LOCK_NOQUEUE,\
1568c2ecf20Sopenharmony_ci		OI_LS_NORMAL)
1578c2ecf20Sopenharmony_civoid ocfs2_inode_unlock(struct inode *inode,
1588c2ecf20Sopenharmony_ci		       int ex);
1598c2ecf20Sopenharmony_ciint ocfs2_super_lock(struct ocfs2_super *osb,
1608c2ecf20Sopenharmony_ci		     int ex);
1618c2ecf20Sopenharmony_civoid ocfs2_super_unlock(struct ocfs2_super *osb,
1628c2ecf20Sopenharmony_ci			int ex);
1638c2ecf20Sopenharmony_ciint ocfs2_orphan_scan_lock(struct ocfs2_super *osb, u32 *seqno);
1648c2ecf20Sopenharmony_civoid ocfs2_orphan_scan_unlock(struct ocfs2_super *osb, u32 seqno);
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ciint ocfs2_rename_lock(struct ocfs2_super *osb);
1678c2ecf20Sopenharmony_civoid ocfs2_rename_unlock(struct ocfs2_super *osb);
1688c2ecf20Sopenharmony_ciint ocfs2_nfs_sync_lock(struct ocfs2_super *osb, int ex);
1698c2ecf20Sopenharmony_civoid ocfs2_nfs_sync_unlock(struct ocfs2_super *osb, int ex);
1708c2ecf20Sopenharmony_civoid ocfs2_trim_fs_lock_res_init(struct ocfs2_super *osb);
1718c2ecf20Sopenharmony_civoid ocfs2_trim_fs_lock_res_uninit(struct ocfs2_super *osb);
1728c2ecf20Sopenharmony_ciint ocfs2_trim_fs_lock(struct ocfs2_super *osb,
1738c2ecf20Sopenharmony_ci		       struct ocfs2_trim_fs_info *info, int trylock);
1748c2ecf20Sopenharmony_civoid ocfs2_trim_fs_unlock(struct ocfs2_super *osb,
1758c2ecf20Sopenharmony_ci			  struct ocfs2_trim_fs_info *info);
1768c2ecf20Sopenharmony_ciint ocfs2_dentry_lock(struct dentry *dentry, int ex);
1778c2ecf20Sopenharmony_civoid ocfs2_dentry_unlock(struct dentry *dentry, int ex);
1788c2ecf20Sopenharmony_ciint ocfs2_file_lock(struct file *file, int ex, int trylock);
1798c2ecf20Sopenharmony_civoid ocfs2_file_unlock(struct file *file);
1808c2ecf20Sopenharmony_ciint ocfs2_qinfo_lock(struct ocfs2_mem_dqinfo *oinfo, int ex);
1818c2ecf20Sopenharmony_civoid ocfs2_qinfo_unlock(struct ocfs2_mem_dqinfo *oinfo, int ex);
1828c2ecf20Sopenharmony_cistruct ocfs2_refcount_tree;
1838c2ecf20Sopenharmony_ciint ocfs2_refcount_lock(struct ocfs2_refcount_tree *ref_tree, int ex);
1848c2ecf20Sopenharmony_civoid ocfs2_refcount_unlock(struct ocfs2_refcount_tree *ref_tree, int ex);
1858c2ecf20Sopenharmony_ci
1868c2ecf20Sopenharmony_ci
1878c2ecf20Sopenharmony_civoid ocfs2_mark_lockres_freeing(struct ocfs2_super *osb,
1888c2ecf20Sopenharmony_ci				struct ocfs2_lock_res *lockres);
1898c2ecf20Sopenharmony_civoid ocfs2_simple_drop_lockres(struct ocfs2_super *osb,
1908c2ecf20Sopenharmony_ci			       struct ocfs2_lock_res *lockres);
1918c2ecf20Sopenharmony_ci
1928c2ecf20Sopenharmony_ci/* for the downconvert thread */
1938c2ecf20Sopenharmony_civoid ocfs2_wake_downconvert_thread(struct ocfs2_super *osb);
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_cistruct ocfs2_dlm_debug *ocfs2_new_dlm_debug(void);
1968c2ecf20Sopenharmony_civoid ocfs2_put_dlm_debug(struct ocfs2_dlm_debug *dlm_debug);
1978c2ecf20Sopenharmony_ci
1988c2ecf20Sopenharmony_ci/* To set the locking protocol on module initialization */
1998c2ecf20Sopenharmony_civoid ocfs2_set_locking_protocol(void);
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_ci/* The _tracker pair is used to avoid cluster recursive locking */
2028c2ecf20Sopenharmony_ciint ocfs2_inode_lock_tracker(struct inode *inode,
2038c2ecf20Sopenharmony_ci			     struct buffer_head **ret_bh,
2048c2ecf20Sopenharmony_ci			     int ex,
2058c2ecf20Sopenharmony_ci			     struct ocfs2_lock_holder *oh);
2068c2ecf20Sopenharmony_civoid ocfs2_inode_unlock_tracker(struct inode *inode,
2078c2ecf20Sopenharmony_ci				int ex,
2088c2ecf20Sopenharmony_ci				struct ocfs2_lock_holder *oh,
2098c2ecf20Sopenharmony_ci				int had_lock);
2108c2ecf20Sopenharmony_ci
2118c2ecf20Sopenharmony_ci#endif	/* DLMGLUE_H */
212