All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
To: <linux-btrfs@vger.kernel.org>
Subject: [PATCH 03/10] btrfs-progs: use btrfs_find_free_dir_index to find free inode index
Date: Fri, 2 Feb 2018 16:27:44 +0800	[thread overview]
Message-ID: <20180202082751.26225-4-lufq.fnst@cn.fujitsu.com> (raw)
In-Reply-To: <20180202082751.26225-1-lufq.fnst@cn.fujitsu.com>

Since we have an existing function to find free inode index, we can
reuse it here.

Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
---
 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;
-- 
2.16.1




  parent reply	other threads:[~2018-02-02  8:28 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-02  8:27 [PATCH 00/10] btrfs-progs: introduce btrfs rescue undelete-subvol subcommand Lu Fengqi
2018-02-02  8:27 ` [PATCH 01/10] btrfs-progs: copy btrfs_del_orphan_item from kernel Lu Fengqi
2018-02-02  8:27 ` [PATCH 02/10] btrfs-progs: extract btrfs_link_subvol from btrfs_mksubvol Lu Fengqi
2018-02-02  8:27 ` Lu Fengqi [this message]
2018-02-02  8:27 ` [PATCH 04/10] btrfs-progs: undelete-subvol: introduce is_subvol_intact Lu Fengqi
2018-02-02  8:27 ` [PATCH 05/10] btrfs-progs: undelete-subvol: introduce recover_dead_root Lu Fengqi
2018-02-02  8:27 ` [PATCH 06/10] btrfs-progs: undelete-subvol: introduce link_subvol_to_lostfound Lu Fengqi
2018-02-02  8:27 ` [PATCH 07/10] btrfs-progs: undelete-subvol: introduce btrfs_undelete_intact_subvols Lu Fengqi
2018-02-02  8:27 ` [PATCH 08/10] btrfs-progs: undelete-subvol: add undelete-subvol subcommand Lu Fengqi
2018-02-02  8:27 ` [PATCH 09/10] btrfs-progs: tests: add testcase for undelete-subvol Lu Fengqi
2018-02-02  8:27 ` [PATCH 10/10] btrfs-progs: undelete-subvol: update completion and documentation Lu Fengqi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180202082751.26225-4-lufq.fnst@cn.fujitsu.com \
    --to=lufq.fnst@cn.fujitsu.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.