Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp835672pxb; Thu, 28 Jan 2021 01:05:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJzfzagY/VoyLc9FAe5c34tJTn1rDvvISA9XnFsxRBjbcuuSXXl0Rx9aix6Fvu2NT57MguzY X-Received: by 2002:a50:b586:: with SMTP id a6mr12933543ede.206.1611824749135; Thu, 28 Jan 2021 01:05:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611824749; cv=none; d=google.com; s=arc-20160816; b=IsLGAM2kDfR3kDFVElJSzpWnhlX7P+k6vS6Yvyzw4Jbw5SS6W+nHwXvBYu+Q0Hcmdz V1qiXLao+yA5w/eznNemVTeM8QHqgwc947wYLkIkVwEPKKXxso49UCQlwSpj7T62zwj4 c0oBjbKw4ClMBqsVqPFAxsiUUtRBLE05+ouQrBy3DTtkD4jJpx+ANWlnUhbuSpfJjUOV nws/0MTEPHbAImOcYo+gIVP2se8eT3peIkr1Cpo9tsIlOCh4CHxjyqnqXLfl1M7dztMJ Kw7tvMWim+KacX2n7IE07YNha5UoKKJvCP2Ki/lOAc4wR/yVUPJoaUlDPo+oB6vYCcpO iraw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=dcG6VzWtyC5AOTfPQ4IDwCmiSozyvfGSYUO19fdzwoM=; b=uDBX50XejS8K4jG/vr+n05povI0SfAmmZ0l7VYbdp3Ikuaa85SNCL6i3f/iy4bitKu kk+cxS4ElFuzHpAeClO7OkJSx6/ZObsSlEkqDl8YuTuWHuTMr8Wiu5wkapSO9UTMOivc DD6/LK+MLmDjoUUk7zla3PSyvspJ+vcNPK3voiDTqjNFq+gelbn+xzbVJJVJqKXsxb4P J519zXKfBm8SRQJ2yq8lIdRAtxdHnDkP/Jg2I9PyZqqjjKGxwJcVwG4nNlXSAIfnjyHi TYOih3/mkASl/62LQvZTWQQnOexoHCDu9T78VIYzm99qD6HhLy4ACFaUucpCnzZnJMtd FEkw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t1si856987ejb.703.2021.01.28.01.05.23; Thu, 28 Jan 2021 01:05:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231591AbhA1JDT (ORCPT + 99 others); Thu, 28 Jan 2021 04:03:19 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:11457 "EHLO szxga06-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231652AbhA1JDE (ORCPT ); Thu, 28 Jan 2021 04:03:04 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4DRDyG4PPgzjDQy; Thu, 28 Jan 2021 17:02:46 +0800 (CST) Received: from szvp000203569.huawei.com (10.120.216.130) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.498.0; Thu, 28 Jan 2021 17:03:38 +0800 From: Chao Yu To: CC: , , , Yi Chen , Daiyue Zhang , Dehe Gu , Junchao Jiang , Ge Qiu Subject: [PATCH] f2fs: fix to avoid inconsistent quota data Date: Thu, 28 Jan 2021 17:02:56 +0800 Message-ID: <20210128090256.73910-1-yuchao0@huawei.com> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.120.216.130] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yi Chen Occasionally, quota data may be corrupted detected by fsck: Info: checkpoint state = 45 : crc compacted_summary unmount [QUOTA WARNING] Usage inconsistent for ID 0:actual (1543036928, 762) != expected (1543032832, 762) [ASSERT] (fsck_chk_quota_files:1986) --> Quota file is missing or invalid quota file content found. [QUOTA WARNING] Usage inconsistent for ID 0:actual (1352478720, 344) != expected (1352474624, 344) [ASSERT] (fsck_chk_quota_files:1986) --> Quota file is missing or invalid quota file content found. [FSCK] Unreachable nat entries [Ok..] [0x0] [FSCK] SIT valid block bitmap checking [Ok..] [FSCK] Hard link checking for regular file [Ok..] [0x0] [FSCK] valid_block_count matching with CP [Ok..] [0xdf299] [FSCK] valid_node_count matcing with CP (de lookup) [Ok..] [0x2b01] [FSCK] valid_node_count matcing with CP (nat lookup) [Ok..] [0x2b01] [FSCK] valid_inode_count matched with CP [Ok..] [0x2665] [FSCK] free segment_count matched with CP [Ok..] [0xcb04] [FSCK] next block offset is free [Ok..] [FSCK] fixing SIT types [FSCK] other corrupted bugs [Fail] The root cause is: If we open file w/ readonly flag, disk quota info won't be initialized for this file, however, following mmap() will force to convert inline inode via f2fs_convert_inline_inode(), which may increase block usage for this inode w/o updating quota data, it causes inconsistent disk quota info. The issue will happen in following stack: open(file, O_RDONLY) mmap(file) - f2fs_convert_inline_inode - f2fs_convert_inline_page - f2fs_reserve_block - f2fs_reserve_new_block - f2fs_reserve_new_blocks - f2fs_i_blocks_write - dquot_claim_block inode->i_blocks increase, but the dqb_curspace keep the size for the dquots is NULL. To fix this issue, let's call dquot_initialize() anyway in both f2fs_truncate() and f2fs_convert_inline_inode() functions to avoid potential inconsistent quota data issue. Fixes: 0abd675e97e6 ("f2fs: support plain user/group quota") Signed-off-by: Daiyue Zhang Signed-off-by: Dehe Gu Signed-off-by: Junchao Jiang Signed-off-by: Ge Qiu Signed-off-by: Yi Chen --- fs/f2fs/file.c | 4 ++++ fs/f2fs/inline.c | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 7db27c81d034..00b2ce47fa37 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -771,6 +771,10 @@ int f2fs_truncate(struct inode *inode) return -EIO; } + err = dquot_initialize(inode); + if (err) + return err; + /* we should check inline_data size */ if (!f2fs_may_inline_data(inode)) { err = f2fs_convert_inline_inode(inode); diff --git a/fs/f2fs/inline.c b/fs/f2fs/inline.c index 806ebabf5870..993caefcd2bb 100644 --- a/fs/f2fs/inline.c +++ b/fs/f2fs/inline.c @@ -192,6 +192,10 @@ int f2fs_convert_inline_inode(struct inode *inode) f2fs_hw_is_readonly(sbi) || f2fs_readonly(sbi->sb)) return 0; + err = dquot_initialize(inode); + if (err) + return err; + page = f2fs_grab_cache_page(inode->i_mapping, 0, false); if (!page) return -ENOMEM; -- 2.29.2