From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62218CA9EBC for ; Mon, 28 Oct 2019 06:55:44 +0000 (UTC) Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3585920873; Mon, 28 Oct 2019 06:55:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=sourceforge.net header.i=@sourceforge.net header.b="GZORnKQO"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=sf.net header.i=@sf.net header.b="FShnXzuH"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="X3gRSYGy" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3585920873 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linux-f2fs-devel-bounces@lists.sourceforge.net Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1iOywJ-000447-RG; Mon, 28 Oct 2019 06:55:43 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1iOywI-00043x-I5 for linux-f2fs-devel@lists.sourceforge.net; Mon, 28 Oct 2019 06:55:42 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=qrIdwLK97Y7D2CiR8DcFv9F3PakptFnEcHp8s+1O4dk=; b=GZORnKQO/1ZPmxRSDgBD41diMT h+l093wtCaQVhmzBzne2vsm6qm8HUZmvJfI7608hybjFBjhtPn9AUZvu1pjkS5NeegMz/vj8h6MZj 3H87ZIZ6IGwZCFMMWhgUmfgZ31nsZRNv1exuV1p7fbHGAt4tiOBc3KVy9qD2wU52Zrdk=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=qrIdwLK97Y7D2CiR8DcFv9F3PakptFnEcHp8s+1O4dk=; b=FShnXzuHbbqJ6gKUdPvAB316ig T6OgaGkobNYzSl6j+2+f/sM4IWJ0G0cr+dvom6X3dIz0gMoSaJZxKyc3B9EdMGrBNwWUU6weYFm6+ uyFqgTO0Oz/iJxhY0wCWf0a+NNvOmHgkqTralfmbJ0U5oxzZ+tgLXiiSS7uH6C8Fied0=; Received: from esa3.hgst.iphmx.com ([216.71.153.141]) by sfi-mx-4.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.2) id 1iOywF-0067BT-4u for linux-f2fs-devel@lists.sourceforge.net; Mon, 28 Oct 2019 06:55:42 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1572245740; x=1603781740; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/Mywkvn8jA36sjb3tpXF3lTLYLwnaruRY3VzYO+Dp4A=; b=X3gRSYGylwKke5cyfLg3DAju9pIiQMnK3cgTW8G7oudRdPtahT8HdKz5 iUoC68XSC8iQbZ0LD4n5x6vV1g/skcvnhtgJOBJm56EOemMiq7lLmuW/7 GpqxNqObnwqbEHj9lLetMT8rSpZ0B4ITLgsde1VykKr7zMzV5en2ZIxih /Rhuo/sZNrdxfFJUJ+CNwVNxfVCPC16KagcFVvYqGxPrO7Ek/7EeG8Qtz BrVnaDHvwEVcxk7gF5pjfryLqxzmyva4VpAH+gBTSEpDHfWZJWeGIscO0 p6XD5EoTYNwsZcgRqgoZH2NLAS5GmluVKulfgJSB1UMgqvWOMnRe1KkUb w==; IronPort-SDR: TdRW7VxoQw+midH/9dzmHEmbEncZYE14r5fj8fKB2Cghs1wzHOcsToq/eFzooUoEFYMmsJ88Kb XM5Me+uv6TVpG7P6/NlknBqTZdeiZIZAU29SZOQw2uX1mAENTSdpQneDjxQ+k8InR/Q3chFIFJ odGZJerz2k4zhfrKnmdVYw98MTTAJxGBmkI4yqebEqkxJpOIoRmN7K0ugGGMzTxrrZwAB8zNio H1fBdMN4EXp3Yj+DNkotUQ3rWqqeaEZ9+z+mdLDBxqCVezoY50oW16oVC5QDtePAO6FqhRr9Pu 6+s= X-IronPort-AV: E=Sophos;i="5.68,239,1569254400"; d="scan'208";a="125879640" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 28 Oct 2019 14:55:28 +0800 IronPort-SDR: v0D7C5g2XmPHqVrrXFIjqXErcdDdMB/JmOzY6muY6/kdrsHBQxnuUTdVkTMZdLfcmUN2BwkUnk l4p+VemIcZpcNADK7Zau3NckGCW5jrzjKo8FX+FmR3J3s7WyWl9uU3QaorSIqfH0Lr8MlyQeOl e/TyQ8OmG8dE6inVOjwsJ9qlfvEe/Uonp73Ap1QGuk3qa6BkEcneodWdr4BLwjsflkvVEVNT5H su4RauDtPrswB4EqkHXAVFYhS9Yghvg2hJVa37Ph7QYvSsN7pEh+a8jyqzTjj7UztV8eXlG9T/ 0+SuKS+HgxGkME0EF0asHw+I Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Oct 2019 23:50:49 -0700 IronPort-SDR: xi1n9X/v1bCORQNpBssAHJxxPPl75kO046dgOT4Ok5DchSnQ1E/otKnmzcqKH+Oy05kIQXyU6T 7qVZUjGTEIjKC+wMD2vsNM7ZnkdMtZRTq2KKn4KTkXUzNTqmro2/wB3Je5f0yoxSgMmkIyhoRJ iDcsqQreP7+/A6Z2xJMe7M92WcLFA+3G15LKi42PnuBt9T8Jj32AWaI8Jf30ZsGDgLu5sDNrXP gC5DiSkSp4PJksF0udz2wuVo1vMsM9urgnYoyxPB2UDcgr680l4TWdTqd0KAsEPEhEHy2A1qLq qXs= WDCIronportException: Internal Received: from shindev.dhcp.fujisawa.hgst.com (HELO shindev.fujisawa.hgst.com) ([10.149.52.166]) by uls-op-cesaip01.wdc.com with ESMTP; 27 Oct 2019 23:55:27 -0700 From: Shin'ichiro Kawasaki To: Jaegeuk Kim , Chao Yu , linux-f2fs-devel@lists.sourceforge.net Date: Mon, 28 Oct 2019 15:55:12 +0900 Message-Id: <20191028065512.27876-9-shinichiro.kawasaki@wdc.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191028065512.27876-1-shinichiro.kawasaki@wdc.com> References: <20191028065512.27876-1-shinichiro.kawasaki@wdc.com> MIME-Version: 1.0 X-Headers-End: 1iOywF-0067BT-4u Subject: [f2fs-dev] [PATCH v6 8/8] fsck: Check write pointer consistency of non-open zones X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Damien Le Moal Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net To catch f2fs bug in write pointer handling code for zoned block devices, have fsck check consistency of write pointers of non-open zones, that current segments do not point to. Check two items comparing write pointer positions with valid block maps in SIT. The first item is check for zones with no valid blocks. When there is no valid blocks in a zone, the write pointer should be at the start of the zone. If not, next write operation to the zone will cause unaligned write error. If write pointer is not at the zone start, reset the zone to move the write pointer to the zone start. The second item is check between write pointer position and the last valid block in the zone. It is unexpected that the last valid block position is beyond the write pointer. In such a case, report as the bug. Fix is not required for such zone, because the zone is not selected for next write operation until the zone get discarded. In the same manner as the consistency check for current segments, do the check and fix twice: at the beginning of do_fsck() to avoid unaligned write error during fsck, and at fsck_verify() to reflect meta data updates by fsck. Signed-off-by: Shin'ichiro Kawasaki --- fsck/fsck.c | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) diff --git a/fsck/fsck.c b/fsck/fsck.c index e0eda4e..8400929 100644 --- a/fsck/fsck.c +++ b/fsck/fsck.c @@ -2751,6 +2751,122 @@ out: return cnt; } +#ifdef HAVE_LINUX_BLKZONED_H + +struct write_pointer_check_data { + struct f2fs_sb_info *sbi; + int dev_index; +}; + +static int chk_and_fix_wp_with_sit(int i, void *blkzone, void *opaque) +{ + struct blk_zone *blkz = (struct blk_zone *)blkzone; + struct write_pointer_check_data *wpd = opaque; + struct f2fs_sb_info *sbi = wpd->sbi; + struct device_info *dev = c.devices + wpd->dev_index; + struct f2fs_fsck *fsck = F2FS_FSCK(sbi); + block_t zone_block, wp_block, wp_blkoff; + unsigned int zone_segno, wp_segno; + struct curseg_info *cs; + int cs_index, ret, last_valid_blkoff; + int log_sectors_per_block = sbi->log_blocksize - SECTOR_SHIFT; + unsigned int segs_per_zone = sbi->segs_per_sec * sbi->secs_per_zone; + + if (blk_zone_conv(blkz)) + return 0; + + zone_block = dev->start_blkaddr + + (blk_zone_sector(blkz) >> log_sectors_per_block); + zone_segno = GET_SEGNO(sbi, zone_block); + if (zone_segno >= MAIN_SEGS(sbi)) + return 0; + + wp_block = dev->start_blkaddr + + (blk_zone_wp_sector(blkz) >> log_sectors_per_block); + wp_segno = GET_SEGNO(sbi, wp_block); + wp_blkoff = wp_block - START_BLOCK(sbi, wp_segno); + + /* if a curseg points to the zone, skip the check */ + for (cs_index = 0; cs_index < NO_CHECK_TYPE; cs_index++) { + cs = &SM_I(sbi)->curseg_array[cs_index]; + if (zone_segno <= cs->segno && + cs->segno < zone_segno + segs_per_zone) + return 0; + } + + last_valid_blkoff = last_vblk_off_in_zone(sbi, zone_segno); + + /* + * When there is no valid block in the zone, check write pointer is + * at zone start. If not, reset the write pointer. + */ + if (last_valid_blkoff < 0 && + blk_zone_wp_sector(blkz) != blk_zone_sector(blkz)) { + if (!c.fix_on) { + MSG(0, "Inconsistent write pointer: wp[0x%x,0x%x]\n", + wp_segno, wp_blkoff); + fsck->chk.wp_inconsistent_zones++; + return 0; + } + + FIX_MSG("Reset write pointer of zone at segment 0x%x", + zone_segno); + ret = f2fs_reset_zone(wpd->dev_index, blkz); + if (ret) { + printf("[FSCK] Write pointer reset failed: %s\n", + dev->path); + return ret; + } + fsck->chk.wp_fixed = 1; + return 0; + } + + /* + * If valid blocks exist in the zone beyond the write pointer, it + * is a f2fs bug. No need to fix because the zone is not selected + * for the write. Just report it. + */ + if (last_valid_blkoff + zone_block > wp_block) { + MSG(0, "Unexpected invalid write pointer: wp[0x%x,0x%x]\n", + wp_segno, wp_blkoff); + return 0; + } + + return 0; +} + +static void fix_wp_sit_alignment(struct f2fs_sb_info *sbi) +{ + unsigned int i; + struct write_pointer_check_data wpd = { sbi, 0 }; + + if (c.zoned_model != F2FS_ZONED_HM) + return; + + for (i = 0; i < MAX_DEVICES; i++) { + if (!c.devices[i].path) + break; + if (c.devices[i].zoned_model != F2FS_ZONED_HM) + break; + + wpd.dev_index = i; + if (f2fs_report_zones(i, chk_and_fix_wp_with_sit, &wpd)) { + printf("[FSCK] Write pointer check failed: %s\n", + c.devices[i].path); + return; + } + } +} + +#else + +static void fix_wp_sit_alignment(struct f2fs_sb_info *sbi) +{ + return; +} + +#endif + /* * Check and fix consistency with write pointers at the beginning of * fsck so that following writes by fsck do not fail. @@ -2766,6 +2882,8 @@ void fsck_chk_and_fix_write_pointers(struct f2fs_sb_info *sbi) fix_curseg_info(sbi); fsck->chk.wp_fixed = 1; } + + fix_wp_sit_alignment(sbi); } int fsck_chk_curseg_info(struct f2fs_sb_info *sbi) @@ -2984,6 +3102,7 @@ int fsck_verify(struct f2fs_sb_info *sbi) fix_hard_links(sbi); fix_nat_entries(sbi); rewrite_sit_area_bitmap(sbi); + fix_wp_sit_alignment(sbi); fix_curseg_info(sbi); fix_checksum(sbi); fix_checkpoints(sbi); -- 2.21.0 _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel