]> xenbits.xensource.com Git - libvirt.git/commitdiff
virsh: Check whether found volume is member of the specified storage pool
authorPeter Krempa <pkrempa@redhat.com>
Fri, 30 May 2014 12:44:55 +0000 (14:44 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 2 Jun 2014 08:56:49 +0000 (10:56 +0200)
When looking up storage volumes virsh uses multiple lookup steps. Some
of the steps don't require a pool name specified. This resulted into a
possibility that a volume would be part of a different pool than the
user specified:

Let's have a /var/lib/libvirt/images/test.qcow image in the 'default'
pool and a second pool 'emptypool':

Currently we'd return:
  $ virsh vol-info --pool emptypool /var/lib/libvirt/images/test.qcow
  Name:           test.qcow
  Type:           file
  Capacity:       100.00 MiB
  Allocation:     212.00 KiB

After the fix:
 $ tools/virsh vol-info --pool emptypool /var/lib/libvirt/images/test.qcow
 error: Requested volume '/var/lib/libvirt/images/test.qcow' is not in pool 'emptypool'

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1088667

tools/virsh-volume.c

index 55bf6f01150d2a9516689ed4c979fca810956c01..f284fa52225c841480026f22fa9f24afb4f19786 100644 (file)
@@ -104,6 +104,25 @@ vshCommandOptVolBy(vshControl *ctl, const vshCmd *cmd,
                             "might help"), n, pooloptname);
     }
 
+    /* If the pool was specified, then make sure that the returned
+     * volume is from the given pool */
+    if (pool && vol) {
+        virStoragePoolPtr volpool = NULL;
+
+        if ((volpool = virStoragePoolLookupByVolume(vol))) {
+            if (STRNEQ(virStoragePoolGetName(volpool),
+                       virStoragePoolGetName(pool))) {
+                vshResetLibvirtError();
+                vshError(ctl,
+                         _("Requested volume '%s' is not in pool '%s'"),
+                         n, virStoragePoolGetName(pool));
+                virStorageVolFree(vol);
+                vol = NULL;
+            }
+            virStoragePoolFree(volpool);
+        }
+    }
+
     if (pool)
         virStoragePoolFree(pool);