Re: [PATCH v2] fs: Invalidate the cache for a parent block-device if fsync() is called for a partition

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 23 Jan 2012, Niels de Vos wrote:

> Executing an fsync() on a file-descriptor of a partition flushes the
> caches for that partition by calling blkdev_issue_flush(). However, it
> seems that 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_fsync() 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@xxxxxxxxxx>
> CC: Mikulas Patocka <mpatocka@xxxxxxxxxx>
> Signed-off-by: Niels de Vos <ndevos@xxxxxxxxxx>
> 

Acked-by: Mikulas Patocka <mpatocka@xxxxxxxxxx>

> ---
> v2:
> - Do not call invalidate_bdev() from blkdev_issue_flush() and prevent
>   performance degration with journalled filesystems.
> 
>   Suggested was to call invalidate_bdev() in fsync_bdev(), but this is
>   not in the call-path of mkfs.ext3 and similar tools. Hence the issue
>   persists.
> 
> - Correct phrasing a little, changing ioctl-BLKFLSBUF is not required.
> 
> - This issue also occurs when doing an ioctl-BLKFLSBUF on a partition.
>   Reading the whole disk will still return cached data. If this is an
>   issue, it will need a seperate patch.
> ---
>  fs/block_dev.c |    4 ++++
>  1 files changed, 4 insertions(+), 0 deletions(-)
> 
> diff --git a/fs/block_dev.c b/fs/block_dev.c
> index 0e575d1..433c4de 100644
> --- a/fs/block_dev.c
> +++ b/fs/block_dev.c
> @@ -424,6 +424,10 @@ int blkdev_fsync(struct file *filp, loff_t start, loff_t end, int datasync)
>  	if (error == -EOPNOTSUPP)
>  		error = 0;
>  
> +	/* invalidate parent block_device */
> +	if (!error && bdev != bdev->bd_contains)
> +		invalidate_bdev(bdev->bd_contains);
> +
>  	return error;
>  }
>  EXPORT_SYMBOL(blkdev_fsync);
> -- 
> 1.7.6.5
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [Samba]     [Device Mapper]     [CEPH Development]
  Powered by Linux