btrfs-progs: fi show: Print missing device for a mounted file system
PATCH 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.
--- 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 ; }
Signature · 1 line
2.17.1
PATCH 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.
--- 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 +
Signature · 1 line
2.17.1
Quoted 11 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:
Quoted 7 lines
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.
The idea is pretty awesome.
Just one question, if one device is missing, how could we know its path? Thus does the device path output make any sense?
Thanks,
Qu
Quoted 40 lines
Signed-off-by Nikolay Borisov <[email protected]>--- 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 ; }
Quoted 19 lines · Qu Wenruo
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/loop0devid 2 size 0 used 0 path/dev/loop1***MISSING***
Quoted 7 lines
Quoted 2 lines
This is a lot more usable output as it presents the user with the id of the missing device and its path.
The idea is pretty awesome.
Just one question, if one device is missing, how could we know its path? Thus does the device path output make any sense?
The path is not canonicalized but otherwise the paths comes from btrfs_ioctl_dev_info_args which is filled by a call to get_fs_info where we call get_device_info for every device in the fs_info.
So the path is really dev->name from kernel space or if we don't have a dev->name it will be 0. In either case it's useful that we get the devid so that the user can do :
btrfs device remove 2 (if we take the above example), alternatively the path would be a NULL-terminated string which aka empty. I guess that's still better than simply saying *some devices are missing*
Quoted 48 lines
Thanks,
QuQuoted 44 lines
Signed-off-by Nikolay Borisov <[email protected]>---
cmds/filesystem.c| 7 +++----1 file changed, 3 insertions(+), 4 deletions(-)cmds/filesystem.c +0
-1@@ -295,7 +295,6 @@ static int print_one_fs(structbtrfs_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;
cmds/filesystem.c +3
-1@@ -325,8 +324,10 @@ static int print_one_fs(structbtrfs_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 +0
-2@@ -339,8 +340,6 @@ static int print_one_fs(structbtrfs_ioctl_fs_info_args *fs_info, free(canonical_path); } - if (missing) - printf("\t*** Some devices missing\n"); printf("\n"); return 0;}
Quoted 34 lines · Nikolay Borisov
Quoted 19 lines · Qu Wenruo
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/loop0devid 2 size 0 used 0 path/dev/loop1***MISSING***Quoted 7 lines
Quoted 2 lines
This is a lot more usable output as it presents the user with the id of the missing device and its path.
The idea is pretty awesome.
Just one question, if one device is missing, how could we know its path? Thus does the device path output make any sense?
The path is not canonicalized but otherwise the paths comes from
btrfs_ioctl_dev_info_argswhich is filled by a call toget_fs_infowhere we callget_device_infofor every device in thefs_info.
Quoted 7 lines
So the path is really
dev->namefrom kernel space or if we don't have adev->nameit will be 0. In either case it's useful that we get the devid so that the user can do :btrfs device remove 2 (if we take the above example), alternatively the path would be a NULL-terminated string which aka empty. I guess that's still better than simply saying *some devices are missing*
Definitely the devid output is way better than the existing output.
I just wonder can we skip the path completely since it's missing (and under most case its NULL anyway).
Despite that, I'm completely fine with the patch.
Thanks,
Qu
Quoted 49 lines
Quoted 49 lines
Thanks,
QuQuoted 44 lines
Signed-off-by Nikolay Borisov <[email protected]>--- cmds/filesystem.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)cmds/filesystem.c +0
-1@@ -295,7 +295,6 @@ static int print_one_fs(structbtrfs_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;
cmds/filesystem.c +3
-1@@ -325,8 +324,10 @@ static int print_one_fs(structbtrfs_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 +0
-2@@ -339,8 +340,6 @@ static int print_one_fs(structbtrfs_ioctl_fs_info_args *fs_info, free(canonical_path); } - if (missing) - printf("\t*** Some devices missing\n"); printf("\n"); return 0;}
Quoted 45 lines · Qu Wenruo
Quoted 34 lines · Nikolay Borisov
Quoted 19 lines · Qu Wenruo
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/loop0devid 2 size 0 used 0 path/dev/loop1***MISSING***Quoted 7 lines
Quoted 2 lines
This is a lot more usable output as it presents the user with the id of the missing device and its path.
The idea is pretty awesome.
Just one question, if one device is missing, how could we know its path? Thus does the device path output make any sense?
The path is not canonicalized but otherwise the paths comes from
btrfs_ioctl_dev_info_argswhich is filled by a call toget_fs_infowhere we callget_device_infofor every device in thefs_info.Quoted 7 lines
So the path is really
dev->namefrom kernel space or if we don't have adev->nameit will be 0. In either case it's useful that we get the devid so that the user can do :btrfs device remove 2 (if we take the above example), alternatively the path would be a NULL-terminated string which aka empty. I guess that's still better than simply saying *some devices are missing*
Quoted 6 lines
Definitely the devid output is way better than the existing output.
I just wonder can we skip the path completely since it's missing (and under most case its NULL anyway).
Despite that, I'm completely fine with the patch.
As you can see form the test I have added this was tested rather synthetically by simply moving a loop device, in this case the device's record was still in the fs_devices and had the name, though the name itself couldn't be acted on. So omitting the path entirely is definitely something we could do, but I'd rather try and be a bit cleverer, simply checking if the name is null or not and if not just print it?
Quoted 55 lines
Thanks,
QuQuoted 50 lines
Quoted 50 lines
Thanks,
QuQuoted 45 lines
Signed-off-by Nikolay Borisov <[email protected]>---
cmds/filesystem.c| 7 +++----1 file changed, 3 insertions(+), 4 deletions(-)cmds/filesystem.c +0
-1@@ -295,7 +295,6 @@ static int print_one_fs(structbtrfs_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;
cmds/filesystem.c +3
-1@@ -325,8 +324,10 @@ static int print_one_fs(structbtrfs_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 +0
-2@@ -339,8 +340,6 @@ static int print_one_fs(structbtrfs_ioctl_fs_info_args *fs_info, free(canonical_path); } - if (missing) - printf("\t*** Some devices missing\n"); printf("\n"); return 0;}
Qu Wenruo
Reviewed-byQuoted 53 lines · Nikolay Borisov
Quoted 50 lines · Qu Wenruo
Quoted 34 lines · Nikolay Borisov
Quoted 19 lines · Qu Wenruo
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/loop0devid 2 size 0 used 0 path/dev/loop1***MISSING***Quoted 7 lines
Quoted 2 lines
This is a lot more usable output as it presents the user with the id of the missing device and its path.
The idea is pretty awesome.
Just one question, if one device is missing, how could we know its path? Thus does the device path output make any sense?
The path is not canonicalized but otherwise the paths comes from
btrfs_ioctl_dev_info_argswhich is filled by a call toget_fs_infowhere we callget_device_infofor every device in thefs_info.Quoted 7 lines
So the path is really
dev->namefrom kernel space or if we don't have adev->nameit will be 0. In either case it's useful that we get the devid so that the user can do :btrfs device remove 2 (if we take the above example), alternatively the path would be a NULL-terminated string which aka empty. I guess that's still better than simply saying *some devices are missing*
Definitely the devid output is way better than the existing output.
I just wonder can we skip the path completely since it's missing (and under most case its NULL anyway).
Quoted 8 lines
Quoted 1 line
Despite that, I'm completely fine with the patch.
As you can see form the test I have added this was tested rather synthetically by simply moving a loop device, in this case the device's record was still in the
fs_devicesand had the name, though the name itself couldn't be acted on. So omitting the path entirely is definitely something we could do, but I'd rather try and be a bit cleverer, simply checking if the name is null or not and if not just print it?
Oh, I forgot the case where the stall path may still be there.
In that case your existing one should be enough to handle it.
printf() can handle NULL pointer for %s without problem.
Then it should be OK.
Thanks,
Qu
Quoted 56 lines
Quoted 56 lines
Thanks,
QuQuoted 50 lines
Quoted 50 lines
Thanks,
QuQuoted 45 lines
Signed-off-by Nikolay Borisov <[email protected]>--- cmds/filesystem.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)cmds/filesystem.c +0
-1@@ -295,7 +295,6 @@ static int print_one_fs(structbtrfs_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;
cmds/filesystem.c +3
-1@@ -325,8 +324,10 @@ static int print_one_fs(structbtrfs_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 +0
-2@@ -339,8 +340,6 @@ static int print_one_fs(structbtrfs_ioctl_fs_info_args *fs_info, free(canonical_path); } - if (missing) - printf("\t*** Some devices missing\n"); printf("\n"); return 0;}
Quoted 69 lines · Qu Wenruo
Quoted 57 lines · Nikolay Borisov
Quoted 54 lines · Qu Wenruo
Quoted 37 lines · Nikolay Borisov
Quoted 20 lines · Qu Wenruo
Quoted 17 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/loop0devid 2 size 0 used 0 path/dev/loop1***MISSING***Quoted 8 lines
Quoted 2 lines
This is a lot more usable output as it presents the user with the id of the missing device and its path.
The idea is pretty awesome.
Just one question, if one device is missing, how could we know its path?
Thus does the device path output make any sense?The path is not canonicalized but otherwise the paths comes from
btrfs_ioctl_dev_info_argswhich is filled by a call toget_fs_infowhere
we callget_device_infofor every device in thefs_info.Quoted 8 lines
So the path is really
dev->namefrom kernel space or if we don't have adev->nameit will be 0. In either case it's useful that we get the devid
so that the user can do :btrfs device remove 2 (if we take the above example), alternatively the path would be a NULL-terminated string which aka empty. I guess that's still better than simply saying *some devices are missing*
Definitely the devid output is way better than the existing output.
I just wonder can we skip the path completely since it's missing (and under most case its NULL anyway).
Quoted 8 lines
Quoted 1 line
Despite that, I'm completely fine with the patch.
As you can see form the test I have added this was tested rather synthetically by simply moving a loop device, in this case the device's record was still in the
fs_devicesand had the name, though the name itself couldn't be acted on. So omitting the path entirely is definitely something we could do, but I'd rather try and be a bit cleverer, simply checking if the name is null or not and if not just print it?
Quoted 3 lines
Oh, I forgot the case where the stall path may still be there.
In that case your existing one should be enough to handle it.
I realise this comment might be too late so feel free to ignore it if so. Could this path name potentially conflict with a (new) device using the same name? For example, could someone have created a new /dev/loop1? Or could a USB disk /dev/sdf1 (say) have been removed and a different disk inserted and acquired the /dev/sdf1 name? Or would that be prevented in the case where "the device's record was still in the fs_devices"?
If so, I think this could be very confusing to the user trying to work out what has happened. Maybe the output needs to change to something like:
devid 2 size 0 used 0 last seen as /dev/loop1 ***MISSING***
"last seen as" could just be "previously". Or, to make it even clearer that this is just a hint to help the user understand which device is missing, maybe something like "(last mounted as /dev/loop1)".
Graham
Quoted 83 lines · On 07/09/2021 00:47, [email protected] wrote:
Quoted 69 lines · Qu Wenruo
Quoted 57 lines · Nikolay Borisov
Quoted 54 lines · Qu Wenruo
Quoted 37 lines · Nikolay Borisov
Quoted 20 lines · Qu Wenruo
Quoted 17 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/loop0devid 2 size 0 used 0 path/dev/loop1***MISSING***Quoted 8 lines
Quoted 2 lines
This is a lot more usable output as it presents the user with the id of the missing device and its path.
The idea is pretty awesome.
Just one question, if one device is missing, how could we know its path?
Thus does the device path output make any sense?The path is not canonicalized but otherwise the paths comes from
btrfs_ioctl_dev_info_argswhich is filled by a call toget_fs_infowhere
we callget_device_infofor every device in thefs_info.Quoted 8 lines
So the path is really
dev->namefrom kernel space or if we don't have adev->nameit will be 0. In either case it's useful that we get the devid
so that the user can do :btrfs device remove 2 (if we take the above example), alternatively the path would be a NULL-terminated string which aka empty. I guess that's still better than simply saying *some devices are missing*
Definitely the devid output is way better than the existing output.
I just wonder can we skip the path completely since it's missing (and under most case its NULL anyway).
Quoted 8 lines
Quoted 1 line
Despite that, I'm completely fine with the patch.
As you can see form the test I have added this was tested rather synthetically by simply moving a loop device, in this case the device's record was still in the
fs_devicesand had the name, though the name itself couldn't be acted on. So omitting the path entirely is definitely something we could do, but I'd rather try and be a bit cleverer, simply checking if the name is null or not and if not just print it?Quoted 3 lines
Oh, I forgot the case where the stall path may still be there.
In that case your existing one should be enough to handle it.
I realise this comment might be too late so feel free to ignore it if so. Could this path name potentially conflict with a (new) device using the same name? For example, could someone have created a new
/dev/loop1? Or could a USB disk/dev/sdf1(say) have been removed and a different disk inserted and acquired the/dev/sdf1name? Or would that be prevented in the case where "the device's record was still in thefs_devices"?
Quoted 8 lines
If so, I think this could be very confusing to the user trying to work out what has happened. Maybe the output needs to change to something like:
devid 2 size 0 used 0 last seen as
/dev/loop1***MISSING***"last seen as" could just be "previously". Or, to make it even clearer that this is just a hint to help the user understand which device is missing, maybe something like "(last mounted as
/dev/loop1)".
Yeah. I agree. We found devid (only) was important in this bug report. Either 'last seen ..' or completely removing the device path will work.
Thanks, Anand
Quoted 3 lines
Graham
Quoted 88 lines · On 6.09.21 г. 19:47, [email protected] wrote:
Quoted 70 lines · Qu Wenruo
Quoted 59 lines · Nikolay Borisov
Quoted 48 lines · Qu Wenruo
Quoted 36 lines · Nikolay Borisov
Quoted 19 lines · Qu Wenruo
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/loop0devid 2 size 0
used 0 path/dev/loop1***MISSING***Quoted 8 lines
Quoted 2 lines
This is a lot more usable output as it presents the user
with the id of the missing device and its path.The idea is pretty awesome.
Just one question, if one device is missing, how could we know its path? Thus does the device path output make any sense?
The path is not canonicalized but otherwise the paths comes from
btrfs_ioctl_dev_info_argswhich is filled by a call toget_fs_infowhere we callget_device_infofor every device in thefs_info.Quoted 8 lines
So the path is really
dev->namefrom kernel space or if we don't have adev->nameit will be 0. In either case it's useful that we get the devid so that the user can do :btrfs device remove 2 (if we take the above example), alternatively the path would be a NULL-terminated string which aka empty. I guess that's still better than simply saying *some devices are missing*
Quoted 7 lines
Definitely the devid output is way better than the existing output.
I just wonder can we skip the path completely since it's missing (and under most case its NULL anyway).
Despite that, I'm completely fine with the patch.
Quoted 7 lines
As you can see form the test I have added this was tested rather synthetically by simply moving a loop device, in this case the device's record was still in the
fs_devicesand had the name, though the name itself couldn't be acted on. So omitting the path entirely is definitely something we could do, but I'd rather try and be a bit cleverer, simply checking if the name is null or not and if not just print it?Quoted 3 lines
Oh, I forgot the case where the stall path may still be there.
In that case your existing one should be enough to handle it.
I realise this comment might be too late so feel free to ignore it if so. Could this path name potentially conflict with a (new) device
using the same name? For example, could someone have created a new/dev/loop1? Or could a USB disk/dev/sdf1(say) have been removed and a different disk inserted and acquired the/dev/sdf1name? Or would that be prevented in the case where "the device's record was still in thefs_devices"?If so, I think this could be very confusing to the user trying to work out what has happened. Maybe the output needs to change to something like:
Quoted 6 lines
devid 2 size 0 used 0 last seen as
/dev/loop1***MISSING***"last seen as" could just be "previously". Or, to make it even clearer that this is just a hint to help the user understand which device is missing, maybe something like "(last mounted as
/dev/loop1)".
Actually in the case of mounted file systems this cannot happen because the missing bit is printed *only* if the device's path cannot be opened, i.e it's indeed missing:
/* Add check for missing devices even mounted */
9 fd = open((char *)tmp_dev_info->path, O_RDONLY);
8 if (fd < 0) {
7 printf("\tdevid %4llu size 0 used 0 path
%s *MISSING*\n",
6 tmp_dev_info->devid,
canonical_path);
5 continue;
4 }Quoted 3 lines
Graham
Quoted 104 lines · Nikolay Borisov
Quoted 88 lines · On 6.09.21 г. 19:47, [email protected] wrote:
Quoted 70 lines · Qu Wenruo
Quoted 59 lines · Nikolay Borisov
Quoted 48 lines · Qu Wenruo
Quoted 36 lines · Nikolay Borisov
Quoted 19 lines · Qu Wenruo
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/loop0devid 2 size 0
used 0 path/dev/loop1***MISSING***Quoted 8 lines
Quoted 2 lines
This is a lot more usable output as it presents the user
with the id of the missing device and its path.The idea is pretty awesome.
Just one question, if one device is missing, how could we know its path? Thus does the device path output make any sense?
The path is not canonicalized but otherwise the paths comes from
btrfs_ioctl_dev_info_argswhich is filled by a call toget_fs_infowhere we callget_device_infofor every device in thefs_info.Quoted 8 lines
So the path is really
dev->namefrom kernel space or if we don't have adev->nameit will be 0. In either case it's useful that we get the devid so that the user can do :btrfs device remove 2 (if we take the above example), alternatively the path would be a NULL-terminated string which aka empty. I guess that's still better than simply saying *some devices are missing*
Quoted 7 lines
Definitely the devid output is way better than the existing output.
I just wonder can we skip the path completely since it's missing (and under most case its NULL anyway).
Despite that, I'm completely fine with the patch.
Quoted 7 lines
As you can see form the test I have added this was tested rather synthetically by simply moving a loop device, in this case the device's record was still in the
fs_devicesand had the name, though the name itself couldn't be acted on. So omitting the path entirely is definitely something we could do, but I'd rather try and be a bit cleverer, simply checking if the name is null or not and if not just print it?Quoted 3 lines
Oh, I forgot the case where the stall path may still be there.
In that case your existing one should be enough to handle it.
I realise this comment might be too late so feel free to ignore it if so. Could this path name potentially conflict with a (new) device
using the same name? For example, could someone have created a new/dev/loop1? Or could a USB disk/dev/sdf1(say) have been removed and a different disk inserted and acquired the/dev/sdf1name? Or would that be prevented in the case where "the device's record was still in thefs_devices"?If so, I think this could be very confusing to the user trying to work out what has happened. Maybe the output needs to change to something like:
Quoted 6 lines
devid 2 size 0 used 0 last seen as
/dev/loop1***MISSING***"last seen as" could just be "previously". Or, to make it even clearer that this is just a hint to help the user understand which device is missing, maybe something like "(last mounted as
/dev/loop1)".Actually in the case of mounted file systems this cannot happen because the missing bit is printed *only* if the device's path cannot be opened, i.e it's indeed missing:
/* Add check for missing devices even mounted */
Quoted 8 lines
9 fd = open((char *)tmp_dev_info->path, O_RDONLY);
8 if (fd < 0) {
7 printf("\tdevid %4llu size 0 used 0 path
%s *MISSING*\n",
6 tmp_dev_info->devid,
canonical_path);
5 continue;
4 }Thanks Nikolay. That makes sense. So to see the MISSING message with a device name, it must have been present when the fs was mounted, got included in the fs when it was mounted, but have gone missing later such that a subsequent "open" fails. Is that correct?
Presumably btrfs is still holding the original fd used at mount time open so the device name (if it can be opened at all) cannot now refer to something else.
Graham
Quoted 115 lines · Graham Cobb
Quoted 104 lines · Nikolay Borisov
Quoted 88 lines · On 6.09.21 г. 19:47, [email protected] wrote:
Quoted 70 lines · Qu Wenruo
Quoted 59 lines · Nikolay Borisov
Quoted 48 lines · Qu Wenruo
Quoted 36 lines · Nikolay Borisov
Quoted 19 lines · Qu Wenruo
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/loop0devid 2 size 0
used 0 path/dev/loop1***MISSING***Quoted 8 lines
Quoted 2 lines
This is a lot more usable output as it presents the user
with the id of the missing device and its path.The idea is pretty awesome.
Just one question, if one device is missing, how could we know its path? Thus does the device path output make any sense?
The path is not canonicalized but otherwise the paths comes from
btrfs_ioctl_dev_info_argswhich is filled by a call toget_fs_infowhere we callget_device_infofor every device in thefs_info.Quoted 8 lines
So the path is really
dev->namefrom kernel space or if we don't have adev->nameit will be 0. In either case it's useful that we get the devid so that the user can do :btrfs device remove 2 (if we take the above example), alternatively the path would be a NULL-terminated string which aka empty. I guess that's still better than simply saying *some devices are missing*
Quoted 7 lines
Definitely the devid output is way better than the existing output.
I just wonder can we skip the path completely since it's missing (and under most case its NULL anyway).
Despite that, I'm completely fine with the patch.
Quoted 7 lines
As you can see form the test I have added this was tested rather synthetically by simply moving a loop device, in this case the device's record was still in the
fs_devicesand had the name, though the name itself couldn't be acted on. So omitting the path entirely is definitely something we could do, but I'd rather try and be a bit cleverer, simply checking if the name is null or not and if not just print it?Quoted 3 lines
Oh, I forgot the case where the stall path may still be there.
In that case your existing one should be enough to handle it.
I realise this comment might be too late so feel free to ignore it if so. Could this path name potentially conflict with a (new) device
using the same name? For example, could someone have created a new/dev/loop1? Or could a USB disk/dev/sdf1(say) have been removed and a different disk inserted and acquired the/dev/sdf1name? Or would that be prevented in the case where "the device's record was still in thefs_devices"?If so, I think this could be very confusing to the user trying to work out what has happened. Maybe the output needs to change to something like:
Quoted 6 lines
devid 2 size 0 used 0 last seen as
/dev/loop1***MISSING***"last seen as" could just be "previously". Or, to make it even clearer that this is just a hint to help the user understand which device is missing, maybe something like "(last mounted as
/dev/loop1)".Actually in the case of mounted file systems this cannot happen because the missing bit is printed *only* if the device's path cannot be opened, i.e it's indeed missing:
/* Add check for missing devices even mounted */
Quoted 8 lines
9 fd = open((char *)tmp_dev_info->path, O_RDONLY); 8 if (fd < 0) { 7 printf("\tdevid %4llu size 0 used 0 path %s *MISSING*\n", 6 tmp_dev_info->devid, canonical_path); 5 continue; 4 }
Quoted 4 lines
Thanks Nikolay. That makes sense. So to see the MISSING message with a device name, it must have been present when the fs was mounted, got included in the fs when it was mounted, but have gone missing later such that a subsequent "open" fails. Is that correct?
No, a filesystem can be mounted with a missing device from the beginning by using the -o degraded, so it's possible that the kernel doesn't even have a possible path for the device. In this case the path would be likely an empty string. So the path is indeed at best advisory
Quoted 4 lines
Presumably btrfs is still holding the original fd used at mount time open so the device name (if it can be opened at all) cannot now refer to something else.
Btrfs does indeed keep a particular device open while it's mounted however if it disappear, and later a device re-appears nothing prevends udev to give it the same name. I.e btrfs cannot control what name a new device would have.
Quoted 3 lines
Graham
Quoted 3 lines · On 9/6/21 6:47 PM, [email protected] wrote:
Quoted 1 line · Qu Wenruo
[...]
Quoted 8 lines
I realise this comment might be too late so feel free to ignore it if so. Could this path name potentially conflict with a (new) device using the same name? For example, could someone have created a new
/dev/loop1? Or could a USB disk/dev/sdf1(say) have been removed and a different disk inserted and acquired the/dev/sdf1name? Or would that be prevented in the case where "the device's record was still in thefs_devices"?
Quoted 9 lines
If so, I think this could be very confusing to the user trying to work out what has happened. Maybe the output needs to change to something like:
devid 2 size 0 used 0 last seen as
/dev/loop1***MISSING***"last seen as" could just be "previously". Or, to make it even clearer that this is just a hint to help the user understand which device is missing, maybe something like "(last mounted as
/dev/loop1)".
My 2¢:
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 ***MISSING*** (last seen as /dev/loop1)
I suggest to swap MISSING and 'last seen as...' part, because I think that the most important part of the message is MISSING.
Quoted 2 lines
Graham
Signature · 2 lines
gpg @keyserver.linux.it: Goffredo Baroncelli <kreijackATinwind.it> Key fingerprint BBF5 1610 0B64 DAC6 5F7D 17B2 0EDA 9B37 8B82 E0B5
Quoted 11 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:
Quoted 7 lines
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.
Looks better. How does this fair in the case of unmounted btrfs? Because btrfs fi show is supposed to work on an unmounted btrfs to help find btrfs devices.
Thx, Anand
Quoted 39 lines
Signed-off-by Nikolay Borisov <[email protected]>--- 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 ; }
Quoted 17 lines · Anand Jain
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/loop0devid 2 size 0 used 0 path/dev/loop1***MISSING***
Quoted 6 lines
Quoted 2 lines
This is a lot more usable output as it presents the user with the id of the missing device and its path.
Looks better. How does this fair in the case of unmounted btrfs? Because btrfs fi show is supposed to work on an unmounted btrfs to help find btrfs devices.
On unmounted fs the output is unchanged - i.e we simply print "missing device" because there is no way to derive the name of the missing device. Check print_one_uuid for reference.
<snip>
Quoted 12 lines · Nikolay Borisov
Quoted 9 lines · Anand Jain
Quoted 8 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 missing
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
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/loop0devid 2 size 0 used 0 path/dev/loop1***MISSING***
This change has to percolate to xfstests as well. I think btrfs/197, btrfs/198 and btrfs/003 depends on the existing format. IMO those test cases still have to be backward btrfs-progs compatible.
Thanks, Anand
Quoted 14 lines
Quoted 7 lines
Quoted 3 lines
This is a lot more usable output as it presents the user with the id of the missing device and its path.
Looks better. How does this fair in the case of unmounted btrfs? Because btrfs fi show is supposed to work on an unmounted btrfs to help find btrfs devices.
On unmounted fs the output is unchanged - i.e we simply print "missing device" because there is no way to derive the name of the missing device. Check
print_one_uuidfor reference.<snip>
Quoted 22 lines · Anand Jain
Quoted 12 lines · Nikolay Borisov
Quoted 9 lines · Anand Jain
Quoted 8 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 missingQuoted 7 lines
Quoted 7 lines
Quoted 7 lines
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/loop0devid 2 size 0 used 0 path/dev/loop1***MISSING***
Quoted 3 lines
This change has to percolate to xfstests as well. I think btrfs/197, btrfs/198 and btrfs/003 depends on the existing format. IMO those test cases still have to be backward btrfs-progs compatible.
Actually it's only btrfs/197, I will fix it.
Quoted 19 lines
Thanks, Anand
Quoted 14 lines
Quoted 7 lines
Quoted 3 lines
This is a lot more usable output as it presents the user with the id of the missing device and its path.
Looks better. How does this fair in the case of unmounted btrfs? Because btrfs fi show is supposed to work on an unmounted btrfs to help find btrfs devices.
On unmounted fs the output is unchanged - i.e we simply print "missing device" because there is no way to derive the name of the missing device. Check
print_one_uuidfor reference.<snip>
Quoted 8 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 missing
Quoted 7 lines
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***
There was a discussion regarding the output, so what's the last version? The path is not always available, so how does the output look like in that case? I'd vote against the *** markers and rather establish some parseable format, like
devid 2 size 0 used 0 MISSING (last: /dev/loop1)
The path is optional so it would bebetter to put it at the end.
Quoted 8 lines · David Sterba
There was a discussion regarding the output, so what's the last version? The path is not always available, so how does the output look like in that case? I'd vote against the *** markers and rather establish some parseable format, like
devid 2 size 0 used 0 MISSING (last:
/dev/loop1)The path is optional so it would bebetter to put it at the end.
I'm fine with this format, will send updated patches.
Quoted 1 line · David Sterba
devid 2 size 0 used 0 MISSING (last:
/dev/loop1)
unfortunately that 'last:' is a bit cryptic, OTOH 'last seen as' sounds a bit verbose. So I'd rather leave it as :
devid 2 size 0 used 0 path /dev/foo MISSING
In case we don't have a path for the device then the output would be :
devid 2 size 0 used 0 path MISSING
I think that's simple enough.