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=-12.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 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 13BC0C4338F for ; Wed, 11 Aug 2021 07:28:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DB30760FC0 for ; Wed, 11 Aug 2021 07:28:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234043AbhHKH2k (ORCPT ); Wed, 11 Aug 2021 03:28:40 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:45668 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233460AbhHKH2j (ORCPT ); Wed, 11 Aug 2021 03:28:39 -0400 Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 924892215E; Wed, 11 Aug 2021 07:28:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1628666895; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1wdt+0e5paIYKlRjMgAw02oS6jidsgEXrd4hYDkw7kY=; b=iwq8Tu3hV5NgZ4AOxfGHU7/6PAY4GUE1BeL9wm89Q/i/BO2LokJdGzWt6a2xglukyBrHkj y783gLlEVGaSrWDUeJ0AZRFTcOwDVOXJ6/Nc/+yl3mhwoVH9Sa+jxhjjhQ2V+cBtCVKoYx GMoXlePQYuQpgpjcs9OpE1a0sh2rxNs= Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap1.suse-dmz.suse.de (Postfix) with ESMTPS id 46672136D9; Wed, 11 Aug 2021 07:28:15 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap1.suse-dmz.suse.de with ESMTPSA id kOrlDQ98E2HCYAAAGKfGzw (envelope-from ); Wed, 11 Aug 2021 07:28:15 +0000 Subject: Re: [PATCH] btrfs-progs: map-logical: handle corrupted fs better To: Qu Wenruo , Qu Wenruo , linux-btrfs@vger.kernel.org References: <20210810235445.44567-1-wqu@suse.com> <40072166-1fa6-33f0-ebad-b47e4c08b633@gmx.com> From: Nikolay Borisov Message-ID: <26765bca-a9de-af53-2d9e-d1131de4d801@suse.com> Date: Wed, 11 Aug 2021 10:28:14 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <40072166-1fa6-33f0-ebad-b47e4c08b633@gmx.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org On 11.08.21 г. 10:17, Qu Wenruo wrote: > > > On 2021/8/11 下午3:03, Nikolay Borisov wrote: >> >> >> On 11.08.21 г. 2:54, Qu Wenruo wrote: >>> Currently if running btrfs-map-logical on a filesystem with corrupted >>> extent tree, it will fail due to open_ctree() error. >>> >>> But the truth is, btrfs-map-logical only requires chunk tree to do >>> logical bytenr mapping. >>> >>> Make btrfs-map-logical more robust by: >>> >>> - Loosen the open_ctree() requirement >>>    Now it doesn't require an extent tree to work. >>> >>> - Don't return error for map_one_extent() >>>    Function map_one_extent() is too lookup extent tree to ensure >>> there is >>>    at least one extent for the range we're looking for. >>> >>>    But since now we don't require extent tree at all, there is no hard >>>    requirement for that function. >>>    Thus here we change it to return void, and only do the check when >>>    possible. >>> >>> Now btrfs-map-logical can work on a filesystem with corrupted extent >>> tree. >>> >>> Signed-off-by: Qu Wenruo >>> --- >> >> >> Furthermore with map_one_extent present the semantics of the program is >> that it prints the logical mapping of the real extent rather then the >> passed in bytes. Because the user is allowed to pass an offset for which >> there isn't a real extent. So if we want to retain this your change is a >> no-go. > > The change just makes the extent item lookup an optional operation. > > If by somehow we failed to lookup the extent item, we just continue with > the values passed-in, no longer to verify whether there is an extent. > > This is especially important for fs with corrupted extent tree. > >> OTOH if we want to have btrfs_map_logical to serve as a simple >> calculation aid i.e you pass in some logical byte, irrespective whether >> it contains a real extent or not, and have the program return what the >> physical mapping is then map_one_extent becomes redundant altogether. > > Yeah, I was also thinking about that, but not sure if we should > completely remove map_one_extent(). > > Thus I took the middle land by rendering it optional. IMO the middle ground would be to add a command line switch i.e force which would ignore map_one_extent. In such exceptional cases a user with a problem could be instructed to run the command with an '-f' switch for example. The rest of the time the program would preserve its old logic which guarantees returning mapping for real extents. > > But if that's the way to go, I can't be more happier as that greatly > simplify the workflow of btrfs-map-logical. > > Thanks, > Qu > >> >> >> >