Re: [PATCH 06/10] qemu: hotplug: Reuse qemuHotplugDiskSourceRemove for disk backend removal

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
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@xxxxxxxxxx>

Jano

Attachment: signature.asc
Description: Digital signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux