The virDomainMemoryModel structure has a @type member which is
really type of virDomainMemoryModel but we store it as int
because the virDomainMemoryModelTypeFromString() call stores its
retval right into it. Then, to have compiler do compile time
check for us, every switch() typecasts the @type. This is
needlessly verbose because the parses already has @val - a
variable to store temporary values. Switch @type in the struct to
virDomainMemoryModel and drop all typecasts.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/conf/domain_conf.c | 9 +++++----
src/conf/domain_conf.h | 2 +-
src/qemu/qemu_command.c | 2 +-
src/qemu/qemu_domain.c | 4 ++--
src/security/security_apparmor.c | 2 +-
src/security/security_dac.c | 4 ++--
src/security/security_selinux.c | 4 ++--
7 files changed, 14 insertions(+), 13 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index da14760e2d..2a2cfd24e0 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -16676,7 +16676,7 @@ virDomainMemorySourceDefParseXML(xmlNodePtr node,
ctxt->node = node;
- switch ((virDomainMemoryModel) def->model) {
+ switch (def->model) {
case VIR_DOMAIN_MEMORY_MODEL_DIMM:
if (virDomainParseMemory("./pagesize", "./pagesize/@unit",
ctxt,
&def->pagesize, false, false) < 0)
@@ -16897,12 +16897,13 @@ virDomainMemoryDefParseXML(virDomainXMLOptionPtr xmlopt,
goto error;
}
- if ((def->model = virDomainMemoryModelTypeFromString(tmp)) <= 0) {
+ if ((val = virDomainMemoryModelTypeFromString(tmp)) <= 0) {
virReportError(VIR_ERR_XML_ERROR,
_("invalid memory model '%s'"), tmp);
goto error;
}
VIR_FREE(tmp);
+ def->model = val;
if ((tmp = virXMLPropString(memdevNode, "access"))) {
if ((val = virDomainMemoryAccessTypeFromString(tmp)) <= 0) {
@@ -18579,7 +18580,7 @@ virDomainMemoryFindByDefInternal(virDomainDefPtr def,
tmp->size != mem->size)
continue;
- switch ((virDomainMemoryModel) mem->model) {
+ switch (mem->model) {
case VIR_DOMAIN_MEMORY_MODEL_DIMM:
/* source stuff -> match with device */
if (tmp->pagesize != mem->pagesize)
@@ -27846,7 +27847,7 @@ virDomainMemorySourceDefFormat(virBufferPtr buf,
virBufferAddLit(buf, "<source>\n");
virBufferAdjustIndent(buf, 2);
- switch ((virDomainMemoryModel) def->model) {
+ switch (def->model) {
case VIR_DOMAIN_MEMORY_MODEL_DIMM:
if (def->sourceNodes) {
if (!(bitmap = virBitmapFormat(def->sourceNodes)))
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 34cde22965..5853e3b290 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2322,7 +2322,7 @@ struct _virDomainMemoryDef {
bool nvdimmPmem; /* valid only for NVDIMM */
/* target */
- int model; /* virDomainMemoryModel */
+ virDomainMemoryModel model;
int targetNode;
unsigned long long size; /* kibibytes */
unsigned long long labelsize; /* kibibytes; valid only for NVDIMM */
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 33f9b96bf8..eb64ce84da 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3280,7 +3280,7 @@ qemuBuildMemoryDeviceStr(virDomainMemoryDefPtr mem)
return NULL;
}
- switch ((virDomainMemoryModel) mem->model) {
+ switch (mem->model) {
case VIR_DOMAIN_MEMORY_MODEL_NVDIMM:
case VIR_DOMAIN_MEMORY_MODEL_DIMM:
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 663c0af867..19a699540f 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -8485,7 +8485,7 @@ static int
qemuDomainDefValidateMemoryHotplugDevice(const virDomainMemoryDef *mem,
const virDomainDef *def)
{
- switch ((virDomainMemoryModel) mem->model) {
+ switch (mem->model) {
case VIR_DOMAIN_MEMORY_MODEL_DIMM:
case VIR_DOMAIN_MEMORY_MODEL_NVDIMM:
if (mem->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DIMM &&
@@ -8598,7 +8598,7 @@ qemuDomainDefValidateMemoryHotplug(const virDomainDef *def,
for (i = 0; i < def->nmems; i++) {
hotplugMemory += def->mems[i]->size;
- switch ((virDomainMemoryModel) def->mems[i]->model) {
+ switch (def->mems[i]->model) {
case VIR_DOMAIN_MEMORY_MODEL_DIMM:
needPCDimmCap = true;
break;
diff --git a/src/security/security_apparmor.c b/src/security/security_apparmor.c
index f306af8dd3..eed66e460f 100644
--- a/src/security/security_apparmor.c
+++ b/src/security/security_apparmor.c
@@ -684,7 +684,7 @@ AppArmorSetMemoryLabel(virSecurityManagerPtr mgr,
if (mem == NULL)
return 0;
- switch ((virDomainMemoryModel) mem->model) {
+ switch (mem->model) {
case VIR_DOMAIN_MEMORY_MODEL_NVDIMM:
if (!virFileExists(mem->nvdimmPath)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
diff --git a/src/security/security_dac.c b/src/security/security_dac.c
index 258d246659..4f4a0a069e 100644
--- a/src/security/security_dac.c
+++ b/src/security/security_dac.c
@@ -1887,7 +1887,7 @@ virSecurityDACRestoreMemoryLabel(virSecurityManagerPtr mgr,
{
int ret = -1;
- switch ((virDomainMemoryModel) mem->model) {
+ switch (mem->model) {
case VIR_DOMAIN_MEMORY_MODEL_NVDIMM:
ret = virSecurityDACRestoreFileLabel(mgr, mem->nvdimmPath);
break;
@@ -2060,7 +2060,7 @@ virSecurityDACSetMemoryLabel(virSecurityManagerPtr mgr,
uid_t user;
gid_t group;
- switch ((virDomainMemoryModel) mem->model) {
+ switch (mem->model) {
case VIR_DOMAIN_MEMORY_MODEL_NVDIMM:
seclabel = virDomainDefGetSecurityLabelDef(def, SECURITY_DAC_NAME);
if (seclabel && !seclabel->relabel)
diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c
index c0e76b2222..e9cd95916e 100644
--- a/src/security/security_selinux.c
+++ b/src/security/security_selinux.c
@@ -1571,7 +1571,7 @@ virSecuritySELinuxSetMemoryLabel(virSecurityManagerPtr mgr,
{
virSecurityLabelDefPtr seclabel;
- switch ((virDomainMemoryModel) mem->model) {
+ switch (mem->model) {
case VIR_DOMAIN_MEMORY_MODEL_NVDIMM:
seclabel = virDomainDefGetSecurityLabelDef(def, SECURITY_SELINUX_NAME);
if (!seclabel || !seclabel->relabel)
@@ -1600,7 +1600,7 @@ virSecuritySELinuxRestoreMemoryLabel(virSecurityManagerPtr mgr,
int ret = -1;
virSecurityLabelDefPtr seclabel;
- switch ((virDomainMemoryModel) mem->model) {
+ switch (mem->model) {
case VIR_DOMAIN_MEMORY_MODEL_NVDIMM:
seclabel = virDomainDefGetSecurityLabelDef(def, SECURITY_SELINUX_NAME);
if (!seclabel || !seclabel->relabel)
--
2.26.2