xref: /linux/fs/ocfs2/inode.h (revision 4506cfb6f8cad594ac73e0df2b2961ca10dbd25e)
1ccd979bdSMark Fasheh /* -*- mode: c; c-basic-offset: 8; -*-
2ccd979bdSMark Fasheh  * vim: noexpandtab sw=8 ts=8 sts=0:
3ccd979bdSMark Fasheh  *
4ccd979bdSMark Fasheh  * inode.h
5ccd979bdSMark Fasheh  *
6ccd979bdSMark Fasheh  * Function prototypes
7ccd979bdSMark Fasheh  *
8ccd979bdSMark Fasheh  * Copyright (C) 2002, 2004 Oracle.  All rights reserved.
9ccd979bdSMark Fasheh  *
10ccd979bdSMark Fasheh  * This program is free software; you can redistribute it and/or
11ccd979bdSMark Fasheh  * modify it under the terms of the GNU General Public
12ccd979bdSMark Fasheh  * License as published by the Free Software Foundation; either
13ccd979bdSMark Fasheh  * version 2 of the License, or (at your option) any later version.
14ccd979bdSMark Fasheh  *
15ccd979bdSMark Fasheh  * This program is distributed in the hope that it will be useful,
16ccd979bdSMark Fasheh  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17ccd979bdSMark Fasheh  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18ccd979bdSMark Fasheh  * General Public License for more details.
19ccd979bdSMark Fasheh  *
20ccd979bdSMark Fasheh  * You should have received a copy of the GNU General Public
21ccd979bdSMark Fasheh  * License along with this program; if not, write to the
22ccd979bdSMark Fasheh  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23ccd979bdSMark Fasheh  * Boston, MA 021110-1307, USA.
24ccd979bdSMark Fasheh  */
25ccd979bdSMark Fasheh 
26ccd979bdSMark Fasheh #ifndef OCFS2_INODE_H
27ccd979bdSMark Fasheh #define OCFS2_INODE_H
28ccd979bdSMark Fasheh 
2983418978SMark Fasheh #include "extent_map.h"
3083418978SMark Fasheh 
31ccd979bdSMark Fasheh /* OCFS2 Inode Private Data */
32ccd979bdSMark Fasheh struct ocfs2_inode_info
33ccd979bdSMark Fasheh {
34ccd979bdSMark Fasheh 	u64			ip_blkno;
35ccd979bdSMark Fasheh 
36ccd979bdSMark Fasheh 	struct ocfs2_lock_res		ip_rw_lockres;
37e63aecb6SMark Fasheh 	struct ocfs2_lock_res		ip_inode_lockres;
3850008630STiger Yang 	struct ocfs2_lock_res		ip_open_lockres;
39ccd979bdSMark Fasheh 
40ccd979bdSMark Fasheh 	/* protects allocation changes on this inode. */
41ccd979bdSMark Fasheh 	struct rw_semaphore		ip_alloc_sem;
42ccd979bdSMark Fasheh 
43cf1d6c76STiger Yang 	/* protects extended attribute changes on this inode */
44cf1d6c76STiger Yang 	struct rw_semaphore		ip_xattr_sem;
45cf1d6c76STiger Yang 
46a11f7e63SMark Fasheh 	/* Number of outstanding AIO's which are not page aligned */
47c18ceab0SWengang Wang 	struct mutex			ip_unaligned_aio;
48a11f7e63SMark Fasheh 
49ccd979bdSMark Fasheh 	/* These fields are protected by ip_lock */
50ccd979bdSMark Fasheh 	spinlock_t			ip_lock;
51ccd979bdSMark Fasheh 	u32				ip_open_count;
52ccd979bdSMark Fasheh 	struct list_head		ip_io_markers;
5383fd9c7fSGoldwyn Rodrigues 	u32				ip_clusters;
54ccd979bdSMark Fasheh 
5583fd9c7fSGoldwyn Rodrigues 	u16				ip_dyn_features;
56251b6eccSMark Fasheh 	struct mutex			ip_io_mutex;
57ccd979bdSMark Fasheh 	u32				ip_flags; /* see below */
58ca4d147eSHerbert Poetzl 	u32				ip_attr; /* inode attributes */
59ccd979bdSMark Fasheh 
60*4506cfb6SRyan Ding 	/* Record unwritten extents during direct io. */
61*4506cfb6SRyan Ding 	struct list_head		ip_unwritten_list;
62*4506cfb6SRyan Ding 
63ccd979bdSMark Fasheh 	/* protected by recovery_lock. */
64ccd979bdSMark Fasheh 	struct inode			*ip_next_orphan;
65ccd979bdSMark Fasheh 
66ccd979bdSMark Fasheh 	struct ocfs2_caching_info	ip_metadata_cache;
6783418978SMark Fasheh 	struct ocfs2_extent_map		ip_extent_map;
68ccd979bdSMark Fasheh 	struct inode			vfs_inode;
692b4e30fbSJoel Becker 	struct jbd2_inode		ip_jinode;
7013821151STao Ma 
7183fd9c7fSGoldwyn Rodrigues 	u32				ip_dir_start_lookup;
7283fd9c7fSGoldwyn Rodrigues 
7313821151STao Ma 	/* Only valid if the inode is the dir. */
7413821151STao Ma 	u32				ip_last_used_slot;
7513821151STao Ma 	u64				ip_last_used_group;
765e98d492SGoldwyn Rodrigues 	u32				ip_dir_lock_gen;
774fe370afSMark Fasheh 
784fe370afSMark Fasheh 	struct ocfs2_alloc_reservation	ip_la_data_resv;
792931cdcbSDarrick J. Wong 
802931cdcbSDarrick J. Wong 	/*
812931cdcbSDarrick J. Wong 	 * Transactions that contain inode's metadata needed to complete
822931cdcbSDarrick J. Wong 	 * fsync and fdatasync, respectively.
832931cdcbSDarrick J. Wong 	 */
842931cdcbSDarrick J. Wong 	tid_t i_sync_tid;
852931cdcbSDarrick J. Wong 	tid_t i_datasync_tid;
861c92ec67SJan Kara 
871c92ec67SJan Kara 	struct dquot *i_dquot[MAXQUOTAS];
88ccd979bdSMark Fasheh };
89ccd979bdSMark Fasheh 
90ccd979bdSMark Fasheh /*
91ccd979bdSMark Fasheh  * Flags for the ip_flags field
92ccd979bdSMark Fasheh  */
93ccd979bdSMark Fasheh /* System file inodes  */
94ccd979bdSMark Fasheh #define OCFS2_INODE_SYSTEM_FILE		0x00000001
95ccd979bdSMark Fasheh #define OCFS2_INODE_JOURNAL		0x00000002
96ccd979bdSMark Fasheh #define OCFS2_INODE_BITMAP		0x00000004
97ccd979bdSMark Fasheh /* This inode has been wiped from disk */
98ccd979bdSMark Fasheh #define OCFS2_INODE_DELETED		0x00000008
99ccd979bdSMark Fasheh /* Has the inode been orphaned on another node?
100ccd979bdSMark Fasheh  *
101ccd979bdSMark Fasheh  * This hints to ocfs2_drop_inode that it should clear i_nlink before
102ccd979bdSMark Fasheh  * continuing.
103ccd979bdSMark Fasheh  *
104ccd979bdSMark Fasheh  * We *only* set this on unlink vote from another node. If the inode
105ccd979bdSMark Fasheh  * was locally orphaned, then we're sure of the state and don't need
106ccd979bdSMark Fasheh  * to twiddle i_nlink later - it's either zero or not depending on
107ccd979bdSMark Fasheh  * whether our unlink succeeded. Otherwise we got this from a node
108ccd979bdSMark Fasheh  * whose intention was to orphan the inode, however he may have
109ccd979bdSMark Fasheh  * crashed, failed etc, so we let ocfs2_drop_inode zero the value and
110ccd979bdSMark Fasheh  * rely on ocfs2_delete_inode to sort things out under the proper
111ccd979bdSMark Fasheh  * cluster locks.
112ccd979bdSMark Fasheh  */
1137bf619c1SJan Kara #define OCFS2_INODE_MAYBE_ORPHANED	0x00000010
114ccd979bdSMark Fasheh /* Does someone have the file open O_DIRECT */
1157bf619c1SJan Kara #define OCFS2_INODE_OPEN_DIRECT		0x00000020
116d4cd1871SLi Dongyang /* Tell the inode wipe code it's not in orphan dir */
1177bf619c1SJan Kara #define OCFS2_INODE_SKIP_ORPHAN_DIR     0x00000040
11893d911fcSJoseph Qi /* Entry in orphan dir with 'dio-' prefix */
11993d911fcSJoseph Qi #define OCFS2_INODE_DIO_ORPHAN_ENTRY	0x00000080
120ccd979bdSMark Fasheh 
121ccd979bdSMark Fasheh static inline struct ocfs2_inode_info *OCFS2_I(struct inode *inode)
122ccd979bdSMark Fasheh {
123ccd979bdSMark Fasheh 	return container_of(inode, struct ocfs2_inode_info, vfs_inode);
124ccd979bdSMark Fasheh }
125ccd979bdSMark Fasheh 
126ccd979bdSMark Fasheh #define INODE_JOURNAL(i) (OCFS2_I(i)->ip_flags & OCFS2_INODE_JOURNAL)
127ccd979bdSMark Fasheh #define SET_INODE_JOURNAL(i) (OCFS2_I(i)->ip_flags |= OCFS2_INODE_JOURNAL)
128ccd979bdSMark Fasheh 
129e18b890bSChristoph Lameter extern struct kmem_cache *ocfs2_inode_cache;
130ccd979bdSMark Fasheh 
131f5e54d6eSChristoph Hellwig extern const struct address_space_operations ocfs2_aops;
1326e5a3d75SJoel Becker extern const struct ocfs2_caching_operations ocfs2_inode_caching_ops;
133ccd979bdSMark Fasheh 
1348cb471e8SJoel Becker static inline struct ocfs2_caching_info *INODE_CACHE(struct inode *inode)
1358cb471e8SJoel Becker {
1368cb471e8SJoel Becker 	return &OCFS2_I(inode)->ip_metadata_cache;
1378cb471e8SJoel Becker }
1388cb471e8SJoel Becker 
139066d92dcSAl Viro void ocfs2_evict_inode(struct inode *inode);
14045321ac5SAl Viro int ocfs2_drop_inode(struct inode *inode);
14124c19ef4SMark Fasheh 
14224c19ef4SMark Fasheh /* Flags for ocfs2_iget() */
1435fa0613eSJan Kara #define OCFS2_FI_FLAG_SYSFILE		0x1
1445fa0613eSJan Kara #define OCFS2_FI_FLAG_ORPHAN_RECOVERY	0x2
145a860f6ebSGang He #define OCFS2_FI_FLAG_FILECHECK_CHK	0x4
146a860f6ebSGang He #define OCFS2_FI_FLAG_FILECHECK_FIX	0x8
147a860f6ebSGang He 
1486ca497a8Swengang wang struct inode *ocfs2_ilookup(struct super_block *sb, u64 feoff);
1495fa0613eSJan Kara struct inode *ocfs2_iget(struct ocfs2_super *osb, u64 feoff, unsigned flags,
1505fa0613eSJan Kara 			 int sysfile_type);
151ccd979bdSMark Fasheh int ocfs2_inode_init_private(struct inode *inode);
152ccd979bdSMark Fasheh int ocfs2_inode_revalidate(struct dentry *dentry);
153b657c95cSJoel Becker void ocfs2_populate_inode(struct inode *inode, struct ocfs2_dinode *fe,
154ccd979bdSMark Fasheh 			  int create_ino);
155ccd979bdSMark Fasheh void ocfs2_read_inode(struct inode *inode);
156ccd979bdSMark Fasheh void ocfs2_read_inode2(struct inode *inode, void *opaque);
157ccd979bdSMark Fasheh ssize_t ocfs2_rw_direct(int rw, struct file *filp, char *buf,
158ccd979bdSMark Fasheh 			size_t size, loff_t *offp);
159ccd979bdSMark Fasheh void ocfs2_sync_blockdev(struct super_block *sb);
160ccd979bdSMark Fasheh void ocfs2_refresh_inode(struct inode *inode,
161ccd979bdSMark Fasheh 			 struct ocfs2_dinode *fe);
1621fabe148SMark Fasheh int ocfs2_mark_inode_dirty(handle_t *handle,
163ccd979bdSMark Fasheh 			   struct inode *inode,
164ccd979bdSMark Fasheh 			   struct buffer_head *bh);
1659e33d69fSJan Kara struct buffer_head *ocfs2_bread(struct inode *inode,
1669e33d69fSJan Kara 				int block, int *err, int reada);
167ccd979bdSMark Fasheh 
168ca4d147eSHerbert Poetzl void ocfs2_set_inode_flags(struct inode *inode);
1696e4b0d56SJan Kara void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
170ca4d147eSHerbert Poetzl 
1718110b073SMark Fasheh static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
1728110b073SMark Fasheh {
1738110b073SMark Fasheh 	int c_to_s_bits = OCFS2_SB(inode->i_sb)->s_clustersize_bits - 9;
1748110b073SMark Fasheh 
1757fa05c6eSJoseph Qi 	return (blkcnt_t)OCFS2_I(inode)->ip_clusters << c_to_s_bits;
1768110b073SMark Fasheh }
1778110b073SMark Fasheh 
178b657c95cSJoel Becker /* Validate that a bh contains a valid inode */
179b657c95cSJoel Becker int ocfs2_validate_inode_block(struct super_block *sb,
180b657c95cSJoel Becker 			       struct buffer_head *bh);
181b657c95cSJoel Becker /*
182b657c95cSJoel Becker  * Read an inode block into *bh.  If *bh is NULL, a bh will be allocated.
183b657c95cSJoel Becker  * This is a cached read.  The inode will be validated with
184b657c95cSJoel Becker  * ocfs2_validate_inode_block().
185b657c95cSJoel Becker  */
186b657c95cSJoel Becker int ocfs2_read_inode_block(struct inode *inode, struct buffer_head **bh);
187b657c95cSJoel Becker /* The same, but can be passed OCFS2_BH_* flags */
188b657c95cSJoel Becker int ocfs2_read_inode_block_full(struct inode *inode, struct buffer_head **bh,
189b657c95cSJoel Becker 				int flags);
1906136ca5fSJoel Becker 
1916136ca5fSJoel Becker static inline struct ocfs2_inode_info *cache_info_to_inode(struct ocfs2_caching_info *ci)
1926136ca5fSJoel Becker {
1936136ca5fSJoel Becker 	return container_of(ci, struct ocfs2_inode_info, ip_metadata_cache);
1946136ca5fSJoel Becker }
1956136ca5fSJoel Becker 
196ccd979bdSMark Fasheh #endif /* OCFS2_INODE_H */
197