linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / fs / xfs / xfs_dfrag.c
index 80562b6..c6191d0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000-2006 Silicon Graphics, Inc.
+ * Copyright (c) 2000-2002,2005 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"
@@ -52,14 +54,24 @@ xfs_swapext(
        xfs_swapext_t   __user *sxu)
 {
        xfs_swapext_t   *sxp;
-       xfs_inode_t     *ip=NULL, *tip=NULL;
+       xfs_inode_t     *ip=NULL, *tip=NULL, *ips[2];
+       xfs_trans_t     *tp;
        xfs_mount_t     *mp;
+       xfs_bstat_t     *sbp;
        struct file     *fp = NULL, *tfp = NULL;
-       bhv_vnode_t     *vp, *tvp;
+       vnode_t         *vp, *tvp;
+       static uint     lock_flags = XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL;
+       int             ilf_fields, tilf_fields;
        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);
-       if (!sxp) {
+       tempifp = kmem_alloc(sizeof(xfs_ifork_t), KM_MAYFAIL);
+       if (!sxp || !tempifp) {
                error = XFS_ERROR(ENOMEM);
                goto error0;
        }
@@ -71,7 +83,7 @@ xfs_swapext(
 
        /* Pull information for the target fd */
        if (((fp = fget((int)sxp->sx_fdtarget)) == NULL) ||
-           ((vp = vn_from_inode(fp->f_dentry->d_inode)) == NULL))  {
+           ((vp = LINVFS_GET_VP(fp->f_dentry->d_inode)) == NULL))  {
                error = XFS_ERROR(EINVAL);
                goto error0;
        }
@@ -83,7 +95,7 @@ xfs_swapext(
        }
 
        if (((tfp = fget((int)sxp->sx_fdtmp)) == NULL) ||
-           ((tvp = vn_from_inode(tfp->f_dentry->d_inode)) == NULL)) {
+           ((tvp = LINVFS_GET_VP(tfp->f_dentry->d_inode)) == NULL)) {
                error = XFS_ERROR(EINVAL);
                goto error0;
        }
@@ -106,56 +118,14 @@ xfs_swapext(
 
        mp = ip->i_mount;
 
+       sbp = &sxp->sx_stat;
+
        if (XFS_FORCED_SHUTDOWN(mp)) {
                error =  XFS_ERROR(EIO);
                goto error0;
        }
 
-       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);
+       locked = 1;
 
        /* Lock in i_ino order */
        if (ip->i_ino < tip->i_ino) {
@@ -167,7 +137,6 @@ xfs_swap_extents(
        }
 
        xfs_lock_inodes(ips, 2, 0, lock_flags);
-       locked = 1;
 
        /* Check permissions */
        error = xfs_iaccess(ip, S_IWUSR, NULL);
@@ -200,7 +169,7 @@ xfs_swap_extents(
 
        if (VN_CACHED(tvp) != 0) {
                xfs_inval_cached_trace(&tip->i_iocore, 0, -1, 0, -1);
-               bhv_vop_flushinval_pages(tvp, 0, -1, FI_REMAPF_LOCKED);
+               VOP_FLUSHINVAL_PAGES(tvp, 0, -1, FI_REMAPF_LOCKED);
        }
 
        /* Verify O_DIRECT for ftmp */
@@ -245,7 +214,7 @@ xfs_swap_extents(
        /* 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)) {
@@ -264,7 +233,7 @@ xfs_swap_extents(
         * fields change.
         */
 
-       bhv_vop_toss_pages(vp, 0, -1, FI_REMAPF);
+       VOP_TOSS_PAGES(vp, 0, -1, FI_REMAPF);
 
        tp = xfs_trans_alloc(mp, XFS_TRANS_SWAPEXT);
        if ((error = xfs_trans_reserve(tp, 0,
@@ -391,7 +360,16 @@ xfs_swap_extents(
                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;
 }