From bd9d7078949ab19fd844926a20196d5533cfdf89 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Mon, 2 May 2016 15:26:51 +0200 Subject: [PATCH] qemu: Reject invalid block copy targets for Extract the relevant parts of the existing checker and reuse them for blockcopy since copying to a non-block device creates an invalid configuration. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1209802 --- src/qemu/qemu_command.c | 14 +------------- src/qemu/qemu_domain.c | 31 +++++++++++++++++++++++++++++++ src/qemu/qemu_domain.h | 3 +++ src/qemu/qemu_driver.c | 4 ++++ 4 files changed, 39 insertions(+), 13 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index a5abf9ba18..cc06a45ac2 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -972,20 +972,8 @@ qemuCheckDiskConfig(virDomainDiskDefPtr disk) return -1; } - if (virStorageSourceGetActualType(disk->src) == VIR_STORAGE_TYPE_NETWORK) { - if (disk->src->protocol != VIR_STORAGE_NET_PROTOCOL_ISCSI) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("disk device='lun' is not supported " - "for protocol='%s'"), - virStorageNetProtocolTypeToString(disk->src->protocol)); - return -1; - } - } else if (!virStorageSourceIsBlockLocal(disk->src)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("disk device='lun' is only valid for block " - "type disk source")); + if (qemuDomainDefValidateDiskLunSource(disk->src) < 0) return -1; - } if (disk->wwn) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index cae356cc89..7540578dfb 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -5297,3 +5297,34 @@ qemuDomainDiskByName(virDomainDefPtr def, return ret; } + + +/** + * qemuDomainDefValidateDiskLunSource: + * @src: disk source struct + * + * Validate whether the disk source is valid for disk device='lun'. + * + * Returns 0 if the configuration is valid -1 and a libvirt error if the soure + * is invalid. + */ +int +qemuDomainDefValidateDiskLunSource(const virStorageSource *src) +{ + if (virStorageSourceGetActualType(src) == VIR_STORAGE_TYPE_NETWORK) { + if (src->protocol != VIR_STORAGE_NET_PROTOCOL_ISCSI) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("disk device='lun' is not supported " + "for protocol='%s'"), + virStorageNetProtocolTypeToString(src->protocol)); + return -1; + } + } else if (!virStorageSourceIsBlockLocal(src)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("disk device='lun' is only valid for block " + "type disk source")); + return -1; + } + + return 0; +} diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index 5af802c02c..c71118845d 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -666,4 +666,7 @@ void qemuDomainSecretDestroy(virDomainObjPtr vm) int qemuDomainSecretPrepare(virConnectPtr conn, virDomainObjPtr vm) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); +int qemuDomainDefValidateDiskLunSource(const virStorageSource *src) + ATTRIBUTE_NONNULL(1); + #endif /* __QEMU_DOMAIN_H__ */ diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 396e64cf0d..b0cfb10db4 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -16759,6 +16759,10 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm, if (qemuDomainDiskBlockJobIsActive(disk)) goto endjob; + if (disk->device == VIR_DOMAIN_DISK_DEVICE_LUN && + qemuDomainDefValidateDiskLunSource(mirror) < 0) + goto endjob; + if (!(virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DRIVE_MIRROR) && virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKJOB_ASYNC))) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", -- GitLab