[PATCH 0/2] btrfs: add support to btrfs filesystem show
Chen Hanxiao (2): New API: btrfs_filesystem_show New API: btrfs_filesystem_show_all daemon/btrfs.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ generator/actions.ml | 21 +++++++++++++++++++++ src/MAX_PROC_NR | 2 +- 3 files changed, 73 insertions(+), 1 deletion(-) -- 2.1.0
Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- daemon/btrfs.c | 26 ++++++++++++++++++++++++++ generator/actions.ml | 10 ++++++++++ src/MAX_PROC_NR | 2 +- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/daemon/btrfs.c b/daemon/btrfs.c index d4b3207..df2fbf6 100644 --- a/daemon/btrfs.c +++ b/daemon/btrfs.c @@ -1608,6 +1608,32 @@ do_btrfs_filesystem_defragment (const char *path, int flush, const char *compres return 0; } +char * +do_btrfs_filesystem_show (const char *device) +{ + const size_t MAX_ARGS = 64; + const char *argv[MAX_ARGS]; + size_t i = 0; + CLEANUP_FREE char *err = NULL; + char *out = NULL; + int r; + + ADD_ARG (argv, i, str_btrfs); + ADD_ARG (argv, i, "filesystem"); + ADD_ARG (argv, i, "show"); + ADD_ARG (argv, i, device); + ADD_ARG (argv, i, NULL); + + r = commandv (&out, &err, argv); + if (r == -1) { + reply_with_error ("%s: %s", device, err); + free(out); + return NULL; + } + + return out; +} + int do_btrfs_rescue_chunk_recover (const char *device) { diff --git a/generator/actions.ml b/generator/actions.ml index 9f32cb5..e6cd8f2 100644 --- a/generator/actions.ml +++ b/generator/actions.ml @@ -12522,6 +12522,16 @@ This will Enable extended inode refs." }; longdesc = "\ This enable skinny metadata extent refs." }; + { defaults with + name = "btrfs_filesystem_show"; + style = RString "output", [Device "device"], []; + proc_nr = Some 453; + optional = Some "btrfs"; camel_name = "BTRFSFilesystemShow"; + test_excuse = "can't be tested becasue output will vary from each mkfs.btrfs"; + shortdesc = "show btrfs filesystem with some additional info"; + longdesc = "\ +This show btrfs filesystem with some additional info." }; + ] (* 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
AFAICT this API doesn't work: $ ./run guestfish -N fs:btrfs btrfs-filesystem-show /dev/sda1 libguestfs: error: btrfs_filesystem_show: /dev/sda1: When I tried the btrfs-filesystem-show-all API, I see a lot of structure in the output: $ ./run guestfish -N fs:btrfs btrfs-filesystem-show-all Label: none uuid: f7754d86-baa1-40e7-a563-46976e81d64c Total devices 1 FS bytes used 28.00KiB devid 1 size 99.88MiB used 12.00MiB path /dev/sda1 Btrfs v3.18 Usually we should try to turn that text into structs, otherwise every consumer of libguestfs has to write parsing code themselves. *However* in this case I'm having a hard time understanding why anyone would want to use the API. Most likely if they were debugging a btrfs problem, they'd be using 'virt-rescue' and would be able to run arbitrary commands. Some of the other information, like UUID and label is available through other APIs (eg. get-uuid). Other information like the layout of devices could be modelled with some very complex structs on the libguestfs side, but does anyone need this? 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
-----Original Message----- From: Richard W.M. Jones [mailto:rjones@redhat.com] Sent: Thursday, March 05, 2015 8:59 PM To: Chen, Hanxiao/陈 晗霄 Cc: libguestfs@redhat.com Subject: Re: [Libguestfs] [PATCH 1/2] New API: btrfs_filesystem_show
AFAICT this API doesn't work:
$ ./run guestfish -N fs:btrfs btrfs-filesystem-show /dev/sda1 libguestfs: error: btrfs_filesystem_show: /dev/sda1:
That might be a bug of btrfs-progs. v3.17 works fine. I'll fix it.
When I tried the btrfs-filesystem-show-all API, I see a lot of structure in the output:
$ ./run guestfish -N fs:btrfs btrfs-filesystem-show-all Label: none uuid: f7754d86-baa1-40e7-a563-46976e81d64c Total devices 1 FS bytes used 28.00KiB devid 1 size 99.88MiB used 12.00MiB path /dev/sda1
Btrfs v3.18
Usually we should try to turn that text into structs, otherwise every consumer of libguestfs has to write parsing code themselves.
*However* in this case I'm having a hard time understanding why anyone would want to use the API. Most likely if they were debugging a btrfs problem, they'd be using 'virt-rescue' and would be able to run arbitrary commands. Some of the other information, like UUID and label is available through other APIs (eg. get-uuid). Other information like the layout of devices could be modelled with some very complex structs on the libguestfs side, but does anyone need this?
btrfs filesystem show could tell user info when they what to use: btrfs filesystem balance What's more, it could tell us if some of the btrfs device is missing: If we had 10 btrfs devices but one of them is missing, we could use btrfs-filesystem-show to find out which one is missing in a convenient way. Regards, - Chen
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
On Fri, Mar 06, 2015 at 07:39:36AM +0000, Chen, Hanxiao wrote:
-----Original Message----- From: Richard W.M. Jones [mailto:rjones@redhat.com] Sent: Thursday, March 05, 2015 8:59 PM To: Chen, Hanxiao/陈 晗霄 Cc: libguestfs@redhat.com Subject: Re: [Libguestfs] [PATCH 1/2] New API: btrfs_filesystem_show
AFAICT this API doesn't work:
$ ./run guestfish -N fs:btrfs btrfs-filesystem-show /dev/sda1 libguestfs: error: btrfs_filesystem_show: /dev/sda1:
That might be a bug of btrfs-progs. v3.17 works fine. I'll fix it.
When I tried the btrfs-filesystem-show-all API, I see a lot of structure in the output:
$ ./run guestfish -N fs:btrfs btrfs-filesystem-show-all Label: none uuid: f7754d86-baa1-40e7-a563-46976e81d64c Total devices 1 FS bytes used 28.00KiB devid 1 size 99.88MiB used 12.00MiB path /dev/sda1
Btrfs v3.18
Usually we should try to turn that text into structs, otherwise every consumer of libguestfs has to write parsing code themselves.
*However* in this case I'm having a hard time understanding why anyone would want to use the API. Most likely if they were debugging a btrfs problem, they'd be using 'virt-rescue' and would be able to run arbitrary commands. Some of the other information, like UUID and label is available through other APIs (eg. get-uuid). Other information like the layout of devices could be modelled with some very complex structs on the libguestfs side, but does anyone need this?
btrfs filesystem show could tell user info when they what to use: btrfs filesystem balance
What's more, it could tell us if some of the btrfs device is missing: If we had 10 btrfs devices but one of them is missing, we could use btrfs-filesystem-show to find out which one is missing in a convenient way.
I don't doubt that it's useful, but these kind of user-facing debugging operations would probably be done using 'virt-rescue'. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-builder quickly builds VMs from scratch http://libguestfs.org/virt-builder.1.html
-----Original Message----- From: Richard W.M. Jones [mailto:rjones@redhat.com] Sent: Friday, March 06, 2015 4:43 PM To: Chen, Hanxiao/陈 晗霄 Cc: libguestfs@redhat.com Subject: Re: [Libguestfs] [PATCH 1/2] New API: btrfs_filesystem_show
On Fri, Mar 06, 2015 at 07:39:36AM +0000, Chen, Hanxiao wrote:
-----Original Message----- From: Richard W.M. Jones [mailto:rjones@redhat.com] Sent: Thursday, March 05, 2015 8:59 PM To: Chen, Hanxiao/陈 晗霄 Cc: libguestfs@redhat.com Subject: Re: [Libguestfs] [PATCH 1/2] New API: btrfs_filesystem_show
AFAICT this API doesn't work:
$ ./run guestfish -N fs:btrfs btrfs-filesystem-show /dev/sda1 libguestfs: error: btrfs_filesystem_show: /dev/sda1:
That might be a bug of btrfs-progs. v3.17 works fine. I'll fix it.
When I tried the btrfs-filesystem-show-all API, I see a lot of structure in the output:
$ ./run guestfish -N fs:btrfs btrfs-filesystem-show-all Label: none uuid: f7754d86-baa1-40e7-a563-46976e81d64c Total devices 1 FS bytes used 28.00KiB devid 1 size 99.88MiB used 12.00MiB path /dev/sda1
Btrfs v3.18
Usually we should try to turn that text into structs, otherwise every consumer of libguestfs has to write parsing code themselves.
*However* in this case I'm having a hard time understanding why anyone would want to use the API. Most likely if they were debugging a btrfs problem, they'd be using 'virt-rescue' and would be able to run arbitrary commands. Some of the other information, like UUID and label is available through other APIs (eg. get-uuid). Other information like the layout of devices could be modelled with some very complex structs on the libguestfs side, but does anyone need this?
btrfs filesystem show could tell user info when they what to use: btrfs filesystem balance
What's more, it could tell us if some of the btrfs device is missing: If we had 10 btrfs devices but one of them is missing, we could use btrfs-filesystem-show to find out which one is missing in a convenient way.
I don't doubt that it's useful, but these kind of user-facing debugging operations would probably be done using 'virt-rescue'.
Thanks for the clarification, I see. Regards, - Chen
-----Original Message----- From: Richard W.M. Jones [mailto:rjones@redhat.com] Sent: Friday, March 06, 2015 4:43 PM To: Chen, Hanxiao/陈 晗霄 Cc: libguestfs@redhat.com Subject: Re: [Libguestfs] [PATCH 1/2] New API: btrfs_filesystem_show
On Fri, Mar 06, 2015 at 07:39:36AM +0000, Chen, Hanxiao wrote:
-----Original Message----- From: Richard W.M. Jones [mailto:rjones@redhat.com] Sent: Thursday, March 05, 2015 8:59 PM To: Chen, Hanxiao/陈 晗霄 Cc: libguestfs@redhat.com Subject: Re: [Libguestfs] [PATCH 1/2] New API: btrfs_filesystem_show
AFAICT this API doesn't work:
$ ./run guestfish -N fs:btrfs btrfs-filesystem-show /dev/sda1 libguestfs: error: btrfs_filesystem_show: /dev/sda1:
That might be a bug of btrfs-progs. v3.17 works fine. I'll fix it.
When I tried the btrfs-filesystem-show-all API, I see a lot of structure in the output:
$ ./run guestfish -N fs:btrfs btrfs-filesystem-show-all Label: none uuid: f7754d86-baa1-40e7-a563-46976e81d64c Total devices 1 FS bytes used 28.00KiB devid 1 size 99.88MiB used 12.00MiB path /dev/sda1
Btrfs v3.18
Usually we should try to turn that text into structs, otherwise every consumer of libguestfs has to write parsing code themselves.
*However* in this case I'm having a hard time understanding why anyone would want to use the API. Most likely if they were debugging a btrfs problem, they'd be using 'virt-rescue' and would be able to run arbitrary commands. Some of the other information, like UUID and label is available through other APIs (eg. get-uuid). Other information like the layout of devices could be modelled with some very complex structs on the libguestfs side, but does anyone need this?
btrfs filesystem show could tell user info when they what to use: btrfs filesystem balance
What's more, it could tell us if some of the btrfs device is missing: If we had 10 btrfs devices but one of them is missing, we could use btrfs-filesystem-show to find out which one is missing in a convenient way.
I don't doubt that it's useful, but these kind of user-facing debugging operations would probably be done using 'virt-rescue'.
Hi, Rich I think we should have a API btrfs_filesystem_show_all: #btrfs fi show Label: none uuid: e34452fa-5444-4e7b-9faa-c26fa1b83686 Total devices 1 FS bytes used 176.00KiB devid 1 size 1.00GiB used 236.00MiB path /dev/sda6 Label: none uuid: 9cdb73b9-d5b9-46c4-9395-25a952e7922a Total devices 5 FS bytes used 112.00KiB devid 1 size 10.00GiB used 1.02GiB path /dev/sdb devid 2 size 10.00GiB used 2.00GiB path /dev/sdd devid 3 size 10.00GiB used 2.00GiB path /dev/sde ... If VM has two btrfs filesystem, this API could tell user which device runs on which btrfs fs. For btrfs [fs1] with uuid 9cdb73b9-d5b9-46c4-9395-25a952e7922a, we could know it runs on: /dev/[sdb|sdd|sde] -> img1,img2,img3 Other one [fs2] runs on /dev/sda6 -> img4 If we want to do something like backup part of btrfs fs data, such as we want to drop data of fs2, we could know which VM image should be backup. AFAIK, it's the only way we could know this. So I think we should provide API: btrfs_filesystem_show_all https://www.redhat.com/archives/libguestfs/2015-March/msg00029.html Regards, - Chen
On Wed, Mar 25, 2015 at 09:39:35AM +0000, Chen, Hanxiao wrote:
So I think we should provide API:
OK, but ...
btrfs_filesystem_show_all https://www.redhat.com/archives/libguestfs/2015-March/msg00029.html
... you can't just dump out the text output of btrfs filesystem show and require API users to parse it. It has to be parsed by the daemon into some suitable structures. It's a lot of work, but if there is a patch I'll take a look. 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
Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- daemon/btrfs.c | 25 +++++++++++++++++++++++++ generator/actions.ml | 11 +++++++++++ src/MAX_PROC_NR | 2 +- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/daemon/btrfs.c b/daemon/btrfs.c index df2fbf6..1c040a4 100644 --- a/daemon/btrfs.c +++ b/daemon/btrfs.c @@ -1634,6 +1634,31 @@ do_btrfs_filesystem_show (const char *device) return out; } +char * +do_btrfs_filesystem_show_all (void) +{ + const size_t MAX_ARGS = 64; + const char *argv[MAX_ARGS]; + size_t i = 0; + CLEANUP_FREE char *err = NULL; + char *out = NULL; + int r; + + ADD_ARG (argv, i, str_btrfs); + ADD_ARG (argv, i, "filesystem"); + ADD_ARG (argv, i, "show"); + ADD_ARG (argv, i, NULL); + + r = commandv (&out, &err, argv); + if (r == -1) { + reply_with_error ("%s", err); + free(out); + return NULL; + } + + return out; +} + int do_btrfs_rescue_chunk_recover (const char *device) { diff --git a/generator/actions.ml b/generator/actions.ml index e6cd8f2..db20875 100644 --- a/generator/actions.ml +++ b/generator/actions.ml @@ -12532,6 +12532,17 @@ This enable skinny metadata extent refs." }; longdesc = "\ This show btrfs filesystem with some additional info." }; + { defaults with + name = "btrfs_filesystem_show_all"; + style = RString "output", [], []; + (*style = RString "output", [], [OString "device"];*) + proc_nr = Some 454; + optional = Some "btrfs"; camel_name = "BTRFSFilesystemShowAll"; + test_excuse = "can't be tested becasue output will vary from each mkfs.btrfs"; + shortdesc = "show all devices run btrfs filesystem with some additional info"; + longdesc = "\ +This show all devices run btrfs filesystem with some additional info." }; + ] (* Non-API meta-commands available only in guestfish. diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR index 534b992..515f19a 100644 --- a/src/MAX_PROC_NR +++ b/src/MAX_PROC_NR @@ -1 +1 @@ -453 +454 -- 2.1.0
participants (3)
-
Chen Hanxiao -
Chen, Hanxiao -
Richard W.M. Jones