Skip to contentSkip to conversation

block: Invalidate the cache for a parent block-device if blkdev_issue_flush() was called for a partition

PATCH Superseded Niels de Vos 2 participants 2 messages Jan 19, 2012 Block layer

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block: Invalidate the cache for a parent block-device if blkdev_issue_flush() was called for a partition

Executing a BLKFLSBUF-ioctl on a partition flushes the caches for that partition but reading data through the parent device will still return the old cached data.

The cache for the block-device is not synced if the block-device is kept open (due to a mounted partition, for example). Only when all users for the disk have exited, the cache for the disk is made consistent again.

Calling invalidate_bdev() on the parent block-device in case blkdev_issue_flush() was called for a partition fixes this.

The problem can be worked around by forcing the caches to be flushed with either

	# blockdev --flushbufs ${dev_disk}
or
	# echo 3 > /proc/sys/vm/drop_caches
CC Bryn M. Reeves <[email protected]>
---
 block/blk-flush.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
block/blk-flush.c +3 -0
index 720ad60..e876f8e 100644
@@ -448,6 +448,9 @@ int blkdev_issue_flush(struct block_device *bdev, gfp_t gfp_mask,
 
 	if (!bio_flagged(bio, BIO_UPTODATE))
 		ret = -EIO;
+	else if (bdev != bdev->bd_contains)
+		/* invalidate parent block_device */
+		invalidate_bdev(bdev->bd_contains);
 
 	bio_put(bio);
 	return ret;
Signature · 1 line
1.7.6.5
Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Niels de Vos

Executing a BLKFLSBUF-ioctl on a partition flushes the caches for that partition but reading data through the parent device will still return the old cached data.

The cache for the block-device is not synced if the block-device is kept open (due to a mounted partition, for example). Only when all users for the disk have exited, the cache for the disk is made consistent again.

Calling invalidate_bdev() on the parent block-device in case blkdev_issue_flush() was called for a partition fixes this.

Quoted 8 lines

The problem can be worked around by forcing the caches to be flushed with either

	# blockdev --flushbufs ${dev_disk}
or
	# echo 3 > /proc/sys/vm/drop_caches
CC Bryn M. Reeves <[email protected]>

Cheers,
Bryn.