From 0bd2ccdeccd6db4ac5321b01a76e39915455e5d3 Mon Sep 17 00:00:00 2001 From: Thorsten Behrens Date: Fri, 14 Feb 2014 18:49:04 +0100 Subject: [PATCH] Widening API change - accept empty path for virDomainBlockStats And provide domain summary stat in that case, for lxc backend. Use case is a container inheriting all devices from the host, e.g. when doing application containerization. --- src/libvirt.c | 8 ++++++-- tools/virsh-domain-monitor.c | 9 ++++++++- tools/virsh.pod | 5 +++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/libvirt.c b/src/libvirt.c index f38556aa1f..dcf6b53f0e 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -7750,7 +7750,9 @@ error: * an unambiguous source name of the block device (the sub-element, such as "/path/to/image"). Valid names * can be found by calling virDomainGetXMLDesc() and inspecting - * elements within //domain/devices/disk. + * elements within //domain/devices/disk. Some drivers might also + * accept the empty string for the @disk parameter, and then yield + * summary stats for the entire domain. * * Domains may have more than one block device. To get stats for * each you should make multiple calls to this function. @@ -7816,7 +7818,9 @@ error: * an unambiguous source name of the block device (the sub-element, such as "/path/to/image"). Valid names * can be found by calling virDomainGetXMLDesc() and inspecting - * elements within //domain/devices/disk. + * elements within //domain/devices/disk. Some drivers might also + * accept the empty string for the @disk parameter, and then yield + * summary stats for the entire domain. * * Domains may have more than one block device. To get stats for * each you should make multiple calls to this function. diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index de4afbb33f..6291ca5fdf 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -888,7 +888,7 @@ static const vshCmdOptDef opts_domblkstat[] = { }, {.name = "device", .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, + .flags = VSH_OFLAG_EMPTY_OK, .help = N_("block device") }, {.name = "human", @@ -954,9 +954,16 @@ cmdDomblkstat(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, &name))) return false; + /* device argument is optional now. if it's missing, supply empty + string to denote 'all devices'. A NULL device arg would violate + API contract. + */ if (vshCommandOptStringReq(ctl, cmd, "device", &device) < 0) goto cleanup; + if (!device) + device = ""; + rc = virDomainBlockStatsFlags(dom, device, NULL, &nparams, 0); /* It might fail when virDomainBlockStatsFlags is not diff --git a/tools/virsh.pod b/tools/virsh.pod index f221475e8c..a13a1c74c6 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -623,12 +623,13 @@ If I<--graceful> is specified, don't resort to extreme measures (e.g. SIGKILL) when the guest doesn't stop after a reasonable timeout; return an error instead. -=item B I I [I<--human>] +=item B I [I] [I<--human>] Get device block stats for a running domain. A I corresponds to a unique target name () or source file () for one of the disk devices attached to I (see -also B for listing these names). +also B for listing these names). On a lxc domain, omitting the +I yields device block stats summarily for the entire domain. Use I<--human> for a more human readable output.