Chen Hanxiao
2015-Feb-21 10:02 UTC
[Libguestfs] [PATCH v2 0/4] btrfs: add support to btrfs inspect-internal
This series adds new APIs to support btrfs inspect-internal. v2: - use full name of btrfs command as inspect-internal Hu Tao (4): New API: btrfs_inspect_internal_rootid New API: btrfs_inspect_internal_subvolid_resolve New API: btrfs_inspect_internal_inode_resolve New API: btrfs_inspect_internal_logical_resolve daemon/btrfs.c | 161 +++++++++++++++++++++++++++++++++++++++++++++++++++ generator/actions.ml | 56 ++++++++++++++++++ src/MAX_PROC_NR | 2 +- 3 files changed, 218 insertions(+), 1 deletion(-) -- 2.1.0
Chen Hanxiao
2015-Feb-21 10:02 UTC
[Libguestfs] [PATCH v2 1/4] New API: btrfs_inspect_internal_rootid
From: Hu Tao <hutao@cn.fujitsu.com> Signed-off-by: Hu Tao <hutao@cn.fujitsu.com> Signed-off-by: Chen Hanxiao <chenhanxiao@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 6b93973..e1f617d 100644 --- a/daemon/btrfs.c +++ b/daemon/btrfs.c @@ -1929,3 +1929,41 @@ error: free (ret); return NULL; } + +int64_t +do_btrfs_inspect_internal_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-internal"); + 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 c995787..be4cc98 100644 --- a/generator/actions.ml +++ b/generator/actions.ml @@ -12475,6 +12475,21 @@ Show the status of a running or paused balance on a btrfs filesystem." }; longdesc = "\ Show status of running or finished scrub on a btrfs filesystem." }; + { defaults with + name = "btrfs_inspect_internal_rootid"; + style = RInt64 "id", [Pathname "path"], []; + proc_nr = Some 450; + optional = Some "btrfs"; camel_name = "BTRFSInspectRootid"; + tests = [ + InitPartition, Always, TestRun ( + [["mkfs_btrfs"; "/dev/sda1"; ""; ""; "NOARG"; ""; "NOARG"; "NOARG"; ""; ""]; + ["mount"; "/dev/sda1"; "/"]; + ["btrfs_inspect_internal_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 2b20fd0..29ba0df 100644 --- a/src/MAX_PROC_NR +++ b/src/MAX_PROC_NR @@ -1 +1 @@ -449 +450 -- 2.1.0
Chen Hanxiao
2015-Feb-21 10:02 UTC
[Libguestfs] [PATCH v2 2/4] New API: btrfs_inspect_internal_subvolid_resolve
From: Hu Tao <hutao@cn.fujitsu.com> Signed-off-by: Hu Tao <hutao@cn.fujitsu.com> Signed-off-by: Chen Hanxiao <chenhanxiao@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
Chen Hanxiao
2015-Feb-21 10:02 UTC
[Libguestfs] [PATCH v2 3/4] New API: btrfs_inspect_internal_inode_resolve
From: Hu Tao <hutao@cn.fujitsu.com> Signed-off-by: Hu Tao <hutao@cn.fujitsu.com> Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- daemon/btrfs.c | 41 +++++++++++++++++++++++++++++++++++++++++ generator/actions.ml | 15 +++++++++++++++ src/MAX_PROC_NR | 2 +- 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/daemon/btrfs.c b/daemon/btrfs.c index d460c19..2c2eb57 100644 --- a/daemon/btrfs.c +++ b/daemon/btrfs.c @@ -2008,3 +2008,44 @@ do_btrfs_inspect_internal_subvolid_resolve (int64_t id, const char *fs) return out; } + +char * +do_btrfs_inspect_internal_inode_resolve (int64_t inode, 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 inode_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, "inode-resolve"); + snprintf (inode_str, sizeof inode_str, "%" PRIi64, inode); + ADD_ARG (argv, i, inode_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 e404f9f..0014c7d 100644 --- a/generator/actions.ml +++ b/generator/actions.ml @@ -12506,6 +12506,21 @@ Get tree ID of the containing subvolume of path." }; longdesc = "\ Get path on a btrfs filesystem for the given subvolume ID." }; + { defaults with + name = "btrfs_inspect_internal_inode_resolve"; + style = RString "path", [Int64 "inode"; Pathname "fs"], []; + proc_nr = Some 452; + optional = Some "btrfs"; camel_name = "BTRFSInspectInternalInodeResolve"; + tests = [ + InitPartition, Always, TestRun ( + [["mkfs_btrfs"; "/dev/sda1"; ""; ""; "NOARG"; ""; "NOARG"; "NOARG"; ""; ""]; + ["mount"; "/dev/sda1"; "/"]; + ["btrfs_inspect_internal_inode_resolve"; "256"; "/"]]), []; + ]; + shortdesc = "get path for the given inode"; + longdesc = "\ +Get path on a btrfs filesystem for the given inode." }; + ] (* Non-API meta-commands available only in guestfish. diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR index 4619a8a..8670c73 100644 --- a/src/MAX_PROC_NR +++ b/src/MAX_PROC_NR @@ -1 +1 @@ -451 +452 -- 2.1.0
Chen Hanxiao
2015-Feb-21 10:02 UTC
[Libguestfs] [PATCH v2 4/4] New API: btrfs_inspect_internal_logical_resolve
From: Hu Tao <hutao@cn.fujitsu.com> Signed-off-by: Hu Tao <hutao@cn.fujitsu.com> Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- daemon/btrfs.c | 41 +++++++++++++++++++++++++++++++++++++++++ generator/actions.ml | 10 ++++++++++ src/MAX_PROC_NR | 2 +- 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/daemon/btrfs.c b/daemon/btrfs.c index 2c2eb57..d84c28e 100644 --- a/daemon/btrfs.c +++ b/daemon/btrfs.c @@ -2049,3 +2049,44 @@ do_btrfs_inspect_internal_inode_resolve (int64_t inode, const char *fs) return out; } + +char * +do_btrfs_inspect_internal_logical_resolve (int64_t logical, 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 logical_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, "logical-resolve"); + snprintf (logical_str, sizeof logical_str, "%" PRIi64, logical); + ADD_ARG (argv, i, logical_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 0014c7d..7b7655d 100644 --- a/generator/actions.ml +++ b/generator/actions.ml @@ -12521,6 +12521,16 @@ Get path on a btrfs filesystem for the given subvolume ID." }; longdesc = "\ Get path on a btrfs filesystem for the given inode." }; + { defaults with + name = "btrfs_inspect_internal_logical_resolve"; + style = RString "path", [Int64 "logical"; Pathname "fs"], []; + proc_nr = Some 453; + optional = Some "btrfs"; camel_name = "BTRFSInspectInternalLogicalResolve"; + test_excuse = "can't determine a valid logical address for test"; + shortdesc = "get path for the given logical address"; + longdesc = "\ +Get path on a btrfs filesystem for the logical address." }; + ] (* Non-API meta-commands available only in guestfish. diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR index 8670c73..534b992 100644 --- a/src/MAX_PROC_NR +++ b/src/MAX_PROC_NR @@ -1 +1 @@ -452 +453 -- 2.1.0
Chen, Hanxiao
2015-Feb-26 03:11 UTC
Re: [Libguestfs] [PATCH v2 0/4] btrfs: add support to btrfs inspect-internal
> -----Original Message----- > From: libguestfs-bounces@redhat.com [mailto:libguestfs-bounces@redhat.com] On > Behalf Of Chen Hanxiao > Sent: Saturday, February 21, 2015 6:02 PM > To: libguestfs@redhat.com > Subject: [Libguestfs] [PATCH v2 0/4] btrfs: add support to btrfs inspect-internal > > This series adds new APIs to support btrfs inspect-internal. > > v2: > - use full name of btrfs command as inspect-internal > > Hu Tao (4): > New API: btrfs_inspect_internal_rootid > New API: btrfs_inspect_internal_subvolid_resolve > New API: btrfs_inspect_internal_inode_resolve > New API: btrfs_inspect_internal_logical_resolve > > daemon/btrfs.c | 161 +++++++++++++++++++++++++++++++++++++++++++++++++++ > generator/actions.ml | 56 ++++++++++++++++++ > src/MAX_PROC_NR | 2 +- > 3 files changed, 218 insertions(+), 1 deletion(-) > > --Hi, I missed the previous thread that Rich and Hu had come to a conclusion that we should not expose this debug command. Please ignore this series. Thanks, - Chen
Apparently Analagous Threads
- [PATCH 00/16] btrfs: add support to btrfs scrub, balance, rescue and inspect
- [PATCH v2 00/11] btrfs support part2: qgroup/quota commands
- [PATCH v3 00/11] btrfs support part2: qgroup/quota commands
- [PATCH 0/6] btrfs support part1: subvolume commands
- [PATCH v2 0/5] btrfs support part1: subvolume commands