diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c index 55bf6f0115..f284fa5222 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);