[libvirt] [PATCH v2] virsh: Two new fields for command domblklist

Disk "type" and "device" are generally interesting stuffs the user who wants to known too. To not breaking the scripts which parses the output field, new options "--details" is introduced to output the two introduced fields. --- tools/virsh.c | 32 +++++++++++++++++++++++++++++--- tools/virsh.pod | 19 ++++++++++--------- 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/tools/virsh.c b/tools/virsh.c index 734c55d..6f1acf6 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -1906,7 +1906,7 @@ cmdDomblkinfo(vshControl *ctl, const vshCmd *cmd) */ static const vshCmdInfo info_domblklist[] = { {"help", N_("list all domain blocks")}, - {"desc", N_("Get the names of block devices for a domain.")}, + {"desc", N_("Get the summary of block devices for a domain.")}, {NULL, NULL} }; @@ -1914,6 +1914,8 @@ static const vshCmdOptDef opts_domblklist[] = { {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")}, {"inactive", VSH_OT_BOOL, 0, N_("get inactive rather than running configuration")}, + {"details", VSH_OT_BOOL, 0, + N_("additionally display the type and device value")}, {NULL, 0, 0, NULL} }; @@ -1929,10 +1931,13 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd) int ndisks; xmlNodePtr *disks = NULL; int i; + bool details = false; if (vshCommandOptBool(cmd, "inactive")) flags |= VIR_DOMAIN_XML_INACTIVE; + details = vshCommandOptBool(cmd, "details"); + if (!vshConnectionUsability(ctl, ctl->conn)) return false; @@ -1951,14 +1956,27 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd) if (ndisks < 0) goto cleanup; - vshPrint(ctl, "%-10s %s\n", _("Target"), _("Source")); + if (details) + vshPrint(ctl, "%-10s %-10s %-10s %s\n", _("Type"), + _("Device"), _("Target"), _("Source")); + else + vshPrint(ctl, "%-10s %s\n", _("Target"), _("Source")); + vshPrint(ctl, "------------------------------------------------\n"); for (i = 0; i < ndisks; i++) { + char *type; + char *device; char *target; char *source; ctxt->node = disks[i]; + + if (details) { + type = virXPathString("string(./@type)", ctxt); + device = virXPathString("string(./@device)", ctxt); + } + target = virXPathString("string(./target/@dev)", ctxt); if (!target) { vshError(ctl, "unable to query block list"); @@ -1968,7 +1986,15 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd) "|./source/@dev" "|./source/@dir" "|./source/@name)", ctxt); - vshPrint(ctl, "%-10s %s\n", target, source ? source : "-"); + if (details) { + vshPrint(ctl, "%-10s %-10s %-10s %s\n", type, device, + target, source ? source : "-"); + VIR_FREE(type); + VIR_FREE(device); + } else { + vshPrint(ctl, "%-10s %s\n", target, source ? source : "-"); + } + VIR_FREE(target); VIR_FREE(source); } diff --git a/tools/virsh.pod b/tools/virsh.pod index d9ca46c..9fd786d 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -512,15 +512,16 @@ to a unique target name (<target dev='name'/>) or source file (<source file='name'/>) for one of the disk devices attached to I<domain> (see also B<domblklist> for listing these names). -=item B<domblklist> I<domain> [I<--inactive>] - -Print a table showing the names of all block devices associated with -I<domain>, as well as the path to the source of each device. If -I<--inactive> is specified, query the block devices that will be used -on the next boot, rather than those currently in use by a running -domain. Other contexts that require a block device name (such as -I<domblkinfo> or I<snapshot-create> for disk snapshots) will accept -either target or unique source names printed by this command. +=item B<domblklist> I<domain> [I<--inactive>] [I<--details>] + +Print a table showing the brief information of all block devices +associated with I<domain>. If I<--inactive> is specified, query the +block devices that will be used on the next boot, rather than those +currently in use by a running domain. If I<--details> is specified, +disk type and device value will be printed additionally. Other +contexts that require a block device name (such as I<domblkinfo> +or I<snapshot-create> for disk snapshots) will accept either target +or unique source names printed by this command. =item B<domiflist> I<domain> [I<--inactive>] -- 1.7.7.3

On 01/12/2012 03:53 AM, Osier Yang wrote:
Disk "type" and "device" are generally interesting stuffs the
s/stuffs/stuff/
user who wants to known too. To not breaking the scripts which
s/who wants to known too/may want to know, too/ s/breaking the/break any/
parses the output field, new options "--details" is introduced
s/parses/parsed/ s/new options/a new option/
to output the two introduced fields. --- tools/virsh.c | 32 +++++++++++++++++++++++++++++--- tools/virsh.pod | 19 ++++++++++--------- 2 files changed, 39 insertions(+), 12 deletions(-)
+++ b/tools/virsh.pod @@ -512,15 +512,16 @@ to a unique target name (<target dev='name'/>) or source file (<source file='name'/>) for one of the disk devices attached to I<domain> (see also B<domblklist> for listing these names).
-=item B<domblklist> I<domain> [I<--inactive>] - -Print a table showing the names of all block devices associated with -I<domain>, as well as the path to the source of each device. If -I<--inactive> is specified, query the block devices that will be used -on the next boot, rather than those currently in use by a running -domain. Other contexts that require a block device name (such as -I<domblkinfo> or I<snapshot-create> for disk snapshots) will accept -either target or unique source names printed by this command. +=item B<domblklist> I<domain> [I<--inactive>] [I<--details>] + +Print a table showing the brief information of all block devices +associated with I<domain>. If I<--inactive> is specified, query the +block devices that will be used on the next boot, rather than those +currently in use by a running domain. If I<--details> is specified, +disk type and device value will be printed additionally. Other
s/be printed additionally/also be printed/
+contexts that require a block device name (such as I<domblkinfo> +or I<snapshot-create> for disk snapshots) will accept either target +or unique source names printed by this command.
ACK with the grammar cleanups. And don't feel bad - English can be a tough language; you did quite well at getting the point across, even if I was able to provide some ideas to polish the final wording. :) -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On 2012年01月13日 07:00, Eric Blake wrote:
On 01/12/2012 03:53 AM, Osier Yang wrote:
Disk "type" and "device" are generally interesting stuffs the
s/stuffs/stuff/
user who wants to known too. To not breaking the scripts which
s/who wants to known too/may want to know, too/ s/breaking the/break any/
parses the output field, new options "--details" is introduced
s/parses/parsed/ s/new options/a new option/
to output the two introduced fields. --- tools/virsh.c | 32 +++++++++++++++++++++++++++++--- tools/virsh.pod | 19 ++++++++++--------- 2 files changed, 39 insertions(+), 12 deletions(-)
+++ b/tools/virsh.pod @@ -512,15 +512,16 @@ to a unique target name (<target dev='name'/>) or source file (<source file='name'/>) for one of the disk devices attached to I<domain> (see also B<domblklist> for listing these names).
-=item B<domblklist> I<domain> [I<--inactive>] - -Print a table showing the names of all block devices associated with -I<domain>, as well as the path to the source of each device. If -I<--inactive> is specified, query the block devices that will be used -on the next boot, rather than those currently in use by a running -domain. Other contexts that require a block device name (such as -I<domblkinfo> or I<snapshot-create> for disk snapshots) will accept -either target or unique source names printed by this command. +=item B<domblklist> I<domain> [I<--inactive>] [I<--details>] + +Print a table showing the brief information of all block devices +associated with I<domain>. If I<--inactive> is specified, query the +block devices that will be used on the next boot, rather than those +currently in use by a running domain. If I<--details> is specified, +disk type and device value will be printed additionally. Other
s/be printed additionally/also be printed/
+contexts that require a block device name (such as I<domblkinfo> +or I<snapshot-create> for disk snapshots) will accept either target +or unique source names printed by this command.
ACK with the grammar cleanups. And don't feel bad - English can be a tough language; you did quite well at getting the point across, even if I was able to provide some ideas to polish the final wording. :)
Thanks, pushed. This makes me feel better. :) Osier
participants (2)
-
Eric Blake
-
Osier Yang