btrfs-progs: add verbose option to btrfs device scan
Subsystems (2)
PATCH v3 1/1 btrfs-progs: add verbose option to btrfs device scan
To help debug device scan issues, add verbose option to btrfs device scan.
---
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(-)
Documentation/btrfs-device.asciidoc +2 -0
@@ -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
cmds/device.c +7 -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 ) {
@@ -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,
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
@@ -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; }
Signature · 1 line
1.8.3.1
PATCH 1/1 btrfs-progs: add verbose option to btrfs device scan
To help debug device scan issues, add verbose option to btrfs device scan.
---
v3.1: Add --help as well. And update the wordings in Documentation.
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 | 11 +++++++++-- 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, 19 insertions(+), 7 deletions(-)
Documentation/btrfs-device.asciidoc +2 -0
@@ -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:::: +List the devices scanned in the current scan and be verbose where needed *stats* [options] <path>|<device>:: Read and print the device IO error statistics for all devices of the given
cmds/device.c +9 -2
@@ -303,6 +303,8 @@ static const char * const cmd_device_scan_usage[] = {" -d|--all-devices enumerate and register all devices, use as a fallback" ," if blkid is not available" ," -u|--forget [<device>...] unregister a given device or all stale devices if no path " , +" -v|--verbose [<device>...] stdout the devices that are scanned in the current scan" , + NULL };
@@ -313,6 +315,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 +323,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 +337,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 +361,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
@@ -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; }
Signature · 1 line
1.8.3.1
Quoted 1 line · Anand Jain
To help debug device scan issues, add verbose option to btrfs device scan.
The common options like --verbose are going to be added into the global command so I'd rather avoid adding them to new subcommands as this would become unnecessary compatibility issue.
There's an pattern to follow, the output formats (--format). So add a definition for global verbosity options, add new GETOPT_VAL global enum values that do not clash with existing options, add relevant HELPINFO_INSERT_ text string and use it in commands where needed.
Quoted 12 lines · David Sterba
Quoted 1 line · Anand Jain
To help debug device scan issues, add verbose option to btrfs device scan.
The common options like --verbose are going to be added into the global command so I'd rather avoid adding them to new subcommands as this would become unnecessary compatibility issue.
There's an pattern to follow, the output formats (--format). So add a definition for global verbosity options, add new
GETOPT_VALglobal enum values that do not clash with existing options, add relevantHELPINFO_INSERT_text string and use it in commands where needed.
IMO a debug option should rather be at the top level command. If verbose is the top level it would emit a lot of unwanted messages. Here is how a user is using --verbose option in dev scan.
https://lore.kernel.org/linux-btrfs/[email protected]/T/#t
------------
useful to get the list of devices it finds.
------------
OR I didn't get the whole idea here. Looks like you are suggesting something like
btrfs --verbose device scan btrfs --verbose subvolume list <mnt> ::
How does the user will know if a subcommand will have any verbose or not?
How would you not emit unwanted messages and keep the output clutter free.
Thanks, Anand
Quoted 25 lines · Anand Jain
Quoted 12 lines · David Sterba
Quoted 1 line · Anand Jain
To help debug device scan issues, add verbose option to btrfs device scan.
The common options like --verbose are going to be added into the global command so I'd rather avoid adding them to new subcommands as this would become unnecessary compatibility issue.
There's an pattern to follow, the output formats (--format). So add a definition for global verbosity options, add new
GETOPT_VALglobal enum values that do not clash with existing options, add relevantHELPINFO_INSERT_text string and use it in commands where needed.IMO a debug option should rather be at the top level command. If verbose is the top level it would emit a lot of unwanted messages. Here is how a user is using --verbose option in dev scan.
https://lore.kernel.org/linux-btrfs/[email protected]/T/#t
------------
useful to get the list of devices it finds.
------------
Quoted 5 lines
OR I didn't get the whole idea here. Looks like you are suggesting something like
btrfs --verbose device scan btrfs --verbose subvolume list <mnt>
Yes this is what I mean.
Quoted 4 lines
::How does the user will know if a subcommand will have any verbose or not?
The point is that the global option will work for all subcommands, so the user does not have to know which support that or not. For compatiblity reasons, what works now will continue to work. This means that the verbosity option will be duplicated for some commands.
Quoted 2 lines
How would you not emit unwanted messages and keep the output clutter free.
What unwanted messages? Though the verbosity option will be set as global option, it will be up to the command itself what to print.
$ btrfs -v device scan
would be equivalent to
$ btrfs device scan -v
Quoted 47 lines · David Sterba
Quoted 25 lines · Anand Jain
Quoted 12 lines · David Sterba
Quoted 1 line · Anand Jain
To help debug device scan issues, add verbose option to btrfs device scan.
The common options like --verbose are going to be added into the global command so I'd rather avoid adding them to new subcommands as this would become unnecessary compatibility issue.
There's an pattern to follow, the output formats (--format). So add a definition for global verbosity options, add new
GETOPT_VALglobal enum values that do not clash with existing options, add relevantHELPINFO_INSERT_text string and use it in commands where needed.IMO a debug option should rather be at the top level command. If verbose is the top level it would emit a lot of unwanted messages. Here is how a user is using --verbose option in dev scan.
https://lore.kernel.org/linux-btrfs/[email protected]/T/#t
------------
useful to get the list of devices it finds.
------------Quoted 5 lines
OR I didn't get the whole idea here. Looks like you are suggesting something like btrfs --verbose device scan btrfs --verbose subvolume list <mnt>Yes this is what I mean.
Quoted 4 lines
::How does the user will know if a subcommand will have any verbose or not?
The point is that the global option will work for all subcommands, so the user does not have to know which support that or not. For compatiblity reasons, what works now will continue to work. This means that the verbosity option will be duplicated for some commands.
Quoted 2 lines
How would you not emit unwanted messages and keep the output clutter free.
Quoted 9 lines
What unwanted messages? Though the verbosity option will be set as global option, it will be up to the command itself what to print.
$ btrfs -v device scanwould be equivalent to
$ btrfs device scan -v
I was thinking there might be some common code between the sub-commands in btrfs-progs now or in future, and if the printf() due to verbose is required in one sub-command and the same printf() due to verbose is not required in another sub-command (which I called unwanted message) then we won't have any choice to not to print those unwanted printf().
But as this is just an anticipatory only, so probably we could try global verbose and see how it fares. I will try.
Thanks, Anand
Quoted 8 lines · Anand Jain
I was thinking there might be some common code between the sub-commands in btrfs-progs now or in future, and if the
printf()due to verbose is required in one sub-command and the sameprintf()due to verbose is not required in another sub-command (which I called unwanted message) then we won't have any choice to not to print those unwantedprintf().
But as this is just an anticipatory only, so probably we could try global verbose and see how it fares. I will try.
I see, but it would be better to have a concrete example where it's problematic so we can figure out ways how to filter unwanted messages.
Quoted 10 lines · David Sterba
Quoted 8 lines · Anand Jain
I was thinking there might be some common code between the sub-commands in btrfs-progs now or in future, and if the
printf()due to verbose is required in one sub-command and the sameprintf()due to verbose is not required in another sub-command (which I called unwanted message) then we won't have any choice to not to print those unwantedprintf().
But as this is just an anticipatory only, so probably we could try global verbose and see how it fares. I will try.
Quoted 3 lines
I see, but it would be better to have a concrete example where it's problematic so we can figure out ways how to filter unwanted messages.
I solved with an argument to btrfs_scan_devcies() [1], by adding %verbose argument to btrfs_scan_devices() to make sure
only btrfs dev scan would print the verbose and not the btrfs fi show. If btrfs fi show prints the verbose it shall break few test-cases in fstests.
[1]
https://patchwork.kernel.org/patch/11201791/
https://patchwork.kernel.org/patch/11201793/