diff options
author | Tejun Heo <tj@kernel.org> | 2011-07-01 10:17:47 -0400 |
---|---|---|
committer | Jens Axboe <jaxboe@fusionio.com> | 2011-07-01 10:17:47 -0400 |
commit | 85ef06d1d252f6a2e73b678591ab71caad4667bb (patch) | |
tree | dc5cbc4f2e54f5b5b3f8653a595799e5fe0f2f18 /fs/block_dev.c | |
parent | 04bf7869ca0fd12009aee301cac2264a36df4d98 (diff) |
block: flush MEDIA_CHANGE from drivers on close(2)
Currently, only open(2) is defined as the 'clearing' point. It has
two roles - first, it's an acknowledgement from userland indicating
that the event has been received and kernel can clear pending states
and proceed to generate more events. Secondly, it's passed on to
device drivers as a hint indicating that a synchronization point has
been reached and it might want to take a deeper look at the device.
The latter currently is only used by sr which uses two different
mechanisms - GET_EVENT_MEDIA_STATUS_NOTIFICATION and TEST_UNIT_READY
to discover events, where the former is lighter weight and safe to be
used repeatedly but may not provide full coverage. Among other
things, GET_EVENT can't detect media removal while TUR can.
This patch makes close(2) - blkdev_put() - indicate clearing hint for
MEDIA_CHANGE to drivers. disk_check_events() is renamed to
disk_flush_events() and updated to take @mask for events to flush
which is or'd to ev->clearing and will be passed to the driver on the
next ->check_events() invocation.
This change makes sr generate MEDIA_CHANGE when media is ejected from
userland - e.g. with eject(1).
Note: Given the current usage, it seems @clearing hint is needlessly
complex. disk_clear_events() can simply clear all events and the hint
can be boolean @flush.
Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Kay Sievers <kay.sievers@vrfy.org>
Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
Diffstat (limited to 'fs/block_dev.c')
-rw-r--r-- | fs/block_dev.c | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/fs/block_dev.c b/fs/block_dev.c index 610e8e0b04b8..6ff7f070016f 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c | |||
@@ -1447,6 +1447,8 @@ static int __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part) | |||
1447 | 1447 | ||
1448 | int blkdev_put(struct block_device *bdev, fmode_t mode) | 1448 | int blkdev_put(struct block_device *bdev, fmode_t mode) |
1449 | { | 1449 | { |
1450 | mutex_lock(&bdev->bd_mutex); | ||
1451 | |||
1450 | if (mode & FMODE_EXCL) { | 1452 | if (mode & FMODE_EXCL) { |
1451 | bool bdev_free; | 1453 | bool bdev_free; |
1452 | 1454 | ||
@@ -1455,7 +1457,6 @@ int blkdev_put(struct block_device *bdev, fmode_t mode) | |||
1455 | * are protected with bdev_lock. bd_mutex is to | 1457 | * are protected with bdev_lock. bd_mutex is to |
1456 | * synchronize disk_holder unlinking. | 1458 | * synchronize disk_holder unlinking. |
1457 | */ | 1459 | */ |
1458 | mutex_lock(&bdev->bd_mutex); | ||
1459 | spin_lock(&bdev_lock); | 1460 | spin_lock(&bdev_lock); |
1460 | 1461 | ||
1461 | WARN_ON_ONCE(--bdev->bd_holders < 0); | 1462 | WARN_ON_ONCE(--bdev->bd_holders < 0); |
@@ -1473,17 +1474,21 @@ int blkdev_put(struct block_device *bdev, fmode_t mode) | |||
1473 | * If this was the last claim, remove holder link and | 1474 | * If this was the last claim, remove holder link and |
1474 | * unblock evpoll if it was a write holder. | 1475 | * unblock evpoll if it was a write holder. |
1475 | */ | 1476 | */ |
1476 | if (bdev_free) { | 1477 | if (bdev_free && bdev->bd_write_holder) { |
1477 | if (bdev->bd_write_holder) { | 1478 | disk_unblock_events(bdev->bd_disk); |
1478 | disk_unblock_events(bdev->bd_disk); | 1479 | bdev->bd_write_holder = false; |
1479 | disk_check_events(bdev->bd_disk); | ||
1480 | bdev->bd_write_holder = false; | ||
1481 | } | ||
1482 | } | 1480 | } |
1483 | |||
1484 | mutex_unlock(&bdev->bd_mutex); | ||
1485 | } | 1481 | } |
1486 | 1482 | ||
1483 | /* | ||
1484 | * Trigger event checking and tell drivers to flush MEDIA_CHANGE | ||
1485 | * event. This is to ensure detection of media removal commanded | ||
1486 | * from userland - e.g. eject(1). | ||
1487 | */ | ||
1488 | disk_flush_events(bdev->bd_disk, DISK_EVENT_MEDIA_CHANGE); | ||
1489 | |||
1490 | mutex_unlock(&bdev->bd_mutex); | ||
1491 | |||
1487 | return __blkdev_put(bdev, mode, 0); | 1492 | return __blkdev_put(bdev, mode, 0); |
1488 | } | 1493 | } |
1489 | EXPORT_SYMBOL(blkdev_put); | 1494 | EXPORT_SYMBOL(blkdev_put); |