From patchwork Tue Nov 5 03:37:39 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kelley Nielsen X-Patchwork-Id: 3139081 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 07FECBEEB3 for ; Tue, 5 Nov 2013 03:37:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 015EE205F0 for ; Tue, 5 Nov 2013 03:37:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E63C2205EC for ; Tue, 5 Nov 2013 03:37:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753495Ab3KEDhm (ORCPT ); Mon, 4 Nov 2013 22:37:42 -0500 Received: from mail-pd0-f181.google.com ([209.85.192.181]:33884 "EHLO mail-pd0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750732Ab3KEDhm (ORCPT ); Mon, 4 Nov 2013 22:37:42 -0500 Received: by mail-pd0-f181.google.com with SMTP id x10so7558481pdj.40 for ; Mon, 04 Nov 2013 19:37:41 -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=oahUXdIkPCHgY8LUqzdyHUXfU2Z034OymF78PCSgRek=; b=TN3A6eItdW9BRZzGB9Uo8fIYVmZyQxZ7gnt55mzsyp+ZwZrar5NLoZMVFleI++lMmJ vBvuQ3KbLDdcppMnqkBLxy6kOXSPsWM1pduYE3fjRdbuavcvoKThH3BdqoqdkTpg1bMJ exg9xlWv/Z2SwD1I1TmxgjBi6bPOZLgHq9lH8Sfd0YSdw4FVRryOEYYCilHXynPEH9Lt /q3yaarP/oHw3iBdjfoVp1g+d89QuWaeR+wR2yEVroX5bnjRyfDCrduJM6hsHwyFDRK3 +XDXlRxjLEicLwZupkCgpjPp+dZBizulPyEz6MlqM2vUM9J1+9+8ioVYPTRnGS6mhpE2 lbGQ== X-Received: by 10.66.118.129 with SMTP id km1mr8179157pab.127.1383622661379; Mon, 04 Nov 2013 19:37:41 -0800 (PST) Received: from kelleynnn-HP-Compaq-8510w ([12.250.97.26]) by mx.google.com with ESMTPSA id rv9sm31406484pbc.4.2013.11.04.19.37.40 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 04 Nov 2013 19:37:40 -0800 (PST) Date: Mon, 4 Nov 2013 19:37:39 -0800 From: Kelley Nielsen To: linux-btrfs@vger.kernel.org Cc: opw-kernel@googlegroups.com Subject: [PATCH v2 3/3] expand btrfs_find_item() to include find_orphan_item functionality 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 This is the third step in bootstrapping the btrfs_find_item interface. The function find_orphan_item(), in orphan.c, is similar to the two functions already replaced by the new interface. It uses two parameters, which are already present in the interface, and is nearly identical to the function brought in in the previous patch. Replace the two calls to find_orphan_item() with calls to btrfs_find_item(), with the defined objectid and type that was used internally by find_orphan_item(), a null path, and a null key. Add a test for a null path to btrfs_find_item, and if it passes, allocate and free the path. Finally, remove find_orphan_item(). Signed-off-by: Kelley Nielsen --- Changes since v1: * Removed comment at the head of btrfs_find_item() * Reworded commit messasge to use imperative, not passive voice fs/btrfs/ctree.c | 26 +++++++++++++------------- fs/btrfs/disk-io.c | 3 ++- fs/btrfs/orphan.c | 20 -------------------- fs/btrfs/tree-log.c | 3 ++- 4 files changed, 17 insertions(+), 35 deletions(-) diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index 7d2f71c..a528a14 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -2462,32 +2462,32 @@ 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, 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, +int btrfs_find_item(struct btrfs_root *fs_root, struct btrfs_path *found_path, u64 iobjectid, u64 ioff, u8 key_type, struct btrfs_key *found_key) { int ret; struct btrfs_key key; struct extent_buffer *eb; + struct btrfs_path *path; key.type = key_type; key.objectid = iobjectid; key.offset = ioff; + if (found_path == NULL) { + path = btrfs_alloc_path(); + if (!path) + return -ENOMEM; + } else + path = found_path; + ret = btrfs_search_slot(NULL, fs_root, &key, path, 0, 0); - if ((ret < 0) || (found_key == NULL)) + if ((ret < 0) || (found_key == NULL)) { + if (path != found_path) + btrfs_free_path(path); return ret; + } eb = path->nodes[0]; if (ret && path->slots[0] >= btrfs_header_nritems(eb)) { diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 4c4ed0b..bce90c9 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -1616,7 +1616,8 @@ again: if (ret) goto fail; - ret = btrfs_find_orphan_item(fs_info->tree_root, location->objectid); + ret = btrfs_find_item(fs_info->tree_root, NULL, BTRFS_ORPHAN_OBJECTID, + location->objectid, BTRFS_ORPHAN_ITEM_KEY, NULL); if (ret < 0) goto fail; if (ret == 0) diff --git a/fs/btrfs/orphan.c b/fs/btrfs/orphan.c index 24cad16..65793ed 100644 --- a/fs/btrfs/orphan.c +++ b/fs/btrfs/orphan.c @@ -69,23 +69,3 @@ out: btrfs_free_path(path); return ret; } - -int btrfs_find_orphan_item(struct btrfs_root *root, u64 offset) -{ - struct btrfs_path *path; - struct btrfs_key key; - int ret; - - key.objectid = BTRFS_ORPHAN_OBJECTID; - key.type = BTRFS_ORPHAN_ITEM_KEY; - key.offset = offset; - - path = btrfs_alloc_path(); - if (!path) - return -ENOMEM; - - ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); - - btrfs_free_path(path); - return ret; -} diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index a2c7b04..9972e2a 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -1238,7 +1238,8 @@ static int insert_orphan_item(struct btrfs_trans_handle *trans, struct btrfs_root *root, u64 offset) { int ret; - ret = btrfs_find_orphan_item(root, offset); + ret = btrfs_find_item(root, NULL, BTRFS_ORPHAN_OBJECTID, + offset, BTRFS_ORPHAN_ITEM_KEY, NULL); if (ret > 0) ret = btrfs_insert_orphan_item(trans, root, offset); return ret;