From patchwork Tue Dec 6 09:00:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hou Tao X-Patchwork-Id: 9486721 X-Mozilla-Keys: nonjunk Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on sandeen.net X-Spam-Level: X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD autolearn=ham autolearn_force=no version=3.4.0 X-Spam-HP: BAYES_00=-1.9,HEADER_FROM_DIFFERENT_DOMAINS=0.001, RCVD_IN_DNSWL_HI=-5,RP_MATCHES_RCVD=-0.1 X-Original-To: sandeen@sandeen.net Delivered-To: sandeen@sandeen.net Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by sandeen.net (Postfix) with ESMTP id A1995479689 for ; Tue, 6 Dec 2016 03:16:05 -0600 (CST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752263AbcLFJRC (ORCPT ); Tue, 6 Dec 2016 04:17:02 -0500 Received: from szxga01-in.huawei.com ([58.251.152.64]:44664 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751936AbcLFJQy (ORCPT ); Tue, 6 Dec 2016 04:16:54 -0500 Received: from 172.24.1.36 (EHLO szxeml428-hub.china.huawei.com) ([172.24.1.36]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DWD38283; Tue, 06 Dec 2016 16:57:56 +0800 (CST) Received: from huawei.com (10.175.124.28) by szxeml428-hub.china.huawei.com (10.82.67.183) with Microsoft SMTP Server id 14.3.235.1; Tue, 6 Dec 2016 16:57:55 +0800 From: Hou Tao To: CC: , Subject: [PATCH] xfs: during log recovery, destroy the unlinked inodes even for read-only mount Date: Tue, 6 Dec 2016 17:00:47 +0800 Message-ID: <1481014847-22242-1-git-send-email-houtao1@huawei.com> X-Mailer: git-send-email 2.5.0 MIME-Version: 1.0 X-Originating-IP: [10.175.124.28] X-CFilter-Loop: Reflected Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org During the 2nd stage of log recovery, if the filesystem is firstly mounted as read-only, the unlink inodes will not be destroyed and the unlinked list in AGI will not be cleared. Even after a read-write remount or umount, the unlinked inodes will still be valid and be kept on disk, and the available freespace will be incorrect. To fix the problem, we need to force xfs_inactive() to destroy the unlinked inode when the filesystem is mounted as read-only. So clear the XFS_MOUNT_RDONLY flag temporarily before the recovery of unlinked inodes and restore the flag after the recovery has done. The problem can be reproduced by the following steps: 1. mount a xfs fs on a KVM VM 2. on the VM launch an application which does the following things: open(xfs_file); unlink(xfs_file); while(1) { write(xfs_file, 2MB); sleep(1); } 3. wait 5 seconds, sync the xfs fs, and wait 5 seconds 4. terminate the VM 5. start the VM and mount the xfs as read-only 6. remount the xfs as read-write or umount 7. check the unlinked list and the available freespace Cc: [3.10+] Signed-off-by: Hou Tao --- fs/xfs/xfs_log_recover.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fs/xfs/xfs_log_recover.c b/fs/xfs/xfs_log_recover.c index 9b3d7c7..fcc83e0 100644 --- a/fs/xfs/xfs_log_recover.c +++ b/fs/xfs/xfs_log_recover.c @@ -5025,6 +5025,7 @@ xlog_recover_process_iunlinks( int bucket; int error; uint mp_dmevmask; + int ro_mount; mp = log->l_mp; @@ -5034,6 +5035,11 @@ xlog_recover_process_iunlinks( mp_dmevmask = mp->m_dmevmask; mp->m_dmevmask = 0; + /* Destroy the unlinked inodes even for read-only mount */ + ro_mount = mp->m_flags & XFS_MOUNT_RDONLY; + if (ro_mount) + mp->m_flags &= ~XFS_MOUNT_RDONLY; + for (agno = 0; agno < mp->m_sb.sb_agcount; agno++) { /* * Find the agi for this ag. @@ -5070,6 +5076,9 @@ xlog_recover_process_iunlinks( xfs_buf_rele(agibp); } + if (ro_mount) + mp->m_flags |= XFS_MOUNT_RDONLY; + mp->m_dmevmask = mp_dmevmask; }