On a Thursday in 2023, Michal Privoznik wrote:
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.
This allows us to shorten some names (e.g. nvdimmPath or
sourceNodes) as their purpose is obvious due to their placement.
But to make this commit as small as possible, that'll be
addressed later.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/conf/domain_conf.c | 125 +++++++++++++++++++++++--------
src/conf/domain_conf.h | 29 +++++--
src/conf/domain_validate.c | 4 +-
src/qemu/qemu_cgroup.c | 12 ++-
src/qemu/qemu_command.c | 97 ++++++++++++++++++------
src/qemu/qemu_hotplug.c | 10 +--
src/qemu/qemu_namespace.c | 4 +-
src/qemu/qemu_process.c | 10 ++-
src/qemu/qemu_validate.c | 4 +-
src/security/security_apparmor.c | 24 ++++--
src/security/security_dac.c | 9 ++-
src/security/security_selinux.c | 52 ++++++-------
src/security/virt-aa-helper.c | 5 +-
13 files changed, 272 insertions(+), 113 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 9a4a26d875..a1dad679dd 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -3490,8 +3490,27 @@ void virDomainMemoryDefFree(virDomainMemoryDef *def)
if (!def)
return;
- g_free(def->nvdimmPath);
- virBitmapFree(def->sourceNodes);
+ switch (def->model) {
+ case VIR_DOMAIN_MEMORY_MODEL_DIMM:
+ virBitmapFree(def->source.dimm.sourceNodes);
+ break;
+ case VIR_DOMAIN_MEMORY_MODEL_NVDIMM:
+ g_free(def->source.nvdimm.nvdimmPath);
+ break;
+ case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM:
+ g_free(def->source.virtio_pmem.nvdimmPath);
+ break;
+ case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM:
+ virBitmapFree(def->source.dimm.sourceNodes);
def->source.virtio_mem.sourceNodes
+ break;
+ case VIR_DOMAIN_MEMORY_MODEL_SGX_EPC:
+ virBitmapFree(def->source.sgx_epc.sourceNodes);
+ break;
+ case VIR_DOMAIN_MEMORY_MODEL_NONE:
+ case VIR_DOMAIN_MEMORY_MODEL_LAST:
+ break;
+ }
+
g_free(def->uuid);
virDomainDeviceInfoClear(&def->info);
g_free(def);
Reviewed-by: Ján Tomko <jtomko(a)redhat.com>
Jano