[PATCH 02/11] virDomainChrSourceDefCopy: Copy more struct members

Michal Privoznik mprivozn at redhat.com
Mon Jan 24 10:07:24 UTC 2022


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 at redhat.com>
---
 src/conf/domain_conf.c | 27 ++++++++++++++++++++++-----
 1 file changed, 22 insertions(+), 5 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 73c6ac6a88..5387cd271a 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -2731,8 +2731,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)
@@ -2742,7 +2743,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:
@@ -2782,10 +2787,22 @@ virDomainChrSourceDefCopy(virDomainChrSourceDef *dest,
         dest->data.nmdm.slave = g_strdup(src->data.nmdm.slave);
 
         break;
+
+    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;
     }
 
-    dest->type = src->type;
-
     return 0;
 }
 
-- 
2.34.1




More information about the libvir-list mailing list