minix: unify the v1 and v2/v3 itree code paths
cover minix: unify the v1 and v2/v3 itree code paths
For as far back as the git history goes and then some, minix's itree functions have been split across three files: itree_v1.c, itree_v2.c, and itree_common.c. The first two of these files had defines, types, static helper functions, and some wrapper functions tailored for version 1 and versions 2 and 3 of the Minix file systems respectively. Each of these files then included itree_common.c.
The reason for this odd arrangement is that there are some stark differences between version 1 and versions 2 and 3 of the Minix fs. Version 1 has doubly indirect blocks and 16 bit block pointers, while versions 2 and 3 have trebly indirect blocks and 32 bit block pointers. By having the separate itree_v1.c and itree_v2.c files that then included itree_common.c, DIRECT, DEPTH, block_t, and Indirect could be defined differently for the two broad types of Minix filesystems while sharing the bulk of their code because the same code in itree_common.c would be treated differently by the preprocessor and compiler depending on which file included it. In other words, DEPTH could mean 3 or 4 depending on if it had been included from itree_v1.c or itree_v2.c.
Christoph Hellwig theorized that minix has this unusual arrangement because this code was written at a time when the branch predictors were much worse than today. This makes sense to me, at least as much sense as can be expected, and I agree with him that modern CPUs should be able to handle a branch for the two cases lower down in the code. At this point, the possible performance boost for a historic filesystem that is at best unlikely to be being used in production anywhere should not outweigh the benefits for readability and maintainability that unifying the itree code paths would bring.
This patch was verified against the minix xfstests-dev branch[1] used for verifying the minix iomap patches. After applying this patch, the minix tests have the same results as the baseline: v1 and v3 outright fail generic/472 (a swapfile test), while v2 passes. This does not include the collection of tests skipped by xfstests because minix will never, ever be able to pass them because of limitations inherent to the filesystems. Functionally, the minix module is identical before and after the patch is applied.
This file unavoidably lands as one relatively large patch, but it ended up not breaking down well into smaller chunks that would still build a working kernel.
[1]: https://github.com/ctdk/xfstests-dev/tree/minix
Jeremy Bingham (1):
minix: consolidate itree* files into one itree.c file
fs/minix/Makefile | 2 +- fs/minix/inode.c | 38 +-- fs/minix/itree.c | 672 ++++++++++++++++++++++++++++++++++++++++ fs/minix/itree_common.c | 374 ---------------------- fs/minix/itree_v1.c | 67 ---- fs/minix/itree_v2.c | 75 ----- fs/minix/minix.h | 26 +- 7 files changed, 702 insertions(+), 552 deletions(-) create mode 100644 fs/minix/itree.c delete mode 100644 fs/minix/itree_common.c delete mode 100644 fs/minix/itree_v1.c delete mode 100644 fs/minix/itree_v2.c
Signature · 1 line
2.47.3
PATCH 1/1 minix: consolidate itree* files into one itree.c file
Consolidate the itree functions by adding fields to the superblock info struct to store the number of direct blocks and levels of indirect blocks because the different versions of the minix filesystems have differing numbers of indirect block pointers and different block pointer sizes. This allows consolidating the itree functions into one itree.c file instead of a system with version specific itree files with version specific definitions and wrapper functions that #include a common itree_common.c file that are in turn called by wrapper functions elsewhere in the code that call the version specific wrapper functions.
No functional changes are intended for this patch.
--- fs/minix/Makefile | 2 +- fs/minix/inode.c | 38 +-- fs/minix/itree.c | 672 ++++++++++++++++++++++++++++++++++++++++ fs/minix/itree_common.c | 374 ---------------------- fs/minix/itree_v1.c | 67 ---- fs/minix/itree_v2.c | 75 ----- fs/minix/minix.h | 26 +- 7 files changed, 702 insertions(+), 552 deletions(-) create mode 100644 fs/minix/itree.c delete mode 100644 fs/minix/itree_common.c delete mode 100644 fs/minix/itree_v1.c delete mode 100644 fs/minix/itree_v2.c
fs/minix/Makefile +1 -1
@@ -5,4 +5,4 @@ obj-$(CONFIG_MINIX_FS) += minix.o -minix-objs := bitmap.o itree_v1.o itree_v2.o namei.o inode.o file.o dir.o +minix-objs := bitmap.o itree.o namei.o inode.o file.o dir.o
fs/minix/inode.c +12 -26
@@ -301,6 +301,16 @@ static int minix_fill_super(struct super_block *s, struct fs_context *fc) }else goto out_no_fs; +/* +* Set the direct block and indirect block depth now that the rest of +* the version-specific settings have been set. +*/ + sbi->s_direct =MINIX_DIRECT ; +if (sbi->s_version ==MINIX_V1 ) + sbi->s_depth =MINIX_V1_DEPTH ; +else + sbi->s_depth =MINIX_V2_DEPTH ; +if (!minix_check_superblock (s)) goto out_illegal_sb;
@@ -439,15 +449,6 @@ static int minix_statfs(struct dentry *dentry, struct kstatfs *buf)return 0 ; } -static int minix_get_block (struct inode *inode,sector_t block, -struct buffer_head *bh_result,int create) -{ -if (INODE_VERSION (inode) ==MINIX_V1 ) -return V1_minix_get_block (inode, block, bh_result, create); -else -return V2_minix_get_block (inode, block, bh_result, create); -} -static int minix_writepages (struct address_space *mapping,struct writeback_control *wbc) {
@@ -731,27 +732,12 @@ int minix_getattr(struct mnt_idmap *idmap, const struct path *path,struct inode *inode =d_inode (path->dentry);generic_fillattr (&nop_mnt_idmap, request_mask, inode, stat); -if (INODE_VERSION (inode) ==MINIX_V1 ) - stat->blocks = (BLOCK_SIZE /512 ) *V1_minix_blocks (stat->size, sb); -else - stat->blocks = (sb->s_blocksize /512 ) *V2_minix_blocks (stat->size, sb); + + stat->blocks = (sb->s_blocksize /512 ) *minix_blocks (stat->size, sb); stat->blksize = sb->s_blocksize;return 0 ; } -/* -* The function that is called for file truncation. -*/ -void minix_truncate (struct inode * inode) -{ -if (!(S_ISREG (inode->i_mode) ||S_ISDIR (inode->i_mode) ||S_ISLNK (inode->i_mode))) -return ; -if (INODE_VERSION (inode) ==MINIX_V1 ) -V1_minix_truncate (inode); -else -V2_minix_truncate (inode); -} -static struct file_system_type minix_fs_type = { .owner =THIS_MODULE , .name ="minix" ,
fs/minix/itree.c new file +672 -0
672 lines not on this page · raw message
fs/minix/itree_common.c deleted +0 -374
374 lines not on this page · raw message
fs/minix/itree_v1.c deleted +0 -67
67 lines not on this page · raw message
fs/minix/itree_v2.c deleted +0 -75
75 lines not on this page · raw message
fs/minix/minix.h +17 -9
@@ -11,13 +11,22 @@#define MINIX_V2 0x0002/* minix V2 fs */ #define MINIX_V3 0x0003/* minix V3 fs */ +/* +* Block storage layout. All versions have 7 direct blocks, but they have +* differing depths: V1 only has doubly indirect blocks, while V2/V3 have +* trebly indirect blocks. Thus, V1 depth is 3 while V2 and V3 are 4. +*/ +enum {MINIX_DIRECT =7 ,MINIX_V1_DEPTH =3 ,MINIX_V2_DEPTH =4 }; +/* * minix fs inode data in memory */ +#define MINIX_INODE_DATA_ELEMENTS 16 +struct minix_inode_info {union { -__u16 i1_data[16 ]; -__u32 i2_data[16 ]; +__u16 i1_data[MINIX_INODE_DATA_ELEMENTS ]; +__u32 i2_data[MINIX_INODE_DATA_ELEMENTS ]; } u;struct mapping_metadata_bhs i_metadata_bhs;struct inode vfs_inode;
@@ -41,6 +50,8 @@ struct minix_sb_info {struct minix_super_block * s_ms;unsigned short s_mount_state;unsigned short s_version; +unsigned short s_direct; +unsigned short s_depth; }; void __minix_error_inode(struct inode *inode, const char *function,
@@ -60,14 +71,11 @@ int minix_getattr(struct mnt_idmap *, const struct path *,int minix_prepare_chunk (struct folio *folio,loff_t pos,unsigned len);struct mapping_metadata_bhs *minix_get_metadata_bhs (struct inode *inode); -extern void V1_minix_truncate (struct inode *); -extern void V2_minix_truncate (struct inode *); -extern void minix_truncate (struct inode *); +void minix_truncate (struct inode *inode);extern void minix_set_inode (struct inode *,dev_t ); -extern int V1_minix_get_block (struct inode *,long ,struct buffer_head *,int ); -extern int V2_minix_get_block (struct inode *,long ,struct buffer_head *,int ); -extern unsigned V1_minix_blocks (loff_t ,struct super_block *); -extern unsigned V2_minix_blocks (loff_t ,struct super_block *); +int minix_get_block (struct inode *inode,sector_t block, +struct buffer_head *bh,int create); +unsigned int minix_blocks (loff_t size,struct super_block *sb);struct minix_dir_entry *minix_find_entry (struct dentry *,struct folio **);int minix_add_link (struct dentry *,struct inode *);
Signature · 1 line
2.47.3
Re: [PATCH v1 1/1] minix: consolidate itree* files into one itree.c file
Quoted 10 lines · Jeremy Bingham
Consolidate the itree functions by adding fields to the superblock info struct to store the number of direct blocks and levels of indirect blocks because the different versions of the minix filesystems have differing numbers of indirect block pointers and different block pointer sizes. This allows consolidating the itree functions into one
itree.cfile instead of a system with version specific itree files with version specific definitions and wrapper functions that #include a commonitree_common.cfile that are in turn called by wrapper functions elsewhere in the code that call the version specific wrapper functions.
Quoted 5 lines
No functional changes are intended for this patch.
Suggested-by Christoph Hellwig <[email protected]>Suggested-by Darrick J. Wong <[email protected]>Signed-off-by Jeremy Bingham <[email protected]>
Looks good from the high-level perspective:
I assume you've run xfstests and checked nothing regresseѕ?
Re: [PATCH v1 1/1] minix: consolidate itree* files into one itree.c file
Quoted 6 lines · Christoph Hellwig
Looks good from the high-level perspective:
Reviewed-by Christoph Hellwig <[email protected]>I assume you've run xfstests and checked nothing regresseѕ?
Of course. I covered the xfstests suite run for this in the cover letter rather than the patch (so I apologize if that was a mistake, but it seemed like the logical place for it), but it was the same branch I've used in the past for the iomap runs. It ran with no regressions compared to the baseline.
Thanks,
-j