Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp83418pxf; Tue, 30 Mar 2021 20:18:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwKE47d7S5dAAaI3EqLAlI2KVe/PhAhYtInRrrMF1OQDCP1PNRbhNQMfEIWf6TK+lZvLxaC X-Received: by 2002:a17:907:1c05:: with SMTP id nc5mr1341141ejc.320.1617160682490; Tue, 30 Mar 2021 20:18:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617160682; cv=none; d=google.com; s=arc-20160816; b=q1nu/BLboe2V7k11pQdWXM630gra0zZdDE30/k9qMFCpb3oSD6EVhylN7yxjFrx5/M ex+LXe7KVS6dZ07srCW7c3UdtlLFGXVgU36QLHnxKmetsOTk9u6pZ5vL697t9DrRykV5 vgQ116wY/JAnZph27eXZd8Qd7O/VJ/E25KrASIHJeVE6/G/5RpEKtBQbJE0OK79sa4Ye GPlFPKj/pKj2FOvP3ZuUE5tAMrSIEKHzgeqS6vzwrwoqTlxeqJZ7n1eTjr3aOZ9cI88b 1jj55OltdiaY1fha695BfmmSA2o8cOy1tPSd+Hbh9gNXpI9VP59DIgV9HXXl8YxMjJHb BBAg== 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=fefsMnvgpO+xg/y1SwAVTJRjqrNYDkT8pmzMROCaIZ8=; b=ZvY7LQteVK7e/FygM51R6DyBT7/o8N8FhUUPmCFusHJ8vAEmUeW/BjNacowHdOTFQa N2bnVnxP57e8V77DHTT8IBXIQEAMzW3xrwKhkPivKLCnLDPDHchp1GR5ahLTwnh91OoH 0eh5sbhT2vZn7wFkhEijHPh4shPtSwL62HknN+aJf32jW6zP08eNeol9+E7N1DA5TT16 WtwWoEkdIFmAhmg0wF4E6wBo2Q6gJ3IPIri+G0vvt3+L1svBAih/sq6nQTBLHVUsIvUG 9bh3ZYw6rFqGxwGgBz3W++49Yc4cHrUVoWeMAsoUjIRE5tcJgP9YBVH8Lbon5tMrwhAg s1tA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k2si590208ejx.546.2021.03.30.20.17.39; Tue, 30 Mar 2021 20:18:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-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-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233368AbhCaDNP (ORCPT + 99 others); Tue, 30 Mar 2021 23:13:15 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:14649 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233072AbhCaDNG (ORCPT ); Tue, 30 Mar 2021 23:13:06 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4F9BC46NcGzmc1x; Wed, 31 Mar 2021 11:10:24 +0800 (CST) Received: from [10.174.176.202] (10.174.176.202) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.498.0; Wed, 31 Mar 2021 11:12:59 +0800 Subject: Re: [PATCH] ext4: fix check to prevent false positive report of incorrect used inodes To: Jan Kara CC: , , References: <20210329061955.2437573-1-yi.zhang@huawei.com> <20210329142631.GC4283@quack2.suse.cz> From: Zhang Yi Message-ID: <5d6e4215-4d42-6621-1004-517caf3d3ebf@huawei.com> Date: Wed, 31 Mar 2021 11:12:58 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.3.1 MIME-Version: 1.0 In-Reply-To: <20210329142631.GC4283@quack2.suse.cz> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.176.202] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On 2021/3/29 22:26, Jan Kara wrote: > On Mon 29-03-21 14:19:55, Zhang Yi wrote: >> Commit <50122847007> ("ext4: fix check to prevent initializing reserved >> inodes") check the block group zero and prevent initializing reserved >> inodes. But in some special cases, the reserved inode may not all belong >> to the group zero, it may exist into the second group if we format >> filesystem below. >> >> mkfs.ext4 -b 4096 -g 8192 -N 1024 -I 4096 /dev/sda >> >> So, it will end up triggering a false positive report of a corrupted >> file system. This patch fix it by avoid check reserved inodes if no free >> inode blocks will be zeroed. >> >> Fixes: 50122847007 ("ext4: fix check to prevent initializing reserved inodes") >> Signed-off-by: Zhang Yi > > Thanks! The patch looks correct but maybe the code can be made more > comprehensible like I suggest below? > >> @@ -1543,22 +1544,25 @@ int ext4_init_inode_table(struct super_block *sb, ext4_group_t group, >> * used inodes so we need to skip blocks with used inodes in >> * inode table. >> */ >> - if (!(gdp->bg_flags & cpu_to_le16(EXT4_BG_INODE_UNINIT))) >> - used_blks = DIV_ROUND_UP((EXT4_INODES_PER_GROUP(sb) - >> - ext4_itable_unused_count(sb, gdp)), >> - sbi->s_inodes_per_block); >> - >> - if ((used_blks < 0) || (used_blks > sbi->s_itb_per_group) || >> - ((group == 0) && ((EXT4_INODES_PER_GROUP(sb) - >> - ext4_itable_unused_count(sb, gdp)) < >> - EXT4_FIRST_INO(sb)))) { >> - ext4_error(sb, "Something is wrong with group %u: " >> - "used itable blocks: %d; " >> - "itable unused count: %u", >> - group, used_blks, >> - ext4_itable_unused_count(sb, gdp)); >> - ret = 1; >> - goto err_out; >> + if (!(gdp->bg_flags & cpu_to_le16(EXT4_BG_INODE_UNINIT))) { >> + used_inos = EXT4_INODES_PER_GROUP(sb) - >> + ext4_itable_unused_count(sb, gdp); >> + used_blks = DIV_ROUND_UP(used_inos, sbi->s_inodes_per_block); >> + >> + if (used_blks >= 0 && used_blks <= sbi->s_itb_per_group) >> + used_inos += group * EXT4_INODES_PER_GROUP(sb); > > Maybe if would be more comprehensible like: > > /* Bogus inode unused count? */ > if (used_blks < 0 || used_blks > sbi->s_itb_per_group) { > ext4_error(...); > ret = 1; > goto err_out; > } > > used_inos += EXT4_INODES_PER_GROUP(sb); > /* > * Are there some uninitialized inodes in the inode table > * before the first normal inode? > */ > if (used_blks != sbi->s_itb_per_group && > used_inos < EXT4_FIRST_INO(sb)) { > ext4_error(...); > ret = 1; > goto err_out; > } Yes, it looks more comprehensible, I will send v2 as you suggested. Thanks, Yi.