From: Anand Jain <anand.jain@oracle.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH v3] btrfs-progs: add verbose option to btrfs device scan
Date: Wed, 2 Oct 2019 12:11:52 +0800 [thread overview]
Message-ID: <1569989512-5594-1-git-send-email-anand.jain@oracle.com> (raw)
To help debug device scan issues, add verbose option to btrfs device scan.
Signed-off-by: Anand Jain <anand.jain@oracle.com>
Tested-by: Graham Cobb <g.btrfs@cobb.uk.net>
---
v3: Add --verbose long option and update documentation. Thanks Graham.A
Add Tested-by.
v2: Use bool instead of int as a btrfs_scan_device() argument.
Documentation/btrfs-device.asciidoc | 2 ++
cmds/device.c | 9 +++++++--
cmds/filesystem.c | 2 +-
common/device-scan.c | 4 +++-
common/device-scan.h | 3 ++-
common/utils.c | 2 +-
disk-io.c | 2 +-
7 files changed, 17 insertions(+), 7 deletions(-)
diff --git a/Documentation/btrfs-device.asciidoc b/Documentation/btrfs-device.asciidoc
index 70ce6c5a97f8..a251be9e0fa2 100644
--- a/Documentation/btrfs-device.asciidoc
+++ b/Documentation/btrfs-device.asciidoc
@@ -120,6 +120,8 @@ available.
-u|--forget::::
Unregister a given device or all stale devices if no path is given, the device
must be unmounted otherwise it's an error.
+-v|--verbose::::
+Be verbose and list the devices scanned.
*stats* [options] <path>|<device>::
Read and print the device IO error statistics for all devices of the given
diff --git a/cmds/device.c b/cmds/device.c
index 24158308a41b..655b97d83cb7 100644
--- a/cmds/device.c
+++ b/cmds/device.c
@@ -313,6 +313,7 @@ static int cmd_device_scan(const struct cmd_struct *cmd, int argc, char **argv)
int all = 0;
int ret = 0;
int forget = 0;
+ bool verbose = false;
optind = 0;
while (1) {
@@ -320,10 +321,11 @@ static int cmd_device_scan(const struct cmd_struct *cmd, int argc, char **argv)
static const struct option long_options[] = {
{ "all-devices", no_argument, NULL, 'd'},
{ "forget", no_argument, NULL, 'u'},
+ { "verbose", no_argument, NULL, 'v'},
{ NULL, 0, NULL, 0}
};
- c = getopt_long(argc, argv, "du", long_options, NULL);
+ c = getopt_long(argc, argv, "duv", long_options, NULL);
if (c < 0)
break;
switch (c) {
@@ -333,6 +335,9 @@ static int cmd_device_scan(const struct cmd_struct *cmd, int argc, char **argv)
case 'u':
forget = 1;
break;
+ case 'v':
+ verbose = true;
+ break;
default:
usage_unknown_option(cmd, argv);
}
@@ -354,7 +359,7 @@ static int cmd_device_scan(const struct cmd_struct *cmd, int argc, char **argv)
}
} else {
printf("Scanning for Btrfs filesystems\n");
- ret = btrfs_scan_devices();
+ ret = btrfs_scan_devices(verbose);
error_on(ret, "error %d while scanning", ret);
ret = btrfs_register_all_devices();
error_on(ret,
diff --git a/cmds/filesystem.c b/cmds/filesystem.c
index 4f22089abeaa..02d47a43a792 100644
--- a/cmds/filesystem.c
+++ b/cmds/filesystem.c
@@ -746,7 +746,7 @@ devs_only:
else
ret = 1;
} else {
- ret = btrfs_scan_devices();
+ ret = btrfs_scan_devices(false);
}
if (ret) {
diff --git a/common/device-scan.c b/common/device-scan.c
index 48dbd9e19715..a500edf0f7d7 100644
--- a/common/device-scan.c
+++ b/common/device-scan.c
@@ -360,7 +360,7 @@ void free_seen_fsid(struct seen_fsid *seen_fsid_hash[])
}
}
-int btrfs_scan_devices(void)
+int btrfs_scan_devices(bool verbose)
{
int fd = -1;
int ret;
@@ -389,6 +389,8 @@ int btrfs_scan_devices(void)
continue;
/* if we are here its definitely a btrfs disk*/
strncpy_null(path, blkid_dev_devname(dev));
+ if (verbose)
+ printf("blkid: btrfs device: %s\n", path);
fd = open(path, O_RDONLY);
if (fd < 0) {
diff --git a/common/device-scan.h b/common/device-scan.h
index eda2bae5c6c4..3e473c48d1af 100644
--- a/common/device-scan.h
+++ b/common/device-scan.h
@@ -1,6 +1,7 @@
#ifndef __DEVICE_SCAN_H__
#define __DEVICE_SCAN_H__
+#include <stdbool.h>
#include "kerncompat.h"
#include "ioctl.h"
@@ -29,7 +30,7 @@ struct seen_fsid {
int fd;
};
-int btrfs_scan_devices(void);
+int btrfs_scan_devices(bool verbose);
int btrfs_register_one_device(const char *fname);
int btrfs_register_all_devices(void);
int btrfs_add_to_fsid(struct btrfs_trans_handle *trans,
diff --git a/common/utils.c b/common/utils.c
index 6617b3ef38b1..9027de596f5d 100644
--- a/common/utils.c
+++ b/common/utils.c
@@ -277,7 +277,7 @@ int check_mounted_where(int fd, const char *file, char *where, int size,
/* scan other devices */
if (is_btrfs && total_devs > 1) {
- ret = btrfs_scan_devices();
+ ret = btrfs_scan_devices(false);
if (ret)
return ret;
}
diff --git a/disk-io.c b/disk-io.c
index fa679133e171..58861ccfb4ec 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -1096,7 +1096,7 @@ int btrfs_scan_fs_devices(int fd, const char *path,
}
if (!skip_devices && total_devs != 1) {
- ret = btrfs_scan_devices();
+ ret = btrfs_scan_devices(false);
if (ret)
return ret;
}
--
1.8.3.1
next reply other threads:[~2019-10-02 4:14 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-02 4:11 Anand Jain [this message]
2019-10-02 4:44 ` [PATCH v3.1] btrfs-progs: add verbose option to btrfs device scan Anand Jain
2019-10-07 17:41 ` [PATCH v3] " David Sterba
2019-10-08 2:53 ` Anand Jain
2019-10-14 15:24 ` David Sterba
2019-10-15 3:29 ` Anand Jain
2019-10-21 13:43 ` David Sterba
2019-10-21 23:48 ` 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=1569989512-5594-1-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).