Commit c431d386 authored by Kemeng Shi's avatar Kemeng Shi Committed by Theodore Ts'o

ext4: extend ext4_mb_mark_context to support allocation under journal

Previously, ext4_mb_mark_context is only called under fast commit
replay path, so there is no valid handle when we update block bitmap
and group descriptor. This patch try to extend ext4_mb_mark_context
to be used by code under journal. There are several improvement:
1. Add "handle_t *handle" to struct ext4_mark_context to journal block
bitmap and group descriptor update inside ext4_mb_mark_context (the
added journal code is based on ext4_mb_mark_diskspace_used where
ext4_mb_mark_context is going to be used.)
2. Adds a flag argument to ext4_mb_mark_context() which controls
a. EXT4_MB_BITMAP_MARKED_CHECK - whether block bitmap checking is needed.
b. EXT4_MB_SYNC_UPDATE - whether dirty buffers (bitmap and group
descriptor) needs sync.
Signed-off-by: default avatarKemeng Shi <shikemeng@huaweicloud.com>
Reviewed-by: default avatar"Ritesh Harjani (IBM)" <ritesh.list@gmail.com>
Link: https://lore.kernel.org/r/20230928160407.142069-5-shikemeng@huaweicloud.comSigned-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
parent 26d0f87b
......@@ -3943,26 +3943,47 @@ void ext4_exit_mballoc(void)
ext4_groupinfo_destroy_slabs();
}
#define EXT4_MB_BITMAP_MARKED_CHECK 0x0001
#define EXT4_MB_SYNC_UPDATE 0x0002
static int
ext4_mb_mark_context(struct super_block *sb, bool state, ext4_group_t group,
ext4_grpblk_t blkoff, ext4_grpblk_t len)
ext4_mb_mark_context(handle_t *handle, struct super_block *sb, bool state,
ext4_group_t group, ext4_grpblk_t blkoff,
ext4_grpblk_t len, int flags, ext4_grpblk_t *ret_changed)
{
struct ext4_sb_info *sbi = EXT4_SB(sb);
struct buffer_head *bitmap_bh = NULL;
struct ext4_group_desc *gdp;
struct buffer_head *gdp_bh;
int err;
unsigned int i, already, changed;
unsigned int i, already, changed = len;
if (ret_changed)
*ret_changed = 0;
bitmap_bh = ext4_read_block_bitmap(sb, group);
if (IS_ERR(bitmap_bh))
return PTR_ERR(bitmap_bh);
if (handle) {
BUFFER_TRACE(bitmap_bh, "getting write access");
err = ext4_journal_get_write_access(handle, sb, bitmap_bh,
EXT4_JTR_NONE);
if (err)
goto out_err;
}
err = -EIO;
gdp = ext4_get_group_desc(sb, group, &gdp_bh);
if (!gdp)
goto out_err;
if (handle) {
BUFFER_TRACE(gdp_bh, "get_write_access");
err = ext4_journal_get_write_access(handle, sb, gdp_bh,
EXT4_JTR_NONE);
if (err)
goto out_err;
}
ext4_lock_group(sb, group);
if (ext4_has_group_desc_csum(sb) &&
(gdp->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT))) {
......@@ -3971,12 +3992,14 @@ ext4_mb_mark_context(struct super_block *sb, bool state, ext4_group_t group,
ext4_free_clusters_after_init(sb, group, gdp));
}
already = 0;
for (i = 0; i < len; i++)
if (mb_test_bit(blkoff + i, bitmap_bh->b_data) ==
state)
already++;
changed = len - already;
if (flags & EXT4_MB_BITMAP_MARKED_CHECK) {
already = 0;
for (i = 0; i < len; i++)
if (mb_test_bit(blkoff + i, bitmap_bh->b_data) ==
state)
already++;
changed = len - already;
}
if (state) {
mb_set_bits(bitmap_bh->b_data, blkoff, len);
......@@ -3991,6 +4014,8 @@ ext4_mb_mark_context(struct super_block *sb, bool state, ext4_group_t group,
ext4_block_bitmap_csum_set(sb, gdp, bitmap_bh);
ext4_group_desc_csum_set(sb, group, gdp);
ext4_unlock_group(sb, group);
if (ret_changed)
*ret_changed = changed;
if (sbi->s_log_groups_per_flex) {
ext4_group_t flex_group = ext4_flex_group(sbi, group);
......@@ -4003,15 +4028,17 @@ ext4_mb_mark_context(struct super_block *sb, bool state, ext4_group_t group,
atomic64_add(changed, &fg->free_clusters);
}
err = ext4_handle_dirty_metadata(NULL, NULL, bitmap_bh);
err = ext4_handle_dirty_metadata(handle, NULL, bitmap_bh);
if (err)
goto out_err;
err = ext4_handle_dirty_metadata(NULL, NULL, gdp_bh);
err = ext4_handle_dirty_metadata(handle, NULL, gdp_bh);
if (err)
goto out_err;
sync_dirty_buffer(bitmap_bh);
sync_dirty_buffer(gdp_bh);
if (flags & EXT4_MB_SYNC_UPDATE) {
sync_dirty_buffer(bitmap_bh);
sync_dirty_buffer(gdp_bh);
}
out_err:
brelse(bitmap_bh);
......@@ -4171,7 +4198,11 @@ void ext4_mb_mark_bb(struct super_block *sb, ext4_fsblk_t block,
break;
}
err = ext4_mb_mark_context(sb, state, group, blkoff, clen);
err = ext4_mb_mark_context(NULL, sb, state,
group, blkoff, clen,
EXT4_MB_BITMAP_MARKED_CHECK |
EXT4_MB_SYNC_UPDATE,
NULL);
if (err)
break;
......@@ -6363,7 +6394,10 @@ static void ext4_free_blocks_simple(struct inode *inode, ext4_fsblk_t block,
ext4_grpblk_t blkoff;
ext4_get_group_no_and_offset(sb, block, &group, &blkoff);
ext4_mb_mark_context(sb, false, group, blkoff, count);
ext4_mb_mark_context(NULL, sb, false, group, blkoff, count,
EXT4_MB_BITMAP_MARKED_CHECK |
EXT4_MB_SYNC_UPDATE,
NULL);
}
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment