]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virDomainChrSourceDefCopy: Copy more struct members
authorMichal Privoznik <mprivozn@redhat.com>
Sun, 23 Jan 2022 13:58:36 +0000 (14:58 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 26 Jan 2022 09:49:11 +0000 (10:49 +0100)
The aim of virDomainChrSourceDefCopy() is to make a deep copy of
given virDomainChrSourceDef. However, some types were not copied
at all (VIR_DOMAIN_CHR_TYPE_SPICEVMC and
VIR_DOMAIN_CHR_TYPE_SPICEPORT) and some members weren't copied
either (@logfile, @logappend).

After this, there are still some members that are not copied
(seclabels and private data), but the sole caller
qemuProcessFindCharDevicePTYsMonitor() doesn't seem to care.
Therefore, just document this behavior so that future user is
aware.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/conf/domain_conf.c

index 87576d48048de39cceb23426fc4ac439cebd33f2..5d3604c085d4d70d642e9ade5ad179a67eca9ffe 100644 (file)
@@ -2732,8 +2732,9 @@ virDomainChrSourceDefClear(virDomainChrSourceDef *def)
     VIR_FREE(def->logfile);
 }
 
-/* Deep copies the contents of src into dest.  Return -1 and report
- * error on failure.  */
+/* Almost deep copies the contents of src into dest. Some parts are not copied
+ * though.
+ * Returns -1 and report error on failure.  */
 int
 virDomainChrSourceDefCopy(virDomainChrSourceDef *dest,
                           virDomainChrSourceDef *src)
@@ -2743,7 +2744,11 @@ virDomainChrSourceDefCopy(virDomainChrSourceDef *dest,
 
     virDomainChrSourceDefClear(dest);
 
-    switch (src->type) {
+    dest->type = src->type;
+    dest->logfile = g_strdup(src->logfile);
+    dest->logappend = src->logappend;
+
+    switch ((virDomainChrType)src->type) {
     case VIR_DOMAIN_CHR_TYPE_FILE:
     case VIR_DOMAIN_CHR_TYPE_PTY:
     case VIR_DOMAIN_CHR_TYPE_DEV:
@@ -2783,9 +2788,21 @@ virDomainChrSourceDefCopy(virDomainChrSourceDef *dest,
         dest->data.nmdm.slave = g_strdup(src->data.nmdm.slave);
 
         break;
-    }
 
-    dest->type = src->type;
+    case VIR_DOMAIN_CHR_TYPE_SPICEVMC:
+        dest->data.spicevmc = src->data.spicevmc;
+        break;
+
+    case VIR_DOMAIN_CHR_TYPE_SPICEPORT:
+        dest->data.spiceport.channel = g_strdup(src->data.spiceport.channel);
+        break;
+
+    case VIR_DOMAIN_CHR_TYPE_NULL:
+    case VIR_DOMAIN_CHR_TYPE_VC:
+    case VIR_DOMAIN_CHR_TYPE_STDIO:
+    case VIR_DOMAIN_CHR_TYPE_LAST:
+        break;
+    }
 
     return 0;
 }