From patchwork Mon Jan 8 19:02:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 10150367 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 906FB601BE for ; Mon, 8 Jan 2018 19:04:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 97BB0289EB for ; Mon, 8 Jan 2018 19:04:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8C51D289ED; Mon, 8 Jan 2018 19:04:47 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, 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 F15A3289EB for ; Mon, 8 Jan 2018 19:04:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756208AbeAHTEq (ORCPT ); Mon, 8 Jan 2018 14:04:46 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:53940 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755418AbeAHTEp (ORCPT ); Mon, 8 Jan 2018 14:04:45 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.21) with SMTP id w08J4LAv149298; Mon, 8 Jan 2018 19:04:22 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : mime-version : content-type; s=corp-2017-10-26; bh=I+0sTJiMSFfERbRJWSV1su/GiHz20gjCJ55MzUZCRVg=; b=BFIi3nJwCle5EYkK2Vji+RkDWh+67y0ilKNERjPvkNbRshmG64ZoBiGTe39IDi/Yul4M 5GANJ87Ra78Z7OzmDmm65aG4OV06ko/1K1F3HdXveIQAIRCXN9RJj/3mGfciseOsr2xx B+K+ohMF4dsF7Gup1I9PiNgzpXBWxW/0nAAHYO30ssFNag3cR5thua6fjbE/WPbft6KG f7nKWt8lXrRdPGyLyH68IlLlAx+FP1NC32oXfmU3EYKAbC0zjDPWZnR/HwK0tiyIZ/mZ nU3fg3xXK/vD0M65/qbKrFaZZhXrcHZ4hkiTWUB6RNXvUFEkbQiL1DhKyHNagqRuQaQy 2Q== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp2120.oracle.com with ESMTP id 2fcdag0dhj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 08 Jan 2018 19:04:21 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w08J2IFx029156 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 8 Jan 2018 19:02:18 GMT Received: from abhmp0004.oracle.com (abhmp0004.oracle.com [141.146.116.10]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w08J2Hox028415; Mon, 8 Jan 2018 19:02:17 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 08 Jan 2018 11:02:17 -0800 Date: Mon, 8 Jan 2018 11:02:16 -0800 From: "Darrick J. Wong" To: xfs , linux-fsdevel Cc: Christoph Hellwig Subject: [PATCH] vfs/xfs: clean up cow mappings during fs data freeze Message-ID: <20180108190216.GR5602@magnolia> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8768 signatures=668652 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1801080270 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 From: Darrick J. Wong As part of the fs freezing process, we want to free the copy-on-write reservations after all the dirty data has been written to disk but prior to freezing the filesystem. Currently, only a sync_filesystem call is hardwired into the VFS code, so provide a new callout, ->freeze_data, so that filesystems can override with whatever behavior they want. In the case of XFS, that behavior is "sync and then clean the cow mappings". This reduces the amount of recovery that must happen if the system goes down while the fs is frozen. Signed-off-by: Darrick J. Wong --- fs/super.c | 23 +++++++++++++++++------ fs/xfs/xfs_super.c | 21 +++++++++++++++++++++ include/linux/fs.h | 1 + 3 files changed, 39 insertions(+), 6 deletions(-) -- 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/super.c b/fs/super.c index d4e33e8..f0ee186 100644 --- a/fs/super.c +++ b/fs/super.c @@ -1454,7 +1454,16 @@ int freeze_super(struct super_block *sb) sb_wait_write(sb, SB_FREEZE_PAGEFAULT); /* All writers are done so after syncing there won't be dirty data */ - sync_filesystem(sb); + if (sb->s_op->freeze_data) { + ret = sb->s_op->freeze_data(sb); + if (ret) { + printk(KERN_ERR + "VFS:Filesystem data freeze failed\n"); + goto freeze_fail; + } + } else { + sync_filesystem(sb); + } /* Now wait for internal filesystem counter */ sb->s_writers.frozen = SB_FREEZE_FS; @@ -1465,11 +1474,7 @@ int freeze_super(struct super_block *sb) if (ret) { printk(KERN_ERR "VFS:Filesystem freeze failed\n"); - sb->s_writers.frozen = SB_UNFROZEN; - sb_freeze_unlock(sb); - wake_up(&sb->s_writers.wait_unfrozen); - deactivate_locked_super(sb); - return ret; + goto freeze_fail; } } /* @@ -1480,6 +1485,12 @@ int freeze_super(struct super_block *sb) lockdep_sb_freeze_release(sb); up_write(&sb->s_umount); return 0; +freeze_fail: + sb->s_writers.frozen = SB_UNFROZEN; + sb_freeze_unlock(sb); + wake_up(&sb->s_writers.wait_unfrozen); + deactivate_locked_super(sb); + return ret; } EXPORT_SYMBOL(freeze_super); diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c index 2db6a40..2817bce 100644 --- a/fs/xfs/xfs_super.c +++ b/fs/xfs/xfs_super.c @@ -1408,6 +1408,26 @@ xfs_fs_remount( } /* + * First stage of a freeze. We need to sync all the dirty data and clean up + * all the leftover CoW mappings to make the filesystem as tidy as possible. + */ +STATIC int +xfs_fs_freeze_data( + struct super_block *sb) +{ + struct xfs_mount *mp = XFS_M(sb); + int error; + + error = sync_filesystem(sb); + if (error) + return error; + + if (!xfs_sb_version_hasreflink(&mp->m_sb)) + return 0; + return xfs_icache_free_cowblocks(mp, NULL); +} + +/* * Second stage of a freeze. The data is already frozen so we only * need to take care of the metadata. Once that's done sync the superblock * to the log to dirty it in case of a crash while frozen. This ensures that we @@ -1780,6 +1800,7 @@ static const struct super_operations xfs_super_operations = { .drop_inode = xfs_fs_drop_inode, .put_super = xfs_fs_put_super, .sync_fs = xfs_fs_sync_fs, + .freeze_data = xfs_fs_freeze_data, .freeze_fs = xfs_fs_freeze, .unfreeze_fs = xfs_fs_unfreeze, .statfs = xfs_fs_statfs, diff --git a/include/linux/fs.h b/include/linux/fs.h index 2995a27..d53d55f 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1811,6 +1811,7 @@ struct super_operations { void (*put_super) (struct super_block *); int (*sync_fs)(struct super_block *sb, int wait); int (*freeze_super) (struct super_block *); + int (*freeze_data) (struct super_block *); int (*freeze_fs) (struct super_block *); int (*thaw_super) (struct super_block *); int (*unfreeze_fs) (struct super_block *);