!48 [sync] PR-47: btrfs-progs: fi show: canonicalize path when using blkid and -d

From: @openeuler-sync-bot 
Reviewed-by: @swf504 
Signed-off-by: @swf504
This commit is contained in:
openeuler-ci-bot 2024-07-01 12:20:43 +00:00 committed by Gitee
commit 1be905cf95
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 80 additions and 1 deletions

View File

@ -0,0 +1,75 @@
From cb740b3dfb97f09e458c4e0bcfd87a6f5d1e7a33 Mon Sep 17 00:00:00 2001
From: David Sterba <dsterba@suse.com>
Date: Wed, 31 Jan 2024 10:58:17 +0100
Subject: [PATCH] btrfs-progs: fi show: canonicalize path when using blkid and
-d
There's a report that passing raw device mapper path and -d don't work
together:
yyy@xxx ~ $ sudo btrfs filesystem show /dev/dm-0
Label: none uuid: a7fbb8d6-ec5d-4e88-bd8b-c686553e0dc7
Total devices 1 FS bytes used 144.00KiB
devid 1 size 256.00MiB used 88.00MiB path /dev/mapper/da0972636816-LogVol00
With --all-devices
yyy@xxx ~ $ sudo btrfs filesystem show --all-devices /dev/dm-0
ERROR: not a valid btrfs filesystem: /dev/dm-0
Where dm-0 corresponds to the LogVol00 device from above.
Passing the option -d skips some steps but still uses the real path of
the device that is required for scanning and identification, while
blkid uses the canonicalized path.
The combination of raw device name and -d was not handled as the raw
path is not in cache and thus not recognized. Canonicalization fixes
that although this changes the device name in the output.
Issue: #732
Signed-off-by: David Sterba <dsterba@suse.com>
---
cmds/filesystem.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/cmds/filesystem.c b/cmds/filesystem.c
index 1b444b8..4967bba 100644
--- a/cmds/filesystem.c
+++ b/cmds/filesystem.c
@@ -708,6 +708,7 @@ static int cmd_filesystem_show(const struct cmd_struct *cmd,
struct btrfs_fs_devices *fs_devices;
struct btrfs_root *root = NULL;
char *search = NULL;
+ char *canon_path = NULL;
int ret;
/* default, search both kernel and udev */
int where = -1;
@@ -789,8 +790,15 @@ static int cmd_filesystem_show(const struct cmd_struct *cmd,
}
}
- if (where == BTRFS_SCAN_LBLKID)
+ if (where == BTRFS_SCAN_LBLKID) {
+ /*
+ * Blkid needs canonicalized paths, eg. when the /dev/dm-0 is
+ * passed on command line.
+ */
+ canon_path = path_canonicalize(search);
+ search = canon_path;
goto devs_only;
+ }
/* show mounted btrfs */
ret = btrfs_scan_kernel(search, unit_mode);
@@ -849,6 +857,7 @@ devs_only:
free_fs_devices(fs_devices);
}
out:
+ free(canon_path);
if (root)
close_ctree(root);
free_seen_fsid(seen_fsid_hash);
--
2.43.0

View File

@ -1,6 +1,6 @@
Name: btrfs-progs
Version: 6.6.3
Release: 7
Release: 8
Summary: btrfs userspace programs
License: GPLv2 and GPL+ and LGPL-2.1+ and GPL-3.0+ and LGPL-2.1 and MIT
URL: https://btrfs.wiki.kernel.org/index.php/Main_Page
@ -12,6 +12,7 @@ Patch0003: 0003-fix-memory-leak-on-exit-path-in-table-vprintf.patch
Patch0004: 0004-btrfs-progs-scrub-status-only-report-limits-if-at-le.patch
Patch0005: 0005-btrfs-progs-fix-freeing-of-device-after-error-in-btr.patch
Patch0006: 0006-fix-double-free-on-error-in-read_raid56.patch
Patch0007: 0007-btrfs-progs-fi-show-canonicalize-path-when-using-blk.patch
BuildRequires: python3-devel >= 3.4
BuildRequires: libacl-devel, e2fsprogs-devel, libblkid-devel, libuuid-devel, zlib-devel, libzstd-devel, lzo-devel, systemd-devel
@ -77,6 +78,9 @@ make mandir=%{_mandir} bindir=%{_sbindir} libdir=%{_libdir} incdir=%{_includedir
%{_mandir}/man8/*.gz
%changelog
* Mon Jul 1 2024 liuh <liuhuan01@kylinos.cn> - 6.6.3-8
- btrfs-progs: fi show: canonicalize path when using blkid and -d
* Mon Jun 24 2024 zhangyaqi <zhangyaqi@kylinos.cn> - 6.6.3-7
- fix double free on error in read_raid56()