From: Jeff Mahoney <jeffm@suse.com>
To: SF Markus Elfring <elfring@users.sourceforge.net>,
linux-btrfs@vger.kernel.org, Chris Mason <clm@fb.com>,
David Sterba <dsterba@suse.com>, Josef Bacik <jbacik@fb.com>
Cc: LKML <linux-kernel@vger.kernel.org>, kernel-janitors@vger.kernel.org
Subject: Re: [PATCH 5/5] btrfs: Use common error handling code in btrfs_mark_extent_written()
Date: Mon, 21 Aug 2017 09:07:00 -0400 [thread overview]
Message-ID: <1cff718d-46db-d5cd-1cc4-f7e1d6e1ce2e@suse.com> (raw)
In-Reply-To: <93116379-7a82-733a-6957-4e01b3572d8f@users.sourceforge.net>
[-- Attachment #1.1: Type: text/plain, Size: 4419 bytes --]
On 8/21/17 8:42 AM, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Mon, 21 Aug 2017 14:15:23 +0200
>
> Add jump targets so that a bit of exception handling can be better reused
> at the end of this function.
>
> This issue was detected by using the Coccinelle software.
btrfs_abort_transaction dumps __FILE__:__LINE__ in the log so this patch
makes the code more difficult to debug.
-Jeff
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
> fs/btrfs/file.c | 62 ++++++++++++++++++++++-----------------------------------
> 1 file changed, 24 insertions(+), 38 deletions(-)
>
> diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
> index 74fd7756cff3..675683051cbc 100644
> --- a/fs/btrfs/file.c
> +++ b/fs/btrfs/file.c
> @@ -1122,25 +1122,17 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
>
> leaf = path->nodes[0];
> btrfs_item_key_to_cpu(leaf, &key, path->slots[0]);
> - if (key.objectid != ino ||
> - key.type != BTRFS_EXTENT_DATA_KEY) {
> - ret = -EINVAL;
> - btrfs_abort_transaction(trans, ret);
> - goto out;
> - }
> + if (key.objectid != ino || key.type != BTRFS_EXTENT_DATA_KEY)
> + goto e_inval;
> +
> fi = btrfs_item_ptr(leaf, path->slots[0],
> struct btrfs_file_extent_item);
> - if (btrfs_file_extent_type(leaf, fi) != BTRFS_FILE_EXTENT_PREALLOC) {
> - ret = -EINVAL;
> - btrfs_abort_transaction(trans, ret);
> - goto out;
> - }
> + if (btrfs_file_extent_type(leaf, fi) != BTRFS_FILE_EXTENT_PREALLOC)
> + goto e_inval;
> +
> extent_end = key.offset + btrfs_file_extent_num_bytes(leaf, fi);
> - if (key.offset > start || extent_end < end) {
> - ret = -EINVAL;
> - btrfs_abort_transaction(trans, ret);
> - goto out;
> - }
> + if (key.offset > start || extent_end < end)
> + goto e_inval;
>
> bytenr = btrfs_file_extent_disk_bytenr(leaf, fi);
> num_bytes = btrfs_file_extent_disk_num_bytes(leaf, fi);
> @@ -1213,10 +1205,8 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
> btrfs_release_path(path);
> goto again;
> }
> - if (ret < 0) {
> - btrfs_abort_transaction(trans, ret);
> - goto out;
> - }
> + if (ret < 0)
> + goto abort_transaction;
>
> leaf = path->nodes[0];
> fi = btrfs_item_ptr(leaf, path->slots[0] - 1,
> @@ -1237,18 +1227,15 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
> ret = btrfs_inc_extent_ref(trans, fs_info, bytenr, num_bytes,
> 0, root->root_key.objectid,
> ino, orig_offset);
> - if (ret) {
> - btrfs_abort_transaction(trans, ret);
> - goto out;
> - }
> + if (ret)
> + goto abort_transaction;
>
> if (split == start) {
> key.offset = start;
> } else {
> if (start != key.offset) {
> ret = -EINVAL;
> - btrfs_abort_transaction(trans, ret);
> - goto out;
> + goto abort_transaction;
> }
> path->slots[0]--;
> extent_end = end;
> @@ -1271,10 +1258,8 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
> ret = btrfs_free_extent(trans, fs_info, bytenr, num_bytes,
> 0, root->root_key.objectid,
> ino, orig_offset);
> - if (ret) {
> - btrfs_abort_transaction(trans, ret);
> - goto out;
> - }
> + if (ret)
> + goto abort_transaction;
> }
> other_start = 0;
> other_end = start;
> @@ -1291,10 +1276,8 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
> ret = btrfs_free_extent(trans, fs_info, bytenr, num_bytes,
> 0, root->root_key.objectid,
> ino, orig_offset);
> - if (ret) {
> - btrfs_abort_transaction(trans, ret);
> - goto out;
> - }
> + if (ret)
> + goto abort_transaction;
> }
> if (del_nr == 0) {
> fi = btrfs_item_ptr(leaf, path->slots[0],
> @@ -1314,14 +1297,17 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
> btrfs_mark_buffer_dirty(leaf);
>
> ret = btrfs_del_items(trans, root, path, del_slot, del_nr);
> - if (ret < 0) {
> - btrfs_abort_transaction(trans, ret);
> - goto out;
> - }
> + if (ret < 0)
> + goto abort_transaction;
> }
> out:
> btrfs_free_path(path);
> return 0;
> +e_inval:
> + ret = -EINVAL;
> +abort_transaction:
> + btrfs_abort_transaction(trans, ret);
> + goto out;
> }
>
> /*
>
--
Jeff Mahoney
SUSE Labs
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
next prev parent reply other threads:[~2017-08-21 13:07 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-21 12:35 [PATCH 0/5] BTRFS: Fine-tuning for five function implementations SF Markus Elfring
2017-08-21 12:37 ` [PATCH 1/5] btrfs: Use common error handling code in tree_mod_log_eb_copy() SF Markus Elfring
2017-08-21 12:38 ` [PATCH 2/5] btrfs: Use common error handling code in __btrfs_free_extent() SF Markus Elfring
2017-08-21 13:07 ` Jeff Mahoney
2017-08-21 13:14 ` Dan Carpenter
2017-08-21 12:40 ` [PATCH 3/5] btrfs: Use common error handling code in btrfs_update_root() SF Markus Elfring
2017-08-21 13:09 ` Jeff Mahoney
2017-08-21 12:41 ` [PATCH 4/5] btrfs: Use common error handling code in update_ref_path() SF Markus Elfring
2017-08-21 13:08 ` Jeff Mahoney
2017-08-21 13:42 ` Dan Carpenter
2017-08-21 13:52 ` [PATCH v2] " SF Markus Elfring
2017-08-21 12:42 ` [PATCH 5/5] btrfs: Use common error handling code in btrfs_mark_extent_written() SF Markus Elfring
2017-08-21 13:07 ` Jeff Mahoney [this message]
2017-08-21 13:24 ` [PATCH 0/5] BTRFS: Fine-tuning for five function implementations David Sterba
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=1cff718d-46db-d5cd-1cc4-f7e1d6e1ce2e@suse.com \
--to=jeffm@suse.com \
--cc=clm@fb.com \
--cc=dsterba@suse.com \
--cc=elfring@users.sourceforge.net \
--cc=jbacik@fb.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).