All of lore.kernel.org
 help / color / mirror / Atom feed
From: xuw2015@gmail.com
To: linux-btrfs@vger.kernel.org
Cc: George Wang <xuw2015@gmail.com>
Subject: [PATCH 2/3] btrfs: support to find missing device by path
Date: Thu, 30 Apr 2015 17:07:24 +0800	[thread overview]
Message-ID: <1430384845-9666-2-git-send-email-xuw2015@gmail.com> (raw)
In-Reply-To: <1430384845-9666-1-git-send-email-xuw2015@gmail.com>

From: George Wang <xuw2015@gmail.com>

First try to find the device matches specified device path, if nothing, then
find the device by (devid, dev_uuid). This can fix the regression for
replacing an offline device which path is held in btrfs_device.

Signed-off-by: George Wang <xuw2015@gmail.com>
---
 fs/btrfs/volumes.c | 46 ++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 44 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 8bcd2a0..c8ece13 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -1888,8 +1888,37 @@ void btrfs_destroy_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,
 	mutex_unlock(&uuid_mutex);
 }
 
-static int btrfs_find_device_by_path(struct btrfs_root *root, char *device_path,
-				     struct btrfs_device **device)
+
+/*
+ * Find specified device in fs_devices, caller must hold volume_mutex.
+ * Use @device_path as the key, do not check the devid and dev_uuid. Depends
+ * on usage, the caller may do more checking for ret device.
+ */
+static int __fast_find_device_by_path(struct btrfs_root *root, char *device_path,
+                                       struct btrfs_device **device)
+{
+	struct list_head *devices;
+	struct btrfs_device *tmp;
+	char *name;
+
+	devices = &root->fs_info->fs_devices->devices;
+
+	list_for_each_entry(tmp, devices, dev_list) {
+		name = rcu_str_deref(tmp->name);
+		if (tmp && 0 == strcmp(name, device_path)) {
+			*device = tmp;
+			return 0;
+		}
+	}
+
+       return -ENOENT;
+}
+
+/*
+ * Real read (devid, dev_uuid) from device, then find it in fs_devices
+ */
+static int __slow_find_device_by_path(struct btrfs_root *root, char *device_path,
+				struct btrfs_device **device)
 {
 	int ret = 0;
 	struct btrfs_super_block *disk_super;
@@ -1915,6 +1944,19 @@ static int btrfs_find_device_by_path(struct btrfs_root *root, char *device_path,
 	return ret;
 }
 
+ 
+static int btrfs_find_device_by_path(struct btrfs_root *root, char *device_path,
+			struct btrfs_device **device)
+{
+	int ret;
+
+	ret = __fast_find_device_by_path(root, device_path, device);
+	if (ret)
+		ret = __slow_find_device_by_path(root, device_path, device);
+
+	return ret;
+}
+
 int btrfs_find_device_missing_or_by_path(struct btrfs_root *root,
 					 char *device_path,
 					 struct btrfs_device **device)
-- 
1.9.3


  reply	other threads:[~2015-04-30  9:07 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-30  9:07 [PATCH 1/3] btrfs: introduce BTRFS_BLOCK_SIZE to replace number 4096 xuw2015
2015-04-30  9:07 ` xuw2015 [this message]
2015-05-05 15:38   ` [PATCH 2/3] btrfs: support to find missing device by path David Sterba
2015-05-06  9:15     ` Anand Jain
2015-05-06  9:22       ` Anand Jain
2015-05-07  2:51         ` George Wang
2015-05-07  3:17           ` Anand Jain
2015-05-07  3:47             ` George Wang
2015-04-30  9:07 ` [PATCH 3/3] btrfs: do not allow device path updated by the stale one xuw2015
2015-05-05 15:34 ` [PATCH 1/3] btrfs: introduce BTRFS_BLOCK_SIZE to replace number 4096 David Sterba
2015-05-11  6:01   ` George Wang

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=1430384845-9666-2-git-send-email-xuw2015@gmail.com \
    --to=xuw2015@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.