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