Zoned block device support improvments
v3 cover Zoned block device support improvments
The first 2 patches of this series are not zoned block device specific and fix compilation warnings and modify .gitignore file to handle /tools/f2fs_io/f2fs_io (note: patch 1 already applied upstream, not resending).
The last 2 patches are improvements of zoned block device support, with the last patch being the most important.
Damien Le Moal (3):
f2fs-tools: Improve zoned model check
f2fs-tools: Fix multi-device format with zoned devices
f2fs-tools: Allow using host-aware devices as regular devices
include/f2fs_fs.h | 2 +- lib/libf2fs.c | 64 ++++++++++++++++++++++++++++++++++++--------- lib/libf2fs_zoned.c | 47 ++++++++++++++++++++++++--------- 3 files changed, 86 insertions(+), 27 deletions(-)
Changes from v2:
* Not resending patch 1 as it is applied upstream
* Fixed space indentation in patch 3 -> use tabs
Changes from v1:
* Dropped patch 4 as further analysis shows no problems with HA drives handling
* Fixed patch 3 to correctly handle zoned_model == none cases
* Added comment in the last patch as suggested by Chao
Signature · 1 line
2.20.1
PATCH v3 1/3 f2fs-tools: Improve zoned model check
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.
--- include/f2fs_fs.h | 2 +- lib/libf2fs.c | 8 ++++++-- lib/libf2fs_zoned.c | 38 ++++++++++++++++++++++++++------------ 3 files changed, 33 insertions(+), 15 deletions(-)
include/f2fs_fs.h +1 -1
@@ -1260,7 +1260,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 );
lib/libf2fs.c +6 -2
@@ -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 ; + } + }if (dev->zoned_model !=F2FS_ZONED_NONE ) {if (dev->zoned_model ==F2FS_ZONED_HM )
lib/libf2fs_zoned.c +26 -12
@@ -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)
Signature · 1 line
2.20.1
PATCH v3 2/3 f2fs-tools: Fix multi-device format with zoned devices
In reply to Damien Le MoalThere is no need to require conventional zones for a zoned block device that is not the first device of a multi-device volume. As a result, there is no need to check the number of conventional zones of the device if the device index is not 0.
--- lib/libf2fs.c | 2 +- lib/libf2fs_zoned.c | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-)
lib/libf2fs.c +1 -1
@@ -929,7 +929,7 @@ int get_device_info(int i)if (f2fs_get_zoned_model (i) <0 ) {free (stat_buf);return -1 ; - } + } }if (dev->zoned_model !=F2FS_ZONED_NONE ) {
lib/libf2fs_zoned.c +8 -1
@@ -216,7 +216,14 @@ int f2fs_check_zones(int j) goto out; } -if (dev->zoned_model ==F2FS_ZONED_HM && +/* +* For a multi-device volume, fixed position metadata blocks are +* stored * only on the first device of the volume. Checking for the +* presence of * conventional zones (randomly writeabl zones) for +* storing these blocks * on a host-managed device is thus needed only +* for the device index 0. +*/ +if (j ==0 && dev->zoned_model ==F2FS_ZONED_HM && !dev->nr_rnd_zones) {ERR_MSG ("No conventional zone for super block\n" ); ret =-1 ;
Signature · 1 line
2.20.1
PATCH v3 3/3 f2fs-tools: Allow using host-aware devices as regular devices
In reply to Damien Le MoalHost-aware zoned block devices can accept random writes anywhere and so do not require to be handled under F2FS_ZONED_HM mode. Allow host aware disks to be treated as regular devices if c.zoned_mode is false, that is, if the -m option is not specified in mkfs.f2fs.
--- lib/libf2fs.c | 56 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 11 deletions(-)
lib/libf2fs.c +45 -11
@@ -933,15 +933,18 @@ int get_device_info(int i) }if (dev->zoned_model !=F2FS_ZONED_NONE ) { -if (dev->zoned_model ==F2FS_ZONED_HM ) - c.zoned_model =F2FS_ZONED_HM ; +/* Get the number of blocks per zones */ if (f2fs_get_zone_blocks (i)) {MSG (0 ,"\tError: Failed to get number of blocks per zone\n" );free (stat_buf);return -1 ; } +/* +* Check zone configuration: for the first disk of a +* multi-device volume, conventional zones are needed. +*/ if (f2fs_check_zones (i)) {MSG (0 ,"\tError: Failed to check zone configuration\n" );free (stat_buf);
@@ -1089,22 +1092,53 @@ int f2fs_get_device_info(void)return -1 ; } +/* +* Check device types and determine the final volume operation mode: +* - If all devices are regular block devices, default operation. +* - If at least one HM device is found, operate in HM mode (BLKZONED +* feature will be enabled by mkfs). +* - If an HA device is found, let mkfs decide based on the -m option +* setting by the user. +*/ + c.zoned_model =F2FS_ZONED_NONE ;for (i =0 ; i < c.ndevs; i++) { -if (c.devices[i].zoned_model !=F2FS_ZONED_NONE ) { +switch (c.devices[i].zoned_model) { +case F2FS_ZONED_NONE : +continue ; +case F2FS_ZONED_HM : + c.zoned_model =F2FS_ZONED_HM ; +break ; +case F2FS_ZONED_HA : +if (c.zoned_model !=F2FS_ZONED_HM ) + c.zoned_model =F2FS_ZONED_HA ; +break ; + } + } + +if (c.zoned_model !=F2FS_ZONED_NONE ) { + +/* +* For zoned model, the zones sizes of all zoned devices must +* be equal. +*/ +for (i =0 ; i < c.ndevs; i++) { +if (c.devices[i].zoned_model ==F2FS_ZONED_NONE ) +continue ;if (c.zone_blocks && - c.zone_blocks != c.devices[i].zone_blocks) { -MSG (0 ,"\tError: not support different zone sizes!!!\n" ); + c.zone_blocks != c.devices[i].zone_blocks) { +MSG (0 ,"\tError: zones of different size are " +"not supported\n" );return -1 ; } c.zone_blocks = c.devices[i].zone_blocks; } - } -/* -* Align sections to the device zone size -* and align F2FS zones to the device zones. -*/ -if (c.zone_blocks) { +/* +* Align sections to the device zone size and align F2FS zones +* to the device zones. For F2FS_ZONED_HA model without the +* BLKZONED feature set at format time, this is only an +* optimization as sequential writes will not be enforced. +*/ c.segs_per_sec = c.zone_blocks /DEFAULT_BLOCKS_PER_SEGMENT ; c.secs_per_zone =1 ; }else {
Signature · 1 line
2.20.1