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 * inode.h
6*4882a593Smuzhiyun *
7*4882a593Smuzhiyun * Function prototypes
8*4882a593Smuzhiyun *
9*4882a593Smuzhiyun * Copyright (C) 2002, 2004 Oracle. All rights reserved.
10*4882a593Smuzhiyun */
11*4882a593Smuzhiyun
12*4882a593Smuzhiyun #ifndef OCFS2_INODE_H
13*4882a593Smuzhiyun #define OCFS2_INODE_H
14*4882a593Smuzhiyun
15*4882a593Smuzhiyun #include "extent_map.h"
16*4882a593Smuzhiyun
17*4882a593Smuzhiyun /* OCFS2 Inode Private Data */
18*4882a593Smuzhiyun struct ocfs2_inode_info
19*4882a593Smuzhiyun {
20*4882a593Smuzhiyun u64 ip_blkno;
21*4882a593Smuzhiyun
22*4882a593Smuzhiyun struct ocfs2_lock_res ip_rw_lockres;
23*4882a593Smuzhiyun struct ocfs2_lock_res ip_inode_lockres;
24*4882a593Smuzhiyun struct ocfs2_lock_res ip_open_lockres;
25*4882a593Smuzhiyun
26*4882a593Smuzhiyun /* protects allocation changes on this inode. */
27*4882a593Smuzhiyun struct rw_semaphore ip_alloc_sem;
28*4882a593Smuzhiyun
29*4882a593Smuzhiyun /* protects extended attribute changes on this inode */
30*4882a593Smuzhiyun struct rw_semaphore ip_xattr_sem;
31*4882a593Smuzhiyun
32*4882a593Smuzhiyun /* These fields are protected by ip_lock */
33*4882a593Smuzhiyun spinlock_t ip_lock;
34*4882a593Smuzhiyun u32 ip_open_count;
35*4882a593Smuzhiyun struct list_head ip_io_markers;
36*4882a593Smuzhiyun u32 ip_clusters;
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun u16 ip_dyn_features;
39*4882a593Smuzhiyun struct mutex ip_io_mutex;
40*4882a593Smuzhiyun u32 ip_flags; /* see below */
41*4882a593Smuzhiyun u32 ip_attr; /* inode attributes */
42*4882a593Smuzhiyun
43*4882a593Smuzhiyun /* Record unwritten extents during direct io. */
44*4882a593Smuzhiyun struct list_head ip_unwritten_list;
45*4882a593Smuzhiyun
46*4882a593Smuzhiyun /* protected by recovery_lock. */
47*4882a593Smuzhiyun struct inode *ip_next_orphan;
48*4882a593Smuzhiyun
49*4882a593Smuzhiyun struct ocfs2_caching_info ip_metadata_cache;
50*4882a593Smuzhiyun struct ocfs2_extent_map ip_extent_map;
51*4882a593Smuzhiyun struct inode vfs_inode;
52*4882a593Smuzhiyun struct jbd2_inode ip_jinode;
53*4882a593Smuzhiyun
54*4882a593Smuzhiyun u32 ip_dir_start_lookup;
55*4882a593Smuzhiyun
56*4882a593Smuzhiyun /* Only valid if the inode is the dir. */
57*4882a593Smuzhiyun u32 ip_last_used_slot;
58*4882a593Smuzhiyun u64 ip_last_used_group;
59*4882a593Smuzhiyun u32 ip_dir_lock_gen;
60*4882a593Smuzhiyun
61*4882a593Smuzhiyun struct ocfs2_alloc_reservation ip_la_data_resv;
62*4882a593Smuzhiyun
63*4882a593Smuzhiyun /*
64*4882a593Smuzhiyun * Transactions that contain inode's metadata needed to complete
65*4882a593Smuzhiyun * fsync and fdatasync, respectively.
66*4882a593Smuzhiyun */
67*4882a593Smuzhiyun tid_t i_sync_tid;
68*4882a593Smuzhiyun tid_t i_datasync_tid;
69*4882a593Smuzhiyun
70*4882a593Smuzhiyun struct dquot *i_dquot[MAXQUOTAS];
71*4882a593Smuzhiyun };
72*4882a593Smuzhiyun
73*4882a593Smuzhiyun /*
74*4882a593Smuzhiyun * Flags for the ip_flags field
75*4882a593Smuzhiyun */
76*4882a593Smuzhiyun /* System file inodes */
77*4882a593Smuzhiyun #define OCFS2_INODE_SYSTEM_FILE 0x00000001
78*4882a593Smuzhiyun #define OCFS2_INODE_JOURNAL 0x00000002
79*4882a593Smuzhiyun #define OCFS2_INODE_BITMAP 0x00000004
80*4882a593Smuzhiyun /* This inode has been wiped from disk */
81*4882a593Smuzhiyun #define OCFS2_INODE_DELETED 0x00000008
82*4882a593Smuzhiyun /* Has the inode been orphaned on another node?
83*4882a593Smuzhiyun *
84*4882a593Smuzhiyun * This hints to ocfs2_drop_inode that it should clear i_nlink before
85*4882a593Smuzhiyun * continuing.
86*4882a593Smuzhiyun *
87*4882a593Smuzhiyun * We *only* set this on unlink vote from another node. If the inode
88*4882a593Smuzhiyun * was locally orphaned, then we're sure of the state and don't need
89*4882a593Smuzhiyun * to twiddle i_nlink later - it's either zero or not depending on
90*4882a593Smuzhiyun * whether our unlink succeeded. Otherwise we got this from a node
91*4882a593Smuzhiyun * whose intention was to orphan the inode, however he may have
92*4882a593Smuzhiyun * crashed, failed etc, so we let ocfs2_drop_inode zero the value and
93*4882a593Smuzhiyun * rely on ocfs2_delete_inode to sort things out under the proper
94*4882a593Smuzhiyun * cluster locks.
95*4882a593Smuzhiyun */
96*4882a593Smuzhiyun #define OCFS2_INODE_MAYBE_ORPHANED 0x00000010
97*4882a593Smuzhiyun /* Does someone have the file open O_DIRECT */
98*4882a593Smuzhiyun #define OCFS2_INODE_OPEN_DIRECT 0x00000020
99*4882a593Smuzhiyun /* Tell the inode wipe code it's not in orphan dir */
100*4882a593Smuzhiyun #define OCFS2_INODE_SKIP_ORPHAN_DIR 0x00000040
101*4882a593Smuzhiyun /* Entry in orphan dir with 'dio-' prefix */
102*4882a593Smuzhiyun #define OCFS2_INODE_DIO_ORPHAN_ENTRY 0x00000080
103*4882a593Smuzhiyun
OCFS2_I(struct inode * inode)104*4882a593Smuzhiyun static inline struct ocfs2_inode_info *OCFS2_I(struct inode *inode)
105*4882a593Smuzhiyun {
106*4882a593Smuzhiyun return container_of(inode, struct ocfs2_inode_info, vfs_inode);
107*4882a593Smuzhiyun }
108*4882a593Smuzhiyun
109*4882a593Smuzhiyun #define INODE_JOURNAL(i) (OCFS2_I(i)->ip_flags & OCFS2_INODE_JOURNAL)
110*4882a593Smuzhiyun #define SET_INODE_JOURNAL(i) (OCFS2_I(i)->ip_flags |= OCFS2_INODE_JOURNAL)
111*4882a593Smuzhiyun
112*4882a593Smuzhiyun extern const struct address_space_operations ocfs2_aops;
113*4882a593Smuzhiyun extern const struct ocfs2_caching_operations ocfs2_inode_caching_ops;
114*4882a593Smuzhiyun
INODE_CACHE(struct inode * inode)115*4882a593Smuzhiyun static inline struct ocfs2_caching_info *INODE_CACHE(struct inode *inode)
116*4882a593Smuzhiyun {
117*4882a593Smuzhiyun return &OCFS2_I(inode)->ip_metadata_cache;
118*4882a593Smuzhiyun }
119*4882a593Smuzhiyun
120*4882a593Smuzhiyun void ocfs2_evict_inode(struct inode *inode);
121*4882a593Smuzhiyun int ocfs2_drop_inode(struct inode *inode);
122*4882a593Smuzhiyun
123*4882a593Smuzhiyun /* Flags for ocfs2_iget() */
124*4882a593Smuzhiyun #define OCFS2_FI_FLAG_SYSFILE 0x1
125*4882a593Smuzhiyun #define OCFS2_FI_FLAG_ORPHAN_RECOVERY 0x2
126*4882a593Smuzhiyun #define OCFS2_FI_FLAG_FILECHECK_CHK 0x4
127*4882a593Smuzhiyun #define OCFS2_FI_FLAG_FILECHECK_FIX 0x8
128*4882a593Smuzhiyun
129*4882a593Smuzhiyun struct inode *ocfs2_ilookup(struct super_block *sb, u64 feoff);
130*4882a593Smuzhiyun struct inode *ocfs2_iget(struct ocfs2_super *osb, u64 feoff, unsigned flags,
131*4882a593Smuzhiyun int sysfile_type);
132*4882a593Smuzhiyun int ocfs2_inode_revalidate(struct dentry *dentry);
133*4882a593Smuzhiyun void ocfs2_populate_inode(struct inode *inode, struct ocfs2_dinode *fe,
134*4882a593Smuzhiyun int create_ino);
135*4882a593Smuzhiyun void ocfs2_sync_blockdev(struct super_block *sb);
136*4882a593Smuzhiyun void ocfs2_refresh_inode(struct inode *inode,
137*4882a593Smuzhiyun struct ocfs2_dinode *fe);
138*4882a593Smuzhiyun int ocfs2_mark_inode_dirty(handle_t *handle,
139*4882a593Smuzhiyun struct inode *inode,
140*4882a593Smuzhiyun struct buffer_head *bh);
141*4882a593Smuzhiyun
142*4882a593Smuzhiyun void ocfs2_set_inode_flags(struct inode *inode);
143*4882a593Smuzhiyun void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
144*4882a593Smuzhiyun
ocfs2_inode_sector_count(struct inode * inode)145*4882a593Smuzhiyun static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
146*4882a593Smuzhiyun {
147*4882a593Smuzhiyun int c_to_s_bits = OCFS2_SB(inode->i_sb)->s_clustersize_bits - 9;
148*4882a593Smuzhiyun
149*4882a593Smuzhiyun return (blkcnt_t)OCFS2_I(inode)->ip_clusters << c_to_s_bits;
150*4882a593Smuzhiyun }
151*4882a593Smuzhiyun
152*4882a593Smuzhiyun /* Validate that a bh contains a valid inode */
153*4882a593Smuzhiyun int ocfs2_validate_inode_block(struct super_block *sb,
154*4882a593Smuzhiyun struct buffer_head *bh);
155*4882a593Smuzhiyun /*
156*4882a593Smuzhiyun * Read an inode block into *bh. If *bh is NULL, a bh will be allocated.
157*4882a593Smuzhiyun * This is a cached read. The inode will be validated with
158*4882a593Smuzhiyun * ocfs2_validate_inode_block().
159*4882a593Smuzhiyun */
160*4882a593Smuzhiyun int ocfs2_read_inode_block(struct inode *inode, struct buffer_head **bh);
161*4882a593Smuzhiyun /* The same, but can be passed OCFS2_BH_* flags */
162*4882a593Smuzhiyun int ocfs2_read_inode_block_full(struct inode *inode, struct buffer_head **bh,
163*4882a593Smuzhiyun int flags);
164*4882a593Smuzhiyun
cache_info_to_inode(struct ocfs2_caching_info * ci)165*4882a593Smuzhiyun static inline struct ocfs2_inode_info *cache_info_to_inode(struct ocfs2_caching_info *ci)
166*4882a593Smuzhiyun {
167*4882a593Smuzhiyun return container_of(ci, struct ocfs2_inode_info, ip_metadata_cache);
168*4882a593Smuzhiyun }
169*4882a593Smuzhiyun
170*4882a593Smuzhiyun /* Does this inode have the reflink flag set? */
ocfs2_is_refcount_inode(struct inode * inode)171*4882a593Smuzhiyun static inline bool ocfs2_is_refcount_inode(struct inode *inode)
172*4882a593Smuzhiyun {
173*4882a593Smuzhiyun return (OCFS2_I(inode)->ip_dyn_features & OCFS2_HAS_REFCOUNT_FL);
174*4882a593Smuzhiyun }
175*4882a593Smuzhiyun
176*4882a593Smuzhiyun #endif /* OCFS2_INODE_H */
177