From: Anand Jain <anand.jain@oracle.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 6/6] btrfs: refactor btrfs_find_device() return error code
Date: Thu, 17 Jan 2019 23:32:33 +0800 [thread overview]
Message-ID: <1547739153-6916-7-git-send-email-anand.jain@oracle.com> (raw)
In-Reply-To: <1547739153-6916-1-git-send-email-anand.jain@oracle.com>
Refactor btrfs_find_device() to return standard error code.
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
fs/btrfs/dev-replace.c | 4 ++--
fs/btrfs/ioctl.c | 4 ++--
fs/btrfs/scrub.c | 12 ++++++++----
fs/btrfs/volumes.c | 32 +++++++++++++-------------------
4 files changed, 25 insertions(+), 27 deletions(-)
diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
index b5897becd542..23cef72a5a87 100644
--- a/fs/btrfs/dev-replace.c
+++ b/fs/btrfs/dev-replace.c
@@ -120,7 +120,7 @@ int btrfs_init_dev_replace(struct btrfs_fs_info *fs_info)
* allow 'btrfs dev replace_cancel' if src/tgt device is
* missing
*/
- if (!dev_replace->srcdev &&
+ if (PTR_ERR(dev_replace->srcdev) == -ENOENT &&
!btrfs_test_opt(fs_info, DEGRADED)) {
ret = -EIO;
btrfs_warn(fs_info,
@@ -129,7 +129,7 @@ int btrfs_init_dev_replace(struct btrfs_fs_info *fs_info)
"srcdev (devid %llu) is missing, need to run 'btrfs dev scan'?",
src_devid);
}
- if (!dev_replace->tgtdev &&
+ if (PTR_ERR(dev_replace->tgtdev) == -ENOENT &&
!btrfs_test_opt(fs_info, DEGRADED)) {
ret = -EIO;
btrfs_warn(fs_info,
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 66f2f9e229d5..71243025b324 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -1643,7 +1643,7 @@ static noinline int btrfs_ioctl_resize(struct file *file,
}
device = btrfs_find_device(fs_info->fs_devices, devid, NULL, NULL, 0);
- if (!device) {
+ if (PTR_ERR(device) == -ENOENT) {
btrfs_info(fs_info, "resizer unable to find device %llu",
devid);
ret = -ENODEV;
@@ -3181,7 +3181,7 @@ static long btrfs_ioctl_dev_info(struct btrfs_fs_info *fs_info,
dev = btrfs_find_device(fs_info->fs_devices, di_args->devid, s_uuid,
NULL, 0);
- if (!dev) {
+ if (PTR_ERR(dev) == -ENOENT) {
ret = -ENODEV;
goto out;
}
diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index 477c585927e4..c8029628282a 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -3836,8 +3836,9 @@ int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start,
mutex_lock(&fs_info->fs_devices->device_list_mutex);
dev = btrfs_find_device(fs_info->fs_devices, devid, NULL, NULL, 0);
- if (!dev || (test_bit(BTRFS_DEV_STATE_MISSING, &dev->dev_state) &&
- !is_dev_replace)) {
+ if (PTR_ERR(dev) == -ENOENT ||
+ (test_bit(BTRFS_DEV_STATE_MISSING, &dev->dev_state) &&
+ !is_dev_replace)) {
mutex_unlock(&fs_info->fs_devices->device_list_mutex);
ret = -ENODEV;
goto out_free_ctx;
@@ -4013,13 +4014,16 @@ int btrfs_scrub_progress(struct btrfs_fs_info *fs_info, u64 devid,
mutex_lock(&fs_info->fs_devices->device_list_mutex);
dev = btrfs_find_device(fs_info->fs_devices, devid, NULL, NULL, 0);
- if (dev)
+ if (PTR_ERR(dev) != -ENOENT)
sctx = dev->scrub_ctx;
if (sctx)
memcpy(progress, &sctx->stat, sizeof(*progress));
mutex_unlock(&fs_info->fs_devices->device_list_mutex);
- return dev ? (sctx ? 0 : -ENOTCONN) : -ENODEV;
+ if (PTR_ERR(dev) == -ENOENT)
+ return -ENODEV;
+ else
+ return sctx ? 0 : -ENOTCONN;
}
static void scrub_remap_extent(struct btrfs_fs_info *fs_info,
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 7f89c8b1cab1..5a3846daabcf 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -966,7 +966,7 @@ static noinline struct btrfs_device *device_list_add(const char *path,
mutex_lock(&fs_devices->device_list_mutex);
list_add(&fs_devices->fs_list, &fs_uuids);
- device = NULL;
+ device = ERR_PTR(-ENOENT);
} else {
mutex_lock(&fs_devices->device_list_mutex);
device = btrfs_find_device(fs_devices, devid,
@@ -988,7 +988,7 @@ static noinline struct btrfs_device *device_list_add(const char *path,
}
}
- if (!device) {
+ if (PTR_ERR(device) == -ENOENT) {
if (fs_devices->opened) {
mutex_unlock(&fs_devices->device_list_mutex);
return ERR_PTR(-EBUSY);
@@ -2404,8 +2404,6 @@ static struct btrfs_device *find_device_by_superblock(
disk_super->fsid, 0);
brelse(bh);
- if (!device)
- device = ERR_PTR(-ENOENT);
blkdev_put(bdev, FMODE_READ);
return device;
}
@@ -2419,13 +2417,9 @@ struct btrfs_device *btrfs_find_device_by_devspec(
{
struct btrfs_device *device;
- if (devid) {
- device = btrfs_find_device(fs_info->fs_devices, devid, NULL,
- NULL, 0);
- if (!device)
- return ERR_PTR(-ENOENT);
- return device;
- }
+ if (devid)
+ return btrfs_find_device(fs_info->fs_devices, devid, NULL,
+ NULL, 0);
if (!device_path || !device_path[0])
return ERR_PTR(-EINVAL);
@@ -2564,7 +2558,7 @@ static int btrfs_finish_sprout(struct btrfs_trans_handle *trans,
BTRFS_FSID_SIZE);
device = btrfs_find_device(fs_info->fs_devices, devid, dev_uuid,
fs_uuid, 0);
- BUG_ON(!device); /* Logic error */
+ BUG_ON(PTR_ERR(device) == -ENOENT); /* Logic error */
if (device->fs_devices->seeding) {
btrfs_set_device_generation(leaf, dev_item,
@@ -6643,11 +6637,11 @@ struct btrfs_device *btrfs_find_device(struct btrfs_fs_devices *fs_devices,
}
}
if (no_seed)
- return NULL;
+ return ERR_PTR(-ENOENT);
else
fs_devices = fs_devices->seed;
}
- return NULL;
+ return ERR_PTR(-ENOENT);
}
static struct btrfs_device *add_missing_dev(struct btrfs_fs_devices *fs_devices,
@@ -6892,13 +6886,13 @@ static int read_one_chunk(struct btrfs_fs_info *fs_info, struct btrfs_key *key,
BTRFS_UUID_SIZE);
map->stripes[i].dev = btrfs_find_device(fs_info->fs_devices,
devid, uuid, NULL, 0);
- if (!map->stripes[i].dev &&
+ if (PTR_ERR(map->stripes[i].dev) == -ENOENT &&
!btrfs_test_opt(fs_info, DEGRADED)) {
free_extent_map(em);
btrfs_report_missing_device(fs_info, devid, uuid, true);
return -ENOENT;
}
- if (!map->stripes[i].dev) {
+ if (PTR_ERR(map->stripes[i].dev) == -ENOENT) {
map->stripes[i].dev =
add_missing_dev(fs_info->fs_devices, devid,
uuid);
@@ -7032,7 +7026,7 @@ static int read_one_dev(struct btrfs_fs_info *fs_info,
device = btrfs_find_device(fs_info->fs_devices, devid, dev_uuid,
fs_uuid, 0);
- if (!device) {
+ if (PTR_ERR(device) == -ENOENT) {
if (!btrfs_test_opt(fs_info, DEGRADED)) {
btrfs_report_missing_device(fs_info, devid,
dev_uuid, true);
@@ -7625,7 +7619,7 @@ int btrfs_get_dev_stats(struct btrfs_fs_info *fs_info,
0);
mutex_unlock(&fs_devices->device_list_mutex);
- if (!dev) {
+ if (PTR_ERR(dev) == -ENOENT) {
btrfs_warn(fs_info, "get dev_stats failed, device not found");
return -ENODEV;
} else if (!dev->dev_stats_valid) {
@@ -7837,7 +7831,7 @@ static int verify_one_dev_extent(struct btrfs_fs_info *fs_info,
/* Make sure no dev extent is beyond device bondary */
dev = btrfs_find_device(fs_info->fs_devices, devid, NULL, NULL, 0);
- if (!dev) {
+ if (PTR_ERR(dev) == -ENOENT) {
btrfs_err(fs_info, "failed to find devid %llu", devid);
ret = -EUCLEAN;
goto out;
--
1.8.3.1
next prev parent reply other threads:[~2019-01-17 15:33 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-17 15:32 [PATCH 0/6] btrfs: find_device cleanups Anand Jain
2019-01-17 15:32 ` [PATCH 1/6] btrfs: merge btrfs_find_device_missing_or_by_path() into parent Anand Jain
2019-01-17 15:57 ` David Sterba
2019-01-17 15:32 ` [PATCH 2/6] btrfs: cleanup btrfs_find_device_by_devspec() Anand Jain
2019-01-17 15:57 ` David Sterba
2019-01-17 15:32 ` [PATCH 3/6] btrfs: rename btrfs_find_device_by_path() Anand Jain
2019-01-17 15:54 ` David Sterba
2019-01-18 6:13 ` Anand Jain
2019-01-18 17:05 ` David Sterba
2019-01-17 15:32 ` [PATCH 4/6] btrfs: refactor btrfs_find_device() take fs_devices as argument Anand Jain
2019-01-17 15:58 ` David Sterba
2019-01-17 15:32 ` [PATCH 5/6] btrfs: merge btrfs_find_device() and find_device() Anand Jain
2019-01-17 15:51 ` David Sterba
2019-01-19 6:48 ` [PATCH 5/6 v2] " Anand Jain
2019-01-23 5:28 ` Anand Jain
2019-01-28 18:44 ` David Sterba
2019-01-17 15:32 ` Anand Jain [this message]
2019-01-17 15:49 ` [PATCH 6/6] btrfs: refactor btrfs_find_device() return error code David Sterba
2019-01-18 6:13 ` Anand Jain
2019-01-18 17:20 ` David Sterba
2019-01-18 17:33 ` [PATCH 0/6] btrfs: find_device cleanups David Sterba
2019-01-19 6:54 ` 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=1547739153-6916-7-git-send-email-anand.jain@oracle.com \
--to=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).