blob: de4f963b268c5203bd15c2d77ca3a963d2d160a2 [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
Christoph Hellwigef14f0c2009-06-10 17:07:47 +020021struct posix_acl;
Christoph Hellwig347d1c02007-08-28 13:57:51 +100022struct xfs_dinode;
Barry Naujok847fff52008-10-30 17:05:38 +110023struct xfs_inode;
Christoph Hellwig347d1c02007-08-28 13:57:51 +100024
Linus Torvalds1da177e2005-04-16 15:20:36 -070025/*
Mandy Kirkconnell0293ce32006-03-14 13:30:23 +110026 * The following xfs_ext_irec_t struct introduces a second (top) level
27 * to the in-core extent allocation scheme. These structs are allocated
28 * in a contiguous block, creating an indirection array where each entry
29 * (irec) contains a pointer to a buffer of in-core extent records which
30 * it manages. Each extent buffer is 4k in size, since 4k is the system
31 * page size on Linux i386 and systems with larger page sizes don't seem
32 * to gain much, if anything, by using their native page size as the
33 * extent buffer size. Also, using 4k extent buffers everywhere provides
34 * a consistent interface for CXFS across different platforms.
35 *
36 * There is currently no limit on the number of irec's (extent lists)
37 * allowed, so heavily fragmented files may require an indirection array
38 * which spans multiple system pages of memory. The number of extents
39 * which would require this amount of contiguous memory is very large
40 * and should not cause problems in the foreseeable future. However,
41 * if the memory needed for the contiguous array ever becomes a problem,
42 * it is possible that a third level of indirection may be required.
43 */
44typedef struct xfs_ext_irec {
Christoph Hellwiga6f64d42007-08-16 16:23:40 +100045 xfs_bmbt_rec_host_t *er_extbuf; /* block of extent records */
Mandy Kirkconnell0293ce32006-03-14 13:30:23 +110046 xfs_extnum_t er_extoff; /* extent offset in file */
47 xfs_extnum_t er_extcount; /* number of extents in page/block */
48} xfs_ext_irec_t;
49
50/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 * File incore extent information, present for each of data & attr forks.
52 */
Mandy Kirkconnell0293ce32006-03-14 13:30:23 +110053#define XFS_IEXT_BUFSZ 4096
54#define XFS_LINEAR_EXTS (XFS_IEXT_BUFSZ / (uint)sizeof(xfs_bmbt_rec_t))
55#define XFS_INLINE_EXTS 2
56#define XFS_INLINE_DATA 32
Linus Torvalds1da177e2005-04-16 15:20:36 -070057typedef struct xfs_ifork {
58 int if_bytes; /* bytes in if_u1 */
59 int if_real_bytes; /* bytes allocated in if_u1 */
Christoph Hellwig7cc95a82008-10-30 17:14:34 +110060 struct xfs_btree_block *if_broot; /* file's incore btree root */
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 short if_broot_bytes; /* bytes allocated for root */
62 unsigned char if_flags; /* per-fork flags */
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 union {
Christoph Hellwiga6f64d42007-08-16 16:23:40 +100064 xfs_bmbt_rec_host_t *if_extents;/* linear map file exts */
Mandy Kirkconnell0293ce32006-03-14 13:30:23 +110065 xfs_ext_irec_t *if_ext_irec; /* irec map file exts */
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 char *if_data; /* inline file data */
67 } if_u1;
68 union {
Christoph Hellwiga6f64d42007-08-16 16:23:40 +100069 xfs_bmbt_rec_host_t if_inline_ext[XFS_INLINE_EXTS];
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 /* very small file extents */
71 char if_inline_data[XFS_INLINE_DATA];
72 /* very small file data */
73 xfs_dev_t if_rdev; /* dev number if special */
74 uuid_t if_uuid; /* mount point value */
75 } if_u2;
76} xfs_ifork_t;
77
78/*
Christoph Hellwig92bfc6e2008-11-28 14:23:41 +110079 * Inode location information. Stored in the inode and passed to
80 * xfs_imap_to_bp() to get a buffer and dinode for a given inode.
81 */
82struct xfs_imap {
83 xfs_daddr_t im_blkno; /* starting BB of inode chunk */
84 ushort im_len; /* length in BBs of inode chunk */
85 ushort im_boffset; /* inode offset in block in bytes */
86};
87
88/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 * This is the xfs in-core inode structure.
90 * Most of the on-disk inode is embedded in the i_d field.
91 *
92 * The extent pointers/inline file space, however, are managed
93 * separately. The memory for this information is pointed to by
94 * the if_u1 unions depending on the type of the data.
95 * This is used to linearize the array of extents for fast in-core
96 * access. This is used until the file's number of extents
97 * surpasses XFS_MAX_INCORE_EXTENTS, at which point all extent pointers
98 * are accessed through the buffer cache.
99 *
100 * Other state kept in the in-core inode is used for identification,
101 * locking, transactional updating, etc of the inode.
102 *
103 * Generally, we do not want to hold the i_rlock while holding the
104 * i_ilock. Hierarchy is i_iolock followed by i_rlock.
105 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300106 * xfs_iptr_t contains all the inode fields up to and including the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 * i_mnext and i_mprev fields, it is used as a marker in the inode
108 * chain off the mount structure by xfs_sync calls.
109 */
110
Barry Naujok847fff52008-10-30 17:05:38 +1100111/*
112 * Flags for xfs_ichgtime().
113 */
114#define XFS_ICHGTIME_MOD 0x1 /* data fork modification timestamp */
115#define XFS_ICHGTIME_CHG 0x2 /* inode field change timestamp */
Christoph Hellwig93848a92013-04-03 16:11:17 +1100116#define XFS_ICHGTIME_CREATE 0x4 /* inode create timestamp */
Barry Naujok847fff52008-10-30 17:05:38 +1100117
118/*
119 * Per-fork incore inode flags.
120 */
121#define XFS_IFINLINE 0x01 /* Inline data is read in */
122#define XFS_IFEXTENTS 0x02 /* All extent pointers are read in */
123#define XFS_IFBROOT 0x04 /* i_broot points to the bmap b-tree root */
124#define XFS_IFEXTIREC 0x08 /* Indirection array of extent blocks */
125
126/*
Barry Naujok847fff52008-10-30 17:05:38 +1100127 * Fork handling.
128 */
129
130#define XFS_IFORK_Q(ip) ((ip)->i_d.di_forkoff != 0)
131#define XFS_IFORK_BOFF(ip) ((int)((ip)->i_d.di_forkoff << 3))
132
133#define XFS_IFORK_PTR(ip,w) \
134 ((w) == XFS_DATA_FORK ? \
135 &(ip)->i_df : \
136 (ip)->i_afp)
137#define XFS_IFORK_DSIZE(ip) \
138 (XFS_IFORK_Q(ip) ? \
139 XFS_IFORK_BOFF(ip) : \
Christoph Hellwig56cea2d2013-03-12 23:30:36 +1100140 XFS_LITINO((ip)->i_mount, (ip)->i_d.di_version))
Barry Naujok847fff52008-10-30 17:05:38 +1100141#define XFS_IFORK_ASIZE(ip) \
142 (XFS_IFORK_Q(ip) ? \
Christoph Hellwig56cea2d2013-03-12 23:30:36 +1100143 XFS_LITINO((ip)->i_mount, (ip)->i_d.di_version) - \
144 XFS_IFORK_BOFF(ip) : \
Barry Naujok847fff52008-10-30 17:05:38 +1100145 0)
146#define XFS_IFORK_SIZE(ip,w) \
147 ((w) == XFS_DATA_FORK ? \
148 XFS_IFORK_DSIZE(ip) : \
149 XFS_IFORK_ASIZE(ip))
150#define XFS_IFORK_FORMAT(ip,w) \
151 ((w) == XFS_DATA_FORK ? \
152 (ip)->i_d.di_format : \
153 (ip)->i_d.di_aformat)
154#define XFS_IFORK_FMT_SET(ip,w,n) \
155 ((w) == XFS_DATA_FORK ? \
156 ((ip)->i_d.di_format = (n)) : \
157 ((ip)->i_d.di_aformat = (n)))
158#define XFS_IFORK_NEXTENTS(ip,w) \
159 ((w) == XFS_DATA_FORK ? \
160 (ip)->i_d.di_nextents : \
161 (ip)->i_d.di_anextents)
162#define XFS_IFORK_NEXT_SET(ip,w,n) \
163 ((w) == XFS_DATA_FORK ? \
164 ((ip)->i_d.di_nextents = (n)) : \
165 ((ip)->i_d.di_anextents = (n)))
Christoph Hellwig8096b1e2011-12-18 20:00:07 +0000166#define XFS_IFORK_MAXEXT(ip, w) \
167 (XFS_IFORK_SIZE(ip, w) / sizeof(xfs_bmbt_rec_t))
Barry Naujok847fff52008-10-30 17:05:38 +1100168
169
170#ifdef __KERNEL__
171
Barry Naujok847fff52008-10-30 17:05:38 +1100172struct xfs_buf;
173struct xfs_bmap_free;
174struct xfs_bmbt_irec;
Barry Naujok847fff52008-10-30 17:05:38 +1100175struct xfs_inode_log_item;
176struct xfs_mount;
177struct xfs_trans;
178struct xfs_dquot;
179
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180typedef struct xfs_inode {
181 /* Inode linking and identification information. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 struct xfs_mount *i_mount; /* fs mount struct ptr */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 struct xfs_dquot *i_udquot; /* user dquot */
184 struct xfs_dquot *i_gdquot; /* group dquot */
Chandra Seetharaman92f8ff72013-07-11 00:00:40 -0500185 struct xfs_dquot *i_pdquot; /* project dquot */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186
187 /* Inode location stuff */
188 xfs_ino_t i_ino; /* inode number (agno/agino)*/
Christoph Hellwig92bfc6e2008-11-28 14:23:41 +1100189 struct xfs_imap i_imap; /* location for xfs_imap() */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
191 /* Extent information. */
192 xfs_ifork_t *i_afp; /* attribute fork pointer */
193 xfs_ifork_t i_df; /* data fork */
194
195 /* Transaction and locking information. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 struct xfs_inode_log_item *i_itemp; /* logging information */
197 mrlock_t i_lock; /* inode lock */
198 mrlock_t i_iolock; /* inode IO lock */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 atomic_t i_pincount; /* inode pin count */
David Chinnerf273ab82006-09-28 11:06:03 +1000200 spinlock_t i_flags_lock; /* inode i_flags lock */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 /* Miscellaneous state. */
Christoph Hellwig49e4c702011-12-18 20:00:08 +0000202 unsigned long i_flags; /* see defined flags below */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 unsigned int i_delayed_blks; /* count of delay alloc blks */
204
Christoph Hellwig347d1c02007-08-28 13:57:51 +1000205 xfs_icdinode_t i_d; /* most of ondisk inode */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
David Chinnerbf904242008-10-30 17:36:14 +1100207 /* VFS inode */
208 struct inode i_vnode; /* embedded VFS inode */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209} xfs_inode_t;
210
David Chinner01651642008-08-13 15:45:15 +1000211/* Convert from vfs inode to xfs inode */
212static inline struct xfs_inode *XFS_I(struct inode *inode)
213{
David Chinnerbf904242008-10-30 17:36:14 +1100214 return container_of(inode, struct xfs_inode, i_vnode);
David Chinner01651642008-08-13 15:45:15 +1000215}
216
David Chinner01651642008-08-13 15:45:15 +1000217/* convert from xfs inode to vfs inode */
218static inline struct inode *VFS_I(struct xfs_inode *ip)
219{
David Chinnerbf904242008-10-30 17:36:14 +1100220 return &ip->i_vnode;
David Chinner01651642008-08-13 15:45:15 +1000221}
David Chinner01651642008-08-13 15:45:15 +1000222
David Chinner7a18c382006-11-11 18:04:54 +1100223/*
Christoph Hellwigce7ae1512011-12-18 20:00:11 +0000224 * For regular files we only update the on-disk filesize when actually
225 * writing data back to disk. Until then only the copy in the VFS inode
226 * is uptodate.
227 */
228static inline xfs_fsize_t XFS_ISIZE(struct xfs_inode *ip)
229{
230 if (S_ISREG(ip->i_d.di_mode))
231 return i_size_read(VFS_I(ip));
232 return ip->i_d.di_size;
233}
234
235/*
Christoph Hellwig6923e682012-02-29 09:53:49 +0000236 * If this I/O goes past the on-disk inode size update it unless it would
237 * be past the current in-core inode size.
238 */
239static inline xfs_fsize_t
240xfs_new_eof(struct xfs_inode *ip, xfs_fsize_t new_size)
241{
242 xfs_fsize_t i_size = i_size_read(VFS_I(ip));
243
244 if (new_size > i_size)
245 new_size = i_size;
246 return new_size > ip->i_d.di_size ? new_size : 0;
247}
248
249/*
David Chinner7a18c382006-11-11 18:04:54 +1100250 * i_flags helper functions
251 */
252static inline void
253__xfs_iflags_set(xfs_inode_t *ip, unsigned short flags)
254{
255 ip->i_flags |= flags;
256}
257
258static inline void
259xfs_iflags_set(xfs_inode_t *ip, unsigned short flags)
260{
261 spin_lock(&ip->i_flags_lock);
262 __xfs_iflags_set(ip, flags);
263 spin_unlock(&ip->i_flags_lock);
264}
265
266static inline void
267xfs_iflags_clear(xfs_inode_t *ip, unsigned short flags)
268{
269 spin_lock(&ip->i_flags_lock);
270 ip->i_flags &= ~flags;
271 spin_unlock(&ip->i_flags_lock);
272}
273
274static inline int
275__xfs_iflags_test(xfs_inode_t *ip, unsigned short flags)
276{
277 return (ip->i_flags & flags);
278}
279
280static inline int
281xfs_iflags_test(xfs_inode_t *ip, unsigned short flags)
282{
283 int ret;
284 spin_lock(&ip->i_flags_lock);
285 ret = __xfs_iflags_test(ip, flags);
286 spin_unlock(&ip->i_flags_lock);
287 return ret;
288}
Christoph Hellwig09262b432007-08-29 11:44:50 +1000289
290static inline int
291xfs_iflags_test_and_clear(xfs_inode_t *ip, unsigned short flags)
292{
293 int ret;
294
295 spin_lock(&ip->i_flags_lock);
296 ret = ip->i_flags & flags;
297 if (ret)
298 ip->i_flags &= ~flags;
299 spin_unlock(&ip->i_flags_lock);
300 return ret;
301}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302
Christoph Hellwig474fce02011-12-18 20:00:09 +0000303static inline int
304xfs_iflags_test_and_set(xfs_inode_t *ip, unsigned short flags)
305{
306 int ret;
307
308 spin_lock(&ip->i_flags_lock);
309 ret = ip->i_flags & flags;
310 if (!ret)
311 ip->i_flags |= flags;
312 spin_unlock(&ip->i_flags_lock);
313 return ret;
314}
315
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316/*
Arkadiusz Mi?kiewicz67430992010-09-26 06:10:18 +0000317 * Project quota id helpers (previously projid was 16bit only
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300318 * and using two 16bit values to hold new 32bit projid was chosen
Arkadiusz Mi?kiewicz67430992010-09-26 06:10:18 +0000319 * to retain compatibility with "old" filesystems).
320 */
321static inline prid_t
322xfs_get_projid(struct xfs_inode *ip)
323{
324 return (prid_t)ip->i_d.di_projid_hi << 16 | ip->i_d.di_projid_lo;
325}
326
327static inline void
328xfs_set_projid(struct xfs_inode *ip,
329 prid_t projid)
330{
331 ip->i_d.di_projid_hi = (__uint16_t) (projid >> 16);
332 ip->i_d.di_projid_lo = (__uint16_t) (projid & 0xffff);
333}
334
335/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 * In-core inode flags.
337 */
Christoph Hellwig474fce02011-12-18 20:00:09 +0000338#define XFS_IRECLAIM (1 << 0) /* started reclaiming this inode */
339#define XFS_ISTALE (1 << 1) /* inode has been staled */
340#define XFS_IRECLAIMABLE (1 << 2) /* inode can be reclaimed */
341#define XFS_INEW (1 << 3) /* inode has just been allocated */
342#define XFS_IFILESTREAM (1 << 4) /* inode is in a filestream dir. */
343#define XFS_ITRUNCATED (1 << 5) /* truncated down so flush-on-close */
344#define XFS_IDIRTY_RELEASE (1 << 6) /* dirty release already seen */
345#define __XFS_IFLOCK_BIT 7 /* inode is being flushed right now */
346#define XFS_IFLOCK (1 << __XFS_IFLOCK_BIT)
Christoph Hellwigf392e632011-12-18 20:00:10 +0000347#define __XFS_IPINNED_BIT 8 /* wakeup key for zero pin count */
348#define XFS_IPINNED (1 << __XFS_IPINNED_BIT)
Dave Chinner5132ba82012-03-22 05:15:10 +0000349#define XFS_IDONTCACHE (1 << 9) /* don't cache the inode long term */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350
351/*
Dave Chinner778e24b2011-06-23 01:34:59 +0000352 * Per-lifetime flags need to be reset when re-using a reclaimable inode during
Dave Chinner5132ba82012-03-22 05:15:10 +0000353 * inode lookup. This prevents unintended behaviour on the new inode from
Dave Chinner778e24b2011-06-23 01:34:59 +0000354 * ocurring.
355 */
356#define XFS_IRECLAIM_RESET_FLAGS \
357 (XFS_IRECLAIMABLE | XFS_IRECLAIM | \
358 XFS_IDIRTY_RELEASE | XFS_ITRUNCATED | \
359 XFS_IFILESTREAM);
360
361/*
Christoph Hellwig474fce02011-12-18 20:00:09 +0000362 * Synchronize processes attempting to flush the in-core inode back to disk.
363 */
364
365extern void __xfs_iflock(struct xfs_inode *ip);
366
367static inline int xfs_iflock_nowait(struct xfs_inode *ip)
368{
369 return !xfs_iflags_test_and_set(ip, XFS_IFLOCK);
370}
371
372static inline void xfs_iflock(struct xfs_inode *ip)
373{
374 if (!xfs_iflock_nowait(ip))
375 __xfs_iflock(ip);
376}
377
378static inline void xfs_ifunlock(struct xfs_inode *ip)
379{
380 xfs_iflags_clear(ip, XFS_IFLOCK);
Alex Elder311f08a2013-02-04 10:13:11 -0600381 smp_mb();
Christoph Hellwig474fce02011-12-18 20:00:09 +0000382 wake_up_bit(&ip->i_flags, __XFS_IFLOCK_BIT);
383}
384
385static inline int xfs_isiflocked(struct xfs_inode *ip)
386{
387 return xfs_iflags_test(ip, XFS_IFLOCK);
388}
389
390/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 * Flags for inode locking.
Lachlan McIlroyf7c66ce2007-05-08 13:50:19 +1000392 * Bit ranges: 1<<1 - 1<<16-1 -- iolock/ilock modes (bitfield)
393 * 1<<16 - 1<<32-1 -- lockdep annotation (integers)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 */
Lachlan McIlroyf7c66ce2007-05-08 13:50:19 +1000395#define XFS_IOLOCK_EXCL (1<<0)
396#define XFS_IOLOCK_SHARED (1<<1)
397#define XFS_ILOCK_EXCL (1<<2)
398#define XFS_ILOCK_SHARED (1<<3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
Lachlan McIlroyf7c66ce2007-05-08 13:50:19 +1000400#define XFS_LOCK_MASK (XFS_IOLOCK_EXCL | XFS_IOLOCK_SHARED \
Christoph Hellwig579aa9c2008-04-22 17:34:00 +1000401 | XFS_ILOCK_EXCL | XFS_ILOCK_SHARED)
Lachlan McIlroyf7c66ce2007-05-08 13:50:19 +1000402
Christoph Hellwig0b1b2132009-12-14 23:14:59 +0000403#define XFS_LOCK_FLAGS \
404 { XFS_IOLOCK_EXCL, "IOLOCK_EXCL" }, \
405 { XFS_IOLOCK_SHARED, "IOLOCK_SHARED" }, \
406 { XFS_ILOCK_EXCL, "ILOCK_EXCL" }, \
Christoph Hellwig5b03ff12012-02-20 02:31:22 +0000407 { XFS_ILOCK_SHARED, "ILOCK_SHARED" }
Christoph Hellwig0b1b2132009-12-14 23:14:59 +0000408
409
Lachlan McIlroyf7c66ce2007-05-08 13:50:19 +1000410/*
411 * Flags for lockdep annotations.
412 *
Christoph Hellwig96811532011-01-25 09:06:21 +0000413 * XFS_LOCK_PARENT - for directory operations that require locking a
414 * parent directory inode and a child entry inode. The parent gets locked
415 * with this flag so it gets a lockdep subclass of 1 and the child entry
416 * lock will have a lockdep subclass of 0.
417 *
418 * XFS_LOCK_RTBITMAP/XFS_LOCK_RTSUM - the realtime device bitmap and summary
419 * inodes do not participate in the normal lock order, and thus have their
420 * own subclasses.
Lachlan McIlroyf7c66ce2007-05-08 13:50:19 +1000421 *
David Chinner0f1145c2007-06-29 17:26:09 +1000422 * XFS_LOCK_INUMORDER - for locking several inodes at the some time
Lachlan McIlroyf7c66ce2007-05-08 13:50:19 +1000423 * with xfs_lock_inodes(). This flag is used as the starting subclass
424 * and each subsequent lock acquired will increment the subclass by one.
Christoph Hellwig96811532011-01-25 09:06:21 +0000425 * So the first lock acquired will have a lockdep subclass of 4, the
426 * second lock will have a lockdep subclass of 5, and so on. It is
David Chinner0f1145c2007-06-29 17:26:09 +1000427 * the responsibility of the class builder to shift this to the correct
428 * portion of the lock_mode lockdep mask.
Lachlan McIlroyf7c66ce2007-05-08 13:50:19 +1000429 */
David Chinner0f1145c2007-06-29 17:26:09 +1000430#define XFS_LOCK_PARENT 1
Christoph Hellwig96811532011-01-25 09:06:21 +0000431#define XFS_LOCK_RTBITMAP 2
432#define XFS_LOCK_RTSUM 3
433#define XFS_LOCK_INUMORDER 4
David Chinner0f1145c2007-06-29 17:26:09 +1000434
Lachlan McIlroyf7c66ce2007-05-08 13:50:19 +1000435#define XFS_IOLOCK_SHIFT 16
David Chinner0f1145c2007-06-29 17:26:09 +1000436#define XFS_IOLOCK_PARENT (XFS_LOCK_PARENT << XFS_IOLOCK_SHIFT)
Lachlan McIlroyf7c66ce2007-05-08 13:50:19 +1000437
438#define XFS_ILOCK_SHIFT 24
David Chinner0f1145c2007-06-29 17:26:09 +1000439#define XFS_ILOCK_PARENT (XFS_LOCK_PARENT << XFS_ILOCK_SHIFT)
Christoph Hellwig96811532011-01-25 09:06:21 +0000440#define XFS_ILOCK_RTBITMAP (XFS_LOCK_RTBITMAP << XFS_ILOCK_SHIFT)
441#define XFS_ILOCK_RTSUM (XFS_LOCK_RTSUM << XFS_ILOCK_SHIFT)
Lachlan McIlroyf7c66ce2007-05-08 13:50:19 +1000442
443#define XFS_IOLOCK_DEP_MASK 0x00ff0000
444#define XFS_ILOCK_DEP_MASK 0xff000000
445#define XFS_LOCK_DEP_MASK (XFS_IOLOCK_DEP_MASK | XFS_ILOCK_DEP_MASK)
446
447#define XFS_IOLOCK_DEP(flags) (((flags) & XFS_IOLOCK_DEP_MASK) >> XFS_IOLOCK_SHIFT)
448#define XFS_ILOCK_DEP(flags) (((flags) & XFS_ILOCK_DEP_MASK) >> XFS_ILOCK_SHIFT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
450/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 * For multiple groups support: if S_ISGID bit is set in the parent
452 * directory, group of new file is set to that of the parent, and
453 * new subdirectory gets S_ISGID bit from parent.
454 */
Christoph Hellwigbd186aa2007-08-30 17:21:12 +1000455#define XFS_INHERIT_GID(pip) \
456 (((pip)->i_mount->m_flags & XFS_MOUNT_GRPID) || \
457 ((pip)->i_d.di_mode & S_ISGID))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458
Dave Chinner33479e02012-10-08 21:56:11 +1100459
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460/*
Dave Chinner33479e02012-10-08 21:56:11 +1100461 * xfs_inode.c prototypes.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463void xfs_ilock(xfs_inode_t *, uint);
464int xfs_ilock_nowait(xfs_inode_t *, uint);
465void xfs_iunlock(xfs_inode_t *, uint);
466void xfs_ilock_demote(xfs_inode_t *, uint);
Christoph Hellwig579aa9c2008-04-22 17:34:00 +1000467int xfs_isilocked(xfs_inode_t *, uint);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468uint xfs_ilock_map_shared(xfs_inode_t *);
469void xfs_iunlock_map_shared(xfs_inode_t *, uint);
Al Viro576b1d62011-07-26 02:50:15 -0400470int xfs_ialloc(struct xfs_trans *, xfs_inode_t *, umode_t,
Arkadiusz Mi?kiewicz67430992010-09-26 06:10:18 +0000471 xfs_nlink_t, xfs_dev_t, prid_t, int,
Christoph Hellwig08358902012-07-04 10:54:47 -0400472 struct xfs_buf **, xfs_inode_t **);
Christoph Hellwig347d1c02007-08-28 13:57:51 +1000473
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474uint xfs_ip2xflags(struct xfs_inode *);
Christoph Hellwig45ba5982007-12-07 14:07:20 +1100475uint xfs_dic2xflags(struct xfs_dinode *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476int xfs_ifree(struct xfs_trans *, xfs_inode_t *,
477 struct xfs_bmap_free *);
Christoph Hellwig8f04c472011-07-08 14:34:34 +0200478int xfs_itruncate_extents(struct xfs_trans **, struct xfs_inode *,
479 int, xfs_fsize_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480int xfs_iunlink(struct xfs_trans *, xfs_inode_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482void xfs_iext_realloc(xfs_inode_t *, int, int);
Dave Chinner777df5a2010-02-06 12:37:26 +1100483void xfs_iunpin_wait(xfs_inode_t *);
Christoph Hellwig4c468192012-04-23 15:58:36 +1000484int xfs_iflush(struct xfs_inode *, struct xfs_buf **);
Christoph Hellwigcfa853e2008-04-22 17:34:06 +1000485void xfs_lock_inodes(xfs_inode_t **, int, uint);
Christoph Hellwige1cccd92008-08-13 16:18:07 +1000486void xfs_lock_two_inodes(xfs_inode_t *, xfs_inode_t *, uint);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
Dave Chinner2a0ec1d2012-04-23 15:59:02 +1000488xfs_extlen_t xfs_get_extsz_hint(struct xfs_inode *ip);
489
Christoph Hellwig5a8d0f32008-12-03 12:20:40 +0100490#define IHOLD(ip) \
491do { \
492 ASSERT(atomic_read(&VFS_I(ip)->i_count) > 0) ; \
Al Viro7de9c6ee2010-10-23 11:11:40 -0400493 ihold(VFS_I(ip)); \
Christoph Hellwig0b1b2132009-12-14 23:14:59 +0000494 trace_xfs_ihold(ip, _THIS_IP_); \
Christoph Hellwig5a8d0f32008-12-03 12:20:40 +0100495} while (0)
496
497#define IRELE(ip) \
498do { \
Christoph Hellwig0b1b2132009-12-14 23:14:59 +0000499 trace_xfs_irele(ip, _THIS_IP_); \
Christoph Hellwig5a8d0f32008-12-03 12:20:40 +0100500 iput(VFS_I(ip)); \
501} while (0)
502
Barry Naujok847fff52008-10-30 17:05:38 +1100503#endif /* __KERNEL__ */
504
Christoph Hellwig6d73cf12008-12-09 04:47:32 -0500505/*
506 * Flags for xfs_iget()
507 */
508#define XFS_IGET_CREATE 0x1
Dave Chinner19207792010-06-24 11:15:47 +1000509#define XFS_IGET_UNTRUSTED 0x2
Dave Chinner5132ba82012-03-22 05:15:10 +0000510#define XFS_IGET_DONTCACHE 0x4
Christoph Hellwig6d73cf12008-12-09 04:47:32 -0500511
Christoph Hellwig475ee412012-07-03 12:21:22 -0400512int xfs_imap_to_bp(struct xfs_mount *, struct xfs_trans *,
513 struct xfs_imap *, struct xfs_dinode **,
514 struct xfs_buf **, uint, uint);
Christoph Hellwig6d73cf12008-12-09 04:47:32 -0500515int xfs_iread(struct xfs_mount *, struct xfs_trans *,
Dave Chinner7b6259e2010-06-24 11:35:17 +1000516 struct xfs_inode *, uint);
Christoph Hellwig93848a92013-04-03 16:11:17 +1100517void xfs_dinode_calc_crc(struct xfs_mount *, struct xfs_dinode *);
Christoph Hellwig81591fe2008-11-28 14:23:39 +1100518void xfs_dinode_to_disk(struct xfs_dinode *,
Barry Naujok847fff52008-10-30 17:05:38 +1100519 struct xfs_icdinode *);
520void xfs_idestroy_fork(struct xfs_inode *, int);
521void xfs_idata_realloc(struct xfs_inode *, int, int);
522void xfs_iroot_realloc(struct xfs_inode *, int, int);
523int xfs_iread_extents(struct xfs_trans *, struct xfs_inode *, int);
524int xfs_iextents_copy(struct xfs_inode *, xfs_bmbt_rec_t *, int);
525
Christoph Hellwiga6f64d42007-08-16 16:23:40 +1000526xfs_bmbt_rec_host_t *xfs_iext_get_ext(xfs_ifork_t *, xfs_extnum_t);
Christoph Hellwig6ef35542009-11-25 00:00:21 +0000527void xfs_iext_insert(xfs_inode_t *, xfs_extnum_t, xfs_extnum_t,
528 xfs_bmbt_irec_t *, int);
Mandy Kirkconnell4eea22f2006-03-14 13:29:52 +1100529void xfs_iext_add(xfs_ifork_t *, xfs_extnum_t, int);
Mandy Kirkconnell0293ce32006-03-14 13:30:23 +1100530void xfs_iext_add_indirect_multi(xfs_ifork_t *, int, xfs_extnum_t, int);
Christoph Hellwig6ef35542009-11-25 00:00:21 +0000531void xfs_iext_remove(xfs_inode_t *, xfs_extnum_t, int, int);
Mandy Kirkconnell4eea22f2006-03-14 13:29:52 +1100532void xfs_iext_remove_inline(xfs_ifork_t *, xfs_extnum_t, int);
533void xfs_iext_remove_direct(xfs_ifork_t *, xfs_extnum_t, int);
Mandy Kirkconnell0293ce32006-03-14 13:30:23 +1100534void xfs_iext_remove_indirect(xfs_ifork_t *, xfs_extnum_t, int);
Mandy Kirkconnell4eea22f2006-03-14 13:29:52 +1100535void xfs_iext_realloc_direct(xfs_ifork_t *, int);
536void xfs_iext_direct_to_inline(xfs_ifork_t *, xfs_extnum_t);
537void xfs_iext_inline_to_direct(xfs_ifork_t *, int);
538void xfs_iext_destroy(xfs_ifork_t *);
Christoph Hellwiga6f64d42007-08-16 16:23:40 +1000539xfs_bmbt_rec_host_t *xfs_iext_bno_to_ext(xfs_ifork_t *, xfs_fileoff_t, int *);
Mandy Kirkconnell0293ce32006-03-14 13:30:23 +1100540xfs_ext_irec_t *xfs_iext_bno_to_irec(xfs_ifork_t *, xfs_fileoff_t, int *);
541xfs_ext_irec_t *xfs_iext_idx_to_irec(xfs_ifork_t *, xfs_extnum_t *, int *, int);
542void xfs_iext_irec_init(xfs_ifork_t *);
543xfs_ext_irec_t *xfs_iext_irec_new(xfs_ifork_t *, int);
544void xfs_iext_irec_remove(xfs_ifork_t *, int);
545void xfs_iext_irec_compact(xfs_ifork_t *);
546void xfs_iext_irec_compact_pages(xfs_ifork_t *);
547void xfs_iext_irec_compact_full(xfs_ifork_t *);
548void xfs_iext_irec_update_extoffs(xfs_ifork_t *, int, int);
Brian Foster72b53ef2012-11-06 09:50:40 -0500549bool xfs_can_free_eofblocks(struct xfs_inode *, bool);
Mandy Kirkconnell4eea22f2006-03-14 13:29:52 +1100550
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551#define xfs_ipincount(ip) ((unsigned int) atomic_read(&ip->i_pincount))
552
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553#if defined(DEBUG)
554void xfs_inobp_check(struct xfs_mount *, struct xfs_buf *);
555#else
556#define xfs_inobp_check(mp, bp)
557#endif /* DEBUG */
558
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559extern struct kmem_zone *xfs_ifork_zone;
560extern struct kmem_zone *xfs_inode_zone;
Dave Chinner1813dd62012-11-14 17:54:40 +1100561extern const struct xfs_buf_ops xfs_inode_buf_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563#endif /* __XFS_INODE_H__ */