From: Hu Tao <hutao(a)cn.fujitsu.com>
Signed-off-by: Hu Tao <hutao(a)cn.fujitsu.com>
Signed-off-by: Chen Hanxiao <chenhanxiao(a)cn.fujitsu.com>
---
daemon/btrfs.c | 41 +++++++++++++++++++++++++++++++++++++++++
generator/actions.ml | 16 ++++++++++++++++
src/MAX_PROC_NR | 2 +-
3 files changed, 58 insertions(+), 1 deletion(-)
diff --git a/daemon/btrfs.c b/daemon/btrfs.c
index e1f617d..d460c19 100644
--- a/daemon/btrfs.c
+++ b/daemon/btrfs.c
@@ -1967,3 +1967,44 @@ do_btrfs_inspect_internal_rootid (const char *path)
return ret;
}
+
+char *
+do_btrfs_inspect_internal_subvolid_resolve (int64_t id, const char *fs)
+{
+ const size_t MAX_ARGS = 64;
+ const char *argv[MAX_ARGS];
+ size_t i = 0;
+ CLEANUP_FREE char *fs_buf = NULL;
+ CLEANUP_FREE char *err = NULL;
+ char *out;
+ size_t len;
+ int r;
+ char id_str[32];
+
+ fs_buf = sysroot_path (fs);
+ if (fs_buf == NULL) {
+ reply_with_perror ("malloc");
+ return NULL;
+ }
+
+ ADD_ARG (argv, i, str_btrfs);
+ ADD_ARG (argv, i, "inspect-internal");
+ ADD_ARG (argv, i, "subvolid-resolve");
+ snprintf (id_str, sizeof id_str, "%" PRIi64, id);
+ ADD_ARG (argv, i, id_str);
+ ADD_ARG (argv, i, fs_buf);
+ ADD_ARG (argv, i, NULL);
+
+ r = commandv (&out, &err, argv);
+ if (r == -1) {
+ reply_with_error ("%s: %s", fs, err);
+ return NULL;
+ }
+
+ /* Trim trailing '\n' */
+ len = strlen (out);
+ if (len > 0 && out[len-1] == '\n')
+ out[len-1] = '\0';
+
+ return out;
+}
diff --git a/generator/actions.ml b/generator/actions.ml
index be4cc98..e404f9f 100644
--- a/generator/actions.ml
+++ b/generator/actions.ml
@@ -12490,6 +12490,22 @@ Show status of running or finished scrub on a btrfs
filesystem." };
longdesc = "\
Get tree ID of the containing subvolume of path." };
+ { defaults with
+ name = "btrfs_inspect_internal_subvolid_resolve";
+ style = RString "path", [Int64 "id"; Pathname "fs"],
[];
+ proc_nr = Some 451;
+ optional = Some "btrfs"; camel_name =
"BTRFSInspectInternalSubvolIdResolve";
+ tests = [
+ InitPartition, Always, TestRun (
+ [["mkfs_btrfs"; "/dev/sda1"; ""; "";
"NOARG"; ""; "NOARG"; "NOARG"; "";
""];
+ ["mount"; "/dev/sda1"; "/"];
+ ["btrfs_subvolume_create"; "/sub1"; "NOARG"];
+ ["btrfs_inspect_internal_subvolid_resolve"; "256";
"/"]]), [];
+ ];
+ shortdesc = "get path for the given subvolume ID";
+ longdesc = "\
+Get path on a btrfs filesystem for the given subvolume ID." };
+
]
(* Non-API meta-commands available only in guestfish.
diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR
index 29ba0df..4619a8a 100644
--- a/src/MAX_PROC_NR
+++ b/src/MAX_PROC_NR
@@ -1 +1 @@
-450
+451
--
2.1.0