btrfs-progs: add verbose option to btrfs device scan
PATCH RESEND v2 1/1 btrfs-progs: add verbose option to btrfs device scan
To help debug device scan issues, add verbose option to btrfs device scan.
---
v2: Use bool instead of int as a btrfs_scan_device() argument.
cmds/device.c | 8 ++++++-- cmds/filesystem.c | 2 +- common/device-scan.c | 4 +++- common/device-scan.h | 3 ++- common/utils.c | 2 +- disk-io.c | 2 +- 6 files changed, 14 insertions(+), 7 deletions(-)
cmds/device.c +6 -2
@@ -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 ) {
@@ -323,7 +324,7 @@ static int cmd_device_scan(const struct cmd_struct *cmd, int argc, char **argv) { 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 +334,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 +358,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,
cmds/filesystem.c +1 -1
@@ -746,7 +746,7 @@ devs_only:else ret =1 ; }else { - ret =btrfs_scan_devices (); + ret =btrfs_scan_devices (false); }if (ret) {
common/device-scan.c +3 -1
@@ -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 ) {
common/device-scan.h +2 -1
@@ -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,
common/utils.c +1 -1
@@ -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; }
disk-io.c +1 -1
@@ -1085,7 +1085,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; }
Signature · 1 line
2.21.0 (Apple Git-120)
Ping?
Quoted 137 lines · Anand Jain
To help debug device scan issues, add verbose option to btrfs device scan.
Signed-off-by Anand Jain <[email protected]>---
v2: Use bool instead of int as abtrfs_scan_device()argument.cmds/device.c | 8 ++++++-- cmds/filesystem.c | 2 +- common/device-scan.c | 4 +++- common/device-scan.h | 3 ++- common/utils.c | 2 +- disk-io.c | 2 +- 6 files changed, 14 insertions(+), 7 deletions(-)cmds/device.c +6
-2@@ -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 ) {@@ -323,7 +324,7 @@ static int cmd_device_scan(const struct cmd_struct *cmd, int argc, char **argv) { 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 +334,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 +358,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,cmds/filesystem.c +1
-1@@ -746,7 +746,7 @@ devs_only:else ret =1 ; }else { - ret =btrfs_scan_devices (); + ret =btrfs_scan_devices (false); }if (ret) {common/device-scan.c +3
-1@@ -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 ) {common/device-scan.h +2
-1@@ -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,common/utils.c +1
-1@@ -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; }disk-io.c +1
-1@@ -1085,7 +1085,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; }
Graham Cobb
Tested-byQuoted 53 lines · Anand Jain
Ping?
Quoted 49 lines · Anand Jain
To help debug device scan issues, add verbose option to btrfs device scan.
Signed-off-by Anand Jain <[email protected]>---
v2: Use bool instead of int as abtrfs_scan_device()argument.cmds/device.c | 8 ++++++--
cmds/filesystem.c | 2 +-
common/device-scan.c| 4 +++-
common/device-scan.h| 3 ++-
common/utils.c | 2 +-
disk-io.c | 2 +-6 files changed, 14 insertions(+), 7 deletions(-)cmds/device.c +2
-0@@ -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) {@@ -323,7 +324,7 @@ static int cmd_device_scan(const struct cmd_struct *cmd, int argc, char **argv) { 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) {
cmds/device.c +0
-0@@ -333,6 +334,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);
}cmds/device.c +0
-0@@ -354,7 +358,7 @@ static int cmd_device_scan(const struct cmd_struct *cmd, int argc, char **argv)
Quoted 8 lines
Quoted 8 lines
cmds/device.c +1
-1} } 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,
Shouldn't "--verbose" be accepted as a long version of the option? That would mean adding it to long_options.
The usage message cmd_device_scan_usage needs to be updated to include the new option(s).
I have tested this on my systems (4.19 kernel) and it not only works well, it is useful to get the list of devices it finds. If you wish, feel free to add:
Graham
Quoted 78 lines
Quoted 77 lines
cmds/filesystem.c +0
-0@@ -746,7 +746,7 @@ devs_only:else
ret = 1;
} else {
- ret =btrfs_scan_devices();
+ ret =btrfs_scan_devices(false);
}
if (ret) {common/device-scan.c +1
-0@@ -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;
common/device-scan.c +2
-0@@ -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) {common/device-scan.h +0
-0@@ -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 @@ structseen_fsid{
int fd;
};
-intbtrfs_scan_devices(void);
+intbtrfs_scan_devices(bool verbose);
intbtrfs_register_one_device(const char *fname); intbtrfs_register_all_devices(void);
int btrfs_add_to_fsid(structbtrfs_trans_handle*trans,common/utils.c +1
-1@@ -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; }disk-io.c +1
-1@@ -1085,7 +1085,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; }
Quoted 3 lines
Shouldn't "--verbose" be accepted as a long version of the option? That would mean adding it to
long_options.
For verbose we provide -v in
btrfs balance
btrfs convert
btrfs filesystem
btrfs inspect-internal
btrfs rescue
and -v|--verbose in
btrfs send
btrfs restore
btrfs subvolume
we kind of lost the consistency. But most of it is -v.
Quoted 2 lines
The usage message
cmd_device_scan_usageneeds to be updated to include the new option(s).
Will do.
Quoted 3 lines
I have tested this on my systems (4.19 kernel) and it not only works well, it is useful to get the list of devices it finds. If you wish, feel free to add:
Thanks.
Quoted 1 line
Tested-by Graham Cobb <[email protected]>
Thanks, Anand
Quoted 1 line
Graham
Quoted 11 lines · Anand Jain
Quoted 3 lines
Shouldn't "--verbose" be accepted as a long version of the option? That would mean adding it to
long_options.For verbose we provide -v in
btrfs balance
btrfs convert
btrfs filesystem
btrfs inspect-internal
btrfs rescue
Quoted 6 lines
and -v|--verbose in
btrfs send
btrfs restore
btrfs subvolumewe kind of lost the consistency. But most of it is -v.
Added --verbose in v3. It is now consistent within btrfs dev scan sub-command. Thanks.
-Anand
Quoted 17 lines
Quoted 3 lines
The usage message
cmd_device_scan_usageneeds to be updated to include the new option(s).Will do.
Quoted 3 lines
I have tested this on my systems (4.19 kernel) and it not only works well, it is useful to get the list of devices it finds. If you wish, feel free to add:
Thanks.
Quoted 1 line
Tested-by Graham Cobb <[email protected]>Thanks, Anand
Quoted 1 line
Graham