2 * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * 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.
14 * 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
18 #ifndef __XFS_INODE_H__
19 #define __XFS_INODE_H__
25 #include "xfs_inode_fork.h"
28 * Inode location information. Stored in the inode and passed to
29 * xfs_imap_to_bp() to get a buffer and dinode for a given inode.
32 xfs_daddr_t im_blkno
; /* starting BB of inode chunk */
33 ushort im_len
; /* length in BBs of inode chunk */
34 ushort im_boffset
; /* inode offset in block in bytes */
38 * This is the xfs in-core inode structure.
39 * Most of the on-disk inode is embedded in the i_d field.
41 * The extent pointers/inline file space, however, are managed
42 * separately. The memory for this information is pointed to by
43 * the if_u1 unions depending on the type of the data.
44 * This is used to linearize the array of extents for fast in-core
45 * access. This is used until the file's number of extents
46 * surpasses XFS_MAX_INCORE_EXTENTS, at which point all extent pointers
47 * are accessed through the buffer cache.
49 * Other state kept in the in-core inode is used for identification,
50 * locking, transactional updating, etc of the inode.
52 * Generally, we do not want to hold the i_rlock while holding the
53 * i_ilock. Hierarchy is i_iolock followed by i_rlock.
55 * xfs_iptr_t contains all the inode fields up to and including the
56 * i_mnext and i_mprev fields, it is used as a marker in the inode
57 * chain off the mount structure by xfs_sync calls.
60 * Flags for xfs_ichgtime().
62 #define XFS_ICHGTIME_MOD 0x1 /* data fork modification timestamp */
63 #define XFS_ICHGTIME_CHG 0x2 /* inode field change timestamp */
64 #define XFS_ICHGTIME_CREATE 0x4 /* inode create timestamp */
72 struct xfs_inode_log_item
;
77 typedef struct xfs_inode
{
78 /* Inode linking and identification information. */
79 struct xfs_mount
*i_mount
; /* fs mount struct ptr */
80 struct xfs_dquot
*i_udquot
; /* user dquot */
81 struct xfs_dquot
*i_gdquot
; /* group dquot */
83 /* Inode location stuff */
84 xfs_ino_t i_ino
; /* inode number (agno/agino)*/
85 struct xfs_imap i_imap
; /* location for xfs_imap() */
87 /* Extent information. */
88 xfs_ifork_t
*i_afp
; /* attribute fork pointer */
89 xfs_ifork_t i_df
; /* data fork */
91 /* Transaction and locking information. */
92 struct xfs_inode_log_item
*i_itemp
; /* logging information */
93 mrlock_t i_lock
; /* inode lock */
94 mrlock_t i_iolock
; /* inode IO lock */
95 atomic_t i_pincount
; /* inode pin count */
96 spinlock_t i_flags_lock
; /* inode i_flags lock */
97 /* Miscellaneous state. */
98 unsigned long i_flags
; /* see defined flags below */
99 unsigned int i_delayed_blks
; /* count of delay alloc blks */
101 xfs_icdinode_t i_d
; /* most of ondisk inode */
104 struct inode i_vnode
; /* embedded VFS inode */
107 /* Convert from vfs inode to xfs inode */
108 static inline struct xfs_inode
*XFS_I(struct inode
*inode
)
110 return container_of(inode
, struct xfs_inode
, i_vnode
);
113 /* convert from xfs inode to vfs inode */
114 static inline struct inode
*VFS_I(struct xfs_inode
*ip
)
120 * For regular files we only update the on-disk filesize when actually
121 * writing data back to disk. Until then only the copy in the VFS inode
124 static inline xfs_fsize_t
XFS_ISIZE(struct xfs_inode
*ip
)
126 if (S_ISREG(ip
->i_d
.di_mode
))
127 return i_size_read(VFS_I(ip
));
128 return ip
->i_d
.di_size
;
132 * If this I/O goes past the on-disk inode size update it unless it would
133 * be past the current in-core inode size.
135 static inline xfs_fsize_t
136 xfs_new_eof(struct xfs_inode
*ip
, xfs_fsize_t new_size
)
138 xfs_fsize_t i_size
= i_size_read(VFS_I(ip
));
140 if (new_size
> i_size
)
142 return new_size
> ip
->i_d
.di_size
? new_size
: 0;
146 * i_flags helper functions
149 __xfs_iflags_set(xfs_inode_t
*ip
, unsigned short flags
)
151 ip
->i_flags
|= flags
;
155 xfs_iflags_set(xfs_inode_t
*ip
, unsigned short flags
)
157 spin_lock(&ip
->i_flags_lock
);
158 __xfs_iflags_set(ip
, flags
);
159 spin_unlock(&ip
->i_flags_lock
);
163 xfs_iflags_clear(xfs_inode_t
*ip
, unsigned short flags
)
165 spin_lock(&ip
->i_flags_lock
);
166 ip
->i_flags
&= ~flags
;
167 spin_unlock(&ip
->i_flags_lock
);
171 __xfs_iflags_test(xfs_inode_t
*ip
, unsigned short flags
)
173 return (ip
->i_flags
& flags
);
177 xfs_iflags_test(xfs_inode_t
*ip
, unsigned short flags
)
180 spin_lock(&ip
->i_flags_lock
);
181 ret
= __xfs_iflags_test(ip
, flags
);
182 spin_unlock(&ip
->i_flags_lock
);
187 xfs_iflags_test_and_clear(xfs_inode_t
*ip
, unsigned short flags
)
191 spin_lock(&ip
->i_flags_lock
);
192 ret
= ip
->i_flags
& flags
;
194 ip
->i_flags
&= ~flags
;
195 spin_unlock(&ip
->i_flags_lock
);
200 xfs_iflags_test_and_set(xfs_inode_t
*ip
, unsigned short flags
)
204 spin_lock(&ip
->i_flags_lock
);
205 ret
= ip
->i_flags
& flags
;
207 ip
->i_flags
|= flags
;
208 spin_unlock(&ip
->i_flags_lock
);
213 * Project quota id helpers (previously projid was 16bit only
214 * and using two 16bit values to hold new 32bit projid was chosen
215 * to retain compatibility with "old" filesystems).
218 xfs_get_projid(struct xfs_inode
*ip
)
220 return (prid_t
)ip
->i_d
.di_projid_hi
<< 16 | ip
->i_d
.di_projid_lo
;
224 xfs_set_projid(struct xfs_inode
*ip
,
227 ip
->i_d
.di_projid_hi
= (__uint16_t
) (projid
>> 16);
228 ip
->i_d
.di_projid_lo
= (__uint16_t
) (projid
& 0xffff);
232 * In-core inode flags.
234 #define XFS_IRECLAIM (1 << 0) /* started reclaiming this inode */
235 #define XFS_ISTALE (1 << 1) /* inode has been staled */
236 #define XFS_IRECLAIMABLE (1 << 2) /* inode can be reclaimed */
237 #define XFS_INEW (1 << 3) /* inode has just been allocated */
238 #define XFS_IFILESTREAM (1 << 4) /* inode is in a filestream dir. */
239 #define XFS_ITRUNCATED (1 << 5) /* truncated down so flush-on-close */
240 #define XFS_IDIRTY_RELEASE (1 << 6) /* dirty release already seen */
241 #define __XFS_IFLOCK_BIT 7 /* inode is being flushed right now */
242 #define XFS_IFLOCK (1 << __XFS_IFLOCK_BIT)
243 #define __XFS_IPINNED_BIT 8 /* wakeup key for zero pin count */
244 #define XFS_IPINNED (1 << __XFS_IPINNED_BIT)
245 #define XFS_IDONTCACHE (1 << 9) /* don't cache the inode long term */
248 * Per-lifetime flags need to be reset when re-using a reclaimable inode during
249 * inode lookup. This prevents unintended behaviour on the new inode from
252 #define XFS_IRECLAIM_RESET_FLAGS \
253 (XFS_IRECLAIMABLE | XFS_IRECLAIM | \
254 XFS_IDIRTY_RELEASE | XFS_ITRUNCATED | \
258 * Synchronize processes attempting to flush the in-core inode back to disk.
261 extern void __xfs_iflock(struct xfs_inode
*ip
);
263 static inline int xfs_iflock_nowait(struct xfs_inode
*ip
)
265 return !xfs_iflags_test_and_set(ip
, XFS_IFLOCK
);
268 static inline void xfs_iflock(struct xfs_inode
*ip
)
270 if (!xfs_iflock_nowait(ip
))
274 static inline void xfs_ifunlock(struct xfs_inode
*ip
)
276 xfs_iflags_clear(ip
, XFS_IFLOCK
);
278 wake_up_bit(&ip
->i_flags
, __XFS_IFLOCK_BIT
);
281 static inline int xfs_isiflocked(struct xfs_inode
*ip
)
283 return xfs_iflags_test(ip
, XFS_IFLOCK
);
287 * Flags for inode locking.
288 * Bit ranges: 1<<1 - 1<<16-1 -- iolock/ilock modes (bitfield)
289 * 1<<16 - 1<<32-1 -- lockdep annotation (integers)
291 #define XFS_IOLOCK_EXCL (1<<0)
292 #define XFS_IOLOCK_SHARED (1<<1)
293 #define XFS_ILOCK_EXCL (1<<2)
294 #define XFS_ILOCK_SHARED (1<<3)
296 #define XFS_LOCK_MASK (XFS_IOLOCK_EXCL | XFS_IOLOCK_SHARED \
297 | XFS_ILOCK_EXCL | XFS_ILOCK_SHARED)
299 #define XFS_LOCK_FLAGS \
300 { XFS_IOLOCK_EXCL, "IOLOCK_EXCL" }, \
301 { XFS_IOLOCK_SHARED, "IOLOCK_SHARED" }, \
302 { XFS_ILOCK_EXCL, "ILOCK_EXCL" }, \
303 { XFS_ILOCK_SHARED, "ILOCK_SHARED" }
307 * Flags for lockdep annotations.
309 * XFS_LOCK_PARENT - for directory operations that require locking a
310 * parent directory inode and a child entry inode. The parent gets locked
311 * with this flag so it gets a lockdep subclass of 1 and the child entry
312 * lock will have a lockdep subclass of 0.
314 * XFS_LOCK_RTBITMAP/XFS_LOCK_RTSUM - the realtime device bitmap and summary
315 * inodes do not participate in the normal lock order, and thus have their
318 * XFS_LOCK_INUMORDER - for locking several inodes at the some time
319 * with xfs_lock_inodes(). This flag is used as the starting subclass
320 * and each subsequent lock acquired will increment the subclass by one.
321 * So the first lock acquired will have a lockdep subclass of 4, the
322 * second lock will have a lockdep subclass of 5, and so on. It is
323 * the responsibility of the class builder to shift this to the correct
324 * portion of the lock_mode lockdep mask.
326 #define XFS_LOCK_PARENT 1
327 #define XFS_LOCK_RTBITMAP 2
328 #define XFS_LOCK_RTSUM 3
329 #define XFS_LOCK_INUMORDER 4
331 #define XFS_IOLOCK_SHIFT 16
332 #define XFS_IOLOCK_PARENT (XFS_LOCK_PARENT << XFS_IOLOCK_SHIFT)
334 #define XFS_ILOCK_SHIFT 24
335 #define XFS_ILOCK_PARENT (XFS_LOCK_PARENT << XFS_ILOCK_SHIFT)
336 #define XFS_ILOCK_RTBITMAP (XFS_LOCK_RTBITMAP << XFS_ILOCK_SHIFT)
337 #define XFS_ILOCK_RTSUM (XFS_LOCK_RTSUM << XFS_ILOCK_SHIFT)
339 #define XFS_IOLOCK_DEP_MASK 0x00ff0000
340 #define XFS_ILOCK_DEP_MASK 0xff000000
341 #define XFS_LOCK_DEP_MASK (XFS_IOLOCK_DEP_MASK | XFS_ILOCK_DEP_MASK)
343 #define XFS_IOLOCK_DEP(flags) (((flags) & XFS_IOLOCK_DEP_MASK) >> XFS_IOLOCK_SHIFT)
344 #define XFS_ILOCK_DEP(flags) (((flags) & XFS_ILOCK_DEP_MASK) >> XFS_ILOCK_SHIFT)
347 * For multiple groups support: if S_ISGID bit is set in the parent
348 * directory, group of new file is set to that of the parent, and
349 * new subdirectory gets S_ISGID bit from parent.
351 #define XFS_INHERIT_GID(pip) \
352 (((pip)->i_mount->m_flags & XFS_MOUNT_GRPID) || \
353 ((pip)->i_d.di_mode & S_ISGID))
357 * xfs_inode.c prototypes.
359 void xfs_ilock(xfs_inode_t
*, uint
);
360 int xfs_ilock_nowait(xfs_inode_t
*, uint
);
361 void xfs_iunlock(xfs_inode_t
*, uint
);
362 void xfs_ilock_demote(xfs_inode_t
*, uint
);
363 int xfs_isilocked(xfs_inode_t
*, uint
);
364 uint
xfs_ilock_map_shared(xfs_inode_t
*);
365 void xfs_iunlock_map_shared(xfs_inode_t
*, uint
);
366 int xfs_ialloc(struct xfs_trans
*, xfs_inode_t
*, umode_t
,
367 xfs_nlink_t
, xfs_dev_t
, prid_t
, int,
368 struct xfs_buf
**, xfs_inode_t
**);
370 uint
xfs_ip2xflags(struct xfs_inode
*);
371 uint
xfs_dic2xflags(struct xfs_dinode
*);
372 int xfs_ifree(struct xfs_trans
*, xfs_inode_t
*,
373 struct xfs_bmap_free
*);
374 int xfs_itruncate_extents(struct xfs_trans
**, struct xfs_inode
*,
376 int xfs_iunlink(struct xfs_trans
*, xfs_inode_t
*);
378 void xfs_iext_realloc(xfs_inode_t
*, int, int);
379 void xfs_iunpin_wait(xfs_inode_t
*);
380 int xfs_iflush(struct xfs_inode
*, struct xfs_buf
**);
381 void xfs_lock_inodes(xfs_inode_t
**, int, uint
);
382 void xfs_lock_two_inodes(xfs_inode_t
*, xfs_inode_t
*, uint
);
384 xfs_extlen_t
xfs_get_extsz_hint(struct xfs_inode
*ip
);
388 ASSERT(atomic_read(&VFS_I(ip)->i_count) > 0) ; \
390 trace_xfs_ihold(ip, _THIS_IP_); \
395 trace_xfs_irele(ip, _THIS_IP_); \
399 #endif /* __KERNEL__ */
402 * Flags for xfs_iget()
404 #define XFS_IGET_CREATE 0x1
405 #define XFS_IGET_UNTRUSTED 0x2
406 #define XFS_IGET_DONTCACHE 0x4
408 int xfs_imap_to_bp(struct xfs_mount
*, struct xfs_trans
*,
409 struct xfs_imap
*, struct xfs_dinode
**,
410 struct xfs_buf
**, uint
, uint
);
411 int xfs_iread(struct xfs_mount
*, struct xfs_trans
*,
412 struct xfs_inode
*, uint
);
413 void xfs_dinode_calc_crc(struct xfs_mount
*, struct xfs_dinode
*);
414 void xfs_dinode_to_disk(struct xfs_dinode
*,
415 struct xfs_icdinode
*);
416 bool xfs_can_free_eofblocks(struct xfs_inode
*, bool);
418 #define xfs_ipincount(ip) ((unsigned int) atomic_read(&ip->i_pincount))
421 void xfs_inobp_check(struct xfs_mount
*, struct xfs_buf
*);
423 #define xfs_inobp_check(mp, bp)
426 extern struct kmem_zone
*xfs_inode_zone
;
427 extern const struct xfs_buf_ops xfs_inode_buf_ops
;
429 #endif /* __XFS_INODE_H__ */