Re: [PATCH 1/3] btrfs-progs: Generic functions to retrieve chunks and their bg info

2017-06-09 Thread divya . indi

Hi,

Working on a v2 of this patch based on the comments received.

Thanks,

Divya


On 06/07/2017 10:03 AM, Goffredo Baroncelli wrote:

Hi,

any news about these commands ?

BR
G.Baroncelli

On 2016-10-28 17:44, David Sterba wrote:

On Mon, Oct 17, 2016 at 05:35:13PM -0700, Divya Indi wrote:

An efficient alternative to retrieving block groups:
get_chunks(): Walk the chunk tree to retrieve the chunks.
get_bg_info(): For each retrieved chunk, lookup an exact match of block
group in the extent tree.

Signed-off-by: Divya Indi 
Reviewed-by: Ashish Samant 
Reviewed-by: Liu Bo 
---
  cmds-inspect.c |   66 
  1 files changed, 66 insertions(+), 0 deletions(-)

diff --git a/cmds-inspect.c b/cmds-inspect.c
index 4b7cea0..f435ea9 100644
--- a/cmds-inspect.c
+++ b/cmds-inspect.c
@@ -81,6 +81,72 @@ out:
return !!ret;
  }
  
+static void bg_flags_to_str(u64 flags, char *ret)

+{
+   int empty = 1;
+
+   if (flags & BTRFS_BLOCK_GROUP_DATA) {
+   empty = 0;
+   strcpy(ret, "DATA");
+   }
+   if (flags & BTRFS_BLOCK_GROUP_METADATA) {
+   if (!empty)
+   strcat(ret, "|");
+   strcat(ret, "METADATA");
+   }
+   if (flags & BTRFS_BLOCK_GROUP_SYSTEM) {
+   if (!empty)
+   strcat(ret, "|");
+   strcat(ret, "SYSTEM");
+   }
+}
+
+/* Walking through the chunk tree to retrieve chunks. */

No empty newline.


+
+static int get_chunks(int fd, struct btrfs_ioctl_search_args *chunk_args)
+{
+   struct btrfs_ioctl_search_key *sk;
+   int ret;
+   int e;
+
+   sk = _args->key;
+
+   sk->tree_id = BTRFS_CHUNK_TREE_OBJECTID;
+   sk->min_objectid = sk->max_objectid = BTRFS_FIRST_CHUNK_TREE_OBJECTID;
+   sk->max_type = sk->min_type = BTRFS_CHUNK_ITEM_KEY;

Please don't do multiple asignments in one statement.


+   sk->nr_items = 4096;
+
+   ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, chunk_args);
+   e = errno;

This is useless asignment, I've removed it from the code, please don't
reintrduce it.


+   if (ret < 0) {
+   fprintf(stderr, "ret %d error '%s'\n", ret,
+   strerror(e));
+   }
+   return ret;
+}



+
+/* Given the objectid, find the block group item in the extent tree */
+static int get_bg_info(int fd, struct btrfs_ioctl_search_args *bg_args,
+  u64 objectid, unsigned long length)
+{
+   struct btrfs_ioctl_search_key *bg_sk;
+   int ret;
+   int e;
+
+   bg_sk = _args->key;
+
+   bg_sk->min_objectid = bg_sk->max_objectid = objectid;
+   bg_sk->nr_items = 1;
+   bg_sk->min_offset = bg_sk->max_offset = length;

Same here.


+
+   ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, bg_args);
+   e = errno;
+   if (ret < 0) {
+   fprintf(stderr, "ret %d error '%s'\n", ret,
+   strerror(e));

Please take a look how the error messages are constructed when the tree
search ioctl fails, there are enough examples in the code.


+   }
+   return ret;
+}
  static const char * const cmd_inspect_inode_resolve_usage[] = {
"btrfs inspect-internal inode-resolve [-v]  ",
"Get file system paths for the given inode",

Actually, I'm not sure if such functions should exist at all, as they
only hide the search ioctl but don't do any validation of the returned
keys and data.
--
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





--
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


Re: [PATCH 1/3] btrfs-progs: Generic functions to retrieve chunks and their bg info

2017-06-07 Thread Goffredo Baroncelli
Hi,

any news about these commands ?

BR
G.Baroncelli

On 2016-10-28 17:44, David Sterba wrote:
> On Mon, Oct 17, 2016 at 05:35:13PM -0700, Divya Indi wrote:
>> An efficient alternative to retrieving block groups:
>> get_chunks(): Walk the chunk tree to retrieve the chunks.
>> get_bg_info(): For each retrieved chunk, lookup an exact match of block
>> group in the extent tree.
>>
>> Signed-off-by: Divya Indi 
>> Reviewed-by: Ashish Samant 
>> Reviewed-by: Liu Bo 
>> ---
>>  cmds-inspect.c |   66 
>> 
>>  1 files changed, 66 insertions(+), 0 deletions(-)
>>
>> diff --git a/cmds-inspect.c b/cmds-inspect.c
>> index 4b7cea0..f435ea9 100644
>> --- a/cmds-inspect.c
>> +++ b/cmds-inspect.c
>> @@ -81,6 +81,72 @@ out:
>>  return !!ret;
>>  }
>>  
>> +static void bg_flags_to_str(u64 flags, char *ret)
>> +{
>> +int empty = 1;
>> +
>> +if (flags & BTRFS_BLOCK_GROUP_DATA) {
>> +empty = 0;
>> +strcpy(ret, "DATA");
>> +}
>> +if (flags & BTRFS_BLOCK_GROUP_METADATA) {
>> +if (!empty)
>> +strcat(ret, "|");
>> +strcat(ret, "METADATA");
>> +}
>> +if (flags & BTRFS_BLOCK_GROUP_SYSTEM) {
>> +if (!empty)
>> +strcat(ret, "|");
>> +strcat(ret, "SYSTEM");
>> +}
>> +}
>> +
>> +/* Walking through the chunk tree to retrieve chunks. */
> 
> No empty newline.
> 
>> +
>> +static int get_chunks(int fd, struct btrfs_ioctl_search_args *chunk_args)
>> +{
>> +struct btrfs_ioctl_search_key *sk;
>> +int ret;
>> +int e;
>> +
>> +sk = _args->key;
>> +
>> +sk->tree_id = BTRFS_CHUNK_TREE_OBJECTID;
>> +sk->min_objectid = sk->max_objectid = BTRFS_FIRST_CHUNK_TREE_OBJECTID;
>> +sk->max_type = sk->min_type = BTRFS_CHUNK_ITEM_KEY;
> 
> Please don't do multiple asignments in one statement.
> 
>> +sk->nr_items = 4096;
>> +
>> +ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, chunk_args);
>> +e = errno;
> 
> This is useless asignment, I've removed it from the code, please don't
> reintrduce it.
> 
>> +if (ret < 0) {
>> +fprintf(stderr, "ret %d error '%s'\n", ret,
>> +strerror(e));
>> +}
>> +return ret;
>> +}
> 
> 
>> +
>> +/* Given the objectid, find the block group item in the extent tree */
>> +static int get_bg_info(int fd, struct btrfs_ioctl_search_args *bg_args,
>> +   u64 objectid, unsigned long length)
>> +{
>> +struct btrfs_ioctl_search_key *bg_sk;
>> +int ret;
>> +int e;
>> +
>> +bg_sk = _args->key;
>> +
>> +bg_sk->min_objectid = bg_sk->max_objectid = objectid;
>> +bg_sk->nr_items = 1;
>> +bg_sk->min_offset = bg_sk->max_offset = length;
> 
> Same here.
> 
>> +
>> +ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, bg_args);
>> +e = errno;
>> +if (ret < 0) {
>> +fprintf(stderr, "ret %d error '%s'\n", ret,
>> +strerror(e));
> 
> Please take a look how the error messages are constructed when the tree
> search ioctl fails, there are enough examples in the code.
> 
>> +}
>> +return ret;
>> +}
>>  static const char * const cmd_inspect_inode_resolve_usage[] = {
>>  "btrfs inspect-internal inode-resolve [-v]  ",
>>  "Get file system paths for the given inode",
> 
> Actually, I'm not sure if such functions should exist at all, as they
> only hide the search ioctl but don't do any validation of the returned
> keys and data.
> --
> 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
> 


-- 
gpg @keyserver.linux.it: Goffredo Baroncelli 
Key fingerprint BBF5 1610 0B64 DAC6 5F7D  17B2 0EDA 9B37 8B82 E0B5
--
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


Re: [PATCH 1/3] btrfs-progs: Generic functions to retrieve chunks and their bg info

2016-11-01 Thread divya . indi



On 10/28/2016 08:44 AM, David Sterba wrote:

On Mon, Oct 17, 2016 at 05:35:13PM -0700, Divya Indi wrote:

An efficient alternative to retrieving block groups:
get_chunks(): Walk the chunk tree to retrieve the chunks.
get_bg_info(): For each retrieved chunk, lookup an exact match of block
group in the extent tree.

Signed-off-by: Divya Indi 
Reviewed-by: Ashish Samant 
Reviewed-by: Liu Bo 
---
  cmds-inspect.c |   66 
  1 files changed, 66 insertions(+), 0 deletions(-)

diff --git a/cmds-inspect.c b/cmds-inspect.c
index 4b7cea0..f435ea9 100644
--- a/cmds-inspect.c
+++ b/cmds-inspect.c
@@ -81,6 +81,72 @@ out:
return !!ret;
  }
  
+static void bg_flags_to_str(u64 flags, char *ret)

+{
+   int empty = 1;
+
+   if (flags & BTRFS_BLOCK_GROUP_DATA) {
+   empty = 0;
+   strcpy(ret, "DATA");
+   }
+   if (flags & BTRFS_BLOCK_GROUP_METADATA) {
+   if (!empty)
+   strcat(ret, "|");
+   strcat(ret, "METADATA");
+   }
+   if (flags & BTRFS_BLOCK_GROUP_SYSTEM) {
+   if (!empty)
+   strcat(ret, "|");
+   strcat(ret, "SYSTEM");
+   }
+}
+
+/* Walking through the chunk tree to retrieve chunks. */

No empty newline.


+
+static int get_chunks(int fd, struct btrfs_ioctl_search_args *chunk_args)
+{
+   struct btrfs_ioctl_search_key *sk;
+   int ret;
+   int e;
+
+   sk = _args->key;
+
+   sk->tree_id = BTRFS_CHUNK_TREE_OBJECTID;
+   sk->min_objectid = sk->max_objectid = BTRFS_FIRST_CHUNK_TREE_OBJECTID;
+   sk->max_type = sk->min_type = BTRFS_CHUNK_ITEM_KEY;

Please don't do multiple asignments in one statement.


+   sk->nr_items = 4096;
+
+   ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, chunk_args);
+   e = errno;

This is useless asignment, I've removed it from the code, please don't
reintrduce it.


+   if (ret < 0) {
+   fprintf(stderr, "ret %d error '%s'\n", ret,
+   strerror(e));
+   }
+   return ret;
+}



+
+/* Given the objectid, find the block group item in the extent tree */
+static int get_bg_info(int fd, struct btrfs_ioctl_search_args *bg_args,
+  u64 objectid, unsigned long length)
+{
+   struct btrfs_ioctl_search_key *bg_sk;
+   int ret;
+   int e;
+
+   bg_sk = _args->key;
+
+   bg_sk->min_objectid = bg_sk->max_objectid = objectid;
+   bg_sk->nr_items = 1;
+   bg_sk->min_offset = bg_sk->max_offset = length;

Same here.


+
+   ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, bg_args);
+   e = errno;
+   if (ret < 0) {
+   fprintf(stderr, "ret %d error '%s'\n", ret,
+   strerror(e));

Please take a look how the error messages are constructed when the tree
search ioctl fails, there are enough examples in the code.


+   }
+   return ret;
+}
  static const char * const cmd_inspect_inode_resolve_usage[] = {
"btrfs inspect-internal inode-resolve [-v]  ",
"Get file system paths for the given inode",

Actually, I'm not sure if such functions should exist at all, as they
only hide the search ioctl but don't do any validation of the returned
keys and data.
The intent was to avoid the same assignments and calls in both the sub 
commands, but I see your point.

 Noted- for v2.

--
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


Re: [PATCH 1/3] btrfs-progs: Generic functions to retrieve chunks and their bg info

2016-10-28 Thread David Sterba
On Mon, Oct 17, 2016 at 05:35:13PM -0700, Divya Indi wrote:
> An efficient alternative to retrieving block groups:
> get_chunks(): Walk the chunk tree to retrieve the chunks.
> get_bg_info(): For each retrieved chunk, lookup an exact match of block
> group in the extent tree.
> 
> Signed-off-by: Divya Indi 
> Reviewed-by: Ashish Samant 
> Reviewed-by: Liu Bo 
> ---
>  cmds-inspect.c |   66 
> 
>  1 files changed, 66 insertions(+), 0 deletions(-)
> 
> diff --git a/cmds-inspect.c b/cmds-inspect.c
> index 4b7cea0..f435ea9 100644
> --- a/cmds-inspect.c
> +++ b/cmds-inspect.c
> @@ -81,6 +81,72 @@ out:
>   return !!ret;
>  }
>  
> +static void bg_flags_to_str(u64 flags, char *ret)
> +{
> + int empty = 1;
> +
> + if (flags & BTRFS_BLOCK_GROUP_DATA) {
> + empty = 0;
> + strcpy(ret, "DATA");
> + }
> + if (flags & BTRFS_BLOCK_GROUP_METADATA) {
> + if (!empty)
> + strcat(ret, "|");
> + strcat(ret, "METADATA");
> + }
> + if (flags & BTRFS_BLOCK_GROUP_SYSTEM) {
> + if (!empty)
> + strcat(ret, "|");
> + strcat(ret, "SYSTEM");
> + }
> +}
> +
> +/* Walking through the chunk tree to retrieve chunks. */

No empty newline.

> +
> +static int get_chunks(int fd, struct btrfs_ioctl_search_args *chunk_args)
> +{
> + struct btrfs_ioctl_search_key *sk;
> + int ret;
> + int e;
> +
> + sk = _args->key;
> +
> + sk->tree_id = BTRFS_CHUNK_TREE_OBJECTID;
> + sk->min_objectid = sk->max_objectid = BTRFS_FIRST_CHUNK_TREE_OBJECTID;
> + sk->max_type = sk->min_type = BTRFS_CHUNK_ITEM_KEY;

Please don't do multiple asignments in one statement.

> + sk->nr_items = 4096;
> +
> + ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, chunk_args);
> + e = errno;

This is useless asignment, I've removed it from the code, please don't
reintrduce it.

> + if (ret < 0) {
> + fprintf(stderr, "ret %d error '%s'\n", ret,
> + strerror(e));
> + }
> + return ret;
> +}


> +
> +/* Given the objectid, find the block group item in the extent tree */
> +static int get_bg_info(int fd, struct btrfs_ioctl_search_args *bg_args,
> +u64 objectid, unsigned long length)
> +{
> + struct btrfs_ioctl_search_key *bg_sk;
> + int ret;
> + int e;
> +
> + bg_sk = _args->key;
> +
> + bg_sk->min_objectid = bg_sk->max_objectid = objectid;
> + bg_sk->nr_items = 1;
> + bg_sk->min_offset = bg_sk->max_offset = length;

Same here.

> +
> + ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, bg_args);
> + e = errno;
> + if (ret < 0) {
> + fprintf(stderr, "ret %d error '%s'\n", ret,
> + strerror(e));

Please take a look how the error messages are constructed when the tree
search ioctl fails, there are enough examples in the code.

> + }
> + return ret;
> +}
>  static const char * const cmd_inspect_inode_resolve_usage[] = {
>   "btrfs inspect-internal inode-resolve [-v]  ",
>   "Get file system paths for the given inode",

Actually, I'm not sure if such functions should exist at all, as they
only hide the search ioctl but don't do any validation of the returned
keys and data.
--
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


Re: [PATCH 1/3] btrfs-progs: Generic functions to retrieve chunks and their bg info

2016-10-17 Thread Qu Wenruo



At 10/18/2016 08:35 AM, Divya Indi wrote:

An efficient alternative to retrieving block groups:
get_chunks(): Walk the chunk tree to retrieve the chunks.
get_bg_info(): For each retrieved chunk, lookup an exact match of block
group in the extent tree.

Signed-off-by: Divya Indi 
Reviewed-by: Ashish Samant 
Reviewed-by: Liu Bo 
---
 cmds-inspect.c |   66 
 1 files changed, 66 insertions(+), 0 deletions(-)

diff --git a/cmds-inspect.c b/cmds-inspect.c
index 4b7cea0..f435ea9 100644
--- a/cmds-inspect.c
+++ b/cmds-inspect.c
@@ -81,6 +81,72 @@ out:
return !!ret;
 }

+static void bg_flags_to_str(u64 flags, char *ret)
+{
+   int empty = 1;
+
+   if (flags & BTRFS_BLOCK_GROUP_DATA) {
+   empty = 0;
+   strcpy(ret, "DATA");
+   }
+   if (flags & BTRFS_BLOCK_GROUP_METADATA) {
+   if (!empty)
+   strcat(ret, "|");
+   strcat(ret, "METADATA");
+   }
+   if (flags & BTRFS_BLOCK_GROUP_SYSTEM) {
+   if (!empty)
+   strcat(ret, "|");
+   strcat(ret, "SYSTEM");
+   }
+}


Check print-tree.c, it has the same function.
Just export it.

And it's stronger than your version, which can also output profiles.


+
+/* Walking through the chunk tree to retrieve chunks. */
+
+static int get_chunks(int fd, struct btrfs_ioctl_search_args *chunk_args)
+{
+   struct btrfs_ioctl_search_key *sk;
+   int ret;
+   int e;
+
+   sk = _args->key;
+
+   sk->tree_id = BTRFS_CHUNK_TREE_OBJECTID;
+   sk->min_objectid = sk->max_objectid = BTRFS_FIRST_CHUNK_TREE_OBJECTID;
+   sk->max_type = sk->min_type = BTRFS_CHUNK_ITEM_KEY;
+   sk->nr_items = 4096;
+
+   ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, chunk_args);
+   e = errno;
+   if (ret < 0) {
+   fprintf(stderr, "ret %d error '%s'\n", ret,
+   strerror(e));


Use error() function.


+   }
+   return ret;
+}
+
+/* Given the objectid, find the block group item in the extent tree */
+static int get_bg_info(int fd, struct btrfs_ioctl_search_args *bg_args,
+  u64 objectid, unsigned long length)
+{
+   struct btrfs_ioctl_search_key *bg_sk;
+   int ret;
+   int e;
+
+   bg_sk = _args->key;
+
+   bg_sk->min_objectid = bg_sk->max_objectid = objectid;
+   bg_sk->nr_items = 1;
+   bg_sk->min_offset = bg_sk->max_offset = length;
+
+   ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, bg_args);
+   e = errno;
+   if (ret < 0) {
+   fprintf(stderr, "ret %d error '%s'\n", ret,
+   strerror(e));


Same problem here.


+   }
+   return ret;
+}
 static const char * const cmd_inspect_inode_resolve_usage[] = {
"btrfs inspect-internal inode-resolve [-v]  ",
"Get file system paths for the given inode",




--
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


[PATCH 1/3] btrfs-progs: Generic functions to retrieve chunks and their bg info

2016-10-17 Thread Divya Indi
An efficient alternative to retrieving block groups:
get_chunks(): Walk the chunk tree to retrieve the chunks.
get_bg_info(): For each retrieved chunk, lookup an exact match of block
group in the extent tree.

Signed-off-by: Divya Indi 
Reviewed-by: Ashish Samant 
Reviewed-by: Liu Bo 
---
 cmds-inspect.c |   66 
 1 files changed, 66 insertions(+), 0 deletions(-)

diff --git a/cmds-inspect.c b/cmds-inspect.c
index 4b7cea0..f435ea9 100644
--- a/cmds-inspect.c
+++ b/cmds-inspect.c
@@ -81,6 +81,72 @@ out:
return !!ret;
 }
 
+static void bg_flags_to_str(u64 flags, char *ret)
+{
+   int empty = 1;
+
+   if (flags & BTRFS_BLOCK_GROUP_DATA) {
+   empty = 0;
+   strcpy(ret, "DATA");
+   }
+   if (flags & BTRFS_BLOCK_GROUP_METADATA) {
+   if (!empty)
+   strcat(ret, "|");
+   strcat(ret, "METADATA");
+   }
+   if (flags & BTRFS_BLOCK_GROUP_SYSTEM) {
+   if (!empty)
+   strcat(ret, "|");
+   strcat(ret, "SYSTEM");
+   }
+}
+
+/* Walking through the chunk tree to retrieve chunks. */
+
+static int get_chunks(int fd, struct btrfs_ioctl_search_args *chunk_args)
+{
+   struct btrfs_ioctl_search_key *sk;
+   int ret;
+   int e;
+
+   sk = _args->key;
+
+   sk->tree_id = BTRFS_CHUNK_TREE_OBJECTID;
+   sk->min_objectid = sk->max_objectid = BTRFS_FIRST_CHUNK_TREE_OBJECTID;
+   sk->max_type = sk->min_type = BTRFS_CHUNK_ITEM_KEY;
+   sk->nr_items = 4096;
+
+   ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, chunk_args);
+   e = errno;
+   if (ret < 0) {
+   fprintf(stderr, "ret %d error '%s'\n", ret,
+   strerror(e));
+   }
+   return ret;
+}
+
+/* Given the objectid, find the block group item in the extent tree */
+static int get_bg_info(int fd, struct btrfs_ioctl_search_args *bg_args,
+  u64 objectid, unsigned long length)
+{
+   struct btrfs_ioctl_search_key *bg_sk;
+   int ret;
+   int e;
+
+   bg_sk = _args->key;
+
+   bg_sk->min_objectid = bg_sk->max_objectid = objectid;
+   bg_sk->nr_items = 1;
+   bg_sk->min_offset = bg_sk->max_offset = length;
+
+   ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, bg_args);
+   e = errno;
+   if (ret < 0) {
+   fprintf(stderr, "ret %d error '%s'\n", ret,
+   strerror(e));
+   }
+   return ret;
+}
 static const char * const cmd_inspect_inode_resolve_usage[] = {
"btrfs inspect-internal inode-resolve [-v]  ",
"Get file system paths for the given inode",
-- 
1.7.1

--
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