Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2280931pxp; Mon, 21 Mar 2022 15:46:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxXo6CYmQ2iRqI43d5fA4v3Fs3B8u6IjuY8fMTdU8XfMB1MyAvmUQnIETPzflvXu7ro+bwu X-Received: by 2002:a17:902:b406:b0:14f:bb35:95ab with SMTP id x6-20020a170902b40600b0014fbb3595abmr15074053plr.140.1647902801443; Mon, 21 Mar 2022 15:46:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647902801; cv=none; d=google.com; s=arc-20160816; b=zfjKbixrRxn249cWJZxrTSekYP+El11ih154S26C/9VJqumfshqc3wS86WLuqSLwMR tCgyA2Y9n/k2CCi9X9yrkLWwzA8EXV2zrJLC9kRgLRWeQ+58apJhY26nVMXAuy90MIWN K5Wxr/WOKwQ29KXQEhwhD4YXo8uA7rAsloRCljoxnERSEPGBNOcf4z05aYlQa554z1cs wCReGb2zlEnkTsRGnS2iYVnUBPiTWTaCClCDDbaKVBzSOG84b5ViDMcIVeAylNzGpego nHFhYC7X+iqjlP1RBMns6kCkJ3S96UWjWTZ0uDv8S8nE22wmxmtmYGuZhVMpAiMx0EUl ZUug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=DCUsvbBIepHFYijDl/UO9fYL4oEbRFymMwxaQVykvOw=; b=NsRO7F4kXkbAH17gMkfBtRcV218LvKFbZFFSrQYAtUXI63RMG8U7QbSl53pFVUwEib o31Xy0K6vLSE92cZjnXDh6CXQszpQQ1gle9ssLigpaCqENjf1Pergw9GebUO0YMgwAeO jqpTvVY3DBJk5js8WKJ8YGr1s7jlY60cldIrovANlMs03wi30sarqKiLp5J3Z7mFP2nD fJf+eUzIPEYBK1pdPoR2f1QEubxH7WJ2pA6Bil3K9qPYplUUvjezph0cwBhJ1WuB0o8v v6lsSsZXkOMDcNowBFEzS1XboizZQGLwaGiZhUfHCpbjBAYa87yVi5GQfZFJsHI6o3Je Z1dg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id k2-20020a63ab42000000b003816043ef09si15558680pgp.254.2022.03.21.15.46.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 15:46:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BD6FA337C16; Mon, 21 Mar 2022 14:54:32 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344112AbiCUCAl (ORCPT + 99 others); Sun, 20 Mar 2022 22:00:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238328AbiCUCAk (ORCPT ); Sun, 20 Mar 2022 22:00:40 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32A5512621 for ; Sun, 20 Mar 2022 18:59:15 -0700 (PDT) Received: from kwepemi500012.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4KMHnK3FCWzfZ35; Mon, 21 Mar 2022 09:57:41 +0800 (CST) Received: from kwepemm600003.china.huawei.com (7.193.23.202) by kwepemi500012.china.huawei.com (7.221.188.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Mon, 21 Mar 2022 09:59:13 +0800 Received: from [127.0.0.1] (10.174.177.249) by kwepemm600003.china.huawei.com (7.193.23.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Mon, 21 Mar 2022 09:59:12 +0800 Subject: Re: [PATCH] e2fsck: subtract acl blocks when setting i_file_acl to zero To: Li Jinlin , CC: , References: <20220317172943.2426272-1-lijinlin3@huawei.com> <8e8f277d-6222-5f63-0dcb-a17771a0deff@huawei.com> From: Zhiqiang Liu Message-ID: Date: Mon, 21 Mar 2022 09:59:11 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <8e8f277d-6222-5f63-0dcb-a17771a0deff@huawei.com> Content-Type: text/plain; charset="gbk" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.177.249] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemm600003.china.huawei.com (7.193.23.202) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org For truncating orphaned inode, we should not remove its ACL in release_inode_blocks(), otherwise it may cause safety problems due to loss of acl. diff --git a/e2fsck/super.c b/e2fsck/super.c index 31e2ffb..6249e12 100644 --- a/e2fsck/super.c +++ b/e2fsck/super.c @@ -236,6 +236,10 @@ static int release_inode_blocks(e2fsck_t ctx, ext2_ino_t ino, ext2fs_iblk_sub_blocks(fs, EXT2_INODE(inode), pb.truncated_blocks); + /* do not clean up file acl if the inode is truncating type */ + if (inode->i_links_count) + return 0; + blk = ext2fs_file_acl_block(fs, EXT2_INODE(inode)); if (blk) { retval = ext2fs_adjust_ea_refcount3(fs, blk, block_buf, -1, -- 2.27.0 On 2022/3/18 0:54, Li Jinlin wrote: > We got issue as follows: > [root@localhost ~]# e2fsck -a img > img: recovering journal > img: Truncating orphaned inode 188 (uid=0, gid=0, mode=0100666, size=0) > img: Truncating orphaned inode 174 (uid=0, gid=0, mode=0100666, size=0) > img: clean, 484/128016 files, 118274/512000 blocks > [root@localhost ~]# e2fsck -fn img > e2fsck 1.46.5 (30-Dec-2021) > Pass 1: Checking inodes, blocks, and sizes > Inode 174, i_blocks is 2, should be 0. Fix? no > > Inode 188, i_blocks is 2, should be 0. Fix? no > > Pass 2: Checking directory structure > Pass 3: Checking directory connectivity > Pass 4: Checking reference counts > Pass 5: Checking group summary information > > img: ********** WARNING: Filesystem still has errors ********** > > img: 484/128016 files (24.6% non-contiguous), 118274/512000 blocks > > > File ACL would be set to zero in release_inode_blocks(), but the > blocks count will not be subtract acl blocks, which causes this issue. > > To slove this issue, subtract acl blocks when setting i_file_acl to > zero. > > Signed-off-by: LiJinlin > Signed-off-by: Zhiqiang Liu > --- > e2fsck/super.c | 7 +++++-- > lib/ext2fs/ext2fs.h | 5 +++++ > lib/ext2fs/ext_attr.c | 15 +++++++++++++-- > 3 files changed, 23 insertions(+), 4 deletions(-) > > diff --git a/e2fsck/super.c b/e2fsck/super.c > index 9495e029..715a8dc9 100644 > --- a/e2fsck/super.c > +++ b/e2fsck/super.c > @@ -194,6 +194,7 @@ static int release_inode_blocks(e2fsck_t ctx, ext2_ino_t ino, > blk64_t blk; > errcode_t retval; > __u32 count; > + __u32 blocks; > > if (!ext2fs_inode_has_valid_blocks2(fs, EXT2_INODE(inode))) > return 0; > @@ -238,8 +239,10 @@ static int release_inode_blocks(e2fsck_t ctx, ext2_ino_t ino, > > blk = ext2fs_file_acl_block(fs, EXT2_INODE(inode)); > if (blk) { > - retval = ext2fs_adjust_ea_refcount3(fs, blk, block_buf, -1, > - &count, ino); > + retval = ext2fs_adjust_ea_refcount4(fs, blk, block_buf, -1, > + &count, ino, &blocks); > + if (retval == 0) > + ext2fs_iblk_sub_blocks(fs, EXT2_INODE(inode), blocks); > if (retval == EXT2_ET_BAD_EA_BLOCK_NUM) { > retval = 0; > count = 1; > diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h > index 68f9c1fe..8ebebf31 100644 > --- a/lib/ext2fs/ext2fs.h > +++ b/lib/ext2fs/ext2fs.h > @@ -1289,6 +1289,11 @@ extern errcode_t ext2fs_adjust_ea_refcount3(ext2_filsys fs, blk64_t blk, > char *block_buf, > int adjust, __u32 *newcount, > ext2_ino_t inum); > +extern errcode_t ext2fs_adjust_ea_refcount4(ext2_filsys fs, blk64_t blk, > + char *block_buf, > + int adjust, __u32 *newcount, > + ext2_ino_t inum, > + __u32 *blocks); > errcode_t ext2fs_xattrs_write(struct ext2_xattr_handle *handle); > errcode_t ext2fs_xattrs_read(struct ext2_xattr_handle *handle); > errcode_t ext2fs_xattrs_read_inode(struct ext2_xattr_handle *handle, > diff --git a/lib/ext2fs/ext_attr.c b/lib/ext2fs/ext_attr.c > index d36fe68d..1538a53a 100644 > --- a/lib/ext2fs/ext_attr.c > +++ b/lib/ext2fs/ext_attr.c > @@ -237,9 +237,10 @@ errcode_t ext2fs_write_ext_attr(ext2_filsys fs, blk_t block, void *inbuf) > /* > * This function adjusts the reference count of the EA block. > */ > -errcode_t ext2fs_adjust_ea_refcount3(ext2_filsys fs, blk64_t blk, > +errcode_t ext2fs_adjust_ea_refcount4(ext2_filsys fs, blk64_t blk, > char *block_buf, int adjust, > - __u32 *newcount, ext2_ino_t inum) > + __u32 *newcount, ext2_ino_t inum, > + __u32 *blocks) > { > errcode_t retval; > struct ext2_ext_attr_header *header; > @@ -264,6 +265,8 @@ errcode_t ext2fs_adjust_ea_refcount3(ext2_filsys fs, blk64_t blk, > header->h_refcount += adjust; > if (newcount) > *newcount = header->h_refcount; > + if (blocks) > + *blocks = header->h_blocks; > > retval = ext2fs_write_ext_attr3(fs, blk, block_buf, inum); > if (retval) > @@ -275,6 +278,14 @@ errout: > return retval; > } > > +errcode_t ext2fs_adjust_ea_refcount3(ext2_filsys fs, blk64_t blk, > + char *block_buf, int adjust, > + __u32 *newcount, ext2_ino_t inum) > +{ > + return ext2fs_adjust_ea_refcount4(fs, blk, block_buf, adjust, > + newcount, 0, NULL); > +} > + > errcode_t ext2fs_adjust_ea_refcount2(ext2_filsys fs, blk64_t blk, > char *block_buf, int adjust, > __u32 *newcount) >