]> xenbits.xensource.com Git - libvirt.git/commitdiff
virsh: add new vol-pool command
authorJustin Clift <justin@salasaga.org>
Tue, 8 Jun 2010 14:06:29 +0000 (00:06 +1000)
committerEric Blake <eblake@redhat.com>
Wed, 9 Jun 2010 00:55:07 +0000 (18:55 -0600)
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

index c0b611280110d23cc527cb872d008987f1c1ec30..2684128aeae31592734adb4a60a907575188575e 100644 (file)
@@ -5980,6 +5980,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
@@ -8842,6 +8889,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},