diff mbox series

[v2,5/8] btrfs-progs: mkfs: check if byte_count is zone size aligned

Message ID 20240514182227.1197664-6-naohiro.aota@wdc.com (mailing list archive)
State New
Headers show
Series btrfs-progs: zoned: proper "mkfs.btrfs -b" support | expand

Commit Message

Naohiro Aota May 14, 2024, 6:22 p.m. UTC
Creating a btrfs whose size is not aligned to the zone boundary is
meaningless and allowing it can confuse users. Disallow creating it.

Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
---
 mkfs/main.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Qu Wenruo May 14, 2024, 10:56 p.m. UTC | #1
在 2024/5/15 03:52, Naohiro Aota 写道:
> Creating a btrfs whose size is not aligned to the zone boundary is
> meaningless and allowing it can confuse users. Disallow creating it.

Can we just round it down and gives a warning?

I'm pretty sure some users are used to just passing some numbers like
1000000 to "-b" option.

And it may also be a good idea to do the same rounddown for non-zoned fs.

Thanks,
Qu
>
> Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
> ---
>   mkfs/main.c | 5 +++++
>   1 file changed, 5 insertions(+)
>
> diff --git a/mkfs/main.c b/mkfs/main.c
> index a437ecc40c7f..faf397848cc4 100644
> --- a/mkfs/main.c
> +++ b/mkfs/main.c
> @@ -1655,6 +1655,11 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
>   		      opt_zoned ? "zoned mode " : "", min_dev_size);
>   		goto error;
>   	}
> +	if (byte_count && opt_zoned && !IS_ALIGNED(byte_count, zone_size(file))) {
> +		error("size %llu is not aligned to zone size %llu", byte_count,
> +		      zone_size(file));
> +		goto error;
> +	}
>
>   	for (i = saved_optind; i < saved_optind + device_count; i++) {
>   		char *path;
Naohiro Aota May 15, 2024, 3:43 p.m. UTC | #2
On Wed, May 15, 2024 at 08:26:56AM +0930, Qu Wenruo wrote:
> 
> 
> 在 2024/5/15 03:52, Naohiro Aota 写道:
> > Creating a btrfs whose size is not aligned to the zone boundary is
> > meaningless and allowing it can confuse users. Disallow creating it.
> 
> Can we just round it down and gives a warning?
> 
> I'm pretty sure some users are used to just passing some numbers like
> 1000000 to "-b" option.

Sure, that would be nice.

> 
> And it may also be a good idea to do the same rounddown for non-zoned fs.

So, round it towards the sector size (4KB)? In fact, we already do it when
we add a device to the FS.

https://github.com/kdave/btrfs-progs/blob/master/mkfs/common.c#L431
https://github.com/kdave/btrfs-progs/blob/master/common/device-scan.c#L144

Still, it would be nice to round it first and do the size checks. I'll
implement it.

> 
> Thanks,
> Qu
> > 
> > Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
> > ---
> >   mkfs/main.c | 5 +++++
> >   1 file changed, 5 insertions(+)
> > 
> > diff --git a/mkfs/main.c b/mkfs/main.c
> > index a437ecc40c7f..faf397848cc4 100644
> > --- a/mkfs/main.c
> > +++ b/mkfs/main.c
> > @@ -1655,6 +1655,11 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
> >   		      opt_zoned ? "zoned mode " : "", min_dev_size);
> >   		goto error;
> >   	}
> > +	if (byte_count && opt_zoned && !IS_ALIGNED(byte_count, zone_size(file))) {
> > +		error("size %llu is not aligned to zone size %llu", byte_count,
> > +		      zone_size(file));
> > +		goto error;
> > +	}
> > 
> >   	for (i = saved_optind; i < saved_optind + device_count; i++) {
> >   		char *path;
diff mbox series

Patch

diff --git a/mkfs/main.c b/mkfs/main.c
index a437ecc40c7f..faf397848cc4 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -1655,6 +1655,11 @@  int BOX_MAIN(mkfs)(int argc, char **argv)
 		      opt_zoned ? "zoned mode " : "", min_dev_size);
 		goto error;
 	}
+	if (byte_count && opt_zoned && !IS_ALIGNED(byte_count, zone_size(file))) {
+		error("size %llu is not aligned to zone size %llu", byte_count,
+		      zone_size(file));
+		goto error;
+	}
 
 	for (i = saved_optind; i < saved_optind + device_count; i++) {
 		char *path;