From patchwork Fri Nov 1 07:00:10 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kelley Nielsen X-Patchwork-Id: 3123161 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 78324BEEB2 for ; Fri, 1 Nov 2013 07:00:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DD0C82045B for ; Fri, 1 Nov 2013 07:00:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A9BB420453 for ; Fri, 1 Nov 2013 07:00:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752151Ab3KAHAQ (ORCPT ); Fri, 1 Nov 2013 03:00:16 -0400 Received: from mail-pd0-f176.google.com ([209.85.192.176]:44674 "EHLO mail-pd0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751551Ab3KAHAP (ORCPT ); Fri, 1 Nov 2013 03:00:15 -0400 Received: by mail-pd0-f176.google.com with SMTP id g10so3431312pdj.7 for ; Fri, 01 Nov 2013 00:00:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=xXyxtYNXNjT9HGwOxSE2josnpNSs1TVcK02gr+hZOaE=; b=Ce6y4YAaS3xzOei2jAPTvNC4CYmyl9i2cD9IS7D3pOpoxGBKB0mxSb21zwN4ajniG0 W0cDj+K9aaEnJUoc1mtF/ZBWVUxdm4nPUCLgV1DwuiYebxoigdX8yxAkkI8+XcyN5NWY KmKR8j575GQNsO3vMC+53Nf4VvAPQ9a6pnPsBFnxcYzY10pWYBgCQv04cF8+Xiq97pzK ym/HvMjJLUhqrKggeTQEp5MJctxmL7Tbn5qLzGiyw54mfMJ/G/3oHkoo2jkfgIxeYwou M9eRxcoXmC3RX9VeqygJ012W7JEhou9wg9k0DKya0I6lIRXIB03/nE/X+1r4MaJC64Fk ipxg== X-Received: by 10.66.25.208 with SMTP id e16mr1693814pag.131.1383289213656; Fri, 01 Nov 2013 00:00:13 -0700 (PDT) Received: from kelleynnn-HP-Compaq-8510w (c-76-103-52-179.hsd1.ca.comcast.net. [76.103.52.179]) by mx.google.com with ESMTPSA id xn12sm10676844pac.12.2013.11.01.00.00.12 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 01 Nov 2013 00:00:12 -0700 (PDT) Date: Fri, 1 Nov 2013 00:00:10 -0700 From: Kelley Nielsen To: linux-btrfs@vger.kernel.org Cc: opw-kernel@googlegroups.com Subject: [PATCH 2/3] btrfs_find_item expanded to include find_root_ref functionality Message-ID: <289ccf95bca0d3366fb183faee8b368fa11b4bd3.1383289182.git.kelleynnn@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch is the second step in bootstrapping the btrfs_find_item interface. The function btrfs_find_root_ref is similar to the former __inode_info; it accepts four of its parameters, and duplicates the first half of its functionality. The one former call to btrfs_find_root_ref has been replaced with a call to btrfs_find_item, along with the defined key type that was used internally by btrfs_find_root ref, and a null found key. In btrfs_find_item, a test for the null key has been added at the place where the functionality of btrfs_find_root_ref ends; btrfs_find_item then returns if the test passes. Finally, btrfs_find_root_ref has been removed. Signed-off-by: Kelley Nielsen Suggested-by: Zach Brown Reviewed-by: Josh Triplett --- fs/btrfs/ctree.c | 10 ++++++++-- fs/btrfs/inode.c | 6 +++--- fs/btrfs/root-tree.c | 15 --------------- 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index 3828352..498b19d 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -2465,7 +2465,13 @@ static int key_search(struct extent_buffer *b, struct btrfs_key *key, /* Proposed generic search function, meant to take the place of the * various small search helper functions throughout the code and standardize * the search interface. Right now, it only replaces the former __inode_info -* in backref.c. +* in backref.c, and the former btrfs_find_root_ref in root-tree.c. +* +* If a null key is passed, it returns immediately after running +* btrfs_search_slot, leaving the path filled as it is and passing its +* return value upward. If a real key is passed, it will set the caller's +* path to point to the first item in the tree after its specified +* objectid, type, and offset for which objectid and type match the input. */ int btrfs_find_item(struct btrfs_root *fs_root, struct btrfs_path *path, u64 inum, u64 ioff, u8 key_type, @@ -2480,7 +2486,7 @@ int btrfs_find_item(struct btrfs_root *fs_root, struct btrfs_path *path, key.offset = ioff; ret = btrfs_search_slot(NULL, fs_root, &key, path, 0, 0); - if (ret < 0) + if ((ret < 0) || (found_key == NULL)) return ret; eb = path->nodes[0]; diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 3911fca..c07afdf 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -4672,9 +4672,9 @@ static int fixup_tree_root_location(struct btrfs_root *root, } err = -ENOENT; - ret = btrfs_find_root_ref(root->fs_info->tree_root, path, - BTRFS_I(dir)->root->root_key.objectid, - location->objectid); + ret = btrfs_find_item(root->fs_info->tree_root, path, + BTRFS_I(dir)->root->root_key.objectid, + location->objectid, BTRFS_ROOT_REF_KEY, NULL); if (ret) { if (ret < 0) err = ret; diff --git a/fs/btrfs/root-tree.c b/fs/btrfs/root-tree.c index ec71ea4..fcc10eb 100644 --- a/fs/btrfs/root-tree.c +++ b/fs/btrfs/root-tree.c @@ -400,21 +400,6 @@ out: return err; } -int btrfs_find_root_ref(struct btrfs_root *tree_root, - struct btrfs_path *path, - u64 root_id, u64 ref_id) -{ - struct btrfs_key key; - int ret; - - key.objectid = root_id; - key.type = BTRFS_ROOT_REF_KEY; - key.offset = ref_id; - - ret = btrfs_search_slot(NULL, tree_root, &key, path, 0, 0); - return ret; -} - /* * add a btrfs_root_ref item. type is either BTRFS_ROOT_REF_KEY * or BTRFS_ROOT_BACKREF_KEY.