erofs-utils: lib: propagate return code for erofs_bflush()
authorGao Xiang <hsiangkao@linux.alibaba.com>
Wed, 25 Oct 2023 05:05:31 +0000 (13:05 +0800)
committerGao Xiang <hsiangkao@linux.alibaba.com>
Wed, 25 Oct 2023 05:11:37 +0000 (13:11 +0800)
Instead of just using a boolean.

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

index 31f54a405db19450390a741ccb9a8eba79f6c6b6..11fc6ab7e2bb452e6e4b75472a36bebee87f4136 100644 (file)
@@ -30,7 +30,7 @@ struct erofs_buffer_block;
 #define DEVT           5
 
 struct erofs_bhops {
-       bool (*flush)(struct erofs_buffer_head *bh);
+       int (*flush)(struct erofs_buffer_head *bh);
 };
 
 struct erofs_buffer_head {
@@ -91,11 +91,11 @@ static inline erofs_off_t erofs_btell(struct erofs_buffer_head *bh, bool end)
                (end ? list_next_entry(bh, list)->off : bh->off);
 }
 
-static inline bool erofs_bh_flush_generic_end(struct erofs_buffer_head *bh)
+static inline int erofs_bh_flush_generic_end(struct erofs_buffer_head *bh)
 {
        list_del(&bh->list);
        free(bh);
-       return true;
+       return 0;
 }
 
 struct erofs_buffer_head *erofs_buffer_init(void);
@@ -108,7 +108,7 @@ struct erofs_buffer_head *erofs_battach(struct erofs_buffer_head *bh,
                                        int type, unsigned int size);
 
 erofs_blk_t erofs_mapbh(struct erofs_buffer_block *bb);
-bool erofs_bflush(struct erofs_buffer_block *bb);
+int erofs_bflush(struct erofs_buffer_block *bb);
 
 void erofs_bdrop(struct erofs_buffer_head *bh, bool tryrevoke);
 erofs_blk_t erofs_total_metablocks(void);
index e3cf69e4e3595a4f5660b0d9221247c361d52c85..393b27505dd14c37eb277868c9deb99c127763a6 100644 (file)
@@ -21,7 +21,7 @@ static struct list_head mapped_buckets[META + 1][EROFS_MAX_BLOCK_SIZE];
 /* last mapped buffer block to accelerate erofs_mapbh() */
 static struct erofs_buffer_block *last_mapped_block = &blkh;
 
-static bool erofs_bh_flush_drop_directly(struct erofs_buffer_head *bh)
+static int erofs_bh_flush_drop_directly(struct erofs_buffer_head *bh)
 {
        return erofs_bh_flush_generic_end(bh);
 }
@@ -30,9 +30,9 @@ const struct erofs_bhops erofs_drop_directly_bhops = {
        .flush = erofs_bh_flush_drop_directly,
 };
 
-static bool erofs_bh_flush_skip_write(struct erofs_buffer_head *bh)
+static int erofs_bh_flush_skip_write(struct erofs_buffer_head *bh)
 {
-       return false;
+       return -EBUSY;
 }
 
 const struct erofs_bhops erofs_skip_write_bhops = {
@@ -366,7 +366,7 @@ static void erofs_bfree(struct erofs_buffer_block *bb)
        free(bb);
 }
 
-bool erofs_bflush(struct erofs_buffer_block *bb)
+int erofs_bflush(struct erofs_buffer_block *bb)
 {
        const unsigned int blksiz = erofs_blksiz(&sbi);
        struct erofs_buffer_block *p, *n;
@@ -376,6 +376,7 @@ bool erofs_bflush(struct erofs_buffer_block *bb)
                struct erofs_buffer_head *bh, *nbh;
                unsigned int padding;
                bool skip = false;
+               int ret;
 
                if (p == bb)
                        break;
@@ -383,9 +384,15 @@ bool erofs_bflush(struct erofs_buffer_block *bb)
                blkaddr = __erofs_mapbh(p);
 
                list_for_each_entry_safe(bh, nbh, &p->buffers.list, list) {
-                       /* flush and remove bh */
-                       if (!bh->op->flush(bh))
+                       if (bh->op == &erofs_skip_write_bhops) {
                                skip = true;
+                               continue;
+                       }
+
+                       /* flush and remove bh */
+                       ret = bh->op->flush(bh);
+                       if (ret < 0)
+                               return ret;
                }
 
                if (skip)
@@ -401,7 +408,7 @@ bool erofs_bflush(struct erofs_buffer_block *bb)
                erofs_dbg("block %u to %u flushed", p->blkaddr, blkaddr - 1);
                erofs_bfree(p);
        }
-       return true;
+       return 0;
 }
 
 void erofs_bdrop(struct erofs_buffer_head *bh, bool tryrevoke)
index f6dc12af24f3cbb515c08eebbf035acbe847dda3..5900233cb31ea9bb0c28e4a57584d373e63f772c 100644 (file)
@@ -1045,6 +1045,7 @@ err_bdrop:
        erofs_bdrop(bh, true);  /* revoke buffer */
 err_free_meta:
        free(compressmeta);
+       inode->compressmeta = NULL;
        return ret;
 }
 
index 8409ccdd027baa5619ebdbe8a644ca1b4ad931cb..98892af1d1d303f708eae6ae00eeade9361459de 100644 (file)
@@ -117,6 +117,7 @@ unsigned int erofs_iput(struct erofs_inode *inode)
        list_for_each_entry_safe(d, t, &inode->i_subdirs, d_child)
                free(d);
 
+       free(inode->compressmeta);
        if (inode->eof_tailraw)
                free(inode->eof_tailraw);
        list_del(&inode->i_hash);
@@ -486,7 +487,7 @@ int erofs_write_file(struct erofs_inode *inode, int fd, u64 fpos)
        return write_uncompressed_file_from_fd(inode, fd);
 }
 
-static bool erofs_bh_flush_write_inode(struct erofs_buffer_head *bh)
+static int erofs_bh_flush_write_inode(struct erofs_buffer_head *bh)
 {
        struct erofs_inode *const inode = bh->fsprivate;
        struct erofs_sb_info *sbi = inode->sbi;
@@ -578,19 +579,19 @@ static bool erofs_bh_flush_write_inode(struct erofs_buffer_head *bh)
 
        ret = dev_write(sbi, &u, off, inode->inode_isize);
        if (ret)
-               return false;
+               return ret;
        off += inode->inode_isize;
 
        if (inode->xattr_isize) {
                char *xattrs = erofs_export_xattr_ibody(inode);
 
                if (IS_ERR(xattrs))
-                       return false;
+                       return PTR_ERR(xattrs);
 
                ret = dev_write(sbi, xattrs, off, inode->xattr_isize);
                free(xattrs);
                if (ret)
-                       return false;
+                       return ret;
 
                off += inode->xattr_isize;
        }
@@ -599,15 +600,14 @@ static bool erofs_bh_flush_write_inode(struct erofs_buffer_head *bh)
                if (inode->datalayout == EROFS_INODE_CHUNK_BASED) {
                        ret = erofs_blob_write_chunk_indexes(inode, off);
                        if (ret)
-                               return false;
+                               return ret;
                } else {
                        /* write compression metadata */
                        off = roundup(off, 8);
                        ret = dev_write(sbi, inode->compressmeta, off,
                                        inode->extent_isize);
                        if (ret)
-                               return false;
-                       free(inode->compressmeta);
+                               return ret;
                }
        }
 
@@ -718,7 +718,7 @@ noinline:
        return 0;
 }
 
-static bool erofs_bh_flush_write_inline(struct erofs_buffer_head *bh)
+static int erofs_bh_flush_write_inline(struct erofs_buffer_head *bh)
 {
        struct erofs_inode *const inode = bh->fsprivate;
        const erofs_off_t off = erofs_btell(bh, false);
@@ -726,7 +726,7 @@ static bool erofs_bh_flush_write_inline(struct erofs_buffer_head *bh)
 
        ret = dev_write(inode->sbi, inode->idata, off, inode->idata_size);
        if (ret)
-               return false;
+               return ret;
 
        inode->idata_size = 0;
        free(inode->idata);
index 6d2b70098d32eac0921ce96662d5b982add9acc3..637d1b9f07373288b476fa86185f3bde2b73660f 100644 (file)
@@ -1170,10 +1170,9 @@ int main(int argc, char **argv)
        }
 
        /* flush all buffers except for the superblock */
-       if (!erofs_bflush(NULL)) {
-               err = -EIO;
+       err = erofs_bflush(NULL);
+       if (err)
                goto exit;
-       }
 
        err = erofs_mkfs_update_super_block(sb_bh, root_nid, &nblocks,
                                            packed_nid);
@@ -1181,10 +1180,11 @@ int main(int argc, char **argv)
                goto exit;
 
        /* flush all remaining buffers */
-       if (!erofs_bflush(NULL))
-               err = -EIO;
-       else
-               err = dev_resize(&sbi, nblocks);
+       err = erofs_bflush(NULL);
+       if (err)
+               goto exit;
+
+       err = dev_resize(&sbi, nblocks);
 
        if (!err && erofs_sb_has_sb_chksum(&sbi))
                err = erofs_mkfs_superblock_csum_set();