From b4c7c3009663ddcfbd6f3dbe611581dd3312ab1e Mon Sep 17 00:00:00 2001 From: Josh Boyer Date: Wed, 25 Jan 2012 17:08:55 -0500 Subject: [PATCH] Add patch to invalidate parent cache when fsync is called on a partition (rhbz 783211) --- ...block-device-if-fsync-called-on-part.patch | 106 ++++++++++++++++++ kernel.spec | 9 ++ 2 files changed, 115 insertions(+) create mode 100644 fs-Inval-cache-for-parent-block-device-if-fsync-called-on-part.patch diff --git a/fs-Inval-cache-for-parent-block-device-if-fsync-called-on-part.patch b/fs-Inval-cache-for-parent-block-device-if-fsync-called-on-part.patch new file mode 100644 index 000000000..5bab4f4ad --- /dev/null +++ b/fs-Inval-cache-for-parent-block-device-if-fsync-called-on-part.patch @@ -0,0 +1,106 @@ +Path: news.gmane.org!not-for-mail +From: Niels de Vos +Newsgroups: gmane.linux.kernel,gmane.linux.file-systems +Subject: [PATCH v2] fs: Invalidate the cache for a parent block-device if fsync() is called for a partition +Date: Mon, 23 Jan 2012 10:38:29 +0000 +Lines: 58 +Approved: news@gmane.org +Message-ID: <1327315109-7740-1-git-send-email-ndevos@redhat.com> +References: <4F19356E.3020708@redhat.com> +NNTP-Posting-Host: lo.gmane.org +X-Trace: dough.gmane.org 1327315263 30652 80.91.229.12 (23 Jan 2012 10:41:03 GMT) +X-Complaints-To: usenet@dough.gmane.org +NNTP-Posting-Date: Mon, 23 Jan 2012 10:41:03 +0000 (UTC) +Cc: linux-kernel@vger.kernel.org, Niels de Vos , + "Bryn M. Reeves" , + Mikulas Patocka +To: linux-fsdevel@vger.kernel.org +Original-X-From: linux-kernel-owner@vger.kernel.org Mon Jan 23 11:40:58 2012 +Return-path: +Envelope-to: glk-linux-kernel-3@lo.gmane.org +Original-Received: from vger.kernel.org ([209.132.180.67]) + by lo.gmane.org with esmtp (Exim 4.69) + (envelope-from ) + id 1RpHKb-0008Bu-Fh + for glk-linux-kernel-3@lo.gmane.org; Mon, 23 Jan 2012 11:40:57 +0100 +Original-Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand + id S1753263Ab2AWKkt (ORCPT ); + Mon, 23 Jan 2012 05:40:49 -0500 +Original-Received: from mx1.redhat.com ([209.132.183.28]:58739 "EHLO mx1.redhat.com" + rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP + id S1751990Ab2AWKks (ORCPT ); + Mon, 23 Jan 2012 05:40:48 -0500 +Original-Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) + by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q0NAelMx027033 + (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); + Mon, 23 Jan 2012 05:40:47 -0500 +Original-Received: from ndevos.usersys.redhat.com (dhcp-1-51.fab.redhat.com [10.33.1.51]) + by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q0NAejLn013691; + Mon, 23 Jan 2012 05:40:46 -0500 +In-Reply-To: <4F19356E.3020708@redhat.com> +X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 +Original-Sender: linux-kernel-owner@vger.kernel.org +Precedence: bulk +List-ID: +X-Mailing-List: linux-kernel@vger.kernel.org +Xref: news.gmane.org gmane.linux.kernel:1242432 gmane.linux.file-systems:60751 +Archived-At: + +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 +CC: Mikulas Patocka +Signed-off-by: Niels de Vos + +--- +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 + diff --git a/kernel.spec b/kernel.spec index 9d029d222..9ec8c629d 100644 --- a/kernel.spec +++ b/kernel.spec @@ -736,6 +736,9 @@ Patch21070: ext4-Support-check-none-nocheck-mount-options.patch Patch21073: KVM-x86-extend-struct-x86_emulate_ops-with-get_cpuid.patch Patch21074: KVM-x86-fix-missing-checks-in-syscall-emulation.patch +#rhbz 783211 +Patch21087: fs-Inval-cache-for-parent-block-device-if-fsync-called-on-part.patch + Patch21091: kmemleak.patch # compat-wireless patches @@ -745,6 +748,7 @@ Patch50002: compat-wireless-integrated-build.patch Patch50100: brcmfmac-gcc47.patch + %endif BuildRoot: %{_tmppath}/kernel-%{KVERREL}-root @@ -1427,6 +1431,9 @@ ApplyPatch KVM-x86-fix-missing-checks-in-syscall-emulation.patch ApplyPatch kmemleak.patch +#rhbz 783211 +ApplyPatch fs-Inval-cache-for-parent-block-device-if-fsync-called-on-part.patch + # END OF PATCH APPLICATIONS %endif @@ -2268,6 +2275,8 @@ fi %changelog * Wed Jan 25 2012 Josh Boyer - Update utrace.patch from Oleg Nesterov +- Add patch to invalidate parent cache when fsync is called on a partition + (rhbz 783211) * Wed Jan 25 2012 Josh Boyer - 3.3.0-0.rc1.git2.1 - Linux 3.3-rc1-git2 (upstream f8275f9694b8adf9f3498e747ea4c3e8b984499b)