Merge to Fedora kernel-2.6.18-1.2224_FC5 patched with stable patch-2.6.18.1-vs2.0...
[linux-2.6.git] / fs / xfs / xfs_dfrag.c
index 4968a63..80562b6 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc.
+ * Copyright (c) 2000-2006 Silicon Graphics, Inc.
  * All Rights Reserved.
  *
  * This program is free software; you can redistribute it and/or
 #include "xfs_trans.h"
 #include "xfs_sb.h"
 #include "xfs_ag.h"
-#include "xfs_dir.h"
 #include "xfs_dir2.h"
 #include "xfs_dmapi.h"
 #include "xfs_mount.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"
-#include "xfs_dir_sf.h"
 #include "xfs_dir2_sf.h"
 #include "xfs_attr_sf.h"
 #include "xfs_dinode.h"
@@ -54,24 +52,14 @@ xfs_swapext(
        xfs_swapext_t   __user *sxu)
 {
        xfs_swapext_t   *sxp;
-       xfs_inode_t     *ip=NULL, *tip=NULL, *ips[2];
-       xfs_trans_t     *tp;
+       xfs_inode_t     *ip=NULL, *tip=NULL;
        xfs_mount_t     *mp;
-       xfs_bstat_t     *sbp;
        struct file     *fp = NULL, *tfp = NULL;
-       vnode_t         *vp, *tvp;
-       static uint     lock_flags = XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL;
-       int             ilf_fields, tilf_fields;
+       bhv_vnode_t     *vp, *tvp;
        int             error = 0;
-       xfs_ifork_t     *tempifp, *ifp, *tifp;
-       __uint64_t      tmp;
-       int             aforkblks = 0;
-       int             taforkblks = 0;
-       char            locked = 0;
 
        sxp = kmem_alloc(sizeof(xfs_swapext_t), KM_MAYFAIL);
-       tempifp = kmem_alloc(sizeof(xfs_ifork_t), KM_MAYFAIL);
-       if (!sxp || !tempifp) {
+       if (!sxp) {
                error = XFS_ERROR(ENOMEM);
                goto error0;
        }
@@ -118,14 +106,56 @@ xfs_swapext(
 
        mp = ip->i_mount;
 
-       sbp = &sxp->sx_stat;
-
        if (XFS_FORCED_SHUTDOWN(mp)) {
                error =  XFS_ERROR(EIO);
                goto error0;
        }
 
-       locked = 1;
+       error = XFS_SWAP_EXTENTS(mp, &ip->i_iocore, &tip->i_iocore, sxp);
+
+ error0:
+       if (fp != NULL)
+               fput(fp);
+       if (tfp != NULL)
+               fput(tfp);
+
+       if (sxp != NULL)
+               kmem_free(sxp, sizeof(xfs_swapext_t));
+
+       return error;
+}
+
+int
+xfs_swap_extents(
+       xfs_inode_t     *ip,
+       xfs_inode_t     *tip,
+       xfs_swapext_t   *sxp)
+{
+       xfs_mount_t     *mp;
+       xfs_inode_t     *ips[2];
+       xfs_trans_t     *tp;
+       xfs_bstat_t     *sbp = &sxp->sx_stat;
+       bhv_vnode_t     *vp, *tvp;
+       xfs_ifork_t     *tempifp, *ifp, *tifp;
+       int             ilf_fields, tilf_fields;
+       static uint     lock_flags = XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL;
+       int             error = 0;
+       int             aforkblks = 0;
+       int             taforkblks = 0;
+       __uint64_t      tmp;
+       char            locked = 0;
+
+       mp = ip->i_mount;
+
+       tempifp = kmem_alloc(sizeof(xfs_ifork_t), KM_MAYFAIL);
+       if (!tempifp) {
+               error = XFS_ERROR(ENOMEM);
+               goto error0;
+       }
+
+       sbp = &sxp->sx_stat;
+       vp = XFS_ITOV(ip);
+       tvp = XFS_ITOV(tip);
 
        /* Lock in i_ino order */
        if (ip->i_ino < tip->i_ino) {
@@ -137,6 +167,7 @@ xfs_swapext(
        }
 
        xfs_lock_inodes(ips, 2, 0, lock_flags);
+       locked = 1;
 
        /* Check permissions */
        error = xfs_iaccess(ip, S_IWUSR, NULL);
@@ -169,7 +200,7 @@ xfs_swapext(
 
        if (VN_CACHED(tvp) != 0) {
                xfs_inval_cached_trace(&tip->i_iocore, 0, -1, 0, -1);
-               VOP_FLUSHINVAL_PAGES(tvp, 0, -1, FI_REMAPF_LOCKED);
+               bhv_vop_flushinval_pages(tvp, 0, -1, FI_REMAPF_LOCKED);
        }
 
        /* Verify O_DIRECT for ftmp */
@@ -214,7 +245,7 @@ xfs_swapext(
        /* We need to fail if the file is memory mapped.  Once we have tossed
         * all existing pages, the page fault will have no option
         * but to go to the filesystem for pages. By making the page fault call
-        * VOP_READ (or write in the case of autogrow) they block on the iolock
+        * vop_read (or write in the case of autogrow) they block on the iolock
         * until we have switched the extents.
         */
        if (VN_MAPPED(vp)) {
@@ -233,7 +264,7 @@ xfs_swapext(
         * fields change.
         */
 
-       VOP_TOSS_PAGES(vp, 0, -1, FI_REMAPF);
+       bhv_vop_toss_pages(vp, 0, -1, FI_REMAPF);
 
        tp = xfs_trans_alloc(mp, XFS_TRANS_SWAPEXT);
        if ((error = xfs_trans_reserve(tp, 0,
@@ -360,16 +391,7 @@ xfs_swapext(
                xfs_iunlock(ip,  lock_flags);
                xfs_iunlock(tip, lock_flags);
        }
-
-       if (fp != NULL)
-               fput(fp);
-       if (tfp != NULL)
-               fput(tfp);
-
-       if (sxp != NULL)
-               kmem_free(sxp, sizeof(xfs_swapext_t));
        if (tempifp != NULL)
                kmem_free(tempifp, sizeof(xfs_ifork_t));
-
        return error;
 }