History

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.

Christoph Hellwig committed 6 years ago

Commit a564e231 parent 568f2704 files · +10 −23Browse files

Unified · Split

4 files
  1. Documentation/filesystems/locking.rst +1 −3
  2. block/genhd.c +1 −7
  3. drivers/md/md.c +8 −11
  4. include/linux/blkdev.h +0 −2
Documentation/filesystems/locking.rst+1−3
@@ -467,7 +467,6 @@ prototypes:: · 466 unmodified lines
467 int (*compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);467 int (*compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
468 int (*direct_access) (struct block_device *, sector_t, void **,468 int (*direct_access) (struct block_device *, sector_t, void **,
469 unsigned long *);469 unsigned long *);
470 int (*media_changed) (struct gendisk *);
471 void (*unlock_native_capacity) (struct gendisk *);470 void (*unlock_native_capacity) (struct gendisk *);
472 int (*revalidate_disk) (struct gendisk *);471 int (*revalidate_disk) (struct gendisk *);
473 int (*getgeo)(struct block_device *, struct hd_geometry *);472 int (*getgeo)(struct block_device *, struct hd_geometry *);
@@ -483,14 +482,13 @@ release: yes · 9 unmodified lines
483ioctl: no482ioctl: no
484compat_ioctl: no483compat_ioctl: no
485direct_access: no484direct_access: no
486media_changed: no
487unlock_native_capacity: no485unlock_native_capacity: no
488revalidate_disk: no486revalidate_disk: no
489getgeo: no487getgeo: no
490swap_slot_free_notify: no (see below)488swap_slot_free_notify: no (see below)
491======================= ===================489======================= ===================
492 490
493media_changed, unlock_native_capacity and revalidate_disk are called only from491unlock_native_capacity and revalidate_disk are called only from
494check_disk_change().492check_disk_change().
495 493
496swap_slot_free_notify is called with swap_lock and sometimes the page lock494swap_slot_free_notify is called with swap_lock and sometimes the page lock
block/genhd.c+1−7
@@ -2056,18 +2056,12 @@ void disk_flush_events(struct gendisk *disk, unsigned int mask) · 2055 unmodified lines
2056 */2056 */
2057unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask)2057unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask)
2058{2058{
2059 const struct block_device_operations *bdops = disk->fops;
2060 struct disk_events *ev = disk->ev;2059 struct disk_events *ev = disk->ev;
2061 unsigned int pending;2060 unsigned int pending;
2062 unsigned int clearing = mask;2061 unsigned int clearing = mask;
2063 2062
2064 if (!ev) {2063 if (!ev)
2065 /* for drivers still using the old ->media_changed method */
2066 if ((mask & DISK_EVENT_MEDIA_CHANGE) &&
2067 bdops->media_changed && bdops->media_changed(disk))
2068 return DISK_EVENT_MEDIA_CHANGE;
2069 return 0;2064 return 0;
2070 }
2071 2065
2072 disk_block_events(disk);2066 disk_block_events(disk);
2073 2067
drivers/md/md.c+8−11
@@ -5670,6 +5670,7 @@ static int md_alloc(dev_t dev, char *name) · 5669 unmodified lines
5670 * remove it now.5670 * remove it now.
5671 */5671 */
5672 disk->flags |= GENHD_FL_EXT_DEVT;5672 disk->flags |= GENHD_FL_EXT_DEVT;
5673 disk->events |= DISK_EVENT_MEDIA_CHANGE;
5673 mddev->gendisk = disk;5674 mddev->gendisk = disk;
5674 /* As soon as we call add_disk(), another thread could get5675 /* As soon as we call add_disk(), another thread could get
5675 * through to md_open, so make sure it doesn't get too far5676 * 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) · 2130 unmodified lines
7806 mddev_put(mddev);7807 mddev_put(mddev);
7807}7808}
7808 7809
7809static int md_media_changed(struct gendisk *disk)7810static unsigned int md_check_events(struct gendisk *disk, unsigned int clearing)
7810{
7811 struct mddev *mddev = disk->private_data;
7812
7813 return mddev->changed;
7814}
7815
7816static int md_revalidate(struct gendisk *disk)
7817{7811{
7818 struct mddev *mddev = disk->private_data;7812 struct mddev *mddev = disk->private_data;
7813 unsigned int ret = 0;
7819 7814
7815 if (mddev->changed)
7816 ret = DISK_EVENT_MEDIA_CHANGE;
7820 mddev->changed = 0;7817 mddev->changed = 0;
7821 return 0;7818 return ret;
7822}7819}
7820
7823static const struct block_device_operations md_fops =7821static const struct block_device_operations md_fops =
7824{7822{
7825 .owner = THIS_MODULE,7823 .owner = THIS_MODULE,
@@ -7831,8 +7829,7 @@ static const struct block_device_operations md_fops = · 5 unmodified lines
7831 .compat_ioctl = md_compat_ioctl,7829 .compat_ioctl = md_compat_ioctl,
7832#endif7830#endif
7833 .getgeo = md_getgeo,7831 .getgeo = md_getgeo,
7834 .media_changed = md_media_changed,7832 .check_events = md_check_events,
7835 .revalidate_disk= md_revalidate,
7836};7833};
7837 7834
7838static int md_thread(void *arg)7835static int md_thread(void *arg)
include/linux/blkdev.h+0−2
@@ -1781,8 +1781,6 @@ struct block_device_operations { · 1780 unmodified lines
1781 int (*compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);1781 int (*compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
1782 unsigned int (*check_events) (struct gendisk *disk,1782 unsigned int (*check_events) (struct gendisk *disk,
1783 unsigned int clearing);1783 unsigned int clearing);
1784 /* ->media_changed() is DEPRECATED, use ->check_events() instead */
1785 int (*media_changed) (struct gendisk *);
1786 void (*unlock_native_capacity) (struct gendisk *);1784 void (*unlock_native_capacity) (struct gendisk *);
1787 int (*revalidate_disk) (struct gendisk *);1785 int (*revalidate_disk) (struct gendisk *);
1788 int (*getgeo)(struct block_device *, struct hd_geometry *);1786 int (*getgeo)(struct block_device *, struct hd_geometry *);