Bug 194961

Summary: btrfs device stats --check <folder> does not work
Product: File System Reporter: Tomas Thiemel (thiemel)
Component: btrfsAssignee: Josef Bacik (josef)
Status: RESOLVED CODE_FIX    
Severity: low CC: dsterba, lakshmipathi.g
Priority: P1    
Hardware: All   
OS: Linux   
Kernel Version: 4.9.6-gentoo-r1 Subsystem:
Regression: No Bisected commit-id:

Description Tomas Thiemel 2017-03-22 22:53:25 UTC
ftp1 ~ # btrfs --version
btrfs-progs v4.9

ftp1 ~ # btrfs device stats --check /DATA
btrfs device stats: unrecognized option '--check'
usage: btrfs device stats [options] <path>|<device>

    Show device IO error statistics

    Show device IO error statistics for all devices of the given filesystem
    identified by PATH or DEVICE. The filesystem must be mounted.

    -c|--check             return non-zero if any stat counter is not zero
    -z|--reset             show current stats and reset values to zero

ftp1 ~ # btrfs device stats -c /DATA
[/dev/sdg1].write_io_errs    0
[/dev/sdg1].read_io_errs     0
[/dev/sdg1].flush_io_errs    0
[/dev/sdg1].corruption_errs  0
[/dev/sdg1].generation_errs  0
[/dev/sdc1].write_io_errs    0
[/dev/sdc1].read_io_errs     0
[/dev/sdc1].flush_io_errs    0
[/dev/sdc1].corruption_errs  0
[/dev/sdc1].generation_errs  0
[/dev/sdi1].write_io_errs    0
[/dev/sdi1].read_io_errs     0
[/dev/sdi1].flush_io_errs    0
[/dev/sdi1].corruption_errs  0
[/dev/sdi1].generation_errs  0
[/dev/sdb1].write_io_errs    0
[/dev/sdb1].read_io_errs     0
[/dev/sdb1].flush_io_errs    0
[/dev/sdb1].corruption_errs  0
[/dev/sdb1].generation_errs  0
[/dev/sdd1].write_io_errs    0
[/dev/sdd1].read_io_errs     0
[/dev/sdd1].flush_io_errs    0
[/dev/sdd1].corruption_errs  0
[/dev/sdd1].generation_errs  0
[/dev/sdh1].write_io_errs    0
[/dev/sdh1].read_io_errs     0
[/dev/sdh1].flush_io_errs    0
[/dev/sdh1].corruption_errs  0
[/dev/sdh1].generation_errs  0
[/dev/sdf1].write_io_errs    0
[/dev/sdf1].read_io_errs     0
[/dev/sdf1].flush_io_errs    0
[/dev/sdf1].corruption_errs  0
[/dev/sdf1].generation_errs  0
[/dev/sde1].write_io_errs    0
[/dev/sde1].read_io_errs     0
[/dev/sde1].flush_io_errs    0
[/dev/sde1].corruption_errs  0
[/dev/sde1].generation_errs  0
Comment 1 Tomas Thiemel 2017-05-15 13:04:22 UTC
Problem still occurs.

ftp1 ~ # uname -a
Linux ftp1 4.9.16-gentoo-xeon #13 SMP Tue Apr 18 03:15:39 CEST 2017 x86_64 Intel(R) Xeon(R) CPU E3-1265L V2 @ 2.50GHz GenuineIntel GNU/Linux


ftp1 ~ # btrfs --version
btrfs-progs v4.10.2


ftp1 ~ # btrfs device stats --check /DATA
btrfs device stats: unrecognized option '--check'
usage: btrfs device stats [options] <path>|<device>

    Show device IO error statistics

    Show device IO error statistics for all devices of the given filesystem
    identified by PATH or DEVICE. The filesystem must be mounted.

    -c|--check             return non-zero if any stat counter is not zero
    -z|--reset             show current stats and reset values to zero


ftp1 ~ # btrfs device stats -c /DATA
[/dev/sdf1].write_io_errs    0
[/dev/sdf1].read_io_errs     0
[/dev/sdf1].flush_io_errs    0
[/dev/sdf1].corruption_errs  0
[/dev/sdf1].generation_errs  0
[/dev/sdc1].write_io_errs    0
[/dev/sdc1].read_io_errs     0
[/dev/sdc1].flush_io_errs    0
[/dev/sdc1].corruption_errs  0
[/dev/sdc1].generation_errs  0
[/dev/sdi1].write_io_errs    0
[/dev/sdi1].read_io_errs     0
[/dev/sdi1].flush_io_errs    0
[/dev/sdi1].corruption_errs  0
[/dev/sdi1].generation_errs  0
[/dev/sdb1].write_io_errs    0
[/dev/sdb1].read_io_errs     0
[/dev/sdb1].flush_io_errs    0
[/dev/sdb1].corruption_errs  0
[/dev/sdb1].generation_errs  0
[/dev/sdd1].write_io_errs    0
[/dev/sdd1].read_io_errs     0
[/dev/sdd1].flush_io_errs    0
[/dev/sdd1].corruption_errs  0
[/dev/sdd1].generation_errs  0
Comment 2 lakshmipathi 2017-06-14 19:08:47 UTC
Thanks for the report. Seems like below 1-line fix, will resolve this issue. Will sent it for review in a day or two. 

diff --git a/cmds-device.c b/cmds-device.c
index 5e016a7..4337eb2 100644
--- a/cmds-device.c
+++ b/cmds-device.c
@@ -400,6 +400,7 @@ static int cmd_device_stats(int argc, char **argv)
        while (1) {
                int c;
                static const struct option long_options[] = {
+                       {"check", no_argument, NULL, 'c'},
                        {"reset", no_argument, NULL, 'z'},
                        {NULL, 0, NULL, 0}
                };

# ./btrfs device stats --check /mntpt
[/dev/sda6].write_io_errs    0
[/dev/sda6].read_io_errs     0
[/dev/sda6].flush_io_errs    0
[/dev/sda6].corruption_errs  0
[/dev/sda6].generation_errs  0
[/dev/sda7].write_io_errs    0
[/dev/sda7].read_io_errs     0
[/dev/sda7].flush_io_errs    0
[/dev/sda7].corruption_errs  0
[/dev/sda7].generation_errs  0
Comment 3 lakshmipathi 2017-06-22 07:39:08 UTC
sent a patch, hopefully it will be merged in next version.
Comment 4 David Sterba 2017-06-26 12:40:32 UTC
Thanks. Patch applied to devel. Will be released in 4.12 at the latest, there might be a minor 4.11.x release (not decided yet).