Commit 0d66b23d authored by Zhang Yi's avatar Zhang Yi Committed by Theodore Ts'o

ext4: make ext4_da_reserve_space() reserve multi-clusters

Add 'nr_resv' parameter to ext4_da_reserve_space(), which indicates the
number of clusters wants to reserve, make it reserve multiple clusters
at a time.
Signed-off-by: default avatarZhang Yi <yi.zhang@huawei.com>
Reviewed-by: default avatarJan Kara <jack@suse.cz>
Link: https://patch.msgid.link/20240517124005.347221-8-yi.zhang@huaweicloud.comSigned-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
parent 12eba993
...@@ -1479,9 +1479,9 @@ static int ext4_journalled_write_end(struct file *file, ...@@ -1479,9 +1479,9 @@ static int ext4_journalled_write_end(struct file *file,
} }
/* /*
* Reserve space for a single cluster * Reserve space for 'nr_resv' clusters
*/ */
static int ext4_da_reserve_space(struct inode *inode) static int ext4_da_reserve_space(struct inode *inode, int nr_resv)
{ {
struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
struct ext4_inode_info *ei = EXT4_I(inode); struct ext4_inode_info *ei = EXT4_I(inode);
...@@ -1492,18 +1492,18 @@ static int ext4_da_reserve_space(struct inode *inode) ...@@ -1492,18 +1492,18 @@ static int ext4_da_reserve_space(struct inode *inode)
* us from metadata over-estimation, though we may go over by * us from metadata over-estimation, though we may go over by
* a small amount in the end. Here we just reserve for data. * a small amount in the end. Here we just reserve for data.
*/ */
ret = dquot_reserve_block(inode, EXT4_C2B(sbi, 1)); ret = dquot_reserve_block(inode, EXT4_C2B(sbi, nr_resv));
if (ret) if (ret)
return ret; return ret;
spin_lock(&ei->i_block_reservation_lock); spin_lock(&ei->i_block_reservation_lock);
if (ext4_claim_free_clusters(sbi, 1, 0)) { if (ext4_claim_free_clusters(sbi, nr_resv, 0)) {
spin_unlock(&ei->i_block_reservation_lock); spin_unlock(&ei->i_block_reservation_lock);
dquot_release_reservation_block(inode, EXT4_C2B(sbi, 1)); dquot_release_reservation_block(inode, EXT4_C2B(sbi, nr_resv));
return -ENOSPC; return -ENOSPC;
} }
ei->i_reserved_data_blocks++; ei->i_reserved_data_blocks += nr_resv;
trace_ext4_da_reserve_space(inode); trace_ext4_da_reserve_space(inode, nr_resv);
spin_unlock(&ei->i_block_reservation_lock); spin_unlock(&ei->i_block_reservation_lock);
return 0; /* success */ return 0; /* success */
...@@ -1678,7 +1678,7 @@ static int ext4_insert_delayed_block(struct inode *inode, ext4_lblk_t lblk) ...@@ -1678,7 +1678,7 @@ static int ext4_insert_delayed_block(struct inode *inode, ext4_lblk_t lblk)
* extents status tree doesn't get a match. * extents status tree doesn't get a match.
*/ */
if (sbi->s_cluster_ratio == 1) { if (sbi->s_cluster_ratio == 1) {
ret = ext4_da_reserve_space(inode); ret = ext4_da_reserve_space(inode, 1);
if (ret != 0) /* ENOSPC */ if (ret != 0) /* ENOSPC */
return ret; return ret;
} else { /* bigalloc */ } else { /* bigalloc */
...@@ -1690,7 +1690,7 @@ static int ext4_insert_delayed_block(struct inode *inode, ext4_lblk_t lblk) ...@@ -1690,7 +1690,7 @@ static int ext4_insert_delayed_block(struct inode *inode, ext4_lblk_t lblk)
if (ret < 0) if (ret < 0)
return ret; return ret;
if (ret == 0) { if (ret == 0) {
ret = ext4_da_reserve_space(inode); ret = ext4_da_reserve_space(inode, 1);
if (ret != 0) /* ENOSPC */ if (ret != 0) /* ENOSPC */
return ret; return ret;
} else { } else {
......
...@@ -1246,14 +1246,15 @@ TRACE_EVENT(ext4_da_update_reserve_space, ...@@ -1246,14 +1246,15 @@ TRACE_EVENT(ext4_da_update_reserve_space,
); );
TRACE_EVENT(ext4_da_reserve_space, TRACE_EVENT(ext4_da_reserve_space,
TP_PROTO(struct inode *inode), TP_PROTO(struct inode *inode, int nr_resv),
TP_ARGS(inode), TP_ARGS(inode, nr_resv),
TP_STRUCT__entry( TP_STRUCT__entry(
__field( dev_t, dev ) __field( dev_t, dev )
__field( ino_t, ino ) __field( ino_t, ino )
__field( __u64, i_blocks ) __field( __u64, i_blocks )
__field( int, reserve_blocks )
__field( int, reserved_data_blocks ) __field( int, reserved_data_blocks )
__field( __u16, mode ) __field( __u16, mode )
), ),
...@@ -1262,16 +1263,17 @@ TRACE_EVENT(ext4_da_reserve_space, ...@@ -1262,16 +1263,17 @@ TRACE_EVENT(ext4_da_reserve_space,
__entry->dev = inode->i_sb->s_dev; __entry->dev = inode->i_sb->s_dev;
__entry->ino = inode->i_ino; __entry->ino = inode->i_ino;
__entry->i_blocks = inode->i_blocks; __entry->i_blocks = inode->i_blocks;
__entry->reserve_blocks = nr_resv;
__entry->reserved_data_blocks = EXT4_I(inode)->i_reserved_data_blocks; __entry->reserved_data_blocks = EXT4_I(inode)->i_reserved_data_blocks;
__entry->mode = inode->i_mode; __entry->mode = inode->i_mode;
), ),
TP_printk("dev %d,%d ino %lu mode 0%o i_blocks %llu " TP_printk("dev %d,%d ino %lu mode 0%o i_blocks %llu reserve_blocks %d"
"reserved_data_blocks %d", "reserved_data_blocks %d",
MAJOR(__entry->dev), MINOR(__entry->dev), MAJOR(__entry->dev), MINOR(__entry->dev),
(unsigned long) __entry->ino, (unsigned long) __entry->ino,
__entry->mode, __entry->i_blocks, __entry->mode, __entry->i_blocks,
__entry->reserved_data_blocks) __entry->reserve_blocks, __entry->reserved_data_blocks)
); );
TRACE_EVENT(ext4_da_release_space, TRACE_EVENT(ext4_da_release_space,
......
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