From: Qu Wenruo <wqu@suse.com>
To: Anand Jain <anand.jain@oracle.com>, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH] btrfs-progs: mkfs: use path_canonicalize for input device
Date: Fri, 16 May 2025 11:13:00 +0930 [thread overview]
Message-ID: <87850150-493e-4c8e-8bbd-1bb36bc88b5e@suse.com> (raw)
In-Reply-To: <0d9762cf51f6e0e92ac56f02f44836d98af957d5.1747318570.git.anand.jain@oracle.com>
在 2025/5/15 23:46, Anand Jain 写道:
> Canonicalize the input device's path before using it.
> So that we show the device path that matches with the /proc/fs/
>
> Before:
> $ mkfs.btrfs -fq /dev/vg_fstests/lv1 /dev/sdb > /dev/null
>
> $ blkid --uuid c3bf2107-292d-4c7f-a288-0fa922ebd71a
> /dev/mapper/vg_fstests-lv1
>
> $ mount --verbose /dev/vg_fstests/lv1 /mnt/scratch
> mount: /dev/mapper/vg_fstests-lv1 mounted on /mnt/scratch.
>
> $ cat /proc/self/mounts | grep scratch
> /dev/vg_fstests/lv1 /mnt/scratch btrfs rw,relatime,space_cache=v2,subvolid=5,subvol=/ 0 0
>
> After:
> $ mkfs.btrfs -fq /dev/vg_fstests/lv1 /dev/sdb > /dev/null
>
> $ blkid --uuid c774b4a6-3ad2-4b15-834a-894dfc898aa9
> /dev/mapper/vg_fstests-lv1
>
> $ mount --verbose /dev/vg_fstests/lv1 /mnt/scratch
> mount: /dev/mapper/vg_fstests-lv1 mounted on /mnt/scratch.
>
> $ cat /proc/self/mounts | grep scratch
> /dev/mapper/vg_fstests-lv1 /mnt/scratch btrfs rw,relatime,space_cache=v2,subvolid=5,subvol=/ 0 0
I do not think this is the correct way to go.
It looks more like a bug in libblkid.
Please explain why the problem happens, not workaround it without any
reasons.
Thanks,
Qu
>
> Signed-off-by: Anand Jain <anand.jain@oracle.com>
> Link: https://lore.kernel.org/linux-btrfs/5f401c48-29f5-403e-8c39-50188028ad00@oracle.com/
> ---
> mkfs/main.c | 13 +++++++------
> 1 file changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/mkfs/main.c b/mkfs/main.c
> index 4c2ce98c784c..e6466d88313a 100644
> --- a/mkfs/main.c
> +++ b/mkfs/main.c
> @@ -1537,7 +1537,7 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
> }
>
> for (i = 0; i < device_count; i++) {
> - file = argv[optind++];
> + file = path_canonicalize(argv[optind++]);
>
> if (source_dir && path_exists(file) == 0)
> ret = 0;
> @@ -1553,7 +1553,7 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
> optind = saved_optind;
> device_count = argc - optind;
>
> - file = argv[optind++];
> + file = path_canonicalize(argv[optind++]);
> ssd = device_get_rotational(file);
> if (opt_zoned) {
> if (!zone_size(file)) {
> @@ -1752,7 +1752,7 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
> for (i = saved_optind; i < saved_optind + device_count; i++) {
> char *path;
>
> - path = argv[i];
> + path = path_canonicalize(argv[i]);
> ret = test_minimum_size(path, min_dev_size);
> if (ret < 0) {
> error("failed to check size for %s: %m", path);
> @@ -1816,7 +1816,8 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
> opt_oflags = O_RDWR;
> for (i = 0; i < device_count; i++) {
> if (opt_zoned &&
> - zoned_model(argv[optind + i - 1]) == ZONED_HOST_MANAGED) {
> + zoned_model(path_canonicalize(argv[optind + i - 1])) ==
> + ZONED_HOST_MANAGED) {
> opt_oflags |= O_DIRECT;
> break;
> }
> @@ -1824,7 +1825,7 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
>
> /* Start threads */
> for (i = 0; i < device_count; i++) {
> - prepare_ctx[i].file = argv[optind + i - 1];
> + prepare_ctx[i].file = path_canonicalize(argv[optind + i - 1]);
> prepare_ctx[i].byte_count = byte_count;
> prepare_ctx[i].dev_byte_count = byte_count;
> ret = pthread_create(&t_prepare[i], NULL, prepare_one_device,
> @@ -2198,7 +2199,7 @@ out:
> optind = saved_optind;
> device_count = argc - optind;
> while (device_count-- > 0) {
> - file = argv[optind++];
> + file = path_canonicalize(argv[optind++]);
> if (path_is_block_device(file) == 1)
> btrfs_register_one_device(file);
> }
next prev parent reply other threads:[~2025-05-16 1:43 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-15 14:16 [PATCH] btrfs-progs: mkfs: use path_canonicalize for input device Anand Jain
2025-05-16 1:43 ` Qu Wenruo [this message]
2025-05-20 10:53 ` Anand Jain
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87850150-493e-4c8e-8bbd-1bb36bc88b5e@suse.com \
--to=wqu@suse.com \
--cc=anand.jain@oracle.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox