diff options
Diffstat (limited to 'fs/xfs/xfs_dfrag.c')
| -rw-r--r-- | fs/xfs/xfs_dfrag.c | 123 |
1 files changed, 59 insertions, 64 deletions
diff --git a/fs/xfs/xfs_dfrag.c b/fs/xfs/xfs_dfrag.c index 681be5c93af5..070259a4254c 100644 --- a/fs/xfs/xfs_dfrag.c +++ b/fs/xfs/xfs_dfrag.c | |||
| @@ -1,58 +1,44 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Copyright (c) 2000-2002 Silicon Graphics, Inc. All Rights Reserved. | 2 | * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc. |
| 3 | * All Rights Reserved. | ||
| 3 | * | 4 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it | 5 | * This program is free software; you can redistribute it and/or |
| 5 | * under the terms of version 2 of the GNU General Public License as | 6 | * modify it under the terms of the GNU General Public License as |
| 6 | * published by the Free Software Foundation. | 7 | * published by the Free Software Foundation. |
| 7 | * | 8 | * |
| 8 | * This program is distributed in the hope that it would be useful, but | 9 | * This program is distributed in the hope that it would be useful, |
| 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. | ||
| 11 | * | 13 | * |
| 12 | * Further, this software is distributed without any warranty that it is | 14 | * You should have received a copy of the GNU General Public License |
| 13 | * free of the rightful claim of any third person regarding infringement | 15 | * along with this program; if not, write the Free Software Foundation, |
| 14 | * or the like. Any license provided herein, whether implied or | 16 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 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 | */ | 17 | */ |
| 32 | |||
| 33 | #include "xfs.h" | 18 | #include "xfs.h" |
| 34 | #include "xfs_macros.h" | 19 | #include "xfs_fs.h" |
| 35 | #include "xfs_types.h" | 20 | #include "xfs_types.h" |
| 36 | #include "xfs_inum.h" | 21 | #include "xfs_bit.h" |
| 37 | #include "xfs_log.h" | 22 | #include "xfs_log.h" |
| 23 | #include "xfs_inum.h" | ||
| 38 | #include "xfs_trans.h" | 24 | #include "xfs_trans.h" |
| 39 | #include "xfs_sb.h" | 25 | #include "xfs_sb.h" |
| 26 | #include "xfs_ag.h" | ||
| 40 | #include "xfs_dir.h" | 27 | #include "xfs_dir.h" |
| 41 | #include "xfs_dir2.h" | 28 | #include "xfs_dir2.h" |
| 42 | #include "xfs_dmapi.h" | 29 | #include "xfs_dmapi.h" |
| 43 | #include "xfs_mount.h" | 30 | #include "xfs_mount.h" |
| 44 | #include "xfs_ag.h" | ||
| 45 | #include "xfs_alloc_btree.h" | ||
| 46 | #include "xfs_bmap_btree.h" | 31 | #include "xfs_bmap_btree.h" |
| 32 | #include "xfs_alloc_btree.h" | ||
| 47 | #include "xfs_ialloc_btree.h" | 33 | #include "xfs_ialloc_btree.h" |
| 48 | #include "xfs_btree.h" | ||
| 49 | #include "xfs_attr_sf.h" | ||
| 50 | #include "xfs_dir_sf.h" | 34 | #include "xfs_dir_sf.h" |
| 51 | #include "xfs_dir2_sf.h" | 35 | #include "xfs_dir2_sf.h" |
| 36 | #include "xfs_attr_sf.h" | ||
| 52 | #include "xfs_dinode.h" | 37 | #include "xfs_dinode.h" |
| 53 | #include "xfs_inode_item.h" | ||
| 54 | #include "xfs_inode.h" | 38 | #include "xfs_inode.h" |
| 39 | #include "xfs_inode_item.h" | ||
| 55 | #include "xfs_bmap.h" | 40 | #include "xfs_bmap.h" |
| 41 | #include "xfs_btree.h" | ||
| 56 | #include "xfs_ialloc.h" | 42 | #include "xfs_ialloc.h" |
| 57 | #include "xfs_itable.h" | 43 | #include "xfs_itable.h" |
| 58 | #include "xfs_dfrag.h" | 44 | #include "xfs_dfrag.h" |
| @@ -65,9 +51,9 @@ | |||
| 65 | */ | 51 | */ |
| 66 | int | 52 | int |
| 67 | xfs_swapext( | 53 | xfs_swapext( |
| 68 | xfs_swapext_t __user *sxp) | 54 | xfs_swapext_t __user *sxu) |
| 69 | { | 55 | { |
| 70 | xfs_swapext_t sx; | 56 | xfs_swapext_t *sxp; |
| 71 | xfs_inode_t *ip=NULL, *tip=NULL, *ips[2]; | 57 | xfs_inode_t *ip=NULL, *tip=NULL, *ips[2]; |
| 72 | xfs_trans_t *tp; | 58 | xfs_trans_t *tp; |
| 73 | xfs_mount_t *mp; | 59 | xfs_mount_t *mp; |
| @@ -76,20 +62,29 @@ xfs_swapext( | |||
| 76 | vnode_t *vp, *tvp; | 62 | vnode_t *vp, *tvp; |
| 77 | bhv_desc_t *bdp, *tbdp; | 63 | bhv_desc_t *bdp, *tbdp; |
| 78 | vn_bhv_head_t *bhp, *tbhp; | 64 | vn_bhv_head_t *bhp, *tbhp; |
| 79 | uint lock_flags=0; | 65 | static uint lock_flags = XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL; |
| 80 | int ilf_fields, tilf_fields; | 66 | int ilf_fields, tilf_fields; |
| 81 | int error = 0; | 67 | int error = 0; |
| 82 | xfs_ifork_t tempif, *ifp, *tifp; | 68 | xfs_ifork_t *tempifp, *ifp, *tifp; |
| 83 | __uint64_t tmp; | 69 | __uint64_t tmp; |
| 84 | int aforkblks = 0; | 70 | int aforkblks = 0; |
| 85 | int taforkblks = 0; | 71 | int taforkblks = 0; |
| 86 | int locked = 0; | 72 | char locked = 0; |
| 87 | 73 | ||
| 88 | if (copy_from_user(&sx, sxp, sizeof(sx))) | 74 | sxp = kmem_alloc(sizeof(xfs_swapext_t), KM_MAYFAIL); |
| 89 | return XFS_ERROR(EFAULT); | 75 | tempifp = kmem_alloc(sizeof(xfs_ifork_t), KM_MAYFAIL); |
| 76 | if (!sxp || !tempifp) { | ||
| 77 | error = XFS_ERROR(ENOMEM); | ||
| 78 | goto error0; | ||
| 79 | } | ||
| 80 | |||
| 81 | if (copy_from_user(sxp, sxu, sizeof(xfs_swapext_t))) { | ||
| 82 | error = XFS_ERROR(EFAULT); | ||
| 83 | goto error0; | ||
| 84 | } | ||
| 90 | 85 | ||
| 91 | /* Pull information for the target fd */ | 86 | /* Pull information for the target fd */ |
| 92 | if (((fp = fget((int)sx.sx_fdtarget)) == NULL) || | 87 | if (((fp = fget((int)sxp->sx_fdtarget)) == NULL) || |
| 93 | ((vp = LINVFS_GET_VP(fp->f_dentry->d_inode)) == NULL)) { | 88 | ((vp = LINVFS_GET_VP(fp->f_dentry->d_inode)) == NULL)) { |
| 94 | error = XFS_ERROR(EINVAL); | 89 | error = XFS_ERROR(EINVAL); |
| 95 | goto error0; | 90 | goto error0; |
| @@ -104,7 +99,7 @@ xfs_swapext( | |||
| 104 | ip = XFS_BHVTOI(bdp); | 99 | ip = XFS_BHVTOI(bdp); |
| 105 | } | 100 | } |
| 106 | 101 | ||
| 107 | if (((tfp = fget((int)sx.sx_fdtmp)) == NULL) || | 102 | if (((tfp = fget((int)sxp->sx_fdtmp)) == NULL) || |
| 108 | ((tvp = LINVFS_GET_VP(tfp->f_dentry->d_inode)) == NULL)) { | 103 | ((tvp = LINVFS_GET_VP(tfp->f_dentry->d_inode)) == NULL)) { |
| 109 | error = XFS_ERROR(EINVAL); | 104 | error = XFS_ERROR(EINVAL); |
| 110 | goto error0; | 105 | goto error0; |
| @@ -131,7 +126,7 @@ xfs_swapext( | |||
| 131 | 126 | ||
| 132 | mp = ip->i_mount; | 127 | mp = ip->i_mount; |
| 133 | 128 | ||
| 134 | sbp = &sx.sx_stat; | 129 | sbp = &sxp->sx_stat; |
| 135 | 130 | ||
| 136 | if (XFS_FORCED_SHUTDOWN(mp)) { | 131 | if (XFS_FORCED_SHUTDOWN(mp)) { |
| 137 | error = XFS_ERROR(EIO); | 132 | error = XFS_ERROR(EIO); |
| @@ -148,7 +143,7 @@ xfs_swapext( | |||
| 148 | ips[0] = tip; | 143 | ips[0] = tip; |
| 149 | ips[1] = ip; | 144 | ips[1] = ip; |
| 150 | } | 145 | } |
| 151 | lock_flags = XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL; | 146 | |
| 152 | xfs_lock_inodes(ips, 2, 0, lock_flags); | 147 | xfs_lock_inodes(ips, 2, 0, lock_flags); |
| 153 | 148 | ||
| 154 | /* Check permissions */ | 149 | /* Check permissions */ |
| @@ -192,9 +187,9 @@ xfs_swapext( | |||
| 192 | } | 187 | } |
| 193 | 188 | ||
| 194 | /* Verify all data are being swapped */ | 189 | /* Verify all data are being swapped */ |
| 195 | if (sx.sx_offset != 0 || | 190 | if (sxp->sx_offset != 0 || |
| 196 | sx.sx_length != ip->i_d.di_size || | 191 | sxp->sx_length != ip->i_d.di_size || |
| 197 | sx.sx_length != tip->i_d.di_size) { | 192 | sxp->sx_length != tip->i_d.di_size) { |
| 198 | error = XFS_ERROR(EFAULT); | 193 | error = XFS_ERROR(EFAULT); |
| 199 | goto error0; | 194 | goto error0; |
| 200 | } | 195 | } |
| @@ -255,7 +250,8 @@ xfs_swapext( | |||
| 255 | xfs_iunlock(ip, XFS_IOLOCK_EXCL); | 250 | xfs_iunlock(ip, XFS_IOLOCK_EXCL); |
| 256 | xfs_iunlock(tip, XFS_IOLOCK_EXCL); | 251 | xfs_iunlock(tip, XFS_IOLOCK_EXCL); |
| 257 | xfs_trans_cancel(tp, 0); | 252 | xfs_trans_cancel(tp, 0); |
| 258 | return error; | 253 | locked = 0; |
| 254 | goto error0; | ||
| 259 | } | 255 | } |
| 260 | xfs_lock_inodes(ips, 2, 0, XFS_ILOCK_EXCL); | 256 | xfs_lock_inodes(ips, 2, 0, XFS_ILOCK_EXCL); |
| 261 | 257 | ||
| @@ -266,10 +262,8 @@ xfs_swapext( | |||
| 266 | (ip->i_d.di_aformat != XFS_DINODE_FMT_LOCAL)) { | 262 | (ip->i_d.di_aformat != XFS_DINODE_FMT_LOCAL)) { |
| 267 | error = xfs_bmap_count_blocks(tp, ip, XFS_ATTR_FORK, &aforkblks); | 263 | error = xfs_bmap_count_blocks(tp, ip, XFS_ATTR_FORK, &aforkblks); |
| 268 | if (error) { | 264 | if (error) { |
| 269 | xfs_iunlock(ip, lock_flags); | ||
| 270 | xfs_iunlock(tip, lock_flags); | ||
| 271 | xfs_trans_cancel(tp, 0); | 265 | xfs_trans_cancel(tp, 0); |
| 272 | return error; | 266 | goto error0; |
| 273 | } | 267 | } |
| 274 | } | 268 | } |
| 275 | if ( ((XFS_IFORK_Q(tip) != 0) && (tip->i_d.di_anextents > 0)) && | 269 | if ( ((XFS_IFORK_Q(tip) != 0) && (tip->i_d.di_anextents > 0)) && |
| @@ -277,10 +271,8 @@ xfs_swapext( | |||
| 277 | error = xfs_bmap_count_blocks(tp, tip, XFS_ATTR_FORK, | 271 | error = xfs_bmap_count_blocks(tp, tip, XFS_ATTR_FORK, |
| 278 | &taforkblks); | 272 | &taforkblks); |
| 279 | if (error) { | 273 | if (error) { |
| 280 | xfs_iunlock(ip, lock_flags); | ||
| 281 | xfs_iunlock(tip, lock_flags); | ||
| 282 | xfs_trans_cancel(tp, 0); | 274 | xfs_trans_cancel(tp, 0); |
| 283 | return error; | 275 | goto error0; |
| 284 | } | 276 | } |
| 285 | } | 277 | } |
| 286 | 278 | ||
| @@ -289,9 +281,9 @@ xfs_swapext( | |||
| 289 | */ | 281 | */ |
| 290 | ifp = &ip->i_df; | 282 | ifp = &ip->i_df; |
| 291 | tifp = &tip->i_df; | 283 | tifp = &tip->i_df; |
| 292 | tempif = *ifp; /* struct copy */ | 284 | *tempifp = *ifp; /* struct copy */ |
| 293 | *ifp = *tifp; /* struct copy */ | 285 | *ifp = *tifp; /* struct copy */ |
| 294 | *tifp = tempif; /* struct copy */ | 286 | *tifp = *tempifp; /* struct copy */ |
| 295 | 287 | ||
| 296 | /* | 288 | /* |
| 297 | * Fix the on-disk inode values | 289 | * Fix the on-disk inode values |
| @@ -369,11 +361,7 @@ xfs_swapext( | |||
| 369 | } | 361 | } |
| 370 | 362 | ||
| 371 | error = xfs_trans_commit(tp, XFS_TRANS_SWAPEXT, NULL); | 363 | error = xfs_trans_commit(tp, XFS_TRANS_SWAPEXT, NULL); |
| 372 | 364 | locked = 0; | |
| 373 | fput(fp); | ||
| 374 | fput(tfp); | ||
| 375 | |||
| 376 | return error; | ||
| 377 | 365 | ||
| 378 | error0: | 366 | error0: |
| 379 | if (locked) { | 367 | if (locked) { |
| @@ -381,8 +369,15 @@ xfs_swapext( | |||
| 381 | xfs_iunlock(tip, lock_flags); | 369 | xfs_iunlock(tip, lock_flags); |
| 382 | } | 370 | } |
| 383 | 371 | ||
| 384 | if (fp != NULL) fput(fp); | 372 | if (fp != NULL) |
| 385 | if (tfp != NULL) fput(tfp); | 373 | fput(fp); |
| 374 | if (tfp != NULL) | ||
| 375 | fput(tfp); | ||
| 376 | |||
| 377 | if (sxp != NULL) | ||
| 378 | kmem_free(sxp, sizeof(xfs_swapext_t)); | ||
| 379 | if (tempifp != NULL) | ||
| 380 | kmem_free(tempifp, sizeof(xfs_ifork_t)); | ||
| 386 | 381 | ||
| 387 | return error; | 382 | return error; |
| 388 | } | 383 | } |
