From patchwork Wed Aug 4 18:48:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcos Paulo de Souza X-Patchwork-Id: 12419609 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 9794FC432BE for ; Wed, 4 Aug 2021 18:49:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7E0FA60F58 for ; Wed, 4 Aug 2021 18:49:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239048AbhHDStq (ORCPT ); Wed, 4 Aug 2021 14:49:46 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:34820 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239047AbhHDStk (ORCPT ); Wed, 4 Aug 2021 14:49:40 -0400 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (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-out2.suse.de (Postfix) with ESMTPS id E0E6A1FE18; Wed, 4 Aug 2021 18:49:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1628102963; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=K8Hi2oWNJjlFo269eqZoIHXcqr48cq44HRIGXvFmLwE=; b=mlq9E0F0KjdZ3/J9cofZicQa/mdFdiMb7NorFCyXYCSSXUR4SMkfVqFMgfZQk+Wl0/go+X 9diNKzJuGetuRWXXe9ta2/aFtZ7ganrJrEx/oPpx23bzihomwzxIBk2Z2eDDtyAcXeW1hE LG3xl1X4ibzn6WX2sKQf01/cQno4uJ8= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (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 imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 95A5313D24; Wed, 4 Aug 2021 18:49:22 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id qNTFFzLhCmGFOQAAMHmgww (envelope-from ); Wed, 04 Aug 2021 18:49:22 +0000 From: Marcos Paulo de Souza To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.com, nborisov@suse.com, Marcos Paulo de Souza Subject: [PATCH 1/7] btrfs: Reorder btrfs_find_item arguments Date: Wed, 4 Aug 2021 15:48:48 -0300 Message-Id: <20210804184854.10696-2-mpdesouza@suse.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210804184854.10696-1-mpdesouza@suse.com> References: <20210804184854.10696-1-mpdesouza@suse.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org It's more natural do use objectid, type and offset, in this order, when dealing with btrfs keys. No functional changes. Signed-off-by: Marcos Paulo de Souza --- fs/btrfs/backref.c | 9 ++++----- fs/btrfs/ctree.c | 2 +- fs/btrfs/ctree.h | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c index f735b8798ba1..9e92faaafa02 100644 --- a/fs/btrfs/backref.c +++ b/fs/btrfs/backref.c @@ -1691,8 +1691,8 @@ char *btrfs_ref_to_path(struct btrfs_root *fs_root, struct btrfs_path *path, btrfs_tree_read_unlock(eb); free_extent_buffer(eb); } - ret = btrfs_find_item(fs_root, path, parent, 0, - BTRFS_INODE_REF_KEY, &found_key); + ret = btrfs_find_item(fs_root, path, parent, BTRFS_INODE_REF_KEY, + 0, &found_key); if (ret > 0) ret = -ENOENT; if (ret) @@ -2063,9 +2063,8 @@ static int iterate_inode_refs(u64 inum, struct btrfs_root *fs_root, struct btrfs_key found_key; while (!ret) { - ret = btrfs_find_item(fs_root, path, inum, - parent ? parent + 1 : 0, BTRFS_INODE_REF_KEY, - &found_key); + ret = btrfs_find_item(fs_root, path, inum, BTRFS_INODE_REF_KEY, + parent ? parent + 1 : 0, &found_key); if (ret < 0) break; diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index 84627cbd5b5b..c0002ec9c025 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -1528,7 +1528,7 @@ setup_nodes_for_search(struct btrfs_trans_handle *trans, } int btrfs_find_item(struct btrfs_root *fs_root, struct btrfs_path *path, - u64 iobjectid, u64 ioff, u8 key_type, + u64 iobjectid, u8 key_type, u64 ioff, struct btrfs_key *found_key) { int ret; diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index a898257ad2b5..0a971e98f5f9 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -2858,7 +2858,7 @@ int btrfs_duplicate_item(struct btrfs_trans_handle *trans, struct btrfs_path *path, const struct btrfs_key *new_key); int btrfs_find_item(struct btrfs_root *fs_root, struct btrfs_path *path, - u64 inum, u64 ioff, u8 key_type, struct btrfs_key *found_key); + u64 inum, u8 key_type, u64 ioff, struct btrfs_key *found_key); int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root *root, const struct btrfs_key *key, struct btrfs_path *p, int ins_len, int cow); From patchwork Wed Aug 4 18:48:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcos Paulo de Souza X-Patchwork-Id: 12419607 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 D39D0C4338F for ; Wed, 4 Aug 2021 18:49:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BA0FF61050 for ; Wed, 4 Aug 2021 18:49:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239065AbhHDStp (ORCPT ); Wed, 4 Aug 2021 14:49:45 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:34828 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239048AbhHDStk (ORCPT ); Wed, 4 Aug 2021 14:49:40 -0400 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (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-out2.suse.de (Postfix) with ESMTPS id A03B41FE1C; Wed, 4 Aug 2021 18:49:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1628102965; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QhmuorOBPK9EjFUWgMNHJe/UF0seN4+kjM0msp4qREU=; b=ZkTo6fYTwc3ejNzv7ns+a4edZcfpBV1w5kn6r1ipfXGQD+Mc7iaWiMUoL89QGQ/DY3Qc3A q42c4EPKOmgVSohsowdJY0IuTSqwclECJikzm62WIhHHBWDF5Ph2VxznHcAeY8bF3dHdN4 QUVH1RbPeg8NwagWC/jISD7MDrLs000= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (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 imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 5105413D24; Wed, 4 Aug 2021 18:49:24 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id eAnmBjThCmGFOQAAMHmgww (envelope-from ); Wed, 04 Aug 2021 18:49:24 +0000 From: Marcos Paulo de Souza To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.com, nborisov@suse.com, Marcos Paulo de Souza Subject: [PATCH 2/7] btrfs: backref: Use btrfs_find_item in btrfs_find_one_extref Date: Wed, 4 Aug 2021 15:48:49 -0300 Message-Id: <20210804184854.10696-3-mpdesouza@suse.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210804184854.10696-1-mpdesouza@suse.com> References: <20210804184854.10696-1-mpdesouza@suse.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org btrfs_find_one_extref is using btrfs_search_slot and iterating over the slots, but in reality it only desires to find an extref, since there is a break without any condition at the end of the while clause. The function can be dramatically simplified by using btrfs_find_item, which calls the btrfs_search_slot, compares if the objectid and type found are the same of those passed as search key, and calls btrfs_item_key_to_cpu if no error was found. No functional changes. Signed-off-by: Marcos Paulo de Souza Reviewed-by: Qu Wenruo --- fs/btrfs/backref.c | 64 ++++++++-------------------------------------- 1 file changed, 11 insertions(+), 53 deletions(-) diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c index 9e92faaafa02..57b955c8a875 100644 --- a/fs/btrfs/backref.c +++ b/fs/btrfs/backref.c @@ -1588,67 +1588,25 @@ int btrfs_find_one_extref(struct btrfs_root *root, u64 inode_objectid, struct btrfs_inode_extref **ret_extref, u64 *found_off) { - int ret, slot; + int ret; struct btrfs_key key; - struct btrfs_key found_key; struct btrfs_inode_extref *extref; - const struct extent_buffer *leaf; unsigned long ptr; - key.objectid = inode_objectid; - key.type = BTRFS_INODE_EXTREF_KEY; - key.offset = start_off; - - ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); + ret = btrfs_find_item(root, path, inode_objectid, BTRFS_INODE_EXTREF_KEY, + start_off, &key); if (ret < 0) return ret; + else if (ret > 0) + return -ENOENT; - while (1) { - leaf = path->nodes[0]; - slot = path->slots[0]; - if (slot >= btrfs_header_nritems(leaf)) { - /* - * If the item at offset is not found, - * btrfs_search_slot will point us to the slot - * where it should be inserted. In our case - * that will be the slot directly before the - * next INODE_REF_KEY_V2 item. In the case - * that we're pointing to the last slot in a - * leaf, we must move one leaf over. - */ - ret = btrfs_next_leaf(root, path); - if (ret) { - if (ret >= 1) - ret = -ENOENT; - break; - } - continue; - } - - btrfs_item_key_to_cpu(leaf, &found_key, slot); - - /* - * Check that we're still looking at an extended ref key for - * this particular objectid. If we have different - * objectid or type then there are no more to be found - * in the tree and we can exit. - */ - ret = -ENOENT; - if (found_key.objectid != inode_objectid) - break; - if (found_key.type != BTRFS_INODE_EXTREF_KEY) - break; - - ret = 0; - ptr = btrfs_item_ptr_offset(leaf, path->slots[0]); - extref = (struct btrfs_inode_extref *)ptr; - *ret_extref = extref; - if (found_off) - *found_off = found_key.offset; - break; - } + ptr = btrfs_item_ptr_offset(path->nodes[0], path->slots[0]); + extref = (struct btrfs_inode_extref *)ptr; + *ret_extref = extref; + if (found_off) + *found_off = key.offset; - return ret; + return 0; } /* From patchwork Wed Aug 4 18:48:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcos Paulo de Souza X-Patchwork-Id: 12419613 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 5A6B6C4320E for ; Wed, 4 Aug 2021 18:49:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 453B961040 for ; Wed, 4 Aug 2021 18:49:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239034AbhHDStr (ORCPT ); Wed, 4 Aug 2021 14:49:47 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:34838 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239068AbhHDStl (ORCPT ); Wed, 4 Aug 2021 14:49:41 -0400 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (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-out2.suse.de (Postfix) with ESMTPS id 57A0A201D1; Wed, 4 Aug 2021 18:49:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1628102967; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Abyxe4wqaqT6xb4U3N9vyf/f5jccB1N5t7XiBoKWyZw=; b=CARdX0rvPAR6b6DhX5P1Vu//V0IDZctAzso3FQmbEE+IGqUnxaeQ+nrLFaE7Vwamx+9EnJ ewsIV72bGcoDJxxWjL9xf85bDW11uEebyj/WBpWBcMZw1NBDFC30ogfGwfH5cZdxIV5V9K F6SFs6SCwBBDUbYWQwV9VwBi6nBjOyg= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (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 imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 0D78D13D24; Wed, 4 Aug 2021 18:49:25 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id qHwIMjXhCmGFOQAAMHmgww (envelope-from ); Wed, 04 Aug 2021 18:49:25 +0000 From: Marcos Paulo de Souza To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.com, nborisov@suse.com, Marcos Paulo de Souza Subject: [PATCH 3/7] btrfs: zoned: Use btrfs_find_item in calculate_emulated_zone_size Date: Wed, 4 Aug 2021 15:48:50 -0300 Message-Id: <20210804184854.10696-4-mpdesouza@suse.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210804184854.10696-1-mpdesouza@suse.com> References: <20210804184854.10696-1-mpdesouza@suse.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org calculate_emulated_zone_size can be simplified by using btrfs_find_item, which executes btrfs_search_slot and calls btrfs_next_leaf if needed. No functional changes. Signed-off-by: Marcos Paulo de Souza Reviewed-by: Qu Wenruo --- fs/btrfs/zoned.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index 47af1ab3bf12..d344baa26de0 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -230,29 +230,20 @@ static int calculate_emulated_zone_size(struct btrfs_fs_info *fs_info) struct btrfs_key key; struct extent_buffer *leaf; struct btrfs_dev_extent *dext; - int ret = 0; - - key.objectid = 1; - key.type = BTRFS_DEV_EXTENT_KEY; - key.offset = 0; + int ret; path = btrfs_alloc_path(); if (!path) return -ENOMEM; - ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); + ret = btrfs_find_item(root, path, 1, BTRFS_DEV_EXTENT_KEY, 0, &key); if (ret < 0) goto out; - if (path->slots[0] >= btrfs_header_nritems(path->nodes[0])) { - ret = btrfs_next_leaf(root, path); - if (ret < 0) - goto out; - /* No dev extents at all? Not good */ - if (ret > 0) { - ret = -EUCLEAN; - goto out; - } + /* No dev extents at all? Not good */ + else if (ret > 0) { + ret = -EUCLEAN; + goto out; } leaf = path->nodes[0]; From patchwork Wed Aug 4 18:48:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcos Paulo de Souza X-Patchwork-Id: 12419611 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 F32EFC4338F for ; Wed, 4 Aug 2021 18:49:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D6C2561040 for ; Wed, 4 Aug 2021 18:49:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232114AbhHDStr (ORCPT ); Wed, 4 Aug 2021 14:49:47 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:34846 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239011AbhHDStm (ORCPT ); Wed, 4 Aug 2021 14:49:42 -0400 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (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-out2.suse.de (Postfix) with ESMTPS id 10B13201D2; Wed, 4 Aug 2021 18:49:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1628102969; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fatp8DYVQeRDvvl4mHcDwHwiKCtgyq+/eqCCJqqjp+A=; b=Q296psR4yJ9pvc4FaI9htnoElLtMgedu7oqIYL9Ea7Kdlhn+xH9GU5LgW7STiMPkenl5G2 6AVywp7HsvnFd9LyVkQjv1lsU2U5ttXan98OkkzFN3kCQE03NvgzBGKChrwW5hWM1LmpPt wI9JXWY9tJe4tMzSemzTNQCQwb6+GXM= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (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 imap2.suse-dmz.suse.de (Postfix) with ESMTPS id BC47713D24; Wed, 4 Aug 2021 18:49:27 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ePoHITfhCmGFOQAAMHmgww (envelope-from ); Wed, 04 Aug 2021 18:49:27 +0000 From: Marcos Paulo de Souza To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.com, nborisov@suse.com, Marcos Paulo de Souza Subject: [PATCH 4/7] btrfs: root-tree: Use btrfs_find_item in btrfs_find_orphan_roots Date: Wed, 4 Aug 2021 15:48:51 -0300 Message-Id: <20210804184854.10696-5-mpdesouza@suse.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210804184854.10696-1-mpdesouza@suse.com> References: <20210804184854.10696-1-mpdesouza@suse.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Prefer btrfs_find_item instead of btrfs_search_slot, since it calls btrfs_next_leaf if needed and checks if the item found has the same objectid and type passed in the search key. No functional changes. Signed-off-by: Marcos Paulo de Souza --- fs/btrfs/root-tree.c | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/fs/btrfs/root-tree.c b/fs/btrfs/root-tree.c index 702dc5441f03..4bb0ad192a2f 100644 --- a/fs/btrfs/root-tree.c +++ b/fs/btrfs/root-tree.c @@ -207,10 +207,10 @@ int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root *root, int btrfs_find_orphan_roots(struct btrfs_fs_info *fs_info) { struct btrfs_root *tree_root = fs_info->tree_root; - struct extent_buffer *leaf; struct btrfs_path *path; struct btrfs_key key; struct btrfs_root *root; + u64 offset = 0; int err = 0; int ret; @@ -218,38 +218,22 @@ int btrfs_find_orphan_roots(struct btrfs_fs_info *fs_info) if (!path) return -ENOMEM; - key.objectid = BTRFS_ORPHAN_OBJECTID; - key.type = BTRFS_ORPHAN_ITEM_KEY; - key.offset = 0; - while (1) { u64 root_objectid; - ret = btrfs_search_slot(NULL, tree_root, &key, path, 0, 0); + ret = btrfs_find_item(tree_root, path, BTRFS_ORPHAN_OBJECTID, + BTRFS_ORPHAN_ITEM_KEY, offset, &key); + + btrfs_release_path(path); if (ret < 0) { err = ret; break; - } - - leaf = path->nodes[0]; - if (path->slots[0] >= btrfs_header_nritems(leaf)) { - ret = btrfs_next_leaf(tree_root, path); - if (ret < 0) - err = ret; - if (ret != 0) - break; - leaf = path->nodes[0]; - } - - btrfs_item_key_to_cpu(leaf, &key, path->slots[0]); - btrfs_release_path(path); - - if (key.objectid != BTRFS_ORPHAN_OBJECTID || - key.type != BTRFS_ORPHAN_ITEM_KEY) + } else if (ret > 0) { break; + } root_objectid = key.offset; - key.offset++; + offset++; root = btrfs_get_fs_root(fs_info, root_objectid, false); err = PTR_ERR_OR_ZERO(root); From patchwork Wed Aug 4 18:48:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcos Paulo de Souza X-Patchwork-Id: 12419617 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 55CB8C4320A for ; Wed, 4 Aug 2021 18:49:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 42D9D61040 for ; Wed, 4 Aug 2021 18:49:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239080AbhHDSts (ORCPT ); Wed, 4 Aug 2021 14:49:48 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:34854 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239078AbhHDSto (ORCPT ); Wed, 4 Aug 2021 14:49:44 -0400 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (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-out2.suse.de (Postfix) with ESMTPS id C8789201D3; Wed, 4 Aug 2021 18:49:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1628102970; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3o9BYEj6GOmieJldwceTT4Fh2sgpeOi0UtaU17AGc8E=; b=TfgE0JpeurFPtKeqMncUFD0zQnLon9EeaG6w2GzzQO2MHp8Ct2K8p8abAcaDNCzwMe2QBF cYlQLytHOHKIFQWnCpz3pUZJIC7SgsAV66PMFrt35eAUIg2wzEcH13FlmHrrHq51jWFPLx LLVnQon2fKptg0iVBQvxyTdOD9JL1bA= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (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 imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 76BCA13D24; Wed, 4 Aug 2021 18:49:29 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id CFMIEDnhCmGFOQAAMHmgww (envelope-from ); Wed, 04 Aug 2021 18:49:29 +0000 From: Marcos Paulo de Souza To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.com, nborisov@suse.com, Marcos Paulo de Souza Subject: [PATCH 5/7] btrfs: scrub: Use btrfs_find_item in scrub_enumerate_chunks Date: Wed, 4 Aug 2021 15:48:52 -0300 Message-Id: <20210804184854.10696-6-mpdesouza@suse.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210804184854.10696-1-mpdesouza@suse.com> References: <20210804184854.10696-1-mpdesouza@suse.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Prefer btrfs_find_item instead of btrfs_search_slot, since it calls btrfs_next_leaf if needed and checks if the item found has the same objectid and type passed in the search key. As result, we can remove one btrfs_key from this function. No functional changes. Signed-off-by: Marcos Paulo de Souza --- fs/btrfs/scrub.c | 52 +++++++++++++----------------------------------- 1 file changed, 14 insertions(+), 38 deletions(-) diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c index 088641ba7a8e..008eeb502267 100644 --- a/fs/btrfs/scrub.c +++ b/fs/btrfs/scrub.c @@ -3657,11 +3657,10 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx, struct btrfs_root *root = fs_info->dev_root; u64 length; u64 chunk_offset; + u64 offset = 0; int ret = 0; int ro_set; - int slot; struct extent_buffer *l; - struct btrfs_key key; struct btrfs_key found_key; struct btrfs_block_group *cache; struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; @@ -3674,47 +3673,24 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx, path->search_commit_root = 1; path->skip_locking = 1; - key.objectid = scrub_dev->devid; - key.offset = 0ull; - key.type = BTRFS_DEV_EXTENT_KEY; - while (1) { - ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); - if (ret < 0) - break; - if (ret > 0) { - if (path->slots[0] >= - btrfs_header_nritems(path->nodes[0])) { - ret = btrfs_next_leaf(root, path); - if (ret < 0) - break; - if (ret > 0) { - ret = 0; - break; - } - } else { - ret = 0; - } - } - - l = path->nodes[0]; - slot = path->slots[0]; - - btrfs_item_key_to_cpu(l, &found_key, slot); - - if (found_key.objectid != scrub_dev->devid) + ret = btrfs_find_item(root, path, scrub_dev->devid, + BTRFS_DEV_EXTENT_KEY, offset, &found_key); + if (ret < 0) { break; - - if (found_key.type != BTRFS_DEV_EXTENT_KEY) - break; - - if (found_key.offset >= end) + } else if (ret > 0) { + /* Reset error if not found. */ + ret = 0; break; + } - if (found_key.offset < key.offset) + if (found_key.offset >= end || + found_key.offset < offset) break; - dev_extent = btrfs_item_ptr(l, slot, struct btrfs_dev_extent); + l = path->nodes[0]; + dev_extent = btrfs_item_ptr(l, path->slots[0], + struct btrfs_dev_extent); length = btrfs_dev_extent_length(l, dev_extent); if (found_key.offset + length <= start) @@ -3938,7 +3914,7 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx, break; } skip: - key.offset = found_key.offset + length; + offset = found_key.offset + length; btrfs_release_path(path); } From patchwork Wed Aug 4 18:48:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcos Paulo de Souza X-Patchwork-Id: 12419615 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 10C4EC432BE for ; Wed, 4 Aug 2021 18:49:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EDDB960F58 for ; Wed, 4 Aug 2021 18:49:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239110AbhHDSts (ORCPT ); Wed, 4 Aug 2021 14:49:48 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:39562 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239162AbhHDStq (ORCPT ); Wed, 4 Aug 2021 14:49:46 -0400 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (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 7994A222ED; Wed, 4 Aug 2021 18:49:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1628102972; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ibsEFebdCWhNSwPx4/WZXXPW3l0/CZ82Cei7cy+4cNA=; b=mHZ5r7+x8fZwudXZL10ykPsfELdkh+Idcey11CHOh+zYZMdoi+3BB75uLuYBd7ugW7dykg m5+M1Jjoej7IL3GzCjLtxfsYXG88W4GNnC0ewdx0eMZPcrD0sPzi/d/i/wcStc1Rl7Rmzv YYLlVScSaL2TOKB638VtJ5v9WxWBw3s= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (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 imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 3423513D24; Wed, 4 Aug 2021 18:49:31 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id sBEbADvhCmGFOQAAMHmgww (envelope-from ); Wed, 04 Aug 2021 18:49:31 +0000 From: Marcos Paulo de Souza To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.com, nborisov@suse.com, Marcos Paulo de Souza Subject: [PATCH 6/7] btrfs: tree-log: Simplify log_new_ancestors Date: Wed, 4 Aug 2021 15:48:53 -0300 Message-Id: <20210804184854.10696-7-mpdesouza@suse.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210804184854.10696-1-mpdesouza@suse.com> References: <20210804184854.10696-1-mpdesouza@suse.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org The search_key variable was being used only as argument of btrfs_search_slot. This can be simplified by calling btrfs_find_item, which also handles the next leaf condition as well. No functional changes. Signed-off-by: Marcos Paulo de Souza --- fs/btrfs/tree-log.c | 40 ++++++++++++---------------------------- 1 file changed, 12 insertions(+), 28 deletions(-) diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index 567adc3de11a..22417cd32347 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -5929,31 +5929,30 @@ static int btrfs_log_all_parents(struct btrfs_trans_handle *trans, return ret; } +/* + * Iterate over the given and all it's parent directories, logging them if + * needed. + * + * Return 0 if we reach the toplevel directory, or < 0 if error. + */ static int log_new_ancestors(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct btrfs_path *path, struct btrfs_log_ctx *ctx) { + struct btrfs_fs_info *fs_info = root->fs_info; struct btrfs_key found_key; + u64 ino; btrfs_item_key_to_cpu(path->nodes[0], &found_key, path->slots[0]); while (true) { - struct btrfs_fs_info *fs_info = root->fs_info; - struct extent_buffer *leaf = path->nodes[0]; - int slot = path->slots[0]; - struct btrfs_key search_key; struct inode *inode; - u64 ino; int ret = 0; btrfs_release_path(path); ino = found_key.offset; - - search_key.objectid = found_key.offset; - search_key.type = BTRFS_INODE_ITEM_KEY; - search_key.offset = 0; inode = btrfs_iget(fs_info->sb, ino, root); if (IS_ERR(inode)) return PTR_ERR(inode); @@ -5966,29 +5965,14 @@ static int log_new_ancestors(struct btrfs_trans_handle *trans, if (ret) return ret; - if (search_key.objectid == BTRFS_FIRST_FREE_OBJECTID) + if (ino == BTRFS_FIRST_FREE_OBJECTID) break; - search_key.type = BTRFS_INODE_REF_KEY; - ret = btrfs_search_slot(NULL, root, &search_key, path, 0, 0); + ret = btrfs_find_item(root, path, ino, BTRFS_INODE_REF_KEY, 0, + &found_key); if (ret < 0) return ret; - - leaf = path->nodes[0]; - slot = path->slots[0]; - if (slot >= btrfs_header_nritems(leaf)) { - ret = btrfs_next_leaf(root, path); - if (ret < 0) - return ret; - else if (ret > 0) - return -ENOENT; - leaf = path->nodes[0]; - slot = path->slots[0]; - } - - btrfs_item_key_to_cpu(leaf, &found_key, slot); - if (found_key.objectid != search_key.objectid || - found_key.type != BTRFS_INODE_REF_KEY) + else if (ret > 0) return -ENOENT; } return 0; From patchwork Wed Aug 4 18:48:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcos Paulo de Souza X-Patchwork-Id: 12419619 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 8A18FC43216 for ; Wed, 4 Aug 2021 18:49:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7031A61050 for ; Wed, 4 Aug 2021 18:49:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239162AbhHDStt (ORCPT ); Wed, 4 Aug 2021 14:49:49 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:39570 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239055AbhHDStr (ORCPT ); Wed, 4 Aug 2021 14:49:47 -0400 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (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 32E12222ED; Wed, 4 Aug 2021 18:49:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1628102974; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rRsycK7Oj2BSBfmsGE+1jES0lQihLv0tkwk9gFaK21w=; b=U+UHfE8cqFkYGxu9s5jatl4nq7UMFTcMYiLAoTY72okvmeOX1qnQ+cd1j2uZ5CI06G/oH6 YPIrf242q+f/jz2G4SzwGNWKU0aC5xlFdCVBSOJfQLgm3zSyLYCuycbz/2DfQoKMQtK3Bb JH7Nov7Se1ver6EbFgQO+H3KpCxOwc4= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (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 imap2.suse-dmz.suse.de (Postfix) with ESMTPS id DE22B13D24; Wed, 4 Aug 2021 18:49:32 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id CGR+KTzhCmGFOQAAMHmgww (envelope-from ); Wed, 04 Aug 2021 18:49:32 +0000 From: Marcos Paulo de Souza To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.com, nborisov@suse.com, Marcos Paulo de Souza Subject: [PATCH 7/7] btrfs: ioctl: Simplify btrfs_ioctl_get_subvol_info Date: Wed, 4 Aug 2021 15:48:54 -0300 Message-Id: <20210804184854.10696-8-mpdesouza@suse.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210804184854.10696-1-mpdesouza@suse.com> References: <20210804184854.10696-1-mpdesouza@suse.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org By using btrfs_find_item we can simplify the code. Also, remove the -ENOENT error condition, since it'll never hit. If find_item returns 0, it means it found the desired objectid and type, so it won't reach the -ENOENT condition. No functional changes. Signed-off-by: Marcos Paulo de Souza --- fs/btrfs/ioctl.c | 56 +++++++++++++++++++----------------------------- 1 file changed, 22 insertions(+), 34 deletions(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index d09eaa83b5d2..2c57bea16c92 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -2685,6 +2685,7 @@ static int btrfs_ioctl_get_subvol_info(struct file *file, void __user *argp) unsigned long item_off; unsigned long item_len; struct inode *inode; + u64 treeid; int slot; int ret = 0; @@ -2702,15 +2703,15 @@ static int btrfs_ioctl_get_subvol_info(struct file *file, void __user *argp) fs_info = BTRFS_I(inode)->root->fs_info; /* Get root_item of inode's subvolume */ - key.objectid = BTRFS_I(inode)->root->root_key.objectid; - root = btrfs_get_fs_root(fs_info, key.objectid, true); + treeid = BTRFS_I(inode)->root->root_key.objectid; + root = btrfs_get_fs_root(fs_info, treeid, true); if (IS_ERR(root)) { ret = PTR_ERR(root); goto out_free; } root_item = &root->root_item; - subvol_info->treeid = key.objectid; + subvol_info->treeid = treeid; subvol_info->generation = btrfs_root_generation(root_item); subvol_info->flags = btrfs_root_flags(root_item); @@ -2737,44 +2738,31 @@ static int btrfs_ioctl_get_subvol_info(struct file *file, void __user *argp) subvol_info->rtime.sec = btrfs_stack_timespec_sec(&root_item->rtime); subvol_info->rtime.nsec = btrfs_stack_timespec_nsec(&root_item->rtime); - if (key.objectid != BTRFS_FS_TREE_OBJECTID) { + if (treeid != BTRFS_FS_TREE_OBJECTID) { /* Search root tree for ROOT_BACKREF of this subvolume */ - key.type = BTRFS_ROOT_BACKREF_KEY; - key.offset = 0; - ret = btrfs_search_slot(NULL, fs_info->tree_root, &key, path, 0, 0); + ret = btrfs_find_item(fs_info->tree_root, path, treeid, + BTRFS_ROOT_BACKREF_KEY, 0, &key); if (ret < 0) { goto out; - } else if (path->slots[0] >= - btrfs_header_nritems(path->nodes[0])) { - ret = btrfs_next_leaf(fs_info->tree_root, path); - if (ret < 0) { - goto out; - } else if (ret > 0) { - ret = -EUCLEAN; - goto out; - } + } else if (ret > 0) { + ret = -EUCLEAN; + goto out; } leaf = path->nodes[0]; slot = path->slots[0]; - btrfs_item_key_to_cpu(leaf, &key, slot); - if (key.objectid == subvol_info->treeid && - key.type == BTRFS_ROOT_BACKREF_KEY) { - subvol_info->parent_id = key.offset; - - rref = btrfs_item_ptr(leaf, slot, struct btrfs_root_ref); - subvol_info->dirid = btrfs_root_ref_dirid(leaf, rref); - - item_off = btrfs_item_ptr_offset(leaf, slot) - + sizeof(struct btrfs_root_ref); - item_len = btrfs_item_size_nr(leaf, slot) - - sizeof(struct btrfs_root_ref); - read_extent_buffer(leaf, subvol_info->name, - item_off, item_len); - } else { - ret = -ENOENT; - goto out; - } + + subvol_info->parent_id = key.offset; + + rref = btrfs_item_ptr(leaf, slot, struct btrfs_root_ref); + subvol_info->dirid = btrfs_root_ref_dirid(leaf, rref); + + item_off = btrfs_item_ptr_offset(leaf, slot) + + sizeof(struct btrfs_root_ref); + item_len = btrfs_item_size_nr(leaf, slot) + - sizeof(struct btrfs_root_ref); + read_extent_buffer(leaf, subvol_info->name, + item_off, item_len); } if (copy_to_user(argp, subvol_info, sizeof(*subvol_info)))