All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yauhen Kharuzhy <yauhen.kharuzhy@zavadatar.com>
To: linux-btrfs@vger.kernel.org
Cc: Yauhen Kharuzhy <yauhen.kharuzhy@zavadatar.com>
Subject: [PATCH] btrfs-progs: Dont' stop scanning of devices at first failed device
Date: Thu, 10 Mar 2016 16:04:35 -0800	[thread overview]
Message-ID: <1457654675-14084-1-git-send-email-yauhen.kharuzhy@zavadatar.com> (raw)

When 'btrfs device scan' command is invoked, it scans all devices,
check them for btrfs superblock and add devices with btrfs to a list.

Next, each device from the list is passed to kernel where it is handled
in the btrfs_scan_one_device() function. This function can, for example,
return -EBUSY when device contains superblock matched to existing and
mounted filesystem (if this device was pulled out from RAID and
connected again after some time).

btrfs tool stops device scan if any device has been failed to add, so
other existing devices with (possibly) valid FS will never be reached.

Fix this by remove stopping at any failure in the btrfs_register_all_devices(),
just return error count. btrfs_scan_one_device() reports any kind of
error already.

Signed-off-by: Yauhen Kharuzhy <yauhen.kharuzhy@zavadatar.com>
---
 cmds-device.c |  2 +-
 utils.c       | 15 +++++++--------
 2 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/cmds-device.c b/cmds-device.c
index 94ffdc5..ec871d2 100644
--- a/cmds-device.c
+++ b/cmds-device.c
@@ -278,7 +278,7 @@ static int cmd_device_scan(int argc, char **argv)
 		ret = btrfs_scan_lblkid();
 		error_on(ret, "error %d while scanning", ret);
 		ret = btrfs_register_all_devices();
-		error_on(ret, "error %d while registering devices", ret);
+		error_on(ret, "there are %d errors while registering devices", ret);
 		goto out;
 	}
 
diff --git a/utils.c b/utils.c
index eabc36d..a5dcfbe 100644
--- a/utils.c
+++ b/utils.c
@@ -1545,7 +1545,7 @@ int btrfs_register_one_device(const char *fname)
  */
 int btrfs_register_all_devices(void)
 {
-	int err;
+	int err, ret = 0;
 	struct btrfs_fs_devices *fs_devices;
 	struct btrfs_device *device;
 	struct list_head *all_uuids;
@@ -1554,16 +1554,15 @@ int btrfs_register_all_devices(void)
 
 	list_for_each_entry(fs_devices, all_uuids, list) {
 		list_for_each_entry(device, &fs_devices->devices, dev_list) {
-			if (*device->name) {
+			if (*device->name)
 				err = btrfs_register_one_device(device->name);
-				if (err < 0)
-					return err;
-				if (err > 0)
-					return -err;
-			}
+
+			if (err)
+				ret++;
 		}
 	}
-	return 0;
+
+	return ret;
 }
 
 int btrfs_device_already_in_root(struct btrfs_root *root, int fd,
-- 
2.5.0


             reply	other threads:[~2016-03-11  0:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-11  0:04 Yauhen Kharuzhy [this message]
2016-03-11 11:21 ` [PATCH] btrfs-progs: Dont' stop scanning of devices at first failed device David Sterba

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=1457654675-14084-1-git-send-email-yauhen.kharuzhy@zavadatar.com \
    --to=yauhen.kharuzhy@zavadatar.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.