Skip to contentSkip to conversation

remove leftovers of the old ->media_changed method

PATCH In review Christoph Hellwig 5 participants 15 messages Jul 8, 2020 – Jul 10, 2020

Subsystems (9)
lore
Share & tools
lore
#0 lore raw

Hi Jens,

this series converts md as the last user of the ->media_changed method over to the modern replacement, and then cleans up a few lose ends in the area.

Diffstat:

 Documentation/cdrom/cdrom-standard.rst |   18 +-----------------
 Documentation/filesystems/locking.rst  |    4 +---
 arch/xtensa/platforms/iss/simdisk.c    |    2 --
 block/genhd.c                          |    7 +------
 drivers/cdrom/cdrom.c                  |   28 +++++-----------------------
 drivers/md/md.c                        |   19 ++++++++-----------
 drivers/mmc/core/block.c               |    3 ---
 fs/block_dev.c                         |   30 +++++++-----------------------
 fs/isofs/inode.c                       |    3 ---
 include/linux/blkdev.h                 |    2 --
 include/linux/cdrom.h                  |    2 --
 11 files changed, 23 insertions(+), 95 deletions(-)
#1 lore raw

PATCH 1/6 md: switch to ->check_events for media change notifications

md is the last driver using the legacy media_changed method. Switch it over to (not so) new ->clear_events approach, which also removes the need for the ->revalidate_disk method.

---
 Documentation/filesystems/locking.rst |  4 +---
 block/genhd.c                         |  7 +------
 drivers/md/md.c                       | 19 ++++++++-----------
 include/linux/blkdev.h                |  2 --
 4 files changed, 10 insertions(+), 22 deletions(-)
Documentation/filesystems/locking.rst +1 -3
index 318605de83f33c..17bea12538c32d 100644
@@ -467,7 +467,6 @@ prototypes::
 	int (*compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
 	int (*direct_access) (struct block_device *, sector_t, void **,
 				unsigned long *);
-	int (*media_changed) (struct gendisk *);
 	void (*unlock_native_capacity) (struct gendisk *);
 	int (*revalidate_disk) (struct gendisk *);
 	int (*getgeo)(struct block_device *, struct hd_geometry *);
@@ -483,14 +482,13 @@ release:		yes
 ioctl:			no
 compat_ioctl:		no
 direct_access:		no
-media_changed:		no
 unlock_native_capacity:	no
 revalidate_disk:	no
 getgeo:			no
 swap_slot_free_notify:	no	(see below)
 ======================= ===================
 
-media_changed, unlock_native_capacity and revalidate_disk are called only from
+unlock_native_capacity and revalidate_disk are called only from
 check_disk_change().
 
 swap_slot_free_notify is called with swap_lock and sometimes the page lock
block/genhd.c +1 -6
index 60ae4e1b4d3877..1070da9d4d9a77 100644
@@ -2061,13 +2061,8 @@ unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask)
 	unsigned int pending;
 	unsigned int clearing = mask;
 
-	if (!ev) {
-		/* for drivers still using the old ->media_changed method */
-		if ((mask & DISK_EVENT_MEDIA_CHANGE) &&
-		    bdops->media_changed && bdops->media_changed(disk))
-			return DISK_EVENT_MEDIA_CHANGE;
+	if (!ev)
 		return 0;
-	}
 
 	disk_block_events(disk);
 
drivers/md/md.c +8 -11
index 8bb69c61afe086..77dfe4765c3111 100644
@@ -5670,6 +5670,7 @@ static int md_alloc(dev_t dev, char *name)
 	 * remove it now.
 	 */
 	disk->flags |= GENHD_FL_EXT_DEVT;
+	disk->events |= DISK_EVENT_MEDIA_CHANGE;
 	mddev->gendisk = disk;
 	/* As soon as we call add_disk(), another thread could get
 	 * through to md_open, so make sure it doesn't get too far
@@ -7806,20 +7807,17 @@ static void md_release(struct gendisk *disk, fmode_t mode)
 	mddev_put(mddev);
 }
 
-static int md_media_changed(struct gendisk *disk)
-{
-	struct mddev *mddev = disk->private_data;
-
-	return mddev->changed;
-}
-
-static int md_revalidate(struct gendisk *disk)
+static unsigned int md_check_events(struct gendisk *disk, unsigned int clearing)
 {
 	struct mddev *mddev = disk->private_data;
+	unsigned int ret = 0;
 
+	if (mddev->changed)
+		ret = DISK_EVENT_MEDIA_CHANGE;
 	mddev->changed = 0;
-	return 0;
+	return ret;
 }
+
 static const struct block_device_operations md_fops =
 {
 	.owner		= THIS_MODULE,
@@ -7831,8 +7829,7 @@ static const struct block_device_operations md_fops =
 	.compat_ioctl	= md_compat_ioctl,
 #endif
 	.getgeo		= md_getgeo,
-	.media_changed  = md_media_changed,
-	.revalidate_disk= md_revalidate,
+	.check_events	= md_check_events,
 };
 
 static int md_thread(void *arg)
include/linux/blkdev.h +0 -2
index 408eb66a82fdc7..71173a1ffa8b87 100644
@@ -1781,8 +1781,6 @@ struct block_device_operations {
 	int (*compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
 	unsigned int (*check_events) (struct gendisk *disk,
 				      unsigned int clearing);
-	/* ->media_changed() is DEPRECATED, use ->check_events() instead */
-	int (*media_changed) (struct gendisk *);
 	void (*unlock_native_capacity) (struct gendisk *);
 	int (*revalidate_disk) (struct gendisk *);
 	int (*getgeo)(struct block_device *, struct hd_geometry *);
Signature · 1 line
2.26.2
#2 lore raw

Re: [PATCH 1/6] md: switch to ->check_events for media change notifications

drivers/md/md.c static void md_release(struct gendisk *disk, fmode_t mode) · line 7814

Quoted 6 lines · Christoph Hellwig
drivers/md/md.c +0 -6
-static int md_media_changed(struct gendisk *disk)
-{
-	struct mddev *mddev = disk->private_data;
-
-	return mddev->changed;
-}

Maybe we can remove "changed" from struct mddev since no one reads it after the change.

Thanks,
Guoqing

#3 lore raw

Re: [PATCH 1/6] md: switch to ->check_events for media change notifications

Quoted 10 lines · Guoqing Jiang

drivers/md/md.c static void md_release(struct gendisk *disk, fmode_t mode) · line 7814

Quoted 6 lines · Christoph Hellwig
drivers/md/md.c +0 -6
-static int md_media_changed(struct gendisk *disk)
-{
-	struct mddev *mddev = disk->private_data;
-
-	return mddev->changed;
-}

Maybe we can remove "changed" from struct mddev since no one reads it after the change.

The new md_check_events method reads it.

maintainer
#4 lore raw

Re: [PATCH 1/6] md: switch to ->check_events for media change notifications

In reply to Guoqing Jiang
Quoted 10 lines · Guoqing Jiang

drivers/md/md.c static void md_release(struct gendisk *disk, fmode_t mode) · line 7814

Quoted 6 lines · Christoph Hellwig
drivers/md/md.c +0 -6
-static int md_media_changed(struct gendisk *disk)
-{
-	struct mddev *mddev = disk->private_data;
-
-	return mddev->changed;
-}

Maybe we can remove "changed" from struct mddev since no one reads it after the change.

You missed this hunk:

+static unsigned int md_check_events(struct gendisk *disk, unsigned int clearing)

 {
        struct mddev *mddev = disk->private_data;

+ unsigned int ret = 0;

+ if (mddev->changed)

+               ret = DISK_EVENT_MEDIA_CHANGE;
        mddev->changed = 0;

- return 0;
+ return ret;
}

#5 lore raw

Re: [PATCH 1/6] md: switch to ->check_events for media change notifications

Quoted 14 lines · Matthew Wilcox
Quoted 9 lines · Guoqing Jiang

drivers/md/md.c static void md_release(struct gendisk *disk, fmode_t mode) · line 7814

Quoted 6 lines · Christoph Hellwig
drivers/md/md.c +0 -6
-static int md_media_changed(struct gendisk *disk)
-{
-	struct mddev *mddev = disk->private_data;
-
-	return mddev->changed;
-}

Maybe we can remove "changed" from struct mddev since no one reads it after the change.

You missed this hunk:

drivers/md/md.c +1 -0
+static unsigned int md_check_events(struct gendisk *disk, unsigned int clearing)

drivers/md/md.c static void md_release(struct gendisk *disk, fmode_t mode) · line 7819

Quoted 10 lines
drivers/md/md.c +4 -1
  {
         struct mddev *mddev = disk->private_data;
+	unsigned int ret = 0;
 
+	if (mddev->changed)
+               ret = DISK_EVENT_MEDIA_CHANGE;
         mddev->changed = 0;
-	return 0;
+	return ret;
  }

Yes, sorry for the noise.

Thanks,
Guoqing

#6 lore raw

PATCH 2/6 cdrom: remove the unused cdrom_media_changed function

In reply to Christoph Hellwig

As well as the ->media_changed method. All these are left over from before the drivers were switched over to the check_events scheme.

---
 Documentation/cdrom/cdrom-standard.rst | 18 +----------------
 drivers/cdrom/cdrom.c                  | 28 +++++---------------------
 include/linux/cdrom.h                  |  2 --
 3 files changed, 6 insertions(+), 42 deletions(-)
Documentation/cdrom/cdrom-standard.rst +1 -17
index dde4f7f7fdbf1c..2de90581059033 100644
@@ -157,7 +157,6 @@ with the kernel as a block device by registering the following general
 		cdrom_release,		/∗ release ∗/
 		NULL,			/∗ fsync ∗/
 		NULL,			/∗ fasync ∗/
-		cdrom_media_changed,	/∗ media change ∗/
 		NULL			/∗ revalidate ∗/
 	};
 
@@ -366,19 +365,6 @@ which may or may not be in the drive). If the drive is not a changer,
 	CDS_DRIVE_NOT_READY	/* something is wrong, tray is moving? */
 	CDS_DISC_OK		/* a disc is loaded and everything is fine */
 
-::
-
-	int media_changed(struct cdrom_device_info *cdi, int disc_nr)
-
-This function is very similar to the original function in $struct
-file_operations*. It returns 1 if the medium of the device *cdi->dev*
-has changed since the last call, and 0 otherwise. The parameter
-*disc_nr* identifies a specific slot in a juke-box, it should be
-ignored for single-disc drives. Note that by `re-routing` this
-function through *cdrom_media_changed()*, we can implement separate
-queues for the VFS and a new *ioctl()* function that can report device
-changes to software (e. g., an auto-mounting daemon).
-
 ::
 
 	int tray_move(struct cdrom_device_info *cdi, int position)
@@ -917,9 +903,7 @@ commands can be identified by the underscores in their names.
 	maximum number of discs in the juke-box found in the *cdrom_dops*.
 `CDROM_MEDIA_CHANGED`
 	Returns 1 if a disc has been changed since the last call.
-	Note that calls to *cdrom_media_changed* by the VFS are treated
-	by an independent queue, so both mechanisms will detect a
-	media change once. For juke-boxes, an extra argument *arg*
+	For juke-boxes, an extra argument *arg*
 	specifies the slot for which the information is given. The special
 	value *CDSL_CURRENT* requests that information about the currently
 	selected slot be returned.
drivers/cdrom/cdrom.c +5 -23
index d82b3b7658bddc..0c271b9e3c5b79 100644
@@ -605,7 +605,7 @@ int register_cdrom(struct gendisk *disk, struct cdrom_device_info *cdi)
 	disk->cdi = cdi;
 
 	ENSURE(cdo, drive_status, CDC_DRIVE_STATUS);
-	if (cdo->check_events == NULL && cdo->media_changed == NULL)
+	if (cdo->check_events == NULL)
 		WARN_ON_ONCE(cdo->capability & (CDC_MEDIA_CHANGED | CDC_SELECT_DISC));
 	ENSURE(cdo, tray_move, CDC_CLOSE_TRAY | CDC_OPEN_TRAY);
 	ENSURE(cdo, lock_door, CDC_LOCK);
@@ -1419,8 +1419,6 @@ static int cdrom_select_disc(struct cdrom_device_info *cdi, int slot)
 
 	if (cdi->ops->check_events)
 		cdi->ops->check_events(cdi, 0, slot);
-	else
-		cdi->ops->media_changed(cdi, slot);
 
 	if (slot == CDSL_NONE) {
 		/* set media changed bits, on both queues */
@@ -1517,13 +1515,10 @@ int media_changed(struct cdrom_device_info *cdi, int queue)
 		return ret;
 
 	/* changed since last call? */
-	if (cdi->ops->check_events) {
-		BUG_ON(!queue);	/* shouldn't be called from VFS path */
-		cdrom_update_events(cdi, DISK_EVENT_MEDIA_CHANGE);
-		changed = cdi->ioctl_events & DISK_EVENT_MEDIA_CHANGE;
-		cdi->ioctl_events = 0;
-	} else
-		changed = cdi->ops->media_changed(cdi, CDSL_CURRENT);
+	BUG_ON(!queue);	/* shouldn't be called from VFS path */
+	cdrom_update_events(cdi, DISK_EVENT_MEDIA_CHANGE);
+	changed = cdi->ioctl_events & DISK_EVENT_MEDIA_CHANGE;
+	cdi->ioctl_events = 0;
 
 	if (changed) {
 		cdi->mc_flags = 0x3;    /* set bit on both queues */
@@ -1535,18 +1530,6 @@ int media_changed(struct cdrom_device_info *cdi, int queue)
 	return ret;
 }
 
-int cdrom_media_changed(struct cdrom_device_info *cdi)
-{
-	/* This talks to the VFS, which doesn't like errors - just 1 or 0.  
-	 * Returning "0" is always safe (media hasn't been changed). Do that 
-	 * if the low-level cdrom driver dosn't support media changed. */ 
-	if (cdi == NULL || cdi->ops->media_changed == NULL)
-		return 0;
-	if (!CDROM_CAN(CDC_MEDIA_CHANGED))
-		return 0;
-	return media_changed(cdi, 0);
-}
-
 /* Requests to the low-level drivers will /always/ be done in the
    following format convention:
 
@@ -3464,7 +3447,6 @@ EXPORT_SYMBOL(unregister_cdrom);
 EXPORT_SYMBOL(cdrom_open);
 EXPORT_SYMBOL(cdrom_release);
 EXPORT_SYMBOL(cdrom_ioctl);
-EXPORT_SYMBOL(cdrom_media_changed);
 EXPORT_SYMBOL(cdrom_number_of_slots);
 EXPORT_SYMBOL(cdrom_mode_select);
 EXPORT_SYMBOL(cdrom_mode_sense);
include/linux/cdrom.h +0 -2
index 8543fa59da7207..f48d0a31deaece 100644
@@ -73,7 +73,6 @@ struct cdrom_device_ops {
 	int (*drive_status) (struct cdrom_device_info *, int);
 	unsigned int (*check_events) (struct cdrom_device_info *cdi,
 				      unsigned int clearing, int slot);
-	int (*media_changed) (struct cdrom_device_info *, int);
 	int (*tray_move) (struct cdrom_device_info *, int);
 	int (*lock_door) (struct cdrom_device_info *, int);
 	int (*select_speed) (struct cdrom_device_info *, int);
@@ -107,7 +106,6 @@ extern int cdrom_ioctl(struct cdrom_device_info *cdi, struct block_device *bdev,
 		       fmode_t mode, unsigned int cmd, unsigned long arg);
 extern unsigned int cdrom_check_events(struct cdrom_device_info *cdi,
 				       unsigned int clearing);
-extern int cdrom_media_changed(struct cdrom_device_info *);
 
 extern int register_cdrom(struct gendisk *disk, struct cdrom_device_info *cdi);
 extern void unregister_cdrom(struct cdrom_device_info *cdi);
Signature · 1 line
2.26.2
#7 lore raw

PATCH 3/6 block: remove flush_disk

In reply to Christoph Hellwig

flush_disk has only two callers, so open code it there. That also helps clarifying the error message for the particular case, and allows to remove setting bd_invalidated in check_disk_size_change, which will be cleared again instantly.

---
 fs/block_dev.c | 30 +++++++-----------------------
 1 file changed, 7 insertions(+), 23 deletions(-)
fs/block_dev.c +7 -23
index 2d2fcb50e78eac..a36d5b6907ea4e 100644
@@ -1347,26 +1347,6 @@ void bd_unlink_disk_holder(struct block_device *bdev, struct gendisk *disk)
 EXPORT_SYMBOL_GPL(bd_unlink_disk_holder);
 #endif
 
-/**
- * flush_disk - invalidates all buffer-cache entries on a disk
- *
- * @bdev:      struct block device to be flushed
- * @kill_dirty: flag to guide handling of dirty inodes
- *
- * Invalidates all buffer-cache entries on a disk. It should be called
- * when a disk has been changed -- either by a media change or online
- * resize.
- */
-static void flush_disk(struct block_device *bdev, bool kill_dirty)
-{
-	if (__invalidate_device(bdev, kill_dirty)) {
-		printk(KERN_WARNING "VFS: busy inodes on changed media or "
-		       "resized disk %s\n",
-		       bdev->bd_disk ? bdev->bd_disk->disk_name : "");
-	}
-	bdev->bd_invalidated = 1;
-}
-
 /**
  * check_disk_size_change - checks for disk size change and adjusts bdev size.
  * @disk: struct gendisk to check
@@ -1391,8 +1371,9 @@ static void check_disk_size_change(struct gendisk *disk,
 			       disk->disk_name, bdev_size, disk_size);
 		}
 		i_size_write(bdev->bd_inode, disk_size);
-		if (bdev_size > disk_size)
-			flush_disk(bdev, false);
+		if (bdev_size > disk_size && __invalidate_device(bdev, false))
+			pr_warn("VFS: busy inodes on resized disk %s\n",
+				disk->disk_name);
 	}
 	bdev->bd_invalidated = 0;
 }
@@ -1451,7 +1432,10 @@ int check_disk_change(struct block_device *bdev)
 	if (!(events & DISK_EVENT_MEDIA_CHANGE))
 		return 0;
 
-	flush_disk(bdev, true);
+	if (__invalidate_device(bdev, true))
+		pr_warn("VFS: busy inodes on changed media %s\n",
+			disk->disk_name);
+	bdev->bd_invalidated = 1;
 	if (bdops->revalidate_disk)
 		bdops->revalidate_disk(bdev->bd_disk);
 	return 1;
Signature · 1 line
2.26.2
#8 lore raw

PATCH 4/6 isofs: remove a stale comment

In reply to Christoph Hellwig

check_disk_change isn't for consumers of the block layer, so remove the comment mentioning it.

---
 fs/isofs/inode.c | 3 ---
 1 file changed, 3 deletions(-)
fs/isofs/inode.c +0 -3
index d634561f871a56..78f5c96c76f31e 100644
@@ -612,9 +612,6 @@ static bool rootdir_empty(struct super_block *sb, unsigned long block)
 
 /*
  * Initialize the superblock and read the root inode.
- *
- * Note: a check_disk_change() has been done immediately prior
- * to this call, so we don't need to check again.
  */
 static int isofs_fill_super(struct super_block *s, void *data, int silent)
 {
Signature · 1 line
2.26.2
#9 lore raw

PATCH 5/6 xtensa/simdisk: remove the call to check_disk_change

In reply to Christoph Hellwig

The simdisk driver doesn't support event notifications, which means that check_disk_change is a no-op.

---
 arch/xtensa/platforms/iss/simdisk.c | 2 --
 1 file changed, 2 deletions(-)
arch/xtensa/platforms/iss/simdisk.c +0 -2
index 5107140dbb7edc..3447556d276d32 100644
@@ -127,8 +127,6 @@ static int simdisk_open(struct block_device *bdev, fmode_t mode)
 	struct simdisk *dev = bdev->bd_disk->private_data;
 
 	spin_lock(&dev->lock);
-	if (!dev->users)
-		check_disk_change(bdev);
 	++dev->users;
 	spin_unlock(&dev->lock);
 	return 0;
Signature · 1 line
2.26.2
#10 lore raw

PATCH 6/6 mmc: remove the call to check_disk_change

In reply to Christoph Hellwig

The mmc driver doesn't support event notifications, which means that check_disk_change is a no-op.

---
 drivers/mmc/core/block.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/mmc/core/block.c +0 -3
index 4791c82f8f7c78..fa313b63413547 100644
@@ -312,10 +312,7 @@ static int mmc_blk_open(struct block_device *bdev, fmode_t mode)
 
 	mutex_lock(&block_mutex);
 	if (md) {
-		if (md->usage == 2)
-			check_disk_change(bdev);
 		ret = 0;
-
 		if ((mode & FMODE_WRITE) && md->read_only) {
 			mmc_blk_put(md);
 			ret = -EROFS;
Signature · 1 line
2.26.2
#11 lore raw

Re: [PATCH 6/6] mmc: remove the call to check_disk_change

Quoted 5 lines · Christoph Hellwig

The mmc driver doesn't support event notifications, which means that check_disk_change is a no-op.

I can queue this via my mmc tree, but perhaps you have plans for some additional cleanups on top? In such a case, it may be better that this goes through Jens' tree?

Kind regards
Uffe

Quoted 22 lines
---
 drivers/mmc/core/block.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/mmc/core/block.c +0 -4
index 4791c82f8f7c78..fa313b63413547 100644
@@ -312,10 +312,7 @@ static int mmc_blk_open(struct block_device *bdev, fmode_t mode)
 
        mutex_lock(&block_mutex);
        if (md) {
-               if (md->usage == 2)
-                       check_disk_change(bdev);
                ret = 0;
-
                if ((mode & FMODE_WRITE) && md->read_only) {
                        mmc_blk_put(md);
                        ret = -EROFS;
--

2.26.2

#12 lore raw

Re: [PATCH 6/6] mmc: remove the call to check_disk_change

Quoted 10 lines · Ulf Hansson
Quoted 5 lines · Christoph Hellwig

The mmc driver doesn't support event notifications, which means that check_disk_change is a no-op.

I can queue this via my mmc tree, but perhaps you have plans for some additional cleanups on top? In such a case, it may be better that this goes through Jens' tree?

I have some vague plans. They might or might not hit this merge window, so if you are fine with Jens picking up the whole thing that would avoid any potential problems.

Acked-by on v1 6/6
#13 lore raw

Re: [PATCH 6/6] mmc: remove the call to check_disk_change

In reply to Christoph Hellwig
Quoted 5 lines · Christoph Hellwig

The mmc driver doesn't support event notifications, which means that check_disk_change is a no-op.

Feel free to add:

Kind regards
Uffe

Quoted 22 lines
---
 drivers/mmc/core/block.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/mmc/core/block.c +0 -4
index 4791c82f8f7c78..fa313b63413547 100644
@@ -312,10 +312,7 @@ static int mmc_blk_open(struct block_device *bdev, fmode_t mode)
 
        mutex_lock(&block_mutex);
        if (md) {
-               if (md->usage == 2)
-                       check_disk_change(bdev);
                ret = 0;
-
                if ((mode & FMODE_WRITE) && md->read_only) {
                        mmc_blk_put(md);
                        ret = -EROFS;
--

2.26.2

maintainer Applied
#14 lore raw
In reply to Christoph Hellwig
Quoted 5 lines · Christoph Hellwig

Hi Jens,

this series converts md as the last user of the ->media_changed method over to the modern replacement, and then cleans up a few lose ends in the area.

Applied, thanks.

Signature · 1 line
Jens Axboe