erofs-utils: separate directory data from file data
authorGao Xiang <hsiangkao@linux.alibaba.com>
Fri, 24 Mar 2023 08:27:49 +0000 (16:27 +0800)
committerGao Xiang <hsiangkao@linux.alibaba.com>
Fri, 24 Mar 2023 09:00:13 +0000 (17:00 +0800)
It'd better to split directory data out although directory data is
still not lazy written since it tends to put directory data next to
the corresponding inode metadata.

Laterly, aligned directory data could be written in a batch way so
that inodes can be more compact.

Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Link: https://lore.kernel.org/r/20230324082749.1915-1-hsiangkao@linux.alibaba.com
include/erofs/cache.h
lib/inode.c
mkfs/main.c

index 14613058dc46aeb2f59b524c80d35af0ef8c7574..b04eb47f0d26f81f3c4823a1b7c880dd0e47dbe5 100644 (file)
@@ -22,10 +22,12 @@ struct erofs_buffer_block;
 #define META           1
 /* including inline xattrs, extent */
 #define INODE          2
+/* directory data */
+#define DIRA           3
 /* shared xattrs */
-#define XATTR          3
+#define XATTR          4
 /* device table */
-#define DEVT           4
+#define DEVT           5
 
 struct erofs_bhops {
        bool (*preflush)(struct erofs_buffer_head *bh);
@@ -60,6 +62,9 @@ static inline const int get_alignsize(int type, int *type_ret)
        if (type == INODE) {
                *type_ret = META;
                return sizeof(struct erofs_inode_compact);
+       } else if (type == DIRA) {
+               *type_ret = META;
+               return erofs_blksiz();
        } else if (type == XATTR) {
                *type_ret = META;
                return sizeof(struct erofs_xattr_entry);
index 7167f19e65095a6883f08e52968d31b5083e4202..9db84a89281feebd14e95e5e2fca7a6d466415c8 100644 (file)
@@ -142,7 +142,8 @@ struct erofs_dentry *erofs_d_alloc(struct erofs_inode *parent,
 
 /* allocate main data for a inode */
 static int __allocate_inode_bh_data(struct erofs_inode *inode,
-                                   unsigned long nblocks)
+                                   unsigned long nblocks,
+                                   int type)
 {
        struct erofs_buffer_head *bh;
        int ret;
@@ -154,7 +155,7 @@ static int __allocate_inode_bh_data(struct erofs_inode *inode,
        }
 
        /* allocate main data buffer */
-       bh = erofs_balloc(DATA, erofs_pos(nblocks), 0, 0);
+       bh = erofs_balloc(type, erofs_pos(nblocks), 0, 0);
        if (IS_ERR(bh))
                return PTR_ERR(bh);
 
@@ -305,7 +306,7 @@ static int erofs_write_dir_file(struct erofs_inode *dir)
        q = used = blkno = 0;
 
        /* allocate dir main data */
-       ret = __allocate_inode_bh_data(dir, erofs_blknr(dir->i_size));
+       ret = __allocate_inode_bh_data(dir, erofs_blknr(dir->i_size), DIRA);
        if (ret)
                return ret;
 
@@ -353,7 +354,7 @@ static int erofs_write_file_from_buffer(struct erofs_inode *inode, char *buf)
 
        inode->datalayout = EROFS_INODE_FLAT_INLINE;
 
-       ret = __allocate_inode_bh_data(inode, nblocks);
+       ret = __allocate_inode_bh_data(inode, nblocks, DATA);
        if (ret)
                return ret;
 
@@ -386,7 +387,7 @@ static int write_uncompressed_file_from_fd(struct erofs_inode *inode, int fd)
        inode->datalayout = EROFS_INODE_FLAT_INLINE;
        nblocks = inode->i_size / erofs_blksiz();
 
-       ret = __allocate_inode_bh_data(inode, nblocks);
+       ret = __allocate_inode_bh_data(inode, nblocks, DATA);
        if (ret)
                return ret;
 
index a05d4f928cca503b18b4f0efc70572bea9fa5674..27e3f0356240244134f5726b2ed9d3bc5cb0cde2 100644 (file)
@@ -802,6 +802,13 @@ int main(int argc, char **argv)
                goto exit;
        }
 
+       /* make sure that the super block should be the very first blocks */
+       (void)erofs_mapbh(sb_bh->block);
+       if (erofs_btell(sb_bh, false) != 0) {
+               erofs_err("failed to reserve erofs_super_block");
+               goto exit;
+       }
+
        err = erofs_load_compress_hints();
        if (err) {
                erofs_err("failed to load compress hints %s",