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 * inode.h
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Function prototypes
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * Copyright (C) 2002, 2004 Oracle.  All rights reserved.
108c2ecf20Sopenharmony_ci */
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#ifndef OCFS2_INODE_H
138c2ecf20Sopenharmony_ci#define OCFS2_INODE_H
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#include "extent_map.h"
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci/* OCFS2 Inode Private Data */
188c2ecf20Sopenharmony_cistruct ocfs2_inode_info
198c2ecf20Sopenharmony_ci{
208c2ecf20Sopenharmony_ci	u64			ip_blkno;
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci	struct ocfs2_lock_res		ip_rw_lockres;
238c2ecf20Sopenharmony_ci	struct ocfs2_lock_res		ip_inode_lockres;
248c2ecf20Sopenharmony_ci	struct ocfs2_lock_res		ip_open_lockres;
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci	/* protects allocation changes on this inode. */
278c2ecf20Sopenharmony_ci	struct rw_semaphore		ip_alloc_sem;
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci	/* protects extended attribute changes on this inode */
308c2ecf20Sopenharmony_ci	struct rw_semaphore		ip_xattr_sem;
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci	/* These fields are protected by ip_lock */
338c2ecf20Sopenharmony_ci	spinlock_t			ip_lock;
348c2ecf20Sopenharmony_ci	u32				ip_open_count;
358c2ecf20Sopenharmony_ci	struct list_head		ip_io_markers;
368c2ecf20Sopenharmony_ci	u32				ip_clusters;
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci	u16				ip_dyn_features;
398c2ecf20Sopenharmony_ci	struct mutex			ip_io_mutex;
408c2ecf20Sopenharmony_ci	u32				ip_flags; /* see below */
418c2ecf20Sopenharmony_ci	u32				ip_attr; /* inode attributes */
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci	/* Record unwritten extents during direct io. */
448c2ecf20Sopenharmony_ci	struct list_head		ip_unwritten_list;
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci	/* protected by recovery_lock. */
478c2ecf20Sopenharmony_ci	struct inode			*ip_next_orphan;
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci	struct ocfs2_caching_info	ip_metadata_cache;
508c2ecf20Sopenharmony_ci	struct ocfs2_extent_map		ip_extent_map;
518c2ecf20Sopenharmony_ci	struct inode			vfs_inode;
528c2ecf20Sopenharmony_ci	struct jbd2_inode		ip_jinode;
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci	u32				ip_dir_start_lookup;
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci	/* Only valid if the inode is the dir. */
578c2ecf20Sopenharmony_ci	u32				ip_last_used_slot;
588c2ecf20Sopenharmony_ci	u64				ip_last_used_group;
598c2ecf20Sopenharmony_ci	u32				ip_dir_lock_gen;
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci	struct ocfs2_alloc_reservation	ip_la_data_resv;
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci	/*
648c2ecf20Sopenharmony_ci	 * Transactions that contain inode's metadata needed to complete
658c2ecf20Sopenharmony_ci	 * fsync and fdatasync, respectively.
668c2ecf20Sopenharmony_ci	 */
678c2ecf20Sopenharmony_ci	tid_t i_sync_tid;
688c2ecf20Sopenharmony_ci	tid_t i_datasync_tid;
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci	struct dquot *i_dquot[MAXQUOTAS];
718c2ecf20Sopenharmony_ci};
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci/*
748c2ecf20Sopenharmony_ci * Flags for the ip_flags field
758c2ecf20Sopenharmony_ci */
768c2ecf20Sopenharmony_ci/* System file inodes  */
778c2ecf20Sopenharmony_ci#define OCFS2_INODE_SYSTEM_FILE		0x00000001
788c2ecf20Sopenharmony_ci#define OCFS2_INODE_JOURNAL		0x00000002
798c2ecf20Sopenharmony_ci#define OCFS2_INODE_BITMAP		0x00000004
808c2ecf20Sopenharmony_ci/* This inode has been wiped from disk */
818c2ecf20Sopenharmony_ci#define OCFS2_INODE_DELETED		0x00000008
828c2ecf20Sopenharmony_ci/* Has the inode been orphaned on another node?
838c2ecf20Sopenharmony_ci *
848c2ecf20Sopenharmony_ci * This hints to ocfs2_drop_inode that it should clear i_nlink before
858c2ecf20Sopenharmony_ci * continuing.
868c2ecf20Sopenharmony_ci *
878c2ecf20Sopenharmony_ci * We *only* set this on unlink vote from another node. If the inode
888c2ecf20Sopenharmony_ci * was locally orphaned, then we're sure of the state and don't need
898c2ecf20Sopenharmony_ci * to twiddle i_nlink later - it's either zero or not depending on
908c2ecf20Sopenharmony_ci * whether our unlink succeeded. Otherwise we got this from a node
918c2ecf20Sopenharmony_ci * whose intention was to orphan the inode, however he may have
928c2ecf20Sopenharmony_ci * crashed, failed etc, so we let ocfs2_drop_inode zero the value and
938c2ecf20Sopenharmony_ci * rely on ocfs2_delete_inode to sort things out under the proper
948c2ecf20Sopenharmony_ci * cluster locks.
958c2ecf20Sopenharmony_ci */
968c2ecf20Sopenharmony_ci#define OCFS2_INODE_MAYBE_ORPHANED	0x00000010
978c2ecf20Sopenharmony_ci/* Does someone have the file open O_DIRECT */
988c2ecf20Sopenharmony_ci#define OCFS2_INODE_OPEN_DIRECT		0x00000020
998c2ecf20Sopenharmony_ci/* Tell the inode wipe code it's not in orphan dir */
1008c2ecf20Sopenharmony_ci#define OCFS2_INODE_SKIP_ORPHAN_DIR     0x00000040
1018c2ecf20Sopenharmony_ci/* Entry in orphan dir with 'dio-' prefix */
1028c2ecf20Sopenharmony_ci#define OCFS2_INODE_DIO_ORPHAN_ENTRY	0x00000080
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_cistatic inline struct ocfs2_inode_info *OCFS2_I(struct inode *inode)
1058c2ecf20Sopenharmony_ci{
1068c2ecf20Sopenharmony_ci	return container_of(inode, struct ocfs2_inode_info, vfs_inode);
1078c2ecf20Sopenharmony_ci}
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci#define INODE_JOURNAL(i) (OCFS2_I(i)->ip_flags & OCFS2_INODE_JOURNAL)
1108c2ecf20Sopenharmony_ci#define SET_INODE_JOURNAL(i) (OCFS2_I(i)->ip_flags |= OCFS2_INODE_JOURNAL)
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ciextern const struct address_space_operations ocfs2_aops;
1138c2ecf20Sopenharmony_ciextern const struct ocfs2_caching_operations ocfs2_inode_caching_ops;
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_cistatic inline struct ocfs2_caching_info *INODE_CACHE(struct inode *inode)
1168c2ecf20Sopenharmony_ci{
1178c2ecf20Sopenharmony_ci	return &OCFS2_I(inode)->ip_metadata_cache;
1188c2ecf20Sopenharmony_ci}
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_civoid ocfs2_evict_inode(struct inode *inode);
1218c2ecf20Sopenharmony_ciint ocfs2_drop_inode(struct inode *inode);
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ci/* Flags for ocfs2_iget() */
1248c2ecf20Sopenharmony_ci#define OCFS2_FI_FLAG_SYSFILE		0x1
1258c2ecf20Sopenharmony_ci#define OCFS2_FI_FLAG_ORPHAN_RECOVERY	0x2
1268c2ecf20Sopenharmony_ci#define OCFS2_FI_FLAG_FILECHECK_CHK	0x4
1278c2ecf20Sopenharmony_ci#define OCFS2_FI_FLAG_FILECHECK_FIX	0x8
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_cistruct inode *ocfs2_ilookup(struct super_block *sb, u64 feoff);
1308c2ecf20Sopenharmony_cistruct inode *ocfs2_iget(struct ocfs2_super *osb, u64 feoff, unsigned flags,
1318c2ecf20Sopenharmony_ci			 int sysfile_type);
1328c2ecf20Sopenharmony_ciint ocfs2_inode_revalidate(struct dentry *dentry);
1338c2ecf20Sopenharmony_civoid ocfs2_populate_inode(struct inode *inode, struct ocfs2_dinode *fe,
1348c2ecf20Sopenharmony_ci			  int create_ino);
1358c2ecf20Sopenharmony_civoid ocfs2_sync_blockdev(struct super_block *sb);
1368c2ecf20Sopenharmony_civoid ocfs2_refresh_inode(struct inode *inode,
1378c2ecf20Sopenharmony_ci			 struct ocfs2_dinode *fe);
1388c2ecf20Sopenharmony_ciint ocfs2_mark_inode_dirty(handle_t *handle,
1398c2ecf20Sopenharmony_ci			   struct inode *inode,
1408c2ecf20Sopenharmony_ci			   struct buffer_head *bh);
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_civoid ocfs2_set_inode_flags(struct inode *inode);
1438c2ecf20Sopenharmony_civoid ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_cistatic inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
1468c2ecf20Sopenharmony_ci{
1478c2ecf20Sopenharmony_ci	int c_to_s_bits = OCFS2_SB(inode->i_sb)->s_clustersize_bits - 9;
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_ci	return (blkcnt_t)OCFS2_I(inode)->ip_clusters << c_to_s_bits;
1508c2ecf20Sopenharmony_ci}
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci/* Validate that a bh contains a valid inode */
1538c2ecf20Sopenharmony_ciint ocfs2_validate_inode_block(struct super_block *sb,
1548c2ecf20Sopenharmony_ci			       struct buffer_head *bh);
1558c2ecf20Sopenharmony_ci/*
1568c2ecf20Sopenharmony_ci * Read an inode block into *bh.  If *bh is NULL, a bh will be allocated.
1578c2ecf20Sopenharmony_ci * This is a cached read.  The inode will be validated with
1588c2ecf20Sopenharmony_ci * ocfs2_validate_inode_block().
1598c2ecf20Sopenharmony_ci */
1608c2ecf20Sopenharmony_ciint ocfs2_read_inode_block(struct inode *inode, struct buffer_head **bh);
1618c2ecf20Sopenharmony_ci/* The same, but can be passed OCFS2_BH_* flags */
1628c2ecf20Sopenharmony_ciint ocfs2_read_inode_block_full(struct inode *inode, struct buffer_head **bh,
1638c2ecf20Sopenharmony_ci				int flags);
1648c2ecf20Sopenharmony_ci
1658c2ecf20Sopenharmony_cistatic inline struct ocfs2_inode_info *cache_info_to_inode(struct ocfs2_caching_info *ci)
1668c2ecf20Sopenharmony_ci{
1678c2ecf20Sopenharmony_ci	return container_of(ci, struct ocfs2_inode_info, ip_metadata_cache);
1688c2ecf20Sopenharmony_ci}
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_ci/* Does this inode have the reflink flag set? */
1718c2ecf20Sopenharmony_cistatic inline bool ocfs2_is_refcount_inode(struct inode *inode)
1728c2ecf20Sopenharmony_ci{
1738c2ecf20Sopenharmony_ci	return (OCFS2_I(inode)->ip_dyn_features & OCFS2_HAS_REFCOUNT_FL);
1748c2ecf20Sopenharmony_ci}
1758c2ecf20Sopenharmony_ci
1768c2ecf20Sopenharmony_ci#endif /* OCFS2_INODE_H */
177