linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Jens Axboe <axboe@kernel.dk>
Cc: Denis Efremov <efremov@linux.com>, Tim Waugh <tim@cyberelk.net>,
	Michal Simek <michal.simek@xilinx.com>,
	Borislav Petkov <bp@alien8.de>,
	"David S. Miller" <davem@davemloft.net>,
	Song Liu <song@kernel.org>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	Finn Thain <fthain@telegraphics.com.au>,
	Michael Schmitz <schmitzmic@gmail.com>,
	linux-m68k@lists.linux-m68k.org, linux-block@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-ide@vger.kernel.org,
	linux-raid@vger.kernel.org, linux-scsi@vger.kernel.org,
	linux-fsdevel@vger.kernel.org,
	Johannes Thumshirn <johannes.thumshirn@wdc.com>
Subject: [PATCH 01/19] block: add a bdev_check_media_change helper
Date: Tue,  8 Sep 2020 16:53:29 +0200	[thread overview]
Message-ID: <20200908145347.2992670-2-hch@lst.de> (raw)
In-Reply-To: <20200908145347.2992670-1-hch@lst.de>

Like check_disk_changed, except that it does not call ->revalidate_disk
but leaves that to the caller.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 block/genhd.c         | 29 ++++++++++++++++++++++++++++-
 fs/block_dev.c        | 17 +++--------------
 include/linux/genhd.h |  2 +-
 3 files changed, 32 insertions(+), 16 deletions(-)

diff --git a/block/genhd.c b/block/genhd.c
index 081f1039d9367f..9d060e79eb31d8 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -2052,7 +2052,7 @@ void disk_flush_events(struct gendisk *disk, unsigned int mask)
  * CONTEXT:
  * Might sleep.
  */
-unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask)
+static unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask)
 {
 	struct disk_events *ev = disk->ev;
 	unsigned int pending;
@@ -2090,6 +2090,33 @@ unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask)
 	return pending;
 }
 
+/**
+ * bdev_check_media_change - check if a removable media has been changed
+ * @bdev: block device 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 block device changed, or %false if not.
+ */
+bool bdev_check_media_change(struct block_device *bdev)
+{
+	unsigned int events;
+
+	events = disk_clear_events(bdev->bd_disk, DISK_EVENT_MEDIA_CHANGE |
+				   DISK_EVENT_EJECT_REQUEST);
+	if (!(events & DISK_EVENT_MEDIA_CHANGE))
+		return false;
+
+	if (__invalidate_device(bdev, true))
+		pr_warn("VFS: busy inodes on changed media %s\n",
+			bdev->bd_disk->disk_name);
+	set_bit(BDEV_NEED_PART_SCAN, &bdev->bd_flags);
+	return true;
+}
+EXPORT_SYMBOL(bdev_check_media_change);
+
 /*
  * Separate this part out so that a different pointer for clearing_ptr can be
  * passed in for disk_clear_events.
diff --git a/fs/block_dev.c b/fs/block_dev.c
index c70c41ecba4872..c6ac0bd22eca70 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -1379,21 +1379,10 @@ EXPORT_SYMBOL(revalidate_disk_size);
  */
 int check_disk_change(struct block_device *bdev)
 {
-	struct gendisk *disk = bdev->bd_disk;
-	const struct block_device_operations *bdops = disk->fops;
-	unsigned int events;
-
-	events = disk_clear_events(disk, DISK_EVENT_MEDIA_CHANGE |
-				   DISK_EVENT_EJECT_REQUEST);
-	if (!(events & DISK_EVENT_MEDIA_CHANGE))
+	if (!bdev_check_media_change(bdev))
 		return 0;
-
-	if (__invalidate_device(bdev, true))
-		pr_warn("VFS: busy inodes on changed media %s\n",
-			disk->disk_name);
-	set_bit(BDEV_NEED_PART_SCAN, &bdev->bd_flags);
-	if (bdops->revalidate_disk)
-		bdops->revalidate_disk(bdev->bd_disk);
+	if (bdev->bd_disk->fops->revalidate_disk)
+		bdev->bd_disk->fops->revalidate_disk(bdev->bd_disk);
 	return 1;
 }
 
diff --git a/include/linux/genhd.h b/include/linux/genhd.h
index c618b27292fcc8..322d48a207728a 100644
--- a/include/linux/genhd.h
+++ b/include/linux/genhd.h
@@ -315,7 +315,6 @@ extern void disk_unblock_events(struct gendisk *disk);
 extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
 void set_capacity_revalidate_and_notify(struct gendisk *disk, sector_t size,
 		bool update_bdev);
-extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
 
 /* drivers/char/random.c */
 extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
@@ -372,6 +371,7 @@ void unregister_blkdev(unsigned int major, const char *name);
 
 void revalidate_disk_size(struct gendisk *disk, bool verbose);
 int check_disk_change(struct block_device *bdev);
+bool bdev_check_media_change(struct block_device *bdev);
 int __invalidate_device(struct block_device *bdev, bool kill_dirty);
 void bd_set_nr_sectors(struct block_device *bdev, sector_t sectors);
 
-- 
2.28.0


  reply	other threads:[~2020-09-08 20:07 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-08 14:53 rework check_disk_change() v2 Christoph Hellwig
2020-09-08 14:53 ` Christoph Hellwig [this message]
2020-09-09  6:59   ` [PATCH 01/19] block: add a bdev_check_media_change helper Hannes Reinecke
2020-09-08 14:53 ` [PATCH 02/19] amiflop: use bdev_check_media_change Christoph Hellwig
2020-09-09  6:59   ` Hannes Reinecke
2020-09-08 14:53 ` [PATCH 03/19] ataflop: " Christoph Hellwig
2020-09-09  7:00   ` Hannes Reinecke
2020-09-08 14:53 ` [PATCH 04/19] floppy: " Christoph Hellwig
2020-09-09  6:52   ` Johannes Thumshirn
2020-09-09  7:00   ` Hannes Reinecke
2020-09-08 14:53 ` [PATCH 05/19] swim: " Christoph Hellwig
2020-09-09  7:01   ` Hannes Reinecke
2020-09-08 14:53 ` [PATCH 06/19] swim: simplify media change handling Christoph Hellwig
2020-09-09  7:09   ` Hannes Reinecke
2020-09-08 14:53 ` [PATCH 07/19] swim3: use bdev_check_media_changed Christoph Hellwig
2020-09-09  7:10   ` Hannes Reinecke
2020-09-09  7:50   ` Sergei Shtylyov
2020-09-08 14:53 ` [PATCH 08/19] xsysace: use bdev_check_media_change Christoph Hellwig
2020-09-09  7:10   ` Hannes Reinecke
2020-09-08 14:53 ` [PATCH 09/19] xsysace: simplify media change handling Christoph Hellwig
2020-09-09  7:10   ` Hannes Reinecke
2020-09-08 14:53 ` [PATCH 10/19] paride/pcd: use bdev_check_media_change Christoph Hellwig
2020-09-09  7:26   ` Hannes Reinecke
2020-09-08 14:53 ` [PATCH 11/19] gdrom: " Christoph Hellwig
2020-09-09  7:27   ` Hannes Reinecke
2020-09-08 14:53 ` [PATCH 12/19] ide-cd: use bdev_check_media_changed Christoph Hellwig
2020-09-09  7:27   ` Hannes Reinecke
2020-09-08 14:53 ` [PATCH 13/19] ide-cd: remove idecd_revalidate_disk Christoph Hellwig
2020-09-09  7:28   ` Hannes Reinecke
2020-09-08 14:53 ` [PATCH 14/19] ide-gd: stop using the disk events mechanism Christoph Hellwig
2020-09-09  7:32   ` Hannes Reinecke
2020-09-08 14:53 ` [PATCH 15/19] md: use bdev_check_media_change Christoph Hellwig
2020-09-09  0:49   ` Song Liu
2020-09-09  7:34   ` Hannes Reinecke
2020-09-08 14:53 ` [PATCH 16/19] sd: " Christoph Hellwig
2020-09-09  7:36   ` Hannes Reinecke
2020-09-09  7:52   ` Sergei Shtylyov
2020-09-08 14:53 ` [PATCH 17/19] sr: " Christoph Hellwig
2020-09-09  7:37   ` Hannes Reinecke
2020-09-08 14:53 ` [PATCH 18/19] sr: simplify sr_block_revalidate_disk Christoph Hellwig
2020-09-09  7:38   ` Hannes Reinecke
2020-09-08 14:53 ` [PATCH 19/19] block: remove check_disk_change Christoph Hellwig
2020-09-09  7:39   ` Hannes Reinecke
2020-09-10 15:54 ` rework check_disk_change() v2 Jens Axboe
  -- strict thread matches above, loose matches on Subject: below --
2020-09-02 14:11 rework check_disk_change() Christoph Hellwig
2020-09-02 14:12 ` [PATCH 01/19] block: add a bdev_check_media_change helper Christoph Hellwig
2020-09-02 15:17   ` Johannes Thumshirn

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=20200908145347.2992670-2-hch@lst.de \
    --to=hch@lst.de \
    --cc=axboe@kernel.dk \
    --cc=bp@alien8.de \
    --cc=davem@davemloft.net \
    --cc=efremov@linux.com \
    --cc=fthain@telegraphics.com.au \
    --cc=johannes.thumshirn@wdc.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-m68k@lists.linux-m68k.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=michal.simek@xilinx.com \
    --cc=schmitzmic@gmail.com \
    --cc=song@kernel.org \
    --cc=tim@cyberelk.net \
    /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;
as well as URLs for NNTP newsgroup(s).