Re: [PATCH v2 03/10] btrfs-progs: use btrfs_find_free_dir_index to find free inode index

2018-04-17 Thread Qu Wenruo


On 2018年03月27日 15:06, Lu Fengqi wrote:
> Since we have an existing function to find free inode index, we can
> reuse it here.
> 
> Signed-off-by: Lu Fengqi 

Looks good.

Reviewed-by: Qu Wenruo 

Thanks,
Qu

> ---
>  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();
> - key.objectid = dirid;
> - key.type = BTRFS_DIR_INDEX_KEY;
> - key.offset = (u64)-1;
> -
> - ret = btrfs_search_slot(NULL, root, , , 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, );
> + 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], , path.slots[0]);
> - if (key.objectid == dirid && key.type == BTRFS_DIR_INDEX_KEY)
> - index = key.offset + 1;
> - }
> - btrfs_release_path();
> -
> - /* add the dir_item/dir_index */
> + btrfs_init_path();
>   key.objectid = dirid;
>   key.offset = 0;
>   key.type =  BTRFS_INODE_ITEM_KEY;
> 



signature.asc
Description: OpenPGP digital signature


[PATCH v2 03/10] btrfs-progs: use btrfs_find_free_dir_index to find free inode index

2018-03-27 Thread Lu Fengqi
Since we have an existing function to find free inode index, we can
reuse it here.

Signed-off-by: Lu Fengqi 
---
 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();
-   key.objectid = dirid;
-   key.type = BTRFS_DIR_INDEX_KEY;
-   key.offset = (u64)-1;
-
-   ret = btrfs_search_slot(NULL, root, , , 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, );
+   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], , path.slots[0]);
-   if (key.objectid == dirid && key.type == BTRFS_DIR_INDEX_KEY)
-   index = key.offset + 1;
-   }
-   btrfs_release_path();
-
-   /* add the dir_item/dir_index */
+   btrfs_init_path();
key.objectid = dirid;
key.offset = 0;
key.type =  BTRFS_INODE_ITEM_KEY;
-- 
2.16.2



--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html