Skip to contentSkip to conversation

Zoned block device support improvments

PATCH Applied Damien Le Moal 3 participants 8 messages Mar 27, 2019 – Apr 5, 2019 Library code

v2 of 3 Applied Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 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.

The last 2 patches are improvements of zoned block device support, with the last patch being the most important.

Damien Le Moal (4):
f2fs-tools: Fix various compilation warnings
f2fs-tools: Add f2fs_io to .gitignore
f2fs-tools: Improve zoned model check
f2fs-tools: Fix multi-device format with zoned devices

 .gitignore          |  1 +
 include/f2fs_fs.h   |  8 ++++----
 lib/libf2fs.c       | 10 +++++++---
 lib/libf2fs_zoned.c | 47 ++++++++++++++++++++++++++++++++-------------
 tools/f2fstat.c     |  2 +-
 5 files changed, 47 insertions(+), 21 deletions(-)

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
#1 lore raw

PATCH v2 1/4 f2fs-tools: Fix various compilation warnings

Avoid various compilation warnings due to strncpy:

libf2fs.c:590:33: warning: ‘snprintf’ output may be truncated before the last format character [-Wformat-truncation=]
snprintf(rootdev, ret, "/dev/%s", buf);

../include/f2fs_fs.h:1384:2: warning: ‘strncpy’ specified bound depends on the length of the source argument [-Wstringop-overflow=]
strncpy(buf, features, strlen(features) + 1);

f2fstat.c:243:3: warning: ‘strncpy’ output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation]
strncpy(ptr_buf, name[i], strlen(name[i]));

This patch does not change any functionality.

---
 include/f2fs_fs.h | 6 +++---
 lib/libf2fs.c     | 2 +-
 tools/f2fstat.c   | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)
include/f2fs_fs.h +3 -3
index a730688..e073723 100644
@@ -1379,9 +1379,9 @@ static inline int parse_feature(struct feature *table, const char *features)
 {
 	char *buf, *sub, *next;
 
-	buf = calloc(strlen(features) + 1, sizeof(char));
-	ASSERT(buf);
-	strncpy(buf, features, strlen(features) + 1);
+	buf = strdup(features);
+	if (!buf)
+		return -1;
 
 	for (sub = buf; sub && *sub; sub = next ? next + 1 : NULL) {
 		/* Skip the beginning blanks */
lib/libf2fs.c +1 -1
index c692bf2..60b84e0 100644
@@ -587,7 +587,7 @@ char *get_rootdev()
 		return NULL;
 	rootdev[ret] = '\0';
 
-	snprintf(rootdev, ret, "/dev/%s", buf);
+	snprintf(rootdev, ret + 1, "/dev/%s", buf);
 	return rootdev;
 #endif
 }
tools/f2fstat.c +1 -1
index 7f485b0..0618806 100644
@@ -240,7 +240,7 @@ void print_head(char *res)
 
 	for (i = 0; i < 20; i++) {
 		ptr = (i == 0) ? strtok(res, " ") : strtok(NULL, " ");
-		strncpy(ptr_buf, name[i], strlen(name[i]));
+		strcpy(ptr_buf, name[i]);
 		if (i == 1) {
 			prev_index = ptr_buf - buf - 1;
 		} else if (i == 7) {
Signature · 8 lines
2.20.1



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

PATCH v2 2/4 f2fs-tools: Add f2fs_io to .gitignore

In reply to Damien Le Moal

GIT ignore compiled executable tools/f2fs_io/f2fs_io.

---
 .gitignore | 1 +
 1 file changed, 1 insertion(+)
.gitignore +1 -0
index 3f04e85..c1341da 100644
@@ -50,6 +50,7 @@ stamp-h1
 /tools/fibmap.f2fs
 /tools/parse.f2fs
 /tools/f2fscrypt
+/tools/f2fs_io/f2fs_io
 /tools/sg_write_buffer/sg_write_buffer
 
 # cscope files
Signature · 1 line
2.20.1
#3 lore raw

PATCH v2 3/4 f2fs-tools: Improve zoned model check

In reply to Damien Le Moal

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
index e073723..97ad774 100644
@@ -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);
lib/libf2fs.c +6 -2
index 60b84e0..5ca1bb0 100644
@@ -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
index 6e32f32..e396a95 100644
@@ -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
Reviewed-by on v2 3/4
#4 lore raw

Re: [PATCH 3/4 v2] f2fs-tools: Improve zoned model check

Quoted 30 lines · Damien Le Moal

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
index e073723..97ad774 100644
@@ -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);
lib/libf2fs.c +0 -0
index 60b84e0..5ca1bb0 100644

lib/libf2fs.c int get_device_info(int i) · line 932

Quoted 10 lines
lib/libf2fs.c +5 -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;
+                }

Needs tabs here...

Otherwise it looks good to me.

Thanks,

Quoted 71 lines
lib/libf2fs.c +1 -0
+	}
 
 	if (dev->zoned_model != F2FS_ZONED_NONE) {
 		if (dev->zoned_model == F2FS_ZONED_HM)
lib/libf2fs_zoned.c +26 -12
index 6e32f32..e396a95 100644
@@ -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)
Applied
#5 lore raw

Re: [PATCH 3/4 v2] f2fs-tools: Improve zoned model check

Quoted 33 lines · Chao Yu
Quoted 32 lines · Damien Le Moal

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
index e073723..97ad774 100644
@@ -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);
lib/libf2fs.c +0 -0
index 60b84e0..5ca1bb0 100644
@@ -925,8 +925,12 @@ int get_device_info(int i)
 	}
 
Quoted 10 lines

lib/libf2fs.c int get_device_info(int i) · line 932

Quoted 8 lines
lib/libf2fs.c +5 -2
 #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. :)

Quoted 78 lines

Otherwise it looks good to me.

Thanks,

Quoted 71 lines
lib/libf2fs.c +1 -0
+	}
 
 	if (dev->zoned_model != F2FS_ZONED_NONE) {
 		if (dev->zoned_model == F2FS_ZONED_HM)
lib/libf2fs_zoned.c +26 -12
index 6e32f32..e396a95 100644
@@ -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)
#6 lore raw

PATCH v2 4/4 f2fs-tools: Fix multi-device format with zoned devices

In reply to Damien Le Moal

There 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_zoned.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
lib/libf2fs_zoned.c +8 -1
index e396a95..97afe0b 100644
@@ -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
Reviewed-by on v2 4/4
#7 lore raw

Re: [PATCH 4/4 v2] f2fs-tools: Fix multi-device format with zoned devices

Quoted 6 lines · Damien Le Moal

There 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.

Thanks,