Skip to content

Commit a564e23

Browse files
Christoph Hellwigaxboe
authored andcommitted
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. Signed-off-by: Christoph Hellwig <hch@lst.de> [axboe: remove unused 'bdops' variable in disk_clear_events()] Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 568f270 commit a564e23

4 files changed

Lines changed: 10 additions & 23 deletions

File tree

‎Documentation/filesystems/locking.rst‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,6 @@ prototypes::
467467
int (*compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
468468
int (*direct_access) (struct block_device *, sector_t, void **,
469469
unsigned long *);
470-
int (*media_changed) (struct gendisk *);
471470
void (*unlock_native_capacity) (struct gendisk *);
472471
int (*revalidate_disk) (struct gendisk *);
473472
int (*getgeo)(struct block_device *, struct hd_geometry *);
@@ -483,14 +482,13 @@ release: yes
483482
ioctl: no
484483
compat_ioctl: no
485484
direct_access: no
486-
media_changed: no
487485
unlock_native_capacity: no
488486
revalidate_disk: no
489487
getgeo: no
490488
swap_slot_free_notify: no (see below)
491489
======================= ===================
492490

493-
media_changed, unlock_native_capacity and revalidate_disk are called only from
491+
unlock_native_capacity and revalidate_disk are called only from
494492
check_disk_change().
495493

496494
swap_slot_free_notify is called with swap_lock and sometimes the page lock

‎block/genhd.c‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2056,18 +2056,12 @@ void disk_flush_events(struct gendisk *disk, unsigned int mask)
20562056
*/
20572057
unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask)
20582058
{
2059-
const struct block_device_operations *bdops = disk->fops;
20602059
struct disk_events *ev = disk->ev;
20612060
unsigned int pending;
20622061
unsigned int clearing = mask;
20632062

2064-
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;
2063+
if (!ev)
20692064
return 0;
2070-
}
20712065

20722066
disk_block_events(disk);
20732067

‎drivers/md/md.c‎

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5670,6 +5670,7 @@ static int md_alloc(dev_t dev, char *name)
56705670
* remove it now.
56715671
*/
56725672
disk->flags |= GENHD_FL_EXT_DEVT;
5673+
disk->events |= DISK_EVENT_MEDIA_CHANGE;
56735674
mddev->gendisk = disk;
56745675
/* As soon as we call add_disk(), another thread could get
56755676
* 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)
78067807
mddev_put(mddev);
78077808
}
78087809

7809-
static int md_media_changed(struct gendisk *disk)
7810-
{
7811-
struct mddev *mddev = disk->private_data;
7812-
7813-
return mddev->changed;
7814-
}
7815-
7816-
static int md_revalidate(struct gendisk *disk)
7810+
static unsigned int md_check_events(struct gendisk *disk, unsigned int clearing)
78177811
{
78187812
struct mddev *mddev = disk->private_data;
7813+
unsigned int ret = 0;
78197814

7815+
if (mddev->changed)
7816+
ret = DISK_EVENT_MEDIA_CHANGE;
78207817
mddev->changed = 0;
7821-
return 0;
7818+
return ret;
78227819
}
7820+
78237821
static const struct block_device_operations md_fops =
78247822
{
78257823
.owner = THIS_MODULE,
@@ -7831,8 +7829,7 @@ static const struct block_device_operations md_fops =
78317829
.compat_ioctl = md_compat_ioctl,
78327830
#endif
78337831
.getgeo = md_getgeo,
7834-
.media_changed = md_media_changed,
7835-
.revalidate_disk= md_revalidate,
7832+
.check_events = md_check_events,
78367833
};
78377834

78387835
static int md_thread(void *arg)

‎include/linux/blkdev.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,8 +1781,6 @@ struct block_device_operations {
17811781
int (*compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
17821782
unsigned int (*check_events) (struct gendisk *disk,
17831783
unsigned int clearing);
1784-
/* ->media_changed() is DEPRECATED, use ->check_events() instead */
1785-
int (*media_changed) (struct gendisk *);
17861784
void (*unlock_native_capacity) (struct gendisk *);
17871785
int (*revalidate_disk) (struct gendisk *);
17881786
int (*getgeo)(struct block_device *, struct hd_geometry *);

0 commit comments

Comments
 (0)