]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: Turn @uuid member of _virDomainMemoryDef struct into a pointer
authorMichal Privoznik <mprivozn@redhat.com>
Mon, 18 Jan 2021 13:10:30 +0000 (14:10 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 18 Jan 2021 15:18:48 +0000 (16:18 +0100)
The _virDomainMemoryDef structure has @uuid member which is
needed for PPC64 guests. No other architectures use it. Since the
member is VIR_UUID_BUFLEN bytes long, the structure is
unnecessary big. If the member is just a pointer then we can also
replace some calls of virUUIDIsValid() with plain test against
NULL and also simplify formatter code which can now also check
the pointer against NULL.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
src/conf/domain_conf.c
src/conf/domain_conf.h
src/qemu/qemu_command.c

index ff3b7cbfc8a7781006217826833f112fba9bf3dd..01b357c638001d1134986f3c24b76a8997c3c260 100644 (file)
@@ -3116,6 +3116,7 @@ void virDomainMemoryDefFree(virDomainMemoryDefPtr def)
 
     VIR_FREE(def->nvdimmPath);
     virBitmapFree(def->sourceNodes);
+    VIR_FREE(def->uuid);
     virDomainDeviceInfoClear(&def->info);
     VIR_FREE(def);
 }
@@ -15530,6 +15531,7 @@ virDomainMemoryDefParseXML(virDomainXMLOptionPtr xmlopt,
         /* Extract nvdimm uuid or generate a new one */
         tmp = virXPathString("string(./uuid[1])", ctxt);
 
+        def->uuid = g_new0(unsigned char, VIR_UUID_BUFLEN);
         if (!tmp) {
             if (virUUIDGenerate(def->uuid) < 0) {
                 virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -22808,7 +22810,9 @@ virDomainMemoryDefCheckABIStability(virDomainMemoryDefPtr src,
             return false;
         }
 
-        if (memcmp(src->uuid, dst->uuid, VIR_UUID_BUFLEN) != 0) {
+        if ((src->uuid || dst->uuid) &&
+            !(src->uuid && dst->uuid &&
+              memcmp(src->uuid, dst->uuid, VIR_UUID_BUFLEN) == 0)) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                            _("Target NVDIMM UUID doesn't match source NVDIMM"));
             return false;
@@ -26560,7 +26564,6 @@ virDomainMemoryTargetDefFormat(virBufferPtr buf,
 static int
 virDomainMemoryDefFormat(virBufferPtr buf,
                          virDomainMemoryDefPtr def,
-                         const virDomainDef *dom,
                          unsigned int flags)
 {
     const char *model = virDomainMemoryModelTypeToString(def->model);
@@ -26575,8 +26578,7 @@ virDomainMemoryDefFormat(virBufferPtr buf,
     virBufferAddLit(buf, ">\n");
     virBufferAdjustIndent(buf, 2);
 
-    if (def->model == VIR_DOMAIN_MEMORY_MODEL_NVDIMM &&
-        ARCH_IS_PPC64(dom->os.arch)) {
+    if (def->uuid) {
         char uuidstr[VIR_UUID_STRING_BUFLEN];
 
         virUUIDFormat(def->uuid, uuidstr);
@@ -28974,7 +28976,7 @@ virDomainDefFormatInternalSetRootName(virDomainDefPtr def,
         virDomainShmemDefFormat(buf, def->shmems[n], flags);
 
     for (n = 0; n < def->nmems; n++) {
-        if (virDomainMemoryDefFormat(buf, def->mems[n], def, flags) < 0)
+        if (virDomainMemoryDefFormat(buf, def->mems[n], flags) < 0)
             return -1;
     }
 
@@ -30091,7 +30093,7 @@ virDomainDeviceDefCopy(virDomainDeviceDefPtr src,
         rc = 0;
         break;
     case VIR_DOMAIN_DEVICE_MEMORY:
-        rc = virDomainMemoryDefFormat(&buf, src->data.memory, def, flags);
+        rc = virDomainMemoryDefFormat(&buf, src->data.memory, flags);
         break;
     case VIR_DOMAIN_DEVICE_SHMEM:
         virDomainShmemDefFormat(&buf, src->data.shmem, flags);
index f59d972c85b8f0fabe833ece4ee479121ff03dad..d514f6360fc1559610f173d1cb1dd240fed5e02b 100644 (file)
@@ -2331,7 +2331,7 @@ struct _virDomainMemoryDef {
     bool readonly; /* valid only for NVDIMM */
 
     /* required for QEMU NVDIMM ppc64 support */
-    unsigned char uuid[VIR_UUID_BUFLEN];
+    unsigned char *uuid; /* VIR_UUID_BUFLEN bytes long */
 
     virDomainDeviceInfo info;
 };
index 99761c217df9c4aa7aee3277ac80cf45c79fe82f..2506248866566c3cbc1fff544a8c965c154a18b8 100644 (file)
@@ -3319,7 +3319,7 @@ qemuBuildMemoryDeviceStr(const virDomainDef *def,
     if (mem->labelsize)
         virBufferAsprintf(&buf, "label-size=%llu,", mem->labelsize * 1024);
 
-    if (virUUIDIsValid(mem->uuid)) {
+    if (mem->uuid) {
         char uuidstr[VIR_UUID_STRING_BUFLEN];
 
         virUUIDFormat(mem->uuid, uuidstr);