diff options
author | David Sterba <dsterba@suse.com> | 2023-12-01 01:58:56 +0100 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2023-12-01 02:08:37 +0100 |
commit | e9a66cde911e69f104c04cff64dc7c5f619b2ed2 (patch) | |
tree | 7bd54763ba5634652676245bcffdca80a4fcec4c | |
parent | 9da7e92af9e0165d5eab4ef4ab29d724da5c053a (diff) | |
download | btrfs-progs-e9a66cde911e69f104c04cff64dc7c5f619b2ed2.tar.gz |
btrfs-progs: use get_sysfs_proto_supported() in device_get_zone_unusable()
Use the sysfs helper to read u64 values of the zoned stats.
Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r-- | common/device-utils.c | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/common/device-utils.c b/common/device-utils.c index a34770f7..680fba6f 100644 --- a/common/device-utils.c +++ b/common/device-utils.c @@ -437,29 +437,25 @@ int device_get_queue_param(const char *file, const char *param, char *buf, size_ */ u64 device_get_zone_unusable(int fd, u64 flags) { - char buf[64]; - int sys_fd; - u64 unusable = DEVICE_ZONE_UNUSABLE_UNKNOWN; + int ret; + u64 unusable; /* Don't report it for a regular fs */ - sys_fd = sysfs_open_fsid_file(fd, "features/zoned"); - if (sys_fd < 0) + ret = sysfs_open_fsid_file(fd, "features/zoned"); + if (ret < 0) return DEVICE_ZONE_UNUSABLE_UNKNOWN; - close(sys_fd); - sys_fd = -1; + close(ret); + ret = -1; if ((flags & BTRFS_BLOCK_GROUP_DATA) == BTRFS_BLOCK_GROUP_DATA) - sys_fd = sysfs_open_fsid_file(fd, "allocation/data/bytes_zone_unusable"); + ret = sysfs_read_fsid_file_u64(fd, "allocation/data/bytes_zone_unusable", &unusable); else if ((flags & BTRFS_BLOCK_GROUP_METADATA) == BTRFS_BLOCK_GROUP_METADATA) - sys_fd = sysfs_open_fsid_file(fd, "allocation/metadata/bytes_zone_unusable"); + ret = sysfs_read_fsid_file_u64(fd, "allocation/metadata/bytes_zone_unusable", &unusable); else if ((flags & BTRFS_BLOCK_GROUP_SYSTEM) == BTRFS_BLOCK_GROUP_SYSTEM) - sys_fd = sysfs_open_fsid_file(fd, "allocation/system/bytes_zone_unusable"); + ret = sysfs_read_fsid_file_u64(fd, "allocation/system/bytes_zone_unusable", &unusable); - if (sys_fd < 0) + if (ret < 0) return DEVICE_ZONE_UNUSABLE_UNKNOWN; - sysfs_read_file(sys_fd, buf, sizeof(buf)); - unusable = strtoull(buf, NULL, 10); - close(sys_fd); return unusable; } |