Skip to contentSkip to conversation

btrfs-progs: fi show: Print missing device for a mounted file system

PATCH In review Nikolay Borisov 2 participants 5 messages Mar 29, 2022 – Jul 18, 2022 Btrfs file system

lore
Share & tools
lore
#0 lore raw

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.

---

Resending this series as it seems to have fallen through the cracks.

 cmds/filesystem.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
cmds/filesystem.c +3 -4
index 7cd08fcd5f62..fe32838a25bf 100644
@@ -296,7 +296,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;
@@ -326,8 +325,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);
@@ -340,8 +341,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

#1 lore raw

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
new file mode 100755
index 000000000000..e24a85d05410
@@ -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
#2 lore raw

Re: [PATCH 2/2] btrfs-progs: tests: Add test for fi show

Quoted 4 lines · Nikolay Borisov

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.

There are some things to fix, even if it's just shell scripting there is a coding style to follow, and some testsuite specific requirements.

Quoted 19 lines
---
 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 +8 -0
new file mode 100755
index 000000000000..e24a85d05410
@@ -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

tests/cli-tests/016-fi-show-missing/test.sh line 18

Quoted 10 lines
tests/cli-tests/016-fi-show-missing/test.sh new file +10 -0
+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

I'd rather use "${loopdevs[@]}", also to add quoting around paths.

tests/cli-tests/016-fi-show-missing/test.sh line 20

Quoted 2 lines
tests/cli-tests/016-fi-show-missing/test.sh new file +2 -0
+# move the device, changing its path, simulating the device being missing
+mv $dev2 /dev/loop-non-existent

This fails if not run by root, so
run_check $SUDO_HELPER mv ...

tests/cli-tests/016-fi-show-missing/test.sh line 22

Quoted 2 lines
tests/cli-tests/016-fi-show-missing/test.sh new file +2 -0
+
+run_check $SUDO_HELPER mount -o degraded $dev1 $TEST_MNT

All variables must be quoted

run_check $SUDO_HELPER mount -o degraded "$dev1" "$TEST_MNT"

tests/cli-tests/016-fi-show-missing/test.sh line 24

Quoted 2 lines
tests/cli-tests/016-fi-show-missing/test.sh new file +2 -0
+
+if ! run_check_stdout $SUDO_HELPER "$TOP"/btrfs fi show $TEST_MNT | \

if ! run_check_stdout $SUDO_HELPER "$TOP"/btrfs filesystem show "$TEST_MNT" | \

no command shortcuts

tests/cli-tests/016-fi-show-missing/test.sh line 30

Quoted 6 lines
tests/cli-tests/016-fi-show-missing/test.sh new file +6 -0
+	grep -q "$dev2 MISSING"; then
+
+	_fail "Didn't find exact missing device"
+fi
+
+mv /dev/loop-non-existent $dev2

Again run_check $SUDO_HELPER

Quoted 7 lines
tests/cli-tests/016-fi-show-missing/test.sh new file +5 -0
+
+run_check $SUDO_HELPER umount $TEST_MNT
+
+cleanup_loopdevs
+
Signature · 1 line
2.17.1
#3 lore raw
In reply to Nikolay Borisov
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 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***

Quoted 4 lines

This is a lot more usable output as it presents the user with the id of the missing device and its path.

Ping

#4 lore raw
Quoted 19 lines · Nikolay Borisov
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 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***

Quoted 7 lines
Quoted 4 lines

This is a lot more usable output as it presents the user with the id of the missing device and its path.

Ping

Sorry for late reponse, added to devel, thanks.