18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
48c2ecf20Sopenharmony_ci * All Rights Reserved.
58c2ecf20Sopenharmony_ci */
68c2ecf20Sopenharmony_ci#ifndef	__XFS_INODE_H__
78c2ecf20Sopenharmony_ci#define	__XFS_INODE_H__
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#include "xfs_inode_buf.h"
108c2ecf20Sopenharmony_ci#include "xfs_inode_fork.h"
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci/*
138c2ecf20Sopenharmony_ci * Kernel only inode definitions
148c2ecf20Sopenharmony_ci */
158c2ecf20Sopenharmony_cistruct xfs_dinode;
168c2ecf20Sopenharmony_cistruct xfs_inode;
178c2ecf20Sopenharmony_cistruct xfs_buf;
188c2ecf20Sopenharmony_cistruct xfs_bmbt_irec;
198c2ecf20Sopenharmony_cistruct xfs_inode_log_item;
208c2ecf20Sopenharmony_cistruct xfs_mount;
218c2ecf20Sopenharmony_cistruct xfs_trans;
228c2ecf20Sopenharmony_cistruct xfs_dquot;
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_citypedef struct xfs_inode {
258c2ecf20Sopenharmony_ci	/* Inode linking and identification information. */
268c2ecf20Sopenharmony_ci	struct xfs_mount	*i_mount;	/* fs mount struct ptr */
278c2ecf20Sopenharmony_ci	struct xfs_dquot	*i_udquot;	/* user dquot */
288c2ecf20Sopenharmony_ci	struct xfs_dquot	*i_gdquot;	/* group dquot */
298c2ecf20Sopenharmony_ci	struct xfs_dquot	*i_pdquot;	/* project dquot */
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci	/* Inode location stuff */
328c2ecf20Sopenharmony_ci	xfs_ino_t		i_ino;		/* inode number (agno/agino)*/
338c2ecf20Sopenharmony_ci	struct xfs_imap		i_imap;		/* location for xfs_imap() */
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci	/* Extent information. */
368c2ecf20Sopenharmony_ci	struct xfs_ifork	*i_afp;		/* attribute fork pointer */
378c2ecf20Sopenharmony_ci	struct xfs_ifork	*i_cowfp;	/* copy on write extents */
388c2ecf20Sopenharmony_ci	struct xfs_ifork	i_df;		/* data fork */
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci	/* Transaction and locking information. */
418c2ecf20Sopenharmony_ci	struct xfs_inode_log_item *i_itemp;	/* logging information */
428c2ecf20Sopenharmony_ci	mrlock_t		i_lock;		/* inode lock */
438c2ecf20Sopenharmony_ci	mrlock_t		i_mmaplock;	/* inode mmap IO lock */
448c2ecf20Sopenharmony_ci	atomic_t		i_pincount;	/* inode pin count */
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci	/*
478c2ecf20Sopenharmony_ci	 * Bitsets of inode metadata that have been checked and/or are sick.
488c2ecf20Sopenharmony_ci	 * Callers must hold i_flags_lock before accessing this field.
498c2ecf20Sopenharmony_ci	 */
508c2ecf20Sopenharmony_ci	uint16_t		i_checked;
518c2ecf20Sopenharmony_ci	uint16_t		i_sick;
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci	spinlock_t		i_flags_lock;	/* inode i_flags lock */
548c2ecf20Sopenharmony_ci	/* Miscellaneous state. */
558c2ecf20Sopenharmony_ci	unsigned long		i_flags;	/* see defined flags below */
568c2ecf20Sopenharmony_ci	uint64_t		i_delayed_blks;	/* count of delay alloc blks */
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci	struct xfs_icdinode	i_d;		/* most of ondisk inode */
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci	/* VFS inode */
618c2ecf20Sopenharmony_ci	struct inode		i_vnode;	/* embedded VFS inode */
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci	/* pending io completions */
648c2ecf20Sopenharmony_ci	spinlock_t		i_ioend_lock;
658c2ecf20Sopenharmony_ci	struct work_struct	i_ioend_work;
668c2ecf20Sopenharmony_ci	struct list_head	i_ioend_list;
678c2ecf20Sopenharmony_ci} xfs_inode_t;
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci/* Convert from vfs inode to xfs inode */
708c2ecf20Sopenharmony_cistatic inline struct xfs_inode *XFS_I(struct inode *inode)
718c2ecf20Sopenharmony_ci{
728c2ecf20Sopenharmony_ci	return container_of(inode, struct xfs_inode, i_vnode);
738c2ecf20Sopenharmony_ci}
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci/* convert from xfs inode to vfs inode */
768c2ecf20Sopenharmony_cistatic inline struct inode *VFS_I(struct xfs_inode *ip)
778c2ecf20Sopenharmony_ci{
788c2ecf20Sopenharmony_ci	return &ip->i_vnode;
798c2ecf20Sopenharmony_ci}
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci/*
828c2ecf20Sopenharmony_ci * For regular files we only update the on-disk filesize when actually
838c2ecf20Sopenharmony_ci * writing data back to disk.  Until then only the copy in the VFS inode
848c2ecf20Sopenharmony_ci * is uptodate.
858c2ecf20Sopenharmony_ci */
868c2ecf20Sopenharmony_cistatic inline xfs_fsize_t XFS_ISIZE(struct xfs_inode *ip)
878c2ecf20Sopenharmony_ci{
888c2ecf20Sopenharmony_ci	if (S_ISREG(VFS_I(ip)->i_mode))
898c2ecf20Sopenharmony_ci		return i_size_read(VFS_I(ip));
908c2ecf20Sopenharmony_ci	return ip->i_d.di_size;
918c2ecf20Sopenharmony_ci}
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci/*
948c2ecf20Sopenharmony_ci * If this I/O goes past the on-disk inode size update it unless it would
958c2ecf20Sopenharmony_ci * be past the current in-core inode size.
968c2ecf20Sopenharmony_ci */
978c2ecf20Sopenharmony_cistatic inline xfs_fsize_t
988c2ecf20Sopenharmony_cixfs_new_eof(struct xfs_inode *ip, xfs_fsize_t new_size)
998c2ecf20Sopenharmony_ci{
1008c2ecf20Sopenharmony_ci	xfs_fsize_t i_size = i_size_read(VFS_I(ip));
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ci	if (new_size > i_size || new_size < 0)
1038c2ecf20Sopenharmony_ci		new_size = i_size;
1048c2ecf20Sopenharmony_ci	return new_size > ip->i_d.di_size ? new_size : 0;
1058c2ecf20Sopenharmony_ci}
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci/*
1088c2ecf20Sopenharmony_ci * i_flags helper functions
1098c2ecf20Sopenharmony_ci */
1108c2ecf20Sopenharmony_cistatic inline void
1118c2ecf20Sopenharmony_ci__xfs_iflags_set(xfs_inode_t *ip, unsigned short flags)
1128c2ecf20Sopenharmony_ci{
1138c2ecf20Sopenharmony_ci	ip->i_flags |= flags;
1148c2ecf20Sopenharmony_ci}
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_cistatic inline void
1178c2ecf20Sopenharmony_cixfs_iflags_set(xfs_inode_t *ip, unsigned short flags)
1188c2ecf20Sopenharmony_ci{
1198c2ecf20Sopenharmony_ci	spin_lock(&ip->i_flags_lock);
1208c2ecf20Sopenharmony_ci	__xfs_iflags_set(ip, flags);
1218c2ecf20Sopenharmony_ci	spin_unlock(&ip->i_flags_lock);
1228c2ecf20Sopenharmony_ci}
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_cistatic inline void
1258c2ecf20Sopenharmony_cixfs_iflags_clear(xfs_inode_t *ip, unsigned short flags)
1268c2ecf20Sopenharmony_ci{
1278c2ecf20Sopenharmony_ci	spin_lock(&ip->i_flags_lock);
1288c2ecf20Sopenharmony_ci	ip->i_flags &= ~flags;
1298c2ecf20Sopenharmony_ci	spin_unlock(&ip->i_flags_lock);
1308c2ecf20Sopenharmony_ci}
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_cistatic inline int
1338c2ecf20Sopenharmony_ci__xfs_iflags_test(xfs_inode_t *ip, unsigned short flags)
1348c2ecf20Sopenharmony_ci{
1358c2ecf20Sopenharmony_ci	return (ip->i_flags & flags);
1368c2ecf20Sopenharmony_ci}
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_cistatic inline int
1398c2ecf20Sopenharmony_cixfs_iflags_test(xfs_inode_t *ip, unsigned short flags)
1408c2ecf20Sopenharmony_ci{
1418c2ecf20Sopenharmony_ci	int ret;
1428c2ecf20Sopenharmony_ci	spin_lock(&ip->i_flags_lock);
1438c2ecf20Sopenharmony_ci	ret = __xfs_iflags_test(ip, flags);
1448c2ecf20Sopenharmony_ci	spin_unlock(&ip->i_flags_lock);
1458c2ecf20Sopenharmony_ci	return ret;
1468c2ecf20Sopenharmony_ci}
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_cistatic inline int
1498c2ecf20Sopenharmony_cixfs_iflags_test_and_clear(xfs_inode_t *ip, unsigned short flags)
1508c2ecf20Sopenharmony_ci{
1518c2ecf20Sopenharmony_ci	int ret;
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_ci	spin_lock(&ip->i_flags_lock);
1548c2ecf20Sopenharmony_ci	ret = ip->i_flags & flags;
1558c2ecf20Sopenharmony_ci	if (ret)
1568c2ecf20Sopenharmony_ci		ip->i_flags &= ~flags;
1578c2ecf20Sopenharmony_ci	spin_unlock(&ip->i_flags_lock);
1588c2ecf20Sopenharmony_ci	return ret;
1598c2ecf20Sopenharmony_ci}
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_cistatic inline int
1628c2ecf20Sopenharmony_cixfs_iflags_test_and_set(xfs_inode_t *ip, unsigned short flags)
1638c2ecf20Sopenharmony_ci{
1648c2ecf20Sopenharmony_ci	int ret;
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ci	spin_lock(&ip->i_flags_lock);
1678c2ecf20Sopenharmony_ci	ret = ip->i_flags & flags;
1688c2ecf20Sopenharmony_ci	if (!ret)
1698c2ecf20Sopenharmony_ci		ip->i_flags |= flags;
1708c2ecf20Sopenharmony_ci	spin_unlock(&ip->i_flags_lock);
1718c2ecf20Sopenharmony_ci	return ret;
1728c2ecf20Sopenharmony_ci}
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_cistatic inline prid_t
1758c2ecf20Sopenharmony_cixfs_get_initial_prid(struct xfs_inode *dp)
1768c2ecf20Sopenharmony_ci{
1778c2ecf20Sopenharmony_ci	if (dp->i_d.di_flags & XFS_DIFLAG_PROJINHERIT)
1788c2ecf20Sopenharmony_ci		return dp->i_d.di_projid;
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_ci	return XFS_PROJID_DEFAULT;
1818c2ecf20Sopenharmony_ci}
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_cistatic inline bool xfs_is_reflink_inode(struct xfs_inode *ip)
1848c2ecf20Sopenharmony_ci{
1858c2ecf20Sopenharmony_ci	return ip->i_d.di_flags2 & XFS_DIFLAG2_REFLINK;
1868c2ecf20Sopenharmony_ci}
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_ci/*
1898c2ecf20Sopenharmony_ci * Check if an inode has any data in the COW fork.  This might be often false
1908c2ecf20Sopenharmony_ci * even for inodes with the reflink flag when there is no pending COW operation.
1918c2ecf20Sopenharmony_ci */
1928c2ecf20Sopenharmony_cistatic inline bool xfs_inode_has_cow_data(struct xfs_inode *ip)
1938c2ecf20Sopenharmony_ci{
1948c2ecf20Sopenharmony_ci	return ip->i_cowfp && ip->i_cowfp->if_bytes;
1958c2ecf20Sopenharmony_ci}
1968c2ecf20Sopenharmony_ci
1978c2ecf20Sopenharmony_cistatic inline bool xfs_inode_has_bigtime(struct xfs_inode *ip)
1988c2ecf20Sopenharmony_ci{
1998c2ecf20Sopenharmony_ci	return ip->i_d.di_flags2 & XFS_DIFLAG2_BIGTIME;
2008c2ecf20Sopenharmony_ci}
2018c2ecf20Sopenharmony_ci
2028c2ecf20Sopenharmony_ci/*
2038c2ecf20Sopenharmony_ci * Return the buftarg used for data allocations on a given inode.
2048c2ecf20Sopenharmony_ci */
2058c2ecf20Sopenharmony_ci#define xfs_inode_buftarg(ip) \
2068c2ecf20Sopenharmony_ci	(XFS_IS_REALTIME_INODE(ip) ? \
2078c2ecf20Sopenharmony_ci		(ip)->i_mount->m_rtdev_targp : (ip)->i_mount->m_ddev_targp)
2088c2ecf20Sopenharmony_ci
2098c2ecf20Sopenharmony_ci/*
2108c2ecf20Sopenharmony_ci * In-core inode flags.
2118c2ecf20Sopenharmony_ci */
2128c2ecf20Sopenharmony_ci#define XFS_IRECLAIM		(1 << 0) /* started reclaiming this inode */
2138c2ecf20Sopenharmony_ci#define XFS_ISTALE		(1 << 1) /* inode has been staled */
2148c2ecf20Sopenharmony_ci#define XFS_IRECLAIMABLE	(1 << 2) /* inode can be reclaimed */
2158c2ecf20Sopenharmony_ci#define __XFS_INEW_BIT		3	 /* inode has just been allocated */
2168c2ecf20Sopenharmony_ci#define XFS_INEW		(1 << __XFS_INEW_BIT)
2178c2ecf20Sopenharmony_ci#define XFS_ITRUNCATED		(1 << 5) /* truncated down so flush-on-close */
2188c2ecf20Sopenharmony_ci#define XFS_IDIRTY_RELEASE	(1 << 6) /* dirty release already seen */
2198c2ecf20Sopenharmony_ci#define XFS_IFLUSHING		(1 << 7) /* inode is being flushed */
2208c2ecf20Sopenharmony_ci#define __XFS_IPINNED_BIT	8	 /* wakeup key for zero pin count */
2218c2ecf20Sopenharmony_ci#define XFS_IPINNED		(1 << __XFS_IPINNED_BIT)
2228c2ecf20Sopenharmony_ci#define XFS_IEOFBLOCKS		(1 << 9) /* has the preallocblocks tag set */
2238c2ecf20Sopenharmony_ci/*
2248c2ecf20Sopenharmony_ci * If this unlinked inode is in the middle of recovery, don't let drop_inode
2258c2ecf20Sopenharmony_ci * truncate and free the inode.  This can happen if we iget the inode during
2268c2ecf20Sopenharmony_ci * log recovery to replay a bmap operation on the inode.
2278c2ecf20Sopenharmony_ci */
2288c2ecf20Sopenharmony_ci#define XFS_IRECOVERY		(1 << 11)
2298c2ecf20Sopenharmony_ci#define XFS_ICOWBLOCKS		(1 << 12)/* has the cowblocks tag set */
2308c2ecf20Sopenharmony_ci
2318c2ecf20Sopenharmony_ci/*
2328c2ecf20Sopenharmony_ci * Per-lifetime flags need to be reset when re-using a reclaimable inode during
2338c2ecf20Sopenharmony_ci * inode lookup. This prevents unintended behaviour on the new inode from
2348c2ecf20Sopenharmony_ci * ocurring.
2358c2ecf20Sopenharmony_ci */
2368c2ecf20Sopenharmony_ci#define XFS_IRECLAIM_RESET_FLAGS	\
2378c2ecf20Sopenharmony_ci	(XFS_IRECLAIMABLE | XFS_IRECLAIM | \
2388c2ecf20Sopenharmony_ci	 XFS_IDIRTY_RELEASE | XFS_ITRUNCATED)
2398c2ecf20Sopenharmony_ci
2408c2ecf20Sopenharmony_ci/*
2418c2ecf20Sopenharmony_ci * Flags for inode locking.
2428c2ecf20Sopenharmony_ci * Bit ranges:	1<<1  - 1<<16-1 -- iolock/ilock modes (bitfield)
2438c2ecf20Sopenharmony_ci *		1<<16 - 1<<32-1 -- lockdep annotation (integers)
2448c2ecf20Sopenharmony_ci */
2458c2ecf20Sopenharmony_ci#define	XFS_IOLOCK_EXCL		(1<<0)
2468c2ecf20Sopenharmony_ci#define	XFS_IOLOCK_SHARED	(1<<1)
2478c2ecf20Sopenharmony_ci#define	XFS_ILOCK_EXCL		(1<<2)
2488c2ecf20Sopenharmony_ci#define	XFS_ILOCK_SHARED	(1<<3)
2498c2ecf20Sopenharmony_ci#define	XFS_MMAPLOCK_EXCL	(1<<4)
2508c2ecf20Sopenharmony_ci#define	XFS_MMAPLOCK_SHARED	(1<<5)
2518c2ecf20Sopenharmony_ci
2528c2ecf20Sopenharmony_ci#define XFS_LOCK_MASK		(XFS_IOLOCK_EXCL | XFS_IOLOCK_SHARED \
2538c2ecf20Sopenharmony_ci				| XFS_ILOCK_EXCL | XFS_ILOCK_SHARED \
2548c2ecf20Sopenharmony_ci				| XFS_MMAPLOCK_EXCL | XFS_MMAPLOCK_SHARED)
2558c2ecf20Sopenharmony_ci
2568c2ecf20Sopenharmony_ci#define XFS_LOCK_FLAGS \
2578c2ecf20Sopenharmony_ci	{ XFS_IOLOCK_EXCL,	"IOLOCK_EXCL" }, \
2588c2ecf20Sopenharmony_ci	{ XFS_IOLOCK_SHARED,	"IOLOCK_SHARED" }, \
2598c2ecf20Sopenharmony_ci	{ XFS_ILOCK_EXCL,	"ILOCK_EXCL" }, \
2608c2ecf20Sopenharmony_ci	{ XFS_ILOCK_SHARED,	"ILOCK_SHARED" }, \
2618c2ecf20Sopenharmony_ci	{ XFS_MMAPLOCK_EXCL,	"MMAPLOCK_EXCL" }, \
2628c2ecf20Sopenharmony_ci	{ XFS_MMAPLOCK_SHARED,	"MMAPLOCK_SHARED" }
2638c2ecf20Sopenharmony_ci
2648c2ecf20Sopenharmony_ci
2658c2ecf20Sopenharmony_ci/*
2668c2ecf20Sopenharmony_ci * Flags for lockdep annotations.
2678c2ecf20Sopenharmony_ci *
2688c2ecf20Sopenharmony_ci * XFS_LOCK_PARENT - for directory operations that require locking a
2698c2ecf20Sopenharmony_ci * parent directory inode and a child entry inode. IOLOCK requires nesting,
2708c2ecf20Sopenharmony_ci * MMAPLOCK does not support this class, ILOCK requires a single subclass
2718c2ecf20Sopenharmony_ci * to differentiate parent from child.
2728c2ecf20Sopenharmony_ci *
2738c2ecf20Sopenharmony_ci * XFS_LOCK_RTBITMAP/XFS_LOCK_RTSUM - the realtime device bitmap and summary
2748c2ecf20Sopenharmony_ci * inodes do not participate in the normal lock order, and thus have their
2758c2ecf20Sopenharmony_ci * own subclasses.
2768c2ecf20Sopenharmony_ci *
2778c2ecf20Sopenharmony_ci * XFS_LOCK_INUMORDER - for locking several inodes at the some time
2788c2ecf20Sopenharmony_ci * with xfs_lock_inodes().  This flag is used as the starting subclass
2798c2ecf20Sopenharmony_ci * and each subsequent lock acquired will increment the subclass by one.
2808c2ecf20Sopenharmony_ci * However, MAX_LOCKDEP_SUBCLASSES == 8, which means we are greatly
2818c2ecf20Sopenharmony_ci * limited to the subclasses we can represent via nesting. We need at least
2828c2ecf20Sopenharmony_ci * 5 inodes nest depth for the ILOCK through rename, and we also have to support
2838c2ecf20Sopenharmony_ci * XFS_ILOCK_PARENT, which gives 6 subclasses. Then we have XFS_ILOCK_RTBITMAP
2848c2ecf20Sopenharmony_ci * and XFS_ILOCK_RTSUM, which are another 2 unique subclasses, so that's all
2858c2ecf20Sopenharmony_ci * 8 subclasses supported by lockdep.
2868c2ecf20Sopenharmony_ci *
2878c2ecf20Sopenharmony_ci * This also means we have to number the sub-classes in the lowest bits of
2888c2ecf20Sopenharmony_ci * the mask we keep, and we have to ensure we never exceed 3 bits of lockdep
2898c2ecf20Sopenharmony_ci * mask and we can't use bit-masking to build the subclasses. What a mess.
2908c2ecf20Sopenharmony_ci *
2918c2ecf20Sopenharmony_ci * Bit layout:
2928c2ecf20Sopenharmony_ci *
2938c2ecf20Sopenharmony_ci * Bit		Lock Region
2948c2ecf20Sopenharmony_ci * 16-19	XFS_IOLOCK_SHIFT dependencies
2958c2ecf20Sopenharmony_ci * 20-23	XFS_MMAPLOCK_SHIFT dependencies
2968c2ecf20Sopenharmony_ci * 24-31	XFS_ILOCK_SHIFT dependencies
2978c2ecf20Sopenharmony_ci *
2988c2ecf20Sopenharmony_ci * IOLOCK values
2998c2ecf20Sopenharmony_ci *
3008c2ecf20Sopenharmony_ci * 0-3		subclass value
3018c2ecf20Sopenharmony_ci * 4-7		unused
3028c2ecf20Sopenharmony_ci *
3038c2ecf20Sopenharmony_ci * MMAPLOCK values
3048c2ecf20Sopenharmony_ci *
3058c2ecf20Sopenharmony_ci * 0-3		subclass value
3068c2ecf20Sopenharmony_ci * 4-7		unused
3078c2ecf20Sopenharmony_ci *
3088c2ecf20Sopenharmony_ci * ILOCK values
3098c2ecf20Sopenharmony_ci * 0-4		subclass values
3108c2ecf20Sopenharmony_ci * 5		PARENT subclass (not nestable)
3118c2ecf20Sopenharmony_ci * 6		RTBITMAP subclass (not nestable)
3128c2ecf20Sopenharmony_ci * 7		RTSUM subclass (not nestable)
3138c2ecf20Sopenharmony_ci *
3148c2ecf20Sopenharmony_ci */
3158c2ecf20Sopenharmony_ci#define XFS_IOLOCK_SHIFT		16
3168c2ecf20Sopenharmony_ci#define XFS_IOLOCK_MAX_SUBCLASS		3
3178c2ecf20Sopenharmony_ci#define XFS_IOLOCK_DEP_MASK		0x000f0000
3188c2ecf20Sopenharmony_ci
3198c2ecf20Sopenharmony_ci#define XFS_MMAPLOCK_SHIFT		20
3208c2ecf20Sopenharmony_ci#define XFS_MMAPLOCK_NUMORDER		0
3218c2ecf20Sopenharmony_ci#define XFS_MMAPLOCK_MAX_SUBCLASS	3
3228c2ecf20Sopenharmony_ci#define XFS_MMAPLOCK_DEP_MASK		0x00f00000
3238c2ecf20Sopenharmony_ci
3248c2ecf20Sopenharmony_ci#define XFS_ILOCK_SHIFT			24
3258c2ecf20Sopenharmony_ci#define XFS_ILOCK_PARENT_VAL		5
3268c2ecf20Sopenharmony_ci#define XFS_ILOCK_MAX_SUBCLASS		(XFS_ILOCK_PARENT_VAL - 1)
3278c2ecf20Sopenharmony_ci#define XFS_ILOCK_RTBITMAP_VAL		6
3288c2ecf20Sopenharmony_ci#define XFS_ILOCK_RTSUM_VAL		7
3298c2ecf20Sopenharmony_ci#define XFS_ILOCK_DEP_MASK		0xff000000
3308c2ecf20Sopenharmony_ci#define	XFS_ILOCK_PARENT		(XFS_ILOCK_PARENT_VAL << XFS_ILOCK_SHIFT)
3318c2ecf20Sopenharmony_ci#define	XFS_ILOCK_RTBITMAP		(XFS_ILOCK_RTBITMAP_VAL << XFS_ILOCK_SHIFT)
3328c2ecf20Sopenharmony_ci#define	XFS_ILOCK_RTSUM			(XFS_ILOCK_RTSUM_VAL << XFS_ILOCK_SHIFT)
3338c2ecf20Sopenharmony_ci
3348c2ecf20Sopenharmony_ci#define XFS_LOCK_SUBCLASS_MASK	(XFS_IOLOCK_DEP_MASK | \
3358c2ecf20Sopenharmony_ci				 XFS_MMAPLOCK_DEP_MASK | \
3368c2ecf20Sopenharmony_ci				 XFS_ILOCK_DEP_MASK)
3378c2ecf20Sopenharmony_ci
3388c2ecf20Sopenharmony_ci#define XFS_IOLOCK_DEP(flags)	(((flags) & XFS_IOLOCK_DEP_MASK) \
3398c2ecf20Sopenharmony_ci					>> XFS_IOLOCK_SHIFT)
3408c2ecf20Sopenharmony_ci#define XFS_MMAPLOCK_DEP(flags)	(((flags) & XFS_MMAPLOCK_DEP_MASK) \
3418c2ecf20Sopenharmony_ci					>> XFS_MMAPLOCK_SHIFT)
3428c2ecf20Sopenharmony_ci#define XFS_ILOCK_DEP(flags)	(((flags) & XFS_ILOCK_DEP_MASK) \
3438c2ecf20Sopenharmony_ci					>> XFS_ILOCK_SHIFT)
3448c2ecf20Sopenharmony_ci
3458c2ecf20Sopenharmony_ci/*
3468c2ecf20Sopenharmony_ci * Layouts are broken in the BREAK_WRITE case to ensure that
3478c2ecf20Sopenharmony_ci * layout-holders do not collide with local writes. Additionally,
3488c2ecf20Sopenharmony_ci * layouts are broken in the BREAK_UNMAP case to make sure the
3498c2ecf20Sopenharmony_ci * layout-holder has a consistent view of the file's extent map. While
3508c2ecf20Sopenharmony_ci * BREAK_WRITE breaks can be satisfied by recalling FL_LAYOUT leases,
3518c2ecf20Sopenharmony_ci * BREAK_UNMAP breaks additionally require waiting for busy dax-pages to
3528c2ecf20Sopenharmony_ci * go idle.
3538c2ecf20Sopenharmony_ci */
3548c2ecf20Sopenharmony_cienum layout_break_reason {
3558c2ecf20Sopenharmony_ci        BREAK_WRITE,
3568c2ecf20Sopenharmony_ci        BREAK_UNMAP,
3578c2ecf20Sopenharmony_ci};
3588c2ecf20Sopenharmony_ci
3598c2ecf20Sopenharmony_ci/*
3608c2ecf20Sopenharmony_ci * For multiple groups support: if S_ISGID bit is set in the parent
3618c2ecf20Sopenharmony_ci * directory, group of new file is set to that of the parent, and
3628c2ecf20Sopenharmony_ci * new subdirectory gets S_ISGID bit from parent.
3638c2ecf20Sopenharmony_ci */
3648c2ecf20Sopenharmony_ci#define XFS_INHERIT_GID(pip)	\
3658c2ecf20Sopenharmony_ci	(((pip)->i_mount->m_flags & XFS_MOUNT_GRPID) || \
3668c2ecf20Sopenharmony_ci	 (VFS_I(pip)->i_mode & S_ISGID))
3678c2ecf20Sopenharmony_ci
3688c2ecf20Sopenharmony_ciint		xfs_release(struct xfs_inode *ip);
3698c2ecf20Sopenharmony_civoid		xfs_inactive(struct xfs_inode *ip);
3708c2ecf20Sopenharmony_ciint		xfs_lookup(struct xfs_inode *dp, struct xfs_name *name,
3718c2ecf20Sopenharmony_ci			   struct xfs_inode **ipp, struct xfs_name *ci_name);
3728c2ecf20Sopenharmony_ciint		xfs_create(struct xfs_inode *dp, struct xfs_name *name,
3738c2ecf20Sopenharmony_ci			   umode_t mode, dev_t rdev, struct xfs_inode **ipp);
3748c2ecf20Sopenharmony_ciint		xfs_create_tmpfile(struct xfs_inode *dp, umode_t mode,
3758c2ecf20Sopenharmony_ci			   struct xfs_inode **ipp);
3768c2ecf20Sopenharmony_ciint		xfs_remove(struct xfs_inode *dp, struct xfs_name *name,
3778c2ecf20Sopenharmony_ci			   struct xfs_inode *ip);
3788c2ecf20Sopenharmony_ciint		xfs_link(struct xfs_inode *tdp, struct xfs_inode *sip,
3798c2ecf20Sopenharmony_ci			 struct xfs_name *target_name);
3808c2ecf20Sopenharmony_ciint		xfs_rename(struct xfs_inode *src_dp, struct xfs_name *src_name,
3818c2ecf20Sopenharmony_ci			   struct xfs_inode *src_ip, struct xfs_inode *target_dp,
3828c2ecf20Sopenharmony_ci			   struct xfs_name *target_name,
3838c2ecf20Sopenharmony_ci			   struct xfs_inode *target_ip, unsigned int flags);
3848c2ecf20Sopenharmony_ci
3858c2ecf20Sopenharmony_civoid		xfs_ilock(xfs_inode_t *, uint);
3868c2ecf20Sopenharmony_ciint		xfs_ilock_nowait(xfs_inode_t *, uint);
3878c2ecf20Sopenharmony_civoid		xfs_iunlock(xfs_inode_t *, uint);
3888c2ecf20Sopenharmony_civoid		xfs_ilock_demote(xfs_inode_t *, uint);
3898c2ecf20Sopenharmony_ciint		xfs_isilocked(xfs_inode_t *, uint);
3908c2ecf20Sopenharmony_ciuint		xfs_ilock_data_map_shared(struct xfs_inode *);
3918c2ecf20Sopenharmony_ciuint		xfs_ilock_attr_map_shared(struct xfs_inode *);
3928c2ecf20Sopenharmony_ci
3938c2ecf20Sopenharmony_ciuint		xfs_ip2xflags(struct xfs_inode *);
3948c2ecf20Sopenharmony_ciint		xfs_ifree(struct xfs_trans *, struct xfs_inode *);
3958c2ecf20Sopenharmony_ciint		xfs_itruncate_extents_flags(struct xfs_trans **,
3968c2ecf20Sopenharmony_ci				struct xfs_inode *, int, xfs_fsize_t, int);
3978c2ecf20Sopenharmony_civoid		xfs_iext_realloc(xfs_inode_t *, int, int);
3988c2ecf20Sopenharmony_ci
3998c2ecf20Sopenharmony_ciint		xfs_log_force_inode(struct xfs_inode *ip);
4008c2ecf20Sopenharmony_civoid		xfs_iunpin_wait(xfs_inode_t *);
4018c2ecf20Sopenharmony_ci#define xfs_ipincount(ip)	((unsigned int) atomic_read(&ip->i_pincount))
4028c2ecf20Sopenharmony_ci
4038c2ecf20Sopenharmony_ciint		xfs_iflush_cluster(struct xfs_buf *);
4048c2ecf20Sopenharmony_civoid		xfs_lock_two_inodes(struct xfs_inode *ip0, uint ip0_mode,
4058c2ecf20Sopenharmony_ci				struct xfs_inode *ip1, uint ip1_mode);
4068c2ecf20Sopenharmony_ci
4078c2ecf20Sopenharmony_cixfs_extlen_t	xfs_get_extsz_hint(struct xfs_inode *ip);
4088c2ecf20Sopenharmony_cixfs_extlen_t	xfs_get_cowextsz_hint(struct xfs_inode *ip);
4098c2ecf20Sopenharmony_ci
4108c2ecf20Sopenharmony_ciint		xfs_dir_ialloc(struct xfs_trans **, struct xfs_inode *, umode_t,
4118c2ecf20Sopenharmony_ci			       xfs_nlink_t, dev_t, prid_t,
4128c2ecf20Sopenharmony_ci			       struct xfs_inode **);
4138c2ecf20Sopenharmony_ci
4148c2ecf20Sopenharmony_cistatic inline int
4158c2ecf20Sopenharmony_cixfs_itruncate_extents(
4168c2ecf20Sopenharmony_ci	struct xfs_trans	**tpp,
4178c2ecf20Sopenharmony_ci	struct xfs_inode	*ip,
4188c2ecf20Sopenharmony_ci	int			whichfork,
4198c2ecf20Sopenharmony_ci	xfs_fsize_t		new_size)
4208c2ecf20Sopenharmony_ci{
4218c2ecf20Sopenharmony_ci	return xfs_itruncate_extents_flags(tpp, ip, whichfork, new_size, 0);
4228c2ecf20Sopenharmony_ci}
4238c2ecf20Sopenharmony_ci
4248c2ecf20Sopenharmony_ci/* from xfs_file.c */
4258c2ecf20Sopenharmony_cienum xfs_prealloc_flags {
4268c2ecf20Sopenharmony_ci	XFS_PREALLOC_SET	= (1 << 1),
4278c2ecf20Sopenharmony_ci	XFS_PREALLOC_CLEAR	= (1 << 2),
4288c2ecf20Sopenharmony_ci	XFS_PREALLOC_SYNC	= (1 << 3),
4298c2ecf20Sopenharmony_ci	XFS_PREALLOC_INVISIBLE	= (1 << 4),
4308c2ecf20Sopenharmony_ci};
4318c2ecf20Sopenharmony_ci
4328c2ecf20Sopenharmony_ciint	xfs_update_prealloc_flags(struct xfs_inode *ip,
4338c2ecf20Sopenharmony_ci				  enum xfs_prealloc_flags flags);
4348c2ecf20Sopenharmony_ciint	xfs_break_layouts(struct inode *inode, uint *iolock,
4358c2ecf20Sopenharmony_ci		enum layout_break_reason reason);
4368c2ecf20Sopenharmony_ci
4378c2ecf20Sopenharmony_ci/* from xfs_iops.c */
4388c2ecf20Sopenharmony_ciextern void xfs_setup_inode(struct xfs_inode *ip);
4398c2ecf20Sopenharmony_ciextern void xfs_setup_iops(struct xfs_inode *ip);
4408c2ecf20Sopenharmony_ciextern void xfs_diflags_to_iflags(struct xfs_inode *ip, bool init);
4418c2ecf20Sopenharmony_ci
4428c2ecf20Sopenharmony_ci/*
4438c2ecf20Sopenharmony_ci * When setting up a newly allocated inode, we need to call
4448c2ecf20Sopenharmony_ci * xfs_finish_inode_setup() once the inode is fully instantiated at
4458c2ecf20Sopenharmony_ci * the VFS level to prevent the rest of the world seeing the inode
4468c2ecf20Sopenharmony_ci * before we've completed instantiation. Otherwise we can do it
4478c2ecf20Sopenharmony_ci * the moment the inode lookup is complete.
4488c2ecf20Sopenharmony_ci */
4498c2ecf20Sopenharmony_cistatic inline void xfs_finish_inode_setup(struct xfs_inode *ip)
4508c2ecf20Sopenharmony_ci{
4518c2ecf20Sopenharmony_ci	xfs_iflags_clear(ip, XFS_INEW);
4528c2ecf20Sopenharmony_ci	barrier();
4538c2ecf20Sopenharmony_ci	unlock_new_inode(VFS_I(ip));
4548c2ecf20Sopenharmony_ci	wake_up_bit(&ip->i_flags, __XFS_INEW_BIT);
4558c2ecf20Sopenharmony_ci}
4568c2ecf20Sopenharmony_ci
4578c2ecf20Sopenharmony_cistatic inline void xfs_setup_existing_inode(struct xfs_inode *ip)
4588c2ecf20Sopenharmony_ci{
4598c2ecf20Sopenharmony_ci	xfs_setup_inode(ip);
4608c2ecf20Sopenharmony_ci	xfs_setup_iops(ip);
4618c2ecf20Sopenharmony_ci	xfs_finish_inode_setup(ip);
4628c2ecf20Sopenharmony_ci}
4638c2ecf20Sopenharmony_ci
4648c2ecf20Sopenharmony_civoid xfs_irele(struct xfs_inode *ip);
4658c2ecf20Sopenharmony_ci
4668c2ecf20Sopenharmony_ciextern struct kmem_zone	*xfs_inode_zone;
4678c2ecf20Sopenharmony_ci
4688c2ecf20Sopenharmony_ci/* The default CoW extent size hint. */
4698c2ecf20Sopenharmony_ci#define XFS_DEFAULT_COWEXTSZ_HINT 32
4708c2ecf20Sopenharmony_ci
4718c2ecf20Sopenharmony_ciint xfs_iunlink_init(struct xfs_perag *pag);
4728c2ecf20Sopenharmony_civoid xfs_iunlink_destroy(struct xfs_perag *pag);
4738c2ecf20Sopenharmony_ci
4748c2ecf20Sopenharmony_civoid xfs_end_io(struct work_struct *work);
4758c2ecf20Sopenharmony_ci
4768c2ecf20Sopenharmony_ciint xfs_ilock2_io_mmap(struct xfs_inode *ip1, struct xfs_inode *ip2);
4778c2ecf20Sopenharmony_civoid xfs_iunlock2_io_mmap(struct xfs_inode *ip1, struct xfs_inode *ip2);
4788c2ecf20Sopenharmony_ci
4798c2ecf20Sopenharmony_ci#endif	/* __XFS_INODE_H__ */
480