From: "Josef 'Jeff' Sipek" <jeffpc@josefsipek.net>
To: Christoph Hellwig <hch@infradead.org>
Cc: xfs@oss.sgi.com
Subject: [PATCH] xfs: cleanup error handling in xfs_swap_extents
Date: Mon, 26 Jan 2009 19:27:40 -0500 [thread overview]
Message-ID: <20090127002739.GO5587@josefsipek.net> (raw)
In-Reply-To: <20090126075552.GA1062@infradead.org>
From: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
Use multiple lables for proper error unwinding and get rid of some now
superflous variables.
Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
Tested-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Felix Blyakher <felixb@sgi.com>
---
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 75b0cd4..ec832bc 100644
--- a/fs/xfs/xfs_dfrag.c
+++ b/fs/xfs/xfs_dfrag.c
@@ -132,19 +132,17 @@ xfs_swap_extents(
xfs_bstat_t *sbp = &sxp->sx_stat;
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;
+ goto out;
}
sbp = &sxp->sx_stat;
@@ -157,25 +155,24 @@ xfs_swap_extents(
*/
xfs_lock_two_inodes(ip, tip, XFS_IOLOCK_EXCL);
xfs_lock_two_inodes(ip, tip, XFS_ILOCK_EXCL);
- locked = 1;
/* Verify that both files have the same format */
if ((ip->i_d.di_mode & S_IFMT) != (tip->i_d.di_mode & S_IFMT)) {
error = XFS_ERROR(EINVAL);
- goto error0;
+ goto out_unlock;
}
/* Verify both files are either real-time or non-realtime */
if (XFS_IS_REALTIME_INODE(ip) != XFS_IS_REALTIME_INODE(tip)) {
error = XFS_ERROR(EINVAL);
- goto error0;
+ goto out_unlock;
}
/* Should never get a local format */
if (ip->i_d.di_format == XFS_DINODE_FMT_LOCAL ||
tip->i_d.di_format == XFS_DINODE_FMT_LOCAL) {
error = XFS_ERROR(EINVAL);
- goto error0;
+ goto out_unlock;
}
if (VN_CACHED(VFS_I(tip)) != 0) {
@@ -183,13 +180,13 @@ xfs_swap_extents(
error = xfs_flushinval_pages(tip, 0, -1,
FI_REMAPF_LOCKED);
if (error)
- goto error0;
+ goto out_unlock;
}
/* Verify O_DIRECT for ftmp */
if (VN_CACHED(VFS_I(tip)) != 0) {
error = XFS_ERROR(EINVAL);
- goto error0;
+ goto out_unlock;
}
/* Verify all data are being swapped */
@@ -197,7 +194,7 @@ xfs_swap_extents(
sxp->sx_length != ip->i_d.di_size ||
sxp->sx_length != tip->i_d.di_size) {
error = XFS_ERROR(EFAULT);
- goto error0;
+ goto out_unlock;
}
/*
@@ -207,7 +204,7 @@ xfs_swap_extents(
*/
if ( XFS_IFORK_Q(ip) != XFS_IFORK_Q(tip) ) {
error = XFS_ERROR(EINVAL);
- goto error0;
+ goto out_unlock;
}
/*
@@ -222,7 +219,7 @@ xfs_swap_extents(
(sbp->bs_mtime.tv_sec != ip->i_d.di_mtime.t_sec) ||
(sbp->bs_mtime.tv_nsec != ip->i_d.di_mtime.t_nsec)) {
error = XFS_ERROR(EBUSY);
- goto error0;
+ goto out_unlock;
}
/* We need to fail if the file is memory mapped. Once we have tossed
@@ -233,7 +230,7 @@ xfs_swap_extents(
*/
if (VN_MAPPED(VFS_I(ip))) {
error = XFS_ERROR(EBUSY);
- goto error0;
+ goto out_unlock;
}
xfs_iunlock(ip, XFS_ILOCK_EXCL);
@@ -256,8 +253,7 @@ xfs_swap_extents(
xfs_iunlock(ip, XFS_IOLOCK_EXCL);
xfs_iunlock(tip, XFS_IOLOCK_EXCL);
xfs_trans_cancel(tp, 0);
- locked = 0;
- goto error0;
+ goto out;
}
xfs_lock_two_inodes(ip, tip, XFS_ILOCK_EXCL);
@@ -267,19 +263,15 @@ xfs_swap_extents(
if ( ((XFS_IFORK_Q(ip) != 0) && (ip->i_d.di_anextents > 0)) &&
(ip->i_d.di_aformat != XFS_DINODE_FMT_LOCAL)) {
error = xfs_bmap_count_blocks(tp, ip, XFS_ATTR_FORK, &aforkblks);
- if (error) {
- xfs_trans_cancel(tp, 0);
- goto error0;
- }
+ if (error)
+ goto out_trans_cancel;
}
if ( ((XFS_IFORK_Q(tip) != 0) && (tip->i_d.di_anextents > 0)) &&
(tip->i_d.di_aformat != XFS_DINODE_FMT_LOCAL)) {
error = xfs_bmap_count_blocks(tp, tip, XFS_ATTR_FORK,
&taforkblks);
- if (error) {
- xfs_trans_cancel(tp, 0);
- goto error0;
- }
+ if (error)
+ goto out_trans_cancel;
}
/*
@@ -346,10 +338,10 @@ xfs_swap_extents(
IHOLD(ip);
- xfs_trans_ijoin(tp, ip, lock_flags);
+ xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL);
IHOLD(tip);
- xfs_trans_ijoin(tp, tip, lock_flags);
+ xfs_trans_ijoin(tp, tip, XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL);
xfs_trans_log_inode(tp, ip, ilf_fields);
xfs_trans_log_inode(tp, tip, tilf_fields);
@@ -358,19 +350,19 @@ xfs_swap_extents(
* If this is a synchronous mount, make sure that the
* transaction goes to disk before returning to the user.
*/
- if (mp->m_flags & XFS_MOUNT_WSYNC) {
+ if (mp->m_flags & XFS_MOUNT_WSYNC)
xfs_trans_set_sync(tp);
- }
error = xfs_trans_commit(tp, XFS_TRANS_SWAPEXT);
- locked = 0;
- error0:
- if (locked) {
- xfs_iunlock(ip, lock_flags);
- xfs_iunlock(tip, lock_flags);
- }
- if (tempifp != NULL)
- kmem_free(tempifp);
+out_unlock:
+ xfs_iunlock(ip, XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL);
+ xfs_iunlock(tip, XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL);
+out:
+ kmem_free(tempifp);
return error;
+
+out_trans_cancel:
+ xfs_trans_cancel(tp, 0);
+ goto out_unlock;
}
--
1.5.6.5
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
next prev parent reply other threads:[~2009-01-27 0:28 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-26 7:31 [PATCH 00/17] 2.6.30 queue Christoph Hellwig
2009-01-26 7:31 ` [PATCH 01/17] xfs: cleanup error handling in xfs_mountfs: Christoph Hellwig
2009-01-26 21:39 ` Felix Blyakher
2009-01-26 7:31 ` [PATCH 02/17] xfs: make sure to free the real-time inodes in the mount error path Christoph Hellwig
2009-01-26 22:02 ` Felix Blyakher
2009-01-28 20:24 ` Martin Steigerwald
2009-01-26 7:31 ` [PATCH 03/17] xfs: cleanup handling in xfs_swap_extents Christoph Hellwig
2009-01-26 7:55 ` Christoph Hellwig
2009-01-27 0:27 ` Josef 'Jeff' Sipek [this message]
2009-01-28 20:25 ` [PATCH] xfs: cleanup error " Martin Steigerwald
2009-01-26 22:13 ` [PATCH 03/17] xfs: cleanup " Felix Blyakher
2009-05-08 0:45 ` Eric Sandeen
2009-01-26 7:31 ` [PATCH 04/17] xfs: tiny cleanup for xfs_link Christoph Hellwig
2009-01-26 22:23 ` Felix Blyakher
2009-01-26 7:31 ` [PATCH 05/17] xfs: remove unused XFS_MOUNT_ILOCK/XFS_MOUNT_IUNLOCK Christoph Hellwig
2009-01-26 23:43 ` Felix Blyakher
2009-01-26 7:31 ` [PATCH 06/17] xfs: remove iclog calculation special cases Christoph Hellwig
2009-02-09 2:15 ` Dave Chinner
2009-01-26 7:31 ` [PATCH 07/17] xfs: remove superflous inobt macros Christoph Hellwig
2009-02-09 2:16 ` Dave Chinner
2009-01-26 7:31 ` [PATCH 08/17] xfs: remove uchar_t/ushort_t/uint_t/ulong_t types Christoph Hellwig
2009-02-09 2:18 ` Dave Chinner
2009-01-26 7:31 ` [PATCH 09/17] xfs: cleanup xfs_find_handle Christoph Hellwig
2009-02-06 5:20 ` Felix Blyakher
2009-02-06 7:17 ` Christoph Hellwig
2009-02-06 20:31 ` Felix Blyakher
2009-01-26 7:31 ` [PATCH 10/17] xfs: factor out attr fork reset handling Christoph Hellwig
2009-01-27 16:53 ` Felix Blyakher
2009-01-26 7:31 ` [PATCH 11/17] xfs: merge xfs_inode_flush into xfs_fs_write_inode Christoph Hellwig
2009-01-27 17:37 ` Felix Blyakher
2009-02-01 0:54 ` Dave Chinner
2009-02-15 6:42 ` Dave Chinner
2009-02-15 20:13 ` Christoph Hellwig
2009-02-16 3:06 ` Dave Chinner
2009-01-26 7:31 ` [PATCH 12/17] xfs: merge xfs_mkdir into xfs_create Christoph Hellwig
2009-02-09 2:28 ` Dave Chinner
2009-01-26 7:31 ` [PATCH 13/17] xfs: get rid of indirections in the quotaops implementation Christoph Hellwig
2009-02-09 2:41 ` Dave Chinner
2009-02-09 7:46 ` Christoph Hellwig
2009-05-13 8:11 ` Christoph Hellwig
2009-01-26 7:31 ` [PATCH 14/17] xfs: remove the unused XFS_QMOPT_DQLOCK flag Christoph Hellwig
2009-02-08 0:35 ` Felix Blyakher
2009-01-26 7:31 ` [PATCH 15/17] xfs: remove XFS_QM_LOCK/XFS_QM_UNLOCK/XFS_QM_HOLD/XFS_QM_RELE Christoph Hellwig
2009-02-09 2:42 ` Dave Chinner
2009-01-26 7:31 ` [PATCH 16/17] xfs: use mutex_is_locked in XFS_DQ_IS_LOCKED Christoph Hellwig
2009-02-09 2:42 ` Dave Chinner
2009-01-26 7:31 ` [PATCH 17/17] xfs: sanitize qh_lock wrappers Christoph Hellwig
2009-02-09 2:45 ` Dave Chinner
2009-02-04 19:37 ` [PATCH 00/17] 2.6.30 queue Christoph Hellwig
2009-02-08 21:12 ` Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090127002739.GO5587@josefsipek.net \
--to=jeffpc@josefsipek.net \
--cc=hch@infradead.org \
--cc=xfs@oss.sgi.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox