[libvirt] [PATCH 06/10] qemu: hotplug: Reuse qemuHotplugDiskSourceRemove for disk backend removal
Ján Tomko
jtomko at redhat.com
Thu Jul 19 12:52:51 UTC 2018
On Tue, Jul 17, 2018 at 02:14:26PM +0200, Peter Krempa wrote:
>Add code which will convert a disk definition into
>qemuHotplugDiskSourceData and then reuse qemuHotplugDiskSourceRemove to
>remove all the backend related objects.
>
>This unifies the detach code as much as possible with the already
>existing helpers and will allow reuse this infrastructure when changing
>removable disk media.
>
>Signed-off-by: Peter Krempa <pkrempa at redhat.com>
>---
> src/qemu/qemu_hotplug.c | 129 +++++++++++++++++++++++++++++++++++-------------
> 1 file changed, 94 insertions(+), 35 deletions(-)
>
>diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
>index f1b18fcc7d..3ee74c8e40 100644
>--- a/src/qemu/qemu_hotplug.c
>+++ b/src/qemu/qemu_hotplug.c
>@@ -373,6 +373,96 @@ qemuHotplugDiskSourceDataFree(qemuHotplugDiskSourceDataPtr data)
> }
>
>
>+/**
>+ * qemuDomainRemoveDiskStorageSourcePrepareData:
>+ * @src: disk source structure
>+ * @driveAlias: Alias of the -drive backend, the pointer is always consumed
>+ *
>+ * Prepare qemuBlockStorageSourceAttachDataPtr for detaching a single source
>+ * from a VM. If @driveAlias is NULL -blockdev is assumed.
>+ */
>+static qemuBlockStorageSourceAttachDataPtr
>+qemuHotplugRemoveStorageSourcePrepareData(virStorageSourcePtr src,
>+ char *driveAlias)
>+
>+{
>+ qemuDomainStorageSourcePrivatePtr srcpriv = QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(src);
>+ qemuBlockStorageSourceAttachDataPtr data;
>+ qemuBlockStorageSourceAttachDataPtr ret = NULL;
>+
>+ if (VIR_ALLOC(data) < 0)
>+ goto cleanup;
>+
>+ if (driveAlias) {
>+ VIR_STEAL_PTR(data->driveAlias, driveAlias);
>+ data->driveAdded = true;
>+ } else {
>+ data->formatNodeName = src->nodeformat;
>+ data->formatAttached = true;
>+ data->storageNodeName = src->nodestorage;
>+ data->storageAttached = true;
>+ }
>+
>+ if (src->pr &&
>+ !virStoragePRDefIsManaged(src->pr) &&
>+ VIR_STRDUP(data->prmgrAlias, src->pr->mgralias) < 0)
>+ goto cleanup;
>+
>+ if (VIR_STRDUP(data->tlsAlias, src->tlsAlias) < 0)
>+ goto cleanup;
>+
>+ if (srcpriv) {
>+ if (srcpriv->secinfo &&
>+ srcpriv->secinfo->type == VIR_DOMAIN_SECRET_INFO_TYPE_AES &&
>+ VIR_STRDUP(data->authsecretAlias, srcpriv->secinfo->s.aes.alias) < 0)
>+ goto cleanup;
>+
>+ if (srcpriv->encinfo &&
>+ srcpriv->encinfo->type == VIR_DOMAIN_SECRET_INFO_TYPE_AES &&
>+ VIR_STRDUP(data->encryptsecretAlias, srcpriv->encinfo->s.aes.alias) < 0)
>+ goto cleanup;
>+ }
>+
>+ VIR_STEAL_PTR(ret, data);
>+
>+ cleanup:
>+ VIR_FREE(driveAlias);
>+ qemuBlockStorageSourceAttachDataFree(data);
>+ return ret;
>+}
>+
>+
>+static qemuHotplugDiskSourceDataPtr
>+qemuHotplugDiskSourceRemovePrepare(virDomainDiskDefPtr disk,
>+ virQEMUCapsPtr qemuCaps ATTRIBUTE_UNUSED)
>+{
>+ qemuBlockStorageSourceAttachDataPtr backend;
>+ qemuHotplugDiskSourceDataPtr data;
>+ qemuHotplugDiskSourceDataPtr ret = NULL;
>+ char *drivealias = NULL;
>+
>+ if (VIR_ALLOC(data) < 0)
>+ return NULL;
>+
>+ if (!(drivealias = qemuAliasDiskDriveFromDisk(disk)))
>+ goto cleanup;
>+
qemu/qemu_hotplug.c:447:9: error: variable 'backend' is used uninitialized whenever 'if' condition is true
[-Werror,-Wsometimes-uninitialized]
if (!(drivealias = qemuAliasDiskDriveFromDisk(disk)))
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>+ if (!(backend = qemuHotplugRemoveStorageSourcePrepareData(disk->src,
>+ drivealias)))
>+ goto cleanup;
>+
Reviewed-by: Ján Tomko <jtomko at redhat.com>
Jano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: Digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20180719/da45ecfd/attachment-0001.sig>
More information about the libvir-list
mailing list