From patchwork Tue Mar 27 07:06:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lu Fengqi X-Patchwork-Id: 10309403 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AD75060325 for ; Tue, 27 Mar 2018 07:07:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9380929836 for ; Tue, 27 Mar 2018 07:07:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 88644298C5; Tue, 27 Mar 2018 07:07:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2CE9029836 for ; Tue, 27 Mar 2018 07:07:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752147AbeC0HHp (ORCPT ); Tue, 27 Mar 2018 03:07:45 -0400 Received: from mail.cn.fujitsu.com ([183.91.158.132]:56162 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752053AbeC0HHR (ORCPT ); Tue, 27 Mar 2018 03:07:17 -0400 X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="38221613" Received: from localhost (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 27 Mar 2018 15:07:08 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (unknown [10.167.33.80]) by cn.fujitsu.com (Postfix) with ESMTP id 5BEB748AE76C for ; Tue, 27 Mar 2018 15:07:08 +0800 (CST) Received: from fnst.localdomain (10.167.226.155) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.361.1; Tue, 27 Mar 2018 15:07:10 +0800 From: Lu Fengqi To: Subject: [PATCH v2 03/10] btrfs-progs: use btrfs_find_free_dir_index to find free inode index Date: Tue, 27 Mar 2018 15:06:51 +0800 Message-ID: <20180327070658.13064-4-lufq.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180327070658.13064-1-lufq.fnst@cn.fujitsu.com> References: <20180327070658.13064-1-lufq.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.155] X-yoursite-MailScanner-ID: 5BEB748AE76C.AC52D X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: lufq.fnst@cn.fujitsu.com Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Since we have an existing function to find free inode index, we can reuse it here. Signed-off-by: Lu Fengqi Reviewed-by: Qu Wenruo --- inode.c | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/inode.c b/inode.c index 478036562652..86905365dfd8 100644 --- a/inode.c +++ b/inode.c @@ -628,7 +628,7 @@ int btrfs_link_subvol(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct btrfs_inode_item *inode_item; struct extent_buffer *leaf; struct btrfs_key key; - u64 index = 2; + u64 index; char buf[BTRFS_NAME_LEN + 1]; /* for snprintf null */ int len; int i; @@ -638,28 +638,15 @@ int btrfs_link_subvol(struct btrfs_trans_handle *trans, struct btrfs_root *root, if (len == 0 || len > BTRFS_NAME_LEN) return -EINVAL; - /* find the free dir_index */ - btrfs_init_path(&path); - key.objectid = dirid; - key.type = BTRFS_DIR_INDEX_KEY; - key.offset = (u64)-1; - - ret = btrfs_search_slot(NULL, root, &key, &path, 0, 0); - if (ret <= 0) { - error("search for DIR_INDEX dirid %llu failed: %d", - (unsigned long long)dirid, ret); + /* add the dir_item/dir_index */ + ret = btrfs_find_free_dir_index(root, dirid, &index); + if (ret < 0) { + error("unable to find free dir index dirid %llu failed: %d", + (unsigned long long)dirid, ret); goto fail; } - if (path.slots[0] > 0) { - path.slots[0]--; - btrfs_item_key_to_cpu(path.nodes[0], &key, path.slots[0]); - if (key.objectid == dirid && key.type == BTRFS_DIR_INDEX_KEY) - index = key.offset + 1; - } - btrfs_release_path(&path); - - /* add the dir_item/dir_index */ + btrfs_init_path(&path); key.objectid = dirid; key.offset = 0; key.type = BTRFS_INODE_ITEM_KEY;