linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] block: Invalidate the cache for a parent block-device if blkdev_issue_flush() was called for a partition
@ 2012-01-19  8:50 Niels de Vos
  2012-01-19 15:06 ` Bryn M. Reeves
  0 siblings, 1 reply; 2+ messages in thread
From: Niels de Vos @ 2012-01-19  8:50 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-kernel, Niels de Vos, Bryn M. Reeves

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 <bmr@redhat.com>
Signed-off-by: Niels de Vos <ndevos@redhat.com>
---
 block/blk-flush.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/block/blk-flush.c b/block/blk-flush.c
index 720ad60..e876f8e 100644
--- a/block/blk-flush.c
+++ b/block/blk-flush.c
@@ -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;
-- 
1.7.6.5


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] block: Invalidate the cache for a parent block-device if blkdev_issue_flush() was called for a partition
  2012-01-19  8:50 [PATCH] block: Invalidate the cache for a parent block-device if blkdev_issue_flush() was called for a partition Niels de Vos
@ 2012-01-19 15:06 ` Bryn M. Reeves
  0 siblings, 0 replies; 2+ messages in thread
From: Bryn M. Reeves @ 2012-01-19 15:06 UTC (permalink / raw)
  To: Niels de Vos; +Cc: Jens Axboe, linux-kernel

On 01/19/2012 08:50 AM, Niels de Vos wrote:
> 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 <bmr@redhat.com>
> Signed-off-by: Niels de Vos <ndevos@redhat.com>

Acked-by: Bryn M. Reeves <bmr@redhat.com>

Cheers,
Bryn.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-01-19 15:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-19  8:50 [PATCH] block: Invalidate the cache for a parent block-device if blkdev_issue_flush() was called for a partition Niels de Vos
2012-01-19 15:06 ` Bryn M. Reeves

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).