From: Christoph Hellwig <hch@lst.de>
To: Jens Axboe <axboe@kernel.dk>
Cc: Richard Weinberger <richard@nod.at>,
Josef Bacik <josef@toxicpanda.com>,
"Md. Haris Iqbal" <haris.iqbal@ionos.com>,
Jack Wang <jinpu.wang@ionos.com>,
Phillip Potter <phil@philpotter.co.uk>, Coly Li <colyli@suse.de>,
Miquel Raynal <miquel.raynal@bootlin.com>,
Vignesh Raghavendra <vigneshr@ti.com>,
"Martin K. Petersen" <martin.petersen@oracle.com>,
Chris Mason <clm@fb.com>, David Sterba <dsterba@suse.com>,
Alexander Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Pavel Machek <pavel@ucw.cz>,
dm-devel@redhat.com, linux-block@vger.kernel.org,
linux-um@lists.infradead.org, linux-scsi@vger.kernel.org,
linux-bcache@vger.kernel.org, linux-mtd@lists.infradead.org,
linux-nvme@lists.infradead.org
Subject: [PATCH 07/30] block: pass a gendisk on bdev_check_media_change
Date: Thu, 8 Jun 2023 13:02:35 +0200 [thread overview]
Message-ID: <20230608110258.189493-8-hch@lst.de> (raw)
In-Reply-To: <20230608110258.189493-1-hch@lst.de>
bdev_check_media_change should only ever be called for the whole device.
Pass a gendisk to make that explicit and rename the function to
disk_check_media_change.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Acked-by: Christian Brauner <brauner@kernel.org>
---
block/disk-events.c | 18 +++++++++---------
drivers/block/amiflop.c | 2 +-
drivers/block/ataflop.c | 6 +++---
drivers/block/floppy.c | 16 ++++++++--------
drivers/block/swim.c | 2 +-
drivers/block/swim3.c | 2 +-
drivers/cdrom/gdrom.c | 2 +-
drivers/md/md.c | 2 +-
drivers/scsi/sd.c | 9 ++++-----
drivers/scsi/sr.c | 2 +-
include/linux/blkdev.h | 2 +-
11 files changed, 31 insertions(+), 32 deletions(-)
diff --git a/block/disk-events.c b/block/disk-events.c
index aee25a7e1ab7de..8b1b63225738f8 100644
--- a/block/disk-events.c
+++ b/block/disk-events.c
@@ -263,31 +263,31 @@ static unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask)
}
/**
- * bdev_check_media_change - check if a removable media has been changed
- * @bdev: block device to check
+ * 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 block device changed, or %false if not.
+ * Returns %true if the media has changed, or %false if not.
*/
-bool bdev_check_media_change(struct block_device *bdev)
+bool disk_check_media_change(struct gendisk *disk)
{
unsigned int events;
- events = disk_clear_events(bdev->bd_disk, DISK_EVENT_MEDIA_CHANGE |
+ events = disk_clear_events(disk, DISK_EVENT_MEDIA_CHANGE |
DISK_EVENT_EJECT_REQUEST);
if (!(events & DISK_EVENT_MEDIA_CHANGE))
return false;
- if (__invalidate_device(bdev, true))
+ if (__invalidate_device(disk->part0, true))
pr_warn("VFS: busy inodes on changed media %s\n",
- bdev->bd_disk->disk_name);
- set_bit(GD_NEED_PART_SCAN, &bdev->bd_disk->state);
+ disk->disk_name);
+ set_bit(GD_NEED_PART_SCAN, &disk->state);
return true;
}
-EXPORT_SYMBOL(bdev_check_media_change);
+EXPORT_SYMBOL(disk_check_media_change);
/**
* disk_force_media_change - force a media change event
diff --git a/drivers/block/amiflop.c b/drivers/block/amiflop.c
index 4c8b2ba579ee6d..6de12b311749a1 100644
--- a/drivers/block/amiflop.c
+++ b/drivers/block/amiflop.c
@@ -1675,7 +1675,7 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
}
if (mode & (FMODE_READ|FMODE_WRITE)) {
- bdev_check_media_change(bdev);
+ disk_check_media_change(bdev->bd_disk);
if (mode & FMODE_WRITE) {
int wrprot;
diff --git a/drivers/block/ataflop.c b/drivers/block/ataflop.c
index 9deb4df6bdb8b2..da481ddbca90db 100644
--- a/drivers/block/ataflop.c
+++ b/drivers/block/ataflop.c
@@ -1760,8 +1760,8 @@ static int fd_locked_ioctl(struct block_device *bdev, fmode_t mode,
/* invalidate the buffer track to force a reread */
BufferDrive = -1;
set_bit(drive, &fake_change);
- if (bdev_check_media_change(bdev))
- floppy_revalidate(bdev->bd_disk);
+ if (disk_check_media_change(disk))
+ floppy_revalidate(disk);
return 0;
default:
return -EINVAL;
@@ -1938,7 +1938,7 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
return 0;
if (mode & (FMODE_READ|FMODE_WRITE)) {
- if (bdev_check_media_change(bdev))
+ if (disk_check_media_change(bdev->bd_disk))
floppy_revalidate(bdev->bd_disk);
if (mode & FMODE_WRITE) {
if (p->wpstat) {
diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index 28ec6b442e9c58..3accafcbc95c85 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -3210,13 +3210,13 @@ static int floppy_raw_cmd_ioctl(int type, int drive, int cmd,
#endif
-static int invalidate_drive(struct block_device *bdev)
+static int invalidate_drive(struct gendisk *disk)
{
/* invalidate the buffer track to force a reread */
- set_bit((long)bdev->bd_disk->private_data, &fake_change);
+ set_bit((long)disk->private_data, &fake_change);
process_fd_request();
- if (bdev_check_media_change(bdev))
- floppy_revalidate(bdev->bd_disk);
+ if (disk_check_media_change(disk))
+ floppy_revalidate(disk);
return 0;
}
@@ -3287,7 +3287,7 @@ static int set_geometry(unsigned int cmd, struct floppy_struct *g,
drive_state[current_drive].maxtrack ||
((user_params[drive].sect ^ oldStretch) &
(FD_SWAPSIDES | FD_SECTBASEMASK)))
- invalidate_drive(bdev);
+ invalidate_drive(bdev->bd_disk);
else
process_fd_request();
}
@@ -3464,7 +3464,7 @@ static int fd_locked_ioctl(struct block_device *bdev, fmode_t mode, unsigned int
current_type[drive] = NULL;
floppy_sizes[drive] = MAX_DISK_SIZE << 1;
drive_state[drive].keep_data = 0;
- return invalidate_drive(bdev);
+ return invalidate_drive(bdev->bd_disk);
case FDSETPRM:
case FDDEFPRM:
return set_geometry(cmd, &inparam.g, drive, type, bdev);
@@ -3503,7 +3503,7 @@ static int fd_locked_ioctl(struct block_device *bdev, fmode_t mode, unsigned int
case FDFLUSH:
if (lock_fdc(drive))
return -EINTR;
- return invalidate_drive(bdev);
+ return invalidate_drive(bdev->bd_disk);
case FDSETEMSGTRESH:
drive_params[drive].max_errors.reporting = (unsigned short)(param & 0x0f);
return 0;
@@ -4054,7 +4054,7 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
drive_state[drive].last_checked = 0;
clear_bit(FD_OPEN_SHOULD_FAIL_BIT,
&drive_state[drive].flags);
- if (bdev_check_media_change(bdev))
+ if (disk_check_media_change(bdev->bd_disk))
floppy_revalidate(bdev->bd_disk);
if (test_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags))
goto out;
diff --git a/drivers/block/swim.c b/drivers/block/swim.c
index 42b4b682869096..105bc5fd1b8c62 100644
--- a/drivers/block/swim.c
+++ b/drivers/block/swim.c
@@ -640,7 +640,7 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
return 0;
if (mode & (FMODE_READ|FMODE_WRITE)) {
- if (bdev_check_media_change(bdev) && fs->disk_in)
+ if (disk_check_media_change(bdev->bd_disk) && fs->disk_in)
fs->ejected = 0;
if ((mode & FMODE_WRITE) && fs->write_protected) {
err = -EROFS;
diff --git a/drivers/block/swim3.c b/drivers/block/swim3.c
index da811a7da03f3d..3d689ba312f568 100644
--- a/drivers/block/swim3.c
+++ b/drivers/block/swim3.c
@@ -963,7 +963,7 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
if (err == 0 && (mode & FMODE_NDELAY) == 0
&& (mode & (FMODE_READ|FMODE_WRITE))) {
- if (bdev_check_media_change(bdev))
+ if (disk_check_media_change(bdev->bd_disk))
floppy_revalidate(bdev->bd_disk);
if (fs->ejected)
err = -ENXIO;
diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
index a401dc4218a998..3cb92df38ebeb8 100644
--- a/drivers/cdrom/gdrom.c
+++ b/drivers/cdrom/gdrom.c
@@ -478,7 +478,7 @@ static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
{
int ret;
- bdev_check_media_change(bdev);
+ disk_check_media_change(bdev->bd_disk);
mutex_lock(&gdrom_mutex);
ret = cdrom_open(gd.cd_info);
diff --git a/drivers/md/md.c b/drivers/md/md.c
index fabf9c543735b6..77046c91bea439 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -7789,7 +7789,7 @@ static int md_open(struct block_device *bdev, fmode_t mode)
atomic_inc(&mddev->openers);
mutex_unlock(&mddev->open_mutex);
- bdev_check_media_change(bdev);
+ disk_check_media_change(bdev->bd_disk);
return 0;
out_unlock:
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 1624d528aa1f9c..aab649d5bad3f8 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -1280,11 +1280,10 @@ static void sd_uninit_command(struct scsi_cmnd *SCpnt)
mempool_free(rq->special_vec.bv_page, sd_page_pool);
}
-static bool sd_need_revalidate(struct block_device *bdev,
- struct scsi_disk *sdkp)
+static bool sd_need_revalidate(struct gendisk *disk, struct scsi_disk *sdkp)
{
if (sdkp->device->removable || sdkp->write_prot) {
- if (bdev_check_media_change(bdev))
+ if (disk_check_media_change(disk))
return true;
}
@@ -1293,7 +1292,7 @@ static bool sd_need_revalidate(struct block_device *bdev,
* nothing to do with partitions, BLKRRPART is used to force a full
* revalidate after things like a format for historical reasons.
*/
- return test_bit(GD_NEED_PART_SCAN, &bdev->bd_disk->state);
+ return test_bit(GD_NEED_PART_SCAN, &disk->state);
}
/**
@@ -1330,7 +1329,7 @@ static int sd_open(struct block_device *bdev, fmode_t mode)
if (!scsi_block_when_processing_errors(sdev))
goto error_out;
- if (sd_need_revalidate(bdev, sdkp))
+ if (sd_need_revalidate(bdev->bd_disk, sdkp))
sd_revalidate_disk(bdev->bd_disk);
/*
diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c
index 6d33120ee5ba85..1592e6e10c7452 100644
--- a/drivers/scsi/sr.c
+++ b/drivers/scsi/sr.c
@@ -494,7 +494,7 @@ static int sr_block_open(struct block_device *bdev, fmode_t mode)
return -ENXIO;
scsi_autopm_get_device(sdev);
- if (bdev_check_media_change(bdev))
+ if (disk_check_media_change(bdev->bd_disk))
sr_revalidate_disk(cd);
mutex_lock(&cd->lock);
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index f4c339d9dd03de..a1688eba7e5e9a 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -817,7 +817,7 @@ int __register_blkdev(unsigned int major, const char *name,
__register_blkdev(major, name, NULL)
void unregister_blkdev(unsigned int major, const char *name);
-bool bdev_check_media_change(struct block_device *bdev);
+bool disk_check_media_change(struct gendisk *disk);
int __invalidate_device(struct block_device *bdev, bool kill_dirty);
void set_capacity(struct gendisk *disk, sector_t size);
--
2.39.2
next prev parent reply other threads:[~2023-06-08 11:02 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-08 11:02 decouple block open flags from fmode_t v2 Christoph Hellwig
2023-06-08 11:02 ` [PATCH 01/30] block: also call ->open for incremental partition opens Christoph Hellwig
[not found] ` <20230608110258.189493-2-hch-jcswGhMUV9g@public.gmane.org>
2023-07-06 0:18 ` [f2fs-dev] " patchwork-bot+f2fs-DgEjT+Ai2ygdnm+yROfE0A
2023-08-25 2:44 ` Al Viro
2023-08-28 12:09 ` Christoph Hellwig
2023-06-08 11:02 ` [PATCH 02/30] cdrom: remove the unused bdev argument to cdrom_open Christoph Hellwig
2023-06-08 11:02 ` [PATCH 03/30] cdrom: remove the unused mode argument to cdrom_ioctl Christoph Hellwig
2023-06-08 11:02 ` [PATCH 04/30] cdrom: remove the unused cdrom_close_write release code Christoph Hellwig
2023-06-08 11:02 ` [PATCH 05/30] cdrom: track if a cdrom_device_info was opened for data Christoph Hellwig
2023-06-09 6:37 ` Hannes Reinecke
2023-06-08 11:02 ` [PATCH 06/30] cdrom: remove the unused mode argument to cdrom_release Christoph Hellwig
2023-06-08 11:02 ` Christoph Hellwig [this message]
2023-06-08 11:02 ` [PATCH 08/30] block: pass a gendisk to ->open Christoph Hellwig
2023-06-08 11:02 ` [PATCH 09/30] block: remove the unused mode argument to ->release Christoph Hellwig
2023-06-08 11:02 ` [PATCH 10/30] block: rename blkdev_close to blkdev_release Christoph Hellwig
2023-06-08 11:02 ` [PATCH 11/30] swsusp: don't pass a stack address to blkdev_get_by_path Christoph Hellwig
2023-06-09 18:13 ` Rafael J. Wysocki
2023-06-08 11:02 ` [PATCH 12/30] bcache: " Christoph Hellwig
2023-06-08 11:02 ` [PATCH 13/30] rnbd-srv: don't pass a holder for non-exclusive blkdev_get_by_path Christoph Hellwig
2023-06-08 11:02 ` [PATCH 14/30] btrfs: " Christoph Hellwig
2023-06-08 11:02 ` [PATCH 15/30] block: use the holder as indication for exclusive opens Christoph Hellwig
2023-06-08 11:02 ` [PATCH 16/30] block: add a sb_open_mode helper Christoph Hellwig
2023-06-08 11:02 ` [PATCH 17/30] fs: remove sb->s_mode Christoph Hellwig
2023-06-08 11:02 ` [PATCH 18/30] scsi: replace the fmode_t argument to scsi_cmd_allowed with a simple bool Christoph Hellwig
2023-06-08 11:02 ` [PATCH 19/30] scsi: replace the fmode_t argument to scsi_ioctl " Christoph Hellwig
2023-06-08 11:02 ` [PATCH 20/30] scsi: replace the fmode_t argument to ->sg_io_fn " Christoph Hellwig
2023-06-08 11:02 ` [PATCH 21/30] nvme: replace the fmode_t argument to the nvme ioctl handlers " Christoph Hellwig
[not found] ` <20230608110258.189493-22-hch-jcswGhMUV9g@public.gmane.org>
2023-06-09 15:49 ` Keith Busch
2023-06-08 11:02 ` [PATCH 22/30] mtd: block: use a simple bool to track open for write Christoph Hellwig
2023-06-08 11:02 ` [PATCH 23/30] rnbd-srv: replace sess->open_flags with a "bool readonly" Christoph Hellwig
2023-06-08 11:02 ` [PATCH 24/30] ubd: remove commented out code in ubd_open Christoph Hellwig
2023-06-08 11:02 ` [PATCH 25/30] block: move a few internal definitions out of blkdev.h Christoph Hellwig
2023-06-08 11:02 ` [PATCH 26/30] block: remove unused fmode_t arguments from ioctl handlers Christoph Hellwig
2023-06-08 11:02 ` [PATCH 27/30] block: replace fmode_t with a block-specific type for block open flags Christoph Hellwig
2023-06-08 11:45 ` Christian Brauner
2023-06-09 6:40 ` [dm-devel] " Hannes Reinecke
2023-06-08 11:02 ` [PATCH 28/30] block: always use I_BDEV on file->f_mapping->host to find the bdev Christoph Hellwig
2023-06-08 11:02 ` [PATCH 29/30] block: store the holder in file->private_data Christoph Hellwig
2023-06-09 6:41 ` Hannes Reinecke
2023-06-08 11:02 ` [PATCH 30/30] fs: remove the now unused FMODE_* flags Christoph Hellwig
2023-06-12 14:11 ` decouple block open flags from fmode_t v2 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=20230608110258.189493-8-hch@lst.de \
--to=hch@lst.de \
--cc=axboe@kernel.dk \
--cc=brauner@kernel.org \
--cc=clm@fb.com \
--cc=colyli@suse.de \
--cc=dm-devel@redhat.com \
--cc=dsterba@suse.com \
--cc=haris.iqbal@ionos.com \
--cc=jinpu.wang@ionos.com \
--cc=josef@toxicpanda.com \
--cc=linux-bcache@vger.kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=linux-nvme@lists.infradead.org \
--cc=linux-scsi@vger.kernel.org \
--cc=linux-um@lists.infradead.org \
--cc=martin.petersen@oracle.com \
--cc=miquel.raynal@bootlin.com \
--cc=pavel@ucw.cz \
--cc=phil@philpotter.co.uk \
--cc=rafael@kernel.org \
--cc=richard@nod.at \
--cc=vigneshr@ti.com \
--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 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).