From patchwork Tue Nov 5 03:33:33 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kelley Nielsen X-Patchwork-Id: 3139041 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 6DE4E9F3C4 for ; Tue, 5 Nov 2013 03:33:42 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6EB72205BD for ; Tue, 5 Nov 2013 03:33:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1E9B6205EF for ; Tue, 5 Nov 2013 03:33:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754164Ab3KEDdh (ORCPT ); Mon, 4 Nov 2013 22:33:37 -0500 Received: from mail-pd0-f178.google.com ([209.85.192.178]:37387 "EHLO mail-pd0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753927Ab3KEDdg (ORCPT ); Mon, 4 Nov 2013 22:33:36 -0500 Received: by mail-pd0-f178.google.com with SMTP id x10so7549886pdj.23 for ; Mon, 04 Nov 2013 19:33:35 -0800 (PST) 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=CA3//+wsYhkkMuYpDsEq5Ju4XgTTag8rfpq8U3MlWhI=; b=N66olRY4lDlLO+zsW8I0j4Tr4QqWsdColw6cSMai18ij9tm7tNwaMhNDuMMCTda8rv ZiT5d0C+fL+SSb2ORmb766zSr3v5GEo/qoFJxAYCBokEoBw1sdlvM3DIC2+lTGcZ0pUp RchB41IQ6TLUiDm5HSS+ANM4qT8njn3I2FPbvAtScnvr0icP8SxnQWtFbcQ1xjzaClNT FPmrcK5AyrXf8FKoHhyS3CvAEwodFcm8WakxSb0PZzZU0x0910B24iVfRfMwxvKtO/Vw 4SC7aR759XYa3+ykLz8NKt+wIGUxUAkJD88j4n47RQSrcxhH3lUf/dll9KuwBi7d3iNE qP8w== X-Received: by 10.66.193.66 with SMTP id hm2mr9948875pac.122.1383622415399; Mon, 04 Nov 2013 19:33:35 -0800 (PST) Received: from kelleynnn-HP-Compaq-8510w ([12.250.97.26]) by mx.google.com with ESMTPSA id hz10sm31372300pbc.36.2013.11.04.19.33.34 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 04 Nov 2013 19:33:34 -0800 (PST) Date: Mon, 4 Nov 2013 19:33:33 -0800 From: Kelley Nielsen To: linux-btrfs@vger.kernel.org Cc: opw-kernel@googlegroups.com Subject: [PATCH v2 1/3] Bootstrap generic btrfs_find_item interface Message-ID: 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=-6.8 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 There are many btrfs functions that manually search the tree for an item. They all reimplement the same mechanism and differ in the conditions that they use to find the item. __inode_info() is one such example. Zach Brown proposed creating a new interface to take the place of these functions. This patch is the first step to creating the interface. A new function, btrfs_find_item, has been added to ctree.c and prototyped in ctree.h. It is identical to __inode_info, except that the order of the parameters has been rearranged to more closely those of similar functions elsewhere in the code (now, root and path come first, then the objectid, offset and type, and the key to be filled in last). __inode_info's callers have been set to call this new function instead, and __inode_info itself has been removed. Signed-off-by: Kelley Nielsen Suggested-by: Zach Brown Reviewed-by: Josh Triplett --- Changes since v1: * reworded commit message to use the imperative rather than passive voice, and to mention Zach Brown in the body as well as in the suggested-by line * Changed parameter inum to iobjectid in btrfs_find_item() * Added a space before __inode_info() in the commit message fs/btrfs/backref.c | 40 ++++------------------------------------ fs/btrfs/ctree.c | 37 +++++++++++++++++++++++++++++++++++++ fs/btrfs/ctree.h | 2 ++ 3 files changed, 43 insertions(+), 36 deletions(-) diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c index 3775947..595bd1f 100644 --- a/fs/btrfs/backref.c +++ b/fs/btrfs/backref.c @@ -1107,38 +1107,6 @@ int btrfs_find_all_roots(struct btrfs_trans_handle *trans, return 0; } - -static int __inode_info(u64 inum, u64 ioff, u8 key_type, - struct btrfs_root *fs_root, struct btrfs_path *path, - struct btrfs_key *found_key) -{ - int ret; - struct btrfs_key key; - struct extent_buffer *eb; - - key.type = key_type; - key.objectid = inum; - key.offset = ioff; - - ret = btrfs_search_slot(NULL, fs_root, &key, path, 0, 0); - if (ret < 0) - return ret; - - eb = path->nodes[0]; - if (ret && path->slots[0] >= btrfs_header_nritems(eb)) { - ret = btrfs_next_leaf(fs_root, path); - if (ret) - return ret; - eb = path->nodes[0]; - } - - btrfs_item_key_to_cpu(eb, found_key, path->slots[0]); - if (found_key->type != key.type || found_key->objectid != key.objectid) - return 1; - - return 0; -} - /* * this makes the path point to (inum INODE_ITEM ioff) */ @@ -1146,16 +1114,16 @@ int inode_item_info(u64 inum, u64 ioff, struct btrfs_root *fs_root, struct btrfs_path *path) { struct btrfs_key key; - return __inode_info(inum, ioff, BTRFS_INODE_ITEM_KEY, fs_root, path, - &key); + return btrfs_find_item(fs_root, path, inum, ioff, + BTRFS_INODE_ITEM_KEY, &key); } static int inode_ref_info(u64 inum, u64 ioff, struct btrfs_root *fs_root, struct btrfs_path *path, struct btrfs_key *found_key) { - return __inode_info(inum, ioff, BTRFS_INODE_REF_KEY, fs_root, path, - found_key); + return btrfs_find_item(fs_root, path, inum, ioff, + BTRFS_INODE_REF_KEY, found_key); } int btrfs_find_one_extref(struct btrfs_root *root, u64 inode_objectid, diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index 316136b..5969473 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -2462,6 +2462,43 @@ static int key_search(struct extent_buffer *b, struct btrfs_key *key, return 0; } +/* 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. +*/ +int btrfs_find_item(struct btrfs_root *fs_root, struct btrfs_path *path, + u64 iobjectid, u64 ioff, u8 key_type, + struct btrfs_key *found_key) +{ + int ret; + struct btrfs_key key; + struct extent_buffer *eb; + + key.type = key_type; + key.objectid = iobjectid; + key.offset = ioff; + + ret = btrfs_search_slot(NULL, fs_root, &key, path, 0, 0); + if (ret < 0) + return ret; + + eb = path->nodes[0]; + if (ret && path->slots[0] >= btrfs_header_nritems(eb)) { + ret = btrfs_next_leaf(fs_root, path); + if (ret) + return ret; + eb = path->nodes[0]; + } + + btrfs_item_key_to_cpu(eb, found_key, path->slots[0]); + if (found_key->type != key.type || + found_key->objectid != key.objectid) + return 1; + + return 0; +} + /* * look for key in the tree. path is filled in with nodes along the way * if key is found, we return zero and you can find the item in the leaf diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index f013a31..0c337f5 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -3357,6 +3357,8 @@ int btrfs_duplicate_item(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct btrfs_path *path, 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); int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct btrfs_key *key, struct btrfs_path *p, int ins_len, int cow);