diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c index 55bf6f01150d2a9516689ed4c979fca810956c01..f284fa52225c841480026f22fa9f24afb4f19786 100644 --- a/tools/virsh-volume.c +++ b/tools/virsh-volume.c @@ -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);