btrfs-progs: fix the uuid report in "btrfs subvolume list -u"
PATCH 2/2 btrfs-progs: misc-tests: add a test case to make sure uuid is correctly reported
In reply to Qu WenruoThe new test case will execute "btrfs subvolume list -u" on the newly create btrfs.
Since the v0 root item is already deprecated for a long time, newly created btrfs should be already using the new root item, thus "btrfs subvolume list -u" should always report the correct uuid.
The test case relies on external program "uuidparse" which should be provided by util-linux.
--- .../056-subvolume-list-uuid/test.sh | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 tests/misc-tests/056-subvolume-list-uuid/test.sh
tests/misc-tests/056-subvolume-list-uuid/test.sh new file +28 -0
@@ -0,0 +1,28 @@ +#!/bin/bash +# +# Make sure "btrfs subvolume list -u" shows uuid correctly + +source "$TEST_TOP/common" + +check_prereq mkfs.btrfs +check_prereq btrfs +check_global_prereq uuidparse + +setup_root_helper +prepare_test_dev + +tmp=$(_mktemp_dir list_uuid) + +run_check_mkfs_test_dev +run_check_mount_test_dev +run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "$TEST_MNT/subv1" +run_check_stdout $SUDO_HELPER "$TOP/btrfs" subvolume list -u "$TEST_MNT" |\ + cut -d\ -f9 > "$tmp/output" + +result=$(cat "$tmp/output" | uuidparse -o TYPE -n) +rm -rf -- "$tmp" + +if [ "$result" == "invalid" ]; then + _fail "subvolume list failed to report uuid" +fi +run_check_umount_test_dev
Signature · 1 line
2.39.0
PATCH 1/2 btrfs-progs: fix the wrong timestamp and UUID check for root items
In reply to Qu Wenruo[BUG]
Since commit d729048be6ef ("btrfs-progs: stop using btrfs_root_item_v0"), "btrfs subvolume list" not longer correctly report UUID nor timestamp, while older (btrfs-progs v6.0.2) still works correct:
v6.0.2:
# btrfs subv list -u /mnt/btrfs/ ID 256 gen 12 top level 5 uuid ed4af580-d512-2644-b392-2a71aaeeb99e path subv1 ID 257 gen 13 top level 5 uuid a22ccba7-0a0a-a94f-af4b-5116ab58bb61 path subv2
v6.1:
# ./btrfs subv list -u /mnt/btrfs/ ID 256 gen 12 top level 5 uuid - path subv1 ID 257 gen 13 top level 5 uuid - path subv2
[CAUSE]
Commit d729048be6ef ("btrfs-progs: stop using btrfs_root_item_v0") removed old btrfs_root_item_v0, but incorrectly changed the check for v0 root item.
Now we will treat v0 root items as latest root items, causing possible out-of-bound access. while treat current root items as older v0 root items, ignoring the UUID nor timestamp.
[FIX]
Fix the bug by using correct checks, and add extra comments on the branches.
Issue: #562
--- cmds/subvolume-list.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
cmds/subvolume-list.c +9 -2
@@ -870,14 +870,21 @@ static int list_subvol_search(int fd, struct rb_root *root_lookup) ri = (struct btrfs_root_item *)(args.buf + off); gen =btrfs_root_generation (ri); flags =btrfs_root_flags (ri); -if (sh.len < -sizeof (struct btrfs_root_item )) { +if (sh.len >=sizeof (struct btrfs_root_item )) { +/* +* The new full btrfs_root_item with +* timestamp and UUID. +*/ otime =btrfs_stack_timespec_sec (&ri->otime); ogen =btrfs_root_otransid (ri);memcpy (uuid, ri->uuid,BTRFS_UUID_SIZE );memcpy (puuid, ri->parent_uuid,BTRFS_UUID_SIZE );memcpy (ruuid, ri->received_uuid,BTRFS_UUID_SIZE ); }else { +/* +* The old v0 root item, which doesn't +* has timestamp nor UUID. +*/ otime =0 ; ogen =0 ;memset (uuid,0 ,BTRFS_UUID_SIZE );
Signature · 1 line
2.39.0
cover btrfs-progs: fix the uuid report in "btrfs subvolume list -u"
There is a regression caused by commit d729048be6ef ("btrfs-progs: stop using btrfs_root_item_v0").
Just fix it and add a simple test case for it.
Qu Wenruo (2):
btrfs-progs: fix the wrong timestamp and UUID check for root items
btrfs-progs: misc-tests: add a test case to make sure uuid is
correctly reported
cmds/subvolume-list.c | 11 ++++++-- .../056-subvolume-list-uuid/test.sh | 28 +++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) create mode 100755 tests/misc-tests/056-subvolume-list-uuid/test.sh
Signature · 1 line
2.39.0
Re: [PATCH 1/2] btrfs-progs: fix the wrong timestamp and UUID check for root items
In reply to Qu WenruoQuoted 54 lines · Qu Wenruo
[BUG]
Since commitd729048be6ef("btrfs-progs: stop usingbtrfs_root_item_v0"), "btrfs subvolume list" not longer correctly report UUID nor timestamp, while older (btrfs-progs v6.0.2) still works correct:v6.0.2:
# btrfs subv list -u /mnt/btrfs/ ID 256 gen 12 top level 5 uuid ed4af580-d512-2644-b392-2a71aaeeb99e path subv1 ID 257 gen 13 top level 5 uuid a22ccba7-0a0a-a94f-af4b-5116ab58bb61 path subv2v6.1:
# ./btrfs subv list -u /mnt/btrfs/ ID 256 gen 12 top level 5 uuid - path subv1 ID 257 gen 13 top level 5 uuid - path subv2[CAUSE]
Commitd729048be6ef("btrfs-progs: stop usingbtrfs_root_item_v0") removed oldbtrfs_root_item_v0, but incorrectly changed the check for v0 root item.Now we will treat v0 root items as latest root items, causing possible out-of-bound access. while treat current root items as older v0 root items, ignoring the UUID nor timestamp.
[FIX]
Fix the bug by using correct checks, and add extra comments on the branches.Issue: #562
Fixes d729048be6ef ("btrfs-progs: stop using btrfs_root_item_v0")Signed-off-by Qu Wenruo <[email protected]>--- cmds/subvolume-list.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)cmds/subvolume-list.c +5
-2@@ -870,14 +870,21 @@ static int list_subvol_search(int fd, struct rb_root *root_lookup) ri = (struct btrfs_root_item *)(args.buf + off); gen =btrfs_root_generation (ri); flags =btrfs_root_flags (ri); -if (sh.len < -sizeof (struct btrfs_root_item )) { +if (sh.len >=sizeof (struct btrfs_root_item )) { +/* +* The new full btrfs_root_item with +* timestamp and UUID. +*/
cmds/subvolume-list.c static int list_subvol_search(int fd, struct rb_root *root_lookup) · line 887
Quoted 10 lines
cmds/subvolume-list.c +4
-0otime =btrfs_stack_timespec_sec (&ri->otime); ogen =btrfs_root_otransid (ri);memcpy (uuid, ri->uuid,BTRFS_UUID_SIZE );memcpy (puuid, ri->parent_uuid,BTRFS_UUID_SIZE );memcpy (ruuid, ri->received_uuid,BTRFS_UUID_SIZE ); }else { +/* +* The old v0 root item, which doesn't +* has timestamp nor UUID. +*/
Quoted 3 lines
cmds/subvolume-list.c +0
-0otime =0 ; ogen =0 ;memset (uuid,0 ,BTRFS_UUID_SIZE );
Re: [PATCH 1/2] btrfs-progs: fix the wrong timestamp and UUID check for root items
In reply to Qu WenruoQuoted 66 lines · Qu Wenruo
[BUG]
Since commitd729048be6ef("btrfs-progs: stop usingbtrfs_root_item_v0"), "btrfs subvolume list" not longer correctly report UUID nor timestamp, while older (btrfs-progs v6.0.2) still works correct:v6.0.2:
# btrfs subv list -u /mnt/btrfs/ ID 256 gen 12 top level 5 uuid ed4af580-d512-2644-b392-2a71aaeeb99e path subv1 ID 257 gen 13 top level 5 uuid a22ccba7-0a0a-a94f-af4b-5116ab58bb61 path subv2v6.1:
# ./btrfs subv list -u /mnt/btrfs/ ID 256 gen 12 top level 5 uuid - path subv1 ID 257 gen 13 top level 5 uuid - path subv2[CAUSE]
Commitd729048be6ef("btrfs-progs: stop usingbtrfs_root_item_v0") removed oldbtrfs_root_item_v0, but incorrectly changed the check for v0 root item.Now we will treat v0 root items as latest root items, causing possible out-of-bound access. while treat current root items as older v0 root items, ignoring the UUID nor timestamp.
[FIX]
Fix the bug by using correct checks, and add extra comments on the branches.Issue: #562
Fixes d729048be6ef ("btrfs-progs: stop using btrfs_root_item_v0")Signed-off-by Qu Wenruo <[email protected]>--- cmds/subvolume-list.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)cmds/subvolume-list.c +9
-3@@ -870,14 +870,21 @@ static int list_subvol_search(int fd, struct rb_root *root_lookup) ri = (struct btrfs_root_item *)(args.buf + off); gen =btrfs_root_generation (ri); flags =btrfs_root_flags (ri); -if (sh.len < -sizeof (struct btrfs_root_item )) { +if (sh.len >=sizeof (struct btrfs_root_item )) { +/* +* The new full btrfs_root_item with +* timestamp and UUID. +*/ otime =btrfs_stack_timespec_sec (&ri->otime); ogen =btrfs_root_otransid (ri);memcpy (uuid, ri->uuid,BTRFS_UUID_SIZE );memcpy (puuid, ri->parent_uuid,BTRFS_UUID_SIZE );memcpy (ruuid, ri->received_uuid,BTRFS_UUID_SIZE ); }else { +/* +* The old v0 root item, which doesn't +* has timestamp nor UUID. +*/ otime =0 ; ogen =0 ;memset (uuid,0 ,BTRFS_UUID_SIZE ); --
Quoted 2 lines
2.39.0
Resolves: rhbz#2156710
Signature · 1 line
真実はいつも一つ!/ Always, there's only one truth!
Re: [PATCH 2/2] btrfs-progs: misc-tests: add a test case to make sure uuid is correctly reported
In reply to Qu WenruoQuoted 52 lines · Qu Wenruo
The new test case will execute "btrfs subvolume list -u" on the newly create btrfs.
Since the v0 root item is already deprecated for a long time, newly created btrfs should be already using the new root item, thus "btrfs subvolume list -u" should always report the correct uuid.
The test case relies on external program "uuidparse" which should be provided by util-linux.
Signed-off-by Qu Wenruo <[email protected]>--- .../056-subvolume-list-uuid/test.sh | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 tests/misc-tests/056-subvolume-list-uuid/test.shtests/misc-tests/056-subvolume-list-uuid/test.sh new file +28
-1@@ -0,0 +1,28 @@ +#!/bin/bash +# +# Make sure "btrfs subvolume list -u" shows uuid correctly + +source "$TEST_TOP/common" + +check_prereq mkfs.btrfs +check_prereq btrfs +check_global_prereq uuidparse + +setup_root_helper +prepare_test_dev + +tmp=$(_mktemp_dir list_uuid) + +run_check_mkfs_test_dev +run_check_mount_test_dev +run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "$TEST_MNT/subv1" +run_check_stdout $SUDO_HELPER "$TOP/btrfs" subvolume list -u "$TEST_MNT" |\ + cut -d\ -f9 > "$tmp/output" + +result=$(cat "$tmp/output" | uuidparse -o TYPE -n) +rm -rf -- "$tmp" + +if [ "$result" == "invalid" ]; then + _fail "subvolume list failed to report uuid" +fi +run_check_umount_test_dev --
Quoted 2 lines
2.39.0
Signature · 1 line
真実はいつも一つ!/ Always, there's only one truth!
Quoted 9 lines · Qu Wenruo
There is a regression caused by commit
d729048be6ef("btrfs-progs: stop usingbtrfs_root_item_v0").Just fix it and add a simple test case for it.
Qu Wenruo (2):
btrfs-progs: fix the wrong timestamp and UUID check for root items
btrfs-progs: misc-tests: add a test case to make sure uuid is
correctly reported
Added to devel, thanks.