Skip to contentSkip to conversation

btrfs-progs: Make btrfs_lookup_dir_index in parity with kernel code

PATCH Superseded Marcos Paulo de Souza 3 participants 3 messages Aug 18, 2020 – Aug 21, 2020 Btrfs file system

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs-progs: Make btrfs_lookup_dir_index in parity with kernel code

From: Marcos Paulo de Souza <[email protected]>

This function exists in kernel side but using the _item suffix, and objectid argument is placed before the name argument. Change the function to reflect the kernel version.

---
 check/main.c             |  6 +++---
 ctree.h                  | 11 ++++++-----
 inode.c                  | 14 +++++++-------
 kernel-shared/dir-item.c | 13 +++++++------
 4 files changed, 23 insertions(+), 21 deletions(-)
check/main.c +3 -3
index f93bd7d4..176bc508 100644
@@ -2072,9 +2072,9 @@ static int delete_dir_index(struct btrfs_root *root,
 		(unsigned long long)root->objectid);
 
 	btrfs_init_path(&path);
-	di = btrfs_lookup_dir_index(trans, root, &path, backref->dir,
-				    backref->name, backref->namelen,
-				    backref->index, -1);
+	di = btrfs_lookup_dir_index_item(trans, root, &path, backref->dir,
+					 backref->index, backref->name,
+					 backref->namelen, -1);
 	if (IS_ERR(di)) {
 		ret = PTR_ERR(di);
 		btrfs_release_path(&path);
ctree.h +6 -5
index 39e03640..a4f70847 100644
@@ -2760,11 +2760,12 @@ struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans,
 					     struct btrfs_path *path, u64 dir,
 					     const char *name, int name_len,
 					     int mod);
-struct btrfs_dir_item *btrfs_lookup_dir_index(struct btrfs_trans_handle *trans,
-					      struct btrfs_root *root,
-					      struct btrfs_path *path, u64 dir,
-					      const char *name, int name_len,
-					      u64 index, int mod);
+struct btrfs_dir_item *
+btrfs_lookup_dir_index_item(struct btrfs_trans_handle *trans,
+			    struct btrfs_root *root,
+			    struct btrfs_path *path, u64 dir,
+			    u64 objectid, const char *name, int name_len,
+			    int mod);
 int btrfs_delete_one_dir_name(struct btrfs_trans_handle *trans,
 			      struct btrfs_root *root,
 			      struct btrfs_path *path,
inode.c +7 -7
index c2d77aa6..67ba9596 100644
@@ -136,8 +136,8 @@ int check_dir_conflict(struct btrfs_root *root, char *name, int namelen,
 	btrfs_release_path(path);
 
 	/* Index conflicting? */
-	dir_item = btrfs_lookup_dir_index(NULL, root, path, dir, name,
-					  namelen, index, 0);
+	dir_item = btrfs_lookup_dir_index_item(NULL, root, path, dir, index,
+					  name, namelen, 0);
 	if (IS_ERR(dir_item) && PTR_ERR(dir_item) == -ENOENT)
 		dir_item = NULL;
 	if (IS_ERR(dir_item)) {
@@ -311,8 +311,8 @@ int btrfs_unlink(struct btrfs_trans_handle *trans, struct btrfs_root *root,
 		del_dir_item = 1;
 	btrfs_release_path(path);
 
-	dir_item = btrfs_lookup_dir_index(NULL, root, path, parent_ino,
-					  name, namelen, index, 0);
+	dir_item = btrfs_lookup_dir_index_item(NULL, root, path, parent_ino,
+					       index, name, namelen, 0);
 	/*
 	 * Since lookup_dir_index() will return -ENOENT when not found,
 	 * we need to do extra check.
@@ -369,9 +369,9 @@ int btrfs_unlink(struct btrfs_trans_handle *trans, struct btrfs_root *root,
 	}
 
 	if (del_dir_index) {
-		dir_item = btrfs_lookup_dir_index(trans, root, path,
-						  parent_ino, name, namelen,
-						  index, -1);
+		dir_item = btrfs_lookup_dir_index_item(trans, root, path,
+						       parent_ino, index, name,
+						       namelen, -1);
 		if (IS_ERR(dir_item)) {
 			ret = PTR_ERR(dir_item);
 			goto out;
kernel-shared/dir-item.c +7 -6
index c8a5a354..d99ace4f 100644
@@ -225,11 +225,12 @@ struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans,
 	return btrfs_match_dir_item_name(root, path, name, name_len);
 }
 
-struct btrfs_dir_item *btrfs_lookup_dir_index(struct btrfs_trans_handle *trans,
-					      struct btrfs_root *root,
-					      struct btrfs_path *path, u64 dir,
-					      const char *name, int name_len,
-					      u64 index, int mod)
+struct btrfs_dir_item *
+btrfs_lookup_dir_index_item(struct btrfs_trans_handle *trans,
+			    struct btrfs_root *root,
+			    struct btrfs_path *path, u64 dir,
+			    u64 objectid, const char *name, int name_len,
+			    int mod)
 {
 	int ret;
 	struct btrfs_key key;
@@ -238,7 +239,7 @@ struct btrfs_dir_item *btrfs_lookup_dir_index(struct btrfs_trans_handle *trans,
 
 	key.objectid = dir;
 	key.type = BTRFS_DIR_INDEX_KEY;
-	key.offset = index;
+	key.offset = objectid;
 
 	ret = btrfs_search_slot(trans, root, &key, path, ins_len, cow);
 	if (ret < 0)
Signature · 1 line
2.28.0
#2 lore raw
In reply to Marcos Paulo de Souza
Quoted 40 lines · Marcos Paulo de Souza

From: Marcos Paulo de Souza <[email protected]>

This function exists in kernel side but using the _item suffix, and objectid argument is placed before the name argument. Change the function to reflect the kernel version.

---
 check/main.c             |  6 +++---
 ctree.h                  | 11 ++++++-----
 inode.c                  | 14 +++++++-------
 kernel-shared/dir-item.c | 13 +++++++------
 4 files changed, 23 insertions(+), 21 deletions(-)
check/main.c +3 -3
index f93bd7d4..176bc508 100644
@@ -2072,9 +2072,9 @@ static int delete_dir_index(struct btrfs_root *root,
 		(unsigned long long)root->objectid);
 
 	btrfs_init_path(&path);
-	di = btrfs_lookup_dir_index(trans, root, &path, backref->dir,
-				    backref->name, backref->namelen,
-				    backref->index, -1);
+	di = btrfs_lookup_dir_index_item(trans, root, &path, backref->dir,
+					 backref->index, backref->name,
+					 backref->namelen, -1);
 	if (IS_ERR(di)) {
 		ret = PTR_ERR(di);
 		btrfs_release_path(&path);
ctree.h +0 -1
index 39e03640..a4f70847 100644
@@ -2760,11 +2760,12 @@ struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans,
 					     struct btrfs_path *path, u64 dir,
 					     const char *name, int name_len,
 					     int mod);
-struct btrfs_dir_item *btrfs_lookup_dir_index(struct btrfs_trans_handle *trans,

ctree.h struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans, · line 2768

Quoted 10 lines
ctree.h +6 -4
-					      struct btrfs_root *root,
-					      struct btrfs_path *path, u64 dir,
-					      const char *name, int name_len,
-					      u64 index, int mod);
+struct btrfs_dir_item *
+btrfs_lookup_dir_index_item(struct btrfs_trans_handle *trans,
+			    struct btrfs_root *root,
+			    struct btrfs_path *path, u64 dir,
+			    u64 objectid, const char *name, int name_len,
+			    int mod);

Please keep the function return type and name on the same line, this is the preferred style. There are still a lot of wrongly formatted functions in kernel like btrfs_lookup_dir_index_item but it should not be in the new code.