From patchwork Thu Jan 30 15:26:54 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Ruder X-Patchwork-Id: 315392 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from casper.infradead.org (unknown [IPv6:2001:770:15f::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40CBA2C009C for ; Fri, 31 Jan 2014 02:33:08 +1100 (EST) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1W8tbl-0005Hc-IA; Thu, 30 Jan 2014 15:32:49 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1W8tbj-0002Uz-QP; Thu, 30 Jan 2014 15:32:47 +0000 Received: from mail-ig0-f175.google.com ([209.85.213.175]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1W8tbh-0002T6-Lg for linux-mtd@lists.infradead.org; Thu, 30 Jan 2014 15:32:46 +0000 Received: by mail-ig0-f175.google.com with SMTP id uq10so17920060igb.2 for ; Thu, 30 Jan 2014 07:32:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=G/Zit71m8MpYf8EiQSRDNlOb0BCMJ30dXYekuHvvy+A=; b=KTTvjSGmgdOSqX9mNglX49lK8JRa+iXWeh0iE8DaqquD1COJ7p0W4VDEBNSLRvGYtJ iu2pvKd7UsM73Tz19ThH2g6dkX+0CNtV34L8XH203wVqYp5Kn5nJNkgziJRl3Rxl7Oqu 5l2T2lWph1dNngvjXhmTXenW9fcLVG1hp6Rp8W2stS5mlY5kqL7KNctvXWybp3BgARtW O7julef2o4Wf3W28+tmq084jLroacYL1COhezy6uKaUzEhtmGARrKTe/LdCFa4KyQhAB ItxY47Rr/3e9SzDlu3dr3l9vGcLOPMKslFND2ZrVsXV4EPwFA/YcqJR9DQjybFYlPSvs BhLA== X-Gm-Message-State: ALoCoQlqca5Gq9PmQciRdtCcGHAyeC8tgTPIucXMmFu0BhRqYyVkM61qMEkI29VkA9GL3HF/EA8e X-Received: by 10.50.97.6 with SMTP id dw6mr34290446igb.21.1391095941620; Thu, 30 Jan 2014 07:32:21 -0800 (PST) Received: from andrewruder-hplin.dci.local (64-198-156-98.ip.mcleodusa.net. [64.198.156.98]) by mx.google.com with ESMTPSA id fk5sm80379736igb.9.2014.01.30.07.32.20 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 30 Jan 2014 07:32:20 -0800 (PST) From: Andrew Ruder To: linux-fsdevel@vger.kernel.org, linux-mtd@lists.infradead.org Subject: [HACK] fs/super.c: sync ro remount after blocking writers Date: Thu, 30 Jan 2014 09:26:54 -0600 Message-Id: <1391095614-21554-1-git-send-email-andrew.ruder@elecsyscorp.com> X-Mailer: git-send-email 1.8.5.2 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140130_103245_737378_D0ABF1C7 X-CRM114-Status: GOOD ( 14.04 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.213.175 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Christoph Hellwig , Richard Weinberger , Andrew Ruder , Alexander Viro , Artem Bityutskiy X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Move sync_filesystem() after sb_prepare_remount_readonly(). If writers sneak in anywhere from sync_filesystem() to sb_prepare_remount_readonly() it can cause inodes to be dirtied and writeback to occur well after sys_mount() has completely successfully. This was spotted by corrupted ubifs filesystems on reboot, but appears that it can cause issues with any filesystem using writeback. Cc: Artem Bityutskiy Cc: Christoph Hellwig Cc: Alexander Viro CC: Richard Weinberger Co-authored-by: Richard Weinberger Signed-off-by: Andrew Ruder --- I marked this as hack as because there is still a race condition concerning the force == 1 situation. mark_files_ro() never actually blocks new writers even through the filesystem-specific remount code because nothing ever sets sb->s_readonly_remount. fs/super.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/super.c b/fs/super.c index 0225c20..1912090d 100644 --- a/fs/super.c +++ b/fs/super.c @@ -735,59 +735,59 @@ rescan: int do_remount_sb(struct super_block *sb, int flags, void *data, int force) { int retval; int remount_ro; if (sb->s_writers.frozen != SB_UNFROZEN) return -EBUSY; #ifdef CONFIG_BLOCK if (!(flags & MS_RDONLY) && bdev_read_only(sb->s_bdev)) return -EACCES; #endif if (flags & MS_RDONLY) acct_auto_close(sb); shrink_dcache_sb(sb); - sync_filesystem(sb); remount_ro = (flags & MS_RDONLY) && !(sb->s_flags & MS_RDONLY); /* If we are remounting RDONLY and current sb is read/write, make sure there are no rw files opened */ if (remount_ro) { if (force) { mark_files_ro(sb); } else { retval = sb_prepare_remount_readonly(sb); if (retval) return retval; } } + sync_filesystem(sb); if (sb->s_op->remount_fs) { retval = sb->s_op->remount_fs(sb, &flags, data); if (retval) { if (!force) goto cancel_readonly; /* If forced remount, go ahead despite any errors */ WARN(1, "forced remount of a %s fs returned %i\n", sb->s_type->name, retval); } } sb->s_flags = (sb->s_flags & ~MS_RMT_MASK) | (flags & MS_RMT_MASK); /* Needs to be ordered wrt mnt_is_readonly() */ smp_wmb(); sb->s_readonly_remount = 0; /* * Some filesystems modify their metadata via some other path than the * bdev buffer cache (eg. use a private mapping, or directories in * pagecache, etc). Also file data modifications go via their own * mappings. So If we try to mount readonly then copy the filesystem * from bdev, we could get stale data, so invalidate it to give a best * effort at coherency. */ if (remount_ro && sb->s_bdev) invalidate_bdev(sb->s_bdev); return 0;