1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

conf: Turn @uuid member of _virDomainMemoryDef struct into a pointer

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>
This commit is contained in:
Michal Privoznik 2021-01-18 14:10:30 +01:00
parent ae83f592a7
commit 0123b42c54
3 changed files with 10 additions and 8 deletions

View File

@ -3116,6 +3116,7 @@ void virDomainMemoryDefFree(virDomainMemoryDefPtr def)
VIR_FREE(def->nvdimmPath); VIR_FREE(def->nvdimmPath);
virBitmapFree(def->sourceNodes); virBitmapFree(def->sourceNodes);
VIR_FREE(def->uuid);
virDomainDeviceInfoClear(&def->info); virDomainDeviceInfoClear(&def->info);
VIR_FREE(def); VIR_FREE(def);
} }
@ -15530,6 +15531,7 @@ virDomainMemoryDefParseXML(virDomainXMLOptionPtr xmlopt,
/* Extract nvdimm uuid or generate a new one */ /* Extract nvdimm uuid or generate a new one */
tmp = virXPathString("string(./uuid[1])", ctxt); tmp = virXPathString("string(./uuid[1])", ctxt);
def->uuid = g_new0(unsigned char, VIR_UUID_BUFLEN);
if (!tmp) { if (!tmp) {
if (virUUIDGenerate(def->uuid) < 0) { if (virUUIDGenerate(def->uuid) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
@ -22808,7 +22810,9 @@ virDomainMemoryDefCheckABIStability(virDomainMemoryDefPtr src,
return false; 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", virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Target NVDIMM UUID doesn't match source NVDIMM")); _("Target NVDIMM UUID doesn't match source NVDIMM"));
return false; return false;
@ -26560,7 +26564,6 @@ virDomainMemoryTargetDefFormat(virBufferPtr buf,
static int static int
virDomainMemoryDefFormat(virBufferPtr buf, virDomainMemoryDefFormat(virBufferPtr buf,
virDomainMemoryDefPtr def, virDomainMemoryDefPtr def,
const virDomainDef *dom,
unsigned int flags) unsigned int flags)
{ {
const char *model = virDomainMemoryModelTypeToString(def->model); const char *model = virDomainMemoryModelTypeToString(def->model);
@ -26575,8 +26578,7 @@ virDomainMemoryDefFormat(virBufferPtr buf,
virBufferAddLit(buf, ">\n"); virBufferAddLit(buf, ">\n");
virBufferAdjustIndent(buf, 2); virBufferAdjustIndent(buf, 2);
if (def->model == VIR_DOMAIN_MEMORY_MODEL_NVDIMM && if (def->uuid) {
ARCH_IS_PPC64(dom->os.arch)) {
char uuidstr[VIR_UUID_STRING_BUFLEN]; char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(def->uuid, uuidstr); virUUIDFormat(def->uuid, uuidstr);
@ -28974,7 +28976,7 @@ virDomainDefFormatInternalSetRootName(virDomainDefPtr def,
virDomainShmemDefFormat(buf, def->shmems[n], flags); virDomainShmemDefFormat(buf, def->shmems[n], flags);
for (n = 0; n < def->nmems; n++) { 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; return -1;
} }
@ -30091,7 +30093,7 @@ virDomainDeviceDefCopy(virDomainDeviceDefPtr src,
rc = 0; rc = 0;
break; break;
case VIR_DOMAIN_DEVICE_MEMORY: case VIR_DOMAIN_DEVICE_MEMORY:
rc = virDomainMemoryDefFormat(&buf, src->data.memory, def, flags); rc = virDomainMemoryDefFormat(&buf, src->data.memory, flags);
break; break;
case VIR_DOMAIN_DEVICE_SHMEM: case VIR_DOMAIN_DEVICE_SHMEM:
virDomainShmemDefFormat(&buf, src->data.shmem, flags); virDomainShmemDefFormat(&buf, src->data.shmem, flags);

View File

@ -2331,7 +2331,7 @@ struct _virDomainMemoryDef {
bool readonly; /* valid only for NVDIMM */ bool readonly; /* valid only for NVDIMM */
/* required for QEMU NVDIMM ppc64 support */ /* required for QEMU NVDIMM ppc64 support */
unsigned char uuid[VIR_UUID_BUFLEN]; unsigned char *uuid; /* VIR_UUID_BUFLEN bytes long */
virDomainDeviceInfo info; virDomainDeviceInfo info;
}; };

View File

@ -3319,7 +3319,7 @@ qemuBuildMemoryDeviceStr(const virDomainDef *def,
if (mem->labelsize) if (mem->labelsize)
virBufferAsprintf(&buf, "label-size=%llu,", mem->labelsize * 1024); virBufferAsprintf(&buf, "label-size=%llu,", mem->labelsize * 1024);
if (virUUIDIsValid(mem->uuid)) { if (mem->uuid) {
char uuidstr[VIR_UUID_STRING_BUFLEN]; char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(mem->uuid, uuidstr); virUUIDFormat(mem->uuid, uuidstr);