blob: d9e9cbaee28e002546e33eb0636a107823405382 [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/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 * File incore extent information, present for each of data & attr forks.
29 */
30#define XFS_INLINE_EXTS 2
31#define XFS_INLINE_DATA 32
32typedef struct xfs_ifork {
33 int if_bytes; /* bytes in if_u1 */
34 int if_real_bytes; /* bytes allocated in if_u1 */
35 xfs_bmbt_block_t *if_broot; /* file's incore btree root */
36 short if_broot_bytes; /* bytes allocated for root */
37 unsigned char if_flags; /* per-fork flags */
38 unsigned char if_ext_max; /* max # of extent records */
39 xfs_extnum_t if_lastex; /* last if_extents used */
40 union {
41 xfs_bmbt_rec_t *if_extents; /* linear map file exts */
42 char *if_data; /* inline file data */
43 } if_u1;
44 union {
45 xfs_bmbt_rec_t if_inline_ext[XFS_INLINE_EXTS];
46 /* very small file extents */
47 char if_inline_data[XFS_INLINE_DATA];
48 /* very small file data */
49 xfs_dev_t if_rdev; /* dev number if special */
50 uuid_t if_uuid; /* mount point value */
51 } if_u2;
52} xfs_ifork_t;
53
54/*
55 * Flags for xfs_ichgtime().
56 */
57#define XFS_ICHGTIME_MOD 0x1 /* data fork modification timestamp */
58#define XFS_ICHGTIME_ACC 0x2 /* data fork access timestamp */
59#define XFS_ICHGTIME_CHG 0x4 /* inode field change timestamp */
60
61/*
62 * Per-fork incore inode flags.
63 */
64#define XFS_IFINLINE 0x0001 /* Inline data is read in */
65#define XFS_IFEXTENTS 0x0002 /* All extent pointers are read in */
66#define XFS_IFBROOT 0x0004 /* i_broot points to the bmap b-tree root */
67
68/*
69 * Flags for xfs_imap() and xfs_dilocate().
70 */
71#define XFS_IMAP_LOOKUP 0x1
72
73/*
74 * Maximum number of extent pointers in if_u1.if_extents.
75 */
76#define XFS_MAX_INCORE_EXTENTS 32768
77
78
79#ifdef __KERNEL__
80struct bhv_desc;
81struct cred;
82struct ktrace;
83struct vnode;
84struct xfs_buf;
85struct xfs_bmap_free;
86struct xfs_bmbt_irec;
87struct xfs_bmbt_block;
88struct xfs_inode;
89struct xfs_inode_log_item;
90struct xfs_mount;
91struct xfs_trans;
92struct xfs_dquot;
93
94#if defined(XFS_ILOCK_TRACE)
95#define XFS_ILOCK_KTRACE_SIZE 32
96extern ktrace_t *xfs_ilock_trace_buf;
97extern void xfs_ilock_trace(struct xfs_inode *, int, unsigned int, inst_t *);
98#else
99#define xfs_ilock_trace(i,n,f,ra)
100#endif
101
102/*
103 * This structure is used to communicate which extents of a file
104 * were holes when a write started from xfs_write_file() to
105 * xfs_strat_read(). This is necessary so that we can know which
106 * blocks need to be zeroed when they are read in in xfs_strat_read()
107 * if they weren\'t allocated when the buffer given to xfs_strat_read()
108 * was mapped.
109 *
110 * We keep a list of these attached to the inode. The list is
111 * protected by the inode lock and the fact that the io lock is
112 * held exclusively by writers.
113 */
114typedef struct xfs_gap {
115 struct xfs_gap *xg_next;
116 xfs_fileoff_t xg_offset_fsb;
117 xfs_extlen_t xg_count_fsb;
118} xfs_gap_t;
119
120typedef struct dm_attrs_s {
121 __uint32_t da_dmevmask; /* DMIG event mask */
122 __uint16_t da_dmstate; /* DMIG state info */
123 __uint16_t da_pad; /* DMIG extra padding */
124} dm_attrs_t;
125
126typedef struct xfs_iocore {
127 void *io_obj; /* pointer to container
128 * inode or dcxvn structure */
129 struct xfs_mount *io_mount; /* fs mount struct ptr */
130#ifdef DEBUG
131 mrlock_t *io_lock; /* inode IO lock */
132 mrlock_t *io_iolock; /* inode IO lock */
133#endif
134
135 /* I/O state */
136 xfs_fsize_t io_new_size; /* sz when write completes */
137
138 /* Miscellaneous state. */
139 unsigned int io_flags; /* IO related flags */
140
141 /* DMAPI state */
142 dm_attrs_t io_dmattrs;
143
144} xfs_iocore_t;
145
146#define io_dmevmask io_dmattrs.da_dmevmask
147#define io_dmstate io_dmattrs.da_dmstate
148
149#define XFS_IO_INODE(io) ((xfs_inode_t *) ((io)->io_obj))
150#define XFS_IO_DCXVN(io) ((dcxvn_t *) ((io)->io_obj))
151
152/*
153 * Flags in the flags field
154 */
155
156#define XFS_IOCORE_RT 0x1
157
158/*
159 * xfs_iocore prototypes
160 */
161
162extern void xfs_iocore_inode_init(struct xfs_inode *);
163extern void xfs_iocore_inode_reinit(struct xfs_inode *);
164
165
166/*
167 * This is the type used in the xfs inode hash table.
168 * An array of these is allocated for each mounted
169 * file system to hash the inodes for that file system.
170 */
171typedef struct xfs_ihash {
172 struct xfs_inode *ih_next;
173 rwlock_t ih_lock;
174 uint ih_version;
175} xfs_ihash_t;
176
177#define XFS_IHASH(mp,ino) ((mp)->m_ihash + (((uint)(ino)) % (mp)->m_ihsize))
178
179/*
180 * This is the xfs inode cluster hash. This hash is used by xfs_iflush to
181 * find inodes that share a cluster and can be flushed to disk at the same
182 * time.
183 */
184typedef struct xfs_chashlist {
185 struct xfs_chashlist *chl_next;
186 struct xfs_inode *chl_ip;
187 xfs_daddr_t chl_blkno; /* starting block number of
188 * the cluster */
189 struct xfs_buf *chl_buf; /* the inode buffer */
190} xfs_chashlist_t;
191
192typedef struct xfs_chash {
193 xfs_chashlist_t *ch_list;
194 lock_t ch_lock;
195} xfs_chash_t;
196
197#define XFS_CHASH(mp,blk) ((mp)->m_chash + (((uint)blk) % (mp)->m_chsize))
198
199
200/*
201 * This is the xfs in-core inode structure.
202 * Most of the on-disk inode is embedded in the i_d field.
203 *
204 * The extent pointers/inline file space, however, are managed
205 * separately. The memory for this information is pointed to by
206 * the if_u1 unions depending on the type of the data.
207 * This is used to linearize the array of extents for fast in-core
208 * access. This is used until the file's number of extents
209 * surpasses XFS_MAX_INCORE_EXTENTS, at which point all extent pointers
210 * are accessed through the buffer cache.
211 *
212 * Other state kept in the in-core inode is used for identification,
213 * locking, transactional updating, etc of the inode.
214 *
215 * Generally, we do not want to hold the i_rlock while holding the
216 * i_ilock. Hierarchy is i_iolock followed by i_rlock.
217 *
218 * xfs_iptr_t contains all the inode fields upto and including the
219 * i_mnext and i_mprev fields, it is used as a marker in the inode
220 * chain off the mount structure by xfs_sync calls.
221 */
222
223typedef struct {
224 struct xfs_ihash *ip_hash; /* pointer to hash header */
225 struct xfs_inode *ip_next; /* inode hash link forw */
226 struct xfs_inode *ip_mnext; /* next inode in mount list */
227 struct xfs_inode *ip_mprev; /* ptr to prev inode */
228 struct xfs_inode **ip_prevp; /* ptr to prev i_next */
229 struct xfs_mount *ip_mount; /* fs mount struct ptr */
230} xfs_iptr_t;
231
232typedef struct xfs_inode {
233 /* Inode linking and identification information. */
234 struct xfs_ihash *i_hash; /* pointer to hash header */
235 struct xfs_inode *i_next; /* inode hash link forw */
236 struct xfs_inode *i_mnext; /* next inode in mount list */
237 struct xfs_inode *i_mprev; /* ptr to prev inode */
238 struct xfs_inode **i_prevp; /* ptr to prev i_next */
239 struct xfs_mount *i_mount; /* fs mount struct ptr */
240 struct list_head i_reclaim; /* reclaim list */
241 struct bhv_desc i_bhv_desc; /* inode behavior descriptor*/
242 struct xfs_dquot *i_udquot; /* user dquot */
243 struct xfs_dquot *i_gdquot; /* group dquot */
244
245 /* Inode location stuff */
246 xfs_ino_t i_ino; /* inode number (agno/agino)*/
247 xfs_daddr_t i_blkno; /* blkno of inode buffer */
248 ushort i_len; /* len of inode buffer */
249 ushort i_boffset; /* off of inode in buffer */
250
251 /* Extent information. */
252 xfs_ifork_t *i_afp; /* attribute fork pointer */
253 xfs_ifork_t i_df; /* data fork */
254
255 /* Transaction and locking information. */
256 struct xfs_trans *i_transp; /* ptr to owning transaction*/
257 struct xfs_inode_log_item *i_itemp; /* logging information */
258 mrlock_t i_lock; /* inode lock */
259 mrlock_t i_iolock; /* inode IO lock */
260 sema_t i_flock; /* inode flush lock */
261 atomic_t i_pincount; /* inode pin count */
262 wait_queue_head_t i_ipin_wait; /* inode pinning wait queue */
263#ifdef HAVE_REFCACHE
264 struct xfs_inode **i_refcache; /* ptr to entry in ref cache */
265 struct xfs_inode *i_release; /* inode to unref */
266#endif
267 /* I/O state */
268 xfs_iocore_t i_iocore; /* I/O core */
269
270 /* Miscellaneous state. */
271 unsigned short i_flags; /* see defined flags below */
272 unsigned char i_update_core; /* timestamps/size is dirty */
273 unsigned char i_update_size; /* di_size field is dirty */
274 unsigned int i_gen; /* generation count */
275 unsigned int i_delayed_blks; /* count of delay alloc blks */
276
277 xfs_dinode_core_t i_d; /* most of ondisk inode */
278 xfs_chashlist_t *i_chash; /* cluster hash list header */
279 struct xfs_inode *i_cnext; /* cluster hash link forward */
280 struct xfs_inode *i_cprev; /* cluster hash link backward */
281
282 /* Trace buffers per inode. */
283#ifdef XFS_BMAP_TRACE
284 struct ktrace *i_xtrace; /* inode extent list trace */
285#endif
286#ifdef XFS_BMBT_TRACE
287 struct ktrace *i_btrace; /* inode bmap btree trace */
288#endif
289#ifdef XFS_RW_TRACE
290 struct ktrace *i_rwtrace; /* inode read/write trace */
291#endif
292#ifdef XFS_ILOCK_TRACE
293 struct ktrace *i_lock_trace; /* inode lock/unlock trace */
294#endif
295#ifdef XFS_DIR2_TRACE
296 struct ktrace *i_dir_trace; /* inode directory trace */
297#endif
298} xfs_inode_t;
299
300#endif /* __KERNEL__ */
301
302
303/*
304 * Fork handling.
305 */
Nathan Scotta844f452005-11-02 14:38:42 +1100306#define XFS_IFORK_PTR(ip,w) \
307 ((w) == XFS_DATA_FORK ? &(ip)->i_df : (ip)->i_afp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308#define XFS_IFORK_Q(ip) XFS_CFORK_Q(&(ip)->i_d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309#define XFS_IFORK_DSIZE(ip) XFS_CFORK_DSIZE(&ip->i_d, ip->i_mount)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310#define XFS_IFORK_ASIZE(ip) XFS_CFORK_ASIZE(&ip->i_d, ip->i_mount)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311#define XFS_IFORK_SIZE(ip,w) XFS_CFORK_SIZE(&ip->i_d, ip->i_mount, w)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312#define XFS_IFORK_FORMAT(ip,w) XFS_CFORK_FORMAT(&ip->i_d, w)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313#define XFS_IFORK_FMT_SET(ip,w,n) XFS_CFORK_FMT_SET(&ip->i_d, w, n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314#define XFS_IFORK_NEXTENTS(ip,w) XFS_CFORK_NEXTENTS(&ip->i_d, w)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315#define XFS_IFORK_NEXT_SET(ip,w,n) XFS_CFORK_NEXT_SET(&ip->i_d, w, n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
317
318#ifdef __KERNEL__
319
320/*
321 * In-core inode flags.
322 */
323#define XFS_IGRIO 0x0001 /* inode used for guaranteed rate i/o */
324#define XFS_IUIOSZ 0x0002 /* inode i/o sizes have been explicitly set */
325#define XFS_IQUIESCE 0x0004 /* we have started quiescing for this inode */
326#define XFS_IRECLAIM 0x0008 /* we have started reclaiming this inode */
327#define XFS_ISTALE 0x0010 /* inode has been staled */
328#define XFS_IRECLAIMABLE 0x0020 /* inode can be reclaimed */
329#define XFS_INEW 0x0040
330
331/*
332 * Flags for inode locking.
333 */
334#define XFS_IOLOCK_EXCL 0x001
335#define XFS_IOLOCK_SHARED 0x002
336#define XFS_ILOCK_EXCL 0x004
337#define XFS_ILOCK_SHARED 0x008
338#define XFS_IUNLOCK_NONOTIFY 0x010
Nathan Scott30dab212005-11-02 10:31:13 +1100339/* XFS_IOLOCK_NESTED 0x020 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340#define XFS_EXTENT_TOKEN_RD 0x040
341#define XFS_SIZE_TOKEN_RD 0x080
342#define XFS_EXTSIZE_RD (XFS_EXTENT_TOKEN_RD|XFS_SIZE_TOKEN_RD)
343#define XFS_WILLLEND 0x100 /* Always acquire tokens for lending */
344#define XFS_EXTENT_TOKEN_WR (XFS_EXTENT_TOKEN_RD | XFS_WILLLEND)
345#define XFS_SIZE_TOKEN_WR (XFS_SIZE_TOKEN_RD | XFS_WILLLEND)
346#define XFS_EXTSIZE_WR (XFS_EXTSIZE_RD | XFS_WILLLEND)
Nathan Scott30dab212005-11-02 10:31:13 +1100347/* XFS_SIZE_TOKEN_WANT 0x200 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348
349#define XFS_LOCK_MASK \
350 (XFS_IOLOCK_EXCL | XFS_IOLOCK_SHARED | XFS_ILOCK_EXCL | \
351 XFS_ILOCK_SHARED | XFS_EXTENT_TOKEN_RD | XFS_SIZE_TOKEN_RD | \
352 XFS_WILLLEND)
353
354/*
355 * Flags for xfs_iflush()
356 */
357#define XFS_IFLUSH_DELWRI_ELSE_SYNC 1
358#define XFS_IFLUSH_DELWRI_ELSE_ASYNC 2
359#define XFS_IFLUSH_SYNC 3
360#define XFS_IFLUSH_ASYNC 4
361#define XFS_IFLUSH_DELWRI 5
362
363/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 * Flags for xfs_itruncate_start().
365 */
366#define XFS_ITRUNC_DEFINITE 0x1
367#define XFS_ITRUNC_MAYBE 0x2
368
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369#define XFS_ITOV(ip) BHV_TO_VNODE(XFS_ITOBHV(ip))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370#define XFS_ITOV_NULL(ip) BHV_TO_VNODE_NULL(XFS_ITOBHV(ip))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371#define XFS_ITOBHV(ip) ((struct bhv_desc *)(&((ip)->i_bhv_desc)))
Nathan Scotta844f452005-11-02 14:38:42 +1100372#define XFS_BHVTOI(bhvp) ((xfs_inode_t *)((char *)(bhvp) - \
373 (char *)&(((xfs_inode_t *)0)->i_bhv_desc)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374#define BHV_IS_XFS(bdp) (BHV_OPS(bdp) == &xfs_vnodeops)
375
376/*
377 * For multiple groups support: if S_ISGID bit is set in the parent
378 * directory, group of new file is set to that of the parent, and
379 * new subdirectory gets S_ISGID bit from parent.
380 */
381#define XFS_INHERIT_GID(pip, vfsp) \
382 (((vfsp)->vfs_flag & VFS_GRPID) || ((pip)->i_d.di_mode & S_ISGID))
383
384/*
385 * xfs_iget.c prototypes.
386 */
387
388#define IGET_CREATE 1
389
390void xfs_ihash_init(struct xfs_mount *);
391void xfs_ihash_free(struct xfs_mount *);
392void xfs_chash_init(struct xfs_mount *);
393void xfs_chash_free(struct xfs_mount *);
394xfs_inode_t *xfs_inode_incore(struct xfs_mount *, xfs_ino_t,
395 struct xfs_trans *);
396void xfs_inode_lock_init(xfs_inode_t *, struct vnode *);
397int xfs_iget(struct xfs_mount *, struct xfs_trans *, xfs_ino_t,
398 uint, uint, xfs_inode_t **, xfs_daddr_t);
399void xfs_iput(xfs_inode_t *, uint);
400void xfs_iput_new(xfs_inode_t *, uint);
401void xfs_ilock(xfs_inode_t *, uint);
402int xfs_ilock_nowait(xfs_inode_t *, uint);
403void xfs_iunlock(xfs_inode_t *, uint);
404void xfs_ilock_demote(xfs_inode_t *, uint);
405void xfs_iflock(xfs_inode_t *);
406int xfs_iflock_nowait(xfs_inode_t *);
407uint xfs_ilock_map_shared(xfs_inode_t *);
408void xfs_iunlock_map_shared(xfs_inode_t *, uint);
409void xfs_ifunlock(xfs_inode_t *);
410void xfs_ireclaim(xfs_inode_t *);
411int xfs_finish_reclaim(xfs_inode_t *, int, int);
412int xfs_finish_reclaim_all(struct xfs_mount *, int);
413
414/*
415 * xfs_inode.c prototypes.
416 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417int xfs_itobp(struct xfs_mount *, struct xfs_trans *,
418 xfs_inode_t *, xfs_dinode_t **, struct xfs_buf **,
419 xfs_daddr_t);
420int xfs_iread(struct xfs_mount *, struct xfs_trans *, xfs_ino_t,
421 xfs_inode_t **, xfs_daddr_t);
422int xfs_iread_extents(struct xfs_trans *, xfs_inode_t *, int);
Nathan Scott31b084a2005-05-05 13:25:00 -0700423int xfs_ialloc(struct xfs_trans *, xfs_inode_t *, mode_t,
424 xfs_nlink_t, xfs_dev_t, struct cred *, xfs_prid_t,
425 int, struct xfs_buf **, boolean_t *, xfs_inode_t **);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426void xfs_xlate_dinode_core(xfs_caddr_t, struct xfs_dinode_core *,
427 int);
428uint xfs_ip2xflags(struct xfs_inode *);
429uint xfs_dic2xflags(struct xfs_dinode_core *);
430int xfs_ifree(struct xfs_trans *, xfs_inode_t *,
431 struct xfs_bmap_free *);
432void xfs_itruncate_start(xfs_inode_t *, uint, xfs_fsize_t);
433int xfs_itruncate_finish(struct xfs_trans **, xfs_inode_t *,
434 xfs_fsize_t, int, int);
435int xfs_iunlink(struct xfs_trans *, xfs_inode_t *);
436int xfs_igrow_start(xfs_inode_t *, xfs_fsize_t, struct cred *);
437void xfs_igrow_finish(struct xfs_trans *, xfs_inode_t *,
438 xfs_fsize_t, int);
439
440void xfs_idestroy_fork(xfs_inode_t *, int);
441void xfs_idestroy(xfs_inode_t *);
442void xfs_idata_realloc(xfs_inode_t *, int, int);
443void xfs_iextract(xfs_inode_t *);
444void xfs_iext_realloc(xfs_inode_t *, int, int);
445void xfs_iroot_realloc(xfs_inode_t *, int, int);
446void xfs_ipin(xfs_inode_t *);
447void xfs_iunpin(xfs_inode_t *);
448int xfs_iextents_copy(xfs_inode_t *, xfs_bmbt_rec_t *, int);
449int xfs_iflush(xfs_inode_t *, uint);
Christoph Hellwigefa80272005-06-21 15:37:17 +1000450void xfs_iflush_all(struct xfs_mount *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451int xfs_iaccess(xfs_inode_t *, mode_t, cred_t *);
452uint xfs_iroundup(uint);
453void xfs_ichgtime(xfs_inode_t *, int);
454xfs_fsize_t xfs_file_last_byte(xfs_inode_t *);
455void xfs_lock_inodes(xfs_inode_t **, int, int, uint);
456
457#define xfs_ipincount(ip) ((unsigned int) atomic_read(&ip->i_pincount))
458
459#ifdef DEBUG
460void xfs_isize_check(struct xfs_mount *, xfs_inode_t *, xfs_fsize_t);
461#else /* DEBUG */
462#define xfs_isize_check(mp, ip, isize)
463#endif /* DEBUG */
464
465#if defined(DEBUG)
466void xfs_inobp_check(struct xfs_mount *, struct xfs_buf *);
467#else
468#define xfs_inobp_check(mp, bp)
469#endif /* DEBUG */
470
471extern struct kmem_zone *xfs_chashlist_zone;
472extern struct kmem_zone *xfs_ifork_zone;
473extern struct kmem_zone *xfs_inode_zone;
474extern struct kmem_zone *xfs_ili_zone;
475extern struct vnodeops xfs_vnodeops;
476
477#endif /* __KERNEL__ */
478
479#endif /* __XFS_INODE_H__ */