[kernel] Add patch to invalidate parent cache when fsync is called on a partition (rhbz 783211)

Josh Boyer jwboyer at fedoraproject.org
Thu Jan 26 01:06:41 UTC 2012


commit b4c7c3009663ddcfbd6f3dbe611581dd3312ab1e
Author: Josh Boyer <jwboyer at redhat.com>
Date:   Wed Jan 25 17:08:55 2012 -0500

    Add patch to invalidate parent cache when fsync is called on a partition
    (rhbz 783211)

 ...rent-block-device-if-fsync-called-on-part.patch |  106 ++++++++++++++++++++
 kernel.spec                                        |    9 ++
 2 files changed, 115 insertions(+), 0 deletions(-)
---
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 0000000..5bab4f4
--- /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 <ndevos at redhat.com>
+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 at gmane.org
+Message-ID: <1327315109-7740-1-git-send-email-ndevos at redhat.com>
+References: <4F19356E.3020708 at 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 at dough.gmane.org
+NNTP-Posting-Date: Mon, 23 Jan 2012 10:41:03 +0000 (UTC)
+Cc: linux-kernel at vger.kernel.org, Niels de Vos <ndevos at redhat.com>,
+	"Bryn M. Reeves" <bmr at redhat.com>,
+	Mikulas Patocka <mpatocka at redhat.com>
+To: linux-fsdevel at vger.kernel.org
+Original-X-From: linux-kernel-owner at vger.kernel.org Mon Jan 23 11:40:58 2012
+Return-path: <linux-kernel-owner at vger.kernel.org>
+Envelope-to: glk-linux-kernel-3 at lo.gmane.org
+Original-Received: from vger.kernel.org ([209.132.180.67])
+	by lo.gmane.org with esmtp (Exim 4.69)
+	(envelope-from <linux-kernel-owner at vger.kernel.org>)
+	id 1RpHKb-0008Bu-Fh
+	for glk-linux-kernel-3 at lo.gmane.org; Mon, 23 Jan 2012 11:40:57 +0100
+Original-Received: (majordomo at vger.kernel.org) by vger.kernel.org via listexpand
+	id S1753263Ab2AWKkt (ORCPT <rfc822;glk-linux-kernel-3 at m.gmane.org>);
+	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 <rfc822;linux-kernel at vger.kernel.org>);
+	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 at redhat.com>
+X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25
+Original-Sender: linux-kernel-owner at vger.kernel.org
+Precedence: bulk
+List-ID: <linux-kernel.vger.kernel.org>
+X-Mailing-List: linux-kernel at vger.kernel.org
+Xref: news.gmane.org gmane.linux.kernel:1242432 gmane.linux.file-systems:60751
+Archived-At: <http://permalink.gmane.org/gmane.linux.kernel/1242432>
+
+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 at redhat.com>
+CC: Mikulas Patocka <mpatocka at redhat.com>
+Signed-off-by: Niels de Vos <ndevos at redhat.com>
+
+---
+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 9d029d2..9ec8c62 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 <jwboyer at redhat.com>
 - 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 <jwboyer at redhat.com> - 3.3.0-0.rc1.git2.1
 - Linux 3.3-rc1-git2 (upstream f8275f9694b8adf9f3498e747ea4c3e8b984499b)


More information about the scm-commits mailing list