diff options
Diffstat (limited to 'fs/xfs/xfs_dfrag.c')
-rw-r--r-- | fs/xfs/xfs_dfrag.c | 74 |
1 files changed, 49 insertions, 25 deletions
diff --git a/fs/xfs/xfs_dfrag.c b/fs/xfs/xfs_dfrag.c index 4968a6358e61..99daf8c0f900 100644 --- a/fs/xfs/xfs_dfrag.c +++ b/fs/xfs/xfs_dfrag.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc. | 2 | * Copyright (c) 2000-2006 Silicon Graphics, Inc. |
3 | * All Rights Reserved. | 3 | * All Rights Reserved. |
4 | * | 4 | * |
5 | * This program is free software; you can redistribute it and/or | 5 | * This program is free software; you can redistribute it and/or |
@@ -54,24 +54,14 @@ xfs_swapext( | |||
54 | xfs_swapext_t __user *sxu) | 54 | xfs_swapext_t __user *sxu) |
55 | { | 55 | { |
56 | xfs_swapext_t *sxp; | 56 | xfs_swapext_t *sxp; |
57 | xfs_inode_t *ip=NULL, *tip=NULL, *ips[2]; | 57 | xfs_inode_t *ip=NULL, *tip=NULL; |
58 | xfs_trans_t *tp; | ||
59 | xfs_mount_t *mp; | 58 | xfs_mount_t *mp; |
60 | xfs_bstat_t *sbp; | ||
61 | struct file *fp = NULL, *tfp = NULL; | 59 | struct file *fp = NULL, *tfp = NULL; |
62 | vnode_t *vp, *tvp; | 60 | vnode_t *vp, *tvp; |
63 | static uint lock_flags = XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL; | ||
64 | int ilf_fields, tilf_fields; | ||
65 | int error = 0; | 61 | int error = 0; |
66 | xfs_ifork_t *tempifp, *ifp, *tifp; | ||
67 | __uint64_t tmp; | ||
68 | int aforkblks = 0; | ||
69 | int taforkblks = 0; | ||
70 | char locked = 0; | ||
71 | 62 | ||
72 | sxp = kmem_alloc(sizeof(xfs_swapext_t), KM_MAYFAIL); | 63 | sxp = kmem_alloc(sizeof(xfs_swapext_t), KM_MAYFAIL); |
73 | tempifp = kmem_alloc(sizeof(xfs_ifork_t), KM_MAYFAIL); | 64 | if (!sxp) { |
74 | if (!sxp || !tempifp) { | ||
75 | error = XFS_ERROR(ENOMEM); | 65 | error = XFS_ERROR(ENOMEM); |
76 | goto error0; | 66 | goto error0; |
77 | } | 67 | } |
@@ -118,14 +108,56 @@ xfs_swapext( | |||
118 | 108 | ||
119 | mp = ip->i_mount; | 109 | mp = ip->i_mount; |
120 | 110 | ||
121 | sbp = &sxp->sx_stat; | ||
122 | |||
123 | if (XFS_FORCED_SHUTDOWN(mp)) { | 111 | if (XFS_FORCED_SHUTDOWN(mp)) { |
124 | error = XFS_ERROR(EIO); | 112 | error = XFS_ERROR(EIO); |
125 | goto error0; | 113 | goto error0; |
126 | } | 114 | } |
127 | 115 | ||
128 | locked = 1; | 116 | error = XFS_SWAP_EXTENTS(mp, &ip->i_iocore, &tip->i_iocore, sxp); |
117 | |||
118 | error0: | ||
119 | if (fp != NULL) | ||
120 | fput(fp); | ||
121 | if (tfp != NULL) | ||
122 | fput(tfp); | ||
123 | |||
124 | if (sxp != NULL) | ||
125 | kmem_free(sxp, sizeof(xfs_swapext_t)); | ||
126 | |||
127 | return error; | ||
128 | } | ||
129 | |||
130 | int | ||
131 | xfs_swap_extents( | ||
132 | xfs_inode_t *ip, | ||
133 | xfs_inode_t *tip, | ||
134 | xfs_swapext_t *sxp) | ||
135 | { | ||
136 | xfs_mount_t *mp; | ||
137 | xfs_inode_t *ips[2]; | ||
138 | xfs_trans_t *tp; | ||
139 | xfs_bstat_t *sbp = &sxp->sx_stat; | ||
140 | vnode_t *vp, *tvp; | ||
141 | xfs_ifork_t *tempifp, *ifp, *tifp; | ||
142 | int ilf_fields, tilf_fields; | ||
143 | static uint lock_flags = XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL; | ||
144 | int error = 0; | ||
145 | int aforkblks = 0; | ||
146 | int taforkblks = 0; | ||
147 | __uint64_t tmp; | ||
148 | char locked = 0; | ||
149 | |||
150 | mp = ip->i_mount; | ||
151 | |||
152 | tempifp = kmem_alloc(sizeof(xfs_ifork_t), KM_MAYFAIL); | ||
153 | if (!tempifp) { | ||
154 | error = XFS_ERROR(ENOMEM); | ||
155 | goto error0; | ||
156 | } | ||
157 | |||
158 | sbp = &sxp->sx_stat; | ||
159 | vp = XFS_ITOV(ip); | ||
160 | tvp = XFS_ITOV(tip); | ||
129 | 161 | ||
130 | /* Lock in i_ino order */ | 162 | /* Lock in i_ino order */ |
131 | if (ip->i_ino < tip->i_ino) { | 163 | if (ip->i_ino < tip->i_ino) { |
@@ -137,6 +169,7 @@ xfs_swapext( | |||
137 | } | 169 | } |
138 | 170 | ||
139 | xfs_lock_inodes(ips, 2, 0, lock_flags); | 171 | xfs_lock_inodes(ips, 2, 0, lock_flags); |
172 | locked = 1; | ||
140 | 173 | ||
141 | /* Check permissions */ | 174 | /* Check permissions */ |
142 | error = xfs_iaccess(ip, S_IWUSR, NULL); | 175 | error = xfs_iaccess(ip, S_IWUSR, NULL); |
@@ -360,16 +393,7 @@ xfs_swapext( | |||
360 | xfs_iunlock(ip, lock_flags); | 393 | xfs_iunlock(ip, lock_flags); |
361 | xfs_iunlock(tip, lock_flags); | 394 | xfs_iunlock(tip, lock_flags); |
362 | } | 395 | } |
363 | |||
364 | if (fp != NULL) | ||
365 | fput(fp); | ||
366 | if (tfp != NULL) | ||
367 | fput(tfp); | ||
368 | |||
369 | if (sxp != NULL) | ||
370 | kmem_free(sxp, sizeof(xfs_swapext_t)); | ||
371 | if (tempifp != NULL) | 396 | if (tempifp != NULL) |
372 | kmem_free(tempifp, sizeof(xfs_ifork_t)); | 397 | kmem_free(tempifp, sizeof(xfs_ifork_t)); |
373 | |||
374 | return error; | 398 | return error; |
375 | } | 399 | } |