[Libguestfs] [PATCH 13/16] New API: btrfs_inspect_rootid

Hu Tao hutao at cn.fujitsu.com
Fri Jan 16 02:23:48 UTC 2015


Signed-off-by: Hu Tao <hutao at cn.fujitsu.com>
---
 daemon/btrfs.c       | 38 ++++++++++++++++++++++++++++++++++++++
 generator/actions.ml | 15 +++++++++++++++
 src/MAX_PROC_NR      |  2 +-
 3 files changed, 54 insertions(+), 1 deletion(-)

diff --git a/daemon/btrfs.c b/daemon/btrfs.c
index e9b6f26..c6ca3c3 100644
--- a/daemon/btrfs.c
+++ b/daemon/btrfs.c
@@ -1699,3 +1699,41 @@ do_btrfs_rescue_super_recover (const char *device)
 
   return 0;
 }
+
+int64_t
+do_btrfs_inspect_rootid (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;
+  int64_t ret;
+
+  path_buf = sysroot_path (path);
+  if (path_buf == NULL) {
+    reply_with_perror ("malloc");
+    return -1;
+  }
+
+  ADD_ARG (argv, i, str_btrfs);
+  ADD_ARG (argv, i, "inspect");
+  ADD_ARG (argv, i, "rootid");
+  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 -1;
+  }
+
+  if (sscanf (out, "%" SCNi64, &ret) != 1) {
+    reply_with_error ("%s: could not parse rootid: %s.", argv[0], out);
+    return -1;
+  }
+
+  return ret;
+}
diff --git a/generator/actions.ml b/generator/actions.ml
index be55a68..f5c4c68 100644
--- a/generator/actions.ml
+++ b/generator/actions.ml
@@ -12392,6 +12392,21 @@ Recover the chunk tree of btrfs filesystem by scannning the devices one by one."
     longdesc = "\
 Recover bad superblocks from good copies." };
 
+  { defaults with
+    name = "btrfs_inspect_rootid";
+    style = RInt64 "id", [Pathname "path"], [];
+    proc_nr = Some 446;
+    optional = Some "btrfs"; camel_name = "BTRFSInspectRootid";
+    tests = [
+      InitPartition, Always, TestRun (
+        [["mkfs_btrfs"; "/dev/sda1"; ""; ""; "NOARG"; ""; "NOARG"; "NOARG"; ""; ""];
+         ["mount"; "/dev/sda1"; "/"];
+         ["btrfs_inspect_rootid"; "/"]]), [];
+    ];
+    shortdesc = "get tree ID of the containing subvolume of path";
+    longdesc = "\
+Get tree ID of the containing subvolume of path." };
+
 ]
 
 (* Non-API meta-commands available only in guestfish.
diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR
index e5a135a..0187835 100644
--- a/src/MAX_PROC_NR
+++ b/src/MAX_PROC_NR
@@ -1 +1 @@
-445
+446
-- 
2.1.0




More information about the Libguestfs mailing list