blob: 012dfd4a958c8537ecd86e2bc4f6b6a0ed89ff0c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Nathan Scott7b718762005-11-02 14:58:39 +11002 * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Nathan Scott7b718762005-11-02 14:58:39 +11005 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * published by the Free Software Foundation.
8 *
Nathan Scott7b718762005-11-02 14:58:39 +11009 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 *
Nathan Scott7b718762005-11-02 14:58:39 +110014 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 */
18#ifndef __XFS_INODE_H__
19#define __XFS_INODE_H__
20
21/*
Nathan Scotta844f452005-11-02 14:38:42 +110022 * Fork identifiers.
23 */
24#define XFS_DATA_FORK 0
25#define XFS_ATTR_FORK 1
26
27/*
Mandy Kirkconnell0293ce32006-03-14 13:30:23 +110028 * The following xfs_ext_irec_t struct introduces a second (top) level
29 * to the in-core extent allocation scheme. These structs are allocated
30 * in a contiguous block, creating an indirection array where each entry
31 * (irec) contains a pointer to a buffer of in-core extent records which
32 * it manages. Each extent buffer is 4k in size, since 4k is the system
33 * page size on Linux i386 and systems with larger page sizes don't seem
34 * to gain much, if anything, by using their native page size as the
35 * extent buffer size. Also, using 4k extent buffers everywhere provides
36 * a consistent interface for CXFS across different platforms.
37 *
38 * There is currently no limit on the number of irec's (extent lists)
39 * allowed, so heavily fragmented files may require an indirection array
40 * which spans multiple system pages of memory. The number of extents
41 * which would require this amount of contiguous memory is very large
42 * and should not cause problems in the foreseeable future. However,
43 * if the memory needed for the contiguous array ever becomes a problem,
44 * it is possible that a third level of indirection may be required.
45 */
46typedef struct xfs_ext_irec {
47 xfs_bmbt_rec_t *er_extbuf; /* block of extent records */
48 xfs_extnum_t er_extoff; /* extent offset in file */
49 xfs_extnum_t er_extcount; /* number of extents in page/block */
50} xfs_ext_irec_t;
51
52/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 * File incore extent information, present for each of data & attr forks.
54 */
Mandy Kirkconnell0293ce32006-03-14 13:30:23 +110055#define XFS_IEXT_BUFSZ 4096
56#define XFS_LINEAR_EXTS (XFS_IEXT_BUFSZ / (uint)sizeof(xfs_bmbt_rec_t))
57#define XFS_INLINE_EXTS 2
58#define XFS_INLINE_DATA 32
Linus Torvalds1da177e2005-04-16 15:20:36 -070059typedef struct xfs_ifork {
60 int if_bytes; /* bytes in if_u1 */
61 int if_real_bytes; /* bytes allocated in if_u1 */
62 xfs_bmbt_block_t *if_broot; /* file's incore btree root */
63 short if_broot_bytes; /* bytes allocated for root */
64 unsigned char if_flags; /* per-fork flags */
65 unsigned char if_ext_max; /* max # of extent records */
66 xfs_extnum_t if_lastex; /* last if_extents used */
67 union {
68 xfs_bmbt_rec_t *if_extents; /* linear map file exts */
Mandy Kirkconnell0293ce32006-03-14 13:30:23 +110069 xfs_ext_irec_t *if_ext_irec; /* irec map file exts */
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 char *if_data; /* inline file data */
71 } if_u1;
72 union {
73 xfs_bmbt_rec_t if_inline_ext[XFS_INLINE_EXTS];
74 /* very small file extents */
75 char if_inline_data[XFS_INLINE_DATA];
76 /* very small file data */
77 xfs_dev_t if_rdev; /* dev number if special */
78 uuid_t if_uuid; /* mount point value */
79 } if_u2;
80} xfs_ifork_t;
81
82/*
83 * Flags for xfs_ichgtime().
84 */
85#define XFS_ICHGTIME_MOD 0x1 /* data fork modification timestamp */
86#define XFS_ICHGTIME_ACC 0x2 /* data fork access timestamp */
87#define XFS_ICHGTIME_CHG 0x4 /* inode field change timestamp */
88
89/*
90 * Per-fork incore inode flags.
91 */
Mandy Kirkconnell0293ce32006-03-14 13:30:23 +110092#define XFS_IFINLINE 0x01 /* Inline data is read in */
93#define XFS_IFEXTENTS 0x02 /* All extent pointers are read in */
94#define XFS_IFBROOT 0x04 /* i_broot points to the bmap b-tree root */
95#define XFS_IFEXTIREC 0x08 /* Indirection array of extent blocks */
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
97/*
Nathan Scottb12dd342006-03-17 17:26:04 +110098 * Flags for xfs_itobp(), xfs_imap() and xfs_dilocate().
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 */
Nathan Scottb12dd342006-03-17 17:26:04 +1100100#define XFS_IMAP_LOOKUP 0x1
101#define XFS_IMAP_BULKSTAT 0x2
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103#ifdef __KERNEL__
104struct bhv_desc;
Nathan Scott67fcaa72006-06-09 17:00:52 +1000105struct bhv_vnode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106struct cred;
107struct ktrace;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108struct xfs_buf;
109struct xfs_bmap_free;
110struct xfs_bmbt_irec;
111struct xfs_bmbt_block;
112struct xfs_inode;
113struct xfs_inode_log_item;
114struct xfs_mount;
115struct xfs_trans;
116struct xfs_dquot;
117
118#if defined(XFS_ILOCK_TRACE)
119#define XFS_ILOCK_KTRACE_SIZE 32
120extern ktrace_t *xfs_ilock_trace_buf;
121extern void xfs_ilock_trace(struct xfs_inode *, int, unsigned int, inst_t *);
122#else
123#define xfs_ilock_trace(i,n,f,ra)
124#endif
125
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126typedef struct dm_attrs_s {
127 __uint32_t da_dmevmask; /* DMIG event mask */
128 __uint16_t da_dmstate; /* DMIG state info */
129 __uint16_t da_pad; /* DMIG extra padding */
130} dm_attrs_t;
131
132typedef struct xfs_iocore {
133 void *io_obj; /* pointer to container
134 * inode or dcxvn structure */
135 struct xfs_mount *io_mount; /* fs mount struct ptr */
136#ifdef DEBUG
137 mrlock_t *io_lock; /* inode IO lock */
138 mrlock_t *io_iolock; /* inode IO lock */
139#endif
140
141 /* I/O state */
142 xfs_fsize_t io_new_size; /* sz when write completes */
143
144 /* Miscellaneous state. */
145 unsigned int io_flags; /* IO related flags */
146
147 /* DMAPI state */
148 dm_attrs_t io_dmattrs;
149
150} xfs_iocore_t;
151
152#define io_dmevmask io_dmattrs.da_dmevmask
153#define io_dmstate io_dmattrs.da_dmstate
154
155#define XFS_IO_INODE(io) ((xfs_inode_t *) ((io)->io_obj))
156#define XFS_IO_DCXVN(io) ((dcxvn_t *) ((io)->io_obj))
157
158/*
159 * Flags in the flags field
160 */
161
162#define XFS_IOCORE_RT 0x1
163
164/*
165 * xfs_iocore prototypes
166 */
167
168extern void xfs_iocore_inode_init(struct xfs_inode *);
169extern void xfs_iocore_inode_reinit(struct xfs_inode *);
170
171
172/*
173 * This is the type used in the xfs inode hash table.
174 * An array of these is allocated for each mounted
175 * file system to hash the inodes for that file system.
176 */
177typedef struct xfs_ihash {
178 struct xfs_inode *ih_next;
179 rwlock_t ih_lock;
180 uint ih_version;
181} xfs_ihash_t;
182
183#define XFS_IHASH(mp,ino) ((mp)->m_ihash + (((uint)(ino)) % (mp)->m_ihsize))
184
185/*
186 * This is the xfs inode cluster hash. This hash is used by xfs_iflush to
187 * find inodes that share a cluster and can be flushed to disk at the same
188 * time.
189 */
190typedef struct xfs_chashlist {
191 struct xfs_chashlist *chl_next;
David Chinner1fc5d952006-04-11 15:11:12 +1000192 struct xfs_chashlist *chl_prev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 struct xfs_inode *chl_ip;
194 xfs_daddr_t chl_blkno; /* starting block number of
195 * the cluster */
196 struct xfs_buf *chl_buf; /* the inode buffer */
197} xfs_chashlist_t;
198
199typedef struct xfs_chash {
200 xfs_chashlist_t *ch_list;
201 lock_t ch_lock;
202} xfs_chash_t;
203
204#define XFS_CHASH(mp,blk) ((mp)->m_chash + (((uint)blk) % (mp)->m_chsize))
205
206
207/*
208 * This is the xfs in-core inode structure.
209 * Most of the on-disk inode is embedded in the i_d field.
210 *
211 * The extent pointers/inline file space, however, are managed
212 * separately. The memory for this information is pointed to by
213 * the if_u1 unions depending on the type of the data.
214 * This is used to linearize the array of extents for fast in-core
215 * access. This is used until the file's number of extents
216 * surpasses XFS_MAX_INCORE_EXTENTS, at which point all extent pointers
217 * are accessed through the buffer cache.
218 *
219 * Other state kept in the in-core inode is used for identification,
220 * locking, transactional updating, etc of the inode.
221 *
222 * Generally, we do not want to hold the i_rlock while holding the
223 * i_ilock. Hierarchy is i_iolock followed by i_rlock.
224 *
225 * xfs_iptr_t contains all the inode fields upto and including the
226 * i_mnext and i_mprev fields, it is used as a marker in the inode
227 * chain off the mount structure by xfs_sync calls.
228 */
229
230typedef struct {
231 struct xfs_ihash *ip_hash; /* pointer to hash header */
232 struct xfs_inode *ip_next; /* inode hash link forw */
233 struct xfs_inode *ip_mnext; /* next inode in mount list */
234 struct xfs_inode *ip_mprev; /* ptr to prev inode */
235 struct xfs_inode **ip_prevp; /* ptr to prev i_next */
236 struct xfs_mount *ip_mount; /* fs mount struct ptr */
237} xfs_iptr_t;
238
239typedef struct xfs_inode {
240 /* Inode linking and identification information. */
241 struct xfs_ihash *i_hash; /* pointer to hash header */
242 struct xfs_inode *i_next; /* inode hash link forw */
243 struct xfs_inode *i_mnext; /* next inode in mount list */
244 struct xfs_inode *i_mprev; /* ptr to prev inode */
245 struct xfs_inode **i_prevp; /* ptr to prev i_next */
246 struct xfs_mount *i_mount; /* fs mount struct ptr */
247 struct list_head i_reclaim; /* reclaim list */
248 struct bhv_desc i_bhv_desc; /* inode behavior descriptor*/
249 struct xfs_dquot *i_udquot; /* user dquot */
250 struct xfs_dquot *i_gdquot; /* group dquot */
251
252 /* Inode location stuff */
253 xfs_ino_t i_ino; /* inode number (agno/agino)*/
254 xfs_daddr_t i_blkno; /* blkno of inode buffer */
255 ushort i_len; /* len of inode buffer */
256 ushort i_boffset; /* off of inode in buffer */
257
258 /* Extent information. */
259 xfs_ifork_t *i_afp; /* attribute fork pointer */
260 xfs_ifork_t i_df; /* data fork */
261
262 /* Transaction and locking information. */
263 struct xfs_trans *i_transp; /* ptr to owning transaction*/
264 struct xfs_inode_log_item *i_itemp; /* logging information */
265 mrlock_t i_lock; /* inode lock */
266 mrlock_t i_iolock; /* inode IO lock */
267 sema_t i_flock; /* inode flush lock */
268 atomic_t i_pincount; /* inode pin count */
269 wait_queue_head_t i_ipin_wait; /* inode pinning wait queue */
David Chinnerf273ab82006-09-28 11:06:03 +1000270 spinlock_t i_flags_lock; /* inode i_flags lock */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271#ifdef HAVE_REFCACHE
272 struct xfs_inode **i_refcache; /* ptr to entry in ref cache */
273 struct xfs_inode *i_release; /* inode to unref */
274#endif
275 /* I/O state */
276 xfs_iocore_t i_iocore; /* I/O core */
277
278 /* Miscellaneous state. */
279 unsigned short i_flags; /* see defined flags below */
280 unsigned char i_update_core; /* timestamps/size is dirty */
281 unsigned char i_update_size; /* di_size field is dirty */
282 unsigned int i_gen; /* generation count */
283 unsigned int i_delayed_blks; /* count of delay alloc blks */
284
285 xfs_dinode_core_t i_d; /* most of ondisk inode */
286 xfs_chashlist_t *i_chash; /* cluster hash list header */
287 struct xfs_inode *i_cnext; /* cluster hash link forward */
288 struct xfs_inode *i_cprev; /* cluster hash link backward */
289
Lachlan McIlroyba87ea62007-05-08 13:49:46 +1000290 xfs_fsize_t i_size; /* in-memory size */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 /* Trace buffers per inode. */
292#ifdef XFS_BMAP_TRACE
293 struct ktrace *i_xtrace; /* inode extent list trace */
294#endif
295#ifdef XFS_BMBT_TRACE
296 struct ktrace *i_btrace; /* inode bmap btree trace */
297#endif
298#ifdef XFS_RW_TRACE
299 struct ktrace *i_rwtrace; /* inode read/write trace */
300#endif
301#ifdef XFS_ILOCK_TRACE
302 struct ktrace *i_lock_trace; /* inode lock/unlock trace */
303#endif
304#ifdef XFS_DIR2_TRACE
305 struct ktrace *i_dir_trace; /* inode directory trace */
306#endif
307} xfs_inode_t;
308
Lachlan McIlroyba87ea62007-05-08 13:49:46 +1000309#define XFS_ISIZE(ip) (((ip)->i_d.di_mode & S_IFMT) == S_IFREG) ? \
310 (ip)->i_size : (ip)->i_d.di_size;
David Chinner7a18c382006-11-11 18:04:54 +1100311
312/*
313 * i_flags helper functions
314 */
315static inline void
316__xfs_iflags_set(xfs_inode_t *ip, unsigned short flags)
317{
318 ip->i_flags |= flags;
319}
320
321static inline void
322xfs_iflags_set(xfs_inode_t *ip, unsigned short flags)
323{
324 spin_lock(&ip->i_flags_lock);
325 __xfs_iflags_set(ip, flags);
326 spin_unlock(&ip->i_flags_lock);
327}
328
329static inline void
330xfs_iflags_clear(xfs_inode_t *ip, unsigned short flags)
331{
332 spin_lock(&ip->i_flags_lock);
333 ip->i_flags &= ~flags;
334 spin_unlock(&ip->i_flags_lock);
335}
336
337static inline int
338__xfs_iflags_test(xfs_inode_t *ip, unsigned short flags)
339{
340 return (ip->i_flags & flags);
341}
342
343static inline int
344xfs_iflags_test(xfs_inode_t *ip, unsigned short flags)
345{
346 int ret;
347 spin_lock(&ip->i_flags_lock);
348 ret = __xfs_iflags_test(ip, flags);
349 spin_unlock(&ip->i_flags_lock);
350 return ret;
351}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352#endif /* __KERNEL__ */
353
354
355/*
356 * Fork handling.
357 */
Nathan Scotta844f452005-11-02 14:38:42 +1100358#define XFS_IFORK_PTR(ip,w) \
359 ((w) == XFS_DATA_FORK ? &(ip)->i_df : (ip)->i_afp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360#define XFS_IFORK_Q(ip) XFS_CFORK_Q(&(ip)->i_d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361#define XFS_IFORK_DSIZE(ip) XFS_CFORK_DSIZE(&ip->i_d, ip->i_mount)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362#define XFS_IFORK_ASIZE(ip) XFS_CFORK_ASIZE(&ip->i_d, ip->i_mount)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363#define XFS_IFORK_SIZE(ip,w) XFS_CFORK_SIZE(&ip->i_d, ip->i_mount, w)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364#define XFS_IFORK_FORMAT(ip,w) XFS_CFORK_FORMAT(&ip->i_d, w)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365#define XFS_IFORK_FMT_SET(ip,w,n) XFS_CFORK_FMT_SET(&ip->i_d, w, n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366#define XFS_IFORK_NEXTENTS(ip,w) XFS_CFORK_NEXTENTS(&ip->i_d, w)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367#define XFS_IFORK_NEXT_SET(ip,w,n) XFS_CFORK_NEXT_SET(&ip->i_d, w, n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
369
370#ifdef __KERNEL__
371
372/*
373 * In-core inode flags.
374 */
375#define XFS_IGRIO 0x0001 /* inode used for guaranteed rate i/o */
376#define XFS_IUIOSZ 0x0002 /* inode i/o sizes have been explicitly set */
377#define XFS_IQUIESCE 0x0004 /* we have started quiescing for this inode */
378#define XFS_IRECLAIM 0x0008 /* we have started reclaiming this inode */
379#define XFS_ISTALE 0x0010 /* inode has been staled */
380#define XFS_IRECLAIMABLE 0x0020 /* inode can be reclaimed */
381#define XFS_INEW 0x0040
David Chinner2a82b8b2007-07-11 11:09:12 +1000382#define XFS_IFILESTREAM 0x0080 /* inode is in a filestream directory */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383
384/*
385 * Flags for inode locking.
Lachlan McIlroyf7c66ce2007-05-08 13:50:19 +1000386 * Bit ranges: 1<<1 - 1<<16-1 -- iolock/ilock modes (bitfield)
387 * 1<<16 - 1<<32-1 -- lockdep annotation (integers)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 */
Lachlan McIlroyf7c66ce2007-05-08 13:50:19 +1000389#define XFS_IOLOCK_EXCL (1<<0)
390#define XFS_IOLOCK_SHARED (1<<1)
391#define XFS_ILOCK_EXCL (1<<2)
392#define XFS_ILOCK_SHARED (1<<3)
393#define XFS_IUNLOCK_NONOTIFY (1<<4)
394/* #define XFS_IOLOCK_NESTED (1<<5) */
395#define XFS_EXTENT_TOKEN_RD (1<<6)
396#define XFS_SIZE_TOKEN_RD (1<<7)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397#define XFS_EXTSIZE_RD (XFS_EXTENT_TOKEN_RD|XFS_SIZE_TOKEN_RD)
Lachlan McIlroyf7c66ce2007-05-08 13:50:19 +1000398#define XFS_WILLLEND (1<<8) /* Always acquire tokens for lending */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399#define XFS_EXTENT_TOKEN_WR (XFS_EXTENT_TOKEN_RD | XFS_WILLLEND)
400#define XFS_SIZE_TOKEN_WR (XFS_SIZE_TOKEN_RD | XFS_WILLLEND)
401#define XFS_EXTSIZE_WR (XFS_EXTSIZE_RD | XFS_WILLLEND)
Lachlan McIlroyf7c66ce2007-05-08 13:50:19 +1000402/* TODO:XFS_SIZE_TOKEN_WANT (1<<9) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403
Lachlan McIlroyf7c66ce2007-05-08 13:50:19 +1000404#define XFS_LOCK_MASK (XFS_IOLOCK_EXCL | XFS_IOLOCK_SHARED \
405 | XFS_ILOCK_EXCL | XFS_ILOCK_SHARED \
406 | XFS_EXTENT_TOKEN_RD | XFS_SIZE_TOKEN_RD \
407 | XFS_WILLLEND)
408
409/*
410 * Flags for lockdep annotations.
411 *
412 * XFS_I[O]LOCK_PARENT - for operations that require locking two inodes
413 * (ie directory operations that require locking a directory inode and
414 * an entry inode). The first inode gets locked with this flag so it
415 * gets a lockdep subclass of 1 and the second lock will have a lockdep
416 * subclass of 0.
417 *
David Chinner0f1145c2007-06-29 17:26:09 +1000418 * XFS_LOCK_INUMORDER - for locking several inodes at the some time
Lachlan McIlroyf7c66ce2007-05-08 13:50:19 +1000419 * with xfs_lock_inodes(). This flag is used as the starting subclass
420 * and each subsequent lock acquired will increment the subclass by one.
421 * So the first lock acquired will have a lockdep subclass of 2, the
David Chinner0f1145c2007-06-29 17:26:09 +1000422 * second lock will have a lockdep subclass of 3, and so on. It is
423 * the responsibility of the class builder to shift this to the correct
424 * portion of the lock_mode lockdep mask.
Lachlan McIlroyf7c66ce2007-05-08 13:50:19 +1000425 */
David Chinner0f1145c2007-06-29 17:26:09 +1000426#define XFS_LOCK_PARENT 1
427#define XFS_LOCK_INUMORDER 2
428
Lachlan McIlroyf7c66ce2007-05-08 13:50:19 +1000429#define XFS_IOLOCK_SHIFT 16
David Chinner0f1145c2007-06-29 17:26:09 +1000430#define XFS_IOLOCK_PARENT (XFS_LOCK_PARENT << XFS_IOLOCK_SHIFT)
Lachlan McIlroyf7c66ce2007-05-08 13:50:19 +1000431
432#define XFS_ILOCK_SHIFT 24
David Chinner0f1145c2007-06-29 17:26:09 +1000433#define XFS_ILOCK_PARENT (XFS_LOCK_PARENT << XFS_ILOCK_SHIFT)
Lachlan McIlroyf7c66ce2007-05-08 13:50:19 +1000434
435#define XFS_IOLOCK_DEP_MASK 0x00ff0000
436#define XFS_ILOCK_DEP_MASK 0xff000000
437#define XFS_LOCK_DEP_MASK (XFS_IOLOCK_DEP_MASK | XFS_ILOCK_DEP_MASK)
438
439#define XFS_IOLOCK_DEP(flags) (((flags) & XFS_IOLOCK_DEP_MASK) >> XFS_IOLOCK_SHIFT)
440#define XFS_ILOCK_DEP(flags) (((flags) & XFS_ILOCK_DEP_MASK) >> XFS_ILOCK_SHIFT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441
442/*
443 * Flags for xfs_iflush()
444 */
445#define XFS_IFLUSH_DELWRI_ELSE_SYNC 1
446#define XFS_IFLUSH_DELWRI_ELSE_ASYNC 2
447#define XFS_IFLUSH_SYNC 3
448#define XFS_IFLUSH_ASYNC 4
449#define XFS_IFLUSH_DELWRI 5
450
451/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 * Flags for xfs_itruncate_start().
453 */
454#define XFS_ITRUNC_DEFINITE 0x1
455#define XFS_ITRUNC_MAYBE 0x2
456
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457#define XFS_ITOV(ip) BHV_TO_VNODE(XFS_ITOBHV(ip))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458#define XFS_ITOV_NULL(ip) BHV_TO_VNODE_NULL(XFS_ITOBHV(ip))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459#define XFS_ITOBHV(ip) ((struct bhv_desc *)(&((ip)->i_bhv_desc)))
Nathan Scotta844f452005-11-02 14:38:42 +1100460#define XFS_BHVTOI(bhvp) ((xfs_inode_t *)((char *)(bhvp) - \
461 (char *)&(((xfs_inode_t *)0)->i_bhv_desc)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462#define BHV_IS_XFS(bdp) (BHV_OPS(bdp) == &xfs_vnodeops)
463
464/*
465 * For multiple groups support: if S_ISGID bit is set in the parent
466 * directory, group of new file is set to that of the parent, and
467 * new subdirectory gets S_ISGID bit from parent.
468 */
469#define XFS_INHERIT_GID(pip, vfsp) \
470 (((vfsp)->vfs_flag & VFS_GRPID) || ((pip)->i_d.di_mode & S_ISGID))
471
472/*
Nathan Scott745b1f472006-09-28 11:02:23 +1000473 * Flags for xfs_iget()
474 */
475#define XFS_IGET_CREATE 0x1
476#define XFS_IGET_BULKSTAT 0x2
477
478/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 * xfs_iget.c prototypes.
480 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481void xfs_ihash_init(struct xfs_mount *);
482void xfs_ihash_free(struct xfs_mount *);
483void xfs_chash_init(struct xfs_mount *);
484void xfs_chash_free(struct xfs_mount *);
485xfs_inode_t *xfs_inode_incore(struct xfs_mount *, xfs_ino_t,
486 struct xfs_trans *);
Nathan Scott67fcaa72006-06-09 17:00:52 +1000487void xfs_inode_lock_init(xfs_inode_t *, struct bhv_vnode *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488int xfs_iget(struct xfs_mount *, struct xfs_trans *, xfs_ino_t,
489 uint, uint, xfs_inode_t **, xfs_daddr_t);
490void xfs_iput(xfs_inode_t *, uint);
491void xfs_iput_new(xfs_inode_t *, uint);
492void xfs_ilock(xfs_inode_t *, uint);
493int xfs_ilock_nowait(xfs_inode_t *, uint);
494void xfs_iunlock(xfs_inode_t *, uint);
495void xfs_ilock_demote(xfs_inode_t *, uint);
496void xfs_iflock(xfs_inode_t *);
497int xfs_iflock_nowait(xfs_inode_t *);
498uint xfs_ilock_map_shared(xfs_inode_t *);
499void xfs_iunlock_map_shared(xfs_inode_t *, uint);
500void xfs_ifunlock(xfs_inode_t *);
501void xfs_ireclaim(xfs_inode_t *);
502int xfs_finish_reclaim(xfs_inode_t *, int, int);
503int xfs_finish_reclaim_all(struct xfs_mount *, int);
504
505/*
506 * xfs_inode.c prototypes.
507 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508int xfs_itobp(struct xfs_mount *, struct xfs_trans *,
509 xfs_inode_t *, xfs_dinode_t **, struct xfs_buf **,
Nathan Scottb12dd342006-03-17 17:26:04 +1100510 xfs_daddr_t, uint);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511int xfs_iread(struct xfs_mount *, struct xfs_trans *, xfs_ino_t,
Nathan Scott745b1f472006-09-28 11:02:23 +1000512 xfs_inode_t **, xfs_daddr_t, uint);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513int xfs_iread_extents(struct xfs_trans *, xfs_inode_t *, int);
Nathan Scott31b084a2005-05-05 13:25:00 -0700514int xfs_ialloc(struct xfs_trans *, xfs_inode_t *, mode_t,
515 xfs_nlink_t, xfs_dev_t, struct cred *, xfs_prid_t,
516 int, struct xfs_buf **, boolean_t *, xfs_inode_t **);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517void xfs_xlate_dinode_core(xfs_caddr_t, struct xfs_dinode_core *,
518 int);
519uint xfs_ip2xflags(struct xfs_inode *);
520uint xfs_dic2xflags(struct xfs_dinode_core *);
521int xfs_ifree(struct xfs_trans *, xfs_inode_t *,
522 struct xfs_bmap_free *);
Lachlan McIlroyd3cf2092007-05-08 13:49:27 +1000523int xfs_itruncate_start(xfs_inode_t *, uint, xfs_fsize_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524int xfs_itruncate_finish(struct xfs_trans **, xfs_inode_t *,
525 xfs_fsize_t, int, int);
526int xfs_iunlink(struct xfs_trans *, xfs_inode_t *);
527int xfs_igrow_start(xfs_inode_t *, xfs_fsize_t, struct cred *);
528void xfs_igrow_finish(struct xfs_trans *, xfs_inode_t *,
529 xfs_fsize_t, int);
530
531void xfs_idestroy_fork(xfs_inode_t *, int);
532void xfs_idestroy(xfs_inode_t *);
533void xfs_idata_realloc(xfs_inode_t *, int, int);
534void xfs_iextract(xfs_inode_t *);
535void xfs_iext_realloc(xfs_inode_t *, int, int);
536void xfs_iroot_realloc(xfs_inode_t *, int, int);
537void xfs_ipin(xfs_inode_t *);
538void xfs_iunpin(xfs_inode_t *);
539int xfs_iextents_copy(xfs_inode_t *, xfs_bmbt_rec_t *, int);
540int xfs_iflush(xfs_inode_t *, uint);
Christoph Hellwigefa80272005-06-21 15:37:17 +1000541void xfs_iflush_all(struct xfs_mount *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542int xfs_iaccess(xfs_inode_t *, mode_t, cred_t *);
543uint xfs_iroundup(uint);
544void xfs_ichgtime(xfs_inode_t *, int);
545xfs_fsize_t xfs_file_last_byte(xfs_inode_t *);
546void xfs_lock_inodes(xfs_inode_t **, int, int, uint);
547
Nathan Scott67fcaa72006-06-09 17:00:52 +1000548xfs_inode_t *xfs_vtoi(struct bhv_vnode *vp);
Christoph Hellwig75e17b32006-01-11 20:58:44 +1100549
Christoph Hellwig42fe2b12006-01-11 15:35:17 +1100550void xfs_synchronize_atime(xfs_inode_t *);
551
Mandy Kirkconnell4eea22f2006-03-14 13:29:52 +1100552xfs_bmbt_rec_t *xfs_iext_get_ext(xfs_ifork_t *, xfs_extnum_t);
553void xfs_iext_insert(xfs_ifork_t *, xfs_extnum_t, xfs_extnum_t,
554 xfs_bmbt_irec_t *);
555void xfs_iext_add(xfs_ifork_t *, xfs_extnum_t, int);
Mandy Kirkconnell0293ce32006-03-14 13:30:23 +1100556void xfs_iext_add_indirect_multi(xfs_ifork_t *, int, xfs_extnum_t, int);
Mandy Kirkconnell4eea22f2006-03-14 13:29:52 +1100557void xfs_iext_remove(xfs_ifork_t *, xfs_extnum_t, int);
558void xfs_iext_remove_inline(xfs_ifork_t *, xfs_extnum_t, int);
559void xfs_iext_remove_direct(xfs_ifork_t *, xfs_extnum_t, int);
Mandy Kirkconnell0293ce32006-03-14 13:30:23 +1100560void xfs_iext_remove_indirect(xfs_ifork_t *, xfs_extnum_t, int);
Mandy Kirkconnell4eea22f2006-03-14 13:29:52 +1100561void xfs_iext_realloc_direct(xfs_ifork_t *, int);
Mandy Kirkconnell0293ce32006-03-14 13:30:23 +1100562void xfs_iext_realloc_indirect(xfs_ifork_t *, int);
563void xfs_iext_indirect_to_direct(xfs_ifork_t *);
Mandy Kirkconnell4eea22f2006-03-14 13:29:52 +1100564void xfs_iext_direct_to_inline(xfs_ifork_t *, xfs_extnum_t);
565void xfs_iext_inline_to_direct(xfs_ifork_t *, int);
566void xfs_iext_destroy(xfs_ifork_t *);
Mandy Kirkconnell8867bc92006-03-17 17:25:04 +1100567xfs_bmbt_rec_t *xfs_iext_bno_to_ext(xfs_ifork_t *, xfs_fileoff_t, int *);
Mandy Kirkconnell0293ce32006-03-14 13:30:23 +1100568xfs_ext_irec_t *xfs_iext_bno_to_irec(xfs_ifork_t *, xfs_fileoff_t, int *);
569xfs_ext_irec_t *xfs_iext_idx_to_irec(xfs_ifork_t *, xfs_extnum_t *, int *, int);
570void xfs_iext_irec_init(xfs_ifork_t *);
571xfs_ext_irec_t *xfs_iext_irec_new(xfs_ifork_t *, int);
572void xfs_iext_irec_remove(xfs_ifork_t *, int);
573void xfs_iext_irec_compact(xfs_ifork_t *);
574void xfs_iext_irec_compact_pages(xfs_ifork_t *);
575void xfs_iext_irec_compact_full(xfs_ifork_t *);
576void xfs_iext_irec_update_extoffs(xfs_ifork_t *, int, int);
Mandy Kirkconnell4eea22f2006-03-14 13:29:52 +1100577
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578#define xfs_ipincount(ip) ((unsigned int) atomic_read(&ip->i_pincount))
579
580#ifdef DEBUG
581void xfs_isize_check(struct xfs_mount *, xfs_inode_t *, xfs_fsize_t);
582#else /* DEBUG */
583#define xfs_isize_check(mp, ip, isize)
584#endif /* DEBUG */
585
586#if defined(DEBUG)
587void xfs_inobp_check(struct xfs_mount *, struct xfs_buf *);
588#else
589#define xfs_inobp_check(mp, bp)
590#endif /* DEBUG */
591
592extern struct kmem_zone *xfs_chashlist_zone;
593extern struct kmem_zone *xfs_ifork_zone;
594extern struct kmem_zone *xfs_inode_zone;
595extern struct kmem_zone *xfs_ili_zone;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596
597#endif /* __KERNEL__ */
598
599#endif /* __XFS_INODE_H__ */