From patchwork Tue May 23 08:40:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13251874 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EE356C7EE23 for ; Tue, 23 May 2023 08:41:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236116AbjEWIly (ORCPT ); Tue, 23 May 2023 04:41:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236077AbjEWIlX (ORCPT ); Tue, 23 May 2023 04:41:23 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DAE4DE49 for ; Tue, 23 May 2023 01:40:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:In-Reply-To:References; bh=vUSIzPyibNrbKOA/j+6+lrk3QbtfAB5OHum8ukhPqWA=; b=dDgxwNzNW6xrZ7QnHY/IU5o40b 2PNsWdU1E56CDsw+nYD0f86bS7o5OLg3lMJGKWIPlgmS2O2OzwzTihRh+wVtPHlK0bXxBCh8FL8TF B50a6C8w3v28IP9cnnykbbikXHbSEk8RkW2eXxtA3tN7Hh+RUtjzMVoAisQeuvoCX1FWpIJQPVZIP ZREfZJK5RDxbi7pVbuvR+m3YpnKootDjd7Tc2ES4eXsmTTXWgUrO1hX+Uu2ZO/Na+kkXPcH3POu60 h3DhUcWTDkPgAGilcMdfcUIliAKYzt4rfKO8C3/r0sqqo1pQNgIXsVLtSdZn4qtWi27IGKbsmNJvY 6QsuhtQQ==; Received: from [2001:4bb8:188:23b2:6ade:85c9:530f:6eb0] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1q1NZ8-009TZ1-2s; Tue, 23 May 2023 08:40:23 +0000 From: Christoph Hellwig To: clm@fb.com, josef@toxicpanda.com, dsterba@suse.com Cc: linux-btrfs@vger.kernel.org Subject: [PATCH 1/3] btrfs: fix the btrfs_get_global_root return value Date: Tue, 23 May 2023 10:40:18 +0200 Message-Id: <20230523084020.336697-1-hch@lst.de> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org btrfs_grab_root returns either the root or NULL, and the callers of btrfs_get_global_root expect it to return the same. But all the more recently added roots instead return an ERR_PTR, so fix this. Fixes: bcef60f24903 ("Btrfs: quota tree support and startup") Fixes: f7a81ea4cc6b ("Btrfs: create UUID tree if required") Fixes: 70f6d82ec73c ("Btrfs: add free space tree mount option") Fixes: 14033b08a029 ("btrfs: don't save block group root into super block") Signed-off-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn --- fs/btrfs/disk-io.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index dc2ad0bf88f84c..5dc5d733ecfa4a 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -1358,19 +1358,13 @@ static struct btrfs_root *btrfs_get_global_root(struct btrfs_fs_info *fs_info, if (objectid == BTRFS_CSUM_TREE_OBJECTID) return btrfs_grab_root(btrfs_global_root(fs_info, &key)); if (objectid == BTRFS_QUOTA_TREE_OBJECTID) - return btrfs_grab_root(fs_info->quota_root) ? - fs_info->quota_root : ERR_PTR(-ENOENT); + return btrfs_grab_root(fs_info->quota_root); if (objectid == BTRFS_UUID_TREE_OBJECTID) - return btrfs_grab_root(fs_info->uuid_root) ? - fs_info->uuid_root : ERR_PTR(-ENOENT); + return btrfs_grab_root(fs_info->uuid_root); if (objectid == BTRFS_BLOCK_GROUP_TREE_OBJECTID) - return btrfs_grab_root(fs_info->block_group_root) ? - fs_info->block_group_root : ERR_PTR(-ENOENT); - if (objectid == BTRFS_FREE_SPACE_TREE_OBJECTID) { - struct btrfs_root *root = btrfs_global_root(fs_info, &key); - - return btrfs_grab_root(root) ? root : ERR_PTR(-ENOENT); - } + return btrfs_grab_root(fs_info->block_group_root); + if (objectid == BTRFS_FREE_SPACE_TREE_OBJECTID) + return btrfs_grab_root(btrfs_global_root(fs_info, &key)); return NULL; } From patchwork Tue May 23 08:40:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13251875 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F18EEC7EE26 for ; Tue, 23 May 2023 08:41:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236258AbjEWIlz (ORCPT ); Tue, 23 May 2023 04:41:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236110AbjEWIlY (ORCPT ); Tue, 23 May 2023 04:41:24 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BBEBBE4C for ; Tue, 23 May 2023 01:40:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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; bh=o9KSxMeE48qQapgk8Q6zc11hw6uYlGdJ7DIF4C3Jkxg=; b=BGQCMBrkNYfDwSmOFYeW4yvaDr P4zjwWjwRXSLJ97jzQ71GjWcwRdwQ2WqlUBi0/hontATRuMxSIBnuc31hfByECLLItNyxbaMSotek 5rIjIxKczUk5CePGlILZGb0oEqgG1x1Z9uMaOZgtZAemx4jsRhkbc7DepANx96Qp9chm1Fsg/oWH2 ZvivXVPeYUe8ZS/0JmZDRXE7OUiJ+pCZ81ZOsQRxGKLRKqcCVKxkih1B8uoF9TMmF/pbUp8JgRCFW O+fDwTybfxKnKbvTQZ7b1vktcxowIbz3ufbMBiBxJKsSxCfwUwSQr/PYzxD5e9HulBbcaLKrl53oa s3mDocnw==; Received: from [2001:4bb8:188:23b2:6ade:85c9:530f:6eb0] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1q1NZB-009TZH-1W; Tue, 23 May 2023 08:40:25 +0000 From: Christoph Hellwig To: clm@fb.com, josef@toxicpanda.com, dsterba@suse.com Cc: linux-btrfs@vger.kernel.org Subject: [PATCH 2/3] btrfs: convert btrfs_get_global_root to use a switch statement Date: Tue, 23 May 2023 10:40:19 +0200 Message-Id: <20230523084020.336697-2-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230523084020.336697-1-hch@lst.de> References: <20230523084020.336697-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Use a switch statement instead of an endless chain of if statements to make the code a little cleaner. Signed-off-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn --- fs/btrfs/disk-io.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 5dc5d733ecfa4a..1edd6685df5760 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -1347,25 +1347,28 @@ static struct btrfs_root *btrfs_get_global_root(struct btrfs_fs_info *fs_info, .offset = 0, }; - if (objectid == BTRFS_ROOT_TREE_OBJECTID) + switch (objectid) { + case BTRFS_ROOT_TREE_OBJECTID: return btrfs_grab_root(fs_info->tree_root); - if (objectid == BTRFS_EXTENT_TREE_OBJECTID) + case BTRFS_EXTENT_TREE_OBJECTID: return btrfs_grab_root(btrfs_global_root(fs_info, &key)); - if (objectid == BTRFS_CHUNK_TREE_OBJECTID) + case BTRFS_CHUNK_TREE_OBJECTID: return btrfs_grab_root(fs_info->chunk_root); - if (objectid == BTRFS_DEV_TREE_OBJECTID) + case BTRFS_DEV_TREE_OBJECTID: return btrfs_grab_root(fs_info->dev_root); - if (objectid == BTRFS_CSUM_TREE_OBJECTID) + case BTRFS_CSUM_TREE_OBJECTID: return btrfs_grab_root(btrfs_global_root(fs_info, &key)); - if (objectid == BTRFS_QUOTA_TREE_OBJECTID) + case BTRFS_QUOTA_TREE_OBJECTID: return btrfs_grab_root(fs_info->quota_root); - if (objectid == BTRFS_UUID_TREE_OBJECTID) + case BTRFS_UUID_TREE_OBJECTID: return btrfs_grab_root(fs_info->uuid_root); - if (objectid == BTRFS_BLOCK_GROUP_TREE_OBJECTID) + case BTRFS_BLOCK_GROUP_TREE_OBJECTID: return btrfs_grab_root(fs_info->block_group_root); - if (objectid == BTRFS_FREE_SPACE_TREE_OBJECTID) + case BTRFS_FREE_SPACE_TREE_OBJECTID: return btrfs_grab_root(btrfs_global_root(fs_info, &key)); - return NULL; + default: + return NULL; + } } int btrfs_insert_fs_root(struct btrfs_fs_info *fs_info, From patchwork Tue May 23 08:40:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13251876 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 445C5C7EE29 for ; Tue, 23 May 2023 08:41:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236110AbjEWIl4 (ORCPT ); Tue, 23 May 2023 04:41:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236129AbjEWIlZ (ORCPT ); Tue, 23 May 2023 04:41:25 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7836BE4F for ; Tue, 23 May 2023 01:40:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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; bh=C0lfNshUPGXqHaUMiEW5g00Pi9Fwa/T9RYSgmZdTpBQ=; b=Cg+3VWgvbKcayuKl+dCah4lvZQ gbGHPCkSKr2qo8iZu6VTj/+icNeqUZgNj5dIFQM8kt18KUFH8e7vcBsWsi1A17yppkQfqSw9xzjPj ZS4CvGnF/DpNtexPECxnEgBDBPcnMTn2bv3Ss8XVveQp8xj62WE92pofFBo0qVh/qctkURENO+N/t AOzMBb3CVroztI8lgY2hLi+aTrLAVBAee3lu1AVWb3+7SrENCoDEiRFQVuFVT4x4JdWDPJRWXpS8D TESLRG/a5QEsufQ46FYaW08JiPRLy+NGjTlNR31w0SezZYm+LPm+9Wc3f0HWDrGgYFZcXaIKgLJtC xPF5q5CQ==; Received: from [2001:4bb8:188:23b2:6ade:85c9:530f:6eb0] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1q1NZE-009TZQ-06; Tue, 23 May 2023 08:40:28 +0000 From: Christoph Hellwig To: clm@fb.com, josef@toxicpanda.com, dsterba@suse.com Cc: linux-btrfs@vger.kernel.org Subject: [PATCH 3/3] btrfs: remove a pointless NULL check in btrfs_lookup_fs_root Date: Tue, 23 May 2023 10:40:20 +0200 Message-Id: <20230523084020.336697-3-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230523084020.336697-1-hch@lst.de> References: <20230523084020.336697-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org btrfs_grab_root already checks for a NULL root itself. Signed-off-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn --- fs/btrfs/disk-io.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 1edd6685df5760..c70d9defb90fa5 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -1332,8 +1332,7 @@ static struct btrfs_root *btrfs_lookup_fs_root(struct btrfs_fs_info *fs_info, spin_lock(&fs_info->fs_roots_radix_lock); root = radix_tree_lookup(&fs_info->fs_roots_radix, (unsigned long)root_id); - if (root) - root = btrfs_grab_root(root); + root = btrfs_grab_root(root); spin_unlock(&fs_info->fs_roots_radix_lock); return root; }