linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Anand Jain <anand.jain@oracle.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 2/6] btrfs: cleanup btrfs_find_device_by_devspec()
Date: Thu, 17 Jan 2019 23:32:29 +0800	[thread overview]
Message-ID: <1547739153-6916-3-git-send-email-anand.jain@oracle.com> (raw)
In-Reply-To: <1547739153-6916-1-git-send-email-anand.jain@oracle.com>

btrfs_find_device_by_devspec() finds the device by @devid or by
@device_path. This patch makes code flow easy to read by open
coding the else part and renames devpath to device_path.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
If the else is preferred, I am ok to keep them. Nikolay?

 fs/btrfs/volumes.c | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index e92404081e25..8b5201c734b9 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -2435,7 +2435,8 @@ static struct btrfs_device *btrfs_find_device_by_path(
  * Lookup a device given by device id, or the path if the id is 0.
  */
 struct btrfs_device *btrfs_find_device_by_devspec(
-		struct btrfs_fs_info *fs_info, u64 devid, const char *devpath)
+		struct btrfs_fs_info *fs_info, u64 devid,
+		const char *device_path)
 {
 	struct btrfs_device *device;
 
@@ -2443,24 +2444,23 @@ struct btrfs_device *btrfs_find_device_by_devspec(
 		device = btrfs_find_device(fs_info, devid, NULL, NULL);
 		if (!device)
 			return ERR_PTR(-ENOENT);
-	} else {
-		if (!devpath || !devpath[0])
-			return ERR_PTR(-EINVAL);
-
-		if (strcmp(devpath, "missing") == 0) {
-			list_for_each_entry(device, &fs_info->fs_devices->devices,
-					    dev_list) {
-				if (test_bit(BTRFS_DEV_STATE_IN_FS_METADATA,
-					     &device->dev_state) &&
-					     !device->bdev)
-					return device;
-			}
-			return ERR_PTR(-ENOENT);
-		} else {
-			device = btrfs_find_device_by_path(fs_info, devpath);
+		return device;
+	}
+
+	if (!device_path || !device_path[0])
+		return ERR_PTR(-EINVAL);
+
+	if (strcmp(device_path, "missing") == 0) {
+		list_for_each_entry(device, &fs_info->fs_devices->devices,
+				    dev_list) {
+			if (test_bit(BTRFS_DEV_STATE_IN_FS_METADATA,
+				     &device->dev_state) && !device->bdev)
+				return device;
 		}
+		return ERR_PTR(-ENOENT);
 	}
-	return device;
+
+	return btrfs_find_device_by_path(fs_info, device_path);
 }
 
 /*
-- 
1.8.3.1


  parent reply	other threads:[~2019-01-17 15:32 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 ` Anand Jain [this message]
2019-01-17 15:57   ` [PATCH 2/6] btrfs: cleanup btrfs_find_device_by_devspec() 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 ` [PATCH 6/6] btrfs: refactor btrfs_find_device() return error code Anand Jain
2019-01-17 15:49   ` 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-3-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).