diff options
author | Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com> | 2019-11-28 16:59:24 +0900 |
---|---|---|
committer | Jaegeuk Kim <jaegeuk@kernel.org> | 2019-12-09 17:23:19 -0800 |
commit | 6d7c7b785febcf9162dbfc607c50fb778983deb6 (patch) | |
tree | 710dd2f077292dcc91269aedeff10e6f0faa6f08 | |
parent | 512b8426acf1f146cf2f07cf680f1155d886ef94 (diff) | |
download | f2fs-tools-6d7c7b785febcf9162dbfc607c50fb778983deb6.tar.gz |
libf2fs_zoned: Introduce f2fs_report_zone() helper function
To prepare for write pointer consistency check by fsck, add
f2fs_report_zone() helper function which calls REPORT ZONE command to
get write pointer status of a single zone. The function is added to
lib/libf2fs_zoned which gathers zoned block device related functions.
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
-rw-r--r-- | include/f2fs_fs.h | 1 | ||||
-rw-r--r-- | lib/libf2fs_zoned.c | 33 |
2 files changed, 34 insertions, 0 deletions
diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h index a437379..1f7ef05 100644 --- a/include/f2fs_fs.h +++ b/include/f2fs_fs.h @@ -1299,6 +1299,7 @@ blk_zone_cond_str(struct blk_zone *blkz) extern int f2fs_get_zoned_model(int); extern int f2fs_get_zone_blocks(int); +extern int f2fs_report_zone(int, u_int64_t, void *); typedef int (report_zones_cb_t)(int i, void *, void *); extern int f2fs_report_zones(int, report_zones_cb_t *, void *); extern int f2fs_check_zones(int); diff --git a/lib/libf2fs_zoned.c b/lib/libf2fs_zoned.c index 8ad4171..5328c56 100644 --- a/lib/libf2fs_zoned.c +++ b/lib/libf2fs_zoned.c @@ -191,6 +191,33 @@ int f2fs_get_zone_blocks(int i) return 0; } +int f2fs_report_zone(int i, u_int64_t sector, void *blkzone) +{ + struct blk_zone *blkz = (struct blk_zone *)blkzone; + struct blk_zone_report *rep; + int ret = -1; + + rep = malloc(sizeof(struct blk_zone_report) + sizeof(struct blk_zone)); + if (!rep) { + ERR_MSG("No memory for report zones\n"); + return -ENOMEM; + } + + rep->sector = sector; + rep->nr_zones = 1; + ret = ioctl(c.devices[i].fd, BLKREPORTZONE, rep); + if (ret != 0) { + ret = -errno; + ERR_MSG("ioctl BLKREPORTZONE failed: errno=%d\n", errno); + goto out; + } + + *blkz = *(struct blk_zone *)(rep + 1); +out: + free(rep); + return ret; +} + #define F2FS_REPORT_ZONES_BUFSZ 524288 int f2fs_report_zones(int j, report_zones_cb_t *report_zones_cb, void *opaque) @@ -425,6 +452,12 @@ out: #else +int f2fs_report_zone(int i, u_int64_t sector, void *blkzone) +{ + ERR_MSG("%d: Unsupported zoned block device\n", i); + return -1; +} + int f2fs_report_zones(int i, report_zones_cb_t *report_zones_cb, void *opaque) { ERR_MSG("%d: Unsupported zoned block device\n", i); |