[PATCH 1/3] erofs-utils: get rid of erofs_buf_write_bhops
Gao Xiang
hsiangkao at linux.alibaba.com
Fri Apr 7 23:38:03 AEST 2023
`nbh->off - bh->off` in erofs_bh_flush_generic_write() is
problematic due to erofs_bdrop(bh, false).
Let's avoid generic erofs_buf_write_bhops instead.
Signed-off-by: Gao Xiang <hsiangkao at linux.alibaba.com>
---
include/erofs/cache.h | 1 -
lib/cache.c | 23 -----------------------
mkfs/main.c | 8 +++++---
3 files changed, 5 insertions(+), 27 deletions(-)
diff --git a/include/erofs/cache.h b/include/erofs/cache.h
index b04eb47..8c3bd46 100644
--- a/include/erofs/cache.h
+++ b/include/erofs/cache.h
@@ -80,7 +80,6 @@ static inline const int get_alignsize(int type, int *type_ret)
extern const struct erofs_bhops erofs_drop_directly_bhops;
extern const struct erofs_bhops erofs_skip_write_bhops;
-extern const struct erofs_bhops erofs_buf_write_bhops;
static inline erofs_off_t erofs_btell(struct erofs_buffer_head *bh, bool end)
{
diff --git a/lib/cache.c b/lib/cache.c
index 9eb0394..178bd5a 100644
--- a/lib/cache.c
+++ b/lib/cache.c
@@ -39,29 +39,6 @@ const struct erofs_bhops erofs_skip_write_bhops = {
.flush = erofs_bh_flush_skip_write,
};
-int erofs_bh_flush_generic_write(struct erofs_buffer_head *bh, void *buf)
-{
- struct erofs_buffer_head *nbh = list_next_entry(bh, list);
- erofs_off_t offset = erofs_btell(bh, false);
-
- DBG_BUGON(nbh->off < bh->off);
- return dev_write(buf, offset, nbh->off - bh->off);
-}
-
-static bool erofs_bh_flush_buf_write(struct erofs_buffer_head *bh)
-{
- int err = erofs_bh_flush_generic_write(bh, bh->fsprivate);
-
- if (err)
- return false;
- free(bh->fsprivate);
- return erofs_bh_flush_generic_end(bh);
-}
-
-const struct erofs_bhops erofs_buf_write_bhops = {
- .flush = erofs_bh_flush_buf_write,
-};
-
/* return buffer_head of erofs super block (with size 0) */
struct erofs_buffer_head *erofs_buffer_init(void)
{
diff --git a/mkfs/main.c b/mkfs/main.c
index 65d3df6..05db4c8 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -580,6 +580,7 @@ int erofs_mkfs_update_super_block(struct erofs_buffer_head *bh,
};
const u32 sb_blksize = round_up(EROFS_SUPER_END, erofs_blksiz());
char *buf;
+ int ret;
*blocks = erofs_mapbh(NULL);
sb.blocks = cpu_to_le32(*blocks);
@@ -601,9 +602,10 @@ int erofs_mkfs_update_super_block(struct erofs_buffer_head *bh,
}
memcpy(buf + EROFS_SUPER_OFFSET, &sb, sizeof(sb));
- bh->fsprivate = buf;
- bh->op = &erofs_buf_write_bhops;
- return 0;
+ ret = dev_write(buf, erofs_btell(bh, false), sb_blksize);
+ free(buf);
+ erofs_bdrop(bh, false);
+ return ret;
}
static int erofs_mkfs_superblock_csum_set(void)
--
2.24.4
More information about the Linux-erofs
mailing list