On 04/01, Chao Yu wrote: > On 2019/3/27 15:54, Damien Le Moal wrote: > > Return an error if an unknown zoned model is reported for a device or > > if parsing of the device zoned model fails. Also add comments to > > briefly explain the zone models and what to do in the absence of a > > kernel reported zoned model for a device. > > > > Signed-off-by: Damien Le Moal <damien.lem...@wdc.com> > > --- > > include/f2fs_fs.h | 2 +- > > lib/libf2fs.c | 8 ++++++-- > > lib/libf2fs_zoned.c | 38 ++++++++++++++++++++++++++------------ > > 3 files changed, 33 insertions(+), 15 deletions(-) > > > > diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h > > index e073723..97ad774 100644 > > --- a/include/f2fs_fs.h > > +++ b/include/f2fs_fs.h > > @@ -1257,7 +1257,7 @@ blk_zone_cond_str(struct blk_zone *blkz) > > > > #endif > > > > -extern void f2fs_get_zoned_model(int); > > +extern int f2fs_get_zoned_model(int); > > extern int f2fs_get_zone_blocks(int); > > extern int f2fs_check_zones(int); > > extern int f2fs_reset_zones(int); > > diff --git a/lib/libf2fs.c b/lib/libf2fs.c > > index 60b84e0..5ca1bb0 100644 > > --- a/lib/libf2fs.c > > +++ b/lib/libf2fs.c > > @@ -925,8 +925,12 @@ int get_device_info(int i) > > } > > > > #if !defined(WITH_ANDROID) && defined(__linux__) > > - if (S_ISBLK(stat_buf->st_mode)) > > - f2fs_get_zoned_model(i); > > + if (S_ISBLK(stat_buf->st_mode)) { > > + if (f2fs_get_zoned_model(i) < 0) { > > + free(stat_buf); > > + return -1; > > + } > > Needs tabs here...
Applied. :) > > Otherwise it looks good to me. > > Reviewed-by: Chao Yu <yuch...@huawei.com> > > Thanks, > > > + } > > > > if (dev->zoned_model != F2FS_ZONED_NONE) { > > if (dev->zoned_model == F2FS_ZONED_HM) > > diff --git a/lib/libf2fs_zoned.c b/lib/libf2fs_zoned.c > > index 6e32f32..e396a95 100644 > > --- a/lib/libf2fs_zoned.c > > +++ b/lib/libf2fs_zoned.c > > @@ -24,7 +24,7 @@ > > > > #ifdef HAVE_LINUX_BLKZONED_H > > > > -void f2fs_get_zoned_model(int i) > > +int f2fs_get_zoned_model(int i) > > { > > struct device_info *dev = c.devices + i; > > char str[128]; > > @@ -36,27 +36,41 @@ void f2fs_get_zoned_model(int i) > > "/sys/block/%s/queue/zoned", > > basename(dev->path)); > > file = fopen(str, "r"); > > - if (!file) > > - goto not_zoned; > > + if (!file) { > > + /* > > + * The kernel does not support zoned block devices, but we have > > + * a block device file. This means that the device is not zoned > > + * or is zoned but can be randomly written (i.e. host-aware > > + * zoned model). Treat the device as a regular block device. > > + */ > > + dev->zoned_model = F2FS_ZONED_NONE; > > + return 0; > > + } > > > > memset(str, 0, sizeof(str)); > > res = fscanf(file, "%s", str); > > fclose(file); > > > > - if (res != 1) > > - goto not_zoned; > > + if (res != 1) { > > + MSG(0, "\tError: Failed to parse the device zoned model\n"); > > + return -1; > > + } > > > > - if (strcmp(str, "host-aware") == 0) { > > + if (strcmp(str, "none") == 0) { > > + /* Regular block device */ > > + dev->zoned_model = F2FS_ZONED_NONE; > > + } else if (strcmp(str, "host-aware") == 0) { > > + /* Host-aware zoned block device: can be randomly written */ > > dev->zoned_model = F2FS_ZONED_HA; > > - return; > > - } > > - if (strcmp(str, "host-managed") == 0) { > > + } else if (strcmp(str, "host-managed") == 0) { > > + /* Host-managed zoned block device: sequential writes needed */ > > dev->zoned_model = F2FS_ZONED_HM; > > - return; > > + } else { > > + MSG(0, "\tError: Unsupported device zoned model\n"); > > + return -1; > > } > > > > -not_zoned: > > - dev->zoned_model = F2FS_ZONED_NONE; > > + return 0; > > } > > > > int f2fs_get_zone_blocks(int i) > > _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel