Three f2fs patches
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
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
@@ -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
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.Cc Peter Collingbourne <[email protected]>Reported-by Peter Collingbourne <[email protected]>Signed-off-by Bart Van Assche <[email protected]>
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
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.Cc Peter Collingbourne <[email protected]>Reported-by Peter Collingbourne <[email protected]>Signed-off-by Bart Van Assche <[email protected]>Reviewed-by Chao Yu <[email protected]>
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_SIZEwas 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 useF2FS_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
PATCH 2/3 Fix f2fs_report_zone()
In reply to Bart Van AsscheThe 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.
--- lib/libf2fs_zoned.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
lib/libf2fs_zoned.c +2 -1
@@ -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
Re: [f2fs-dev] [PATCH 2/3] Fix f2fs_report_zone()
Quoted 16 lines · Bart Van Assche
The definition of struct
blk_zone_reportis 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 withmalloc()and sincef2fs_report_zone()only initializes the sector andnr_zonesmembers, the flags member is not initialized. Modifyf2fs_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")Signed-off-by Bart Van Assche <[email protected]>
Thanks,
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
PATCH 3/3 Improve compile-time type checking for f2fs_report_zone()
In reply to Bart Van AsscheChange 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
@@ -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
@@ -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
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 structblk_zone* to enable type checking.Signed-off-by Bart Van Assche <[email protected]>
Thanks,
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
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 structf2fs_dentry_blocksize check
Fixf2fs_report_zone()
Improve compile-time type checking forf2fs_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