[PATCH 1/2] btrfs-progs: use btrfs_device_size() instead of device_get_partition_size_fd()
From: Naohiro Aota <naohiro.aota@wdc.com>
Date: 2021-09-22 07:53:51
Subsystem:
the rest · Maintainer:
Linus Torvalds
From: Naohiro Aota <naohiro.aota@wdc.com>
Date: 2021-09-22 07:53:51
Subsystem:
the rest · Maintainer:
Linus Torvalds
device_get_partition_size_fd() fails if we pass a regular file. This can happen when trying to create an emualted zoned btrfs on a regular file. Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com> --- kernel-shared/zoned.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/kernel-shared/zoned.c b/kernel-shared/zoned.c
index 75c6c53393ac..891a2c0aeef2 100644
--- a/kernel-shared/zoned.c
+++ b/kernel-shared/zoned.c@@ -267,6 +267,7 @@ static int report_zones(int fd, const char *file, u64 zone_bytes = zone_size(file); size_t rep_size; u64 sector = 0; + struct stat st; struct blk_zone_report *rep; struct blk_zone *zone; unsigned int i, n = 0;
@@ -291,11 +292,13 @@ static int report_zones(int fd, const char *file, exit(1); } - /* - * No need to use btrfs_device_size() here, since it is ensured - * that the file is block device. - */ - device_size = device_get_partition_size_fd(fd); + ret = fstat(fd, &st); + if (ret < 0) { + error("unable to stat %s: %m", file); + return -EIO; + } + + device_size = btrfs_device_size(fd, &st); if (device_size == 0) { error("zoned: failed to read size of %s: %m", file); exit(1);
--
2.33.0