From: Edmund Nadolski <enadolski@suse.de>
To: Nikolay Borisov <nborisov@suse.com>, dsterba@suse.cz
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH v4] btrfs: Fix transaction abort during failure in btrfs_rm_dev_item
Date: Mon, 23 Oct 2017 10:29:27 -0600 [thread overview]
Message-ID: <7f2a3c59-818f-c7dd-de6a-7db8f9e8d818@suse.de> (raw)
In-Reply-To: <1508741926-27125-1-git-send-email-nborisov@suse.com>
On 10/23/2017 12:58 AM, Nikolay Borisov wrote:
> btrfs_rm_dev_item calls several function under an activa transaction, however
^^
active
> it fails to abort it if an error happens. Fix this by adding explicit
> btrfs_abort_transaction/btrfs_end_transaction calls
>
> Signed-off-by: Nikolay Borisov <nborisov@suse.com>
> ---
> V4:
> * Reorder the code a bit to prevent duplication of btrfs_free_path
> invocation.
>
> * Collapse the handling of btrfs_search_slot return value in a single if
> branch rather than having it spread across 2 branches
>
> V3:
> * The path needs to be freed before the the transaction is comitted otherwise
> we will deadlock.
> fs/btrfs/volumes.c | 20 ++++++++++++--------
> 1 file changed, 12 insertions(+), 8 deletions(-)
>
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index 0e8f16c305df..8b139d203f8c 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -1765,20 +1765,24 @@ static int btrfs_rm_dev_item(struct btrfs_fs_info *fs_info,
> key.offset = device->devid;
>
> ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
> - if (ret < 0)
> - goto out;
> -
> - if (ret > 0) {
> - ret = -ENOENT;
> + if (ret) {
> + if (ret > 0)
> + ret = -ENOENT;
> + btrfs_abort_transaction(trans, ret);
> + btrfs_end_transaction(trans);
> goto out;
> }
>
> ret = btrfs_del_item(trans, root, path);
> - if (ret)
> - goto out;
> + if (ret) {
> + btrfs_abort_transaction(trans, ret);
> + btrfs_end_transaction(trans);
> + }
> +
> out:
> btrfs_free_path(path);
> - btrfs_commit_transaction(trans);
> + if (!ret)
> + ret = btrfs_commit_transaction(trans);
> return ret;
> }
>
>
Perhaps slightly simpler (and the 'out:' label maybe goes away):
.....
ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
if (ret > 0)
ret = -ENOENT;
else if (!ret)
ret = btrfs_del_item(trans, root, path);
if (ret) {
btrfs_abort_transaction(trans, ret);
btrfs_end_transaction(trans);
}
out:
.....
Ed
next prev parent reply other threads:[~2017-10-23 16:29 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-27 10:48 [PATCH 0/3] Few transaction semantic fixes Nikolay Borisov
2017-09-27 10:48 ` [PATCH 1/3] btrfs: Remove unnecessary btrfs_abort_transaction on transaction commit failure Nikolay Borisov
2017-09-27 10:48 ` [PATCH 2/3] btrfs: Handle failure to add to add received uuid to uuid tree in _btrfs_ioctl_set_received_subvol Nikolay Borisov
2017-09-27 10:48 ` [PATCH 3/3] btrfs: Fix transaction abort during failure in btrfs_rm_dev_item Nikolay Borisov
2017-09-28 8:45 ` [PATCH v2 1/2] btrfs: Refactor transaction handling Nikolay Borisov
2017-09-28 8:45 ` [PATCH v2 2/2] btrfs: Fix transaction abort during failure in btrfs_rm_dev_item Nikolay Borisov
2017-10-06 16:14 ` David Sterba
2017-10-19 11:54 ` David Sterba
2017-10-19 13:26 ` Nikolay Borisov
2017-10-20 6:30 ` [PATCH v3] " Nikolay Borisov
2017-10-23 6:58 ` [PATCH v4] " Nikolay Borisov
2017-10-23 16:29 ` Edmund Nadolski [this message]
2017-10-30 15:02 ` David Sterba
2017-10-06 16:11 ` [PATCH v2 1/2] btrfs: Refactor transaction handling 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=7f2a3c59-818f-c7dd-de6a-7db8f9e8d818@suse.de \
--to=enadolski@suse.de \
--cc=dsterba@suse.cz \
--cc=linux-btrfs@vger.kernel.org \
--cc=nborisov@suse.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;
as well as URLs for NNTP newsgroup(s).