public inbox for linux-ext4@vger.kernel.org
 help / color / mirror / Atom feed
From: Zhang Yi <yi.zhang@huawei.com>
To: <linux-ext4@vger.kernel.org>
Cc: <tytso@mit.edu>, <adilger.kernel@dilger.ca>, <jack@suse.cz>,
	<yi.zhang@huawei.com>, <yukuai3@huawei.com>
Subject: [PATCH] ext4: add barrier info if journal device write cache is not enabled
Date: Thu, 24 Nov 2022 21:57:44 +0800	[thread overview]
Message-ID: <20221124135744.1488959-1-yi.zhang@huawei.com> (raw)

The block layer will check and suppress flush bio if the device write
cache is not enabled, so the journal barrier will not go into effect
even if uer specify 'barrier=1' mount option. It's dangerous if the
write cache state is false negative, and we cannot distinguish such
case easily. So just give an info and an inquire interface to let
sysadmin know the barrier is suppressed for the case of write cache is
not enabled.

Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
---
 fs/ext4/super.c |  3 +++
 fs/ext4/sysfs.c | 19 +++++++++++++++++++
 2 files changed, 22 insertions(+)

diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 7cdd2138c897..916f756ebbca 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -5920,6 +5920,9 @@ static int ext4_load_journal(struct super_block *sb,
 
 	if (!(journal->j_flags & JBD2_BARRIER))
 		ext4_msg(sb, KERN_INFO, "barriers disabled");
+	else if (!bdev_write_cache(journal->j_dev))
+		ext4_msg(sb, KERN_INFO, "journal device write cache disabled, "
+					"barriers suppressed");
 
 	if (!ext4_has_feature_journal_needs_recovery(sb))
 		err = jbd2_journal_wipe(journal, !really_read_only);
diff --git a/fs/ext4/sysfs.c b/fs/ext4/sysfs.c
index d233c24ea342..67f619c1202e 100644
--- a/fs/ext4/sysfs.c
+++ b/fs/ext4/sysfs.c
@@ -37,6 +37,7 @@ typedef enum {
 	attr_pointer_string,
 	attr_pointer_atomic,
 	attr_journal_task,
+	attr_journal_barrier,
 } attr_id_t;
 
 typedef enum {
@@ -135,6 +136,20 @@ static ssize_t journal_task_show(struct ext4_sb_info *sbi, char *buf)
 			task_pid_vnr(sbi->s_journal->j_task));
 }
 
+static ssize_t journal_barrier_show(struct ext4_sb_info *sbi, char *buf)
+{
+	journal_t *journal = sbi->s_journal;
+
+	if (!journal)
+		return sysfs_emit(buf, "none\n");
+
+	if (!(journal->j_flags & JBD2_BARRIER))
+		return sysfs_emit(buf, "disabled\n");
+	if (!bdev_write_cache(sbi->s_journal->j_dev))
+		return sysfs_emit(buf, "suppressed\n");
+	return sysfs_emit(buf, "enabled\n");
+}
+
 #define EXT4_ATTR(_name,_mode,_id)					\
 static struct ext4_attr ext4_attr_##_name = {				\
 	.attr = {.name = __stringify(_name), .mode = _mode },		\
@@ -243,6 +258,7 @@ EXT4_RO_ATTR_ES_STRING(last_error_func, s_last_error_func, 32);
 EXT4_ATTR(first_error_time, 0444, first_error_time);
 EXT4_ATTR(last_error_time, 0444, last_error_time);
 EXT4_ATTR(journal_task, 0444, journal_task);
+EXT4_ATTR(journal_barrier, 0444, journal_barrier);
 EXT4_RW_ATTR_SBI_UI(mb_prefetch, s_mb_prefetch);
 EXT4_RW_ATTR_SBI_UI(mb_prefetch_limit, s_mb_prefetch_limit);
 EXT4_RW_ATTR_SBI_UL(last_trim_minblks, s_last_trim_minblks);
@@ -291,6 +307,7 @@ static struct attribute *ext4_attrs[] = {
 	ATTR_LIST(first_error_time),
 	ATTR_LIST(last_error_time),
 	ATTR_LIST(journal_task),
+	ATTR_LIST(journal_barrier),
 #ifdef CONFIG_EXT4_DEBUG
 	ATTR_LIST(simulate_fail),
 #endif
@@ -438,6 +455,8 @@ static ssize_t ext4_attr_show(struct kobject *kobj,
 		return print_tstamp(buf, sbi->s_es, s_last_error_time);
 	case attr_journal_task:
 		return journal_task_show(sbi, buf);
+	case attr_journal_barrier:
+		return journal_barrier_show(sbi, buf);
 	}
 
 	return 0;
-- 
2.31.1


             reply	other threads:[~2022-11-24 13:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-24 13:57 Zhang Yi [this message]
2022-11-28 10:11 ` [PATCH] ext4: add barrier info if journal device write cache is not enabled Jan Kara
2022-11-28 13:01   ` Zhang Yi
2022-11-28 15:15     ` Jan Kara
2022-11-29  6:16       ` Zhang Yi

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=20221124135744.1488959-1-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=yukuai3@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox