From patchwork Tue Feb 9 17:34:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 12078669 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, 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 C8192C433DB for ; Tue, 9 Feb 2021 17:36:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8BD6064E15 for ; Tue, 9 Feb 2021 17:36:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233276AbhBIRgl (ORCPT ); Tue, 9 Feb 2021 12:36:41 -0500 Received: from mail.nic.cz ([217.31.204.67]:34870 "EHLO mail.nic.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232938AbhBIRfJ (ORCPT ); Tue, 9 Feb 2021 12:35:09 -0500 Received: from dellmb.labs.office.nic.cz (unknown [IPv6:2001:1488:fffe:6:8982:ed8c:62b1:c0c8]) by mail.nic.cz (Postfix) with ESMTPSA id 80FD413FD0E; Tue, 9 Feb 2021 18:34:23 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nic.cz; s=default; t=1612892063; bh=EBMx+zpY74gnPIYMRVud8JLa1FxIsNwqSbrosdN1yH0=; h=From:To:Date; b=lsG7ifGg2tm2PJos9YY6D/nDjT0qr2ZEZtFz02ZjPFlTYCvYrPRCKqK7oGO6/hdp8 Q7YINoMPLgYl0eIt4Ouq5uDDqLM+PhTKvU1tEP8WrM8xFpnGsxWlJhfq/vssFmdGfe p4ScNsQMckdbthgfvIx+qvV9o1zjQz7a0GeTbS4Y= From: =?utf-8?q?Marek_Beh=C3=BAn?= To: linux-btrfs@vger.kernel.org Cc: u-boot@lists.denx.de, =?utf-8?q?Marek_Beh=C3=BAn?= , David Sterba , Qu Wenruo , Tom Rini Subject: [PATCH btrfs-progs] btrfs-progs: do not fail when offset of a ROOT_ITEM is not -1 Date: Tue, 9 Feb 2021 18:34:06 +0100 Message-Id: <20210209173406.16691-1-marek.behun@nic.cz> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.2 at mail X-Virus-Status: Clean Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org When the btrfs_read_fs_root() function is searching a ROOT_ITEM with location key offset other than -1, it currently fails via BUG_ON. The offset can have other value than -1, though. This can happen for example if a subvolume is renamed: $ btrfs subvolume create X && sync Create subvolume './X' $ btrfs inspect-internal dump-tree /dev/root | grep -B 2 'name: X$ location key (270 ROOT_ITEM 18446744073709551615) type DIR transid 283 data_len 0 name_len 1 name: X $ mv X Y && sync $ btrfs inspect-internal dump-tree /dev/root | grep -B 2 'name: Y$ location key (270 ROOT_ITEM 0) type DIR transid 285 data_len 0 name_len 1 name: Y As can be seen the offset changed from -1ULL to 0. Do not fail in this case. Signed-off-by: Marek BehĂșn Cc: David Sterba Cc: Qu Wenruo Cc: Tom Rini --- kernel-shared/disk-io.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/kernel-shared/disk-io.c b/kernel-shared/disk-io.c index 6f584986..ba8ffd8b 100644 --- a/kernel-shared/disk-io.c +++ b/kernel-shared/disk-io.c @@ -752,8 +752,7 @@ struct btrfs_root *btrfs_read_fs_root(struct btrfs_fs_info *fs_info, return fs_info->free_space_root ? fs_info->free_space_root : ERR_PTR(-ENOENT); - BUG_ON(location->objectid == BTRFS_TREE_RELOC_OBJECTID || - location->offset != (u64)-1); + BUG_ON(location->objectid == BTRFS_TREE_RELOC_OBJECTID); node = rb_search(&fs_info->fs_root_tree, (void *)&objectid, btrfs_fs_roots_compare_objectids, NULL);