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.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
[Jaegeuk Kim: Fix one missing function def change]
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
This commit is contained in:
Damien Le Moal 2019-04-02 11:44:53 +09:00 committed by Jaegeuk Kim
parent 36aa17a3bc
commit 658a0c8f20
3 changed files with 35 additions and 16 deletions

View File

@ -1274,7 +1274,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);

View File

@ -961,8 +961,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)

View File

@ -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)
@ -276,12 +290,13 @@ out:
#else
void f2fs_get_zoned_model(int i)
int f2fs_get_zoned_model(int i)
{
struct device_info *dev = c.devices + i;
c.zoned_mode = 0;
dev->zoned_model = F2FS_ZONED_NONE;
return 0;
}
int f2fs_get_zone_blocks(int i)