block: don't warn when doing fsync on read-only devices

This change “block: don't warn when doing fsync on read-only devices” (commit 8b2ded1) in Linux kernel is authored by Mikulas Patocka <mpatocka [at] redhat.com> on Wed Sep 5 16:14:36 2018 -0600.

Description of "block: don't warn when doing fsync on read-only devices"

The change “block: don't warn when doing fsync on read-only devices” introduces changes as follows.

block: don't warn when doing fsync on read-only devices

It is possible to call fsync on a read-only handle (for example, fsck.ext2
does it when doing read-only check), and this call results in kernel
warning.

The patch b089cfd95d32 ("block: don't warn for flush on read-only device")
attempted to disable the warning, but it is buggy and it doesn't
(op_is_flush tests flags, but bio_op strips off the flags).

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Fixes: 721c7fc701c7 ("block: fail op_is_write() requests to read-only partitions")
Cc: stable@vger.kernel.org      # 4.18
Signed-off-by: Jens Axboe <axboe@kernel.dk>

Linux kernel releases containing commit 8b2ded1

The Linux kernel releases containing this commit are as follows.

Linux kernel code changes from "block: don't warn when doing fsync on read-only devices"

There are 5 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 block/blk-core.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
 
diff --git a/block/blk-core.c b/block/blk-core.c
index dee56c282efb..4dbc93f43b38 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -2163,9 +2163,12 @@ static inline bool bio_check_ro(struct bio *bio, struct hd_struct *part)
 {
 	const int op = bio_op(bio);
 
-	if (part->policy && (op_is_write(op) && !op_is_flush(op))) {
+	if (part->policy && op_is_write(op)) {
 		char b[BDEVNAME_SIZE];
 
+		if (op_is_flush(bio->bi_opf) && !bio_sectors(bio))
+			return false;
+
 		WARN_ONCE(1,
 		       "generic_make_request: Trying to write "
 			"to read-only block-device %s (partno %d)\n",

The commit for this change in Linux stable tree is 8b2ded1 (patch).

Last modified: 2020/02/09