All of lore.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo@cn.fujitsu.com>
To: <linux-btrfs@vger.kernel.org>
Cc: Anand Jain <Anand.Jain@oracle.com>
Subject: [RFC PATCH 1/2] btrfs: Add missing device check in dev_info/rm_dev ioctl
Date: Tue, 6 May 2014 14:33:12 +0800	[thread overview]
Message-ID: <1399357993-9254-2-git-send-email-quwenruo@cn.fujitsu.com> (raw)
In-Reply-To: <1399357993-9254-1-git-send-email-quwenruo@cn.fujitsu.com>

Old btrfs can't find a missing btrfs device since there is no
mechanism for block layer to inform fs layer.

But we can use a workaround that only check status(by using
request_queue->queue_flags) of every device in a btrfs
filesystem when calling dev_info/rm_dev ioctl, since other ioctls
do not really cares about missing device.

Cc: Anand Jain <Anand.Jain@oracle.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
 fs/btrfs/ioctl.c   |  1 +
 fs/btrfs/volumes.c | 25 ++++++++++++++++++++++++-
 fs/btrfs/volumes.h |  2 ++
 3 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 0401397..7680a40 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -2606,6 +2606,7 @@ static long btrfs_ioctl_dev_info(struct btrfs_root *root, void __user *arg)
 		goto out;
 	}
 
+	btrfs_check_dev_missing(root, dev, 1);
 	di_args->devid = dev->devid;
 	di_args->bytes_used = dev->bytes_used;
 	di_args->total_bytes = dev->total_bytes;
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index d241130a..c7d7908 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -1548,9 +1548,10 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)
 		 * is held.
 		 */
 		list_for_each_entry(tmp, devices, dev_list) {
+			btrfs_check_dev_missing(root, tmp, 0);
 			if (tmp->in_fs_metadata &&
 			    !tmp->is_tgtdev_for_dev_replace &&
-			    !tmp->bdev) {
+			    (!tmp->bdev || tmp->missing)) {
 				device = tmp;
 				break;
 			}
@@ -6300,3 +6301,25 @@ int btrfs_scratch_superblock(struct btrfs_device *device)
 
 	return 0;
 }
+
+/* If need_lock is set, uuid_mutex will be used */
+int btrfs_check_dev_missing(struct btrfs_root *root, struct btrfs_device *dev,
+			    int need_lock)
+{
+	struct request_queue *q;
+
+	if (unlikely(!dev || !dev->bdev || !dev->bdev->bd_queue))
+		return -ENOENT;
+	q = dev->bdev->bd_queue;
+
+	if (need_lock)
+		mutex_lock(&uuid_mutex);
+	if (test_bit(QUEUE_FLAG_DEAD, &q->queue_flags) ||
+	    test_bit(QUEUE_FLAG_DYING, &q->queue_flags)) {
+		dev->missing = 1;
+		root->fs_info->fs_devices->missing_devices++;
+	}
+	if (need_lock)
+		mutex_unlock(&uuid_mutex);
+	return 0;
+}
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index 80754f9..47a44af 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -356,6 +356,8 @@ unsigned long btrfs_full_stripe_len(struct btrfs_root *root,
 int btrfs_finish_chunk_alloc(struct btrfs_trans_handle *trans,
 				struct btrfs_root *extent_root,
 				u64 chunk_offset, u64 chunk_size);
+int btrfs_check_dev_missing(struct btrfs_root *root, struct btrfs_device *dev,
+			    int need_lock);
 static inline void btrfs_dev_stat_inc(struct btrfs_device *dev,
 				      int index)
 {
-- 
1.9.2


  reply	other threads:[~2014-05-06  6:32 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-06  6:33 [RFC PATCH 0/2] Kernel space btrfs missing device detection Qu Wenruo
2014-05-06  6:33 ` Qu Wenruo [this message]
2014-05-07  8:00   ` [RFC PATCH 1/2] btrfs: Add missing device check in dev_info/rm_dev ioctl Anand Jain
2014-05-07  8:02     ` Qu Wenruo
2014-05-21  3:12     ` Qu Wenruo
2014-05-21  3:54       ` Anand Jain
2014-05-21  4:15         ` Qu Wenruo
2014-05-21 18:26           ` Brendan Hide
2014-05-21  3:47   ` Anand Jain
2014-05-06  6:33 ` [RFC PATCH 2/2] btrfs: Add new member of btrfs_ioctl_dev_info_args Qu Wenruo
2014-05-06 18:10 ` [RFC PATCH 0/2] Kernel space btrfs missing device detection Goffredo Baroncelli
2014-05-07  1:48   ` Qu Wenruo

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=1399357993-9254-2-git-send-email-quwenruo@cn.fujitsu.com \
    --to=quwenruo@cn.fujitsu.com \
    --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 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.