Skip to content

Commit 2d069c0

Browse files
zhangyi089tytso
authored andcommitted
ext4: use common helpers in all places reading metadata buffers
Revome all open codes that read metadata buffers, switch to use ext4_read_bh_*() common helpers. Signed-off-by: zhangyi (F) <yi.zhang@huawei.com> Suggested-by: Jan Kara <jack@suse.cz> Link: https://lore.kernel.org/r/20200924073337.861472-4-yi.zhang@huawei.com Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent fa491b1 commit 2d069c0

9 files changed

Lines changed: 36 additions & 54 deletions

File tree

‎fs/ext4/balloc.c‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -494,12 +494,10 @@ ext4_read_block_bitmap_nowait(struct super_block *sb, ext4_group_t block_group,
494494
* submit the buffer_head for reading
495495
*/
496496
set_buffer_new(bh);
497-
clear_buffer_verified(bh);
498497
trace_ext4_read_block_bitmap_load(sb, block_group, ignore_locked);
499-
bh->b_end_io = ext4_end_bitmap_read;
500-
get_bh(bh);
501-
submit_bh(REQ_OP_READ, REQ_META | REQ_PRIO |
502-
(ignore_locked ? REQ_RAHEAD : 0), bh);
498+
ext4_read_bh_nowait(bh, REQ_META | REQ_PRIO |
499+
(ignore_locked ? REQ_RAHEAD : 0),
500+
ext4_end_bitmap_read);
503501
return bh;
504502
verify:
505503
err = ext4_validate_block_bitmap(sb, desc, block_group, bh);

‎fs/ext4/extents.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,7 @@ __read_extent_tree_block(const char *function, unsigned int line,
501501

502502
if (!bh_uptodate_or_lock(bh)) {
503503
trace_ext4_ext_load_extent(inode, pblk, _RET_IP_);
504-
clear_buffer_verified(bh);
505-
err = bh_submit_read(bh);
504+
err = ext4_read_bh(bh, 0, NULL);
506505
if (err < 0)
507506
goto errout;
508507
}

‎fs/ext4/ialloc.c‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,8 @@ ext4_read_inode_bitmap(struct super_block *sb, ext4_group_t block_group)
188188
/*
189189
* submit the buffer_head for reading
190190
*/
191-
clear_buffer_verified(bh);
192191
trace_ext4_load_inode_bitmap(sb, block_group);
193-
bh->b_end_io = ext4_end_bitmap_read;
194-
get_bh(bh);
195-
submit_bh(REQ_OP_READ, REQ_META | REQ_PRIO, bh);
196-
wait_on_buffer(bh);
192+
ext4_read_bh(bh, REQ_META | REQ_PRIO, ext4_end_bitmap_read);
197193
ext4_simulate_fail_bh(sb, bh, EXT4_SIM_IBITMAP_EIO);
198194
if (!buffer_uptodate(bh)) {
199195
put_bh(bh);

‎fs/ext4/indirect.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ static Indirect *ext4_get_branch(struct inode *inode, int depth,
163163
}
164164

165165
if (!bh_uptodate_or_lock(bh)) {
166-
if (bh_submit_read(bh) < 0) {
166+
if (ext4_read_bh(bh, 0, NULL) < 0) {
167167
put_bh(bh);
168168
goto failure;
169169
}

‎fs/ext4/inode.c‎

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -878,19 +878,20 @@ struct buffer_head *ext4_bread(handle_t *handle, struct inode *inode,
878878
ext4_lblk_t block, int map_flags)
879879
{
880880
struct buffer_head *bh;
881+
int ret;
881882

882883
bh = ext4_getblk(handle, inode, block, map_flags);
883884
if (IS_ERR(bh))
884885
return bh;
885886
if (!bh || ext4_buffer_uptodate(bh))
886887
return bh;
887-
clear_buffer_verified(bh);
888-
ll_rw_block(REQ_OP_READ, REQ_META | REQ_PRIO, 1, &bh);
889-
wait_on_buffer(bh);
890-
if (buffer_uptodate(bh))
891-
return bh;
892-
put_bh(bh);
893-
return ERR_PTR(-EIO);
888+
889+
ret = ext4_read_bh_lock(bh, REQ_META | REQ_PRIO, true);
890+
if (ret) {
891+
put_bh(bh);
892+
return ERR_PTR(ret);
893+
}
894+
return bh;
894895
}
895896

896897
/* Read a contiguous batch of blocks. */
@@ -910,11 +911,8 @@ int ext4_bread_batch(struct inode *inode, ext4_lblk_t block, int bh_count,
910911

911912
for (i = 0; i < bh_count; i++)
912913
/* Note that NULL bhs[i] is valid because of holes. */
913-
if (bhs[i] && !ext4_buffer_uptodate(bhs[i])) {
914-
clear_buffer_verified(bhs[i]);
915-
ll_rw_block(REQ_OP_READ, REQ_META | REQ_PRIO, 1,
916-
&bhs[i]);
917-
}
914+
if (bhs[i] && !ext4_buffer_uptodate(bhs[i]))
915+
ext4_read_bh_lock(bhs[i], REQ_META | REQ_PRIO, false);
918916

919917
if (!wait)
920918
return 0;
@@ -1084,7 +1082,7 @@ static int ext4_block_write_begin(struct page *page, loff_t pos, unsigned len,
10841082
if (!buffer_uptodate(bh) && !buffer_delay(bh) &&
10851083
!buffer_unwritten(bh) &&
10861084
(block_start < from || block_end > to)) {
1087-
ll_rw_block(REQ_OP_READ, 0, 1, &bh);
1085+
ext4_read_bh_lock(bh, 0, false);
10881086
wait[nr_wait++] = bh;
10891087
}
10901088
}
@@ -3756,11 +3754,8 @@ static int __ext4_block_zero_page_range(handle_t *handle,
37563754
set_buffer_uptodate(bh);
37573755

37583756
if (!buffer_uptodate(bh)) {
3759-
err = -EIO;
3760-
ll_rw_block(REQ_OP_READ, 0, 1, &bh);
3761-
wait_on_buffer(bh);
3762-
/* Uhhuh. Read error. Complain and punt. */
3763-
if (!buffer_uptodate(bh))
3757+
err = ext4_read_bh_lock(bh, 0, true);
3758+
if (err)
37643759
goto unlock;
37653760
if (fscrypt_inode_uses_fs_layer_crypto(inode)) {
37663761
/* We expect the key to be set. */
@@ -4404,9 +4399,7 @@ static int __ext4_get_inode_loc(struct inode *inode,
44044399
* Read the block from disk.
44054400
*/
44064401
trace_ext4_load_inode(inode);
4407-
get_bh(bh);
4408-
bh->b_end_io = end_buffer_read_sync;
4409-
submit_bh(REQ_OP_READ, REQ_META | REQ_PRIO, bh);
4402+
ext4_read_bh_nowait(bh, REQ_META | REQ_PRIO, NULL);
44104403
blk_finish_plug(&plug);
44114404
wait_on_buffer(bh);
44124405
if (!buffer_uptodate(bh)) {

‎fs/ext4/mmp.c‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,11 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
8585
}
8686
}
8787

88-
get_bh(*bh);
8988
lock_buffer(*bh);
90-
(*bh)->b_end_io = end_buffer_read_sync;
91-
submit_bh(REQ_OP_READ, REQ_META | REQ_PRIO, *bh);
92-
wait_on_buffer(*bh);
93-
if (!buffer_uptodate(*bh)) {
94-
ret = -EIO;
89+
ret = ext4_read_bh(*bh, REQ_META | REQ_PRIO, NULL);
90+
if (ret)
9591
goto warn_exit;
96-
}
92+
9793
mmp = (struct mmp_struct *)((*bh)->b_data);
9894
if (le32_to_cpu(mmp->mmp_magic) != EXT4_MMP_MAGIC) {
9995
ret = -EFSCORRUPTED;

‎fs/ext4/move_extent.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ mext_page_mkuptodate(struct page *page, unsigned from, unsigned to)
215215
for (i = 0; i < nr; i++) {
216216
bh = arr[i];
217217
if (!bh_uptodate_or_lock(bh)) {
218-
err = bh_submit_read(bh);
218+
err = ext4_read_bh(bh, 0, NULL);
219219
if (err)
220220
return err;
221221
}

‎fs/ext4/resize.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,7 @@ static struct buffer_head *ext4_get_bitmap(struct super_block *sb, __u64 block)
12451245
if (unlikely(!bh))
12461246
return NULL;
12471247
if (!bh_uptodate_or_lock(bh)) {
1248-
if (bh_submit_read(bh) < 0) {
1248+
if (ext4_read_bh(bh, 0, NULL) < 0) {
12491249
brelse(bh);
12501250
return NULL;
12511251
}

‎fs/ext4/super.c‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -212,19 +212,21 @@ int ext4_read_bh_lock(struct buffer_head *bh, int op_flags, bool wait)
212212
struct buffer_head *
213213
ext4_sb_bread(struct super_block *sb, sector_t block, int op_flags)
214214
{
215-
struct buffer_head *bh = sb_getblk(sb, block);
215+
struct buffer_head *bh;
216+
int ret;
216217

218+
bh = sb_getblk(sb, block);
217219
if (bh == NULL)
218220
return ERR_PTR(-ENOMEM);
219221
if (ext4_buffer_uptodate(bh))
220222
return bh;
221-
clear_buffer_verified(bh);
222-
ll_rw_block(REQ_OP_READ, REQ_META | op_flags, 1, &bh);
223-
wait_on_buffer(bh);
224-
if (buffer_uptodate(bh))
225-
return bh;
226-
put_bh(bh);
227-
return ERR_PTR(-EIO);
223+
224+
ret = ext4_read_bh_lock(bh, REQ_META | op_flags, true);
225+
if (ret) {
226+
put_bh(bh);
227+
return ERR_PTR(ret);
228+
}
229+
return bh;
228230
}
229231

230232
static int ext4_verify_csum_type(struct super_block *sb,
@@ -5176,9 +5178,7 @@ static journal_t *ext4_get_dev_journal(struct super_block *sb,
51765178
goto out_bdev;
51775179
}
51785180
journal->j_private = sb;
5179-
ll_rw_block(REQ_OP_READ, REQ_META | REQ_PRIO, 1, &journal->j_sb_buffer);
5180-
wait_on_buffer(journal->j_sb_buffer);
5181-
if (!buffer_uptodate(journal->j_sb_buffer)) {
5181+
if (ext4_read_bh_lock(journal->j_sb_buffer, REQ_META | REQ_PRIO, true)) {
51825182
ext4_msg(sb, KERN_ERR, "I/O error on journal device");
51835183
goto out_journal;
51845184
}

0 commit comments

Comments
 (0)