Skip to contentSkip to conversation

Three f2fs patches

PATCH In review Bart Van Assche 3 participants 9 messages Jun 14, 2022 – Jun 19, 2022 1 message not in the archive Library code

lore
Share & tools
lore
#0 lore raw

cover Three f2fs patches

Hi Jaegeuk,

This patch series fixes one issue reported by Peter Collingbourne and two issues I discovered by reading the zoned block device source code. Please consider these patches for inclusion in the official f2fs-tools repository.

Thanks,

Bart.

Bart Van Assche (3):
Fix the struct f2fs_dentry_block size check
Fix f2fs_report_zone()
Improve compile-time type checking for f2fs_report_zone()

 include/f2fs_fs.h   |  6 ++++--
 lib/libf2fs_zoned.c | 21 +++++++++++++--------
 2 files changed, 17 insertions(+), 10 deletions(-)

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

#1 lore raw

PATCH 1/3 Fix the struct f2fs_dentry_block size check

Fix the f2fs-tools build on systems for which PAGE_SIZE != 4096.

---
 include/f2fs_fs.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/f2fs_fs.h +1 -1
index 21a7e70d952d..3b1bd6eb7dc7 100644
@@ -1341,7 +1341,7 @@ struct f2fs_dentry_block {
 	__u8 filename[NR_DENTRY_IN_BLOCK][F2FS_SLOT_LEN];
 };
 
-static_assert(sizeof(struct f2fs_dentry_block) == 4096, "");
+static_assert(sizeof(struct f2fs_dentry_block) == PAGE_SIZE, "");
 
 /* for inline stuff */
 #define DEF_INLINE_RESERVED_SIZE	1

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

Reviewed-by on v1 1/3
#2 lore raw

Re: [f2fs-dev] [PATCH 1/3] Fix the struct f2fs_dentry_block size check

Quoted 5 lines · Bart Van Assche

Fix the f2fs-tools build on systems for which PAGE_SIZE != 4096.

Thanks,

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

A message that is not in the archive (sent off-list or not yet received): CAMn1gO4=iy7tzvvcx6n5DLBM+V4f9Kj=_U1abRf4Cm8XAL+gCA@mail.gmail.com

#4 lore raw

Re: [f2fs-dev] [PATCH 1/3] Fix the struct f2fs_dentry_block size check

Quoted 12 lines · Peter Collingbourne
Quoted 9 lines · On Sat, Jun 18, 2022, 16:41 Chao Yu <[email protected]> wrote:
Quoted 5 lines · Bart Van Assche

Fix the f2fs-tools build on systems for which PAGE_SIZE != 4096.

Quoted 8 lines

I'm not sure if this is the correct fix. From what I was able to figure out this is actually an on-disk data structure so it needs to be sized the same way as in the kernel. The kernel implementation of the file system requires a 4K page size which means that it only makes sense for this to be sized as if PAGE_SIZE was defined to 4096. It should at least be possible to use this tool on a non-4K page size kernel to create a file system that can be read on a 4K page size kernel, so I think the right fix would be to change the definition of this struct to use F2FS_BLKSIZE (or just hardcode 4096).

Yeah, since F2FS support 4KB page size, we need F2FS_BLKSIZE.

Quoted 2 lines

Peter

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

#5 lore raw

PATCH 2/3 Fix f2fs_report_zone()

In reply to Bart Van Assche

The definition of struct blk_zone_report is as follows:

	struct blk_zone_report {
		__u64		sector;
		__u32		nr_zones;
		__u32		flags;
		struct blk_zone zones[0];
	};

Since f2fs_report_zone() allocates the above data structure with malloc() and since f2fs_report_zone() only initializes the sector and nr_zones members, the flags member is not initialized. Modify f2fs_report_zone() such that 0 is passed as flags to the BLKREPORTZONE ioctl instead of a random value. This has been discovered by reading the source code.

Cc Shin'ichiro Kawasaki <[email protected]>
Fixes 6d7c7b785feb ("libf2fs_zoned: Introduce f2fs_report_zone() helper function")
---
 lib/libf2fs_zoned.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
lib/libf2fs_zoned.c +2 -1
index f383ce275342..d8de66b82029 100644
@@ -206,7 +206,8 @@ int f2fs_report_zone(int i, uint64_t sector, void *blkzone)
 	struct blk_zone_report *rep;
 	int ret = -1;
 
-	rep = malloc(sizeof(struct blk_zone_report) + sizeof(struct blk_zone));
+	rep = calloc(1, sizeof(struct blk_zone_report) +
+		     sizeof(struct blk_zone));
 	if (!rep) {
 		ERR_MSG("No memory for report zones\n");
 		return -ENOMEM;

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

Reviewed-by on v1 2/3
#6 lore raw

Re: [f2fs-dev] [PATCH 2/3] Fix f2fs_report_zone()

Quoted 16 lines · Bart Van Assche

The definition of struct blk_zone_report is as follows:

	struct blk_zone_report {
		__u64		sector;
		__u32		nr_zones;
		__u32		flags;
		struct blk_zone zones[0];
	};

Since f2fs_report_zone() allocates the above data structure with malloc() and since f2fs_report_zone() only initializes the sector and nr_zones members, the flags member is not initialized. Modify f2fs_report_zone() such that 0 is passed as flags to the BLKREPORTZONE ioctl instead of a random value. This has been discovered by reading the source code.

Quoted 3 lines
Cc Shin'ichiro Kawasaki <[email protected]>
Fixes 6d7c7b785feb ("libf2fs_zoned: Introduce f2fs_report_zone() helper function")

Thanks,

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

#7 lore raw

PATCH 3/3 Improve compile-time type checking for f2fs_report_zone()

In reply to Bart Van Assche

Change the type of the third argument of f2fs_report_zone() from void * into struct blk_zone * to enable type checking.

---
 include/f2fs_fs.h   |  4 +++-
 lib/libf2fs_zoned.c | 22 +++++++++++++---------
 2 files changed, 16 insertions(+), 10 deletions(-)
include/f2fs_fs.h +3 -1
index 3b1bd6eb7dc7..2dbb56967676 100644
@@ -1560,9 +1560,11 @@ blk_zone_cond_str(struct blk_zone *blkz)
 
 #endif
 
+struct blk_zone;
+
 extern int f2fs_get_zoned_model(int);
 extern int f2fs_get_zone_blocks(int);
-extern int f2fs_report_zone(int, uint64_t, void *);
+extern int f2fs_report_zone(int, uint64_t, struct blk_zone *);
 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);
lib/libf2fs_zoned.c +13 -9
index d8de66b82029..f0df15220d56 100644
@@ -200,21 +200,24 @@ int f2fs_get_zone_blocks(int i)
 	return 0;
 }
 
-int f2fs_report_zone(int i, uint64_t sector, void *blkzone)
+int f2fs_report_zone(int i, uint64_t sector, struct blk_zone *blkzone)
 {
-	struct blk_zone *blkz = (struct blk_zone *)blkzone;
-	struct blk_zone_report *rep;
+	struct one_zone_report {
+		struct blk_zone_report	rep;
+		struct blk_zone		zone;
+	} *rep;
 	int ret = -1;
 
-	rep = calloc(1, sizeof(struct blk_zone_report) +
-		     sizeof(struct blk_zone));
+	rep = calloc(1, sizeof(*rep));
 	if (!rep) {
 		ERR_MSG("No memory for report zones\n");
 		return -ENOMEM;
 	}
 
-	rep->sector = sector;
-	rep->nr_zones = 1;
+	rep->rep = (struct blk_zone_report){
+		.sector = sector,
+		.nr_zones = 1,
+	};
 	ret = ioctl(c.devices[i].fd, BLKREPORTZONE, rep);
 	if (ret != 0) {
 		ret = -errno;
@@ -222,7 +225,7 @@ int f2fs_report_zone(int i, uint64_t sector, void *blkzone)
 		goto out;
 	}
 
-	*blkz = *(struct blk_zone *)(rep + 1);
+	*blkzone = rep->zone;
 out:
 	free(rep);
 	return ret;
@@ -531,7 +534,8 @@ uint32_t f2fs_get_usable_segments(struct f2fs_super_block *sb)
 
 #else
 
-int f2fs_report_zone(int i, uint64_t UNUSED(sector), void *UNUSED(blkzone))
+int f2fs_report_zone(int i, uint64_t UNUSED(sector),
+		     struct blk_zone *UNUSED(blkzone))
 {
 	ERR_MSG("%d: Unsupported zoned block device\n", i);
 	return -1;

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

Reviewed-by on v1 3/3
#8 lore raw

Re: [f2fs-dev] [PATCH 3/3] Improve compile-time type checking for f2fs_report_zone()

Quoted 4 lines · Bart Van Assche

Change the type of the third argument of f2fs_report_zone() from void * into struct blk_zone * to enable type checking.

Thanks,

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

#9 lore raw
In reply to Bart Van Assche

Thanks, merged.

Quoted 10 lines · Bart Van Assche

Hi Jaegeuk,

This patch series fixes one issue reported by Peter Collingbourne and two issues I discovered by reading the zoned block device source code. Please consider these patches for inclusion in the official f2fs-tools repository.

Thanks,

Bart.

Quoted 8 lines

Bart Van Assche (3):
Fix the struct f2fs_dentry_block size check
Fix f2fs_report_zone()
Improve compile-time type checking for f2fs_report_zone()

 include/f2fs_fs.h   |  6 ++++--
 lib/libf2fs_zoned.c | 21 +++++++++++++--------
 2 files changed, 17 insertions(+), 10 deletions(-)

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