[libvirt] [PATCH] virsh: add new vol-pool command

This patch adds a new "vol-pool" command to virsh, to round out the identifier conversion functions for volumes in virsh. Now it is possible to work with volumes when starting from just a volume key or volume path. --- tools/virsh.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 48 insertions(+), 0 deletions(-) diff --git a/tools/virsh.c b/tools/virsh.c index 1279f41..b45cf38 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -5975,6 +5975,53 @@ cmdVolName(vshControl *ctl, const vshCmd *cmd) } +/* + * "vol-pool" command + */ +static const vshCmdInfo info_vol_pool[] = { + {"help", N_("returns the storage pool for a given volume key or path")}, + {"desc", ""}, + {NULL, NULL} +}; + +static const vshCmdOptDef opts_vol_pool[] = { + {"vol", VSH_OT_DATA, VSH_OFLAG_REQ, N_("volume key or path")}, + {NULL, 0, 0, NULL} +}; + +static int +cmdVolPool(vshControl *ctl, const vshCmd *cmd) +{ + virStoragePoolPtr pool; + virStorageVolPtr vol; + + /* Check the connection to libvirtd daemon is still working */ + if (!vshConnectionUsability(ctl, ctl->conn, TRUE)) + return FALSE; + + /* Use the supplied string to locate the volume */ + if (!(vol = vshCommandOptVolBy(ctl, cmd, "vol", "pool", NULL, + VSH_BYUUID))) { + return FALSE; + } + + /* Look up the parent storage pool for the volume */ + pool = virStoragePoolLookupByVolume(vol); + if (pool == NULL) { + vshError(ctl, "%s", _("failed to get parent pool")); + virStorageVolFree(vol); + return FALSE; + } + + /* Return the name of the parent storage pool */ + vshPrint(ctl, "%s\n", virStoragePoolGetName(pool)); + + /* Cleanup */ + virStorageVolFree(vol); + virStoragePoolFree(pool); + return TRUE; +} + /* * "vol-key" command @@ -8837,6 +8884,7 @@ static const vshCmdDef commands[] = { {"vol-dumpxml", cmdVolDumpXML, opts_vol_dumpxml, info_vol_dumpxml}, {"vol-info", cmdVolInfo, opts_vol_info, info_vol_info}, {"vol-list", cmdVolList, opts_vol_list, info_vol_list}, + {"vol-pool", cmdVolPool, opts_vol_pool, info_vol_pool}, {"vol-path", cmdVolPath, opts_vol_path, info_vol_path}, {"vol-name", cmdVolName, opts_vol_name, info_vol_name}, {"vol-key", cmdVolKey, opts_vol_key, info_vol_key}, -- 1.7.0.1

On 06/08/2010 08:06 AM, Justin Clift wrote:
This patch adds a new "vol-pool" command to virsh, to round out the identifier conversion functions for volumes in virsh. Now it is possible to work with volumes when starting from just a volume key or volume path.
When resending, it helps to use 'git send-email --subject-prefix=PATCHv2' to call attention to the fact that it is a resend.
---
Also, if you list what changed between v1 and v2, it makes subsequent reviews easier for anyone who read the first version. Listing it after the --- output by git means that it is not part of the git commit message but is part of the email (here, I use git send-email --annotate to pull up an editor on everything I'm about to send, and type after the ---); but several others on this list find it easier to track their v2, v3, ... changes directly in the commit message. I kind of like the sideband effect of doing it only in the email (a year from now, when reading 'git log', I don't care how many tries it took you to get to what was actually committed, if the intermediate tries weren't also committed), but tracking the changes with 'git commit --amend' is also nice, so a compromise is to keep your interdiff changelog in the commit messages locally, then manually move the --- up a few lines when doing the 'git send-email' so that someone else doing 'git am' doesn't replay the history.
tools/virsh.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 48 insertions(+), 0 deletions(-)
Given your separate email with the virsh.pod patches for this and several other vol-* commands at once, ACK. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

On 06/09/2010 10:54 AM, Eric Blake wrote: <snip>
When resending, it helps to use 'git send-email --subject-prefix=PATCHv2' to call attention to the fact that it is a resend.
Thanks Eric. I'll resend the outstanding ones with v2 in the Subject line. Please disregard any ones without v2 prior to this message. Regards and best wishes, Justin Clift -- Salasaga - Open Source eLearning IDE http://www.salasaga.org
participants (2)
-
Eric Blake
-
Justin Clift