[PATCH v5 03/16] qemu: Introduce qemuDomainStorageSourceCopy

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

 



Create a qemu* specific StorageSourceCopy helper because we need
to be able to copy the PrivateData too if it exists without adding
any knowledge to the virStorageSourceCopy function.

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/qemu/qemu_blockjob.c |  2 +-
 src/qemu/qemu_domain.c   | 62 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_domain.h   |  4 ++++
 src/qemu/qemu_driver.c   |  8 +++----
 4 files changed, 71 insertions(+), 5 deletions(-)

diff --git a/src/qemu/qemu_blockjob.c b/src/qemu/qemu_blockjob.c
index c1b46f7d0a..15893a6048 100644
--- a/src/qemu/qemu_blockjob.c
+++ b/src/qemu/qemu_blockjob.c
@@ -124,7 +124,7 @@ qemuBlockJobEventProcess(virQEMUDriverPtr driver,
 
                 if ((persistDisk = virDomainDiskByName(vm->newDef,
                                                        disk->dst, false))) {
-                    copy = virStorageSourceCopy(disk->mirror, false);
+                    copy = qemuDomainStorageSourceCopy(disk->mirror, false);
                     if (!copy ||
                         virStorageSourceInitChainElement(copy,
                                                          persistDisk->src,
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index e8e7b31ff0..e040614fe4 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -883,6 +883,39 @@ qemuDomainSecretInfoFree(qemuDomainSecretInfoPtr *secinfo)
 }
 
 
+static qemuDomainSecretInfoPtr
+qemuDomainSecretInfoCopy(qemuDomainSecretInfoPtr src)
+{
+    qemuDomainSecretInfoPtr dst = NULL;
+    if (VIR_ALLOC(dst) < 0)
+        return NULL;
+
+    dst->type = src->type;
+    if (src->type == VIR_DOMAIN_SECRET_INFO_TYPE_PLAIN) {
+        if (VIR_STRDUP(dst->s.plain.username, src->s.plain.username) < 0)
+            goto error;
+
+        if (VIR_ALLOC_N(dst->s.plain.secret, src->s.plain.secretlen) < 0)
+            goto error;
+
+        memcpy(dst->s.plain.secret, src->s.plain.secret, src->s.plain.secretlen);
+        dst->s.plain.secretlen = src->s.plain.secretlen;
+    } else {
+        if (VIR_STRDUP(dst->s.aes.username, src->s.aes.username) < 0 ||
+            VIR_STRDUP(dst->s.aes.alias, src->s.aes.alias) < 0 ||
+            VIR_STRDUP(dst->s.aes.iv, src->s.aes.alias) < 0 ||
+            VIR_STRDUP(dst->s.aes.ciphertext, src->s.aes.ciphertext) < 0)
+            goto error;
+    }
+
+    return dst;
+
+ error:
+    qemuDomainSecretInfoFree(&dst);
+    return NULL;
+}
+
+
 static virClassPtr qemuDomainDiskPrivateClass;
 static void qemuDomainDiskPrivateDispose(void *obj);
 
@@ -959,6 +992,35 @@ qemuDomainDiskSrcPrivateNew(void)
 }
 
 
+virStorageSourcePtr
+qemuDomainStorageSourceCopy(const virStorageSource *src,
+                            bool backingChain)
+{
+    qemuDomainDiskSrcPrivatePtr srcPriv = QEMU_DOMAIN_DISK_SRC_PRIVATE(src);
+    virStorageSourcePtr dst;
+    qemuDomainDiskSrcPrivatePtr dstPriv;
+
+    if (!(dst = virStorageSourceCopy(src, backingChain)))
+        return NULL;
+
+    if (!srcPriv->secinfo)
+        return dst;
+
+    if (!(dst->privateData = qemuDomainDiskSrcPrivateNew()))
+        goto error;
+
+    dstPriv = QEMU_DOMAIN_DISK_SRC_PRIVATE(dst);
+    if (!(dstPriv->secinfo = qemuDomainSecretInfoCopy(srcPriv->secinfo)))
+        goto error;
+
+    return dst;
+
+ error:
+    virStorageSourceFree(dst);
+    return NULL;
+}
+
+
 static void
 qemuDomainDiskSrcPrivateDispose(void *obj)
 {
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index aba70f4030..a7a590c950 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -818,6 +818,10 @@ void qemuDomainMasterKeyRemove(qemuDomainObjPrivatePtr priv);
 void qemuDomainSecretInfoFree(qemuDomainSecretInfoPtr *secinfo)
     ATTRIBUTE_NONNULL(1);
 
+virStorageSourcePtr
+qemuDomainStorageSourceCopy(const virStorageSource *src,
+                            bool backingChain);
+
 void qemuDomainSecretDiskDestroy(virDomainDiskDefPtr disk)
     ATTRIBUTE_NONNULL(1);
 
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 7c6f1674a9..b1da17651a 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -345,7 +345,7 @@ qemuSecurityChownCallback(const virStorageSource *src,
         if (chown(src->path, uid, gid) < 0)
             goto cleanup;
     } else {
-        if (!(cpy = virStorageSourceCopy(src, false)))
+        if (!(cpy = qemuDomainStorageSourceCopy(src, false)))
             goto cleanup;
 
         /* src file init reports errors, return -2 on failure */
@@ -14396,7 +14396,7 @@ qemuDomainSnapshotDiskDataCollect(virQEMUDriverPtr driver,
 
         dd->disk = vm->def->disks[i];
 
-        if (!(dd->src = virStorageSourceCopy(snap->def->disks[i].src, false)))
+        if (!(dd->src = qemuDomainStorageSourceCopy(snap->def->disks[i].src, false)))
             goto error;
 
         if (virStorageSourceInitChainElement(dd->src, dd->disk->src, false) < 0)
@@ -14425,7 +14425,7 @@ qemuDomainSnapshotDiskDataCollect(virQEMUDriverPtr driver,
             (dd->persistdisk = virDomainDiskByName(vm->newDef, dd->disk->dst,
                                                    false))) {
 
-            if (!(dd->persistsrc = virStorageSourceCopy(dd->src, false)))
+            if (!(dd->persistsrc = qemuDomainStorageSourceCopy(dd->src, false)))
                 goto error;
 
             if (virStorageSourceInitChainElement(dd->persistsrc,
@@ -17450,7 +17450,7 @@ qemuDomainBlockCommit(virDomainPtr dom,
 
     /* For an active commit, clone enough of the base to act as the mirror */
     if (topSource == disk->src) {
-        if (!(mirror = virStorageSourceCopy(baseSource, false)))
+        if (!(mirror = qemuDomainStorageSourceCopy(baseSource, false)))
             goto endjob;
         if (virStorageSourceInitChainElement(mirror,
                                              disk->src,
-- 
2.13.6

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