From: David Sterba <dsterba@suse.cz>
To: Anand Jain <anand.jain@oracle.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 7/7] btrfs: add helper function check device delete able
Date: Thu, 19 Jul 2018 13:45:46 +0200 [thread overview]
Message-ID: <20180719114546.GH26141@twin.jikos.cz> (raw)
In-Reply-To: <20180716145812.20836-8-anand.jain@oracle.com>
On Mon, Jul 16, 2018 at 10:58:12PM +0800, Anand Jain wrote:
> Move the section of the code which performs the check if the device is
> indelible, move that into a helper function.
>
> Signed-off-by: Anand Jain <anand.jain@oracle.com>
> ---
> v1->v2: Rename function to btrfs_get_device_for_delete(), thanks
> Nikolay.
>
> fs/btrfs/volumes.c | 49 ++++++++++++++++++++++++++++++-------------------
> 1 file changed, 30 insertions(+), 19 deletions(-)
>
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index 1c0b56374992..0cefc24b028c 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -1859,6 +1859,33 @@ static inline u64 btrfs_num_devices(struct btrfs_fs_info *fs_info)
> return num_devices;
> }
>
> +static struct btrfs_device *btrfs_get_device_for_delete(
> + struct btrfs_fs_info *fs_info,
> + const char *device_path, u64 devid)
> +{
> + int ret;
> + struct btrfs_device *device;
> +
> + ret = btrfs_check_raid_min_devices(fs_info,
> + btrfs_num_devices(fs_info) - 1);
> + if (ret)
> + return ERR_PTR(ret);
> +
> + ret = btrfs_find_device_by_devspec(fs_info, devid, device_path,
> + &device);
> + if (ret)
> + return ERR_PTR(ret);
> +
> + if (test_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state))
> + return ERR_PTR(BTRFS_ERROR_DEV_TGT_REPLACE);
This is wrong, the BTRFS_ERROR valueas are >= 1, but the IS_ERR, ERR_PTR
work for errno values -4095..0 .
Thouth ERR_PTR would cast the integer into pointer, the callers of
btrfs_get_device_for_delete will not detect the error and continue.
> +
> + if (test_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state) &&
> + fs_info->fs_devices->rw_devices == 1)
> + return ERR_PTR(BTRFS_ERROR_DEV_ONLY_WRITABLE);
> +
> + return device;
> +}
> +
> int btrfs_rm_device(struct btrfs_fs_info *fs_info, const char *device_path,
> u64 devid)
> {
> @@ -1872,25 +1899,9 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info, const char *device_path,
>
> mutex_lock(&uuid_mutex);
>
> - num_devices = btrfs_num_devices(fs_info);
> -
> - ret = btrfs_check_raid_min_devices(fs_info, num_devices - 1);
> - if (ret)
> - goto out;
> -
> - ret = btrfs_find_device_by_devspec(fs_info, devid, device_path,
> - &device);
> - if (ret)
> - goto out;
> -
> - if (test_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state)) {
> - ret = BTRFS_ERROR_DEV_TGT_REPLACE;
> - goto out;
> - }
> -
> - if (test_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state) &&
> - fs_info->fs_devices->rw_devices == 1) {
> - ret = BTRFS_ERROR_DEV_ONLY_WRITABLE;
> + device = btrfs_get_device_for_delete(fs_info, device_path, devid);
> + if (IS_ERR(device)) {
BTRFS_ERROR_DEV_ONLY_WRITABLE won't work here.
> + ret = PTR_ERR(device);
> goto out;
> }
>
> --
> 2.7.0
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2018-07-19 12:28 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-16 14:58 [PATCH 0/7] Misc volume patch set part2 Anand Jain
2018-07-16 14:58 ` [PATCH v4 1/7] btrfs: drop uuid_mutex in btrfs_free_extra_devids() Anand Jain
2018-07-16 14:58 ` [PATCH v2 2/7] btrfs: fix race between free_stale_devices and close_fs_devices Anand Jain
2018-07-16 14:58 ` [PATCH 3/7] btrfs: do device clone using the btrfs_scan_one_device Anand Jain
2018-07-19 12:31 ` David Sterba
2018-07-20 6:35 ` Anand Jain
2018-07-20 7:13 ` Anand Jain
2018-07-16 14:58 ` [PATCH 4/7] btrfs: use the assigned fs_devices instead of the dereference Anand Jain
2018-07-19 12:01 ` David Sterba
2018-07-16 14:58 ` [PATCH 5/7] btrfs: warn for num_devices below 0 Anand Jain
2018-07-23 14:01 ` David Sterba
2018-07-23 14:15 ` Anand Jain
2018-07-16 14:58 ` [PATCH 6/7] btrfs: add helper btrfs_num_devices() to deduce num_devices Anand Jain
2018-07-19 11:53 ` David Sterba
2018-07-20 1:41 ` Anand Jain
2018-07-20 11:18 ` Anand Jain
2018-07-23 13:57 ` David Sterba
2018-07-23 14:21 ` Anand Jain
2018-07-16 14:58 ` [PATCH 7/7] btrfs: add helper function check device delete able Anand Jain
2018-07-19 11:45 ` David Sterba [this message]
2018-07-20 1:34 ` Anand Jain
2018-07-20 11:22 ` Anand Jain
2018-07-16 15:27 ` [PATCH 0/7] Misc volume patch set part2 Anand Jain
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=20180719114546.GH26141@twin.jikos.cz \
--to=dsterba@suse.cz \
--cc=anand.jain@oracle.com \
--cc=linux-btrfs@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).