Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2415079pxb; Tue, 13 Apr 2021 01:01:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyUHaNU3qe3URVyCYqstvYHRBCxelyVxSQGXpDmbdGEf3oUnQHWV8wXvWB/UNZTs/zBwmpN X-Received: by 2002:a17:906:86d0:: with SMTP id j16mr2857842ejy.444.1618300869262; Tue, 13 Apr 2021 01:01:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618300869; cv=none; d=google.com; s=arc-20160816; b=Mb2SLH2zdlW9MzeFbZkmYMMxlwnBPm96/Yd0KTMTgjaYCdxhR7R2YmVqJZ4hgyGXy8 iyrYLmZp9BwSaoX6cZMqT9GMb92PHle80P51ekFDE23JvYRlht8fUmrO9YkhUHAoLLLW Sl2dBPDud0/hxGliuUhmavMlH8MZ0+uRV+LFgOlnzrRGijOm/KDWRuaGEFDVGg+v/YLF gb6+rWhE0aqKWGIRjqFxBs55e+fvsJUln4ilCPv1XEHfk78N4+m0wCmKGJ8iK3c3EuA9 zLoPQKIR5pnF+XNxS10ajzs/kyztk7AqTAqk5Of9TxnePCjR4Yj0GfGUWWgiNsYHpyd4 kn/w== 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 :user-agent:date:message-id:cc:to:subject:from; bh=xrs4ZLXkdM6FX1BvpiR8i+JXq326d0Q9L31mbm1orGc=; b=rZ/zdZx88WEZl2xSDDQDnI9xOtFTx8w6Xi4T5846Pc3324VuoDaPGfIOuZzlzMBLkC pbOChmNQL7SgsAjz2DVZIoBS//mgSRspPZvvaE/GyhbjJ3Q1/a3zwTpdMm/Q5FThhWzQ ArTCtzBFl17HcFR1ST2fL1lbSuIDuHJzx/Sd7pgC65spPay0jEGkjcNvzrX5Ln5amTI8 hCobxVgIVok4j95U40Nod2wHMv2h8SqLUMYWSDAxX0NseA5zdt8cBSSYrGsYBgwG4dsR 3sUqEX9/PuhZMLHGJeSN3EfmqkbV+uLdkVM0hlthffv7ZBDSBdEyNPxM64VMFFrppPWa fjug== 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 h28si10169391edj.546.2021.04.13.01.00.42; Tue, 13 Apr 2021 01:01:09 -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 S237806AbhDMDT4 (ORCPT + 99 others); Mon, 12 Apr 2021 23:19:56 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:16579 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237789AbhDMDT4 (ORCPT ); Mon, 12 Apr 2021 23:19:56 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4FK9l43DmPz18Hqb; Tue, 13 Apr 2021 11:17:20 +0800 (CST) Received: from [10.174.177.93] (10.174.177.93) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.498.0; Tue, 13 Apr 2021 11:19:30 +0800 From: Haotian Li Subject: [PATCH] e2fsck: try write_primary_superblock() again when it failed To: Ext4 Developers List CC: "Theodore Y. Ts'o" , "liuzhiqiang (I)" , linfeilong Message-ID: <7486f08c-7f14-9fac-fdb2-0fe78a799d90@huawei.com> Date: Tue, 13 Apr 2021 11:19:30 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.1.0 MIME-Version: 1.0 Content-Type: text/plain; charset="gbk" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.177.93] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Function write_primary_superblock() has two ways to flush superblock, byte-by-byte as default. It may use io_channel_write_byte() many times. If some errors occur during these funcs, the superblock may become inconsistent and produce checksum error. Try write_primary_superblock() with whole-block way again when it failed on byte-by-byte way. --- lib/ext2fs/closefs.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/ext2fs/closefs.c b/lib/ext2fs/closefs.c index 69cbdd8c..1fc27fb5 100644 --- a/lib/ext2fs/closefs.c +++ b/lib/ext2fs/closefs.c @@ -223,10 +223,8 @@ static errcode_t write_primary_superblock(ext2_filsys fs, retval = io_channel_write_byte(fs->io, SUPERBLOCK_OFFSET + (2 * write_idx), size, new_super + write_idx); - if (retval == EXT2_ET_UNIMPLEMENTED) - goto fallback; if (retval) - return retval; + goto fallback; } memcpy(fs->orig_super, super, SUPERBLOCK_SIZE); return 0; -- 2.23.0