linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/6] btrfs-progs: device_get_partition_size*() enhancement and cleanup
@ 2025-08-06  4:48 Qu Wenruo
  2025-08-06  4:48 ` [PATCH v2 1/6] btrfs-progs: fix the wrong size from device_get_partition_size_sysfs() Qu Wenruo
                   ` (6 more replies)
  0 siblings, 7 replies; 20+ messages in thread
From: Qu Wenruo @ 2025-08-06  4:48 UTC (permalink / raw)
  To: linux-btrfs

[CHANGELOG]
v2:
- Include and update Zoltan's fix to device_get_partition_size_sysfs()
  The "/dev/block/<device>/size" attribute is always in sector unit
  (512Bytes), independent from the physical device's block size.

  So the fix is pretty straightforward, just do the left shift before
  returning.

  And update the commit message to properly reflect that.

- Use s64 as the return value of device_get_partition_size*()
  Kernel ensures the max sector number of a device is LLONG_MAX >> 9,
  so s64 is more than enough to cover the device size, and we are safe
  to use the minus part to pass errors.

- Extra error handling when device_get_partition_size*() failed
  Ouput an error message and exit.
  Most callers are already doing that correctly but some are not.

- Keep the sysfs method as the fallback way to grab device size
  Since the device_get_partition_size_sysfs() can be easily fixed, no
  need to use complex path search for sector size.

- Add a new cleanup to remove is_vol_small()

Zoltan recently sent a fix to solve the bug in
device_get_partition_size_sysfs(), which is causing problems for "btrfs
dev usage".

It turns out that, the bug is just the attribute
"/sys/block/<device>/size" is in sector unit (512B), not in bytes.

So fix the bug first by reporting the correct size in bytes.

Then remove several unused functions exposed during the error handling
cleanup.

Finally cleanup device_get_partition_size*() helpers to provide a proper
error handling, not just return 0 for errors, but proper minus erro
code, and extra overflow check.

Qu Wenruo (5):
  btrfs-progs: remove the unnecessary device_get_partition_size() call
  btrfs-progs: remove device_get_partition_size_fd()
  btrfs-progs: remove is_vol_small() helper
  btrfs-progs: add error handling for device_get_partition_size()
  btrfs-progs: add error handling for
    device_get_partition_size_fd_stat()

Zoltan Racz (1):
  btrfs-progs: fix the wrong size from device_get_partition_size_sysfs()

 check/main.c            |  8 ++++-
 check/mode-lowmem.c     |  9 ++++-
 cmds/filesystem-usage.c | 15 ++++++---
 cmds/replace.c          | 14 ++++++--
 common/device-utils.c   | 74 ++++++++++++++++++-----------------------
 common/device-utils.h   |  5 ++-
 kernel-shared/volumes.c | 11 ++++--
 kernel-shared/zoned.c   | 18 +++++++---
 mkfs/common.c           | 39 ++++------------------
 mkfs/common.h           |  1 -
 mkfs/main.c             | 14 +++++---
 11 files changed, 110 insertions(+), 98 deletions(-)

--
2.50.1


^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2025-08-08 17:07 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-06  4:48 [PATCH v2 0/6] btrfs-progs: device_get_partition_size*() enhancement and cleanup Qu Wenruo
2025-08-06  4:48 ` [PATCH v2 1/6] btrfs-progs: fix the wrong size from device_get_partition_size_sysfs() Qu Wenruo
2025-08-08  5:47   ` Anand Jain
2025-08-08  6:05     ` Qu Wenruo
2025-08-08 15:23       ` David Sterba
2025-08-06  4:48 ` [PATCH v2 2/6] btrfs-progs: remove the unnecessary device_get_partition_size() call Qu Wenruo
2025-08-08  5:53   ` Anand Jain
2025-08-06  4:48 ` [PATCH v2 3/6] btrfs-progs: remove device_get_partition_size_fd() Qu Wenruo
2025-08-08  5:59   ` Anand Jain
2025-08-06  4:48 ` [PATCH v2 4/6] btrfs-progs: remove is_vol_small() helper Qu Wenruo
2025-08-08  6:11   ` Anand Jain
2025-08-06  4:48 ` [PATCH v2 5/6] btrfs-progs: add error handling for device_get_partition_size() Qu Wenruo
2025-08-08  7:23   ` Anand Jain
2025-08-08  9:26     ` Anand Jain
2025-08-08  9:31       ` Qu Wenruo
2025-08-08 15:37         ` David Sterba
2025-08-08 16:28         ` Boris Burkov
2025-08-06  4:48 ` [PATCH v2 6/6] btrfs-progs: add error handling for device_get_partition_size_fd_stat() Qu Wenruo
2025-08-08  7:27   ` Anand Jain
2025-08-08 17:07 ` [PATCH v2 0/6] btrfs-progs: device_get_partition_size*() enhancement and cleanup David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).