From: Luis Chamberlain <[email protected]>

This moves the code which fetches the chunk_sectors into a helper.
Yes, this could in theory be used by non-zoned devices but that's
not the case yet, so no need to make this a generic routine.

This makes it clear what this is doing, and helps us make the
subsequent changes easier to read.

Signed-off-by: Luis Chamberlain <[email protected]>
---
 lib/libf2fs_zoned.c | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/lib/libf2fs_zoned.c b/lib/libf2fs_zoned.c
index ce73b9a..1447181 100644
--- a/lib/libf2fs_zoned.c
+++ b/lib/libf2fs_zoned.c
@@ -146,35 +146,46 @@ int f2fs_get_zoned_model(int i)
        return 0;
 }
 
-int f2fs_get_zone_blocks(int i)
+uint64_t f2fs_get_zone_chunk_sectors(struct device_info *dev)
 {
-       struct device_info *dev = c.devices + i;
        uint64_t sectors;
        char str[PATH_MAX];
        FILE *file;
        int res;
 
-       /* Get zone size */
-       dev->zone_blocks = 0;
-
        res = get_sysfs_path(dev, "queue/chunk_sectors", str, sizeof(str));
        if (res != 0) {
                MSG(0, "\tError: Failed to get device sysfs attribute path\n");
-               return -1;
+               return 0;
        }
 
        file = fopen(str, "r");
        if (!file)
-               return -1;
+               return 0;
 
        memset(str, 0, sizeof(str));
        res = fscanf(file, "%s", str);
        fclose(file);
 
        if (res != 1)
-               return -1;
+               return 0;
 
        sectors = atol(str);
+       if (!sectors)
+               return 0;
+
+       return sectors;
+}
+
+int f2fs_get_zone_blocks(int i)
+{
+       struct device_info *dev = c.devices + i;
+       uint64_t sectors;
+
+       /* Get zone size */
+       dev->zone_blocks = 0;
+
+       sectors = f2fs_get_zone_chunk_sectors(dev);
        if (!sectors)
                return -1;
 
-- 
2.25.1



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

Reply via email to