btrfs-progs: fi show: Print missing device for a mounted file system
PATCH v2 1/2 btrfs-progs: fi show: Print missing device for a mounted file system
Currently when a device is missing for a mounted filesystem the output that is produced is unhelpful:
Label: none uuid: 139ef309-021f-4b98-a3a8-ce230a83b1e2
Total devices 2 FS bytes used 128.00KiB
devid 1 size 5.00GiB used 1.26GiB path /dev/loop0
*** Some devices missing
While the context which prints this is perfectly capable of showing which device exactly is missing, like so:
Label: none uuid: 4a85a40b-9b79-4bde-8e52-c65a550a176b
Total devices 2 FS bytes used 128.00KiB
devid 1 size 5.00GiB used 1.26GiB path /dev/loop0
devid 2 size 0 used 0 path /dev/loop1 MISSING
This is a lot more usable output as it presents the user with the id of the missing device and its path.
---
V2:
* Removed stars around MISSING
cmds/filesystem.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
cmds/filesystem.c +3 -4
@@ -295,7 +295,6 @@ static int print_one_fs(struct btrfs_ioctl_fs_info_args *fs_info, {int i;int fd; -int missing =0 ;char uuidbuf[BTRFS_UUID_UNPARSED_SIZE ];struct btrfs_ioctl_dev_info_args *tmp_dev_info;int ret;
@@ -325,8 +324,10 @@ static int print_one_fs(struct btrfs_ioctl_fs_info_args *fs_info,/* Add check for missing devices even mounted */ fd =open ((char *)tmp_dev_info->path,O_RDONLY );if (fd <0 ) { - missing =1 ; +printf ("\tdevid %4llu size 0 used 0 path %s MISSING\n" , + tmp_dev_info->devid, tmp_dev_info->path);continue ; + }close (fd); canonical_path =path_canonicalize ((char *)tmp_dev_info->path);
@@ -339,8 +340,6 @@ static int print_one_fs(struct btrfs_ioctl_fs_info_args *fs_info,free (canonical_path); } -if (missing) -printf ("\t*** Some devices missing\n" );printf ("\n" );return 0 ; }
--
2.17.1
PATCH v2 2/2 btrfs-progs: tests: Add test for fi show
Add a test to ensure that 'btrfs fi show' on a mounted filesyste, which has a missing device will explicitly print which device is missing.
---
V2:
* Adjust output to detect
tests/cli-tests/016-fi-show-missing/test.sh | 35 +++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 tests/cli-tests/016-fi-show-missing/test.sh
tests/cli-tests/016-fi-show-missing/test.sh new file +35 -0
@@ -0,0 +1,35 @@ +#!/bin/bash +# +# Test that if a device is missing for a mounted filesystem, btrfs fi show will +# show which device exactly is missing. + +source "$TEST_TOP/common" + +check_prereq mkfs.btrfs +check_prereq btrfs + +setup_root_helper +setup_loopdevs 2 +prepare_loopdevs + +dev1=${loopdevs[1]} +dev2=${loopdevs[2]} + +run_check $SUDO_HELPER "$TOP"/mkfs.btrfs -f -draid1 $dev1 $dev2 +# move the device, changing its path, simulating the device being missing +mv $dev2 /dev/loop-non-existent + +run_check $SUDO_HELPER mount -o degraded $dev1 $TEST_MNT + +if ! run_check_stdout $SUDO_HELPER "$TOP"/btrfs fi show $TEST_MNT | \ + grep -q "$dev2 MISSING"; then + + _fail "Didn't find exact missing device" +fi + +mv /dev/loop-non-existent $dev2 + +run_check $SUDO_HELPER umount $TEST_MNT + +cleanup_loopdevs +
--
2.17.1
Quoted 16 lines · Nikolay Borisov
Currently when a device is missing for a mounted filesystem the output that is produced is unhelpful:
Label: none uuid: 139ef309-021f-4b98-a3a8-ce230a83b1e2
Total devices 2 FS bytes used 128.00KiB
devid 1 size 5.00GiB used 1.26GiB path/dev/loop0
*** Some devices missingWhile the context which prints this is perfectly capable of showing which device exactly is missing, like so:
Label: none uuid: 4a85a40b-9b79-4bde-8e52-c65a550a176b
Total devices 2 FS bytes used 128.00KiB
devid 1 size 5.00GiB used 1.26GiB path/dev/loop0
devid 2 size 0 used 0 path/dev/loop1MISSING
Quoted 5 lines
This is a lot more usable output as it presents the user with the id of the missing device and its path.
Signed-off-by Nikolay Borisov <[email protected]>---
Looks good,
but I think this also needs a patch for xfstests adjusting the filters.
Quoted 20 lines · Johannes Thumshirn
Quoted 19 lines · Nikolay Borisov
Currently when a device is missing for a mounted filesystem the output that is produced is unhelpful:
Label: none uuid: 139ef309-021f-4b98-a3a8-ce230a83b1e2
Total devices 2 FS bytes used 128.00KiB
devid 1 size 5.00GiB used 1.26GiB path/dev/loop0
*** Some devices missingWhile the context which prints this is perfectly capable of showing which device exactly is missing, like so:
Label: none uuid: 4a85a40b-9b79-4bde-8e52-c65a550a176b
Total devices 2 FS bytes used 128.00KiB
devid 1 size 5.00GiB used 1.26GiB path/dev/loop0
devid 2 size 0 used 0 path/dev/loop1MISSINGThis is a lot more usable output as it presents the user with the id of the missing device and its path.
Quoted 7 lines
Quoted 2 lines
Signed-off-by Nikolay Borisov <[email protected]>---
Looks good,
Reviewed-by Johannes Thumshirn <[email protected]>but I think this also needs a patch for xfstests adjusting the filters.
It does, I had sent one, but I need to send v2 to adjust for the removed ***, ah this bike shedding ...
Quoted 16 lines · Nikolay Borisov
Currently when a device is missing for a mounted filesystem the output that is produced is unhelpful:
Label: none uuid: 139ef309-021f-4b98-a3a8-ce230a83b1e2
Total devices 2 FS bytes used 128.00KiB
devid 1 size 5.00GiB used 1.26GiB path/dev/loop0
*** Some devices missingWhile the context which prints this is perfectly capable of showing which device exactly is missing, like so:
Label: none uuid: 4a85a40b-9b79-4bde-8e52-c65a550a176b
Total devices 2 FS bytes used 128.00KiB
devid 1 size 5.00GiB used 1.26GiB path/dev/loop0
devid 2 size 0 used 0 path/dev/loop1MISSING
Quoted 8 lines
This is a lot more usable output as it presents the user with the id of the missing device and its path.
Signed-off-by Nikolay Borisov <[email protected]>---
V2:
* Removed stars around MISSING
Ping
Hi,
Quoted 52 lines
Currently when a device is missing for a mounted filesystem the output that is produced is unhelpful:
Label: none uuid: 139ef309-021f-4b98-a3a8-ce230a83b1e2
Total devices 2 FS bytes used 128.00KiB
devid 1 size 5.00GiB used 1.26GiB path/dev/loop0
*** Some devices missingWhile the context which prints this is perfectly capable of showing which device exactly is missing, like so:
Label: none uuid: 4a85a40b-9b79-4bde-8e52-c65a550a176b
Total devices 2 FS bytes used 128.00KiB
devid 1 size 5.00GiB used 1.26GiB path/dev/loop0
devid 2 size 0 used 0 path/dev/loop1MISSINGThis is a lot more usable output as it presents the user with the id of the missing device and its path.
Signed-off-by Nikolay Borisov <[email protected]>---
V2:
* Removed stars around MISSINGcmds/filesystem.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)cmds/filesystem.c +3
-2@@ -295,7 +295,6 @@ static int print_one_fs(struct btrfs_ioctl_fs_info_args *fs_info, {int i;int fd; -int missing =0 ;char uuidbuf[BTRFS_UUID_UNPARSED_SIZE ];struct btrfs_ioctl_dev_info_args *tmp_dev_info;int ret;@@ -325,8 +324,10 @@ static int print_one_fs(struct btrfs_ioctl_fs_info_args *fs_info,/* Add check for missing devices even mounted */ fd =open ((char *)tmp_dev_info->path,O_RDONLY );if (fd <0 ) { - missing =1 ; +printf ("\tdevid %4llu size 0 used 0 path %s MISSING\n" , + tmp_dev_info->devid, tmp_dev_info->path);continue ; + }close (fd); canonical_path =path_canonicalize ((char *)tmp_dev_info->path);
cmds/filesystem.c static int print_one_fs(struct btrfs_ioctl_fs_info_args *fs_info, · line 345
Quoted 8 lines
cmds/filesystem.c +0
-2@@ -339,8 +340,6 @@ static int print_one_fs(struct btrfs_ioctl_fs_info_args *fs_info,free (canonical_path); } -if (missing) -printf ("\t*** Some devices missing\n" );printf ("\n" );return 0 ; }
Need we also fix print_one_uuid()/print_devices()?
There is
pr_verbose(LOG_DEFAULT, "\t*** Some devices missing\n");
in print_one_uuid();
sorry that there is yet not a fix here.
Best Regards
Wang Yugui ([email protected])
2022/12/22