Re: [PATCH 10/12] Btrfs-progs: add show subcommand to subvol cli

2013-01-30 Thread Wang Shilong
Hi,
 This adds show sub-command to the btrfs subvol cli
 to display detailed inforamtion of the given subvol
 or snapshot.

 Signed-off-by: Anand Jain anand.j...@oracle.com
 ---
  btrfs-list.c |  25 +++--
  btrfs-list.h |   3 +-
  cmds-subvolume.c | 155 
 +--
  man/btrfs.8.in   |   6 +++
  4 files changed, 182 insertions(+), 7 deletions(-)

 diff --git a/btrfs-list.c b/btrfs-list.c
 index 656de10..1915ece 100644
 --- a/btrfs-list.c
 +++ b/btrfs-list.c
 @@ -1335,6 +1335,22 @@ static void print_subvolume_column(struct root_info 
 *subv,
   }
  }
  
 +static void print_single_volume_info_raw(struct root_info *subv, char 
 *raw_prefix)
 +{
 + int i;
 +
 + for (i = 0; i  BTRFS_LIST_ALL; i++) {
 + if (!btrfs_list_columns[i].need_print)
 + continue;
 +
 + if (raw_prefix)
 + printf(%s,raw_prefix);
 +
 + print_subvolume_column(subv, i);
 + }
 + printf(\n);
 +}
 +
  static void print_single_volume_info_table(struct root_info *subv)
  {
   int i;
 @@ -1401,7 +1417,7 @@ static void print_all_volume_info_tab_head()
  }
  
  static void print_all_volume_info(struct root_lookup *sorted_tree,
 -   int layout)
 +   int layout, char *raw_prefix)
  {
   struct rb_node *n;
   struct root_info *entry;
 @@ -1419,6 +1435,9 @@ static void print_all_volume_info(struct root_lookup 
 *sorted_tree,
   case BTRFS_LIST_LAYOUT_TABLE:
   print_single_volume_info_table(entry);
   break;
 + case BTRFS_LIST_LAYOUT_RAW:
 + print_single_volume_info_raw(entry, raw_prefix);
 + break;
   }
   n = rb_next(n);
   }
 @@ -1445,7 +1464,7 @@ int btrfs_list_subvols(int fd, struct root_lookup 
 *root_lookup)
  
  int btrfs_list_subvols_print(int fd, struct btrfs_list_filter_set 
 *filter_set,
  struct btrfs_list_comparer_set *comp_set,
 -int layout)
 +int layout, char *raw_prefix)
  {
   struct root_lookup root_lookup;
   struct root_lookup root_sort;
 @@ -1457,7 +1476,7 @@ int btrfs_list_subvols_print(int fd, struct 
 btrfs_list_filter_set *filter_set,
   __filter_and_sort_subvol(root_lookup, root_sort, filter_set,
comp_set, fd);
  
 - print_all_volume_info(root_sort, layout);
 + print_all_volume_info(root_sort, layout, raw_prefix);
   __free_all_subvolumn(root_lookup);
  
   return 0;
 diff --git a/btrfs-list.h b/btrfs-list.h
 index 5b60068..09d35f7 100644
 --- a/btrfs-list.h
 +++ b/btrfs-list.h
 @@ -20,6 +20,7 @@
  
  #define BTRFS_LIST_LAYOUT_DEFAULT0
  #define BTRFS_LIST_LAYOUT_TABLE  1
 +#define BTRFS_LIST_LAYOUT_RAW2
  
  /*
   * one of these for each root we find.
 @@ -150,7 +151,7 @@ int btrfs_list_setup_comparer(struct 
 btrfs_list_comparer_set **comp_set,
  
  int btrfs_list_subvols_print(int fd, struct btrfs_list_filter_set 
 *filter_set,
  struct btrfs_list_comparer_set *comp_set,
 - int is_tab_result);
 + int layout, char *raw_prefix);
  int btrfs_list_find_updated_files(int fd, u64 root_id, u64 oldest_gen);
  int btrfs_list_get_default_subvolume(int fd, u64 *default_id);
  char *btrfs_list_path_for_root(int fd, u64 root);
 diff --git a/cmds-subvolume.c b/cmds-subvolume.c
 index bb9629f..6a14c4c 100644
 --- a/cmds-subvolume.c
 +++ b/cmds-subvolume.c
 @@ -24,6 +24,7 @@
  #include libgen.h
  #include limits.h
  #include getopt.h
 +#include uuid/uuid.h
  
  #include kerncompat.h
  #include ioctl.h
 @@ -418,10 +419,10 @@ static int cmd_subvol_list(int argc, char **argv)
  
   if (is_tab_result)
   ret = btrfs_list_subvols_print(fd, filter_set, comparer_set,
 - BTRFS_LIST_LAYOUT_TABLE);
 + BTRFS_LIST_LAYOUT_TABLE, NULL);
   else
   ret = btrfs_list_subvols_print(fd, filter_set, comparer_set,
 - BTRFS_LIST_LAYOUT_DEFAULT);
 + BTRFS_LIST_LAYOUT_DEFAULT, NULL);
   if (ret)
   return 19;
   return 0;
 @@ -634,7 +635,7 @@ static int cmd_subvol_get_default(int argc, char **argv)
   btrfs_list_setup_print_column(BTRFS_LIST_PATH);
  
   ret = btrfs_list_subvols_print(fd, filter_set, NULL,
 - BTRFS_LIST_LAYOUT_DEFAULT);
 + BTRFS_LIST_LAYOUT_DEFAULT, NULL);
   if (ret)
   return 19;
   return 0;
 @@ -721,6 +722,153 @@ static int cmd_find_new(int argc, char **argv)
   return 0;
  }
  
 +static const char * const cmd_subvol_show_usage[] = {
 + btrfs subvolume show subvol-path,
 + Show more information of the subvolume,
 + NULL
 +};
 +
 +static int cmd_subvol_show(int argc, 

Re: [PATCH 10/12] Btrfs-progs: add show subcommand to subvol cli

2013-01-30 Thread Anand Jain


Wang,


+   ret = 0;
+   /* print the info */

 I think it will be better if you can move the following
 printing to a function..it will make the code more clear and
 readable..


 Thanks for looking into this. However IMO there is no need
 as of now.  This can be taken when there is more reasonable
 need. I hope you would agree with me.

-Anand
--
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 10/12] Btrfs-progs: add show subcommand to subvol cli

2013-01-28 Thread Anand Jain
This adds show sub-command to the btrfs subvol cli
to display detailed inforamtion of the given subvol
or snapshot.

Signed-off-by: Anand Jain anand.j...@oracle.com
---
 btrfs-list.c |  25 +++--
 btrfs-list.h |   3 +-
 cmds-subvolume.c | 155 +--
 man/btrfs.8.in   |   6 +++
 4 files changed, 182 insertions(+), 7 deletions(-)

diff --git a/btrfs-list.c b/btrfs-list.c
index 656de10..1915ece 100644
--- a/btrfs-list.c
+++ b/btrfs-list.c
@@ -1335,6 +1335,22 @@ static void print_subvolume_column(struct root_info 
*subv,
}
 }
 
+static void print_single_volume_info_raw(struct root_info *subv, char 
*raw_prefix)
+{
+   int i;
+
+   for (i = 0; i  BTRFS_LIST_ALL; i++) {
+   if (!btrfs_list_columns[i].need_print)
+   continue;
+
+   if (raw_prefix)
+   printf(%s,raw_prefix);
+
+   print_subvolume_column(subv, i);
+   }
+   printf(\n);
+}
+
 static void print_single_volume_info_table(struct root_info *subv)
 {
int i;
@@ -1401,7 +1417,7 @@ static void print_all_volume_info_tab_head()
 }
 
 static void print_all_volume_info(struct root_lookup *sorted_tree,
- int layout)
+ int layout, char *raw_prefix)
 {
struct rb_node *n;
struct root_info *entry;
@@ -1419,6 +1435,9 @@ static void print_all_volume_info(struct root_lookup 
*sorted_tree,
case BTRFS_LIST_LAYOUT_TABLE:
print_single_volume_info_table(entry);
break;
+   case BTRFS_LIST_LAYOUT_RAW:
+   print_single_volume_info_raw(entry, raw_prefix);
+   break;
}
n = rb_next(n);
}
@@ -1445,7 +1464,7 @@ int btrfs_list_subvols(int fd, struct root_lookup 
*root_lookup)
 
 int btrfs_list_subvols_print(int fd, struct btrfs_list_filter_set *filter_set,
   struct btrfs_list_comparer_set *comp_set,
-  int layout)
+  int layout, char *raw_prefix)
 {
struct root_lookup root_lookup;
struct root_lookup root_sort;
@@ -1457,7 +1476,7 @@ int btrfs_list_subvols_print(int fd, struct 
btrfs_list_filter_set *filter_set,
__filter_and_sort_subvol(root_lookup, root_sort, filter_set,
 comp_set, fd);
 
-   print_all_volume_info(root_sort, layout);
+   print_all_volume_info(root_sort, layout, raw_prefix);
__free_all_subvolumn(root_lookup);
 
return 0;
diff --git a/btrfs-list.h b/btrfs-list.h
index 5b60068..09d35f7 100644
--- a/btrfs-list.h
+++ b/btrfs-list.h
@@ -20,6 +20,7 @@
 
 #define BTRFS_LIST_LAYOUT_DEFAULT  0
 #define BTRFS_LIST_LAYOUT_TABLE1
+#define BTRFS_LIST_LAYOUT_RAW  2
 
 /*
  * one of these for each root we find.
@@ -150,7 +151,7 @@ int btrfs_list_setup_comparer(struct 
btrfs_list_comparer_set **comp_set,
 
 int btrfs_list_subvols_print(int fd, struct btrfs_list_filter_set *filter_set,
   struct btrfs_list_comparer_set *comp_set,
-   int is_tab_result);
+   int layout, char *raw_prefix);
 int btrfs_list_find_updated_files(int fd, u64 root_id, u64 oldest_gen);
 int btrfs_list_get_default_subvolume(int fd, u64 *default_id);
 char *btrfs_list_path_for_root(int fd, u64 root);
diff --git a/cmds-subvolume.c b/cmds-subvolume.c
index bb9629f..6a14c4c 100644
--- a/cmds-subvolume.c
+++ b/cmds-subvolume.c
@@ -24,6 +24,7 @@
 #include libgen.h
 #include limits.h
 #include getopt.h
+#include uuid/uuid.h
 
 #include kerncompat.h
 #include ioctl.h
@@ -418,10 +419,10 @@ static int cmd_subvol_list(int argc, char **argv)
 
if (is_tab_result)
ret = btrfs_list_subvols_print(fd, filter_set, comparer_set,
-   BTRFS_LIST_LAYOUT_TABLE);
+   BTRFS_LIST_LAYOUT_TABLE, NULL);
else
ret = btrfs_list_subvols_print(fd, filter_set, comparer_set,
-   BTRFS_LIST_LAYOUT_DEFAULT);
+   BTRFS_LIST_LAYOUT_DEFAULT, NULL);
if (ret)
return 19;
return 0;
@@ -634,7 +635,7 @@ static int cmd_subvol_get_default(int argc, char **argv)
btrfs_list_setup_print_column(BTRFS_LIST_PATH);
 
ret = btrfs_list_subvols_print(fd, filter_set, NULL,
-   BTRFS_LIST_LAYOUT_DEFAULT);
+   BTRFS_LIST_LAYOUT_DEFAULT, NULL);
if (ret)
return 19;
return 0;
@@ -721,6 +722,153 @@ static int cmd_find_new(int argc, char **argv)
return 0;
 }
 
+static const char * const cmd_subvol_show_usage[] = {
+   btrfs subvolume show subvol-path,
+   Show more information of the subvolume,
+   NULL
+};
+
+static int cmd_subvol_show(int argc, char **argv)
+{
+   struct