From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: Naohiro Aota <naohiro.aota@wdc.com>, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH v3 05/10] btrfs-progs: mkfs: align byte_count with sectorsize and zone size
Date: Wed, 22 May 2024 16:19:09 +0930 [thread overview]
Message-ID: <fdc34db2-b6a4-49ee-88e8-26c8f943d447@gmx.com> (raw)
In-Reply-To: <d959127a-d0f0-4444-a69a-0ffa1002d5f1@gmx.com>
在 2024/5/22 16:13, Qu Wenruo 写道:
>
>
> 在 2024/5/22 15:32, Naohiro Aota 写道:
>> While "byte_count" is eventually rounded down to sectorsize at
>> make_btrfs()
>> or btrfs_add_to_fs_id(), it would be better round it down first and do
>> the
>> size checks not to confuse the things.
>>
>> Also, on a zoned device, creating a btrfs whose size is not aligned to
>> the
>> zone boundary can be confusing. Round it down further to the zone
>> boundary.
>>
>> The size calculation with a source directory is also tweaked to be
>> aligned.
>>
>> Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
>> ---
>> mkfs/main.c | 11 +++++++++--
>> 1 file changed, 9 insertions(+), 2 deletions(-)
>>
>> diff --git a/mkfs/main.c b/mkfs/main.c
>> index a437ecc40c7f..baf889873b41 100644
>> --- a/mkfs/main.c
>> +++ b/mkfs/main.c
>> @@ -1591,6 +1591,12 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
>> min_dev_size = btrfs_min_dev_size(nodesize, mixed,
>> opt_zoned ? zone_size(file) : 0,
>> metadata_profile, data_profile);
>> + if (byte_count) {
>> + byte_count = round_down(byte_count, sectorsize);
>> + if (opt_zoned)
>> + byte_count = round_down(byte_count, zone_size(file));
>> + }
>> +
>> /*
>> * Enlarge the destination file or create a new one, using the size
>> * calculated from source dir.
>> @@ -1624,12 +1630,13 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
>> * Or we will always use source_dir_size calculated for mkfs.
>> */
>> if (!byte_count)
>> - byte_count = device_get_partition_size_fd_stat(fd,
>> &statbuf);
>> + byte_count =
>> round_up(device_get_partition_size_fd_stat(fd, &statbuf),
>> + sectorsize);
My bad, forgot this one too.
We should round_down() here.
As if we have a 512 bytes blocked device, and the partition is only
aligned to 512 bytes, this can make the last sector go beyond device
boundary.
Thanks,
Qu
>> source_dir_size = btrfs_mkfs_size_dir(source_dir, sectorsize,
>> min_dev_size, metadata_profile, data_profile);
>> if (byte_count < source_dir_size) {
>> if (S_ISREG(statbuf.st_mode)) {
>> - byte_count = source_dir_size;
>> + byte_count = round_up(source_dir_size, sectorsize);
>
> I believe we should round up not round down, if we're using --rootdir
> option.
>
> As smaller size would only be more possible to hit ENOSPC.
>
> Otherwise looks good to me.
>
> Thanks,
> Qu
>> } else {
>> warning(
>> "the target device %llu (%s) is smaller than the calculated source
>> directory size %llu (%s), mkfs may fail",
>
next prev parent reply other threads:[~2024-05-22 6:49 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-22 6:02 [PATCH v3 00/10] btrfs-progs: zoned: proper "mkfs.btrfs -b" support Naohiro Aota
2024-05-22 6:02 ` [PATCH v3 01/10] btrfs-progs: rename block_count to byte_count Naohiro Aota
2024-05-22 6:02 ` [PATCH v3 02/10] btrfs-progs: mkfs: remove duplicated device size check Naohiro Aota
2024-05-22 6:02 ` [PATCH v3 03/10] btrfs-progs: mkfs: unify zoned mode minimum size calc into btrfs_min_dev_size() Naohiro Aota
2024-05-22 6:02 ` [PATCH v3 04/10] btrfs-progs: mkfs: fix minimum size calculation for zoned mode Naohiro Aota
2024-05-22 6:02 ` [PATCH v3 05/10] btrfs-progs: mkfs: align byte_count with sectorsize and zone size Naohiro Aota
2024-05-22 6:43 ` Qu Wenruo
2024-05-22 6:49 ` Qu Wenruo [this message]
2024-05-22 6:53 ` Naohiro Aota
2024-05-22 7:38 ` Naohiro Aota
2024-05-22 6:02 ` [PATCH v3 06/10] btrfs-progs: support byte length for zone resetting Naohiro Aota
2024-05-22 6:02 ` [PATCH v3 07/10] btrfs-progs: test: add nullb setup functions Naohiro Aota
2024-05-22 6:02 ` [PATCH v3 08/10] btrfs-progs: test: add test for zone resetting Naohiro Aota
2024-05-22 6:02 ` [PATCH v3 09/10] btrfs-progs: test: use nullb helper and smaller zone size Naohiro Aota
2024-05-22 6:02 ` [PATCH v3 10/10] btrfs-progs: test: use nullb helpers in 031-zoned-bgt Naohiro Aota
2024-05-22 6:50 ` [PATCH v3 00/10] btrfs-progs: zoned: proper "mkfs.btrfs -b" support Qu Wenruo
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=fdc34db2-b6a4-49ee-88e8-26c8f943d447@gmx.com \
--to=quwenruo.btrfs@gmx.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=naohiro.aota@wdc.com \
/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