Re: btrfs-progs: v3, move out print in cmd_df to another function

2013-09-01 Thread Wang Shilong

On 09/02/2013 10:58 AM, Anand Jain wrote:


 Wang, kindly note that this was fixed in v4.


Yeah...This is sent by my shell script by accident, I have fixed it and
it won't send the repeated message again.

Thanks for reminding .. ^_^



Anand


On 09/01/2013 02:15 PM, Wang Shilong wrote:

Hello, Using checkpatch.pl, i get the following warnings(errors):
ERROR: "foo * bar" should be "foo *bar"
#37: FILE: cmds-filesystem.c:47:
+static char * group_type_str(u64 flag)

ERROR: "foo * bar" should be "foo *bar"
#69: FILE: cmds-filesystem.c:63:
+static char * group_profile_str(u64 flag)

total: 2 errors, 0 warnings, 229 lines checked

patch has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

Thanks, Wang
--
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



--
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: btrfs-progs: v3, move out print in cmd_df to another function

2013-09-01 Thread Anand Jain


 Wang, kindly note that this was fixed in v4.

Anand


On 09/01/2013 02:15 PM, Wang Shilong wrote:

Hello, Using checkpatch.pl, i get the following warnings(errors):
ERROR: "foo * bar" should be "foo *bar"
#37: FILE: cmds-filesystem.c:47:
+static char * group_type_str(u64 flag)

ERROR: "foo * bar" should be "foo *bar"
#69: FILE: cmds-filesystem.c:63:
+static char * group_profile_str(u64 flag)

total: 2 errors, 0 warnings, 229 lines checked

patch has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

Thanks, Wang
--
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: btrfs-progs: v3, move out print in cmd_df to another function

2013-08-31 Thread Wang Shilong
Hello, Using checkpatch.pl, i get the following warnings(errors):
ERROR: "foo * bar" should be "foo *bar"
#37: FILE: cmds-filesystem.c:47:
+static char * group_type_str(u64 flag)

ERROR: "foo * bar" should be "foo *bar"
#69: FILE: cmds-filesystem.c:63:
+static char * group_profile_str(u64 flag)

total: 2 errors, 0 warnings, 229 lines checked

patch has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

Thanks, Wang
--
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] btrfs-progs: v3, move out print in cmd_df to another function

2013-08-19 Thread Anand Jain
This is a prepatory work for the following btrfs fi show command
fixes. So that we have a function get_df to get the fs sizes

v3:
 accepts Zach review comments
v2:
combined the other patches as below and rebase
 btrfs-progs: get string for the group profile and type

Signed-off-by: Anand Jain 
---
 cmds-filesystem.c |  181 
 ctree.h   |   11 +++
 2 files changed, 108 insertions(+), 84 deletions(-)

diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index a4e30ea..d06de35 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -44,28 +44,51 @@ static const char * const cmd_df_usage[] = {
NULL
 };
 
-static int cmd_df(int argc, char **argv)
+static char * group_type_str(u64 flag)
 {
-   struct btrfs_ioctl_space_args *sargs, *sargs_orig;
-   u64 count = 0, i;
-   int ret;
-   int fd;
-   int e;
-   char *path;
-   DIR  *dirstream = NULL;
-
-   if (check_argc_exact(argc, 2))
-   usage(cmd_df_usage);
-
-   path = argv[1];
+   switch (flag & BTRFS_BLOCK_GROUP_TYPE_MASK) {
+   case BTRFS_BLOCK_GROUP_DATA:
+   return "data";
+   case BTRFS_BLOCK_GROUP_SYSTEM:
+   return "system";
+   case BTRFS_BLOCK_GROUP_METADATA:
+   return "metadata";
+   case BTRFS_BLOCK_GROUP_DATA|BTRFS_BLOCK_GROUP_METADATA:
+   return "mixed";
+   default:
+   return "unknown";
+   }
+}
 
-   fd = open_file_or_dir(path, &dirstream);
-   if (fd < 0) {
-   fprintf(stderr, "ERROR: can't access to '%s'\n", path);
-   return 12;
+static char * group_profile_str(u64 flag)
+{
+   switch (flag & BTRFS_BLOCK_GROUP_PROFILE_MASK) {
+   case 0:
+   return "single";
+   case BTRFS_BLOCK_GROUP_RAID0:
+   return "RAID0";
+   case BTRFS_BLOCK_GROUP_RAID1:
+   return "RAID1";
+   case BTRFS_BLOCK_GROUP_RAID5:
+   return "RAID5";
+   case BTRFS_BLOCK_GROUP_RAID6:
+   return "RAID6";
+   case BTRFS_BLOCK_GROUP_DUP:
+   return "DUP";
+   case BTRFS_BLOCK_GROUP_RAID10:
+   return "RAID10";
+   default:
+   return "unknown";
}
+}
 
-   sargs_orig = sargs = malloc(sizeof(struct btrfs_ioctl_space_args));
+static int get_df(int fd, struct btrfs_ioctl_space_args **sargs_ret)
+{
+   u64 count = 0;
+   int ret, e;
+   struct btrfs_ioctl_space_args *sargs;
+
+   sargs = malloc(sizeof(struct btrfs_ioctl_space_args));
if (!sargs)
return -ENOMEM;
 
@@ -75,89 +98,79 @@ static int cmd_df(int argc, char **argv)
ret = ioctl(fd, BTRFS_IOC_SPACE_INFO, sargs);
e = errno;
if (ret) {
-   fprintf(stderr, "ERROR: couldn't get space info on '%s' - %s\n",
-   path, strerror(e));
-   goto out;
+   fprintf(stderr, "ERROR: couldn't get space info - %s\n",
+   strerror(e));
+   free(sargs);
+   return ret;
}
if (!sargs->total_spaces) {
-   ret = 0;
-   goto out;
+   free(sargs);
+   return 0;
}
-
count = sargs->total_spaces;
+   free(sargs);
 
-   sargs = realloc(sargs, sizeof(struct btrfs_ioctl_space_args) +
+   sargs = malloc(sizeof(struct btrfs_ioctl_space_args) +
(count * sizeof(struct btrfs_ioctl_space_info)));
-   if (!sargs) {
-   sargs = sargs_orig;
+   if (!sargs)
ret = -ENOMEM;
-   goto out;
-   }
 
sargs->space_slots = count;
sargs->total_spaces = 0;
-
ret = ioctl(fd, BTRFS_IOC_SPACE_INFO, sargs);
e = errno;
if (ret) {
-   fprintf(stderr, "ERROR: couldn't get space info on '%s' - %s\n",
-   path, strerror(e));
-   goto out;
+   fprintf(stderr, "ERROR: get space info count %llu - %s\n",
+   count, strerror(e));
+   free(sargs);
+   return ret;
}
+   *sargs_ret = sargs;
+   return 0;
+}
 
-   for (i = 0; i < sargs->total_spaces; i++) {
-   char description[80];
-   int written = 0;
-   u64 flags = sargs->spaces[i].flags;
-
-   memset(description, 0, 80);
-
-   if (flags & BTRFS_BLOCK_GROUP_DATA) {
-   if (flags & BTRFS_BLOCK_GROUP_METADATA) {
-   snprintf(description, 14, "%s",
-"Data+Metadata");
-   written += 13;
-   } else {
-   snprintf(description, 5, "%s", "Data");
-   written += 4;
-   }
-   } else if (flags & BTRFS_BLOCK_GROUP_