On Fri, Dec 05, 2014 at 04:20:40PM +0800, Hu Tao wrote:
btrfs_qgroup_show shows all qgroups on a btrfs filesystem.
Signed-off-by: Hu Tao <hutao(a)cn.fujitsu.com>
---
daemon/btrfs.c | 88 ++++++++++++++++++++++++++++++++
generator/actions.ml | 10 ++++
generator/structs.ml | 10 ++++
gobject/Makefile.inc | 2 +
java/Makefile.inc | 1 +
java/com/redhat/et/libguestfs/.gitignore | 1 +
po/POTFILES | 1 +
src/MAX_PROC_NR | 2 +-
8 files changed, 114 insertions(+), 1 deletion(-)
diff --git a/daemon/btrfs.c b/daemon/btrfs.c
index 15e481a..3d7e79c 100644
--- a/daemon/btrfs.c
+++ b/daemon/btrfs.c
@@ -1184,3 +1184,91 @@ int do_btrfs_qgroup_destroy (const char *qgroupid, const char
*subvolume)
return 0;
}
+
+guestfs_int_btrfsqgroup_list *do_btrfs_qgroup_show (const char *path)
+{
+ const size_t MAX_ARGS = 64;
+ const char *argv[MAX_ARGS];
+ size_t i = 0;
+ CLEANUP_FREE char *path_buf = NULL;
+ CLEANUP_FREE char *err = NULL;
+ CLEANUP_FREE char *out = NULL;
+ int r;
+ char **lines;
+
+ path_buf = sysroot_path (path);
+ if (path_buf == NULL) {
+ reply_with_perror ("malloc");
+ return NULL;
+ }
+
+ ADD_ARG (argv, i, str_btrfs);
+ ADD_ARG (argv, i, "qgroup");
+ ADD_ARG (argv, i, "show");
+ ADD_ARG (argv, i, path_buf);
+ ADD_ARG (argv, i, NULL);
+
+ r = commandv (&out, &err, argv);
+ if (r == -1) {
+ reply_with_error ("%s: %s", path, err);
+ return NULL;
+ }
+
+ lines = split_lines (out);
+ if (!lines)
+ return NULL;
+
+ /* line 0 and 1 are:
+ *
+ * qgroupid rfer excl
+ * -------- ---- ----
+ */
+ size_t nr_qgroups = count_strings (lines) - 2;
+ guestfs_int_btrfsqgroup_list *ret = NULL;
+ ret = malloc (sizeof *ret);
+ if (!ret) {
+ reply_with_perror ("malloc");
+ goto error;
+ }
+
+ ret->guestfs_int_btrfsqgroup_list_len = nr_qgroups;
+ ret->guestfs_int_btrfsqgroup_list_val =
+ calloc (nr_qgroups, sizeof (struct guestfs_int_btrfsqgroup));
+ if (ret->guestfs_int_btrfsqgroup_list_val == NULL) {
+ reply_with_perror ("malloc");
+ goto error;
+ }
+
+ for (i = 0; i < nr_qgroups; ++i) {
+ char *line = lines[i + 2];
+ struct guestfs_int_btrfsqgroup *this =
+ &ret->guestfs_int_btrfsqgroup_list_val[i];
+ uint64_t dummy1, dummy2;
+ char *p;
+
+ if (sscanf (line, "%" SCNu64 "/%" SCNu64 " %" SCNu64
" %" SCNu64,
+ &dummy1, &dummy2, &this->btrfsqgroup_rfer,
+ &this->btrfsqgroup_excl) != 4) {
+ reply_with_perror ("sscanf");
+ goto error;
+ }
+ p = strchr(line, ' ');
+ if (!p) {
+ reply_with_error ("truncated line: %s", line);
+ goto error;
+ }
+ *p = '\0';
+ this->btrfsqgroup_id = line;
+ }
+
+ free (lines);
+ return ret;
+
+error:
+ free_stringslen (lines, nr_qgroups + 2);
+ if (ret)
+ free (ret->guestfs_int_btrfsqgroup_list_val);
+ free (ret);
+
+ return NULL;
+}
diff --git a/generator/actions.ml b/generator/actions.ml
index 78aafb7..c7df0dd 100644
--- a/generator/actions.ml
+++ b/generator/actions.ml
@@ -12100,6 +12100,16 @@ Create a quota group (qgroup) for subvolume at
C<subvolume>." };
longdesc = "\
Destroy a quota group." };
+ { defaults with
+ name = "btrfs_qgroup_show";
+ style = RStructList ("qgroups", "btrfsqgroup"), [Pathname
"path"], [];
+ proc_nr = Some 433;
+ optional = Some "btrfs"; camel_name = "BTRFSQgroupShow";
+ shortdesc = "show subvolume quota groups";
+ longdesc = "\
+Show all subvolume quota groups in a btrfs filesystem, inclding their
+usages." };
+
]
(* Non-API meta-commands available only in guestfish.
diff --git a/generator/structs.ml b/generator/structs.ml
index 578ebb7..df3ff47 100644
--- a/generator/structs.ml
+++ b/generator/structs.ml
@@ -330,6 +330,16 @@ let structs = [
];
s_camel_name = "BTRFSSubvolume" };
+ (* btrfs qgroup show output *)
+ { defaults with
+ s_name = "btrfsqgroup";
+ s_cols = [
+ "btrfsqgroup_id", FString;
+ "btrfsqgroup_rfer", FUInt64;
+ "btrfsqgroup_excl", FUInt64;
+ ];
+ s_camel_name = "BTRFSQgroup" };
+
(* XFS info descriptor. *)
{ defaults with
s_name = "xfsinfo";
diff --git a/gobject/Makefile.inc b/gobject/Makefile.inc
index 56a2fc3..2b15a10 100644
--- a/gobject/Makefile.inc
+++ b/gobject/Makefile.inc
@@ -25,6 +25,7 @@ guestfs_gobject_headers= \
include/guestfs-gobject/tristate.h \
include/guestfs-gobject/struct-application.h \
include/guestfs-gobject/struct-application2.h \
+ include/guestfs-gobject/struct-btrfsqgroup.h \
include/guestfs-gobject/struct-btrfssubvolume.h \
include/guestfs-gobject/struct-dirent.h \
include/guestfs-gobject/struct-hivex_node.h \
@@ -105,6 +106,7 @@ guestfs_gobject_sources= \
src/tristate.c \
src/struct-application.c \
src/struct-application2.c \
+ src/struct-btrfsqgroup.c \
src/struct-btrfssubvolume.c \
src/struct-dirent.c \
src/struct-hivex_node.c \
diff --git a/java/Makefile.inc b/java/Makefile.inc
index 614caaa..34938fb 100644
--- a/java/Makefile.inc
+++ b/java/Makefile.inc
@@ -22,6 +22,7 @@
java_built_sources = \
com/redhat/et/libguestfs/Application.java \
com/redhat/et/libguestfs/Application2.java \
+ com/redhat/et/libguestfs/BTRFSQgroup.java \
com/redhat/et/libguestfs/BTRFSSubvolume.java \
com/redhat/et/libguestfs/Dirent.java \
com/redhat/et/libguestfs/HivexNode.java \
diff --git a/java/com/redhat/et/libguestfs/.gitignore
b/java/com/redhat/et/libguestfs/.gitignore
index 4882c96..1d4accc 100644
--- a/java/com/redhat/et/libguestfs/.gitignore
+++ b/java/com/redhat/et/libguestfs/.gitignore
@@ -1,5 +1,6 @@
Application.java
Application2.java
+BTRFSQgroup.java
BTRFSSubvolume.java
Dirent.java
HivexNode.java
diff --git a/po/POTFILES b/po/POTFILES
index 36f61b2..ed40658 100644
--- a/po/POTFILES
+++ b/po/POTFILES
@@ -228,6 +228,7 @@ gobject/src/optargs-xfs_repair.c
gobject/src/session.c
gobject/src/struct-application.c
gobject/src/struct-application2.c
+gobject/src/struct-btrfsqgroup.c
gobject/src/struct-btrfssubvolume.c
gobject/src/struct-dirent.c
gobject/src/struct-hivex_node.c
diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR
index 84796bf..21fbd2e 100644
--- a/src/MAX_PROC_NR
+++ b/src/MAX_PROC_NR
@@ -1 +1 @@
-432
+433
Looks OK, needs to be included in some kind of qgroup test.
Rich.
--
Richard Jones, Virtualization Group, Red Hat
http://people.redhat.com/~rjones
Read my programming and virtualization blog:
http://rwmj.wordpress.com
virt-top is 'top' for virtual machines. Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://people.redhat.com/~rjones/virt-top