All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Christian Brauner <brauner@kernel.org>,
	Al Viro <viro@zeniv.linux.org.uk>, Jens Axboe <axboe@kernel.dk>
Cc: Jan Kara <jack@suse.cz>, Denis Efremov <efremov@linux.com>,
	linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org
Subject: [PATCH 3/5] block: move bdev_mark_dead out of disk_check_media_change
Date: Tue, 17 Oct 2023 20:48:21 +0200	[thread overview]
Message-ID: <20231017184823.1383356-4-hch@lst.de> (raw)
In-Reply-To: <20231017184823.1383356-1-hch@lst.de>

disk_check_media_change is mostly called from ->open where it makes
little sense to mark the file system on the device as dead, as we
are just opening it.  So instead of calling bdev_mark_dead from
disk_check_media_change move it into the few callers that are not
in an open instance.  This avoid calling into bdev_mark_dead and
thus taking s_umount with open_mutex held.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 block/disk-events.c     | 18 +++++++-----------
 drivers/block/ataflop.c |  4 +++-
 drivers/block/floppy.c  |  4 +++-
 3 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/block/disk-events.c b/block/disk-events.c
index 13c3372c465a39..2f697224386aa8 100644
--- a/block/disk-events.c
+++ b/block/disk-events.c
@@ -266,11 +266,8 @@ static unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask)
  * disk_check_media_change - check if a removable media has been changed
  * @disk: gendisk to check
  *
- * Check whether a removable media has been changed, and attempt to free all
- * dentries and inodes and invalidates all block device page cache entries in
- * that case.
- *
- * Returns %true if the media has changed, or %false if not.
+ * Returns %true and marks the disk for a partition rescan whether a removable
+ * media has been changed, and %false if the media did not change.
  */
 bool disk_check_media_change(struct gendisk *disk)
 {
@@ -278,12 +275,11 @@ bool disk_check_media_change(struct gendisk *disk)
 
 	events = disk_clear_events(disk, DISK_EVENT_MEDIA_CHANGE |
 				   DISK_EVENT_EJECT_REQUEST);
-	if (!(events & DISK_EVENT_MEDIA_CHANGE))
-		return false;
-
-	bdev_mark_dead(disk->part0, true);
-	set_bit(GD_NEED_PART_SCAN, &disk->state);
-	return true;
+	if (events & DISK_EVENT_MEDIA_CHANGE) {
+		set_bit(GD_NEED_PART_SCAN, &disk->state);
+		return true;
+	}
+	return false;
 }
 EXPORT_SYMBOL(disk_check_media_change);
 
diff --git a/drivers/block/ataflop.c b/drivers/block/ataflop.c
index cd738cab725f39..50949207798d2a 100644
--- a/drivers/block/ataflop.c
+++ b/drivers/block/ataflop.c
@@ -1760,8 +1760,10 @@ static int fd_locked_ioctl(struct block_device *bdev, blk_mode_t mode,
 		/* invalidate the buffer track to force a reread */
 		BufferDrive = -1;
 		set_bit(drive, &fake_change);
-		if (disk_check_media_change(disk))
+		if (disk_check_media_change(disk)) {
+			bdev_mark_dead(disk->part0, true);
 			floppy_revalidate(disk);
+		}
 		return 0;
 	default:
 		return -EINVAL;
diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index ea4eb88a2e45f4..11114a5d9e5c46 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -3215,8 +3215,10 @@ static int invalidate_drive(struct gendisk *disk)
 	/* invalidate the buffer track to force a reread */
 	set_bit((long)disk->private_data, &fake_change);
 	process_fd_request();
-	if (disk_check_media_change(disk))
+	if (disk_check_media_change(disk)) {
+		bdev_mark_dead(disk->part0, true);
 		floppy_revalidate(disk);
+	}
 	return 0;
 }
 
-- 
2.39.2


  parent reply	other threads:[~2023-10-17 18:48 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-17 18:48 don't take s_umount under open_mutex Christoph Hellwig
2023-10-17 18:48 ` [PATCH 1/5] block: simplify bdev_del_partition() Christoph Hellwig
2023-10-18  2:33   ` Ming Lei
2023-10-17 18:48 ` [PATCH 2/5] block: WARN_ON_ONCE() when we remove active partitions Christoph Hellwig
2023-10-18  2:36   ` Ming Lei
2023-10-19  8:31   ` Jan Kara
2023-10-17 18:48 ` Christoph Hellwig [this message]
2023-10-18  3:16   ` [PATCH 3/5] block: move bdev_mark_dead out of disk_check_media_change Ming Lei
2023-10-18  6:46     ` Christoph Hellwig
2023-10-18  9:15       ` Ming Lei
2023-10-18 12:10         ` Christoph Hellwig
2023-10-18  9:24   ` Christian Brauner
2023-10-19  5:57     ` Christoph Hellwig
2023-10-19  7:24       ` Christian Brauner
2023-10-19  8:34   ` Jan Kara
2023-10-17 18:48 ` [PATCH 4/5] block: assert that we're not holding open_mutex over blk_report_disk_dead Christoph Hellwig
2023-10-18  3:18   ` Ming Lei
2023-10-19  8:43   ` Jan Kara
2023-10-17 18:48 ` [PATCH 5/5] fs: assert that open_mutex isn't held over holder ops Christoph Hellwig
2023-10-18  9:53   ` Ming Lei
2023-10-19  8:43   ` Jan Kara
2023-10-19  9:35 ` don't take s_umount under open_mutex Christian Brauner
2023-10-19 11:27   ` Jens Axboe

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=20231017184823.1383356-4-hch@lst.de \
    --to=hch@lst.de \
    --cc=axboe@kernel.dk \
    --cc=brauner@kernel.org \
    --cc=efremov@linux.com \
    --cc=jack@suse.cz \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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.