Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / fs / xfs / xfs_inode.h
index 37e1c31..3b544db 100644 (file)
@@ -1,42 +1,61 @@
 /*
- * Copyright (c) 2000-2003 Silicon Graphics, Inc.  All Rights Reserved.
+ * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
+ * All Rights Reserved.
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
  * published by the Free Software Foundation.
  *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
  *
- * Further, this software is distributed without any warranty that it is
- * free of the rightful claim of any third person regarding infringement
- * or the like.  Any license provided herein, whether implied or
- * otherwise, applies only to this software file.  Patent licenses, if
- * any, provided herein do not apply to combinations of this program with
- * other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc., 59
- * Temple Place - Suite 330, Boston MA 02111-1307, USA.
- *
- * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
- * Mountain View, CA  94043, or:
- *
- * http://www.sgi.com
- *
- * For further information regarding this notice, see:
- *
- * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software Foundation,
+ * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 #ifndef        __XFS_INODE_H__
 #define        __XFS_INODE_H__
 
+/*
+ * Fork identifiers.
+ */
+#define        XFS_DATA_FORK   0
+#define        XFS_ATTR_FORK   1
+
+/*
+ * The following xfs_ext_irec_t struct introduces a second (top) level
+ * to the in-core extent allocation scheme. These structs are allocated
+ * in a contiguous block, creating an indirection array where each entry
+ * (irec) contains a pointer to a buffer of in-core extent records which
+ * it manages. Each extent buffer is 4k in size, since 4k is the system
+ * page size on Linux i386 and systems with larger page sizes don't seem
+ * to gain much, if anything, by using their native page size as the
+ * extent buffer size. Also, using 4k extent buffers everywhere provides
+ * a consistent interface for CXFS across different platforms.
+ *
+ * There is currently no limit on the number of irec's (extent lists)
+ * allowed, so heavily fragmented files may require an indirection array
+ * which spans multiple system pages of memory. The number of extents
+ * which would require this amount of contiguous memory is very large
+ * and should not cause problems in the foreseeable future. However,
+ * if the memory needed for the contiguous array ever becomes a problem,
+ * it is possible that a third level of indirection may be required.
+ */
+typedef struct xfs_ext_irec {
+       xfs_bmbt_rec_t  *er_extbuf;     /* block of extent records */
+       xfs_extnum_t    er_extoff;      /* extent offset in file */
+       xfs_extnum_t    er_extcount;    /* number of extents in page/block */
+} xfs_ext_irec_t;
+
 /*
  * File incore extent information, present for each of data & attr forks.
  */
-#define        XFS_INLINE_EXTS 2
-#define        XFS_INLINE_DATA 32
+#define        XFS_IEXT_BUFSZ          4096
+#define        XFS_LINEAR_EXTS         (XFS_IEXT_BUFSZ / (uint)sizeof(xfs_bmbt_rec_t))
+#define        XFS_INLINE_EXTS         2
+#define        XFS_INLINE_DATA         32
 typedef struct xfs_ifork {
        int                     if_bytes;       /* bytes in if_u1 */
        int                     if_real_bytes;  /* bytes allocated in if_u1 */
@@ -47,6 +66,7 @@ typedef struct xfs_ifork {
        xfs_extnum_t            if_lastex;      /* last if_extents used */
        union {
                xfs_bmbt_rec_t  *if_extents;    /* linear map file exts */
+               xfs_ext_irec_t  *if_ext_irec;   /* irec map file exts */
                char            *if_data;       /* inline file data */
        } if_u1;
        union {
@@ -69,20 +89,16 @@ typedef struct xfs_ifork {
 /*
  * Per-fork incore inode flags.
  */
-#define        XFS_IFINLINE    0x0001  /* Inline data is read in */
-#define        XFS_IFEXTENTS   0x0002  /* All extent pointers are read in */
-#define        XFS_IFBROOT     0x0004  /* i_broot points to the bmap b-tree root */
+#define        XFS_IFINLINE    0x01    /* Inline data is read in */
+#define        XFS_IFEXTENTS   0x02    /* All extent pointers are read in */
+#define        XFS_IFBROOT     0x04    /* i_broot points to the bmap b-tree root */
+#define        XFS_IFEXTIREC   0x08    /* Indirection array of extent blocks */
 
 /*
- * Flags for xfs_imap() and xfs_dilocate().
+ * Flags for xfs_itobp(), xfs_imap() and xfs_dilocate().
  */
-#define        XFS_IMAP_LOOKUP         0x1
-
-/*
- * Maximum number of extent pointers in if_u1.if_extents.
- */
-#define        XFS_MAX_INCORE_EXTENTS  32768
-
+#define XFS_IMAP_LOOKUP                0x1
+#define XFS_IMAP_BULKSTAT      0x2
 
 #ifdef __KERNEL__
 struct bhv_desc;
@@ -107,24 +123,6 @@ extern void xfs_ilock_trace(struct xfs_inode *, int, unsigned int, inst_t *);
 #define        xfs_ilock_trace(i,n,f,ra)
 #endif
 
-/*
- * This structure is used to communicate which extents of a file
- * were holes when a write started from xfs_write_file() to
- * xfs_strat_read().  This is necessary so that we can know which
- * blocks need to be zeroed when they are read in in xfs_strat_read()
- * if they weren\'t allocated when the buffer given to xfs_strat_read()
- * was mapped.
- *
- * We keep a list of these attached to the inode.  The list is
- * protected by the inode lock and the fact that the io lock is
- * held exclusively by writers.
- */
-typedef struct xfs_gap {
-       struct xfs_gap  *xg_next;
-       xfs_fileoff_t   xg_offset_fsb;
-       xfs_extlen_t    xg_count_fsb;
-} xfs_gap_t;
-
 typedef struct dm_attrs_s {
        __uint32_t      da_dmevmask;    /* DMIG event mask */
        __uint16_t      da_dmstate;     /* DMIG state info */
@@ -191,6 +189,7 @@ typedef struct xfs_ihash {
  */
 typedef struct xfs_chashlist {
        struct xfs_chashlist    *chl_next;
+       struct xfs_chashlist    *chl_prev;
        struct xfs_inode        *chl_ip;
        xfs_daddr_t             chl_blkno;      /* starting block number of
                                                 * the cluster */
@@ -311,60 +310,16 @@ typedef struct xfs_inode {
 /*
  * Fork handling.
  */
-#if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_IFORK_PTR)
-xfs_ifork_t *xfs_ifork_ptr(xfs_inode_t *ip, int w);
-#define        XFS_IFORK_PTR(ip,w)             xfs_ifork_ptr(ip,w)
-#else
-#define        XFS_IFORK_PTR(ip,w)   ((w) == XFS_DATA_FORK ? &(ip)->i_df : (ip)->i_afp)
-#endif
-#if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_IFORK_Q)
-int xfs_ifork_q(xfs_inode_t *ip);
-#define        XFS_IFORK_Q(ip)                 xfs_ifork_q(ip)
-#else
+#define        XFS_IFORK_PTR(ip,w)             \
+       ((w) == XFS_DATA_FORK ? &(ip)->i_df : (ip)->i_afp)
 #define        XFS_IFORK_Q(ip)                 XFS_CFORK_Q(&(ip)->i_d)
-#endif
-#if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_IFORK_DSIZE)
-int xfs_ifork_dsize(xfs_inode_t *ip);
-#define        XFS_IFORK_DSIZE(ip)             xfs_ifork_dsize(ip)
-#else
 #define        XFS_IFORK_DSIZE(ip)             XFS_CFORK_DSIZE(&ip->i_d, ip->i_mount)
-#endif
-#if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_IFORK_ASIZE)
-int xfs_ifork_asize(xfs_inode_t *ip);
-#define        XFS_IFORK_ASIZE(ip)             xfs_ifork_asize(ip)
-#else
 #define        XFS_IFORK_ASIZE(ip)             XFS_CFORK_ASIZE(&ip->i_d, ip->i_mount)
-#endif
-#if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_IFORK_SIZE)
-int xfs_ifork_size(xfs_inode_t *ip, int w);
-#define        XFS_IFORK_SIZE(ip,w)            xfs_ifork_size(ip,w)
-#else
 #define        XFS_IFORK_SIZE(ip,w)            XFS_CFORK_SIZE(&ip->i_d, ip->i_mount, w)
-#endif
-#if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_IFORK_FORMAT)
-int xfs_ifork_format(xfs_inode_t *ip, int w);
-#define        XFS_IFORK_FORMAT(ip,w)          xfs_ifork_format(ip,w)
-#else
 #define        XFS_IFORK_FORMAT(ip,w)          XFS_CFORK_FORMAT(&ip->i_d, w)
-#endif
-#if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_IFORK_FMT_SET)
-void xfs_ifork_fmt_set(xfs_inode_t *ip, int w, int n);
-#define        XFS_IFORK_FMT_SET(ip,w,n)       xfs_ifork_fmt_set(ip,w,n)
-#else
 #define        XFS_IFORK_FMT_SET(ip,w,n)       XFS_CFORK_FMT_SET(&ip->i_d, w, n)
-#endif
-#if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_IFORK_NEXTENTS)
-int xfs_ifork_nextents(xfs_inode_t *ip, int w);
-#define        XFS_IFORK_NEXTENTS(ip,w)        xfs_ifork_nextents(ip,w)
-#else
 #define        XFS_IFORK_NEXTENTS(ip,w)        XFS_CFORK_NEXTENTS(&ip->i_d, w)
-#endif
-#if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_IFORK_NEXT_SET)
-void xfs_ifork_next_set(xfs_inode_t *ip, int w, int n);
-#define        XFS_IFORK_NEXT_SET(ip,w,n)      xfs_ifork_next_set(ip,w,n)
-#else
 #define        XFS_IFORK_NEXT_SET(ip,w,n)      XFS_CFORK_NEXT_SET(&ip->i_d, w, n)
-#endif
 
 
 #ifdef __KERNEL__
@@ -388,6 +343,7 @@ void xfs_ifork_next_set(xfs_inode_t *ip, int w, int n);
 #define        XFS_ILOCK_EXCL          0x004
 #define        XFS_ILOCK_SHARED        0x008
 #define        XFS_IUNLOCK_NONOTIFY    0x010
+/*     XFS_IOLOCK_NESTED       0x020 */
 #define XFS_EXTENT_TOKEN_RD    0x040
 #define XFS_SIZE_TOKEN_RD      0x080
 #define XFS_EXTSIZE_RD         (XFS_EXTENT_TOKEN_RD|XFS_SIZE_TOKEN_RD)
@@ -395,7 +351,7 @@ void xfs_ifork_next_set(xfs_inode_t *ip, int w, int n);
 #define XFS_EXTENT_TOKEN_WR    (XFS_EXTENT_TOKEN_RD | XFS_WILLLEND)
 #define XFS_SIZE_TOKEN_WR       (XFS_SIZE_TOKEN_RD | XFS_WILLLEND)
 #define XFS_EXTSIZE_WR         (XFS_EXTSIZE_RD | XFS_WILLLEND)
-
+/*     XFS_SIZE_TOKEN_WANT     0x200 */
 
 #define XFS_LOCK_MASK  \
        (XFS_IOLOCK_EXCL | XFS_IOLOCK_SHARED | XFS_ILOCK_EXCL | \
@@ -411,39 +367,17 @@ void xfs_ifork_next_set(xfs_inode_t *ip, int w, int n);
 #define        XFS_IFLUSH_ASYNC                4
 #define        XFS_IFLUSH_DELWRI               5
 
-/*
- * Flags for xfs_iflush_all.
- */
-#define        XFS_FLUSH_ALL           0x1
-
 /*
  * Flags for xfs_itruncate_start().
  */
 #define        XFS_ITRUNC_DEFINITE     0x1
 #define        XFS_ITRUNC_MAYBE        0x2
 
-#if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_ITOV)
-struct vnode *xfs_itov(xfs_inode_t *ip);
-#define        XFS_ITOV(ip)            xfs_itov(ip)
-#else
 #define        XFS_ITOV(ip)            BHV_TO_VNODE(XFS_ITOBHV(ip))
-#endif
 #define        XFS_ITOV_NULL(ip)       BHV_TO_VNODE_NULL(XFS_ITOBHV(ip))
-#if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_ITOBHV)
-struct bhv_desc *xfs_itobhv(xfs_inode_t *ip);
-#define        XFS_ITOBHV(ip)          xfs_itobhv(ip)
-#else
 #define        XFS_ITOBHV(ip)          ((struct bhv_desc *)(&((ip)->i_bhv_desc)))
-#endif
-#if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_BHVTOI)
-xfs_inode_t *xfs_bhvtoi(struct bhv_desc *bhvp);
-#define        XFS_BHVTOI(bhvp)        xfs_bhvtoi(bhvp)
-#else
-#define        XFS_BHVTOI(bhvp)        \
-       ((xfs_inode_t *)((char *)(bhvp) - \
-                        (char *)&(((xfs_inode_t *)0)->i_bhv_desc)))
-#endif
-
+#define        XFS_BHVTOI(bhvp)        ((xfs_inode_t *)((char *)(bhvp) - \
+                               (char *)&(((xfs_inode_t *)0)->i_bhv_desc)))
 #define BHV_IS_XFS(bdp)                (BHV_OPS(bdp) == &xfs_vnodeops)
 
 /*
@@ -487,11 +421,9 @@ int                xfs_finish_reclaim_all(struct xfs_mount *, int);
 /*
  * xfs_inode.c prototypes.
  */
-int            xfs_inotobp(struct xfs_mount *, struct xfs_trans *, xfs_ino_t,
-                           xfs_dinode_t **, struct xfs_buf **, int *);
 int            xfs_itobp(struct xfs_mount *, struct xfs_trans *,
                          xfs_inode_t *, xfs_dinode_t **, struct xfs_buf **,
-                         xfs_daddr_t);
+                         xfs_daddr_t, uint);
 int            xfs_iread(struct xfs_mount *, struct xfs_trans *, xfs_ino_t,
                          xfs_inode_t **, xfs_daddr_t);
 int            xfs_iread_extents(struct xfs_trans *, xfs_inode_t *, int);
@@ -522,13 +454,43 @@ void              xfs_ipin(xfs_inode_t *);
 void           xfs_iunpin(xfs_inode_t *);
 int            xfs_iextents_copy(xfs_inode_t *, xfs_bmbt_rec_t *, int);
 int            xfs_iflush(xfs_inode_t *, uint);
-int            xfs_iflush_all(struct xfs_mount *, int);
+void           xfs_iflush_all(struct xfs_mount *);
 int            xfs_iaccess(xfs_inode_t *, mode_t, cred_t *);
 uint           xfs_iroundup(uint);
 void           xfs_ichgtime(xfs_inode_t *, int);
 xfs_fsize_t    xfs_file_last_byte(xfs_inode_t *);
 void           xfs_lock_inodes(xfs_inode_t **, int, int, uint);
 
+xfs_inode_t    *xfs_vtoi(struct vnode *vp);
+
+void           xfs_synchronize_atime(xfs_inode_t *);
+
+xfs_bmbt_rec_t *xfs_iext_get_ext(xfs_ifork_t *, xfs_extnum_t);
+void           xfs_iext_insert(xfs_ifork_t *, xfs_extnum_t, xfs_extnum_t,
+                               xfs_bmbt_irec_t *);
+void           xfs_iext_add(xfs_ifork_t *, xfs_extnum_t, int);
+void           xfs_iext_add_indirect_multi(xfs_ifork_t *, int, xfs_extnum_t, int);
+void           xfs_iext_remove(xfs_ifork_t *, xfs_extnum_t, int);
+void           xfs_iext_remove_inline(xfs_ifork_t *, xfs_extnum_t, int);
+void           xfs_iext_remove_direct(xfs_ifork_t *, xfs_extnum_t, int);
+void           xfs_iext_remove_indirect(xfs_ifork_t *, xfs_extnum_t, int);
+void           xfs_iext_realloc_direct(xfs_ifork_t *, int);
+void           xfs_iext_realloc_indirect(xfs_ifork_t *, int);
+void           xfs_iext_indirect_to_direct(xfs_ifork_t *);
+void           xfs_iext_direct_to_inline(xfs_ifork_t *, xfs_extnum_t);
+void           xfs_iext_inline_to_direct(xfs_ifork_t *, int);
+void           xfs_iext_destroy(xfs_ifork_t *);
+xfs_bmbt_rec_t *xfs_iext_bno_to_ext(xfs_ifork_t *, xfs_fileoff_t, int *);
+xfs_ext_irec_t *xfs_iext_bno_to_irec(xfs_ifork_t *, xfs_fileoff_t, int *);
+xfs_ext_irec_t *xfs_iext_idx_to_irec(xfs_ifork_t *, xfs_extnum_t *, int *, int);
+void           xfs_iext_irec_init(xfs_ifork_t *);
+xfs_ext_irec_t *xfs_iext_irec_new(xfs_ifork_t *, int);
+void           xfs_iext_irec_remove(xfs_ifork_t *, int);
+void           xfs_iext_irec_compact(xfs_ifork_t *);
+void           xfs_iext_irec_compact_pages(xfs_ifork_t *);
+void           xfs_iext_irec_compact_full(xfs_ifork_t *);
+void           xfs_iext_irec_update_extoffs(xfs_ifork_t *, int, int);
+
 #define xfs_ipincount(ip)      ((unsigned int) atomic_read(&ip->i_pincount))
 
 #ifdef DEBUG