From patchwork Thu May 18 01:32:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 9732257 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 70BE9600CC for ; Thu, 18 May 2017 01:32:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 25D86287FA for ; Thu, 18 May 2017 01:32:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1A65B28830; Thu, 18 May 2017 01:32:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6DD00287FA for ; Thu, 18 May 2017 01:32:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754363AbdERBcq (ORCPT ); Wed, 17 May 2017 21:32:46 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:51454 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753397AbdERBcq (ORCPT ); Wed, 17 May 2017 21:32:46 -0400 Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v4I1Wh45012259 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 18 May 2017 01:32:43 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id v4I1Wh8C032135 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 18 May 2017 01:32:43 GMT Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id v4I1Whqk021753; Thu, 18 May 2017 01:32:43 GMT Received: from localhost (/24.21.211.40) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 17 May 2017 18:32:42 -0700 Date: Wed, 17 May 2017 18:32:42 -0700 From: "Darrick J. Wong" To: xfs Cc: Eric Sandeen Subject: [PATCH 3/3] xfs: freeze rw filesystems just prior to reboot Message-ID: <20170518013242.GW4519@birch.djwong.org> References: <20170518012618.GT4519@birch.djwong.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20170518012618.GT4519@birch.djwong.org> User-Agent: Mutt/1.5.24 (2015-08-30) X-Source-IP: userv0021.oracle.com [156.151.31.71] Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Apparently there are certain system software configurations that do odd things like update the kernel and reboot without umounting the /boot fs or remounting it readonly, either of which would push all the AIL items out to disk. As a result, a subsequent invocation of something like grub (which has a frightening willingness to read a fs with a dirty log) can read stale disk contents and/or miss files the metadata for which have been written to the log but not checkpointed into the filesystem. Granted, most of the time /boot is a separate partition and systemd/sysvinit/whatever actually /do/ unmount /boot before rebooting. This "fix" is only needed for people who have one giant filesystem. Therefore, add a reboot hook to freeze the rw filesystems (which checkpoints the log) just prior to reboot. This is an unfortunate and insufficient workaround for multiple layers of inadequate external software, but at least it will reduce boot time surprises for the "OS updater failed to disengage the filesystem before rebooting" case. Seeing as grub is unlikely ever to learn to replay the XFS log (and we probably don't want it doing that), *LILO has been discontinued for at least 18 months, and we're not quite to the point of putting kernel files directly on the EFI System Partition, this seems like the least crappy solution to this problem. Yes, you're still screwed in grub if the system crashes. :) I don't anticipate this patch will make it upstream, but the idea could get at least a single hearing. Signed-off-by: Darrick J. Wong --- fs/xfs/xfs_super.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c index 455a575..415b1e8 100644 --- a/fs/xfs/xfs_super.c +++ b/fs/xfs/xfs_super.c @@ -61,6 +61,7 @@ #include #include #include +#include static const struct super_operations xfs_super_operations; struct bio_set *xfs_ioend_bioset; @@ -1982,6 +1983,38 @@ xfs_destroy_workqueues(void) destroy_workqueue(xfs_alloc_wq); } +STATIC void +xfs_reboot_fs( + struct super_block *sb, + void *priv) +{ + int error; + + if (sb->s_flags & MS_RDONLY) + return; + xfs_info(XFS_M(sb), "Freezing prior to reboot."); + up_read(&sb->s_umount); + error = freeze_super(sb); + down_read(&sb->s_umount); + if (error && error != -EBUSY) + xfs_info(XFS_M(sb), "Unable to freeze, error=%d", error); +} + +STATIC int +xfs_reboot( + struct notifier_block *nb, + ulong event, + void *buf) +{ + iterate_supers_type(&xfs_fs_type, xfs_reboot_fs, NULL); + return NOTIFY_DONE; +} + +static struct notifier_block xfs_reboot_notifier = { + .notifier_call = xfs_reboot, + .priority = INT_MAX, +}; + STATIC int __init init_xfs_fs(void) { @@ -2056,8 +2089,14 @@ init_xfs_fs(void) error = register_filesystem(&xfs_fs_type); if (error) goto out_qm_exit; + + error = register_reboot_notifier(&xfs_reboot_notifier); + if (error) + goto out_register_fs; return 0; + out_register_fs: + unregister_filesystem(&xfs_fs_type); out_qm_exit: xfs_qm_exit(); out_remove_dbg_kobj: @@ -2089,6 +2128,7 @@ init_xfs_fs(void) STATIC void __exit exit_xfs_fs(void) { + unregister_reboot_notifier(&xfs_reboot_notifier); xfs_qm_exit(); unregister_filesystem(&xfs_fs_type); #ifdef DEBUG