[PATCH 8/9] src: Move _virDomainMemoryDef target nodes into an union

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

 



The _virDomainMemoryDef struct is getting a bit messy. It has
various members and only some of them are valid for given model.
Worse, some are re-used for different models. We tried to make
this more bearable by putting a comment next to each member
describing what models the member is valid for, but that gets
messy too.

Therefore, do what we do elsewhere: introduce an union of structs
and move individual members into their respective groups.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/conf/domain_conf.c      | 167 ++++++++++++++++++++++--------------
 src/conf/domain_conf.h      |  39 ++++++---
 src/conf/domain_postparse.c |   6 +-
 src/conf/domain_validate.c  |  14 +--
 src/qemu/qemu_command.c     |  34 +++++---
 src/qemu/qemu_domain.c      |  13 +--
 src/qemu/qemu_driver.c      |   8 +-
 src/qemu/qemu_hotplug.c     |  14 +--
 src/qemu/qemu_process.c     |   4 +-
 src/qemu/qemu_validate.c    |   2 +-
 10 files changed, 182 insertions(+), 119 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index a1dad679dd..38d7250c6d 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -3496,6 +3496,7 @@ void virDomainMemoryDefFree(virDomainMemoryDef *def)
         break;
     case VIR_DOMAIN_MEMORY_MODEL_NVDIMM:
         g_free(def->source.nvdimm.nvdimmPath);
+        g_free(def->target.nvdimm.uuid);
         break;
     case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM:
         g_free(def->source.virtio_pmem.nvdimmPath);
@@ -3511,7 +3512,6 @@ void virDomainMemoryDefFree(virDomainMemoryDef *def)
         break;
     }
 
-    g_free(def->uuid);
     virDomainDeviceInfoClear(&def->info);
     g_free(def);
 }
@@ -13366,6 +13366,7 @@ virDomainMemoryTargetDefParseXML(xmlNodePtr node,
 {
     VIR_XPATH_NODE_AUTORESTORE(ctxt)
     xmlNodePtr addrNode = NULL;
+    unsigned long long *addr;
     int rv;
 
     ctxt->node = node;
@@ -13384,39 +13385,41 @@ virDomainMemoryTargetDefParseXML(xmlNodePtr node,
     switch (def->model) {
     case VIR_DOMAIN_MEMORY_MODEL_NVDIMM:
         if (virDomainParseMemory("./label/size", "./label/size/@unit", ctxt,
-                                 &def->labelsize, false, false) < 0)
+                                 &def->target.nvdimm.labelsize, false, false) < 0)
             return -1;
 
-        if (def->labelsize && def->labelsize < 128) {
+        if (def->target.nvdimm.labelsize && def->target.nvdimm.labelsize < 128) {
             virReportError(VIR_ERR_XML_ERROR, "%s",
                            _("nvdimm label must be at least 128KiB"));
             return -1;
         }
 
-        if (def->labelsize >= def->size) {
+        if (def->target.nvdimm.labelsize >= def->size) {
             virReportError(VIR_ERR_XML_ERROR, "%s",
                            _("label size must be smaller than NVDIMM size"));
             return -1;
         }
 
         if (virXPathBoolean("boolean(./readonly)", ctxt))
-            def->readonly = true;
+            def->target.nvdimm.readonly = true;
         break;
 
     case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM:
         if (virDomainParseMemory("./block", "./block/@unit", ctxt,
-                                 &def->blocksize, false, false) < 0)
+                                 &def->target.virtio_mem.blocksize, false, false) < 0)
             return -1;
 
         if (virDomainParseMemory("./requested", "./requested/@unit", ctxt,
-                                 &def->requestedsize, false, false) < 0)
+                                 &def->target.virtio_mem.requestedsize, false, false) < 0)
             return -1;
 
         addrNode = virXPathNode("./address", ctxt);
+        addr = &def->target.virtio_mem.address;
         break;
 
     case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM:
         addrNode = virXPathNode("./address", ctxt);
+        addr = &def->target.virtio_pmem.address;
         break;
 
     case VIR_DOMAIN_MEMORY_MODEL_NONE:
@@ -13428,7 +13431,7 @@ virDomainMemoryTargetDefParseXML(xmlNodePtr node,
 
     if (addrNode &&
         virXMLPropULongLong(addrNode, "base", 16,
-                            VIR_XML_PROP_NONE, &def->address) < 0) {
+                            VIR_XML_PROP_NONE, addr) < 0) {
         return -1;
     }
 
@@ -13562,9 +13565,9 @@ virDomainMemoryDefParseXML(virDomainXMLOption *xmlopt,
     /* Extract NVDIMM UUID. */
     if (def->model == VIR_DOMAIN_MEMORY_MODEL_NVDIMM &&
         (tmp = virXPathString("string(./uuid[1])", ctxt))) {
-        def->uuid = g_new0(unsigned char, VIR_UUID_BUFLEN);
+        def->target.nvdimm.uuid = g_new0(unsigned char, VIR_UUID_BUFLEN);
 
-        if (virUUIDParse(tmp, def->uuid) < 0) {
+        if (virUUIDParse(tmp, def->target.nvdimm.uuid) < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            "%s", _("malformed uuid element"));
             return NULL;
@@ -15282,10 +15285,7 @@ virDomainMemoryFindByDefInternal(virDomainDef *def,
         /* target info -> always present */
         if (tmp->model != mem->model ||
             tmp->targetNode != mem->targetNode ||
-            tmp->size != mem->size ||
-            tmp->blocksize != mem->blocksize ||
-            tmp->requestedsize != mem->requestedsize ||
-            tmp->address != mem->address)
+            tmp->size != mem->size)
             continue;
 
         switch (mem->model) {
@@ -15298,7 +15298,10 @@ virDomainMemoryFindByDefInternal(virDomainDef *def,
                 continue;
             break;
         case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM:
-            if (tmp->source.virtio_mem.pagesize != mem->source.virtio_mem.pagesize)
+            if (tmp->source.virtio_mem.pagesize != mem->source.virtio_mem.pagesize ||
+                tmp->target.virtio_mem.blocksize != mem->target.virtio_mem.blocksize ||
+                tmp->target.virtio_mem.requestedsize != mem->target.virtio_mem.requestedsize ||
+                tmp->target.virtio_mem.address != mem->target.virtio_mem.address)
                 continue;
 
             if (!virBitmapEqual(tmp->source.virtio_mem.sourceNodes,
@@ -15313,7 +15316,8 @@ virDomainMemoryFindByDefInternal(virDomainDef *def,
 
         case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM:
             if (STRNEQ(tmp->source.virtio_pmem.nvdimmPath,
-                       mem->source.virtio_pmem.nvdimmPath))
+                       mem->source.virtio_pmem.nvdimmPath) ||
+                tmp->target.virtio_pmem.address != mem->target.virtio_pmem.address)
                 continue;
             break;
 
@@ -21022,33 +21026,13 @@ virDomainMemoryDefCheckABIStability(virDomainMemoryDef *src,
         return false;
     }
 
-    if (src->blocksize != dst->blocksize) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                       _("Target memory device block size '%1$llu' doesn't match source memory device block size '%2$llu'"),
-                       dst->blocksize, src->blocksize);
-        return false;
-    }
-
-    if (src->requestedsize != dst->requestedsize) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                       _("Target memory device requested size '%1$llu' doesn't match source memory device requested size '%2$llu'"),
-                       dst->requestedsize, src->requestedsize);
-        return false;
-    }
-
-    if (src->address != dst->address) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                       _("Target memory device address '0x%1$llx' doesn't match source memory device address '0x%2$llx'"),
-                       dst->address, src->address);
-        return false;
-    }
-
     switch (src->model) {
     case VIR_DOMAIN_MEMORY_MODEL_NVDIMM:
-        if (src->labelsize != dst->labelsize) {
+        if (src->target.nvdimm.labelsize != dst->target.nvdimm.labelsize) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                            _("Target NVDIMM label size '%1$llu' doesn't match source NVDIMM label size '%2$llu'"),
-                           src->labelsize, dst->labelsize);
+                           src->target.nvdimm.labelsize,
+                           dst->target.nvdimm.labelsize);
             return false;
         }
 
@@ -21067,25 +21051,59 @@ virDomainMemoryDefCheckABIStability(virDomainMemoryDef *src,
             return false;
         }
 
-        if (src->readonly != dst->readonly) {
+        if (src->target.nvdimm.readonly != dst->target.nvdimm.readonly) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                            _("Target NVDIMM readonly flag doesn't match "
                              "source NVDIMM readonly flag"));
             return false;
         }
 
-        if ((src->uuid || dst->uuid) &&
-            !(src->uuid && dst->uuid &&
-              memcmp(src->uuid, dst->uuid, VIR_UUID_BUFLEN) == 0)) {
+        if ((src->target.nvdimm.uuid || dst->target.nvdimm.uuid) &&
+            !(src->target.nvdimm.uuid && dst->target.nvdimm.uuid &&
+              memcmp(src->target.nvdimm.uuid, dst->target.nvdimm.uuid, VIR_UUID_BUFLEN) == 0)) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                            _("Target NVDIMM UUID doesn't match source NVDIMM"));
             return false;
         }
         break;
 
-    case VIR_DOMAIN_MEMORY_MODEL_DIMM:
     case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM:
+        if (src->target.virtio_pmem.address != dst->target.virtio_pmem.address) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           _("Target memory device address '0x%1$llx' doesn't match source memory device address '0x%2$llx'"),
+                           dst->target.virtio_pmem.address,
+                           src->target.virtio_pmem.address);
+            return false;
+        }
+        break;
+
     case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM:
+        if (src->target.virtio_mem.blocksize != dst->target.virtio_mem.blocksize) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           _("Target memory device block size '%1$llu' doesn't match source memory device block size '%2$llu'"),
+                           dst->target.virtio_mem.blocksize,
+                           src->target.virtio_mem.blocksize);
+            return false;
+        }
+
+        if (src->target.virtio_mem.requestedsize != dst->target.virtio_mem.requestedsize) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           _("Target memory device requested size '%1$llu' doesn't match source memory device requested size '%2$llu'"),
+                           dst->target.virtio_mem.requestedsize,
+                           src->target.virtio_mem.requestedsize);
+            return false;
+        }
+
+        if (src->target.virtio_mem.address != dst->target.virtio_mem.address) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           _("Target memory device address '0x%1$llx' doesn't match source memory device address '0x%2$llx'"),
+                           dst->target.virtio_mem.address,
+                           src->target.virtio_mem.address);
+            return false;
+        }
+        break;
+
+    case VIR_DOMAIN_MEMORY_MODEL_DIMM:
     case VIR_DOMAIN_MEMORY_MODEL_SGX_EPC:
     case VIR_DOMAIN_MEMORY_MODEL_NONE:
     case VIR_DOMAIN_MEMORY_MODEL_LAST:
@@ -25216,29 +25234,49 @@ virDomainMemoryTargetDefFormat(virBuffer *buf,
     virBufferAsprintf(&childBuf, "<size unit='KiB'>%llu</size>\n", def->size);
     if (def->targetNode >= 0)
         virBufferAsprintf(&childBuf, "<node>%d</node>\n", def->targetNode);
-    if (def->labelsize) {
-        g_auto(virBuffer) labelChildBuf = VIR_BUFFER_INIT_CHILD(&childBuf);
 
-        virBufferAsprintf(&labelChildBuf, "<size unit='KiB'>%llu</size>\n", def->labelsize);
-        virXMLFormatElement(&childBuf, "label", NULL, &labelChildBuf);
-    }
-    if (def->readonly)
-        virBufferAddLit(&childBuf, "<readonly/>\n");
+    switch (def->model) {
+    case VIR_DOMAIN_MEMORY_MODEL_NVDIMM:
+        if (def->target.nvdimm.labelsize) {
+            g_auto(virBuffer) labelChildBuf = VIR_BUFFER_INIT_CHILD(&childBuf);
+
+            virBufferAsprintf(&labelChildBuf, "<size unit='KiB'>%llu</size>\n",
+                              def->target.nvdimm.labelsize);
+            virXMLFormatElement(&childBuf, "label", NULL, &labelChildBuf);
+        }
+        if (def->target.nvdimm.readonly)
+            virBufferAddLit(&childBuf, "<readonly/>\n");
+        break;
 
-    if (def->blocksize) {
-        virBufferAsprintf(&childBuf, "<block unit='KiB'>%llu</block>\n",
-                          def->blocksize);
+    case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM:
+        if (def->target.virtio_pmem.address)
+            virBufferAsprintf(&childBuf, "<address base='0x%llx'/>\n",
+                              def->target.virtio_pmem.address);
+        break;
 
-        virBufferAsprintf(&childBuf, "<requested unit='KiB'>%llu</requested>\n",
-                          def->requestedsize);
-        if (!(flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE)) {
-            virBufferAsprintf(&childBuf, "<current unit='KiB'>%llu</current>\n",
-                              def->currentsize);
+    case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM:
+        if (def->target.virtio_mem.blocksize) {
+            virBufferAsprintf(&childBuf, "<block unit='KiB'>%llu</block>\n",
+                              def->target.virtio_mem.blocksize);
+
+            virBufferAsprintf(&childBuf, "<requested unit='KiB'>%llu</requested>\n",
+                              def->target.virtio_mem.requestedsize);
+            if (!(flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE)) {
+                virBufferAsprintf(&childBuf, "<current unit='KiB'>%llu</current>\n",
+                                  def->target.virtio_mem.currentsize);
+            }
         }
-    }
+        if (def->target.virtio_mem.address)
+            virBufferAsprintf(&childBuf, "<address base='0x%llx'/>\n",
+                              def->target.virtio_mem.address);
+        break;
 
-    if (def->address)
-        virBufferAsprintf(&childBuf, "<address base='0x%llx'/>\n", def->address);
+    case VIR_DOMAIN_MEMORY_MODEL_SGX_EPC:
+    case VIR_DOMAIN_MEMORY_MODEL_DIMM:
+    case VIR_DOMAIN_MEMORY_MODEL_NONE:
+    case VIR_DOMAIN_MEMORY_MODEL_LAST:
+        break;
+    }
 
     virXMLFormatElement(buf, "target", NULL, &childBuf);
 }
@@ -25260,10 +25298,11 @@ virDomainMemoryDefFormat(virBuffer *buf,
     virBufferAddLit(buf, ">\n");
     virBufferAdjustIndent(buf, 2);
 
-    if (def->uuid) {
+    if (def->model == VIR_DOMAIN_MEMORY_MODEL_NVDIMM &&
+        def->target.nvdimm.uuid) {
         char uuidstr[VIR_UUID_STRING_BUFLEN];
 
-        virUUIDFormat(def->uuid, uuidstr);
+        virUUIDFormat(def->target.nvdimm.uuid, uuidstr);
         virBufferAsprintf(buf, "<uuid>%s</uuid>\n", uuidstr);
     }
 
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 8770547590..cf4cb04a6f 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2638,6 +2638,9 @@ struct _virDomainMemoryDef {
     virDomainMemoryAccess access;
     virTristateBool discard;
 
+    unsigned long long size; /* kibibytes */
+    int targetNode;
+
     union {
         struct {
             unsigned long long pagesize; /* kibibytes */
@@ -2660,21 +2663,29 @@ struct _virDomainMemoryDef {
         } sgx_epc;
     } source;
 
-    /* target */
-    int targetNode;
-    unsigned long long size; /* kibibytes */
-    unsigned long long labelsize; /* kibibytes; valid only for NVDIMM */
-    unsigned long long blocksize; /* kibibytes; valid only for VIRTIO_MEM */
-    unsigned long long requestedsize; /* kibibytes; valid only for VIRTIO_MEM */
-    unsigned long long currentsize; /* kibibytes, valid for VIRTIO_MEM and
-                                       active domain only, only to report never
-                                       parse */
-    unsigned long long address; /* address where memory is mapped, valid for
-                                   VIRTIO_PMEM and VIRTIO_MEM only. */
-    bool readonly; /* valid only for NVDIMM */
+    union {
+        struct {
+        } dimm;
+        struct {
+            unsigned long long labelsize; /* kibibytes */
+            bool readonly;
 
-    /* required for QEMU NVDIMM ppc64 support */
-    unsigned char *uuid; /* VIR_UUID_BUFLEN bytes long */
+            /* required for QEMU NVDIMM ppc64 support */
+            unsigned char *uuid; /* VIR_UUID_BUFLEN bytes long */
+        } nvdimm;
+        struct {
+            unsigned long long address; /* address where memory is mapped */
+        } virtio_pmem;
+        struct {
+            unsigned long long blocksize; /* kibibytes */
+            unsigned long long requestedsize; /* kibibytes */
+            unsigned long long currentsize; /* kibibytes, valid for an active
+                                               domain only and parsed */
+            unsigned long long address; /* address where memory is mapped */
+        } virtio_mem;
+        struct {
+        } sgx_epc;
+    } target;
 
     virDomainDeviceInfo info;
 };
diff --git a/src/conf/domain_postparse.c b/src/conf/domain_postparse.c
index f1dfdb7665..b76e8dcc5c 100644
--- a/src/conf/domain_postparse.c
+++ b/src/conf/domain_postparse.c
@@ -616,10 +616,10 @@ virDomainMemoryDefPostParse(virDomainMemoryDef *mem,
     case VIR_DOMAIN_MEMORY_MODEL_NVDIMM:
         /* If no NVDIMM UUID was provided in XML, generate one. */
         if (ARCH_IS_PPC64(def->os.arch) &&
-            !mem->uuid) {
+            !mem->target.nvdimm.uuid) {
 
-            mem->uuid = g_new0(unsigned char, VIR_UUID_BUFLEN);
-            if (virUUIDGenerate(mem->uuid) < 0) {
+            mem->target.nvdimm.uuid = g_new0(unsigned char, VIR_UUID_BUFLEN);
+            if (virUUIDGenerate(mem->target.nvdimm.uuid) < 0) {
                 virReportError(VIR_ERR_INTERNAL_ERROR,
                                "%s", _("Failed to generate UUID"));
                 return -1;
diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c
index 2832fd010e..ddf2e8effa 100644
--- a/src/conf/domain_validate.c
+++ b/src/conf/domain_validate.c
@@ -2273,12 +2273,12 @@ virDomainMemoryDefValidate(const virDomainMemoryDef *mem,
         }
 
         if (ARCH_IS_PPC64(def->os.arch)) {
-            if (mem->labelsize == 0) {
+            if (mem->target.nvdimm.labelsize == 0) {
                 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                                _("label size is required for NVDIMM device"));
                 return -1;
             }
-        } else if (mem->uuid) {
+        } else if (mem->target.nvdimm.uuid) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                            _("UUID is not supported for NVDIMM device"));
             return -1;
@@ -2314,14 +2314,14 @@ virDomainMemoryDefValidate(const virDomainMemoryDef *mem,
         break;
 
     case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM:
-        if (mem->requestedsize > mem->size) {
+        if (mem->target.virtio_mem.requestedsize > mem->size) {
             virReportError(VIR_ERR_XML_DETAIL,
                            _("requested size must be smaller than or equal to @size (%1$lluKiB)"),
                            mem->size);
             return -1;
         }
 
-        if (!VIR_IS_POW2(mem->blocksize)) {
+        if (!VIR_IS_POW2(mem->target.virtio_mem.blocksize)) {
             virReportError(VIR_ERR_XML_DETAIL, "%s",
                            _("block size must be a power of two"));
             return -1;
@@ -2335,20 +2335,20 @@ virDomainMemoryDefValidate(const virDomainMemoryDef *mem,
             thpSize = 2048;
         }
 
-        if (mem->blocksize < thpSize) {
+        if (mem->target.virtio_mem.blocksize < thpSize) {
             virReportError(VIR_ERR_XML_DETAIL,
                            _("block size too small, must be at least %1$lluKiB"),
                            thpSize);
             return -1;
         }
 
-        if (mem->requestedsize % mem->blocksize != 0) {
+        if (mem->target.virtio_mem.requestedsize % mem->target.virtio_mem.blocksize != 0) {
             virReportError(VIR_ERR_XML_DETAIL, "%s",
                            _("requested size must be an integer multiple of block size"));
             return -1;
         }
 
-        if (mem->address % mem->blocksize != 0) {
+        if (mem->target.virtio_mem.address % mem->target.virtio_mem.blocksize != 0) {
             virReportError(VIR_ERR_XML_DETAIL, "%s",
                            _("memory device address must be aligned to blocksize"));
             return -1;
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 2e06261ef2..77601d27c5 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3622,6 +3622,10 @@ qemuBuildMemoryDeviceProps(virQEMUDriverConfig *cfg,
     g_autofree char *uuidstr = NULL;
     virTristateBool unarmed = VIR_TRISTATE_BOOL_ABSENT;
     g_autofree char *memdev = NULL;
+    unsigned long long labelsize = 0;
+    unsigned long long blocksize = 0;
+    unsigned long long requestedsize = 0;
+    unsigned long long address = 0;
     bool prealloc = false;
 
     if (!mem->info.alias) {
@@ -3638,10 +3642,20 @@ qemuBuildMemoryDeviceProps(virQEMUDriverConfig *cfg,
         break;
     case VIR_DOMAIN_MEMORY_MODEL_NVDIMM:
         device = "nvdimm";
+        if (mem->target.nvdimm.readonly)
+            unarmed = VIR_TRISTATE_BOOL_YES;
+
+        if (mem->target.nvdimm.uuid) {
+            uuidstr = g_new0(char, VIR_UUID_STRING_BUFLEN);
+            virUUIDFormat(mem->target.nvdimm.uuid, uuidstr);
+        }
+
+        labelsize = mem->target.nvdimm.labelsize;
         break;
 
     case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM:
         device = "virtio-pmem-pci";
+        address = mem->target.virtio_pmem.address;
         break;
 
     case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM:
@@ -3650,6 +3664,10 @@ qemuBuildMemoryDeviceProps(virQEMUDriverConfig *cfg,
         if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE_VIRTIO_MEM_PCI_PREALLOC) &&
             qemuBuildMemoryGetPagesize(cfg, def, mem, NULL, NULL, NULL, &prealloc) < 0)
             return NULL;
+
+        blocksize = mem->target.virtio_mem.blocksize;
+        requestedsize = mem->target.virtio_mem.requestedsize;
+        address = mem->target.virtio_mem.address;
         break;
 
     case VIR_DOMAIN_MEMORY_MODEL_SGX_EPC:
@@ -3661,25 +3679,17 @@ qemuBuildMemoryDeviceProps(virQEMUDriverConfig *cfg,
         break;
     }
 
-    if (mem->readonly)
-        unarmed = VIR_TRISTATE_BOOL_YES;
-
-    if (mem->uuid) {
-        uuidstr = g_new0(char, VIR_UUID_STRING_BUFLEN);
-        virUUIDFormat(mem->uuid, uuidstr);
-    }
-
     if (virJSONValueObjectAdd(&props,
                               "s:driver", device,
                               "k:node", mem->targetNode,
-                              "P:label-size", mem->labelsize * 1024,
-                              "P:block-size", mem->blocksize * 1024,
-                              "P:requested-size", mem->requestedsize * 1024,
+                              "P:label-size", labelsize * 1024,
+                              "P:block-size", blocksize * 1024,
+                              "P:requested-size", requestedsize * 1024,
                               "S:uuid", uuidstr,
                               "T:unarmed", unarmed,
                               "s:memdev", memdev,
                               "B:prealloc", prealloc,
-                              "P:memaddr", mem->address,
+                              "P:memaddr", address,
                               "s:id", mem->info.alias,
                               NULL) < 0)
         return NULL;
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 029238a9d7..2eda3ef59c 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -6080,7 +6080,7 @@ qemuDomainNVDimmAlignSizePseries(virDomainMemoryDef *mem)
      * target_size = AlignDown(target_size - label_size) + label_size
      */
     unsigned long long ppc64AlignSize =  256 * 1024;
-    unsigned long long guestArea = mem->size - mem->labelsize;
+    unsigned long long guestArea = mem->size - mem->target.nvdimm.labelsize;
 
     /* Align down guestArea. We can't align down if guestArea is
      * smaller than the 256MiB alignment. */
@@ -6092,7 +6092,7 @@ qemuDomainNVDimmAlignSizePseries(virDomainMemoryDef *mem)
     }
 
     guestArea = (guestArea/ppc64AlignSize) * ppc64AlignSize;
-    mem->size = guestArea + mem->labelsize;
+    mem->size = guestArea + mem->target.nvdimm.labelsize;
 
     return 0;
 }
@@ -8604,11 +8604,12 @@ qemuDomainUpdateMemoryDeviceInfo(virDomainObj *vm,
 
         switch (mem->model) {
         case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM:
+            mem->target.virtio_mem.currentsize = VIR_DIV_UP(dimm->size, 1024);
+            mem->target.virtio_mem.address = dimm->address;
+            break;
+
         case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM:
-            if (mem->model == VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM) {
-                mem->currentsize = VIR_DIV_UP(dimm->size, 1024);
-            }
-            mem->address = dimm->address;
+            mem->target.virtio_pmem.address = dimm->address;
             break;
 
         case VIR_DOMAIN_MEMORY_MODEL_DIMM:
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index f0eda71c4f..73fa499e40 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4010,14 +4010,14 @@ processMemoryDeviceSizeChange(virQEMUDriver *driver,
      * It really contains just the balloon size. But in domain
      * definition we want to report also sum of @currentsize. Do
      * a bit of math to fix the domain definition. */
-    balloon = vm->def->mem.cur_balloon - mem->currentsize;
-    mem->currentsize = VIR_DIV_UP(info->size, 1024);
-    balloon += mem->currentsize;
+    balloon = vm->def->mem.cur_balloon - mem->target.virtio_mem.currentsize;
+    mem->target.virtio_mem.currentsize = VIR_DIV_UP(info->size, 1024);
+    balloon += mem->target.virtio_mem.currentsize;
     vm->def->mem.cur_balloon = balloon;
 
     event = virDomainEventMemoryDeviceSizeChangeNewFromObj(vm,
                                                            info->devAlias,
-                                                           mem->currentsize);
+                                                           mem->target.virtio_mem.currentsize);
 
  endjob:
     virDomainObjEndJob(vm);
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index ece5b2598d..c461c7454f 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -7051,20 +7051,22 @@ qemuDomainChangeMemoryLiveValidateChange(const virDomainMemoryDef *oldDef,
         return false;
     }
 
-    if (oldDef->blocksize != newDef->blocksize) {
+    if (oldDef->target.virtio_mem.blocksize != newDef->target.virtio_mem.blocksize) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                        _("cannot modify memory block size from '%1$llu' to '%2$llu'"),
-                       oldDef->blocksize, newDef->blocksize);
+                       oldDef->target.virtio_mem.blocksize,
+                       newDef->target.virtio_mem.blocksize);
         return false;
     }
 
     /* requestedsize can change */
 
 
-    if (oldDef->address != newDef->address) {
+    if (oldDef->target.virtio_mem.address != newDef->target.virtio_mem.address) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                        _("cannot modify memory address from '0x%1$llx' to '0x%2$llx'"),
-                       oldDef->address, newDef->address);
+                       oldDef->target.virtio_mem.address,
+                       newDef->target.virtio_mem.address);
         return false;
     }
 
@@ -7099,10 +7101,10 @@ qemuDomainChangeMemoryLive(virQEMUDriver *driver G_GNUC_UNUSED,
         return -1;
 
     if (qemuDomainChangeMemoryRequestedSize(vm, newDef->info.alias,
-                                            newDef->requestedsize) < 0)
+                                            newDef->target.virtio_mem.requestedsize) < 0)
         return -1;
 
-    oldDef->requestedsize = newDef->requestedsize;
+    oldDef->target.virtio_mem.requestedsize = newDef->target.virtio_mem.requestedsize;
     return 0;
 }
 
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index aa2593fa9a..5331996c93 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -1096,7 +1096,7 @@ qemuProcessHandleBalloonChange(qemuMonitor *mon G_GNUC_UNUSED,
     VIR_DEBUG("balloon size before fix is %lld", actual);
     for (i = 0; i < vm->def->nmems; i++) {
         if (vm->def->mems[i]->model == VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM)
-            actual += vm->def->mems[i]->currentsize;
+            actual += vm->def->mems[i]->target.virtio_mem.currentsize;
     }
 
     VIR_DEBUG("Updating balloon from %lld to %lld kb",
@@ -2286,7 +2286,7 @@ qemuProcessRefreshBalloonState(virDomainObj *vm,
     VIR_DEBUG("balloon size before fix is %lld", balloon);
     for (i = 0; i < vm->def->nmems; i++) {
         if (vm->def->mems[i]->model == VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM)
-            balloon += vm->def->mems[i]->currentsize;
+            balloon += vm->def->mems[i]->target.virtio_mem.currentsize;
     }
     VIR_DEBUG("Updating balloon from %lld to %lld kb",
               vm->def->mem.cur_balloon, balloon);
diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
index 9b548ee515..a9a21843b5 100644
--- a/src/qemu/qemu_validate.c
+++ b/src/qemu/qemu_validate.c
@@ -5034,7 +5034,7 @@ qemuValidateDomainDeviceDefMemory(virDomainMemoryDef *mem,
             return -1;
         }
 
-        if (mem->readonly &&
+        if (mem->target.nvdimm.readonly &&
             !virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_NVDIMM_UNARMED)) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                            _("nvdimm readonly property is not available "
-- 
2.41.0




[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