diff options
author | Josef 'Jeff' Sipek <jeffpc@josefsipek.net> | 2009-02-04 03:37:43 -0500 |
---|---|---|
committer | Christoph Hellwig <hch@brick.lst.de> | 2009-02-04 03:37:43 -0500 |
commit | ef8f7fc549bf345d92f396f5aa7b152b4969cbf7 (patch) | |
tree | a3c2fc624b83d3fced5c95c036a8d0d20227fab8 /fs/xfs/xfs_dfrag.c | |
parent | d4bb6d0698090c485e2e80e8a13852be5a8bfb04 (diff) |
xfs: cleanup error handling in xfs_swap_extents
Use multiple lables for proper error unwinding and get rid of some now
superflous variables.
Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Tested-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Felix Blyakher <felixb@sgi.com>
Diffstat (limited to 'fs/xfs/xfs_dfrag.c')
-rw-r--r-- | fs/xfs/xfs_dfrag.c | 62 |
1 files changed, 27 insertions, 35 deletions
diff --git a/fs/xfs/xfs_dfrag.c b/fs/xfs/xfs_dfrag.c index f8278cfcc1d3..ac96ab9f70a2 100644 --- a/fs/xfs/xfs_dfrag.c +++ b/fs/xfs/xfs_dfrag.c | |||
@@ -118,19 +118,17 @@ xfs_swap_extents( | |||
118 | xfs_bstat_t *sbp = &sxp->sx_stat; | 118 | xfs_bstat_t *sbp = &sxp->sx_stat; |
119 | xfs_ifork_t *tempifp, *ifp, *tifp; | 119 | xfs_ifork_t *tempifp, *ifp, *tifp; |
120 | int ilf_fields, tilf_fields; | 120 | int ilf_fields, tilf_fields; |
121 | static uint lock_flags = XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL; | ||
122 | int error = 0; | 121 | int error = 0; |
123 | int aforkblks = 0; | 122 | int aforkblks = 0; |
124 | int taforkblks = 0; | 123 | int taforkblks = 0; |
125 | __uint64_t tmp; | 124 | __uint64_t tmp; |
126 | char locked = 0; | ||
127 | 125 | ||
128 | mp = ip->i_mount; | 126 | mp = ip->i_mount; |
129 | 127 | ||
130 | tempifp = kmem_alloc(sizeof(xfs_ifork_t), KM_MAYFAIL); | 128 | tempifp = kmem_alloc(sizeof(xfs_ifork_t), KM_MAYFAIL); |
131 | if (!tempifp) { | 129 | if (!tempifp) { |
132 | error = XFS_ERROR(ENOMEM); | 130 | error = XFS_ERROR(ENOMEM); |
133 | goto error0; | 131 | goto out; |
134 | } | 132 | } |
135 | 133 | ||
136 | sbp = &sxp->sx_stat; | 134 | sbp = &sxp->sx_stat; |
@@ -143,25 +141,24 @@ xfs_swap_extents( | |||
143 | */ | 141 | */ |
144 | xfs_lock_two_inodes(ip, tip, XFS_IOLOCK_EXCL); | 142 | xfs_lock_two_inodes(ip, tip, XFS_IOLOCK_EXCL); |
145 | xfs_lock_two_inodes(ip, tip, XFS_ILOCK_EXCL); | 143 | xfs_lock_two_inodes(ip, tip, XFS_ILOCK_EXCL); |
146 | locked = 1; | ||
147 | 144 | ||
148 | /* Verify that both files have the same format */ | 145 | /* Verify that both files have the same format */ |
149 | if ((ip->i_d.di_mode & S_IFMT) != (tip->i_d.di_mode & S_IFMT)) { | 146 | if ((ip->i_d.di_mode & S_IFMT) != (tip->i_d.di_mode & S_IFMT)) { |
150 | error = XFS_ERROR(EINVAL); | 147 | error = XFS_ERROR(EINVAL); |
151 | goto error0; | 148 | goto out_unlock; |
152 | } | 149 | } |
153 | 150 | ||
154 | /* Verify both files are either real-time or non-realtime */ | 151 | /* Verify both files are either real-time or non-realtime */ |
155 | if (XFS_IS_REALTIME_INODE(ip) != XFS_IS_REALTIME_INODE(tip)) { | 152 | if (XFS_IS_REALTIME_INODE(ip) != XFS_IS_REALTIME_INODE(tip)) { |
156 | error = XFS_ERROR(EINVAL); | 153 | error = XFS_ERROR(EINVAL); |
157 | goto error0; | 154 | goto out_unlock; |
158 | } | 155 | } |
159 | 156 | ||
160 | /* Should never get a local format */ | 157 | /* Should never get a local format */ |
161 | if (ip->i_d.di_format == XFS_DINODE_FMT_LOCAL || | 158 | if (ip->i_d.di_format == XFS_DINODE_FMT_LOCAL || |
162 | tip->i_d.di_format == XFS_DINODE_FMT_LOCAL) { | 159 | tip->i_d.di_format == XFS_DINODE_FMT_LOCAL) { |
163 | error = XFS_ERROR(EINVAL); | 160 | error = XFS_ERROR(EINVAL); |
164 | goto error0; | 161 | goto out_unlock; |
165 | } | 162 | } |
166 | 163 | ||
167 | if (VN_CACHED(VFS_I(tip)) != 0) { | 164 | if (VN_CACHED(VFS_I(tip)) != 0) { |
@@ -169,13 +166,13 @@ xfs_swap_extents( | |||
169 | error = xfs_flushinval_pages(tip, 0, -1, | 166 | error = xfs_flushinval_pages(tip, 0, -1, |
170 | FI_REMAPF_LOCKED); | 167 | FI_REMAPF_LOCKED); |
171 | if (error) | 168 | if (error) |
172 | goto error0; | 169 | goto out_unlock; |
173 | } | 170 | } |
174 | 171 | ||
175 | /* Verify O_DIRECT for ftmp */ | 172 | /* Verify O_DIRECT for ftmp */ |
176 | if (VN_CACHED(VFS_I(tip)) != 0) { | 173 | if (VN_CACHED(VFS_I(tip)) != 0) { |
177 | error = XFS_ERROR(EINVAL); | 174 | error = XFS_ERROR(EINVAL); |
178 | goto error0; | 175 | goto out_unlock; |
179 | } | 176 | } |
180 | 177 | ||
181 | /* Verify all data are being swapped */ | 178 | /* Verify all data are being swapped */ |
@@ -183,7 +180,7 @@ xfs_swap_extents( | |||
183 | sxp->sx_length != ip->i_d.di_size || | 180 | sxp->sx_length != ip->i_d.di_size || |
184 | sxp->sx_length != tip->i_d.di_size) { | 181 | sxp->sx_length != tip->i_d.di_size) { |
185 | error = XFS_ERROR(EFAULT); | 182 | error = XFS_ERROR(EFAULT); |
186 | goto error0; | 183 | goto out_unlock; |
187 | } | 184 | } |
188 | 185 | ||
189 | /* | 186 | /* |
@@ -193,7 +190,7 @@ xfs_swap_extents( | |||
193 | */ | 190 | */ |
194 | if ( XFS_IFORK_Q(ip) != XFS_IFORK_Q(tip) ) { | 191 | if ( XFS_IFORK_Q(ip) != XFS_IFORK_Q(tip) ) { |
195 | error = XFS_ERROR(EINVAL); | 192 | error = XFS_ERROR(EINVAL); |
196 | goto error0; | 193 | goto out_unlock; |
197 | } | 194 | } |
198 | 195 | ||
199 | /* | 196 | /* |
@@ -208,7 +205,7 @@ xfs_swap_extents( | |||
208 | (sbp->bs_mtime.tv_sec != ip->i_d.di_mtime.t_sec) || | 205 | (sbp->bs_mtime.tv_sec != ip->i_d.di_mtime.t_sec) || |
209 | (sbp->bs_mtime.tv_nsec != ip->i_d.di_mtime.t_nsec)) { | 206 | (sbp->bs_mtime.tv_nsec != ip->i_d.di_mtime.t_nsec)) { |
210 | error = XFS_ERROR(EBUSY); | 207 | error = XFS_ERROR(EBUSY); |
211 | goto error0; | 208 | goto out_unlock; |
212 | } | 209 | } |
213 | 210 | ||
214 | /* We need to fail if the file is memory mapped. Once we have tossed | 211 | /* We need to fail if the file is memory mapped. Once we have tossed |
@@ -219,7 +216,7 @@ xfs_swap_extents( | |||
219 | */ | 216 | */ |
220 | if (VN_MAPPED(VFS_I(ip))) { | 217 | if (VN_MAPPED(VFS_I(ip))) { |
221 | error = XFS_ERROR(EBUSY); | 218 | error = XFS_ERROR(EBUSY); |
222 | goto error0; | 219 | goto out_unlock; |
223 | } | 220 | } |
224 | 221 | ||
225 | xfs_iunlock(ip, XFS_ILOCK_EXCL); | 222 | xfs_iunlock(ip, XFS_ILOCK_EXCL); |
@@ -242,8 +239,7 @@ xfs_swap_extents( | |||
242 | xfs_iunlock(ip, XFS_IOLOCK_EXCL); | 239 | xfs_iunlock(ip, XFS_IOLOCK_EXCL); |
243 | xfs_iunlock(tip, XFS_IOLOCK_EXCL); | 240 | xfs_iunlock(tip, XFS_IOLOCK_EXCL); |
244 | xfs_trans_cancel(tp, 0); | 241 | xfs_trans_cancel(tp, 0); |
245 | locked = 0; | 242 | goto out; |
246 | goto error0; | ||
247 | } | 243 | } |
248 | xfs_lock_two_inodes(ip, tip, XFS_ILOCK_EXCL); | 244 | xfs_lock_two_inodes(ip, tip, XFS_ILOCK_EXCL); |
249 | 245 | ||
@@ -253,19 +249,15 @@ xfs_swap_extents( | |||
253 | if ( ((XFS_IFORK_Q(ip) != 0) && (ip->i_d.di_anextents > 0)) && | 249 | if ( ((XFS_IFORK_Q(ip) != 0) && (ip->i_d.di_anextents > 0)) && |
254 | (ip->i_d.di_aformat != XFS_DINODE_FMT_LOCAL)) { | 250 | (ip->i_d.di_aformat != XFS_DINODE_FMT_LOCAL)) { |
255 | error = xfs_bmap_count_blocks(tp, ip, XFS_ATTR_FORK, &aforkblks); | 251 | error = xfs_bmap_count_blocks(tp, ip, XFS_ATTR_FORK, &aforkblks); |
256 | if (error) { | 252 | if (error) |
257 | xfs_trans_cancel(tp, 0); | 253 | goto out_trans_cancel; |
258 | goto error0; | ||
259 | } | ||
260 | } | 254 | } |
261 | if ( ((XFS_IFORK_Q(tip) != 0) && (tip->i_d.di_anextents > 0)) && | 255 | if ( ((XFS_IFORK_Q(tip) != 0) && (tip->i_d.di_anextents > 0)) && |
262 | (tip->i_d.di_aformat != XFS_DINODE_FMT_LOCAL)) { | 256 | (tip->i_d.di_aformat != XFS_DINODE_FMT_LOCAL)) { |
263 | error = xfs_bmap_count_blocks(tp, tip, XFS_ATTR_FORK, | 257 | error = xfs_bmap_count_blocks(tp, tip, XFS_ATTR_FORK, |
264 | &taforkblks); | 258 | &taforkblks); |
265 | if (error) { | 259 | if (error) |
266 | xfs_trans_cancel(tp, 0); | 260 | goto out_trans_cancel; |
267 | goto error0; | ||
268 | } | ||
269 | } | 261 | } |
270 | 262 | ||
271 | /* | 263 | /* |
@@ -332,10 +324,10 @@ xfs_swap_extents( | |||
332 | 324 | ||
333 | 325 | ||
334 | IHOLD(ip); | 326 | IHOLD(ip); |
335 | xfs_trans_ijoin(tp, ip, lock_flags); | 327 | xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL); |
336 | 328 | ||
337 | IHOLD(tip); | 329 | IHOLD(tip); |
338 | xfs_trans_ijoin(tp, tip, lock_flags); | 330 | xfs_trans_ijoin(tp, tip, XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL); |
339 | 331 | ||
340 | xfs_trans_log_inode(tp, ip, ilf_fields); | 332 | xfs_trans_log_inode(tp, ip, ilf_fields); |
341 | xfs_trans_log_inode(tp, tip, tilf_fields); | 333 | xfs_trans_log_inode(tp, tip, tilf_fields); |
@@ -344,19 +336,19 @@ xfs_swap_extents( | |||
344 | * If this is a synchronous mount, make sure that the | 336 | * If this is a synchronous mount, make sure that the |
345 | * transaction goes to disk before returning to the user. | 337 | * transaction goes to disk before returning to the user. |
346 | */ | 338 | */ |
347 | if (mp->m_flags & XFS_MOUNT_WSYNC) { | 339 | if (mp->m_flags & XFS_MOUNT_WSYNC) |
348 | xfs_trans_set_sync(tp); | 340 | xfs_trans_set_sync(tp); |
349 | } | ||
350 | 341 | ||
351 | error = xfs_trans_commit(tp, XFS_TRANS_SWAPEXT); | 342 | error = xfs_trans_commit(tp, XFS_TRANS_SWAPEXT); |
352 | locked = 0; | ||
353 | 343 | ||
354 | error0: | 344 | out_unlock: |
355 | if (locked) { | 345 | xfs_iunlock(ip, XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL); |
356 | xfs_iunlock(ip, lock_flags); | 346 | xfs_iunlock(tip, XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL); |
357 | xfs_iunlock(tip, lock_flags); | 347 | out: |
358 | } | 348 | kmem_free(tempifp); |
359 | if (tempifp != NULL) | ||
360 | kmem_free(tempifp); | ||
361 | return error; | 349 | return error; |
350 | |||
351 | out_trans_cancel: | ||
352 | xfs_trans_cancel(tp, 0); | ||
353 | goto out_unlock; | ||
362 | } | 354 | } |