All of lore.kernel.org
 help / color / mirror / Atom feed
From: "zhangyi (F)" <yi.zhang@huawei.com>
To: <linux-ext4@vger.kernel.org>
Cc: <tytso@mit.edu>, <jack@suse.cz>, <adilger.kernel@dilger.ca>,
	<yi.zhang@huawei.com>, <zhangxiaoxu5@huawei.com>
Subject: [PATCH 08/10] ext4: replace sb_breadahead() with ext4_sb_breadahead()
Date: Tue, 26 May 2020 15:17:52 +0800	[thread overview]
Message-ID: <20200526071754.33819-9-yi.zhang@huawei.com> (raw)
In-Reply-To: <20200526071754.33819-1-yi.zhang@huawei.com>

For the cases of read ahead blocks, we also need to check the write io
error flag to prevent reading block from disk if it is actually
uptodate. Add a new wrapper ext4_sb_breadahead() to check the uptodate
flag and prevent unnecessary read operation, and replace all
sb_breadahead().

Signed-off-by: zhangyi (F) <yi.zhang@huawei.com>
---
 fs/ext4/ext4.h  | 11 +++++------
 fs/ext4/inode.c |  2 +-
 fs/ext4/super.c | 19 ++++++++++++++++++-
 3 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 81c1bdfb9397..cafa2617a093 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -2767,6 +2767,8 @@ extern struct buffer_head *__ext4_sb_getblk(struct super_block *sb,
 extern struct buffer_head *__ext4_sb_bread_gfp(struct super_block *sb,
 					       sector_t block, int op_flags,
 					       gfp_t gfp);
+extern void ext4_sb_breadahead_unmovable(struct super_block *sb,
+					 sector_t block);
 extern int ext4_seq_options_show(struct seq_file *seq, void *offset);
 extern int ext4_calculate_overhead(struct super_block *sb);
 extern void ext4_superblock_csum_set(struct super_block *sb);
@@ -3533,13 +3535,10 @@ static inline int ext4_buffer_uptodate(struct buffer_head *bh)
 {
 	/*
 	 * If the buffer has the write error flag, we have failed
-	 * to write out data in the block.  In this  case, we don't
-	 * have to read the block because we may read the old data
-	 * successfully.
+	 * to write out this metadata block. In this case, the data
+	 * in this block is uptodate.
 	 */
-	if (!buffer_uptodate(bh) && buffer_write_io_error(bh))
-		set_buffer_uptodate(bh);
-	return buffer_uptodate(bh);
+	return buffer_uptodate(bh) || buffer_write_io_error(bh);
 }
 
 #endif	/* __KERNEL__ */
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 4989a9633fc7..7354edb444c5 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -4351,7 +4351,7 @@ static int __ext4_get_inode_loc(struct inode *inode,
 			if (end > table)
 				end = table;
 			while (b <= end)
-				sb_breadahead_unmovable(sb, b++);
+				ext4_sb_breadahead_unmovable(sb, b++);
 		}
 
 		/*
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index b9aab334a5d0..d25a0fe44bec 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -218,6 +218,23 @@ __ext4_sb_bread_gfp(struct super_block *sb, sector_t block,
 	return ERR_PTR(-EIO);
 }
 
+/*
+ * This works like sb_breadahead_unmovable() except it use
+ * ext4_buffer_uptodate() instead of buffer_uptodate() to check the
+ * metadata buffer is actually uptodate or not. The buffer should be
+ * considered as actually uptodate for the case of it has been
+ * failed to write out.
+ */
+void ext4_sb_breadahead_unmovable(struct super_block *sb, sector_t block)
+{
+	struct buffer_head *bh = ext4_sb_getblk_gfp(sb, block, 0);
+
+	if (likely(bh) && !ext4_buffer_uptodate(bh)) {
+		ll_rw_block(REQ_OP_READ, REQ_META | REQ_RAHEAD, 1, &bh);
+		brelse(bh);
+	}
+}
+
 static int ext4_verify_csum_type(struct super_block *sb,
 				 struct ext4_super_block *es)
 {
@@ -4395,7 +4412,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
 	/* Pre-read the descriptors into the buffer cache */
 	for (i = 0; i < db_count; i++) {
 		block = descriptor_loc(sb, logical_sb_block, i);
-		sb_breadahead_unmovable(sb, block);
+		ext4_sb_breadahead_unmovable(sb, block);
 	}
 
 	for (i = 0; i < db_count; i++) {
-- 
2.21.3


  parent reply	other threads:[~2020-05-26  7:19 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-26  7:17 [PATCH 00/10] ext4: fix inconsistency since reading old metadata from disk zhangyi (F)
2020-05-26  7:17 ` [PATCH 01/10] ext4: move inode eio simulation behind io completeion zhangyi (F)
2020-05-26  7:17 ` [PATCH 02/10] fs: pick out ll_rw_one_block() helper function zhangyi (F)
2020-05-28  5:07   ` Christoph Hellwig
2020-05-28 13:23     ` zhangyi (F)
2020-05-26  7:17 ` [PATCH 03/10] ext4: add ext4_sb_getblk*() wrapper functions zhangyi (F)
2020-05-26  7:17 ` [PATCH 04/10] ext4: replace sb_getblk() with ext4_sb_getblk_locked() zhangyi (F)
2020-05-26  7:17 ` [PATCH 05/10] ext4: replace sb_bread*() with ext4_sb_bread*() zhangyi (F)
2020-05-26  7:17 ` [PATCH 06/10] ext4: replace sb_getblk() with ext4_sb_getblk() zhangyi (F)
2020-05-26  7:17 ` [PATCH 07/10] ext4: switch to use ext4_sb_getblk_locked() in ext4_getblk() zhangyi (F)
2020-05-26  7:17 ` zhangyi (F) [this message]
2020-05-26  7:17 ` [PATCH 09/10] ext4: abort the filesystem while freeing the write error io buffer zhangyi (F)
2020-05-26  7:17 ` [PATCH 10/10] ext4: remove unused parameter in jbd2_journal_try_to_free_buffers() zhangyi (F)
2020-06-08  3:32 ` [PATCH 00/10] ext4: fix inconsistency since reading old metadata from disk zhangyi (F)
2020-06-08  8:20 ` Jan Kara
2020-06-08 14:39   ` zhangyi (F)
2020-06-09 12:19     ` Jan Kara
2020-06-10  8:55       ` zhangyi (F)
2020-06-10  9:57         ` Jan Kara
2020-06-10 15:45           ` Theodore Y. Ts'o
2020-06-10 16:27             ` Jan Kara
2020-06-11  2:12               ` zhangyi (F)
2020-06-11  8:21                 ` Jan Kara
2020-06-11 16:55                   ` Theodore Y. Ts'o
2020-06-12 11:13                     ` zhangyi (F)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200526071754.33819-9-yi.zhang@huawei.com \
    --to=yi.zhang@huawei.com \
    --cc=adilger.kernel@dilger.ca \
    --cc=jack@suse.cz \
    --cc=linux-ext4@vger.kernel.org \
    --cc=tytso@mit.edu \
    --cc=zhangxiaoxu5@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.