From patchwork Tue Oct 10 19:36:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daeho Jeong X-Patchwork-Id: 13415939 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 3E2B5CD8CB4 for ; Tue, 10 Oct 2023 19:36:43 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-3.v29.lw.sourceforge.com) by sfs-ml-3.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1qqIX3-0004s1-GC; Tue, 10 Oct 2023 19:36:40 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-3.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1qqIX2-0004rv-Ff for linux-f2fs-devel@lists.sourceforge.net; Tue, 10 Oct 2023 19:36:39 +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: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:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=INY/SzLXsAM+QGsHgo0WCQKlaTJNpU+Xp7b/wSnGcRY=; b=LCOWU06BIvfmRlB5+aYeLzMzqE VueiqyYwBBWtewoYTJtDJNL3umNjhlf8gu6lFz6i54GINl+KZshdhumBi5ebAiN4VjvW0sP2u72MT KI/3Tb+/Jfy13p6dQ8SljqjTb58OR3F1G69raJ33rdwWB1tbmh/lYIfXFTXU6pmIebBY=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version: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:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=INY/SzLXsAM+QGsHgo0WCQKlaTJNpU+Xp7b/wSnGcRY=; b=k D3d7AX2FS/fRyLqLBSlJxr4WnsOM02bB87ULusQQLp2I/nfAswdoivDeSdx25r+K/evuWYNUhorFZ 2JRDQZ9pRTWMP74oL2Tv45M2i7t1Ai6kqEl7RgcNNwEhgyyCD1aOFrqTxa85gw86x+1TtG1nb0u1k zn2pNtW1beoYeI38=; Received: from mail-pl1-f172.google.com ([209.85.214.172]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.95) id 1qqIWy-0005Mn-U8 for linux-f2fs-devel@lists.sourceforge.net; Tue, 10 Oct 2023 19:36:38 +0000 Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-1c8a1541233so20883235ad.1 for ; Tue, 10 Oct 2023 12:36:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696966591; x=1697571391; darn=lists.sourceforge.net; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=INY/SzLXsAM+QGsHgo0WCQKlaTJNpU+Xp7b/wSnGcRY=; b=Im2DEkyvN5x+PVJVUQ6V/5DjevwJ9ND+BjrfZSSWC5KAq3/hLUB1QjC5vXRmv8rSbJ oOWR5G9I1zwpx9pM900lLHXo/V5rXcAgvc6NmLQPGv2SDVIToSbSlfdxtly2rkCqlnOj hxw8FpmyiX3R/DXWUcbGDyDlG/w/GvPa+xWqps/FIp6WPvIks3hluNtpURV7nrMge0pw Hc9+5Doehy/GarbOCH3xu4LKHUdpg0U9RmLso//K2MvkJNc7QQkZ2ckLZkP/HPV0OnN7 FNveHafAeoziGVCuCwMWhw1JdrUpZxFwrlnKSDQixsU9ktTFg8S+10hh3cx1yIfQJ5ov nBkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696966591; x=1697571391; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=INY/SzLXsAM+QGsHgo0WCQKlaTJNpU+Xp7b/wSnGcRY=; b=i1r579c7B7B4/JY7nnU88ebui62WSJbl72zl0Qkc7wIfnE5LkUKJs/nTAZBqUCVm7G /drTz53lfD9BNGUk0RcE/j8ovrjLLZqo+k/atBA3A+dtwtxyrutiHfIBF2ZpXSuGfv40 mAfGix5YjarayYldr550PiqZ/8enrcQudrzrRWrz3tJepc8+K9jdIfHcZbZ3BYg7HDM4 pas0UTa3DnriZXBDlH/gEUUV+EoYmUh+1+pz9CeHBhA5o7hX4g9afZTMAwG5rF51HHyL FRHsu90Ir6RhA1CtjXvDWjRsjMYivLGrp8iDTIJ+9cYAF0eTKmH3IvDTFJ+3bycOjLJa xY8Q== X-Gm-Message-State: AOJu0YyY9SxVKHsT7x9niv68E9aAS/w1218TFc2PKMDQ7JUGNbhYragl /qyrpJ3Efvc4uGbZwx3ewUf/F4u6qWo= X-Google-Smtp-Source: AGHT+IGy6D6GOlaIAhGMMOonaJooiC82u2oFSkvNb9FV19mJHBuMBfhfHgdV9Vw51g2lGIiNd+CZ6A== X-Received: by 2002:a17:903:22cb:b0:1c4:5e9e:7865 with SMTP id y11-20020a17090322cb00b001c45e9e7865mr19584082plg.0.1696966591381; Tue, 10 Oct 2023 12:36:31 -0700 (PDT) Received: from daehojeong-desktop.mtv.corp.google.com ([2620:15c:211:201:b6de:85b9:6077:28b4]) by smtp.gmail.com with ESMTPSA id d20-20020a170902c19400b001b890009634sm12142703pld.139.2023.10.10.12.36.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 12:36:31 -0700 (PDT) From: Daeho Jeong To: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, kernel-team@android.com Date: Tue, 10 Oct 2023 12:36:28 -0700 Message-ID: <20231010193628.2629168-1-daeho43@gmail.com> X-Mailer: git-send-email 2.42.0.609.gbb76f46606-goog MIME-Version: 1.0 X-Headers-End: 1qqIWy-0005Mn-U8 Subject: [f2fs-dev] [PATCH] f2fs: clean up zones when not successfully unmounted 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: Daeho Jeong Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net From: Daeho Jeong We can't trust write pointers when the previous mount was not successfully unmounted. Signed-off-by: Daeho Jeong Reviewed-by: Chao Yu --- fs/f2fs/segment.c | 92 ++++++++++++++++++++++++++++------------------- 1 file changed, 56 insertions(+), 36 deletions(-) diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index d05b41608fc0..727d016318f9 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -4910,22 +4910,31 @@ static int check_zone_write_pointer(struct f2fs_sb_info *sbi, } /* - * The write pointer matches with the valid blocks or - * already points to the end of the zone. + * When safely unmounted in the previous mount, we can trust write + * pointers. Otherwise, finish zones. */ - if ((last_valid_block + 1 == wp_block) || - (zone->wp == zone->start + zone->len)) - return 0; - - if (last_valid_block + 1 == zone_block) { + if (is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG)) { /* - * If there is no valid block in the zone and if write pointer - * is not at zone start, reset the write pointer. + * The write pointer matches with the valid blocks or + * already points to the end of the zone. */ - f2fs_notice(sbi, - "Zone without valid block has non-zero write " - "pointer. Reset the write pointer: wp[0x%x,0x%x]", - wp_segno, wp_blkoff); + if ((last_valid_block + 1 == wp_block) || + (zone->wp == zone->start + zone->len)) + return 0; + } + + if (last_valid_block + 1 == zone_block) { + if (is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG)) { + /* + * If there is no valid block in the zone and if write + * pointer is not at zone start, reset the write + * pointer. + */ + f2fs_notice(sbi, + "Zone without valid block has non-zero write " + "pointer. Reset the write pointer: wp[0x%x,0x%x]", + wp_segno, wp_blkoff); + } ret = __f2fs_issue_discard_zone(sbi, fdev->bdev, zone_block, zone->len >> log_sectors_per_block); if (ret) @@ -4935,18 +4944,20 @@ static int check_zone_write_pointer(struct f2fs_sb_info *sbi, return ret; } - /* - * If there are valid blocks and the write pointer doesn't - * match with them, we need to report the inconsistency and - * fill the zone till the end to close the zone. This inconsistency - * does not cause write error because the zone will not be selected - * for write operation until it get discarded. - */ - f2fs_notice(sbi, "Valid blocks are not aligned with write pointer: " - "valid block[0x%x,0x%x] wp[0x%x,0x%x]", - GET_SEGNO(sbi, last_valid_block), - GET_BLKOFF_FROM_SEG0(sbi, last_valid_block), - wp_segno, wp_blkoff); + if (is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG)) { + /* + * If there are valid blocks and the write pointer doesn't match + * with them, we need to report the inconsistency and fill + * the zone till the end to close the zone. This inconsistency + * does not cause write error because the zone will not be + * selected for write operation until it get discarded. + */ + f2fs_notice(sbi, "Valid blocks are not aligned with write " + "pointer: valid block[0x%x,0x%x] wp[0x%x,0x%x]", + GET_SEGNO(sbi, last_valid_block), + GET_BLKOFF_FROM_SEG0(sbi, last_valid_block), + wp_segno, wp_blkoff); + } ret = blkdev_zone_mgmt(fdev->bdev, REQ_OP_ZONE_FINISH, zone->start, zone->len, GFP_NOFS); @@ -5020,18 +5031,27 @@ static int fix_curseg_write_pointer(struct f2fs_sb_info *sbi, int type) if (zone.type != BLK_ZONE_TYPE_SEQWRITE_REQ) return 0; - wp_block = zbd->start_blk + (zone.wp >> log_sectors_per_block); - wp_segno = GET_SEGNO(sbi, wp_block); - wp_blkoff = wp_block - START_BLOCK(sbi, wp_segno); - wp_sector_off = zone.wp & GENMASK(log_sectors_per_block - 1, 0); - - if (cs->segno == wp_segno && cs->next_blkoff == wp_blkoff && - wp_sector_off == 0) - return 0; + /* + * When safely unmounted in the previous mount, we could use current + * segments. Otherwise, allocate new sections. + */ + if (is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG)) { + wp_block = zbd->start_blk + (zone.wp >> log_sectors_per_block); + wp_segno = GET_SEGNO(sbi, wp_block); + wp_blkoff = wp_block - START_BLOCK(sbi, wp_segno); + wp_sector_off = zone.wp & GENMASK(log_sectors_per_block - 1, 0); + + if (cs->segno == wp_segno && cs->next_blkoff == wp_blkoff && + wp_sector_off == 0) + return 0; - f2fs_notice(sbi, "Unaligned curseg[%d] with write pointer: " - "curseg[0x%x,0x%x] wp[0x%x,0x%x]", - type, cs->segno, cs->next_blkoff, wp_segno, wp_blkoff); + f2fs_notice(sbi, "Unaligned curseg[%d] with write pointer: " + "curseg[0x%x,0x%x] wp[0x%x,0x%x]", type, cs->segno, + cs->next_blkoff, wp_segno, wp_blkoff); + } else { + f2fs_notice(sbi, "Not successfully unmounted in the previous " + "mount"); + } f2fs_notice(sbi, "Assign new section to curseg[%d]: " "curseg[0x%x,0x%x]", type, cs->segno, cs->next_blkoff);