]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
domain_conf: Fix virDomainMemoryModel type
authorMichal Privoznik <mprivozn@redhat.com>
Sat, 31 Oct 2020 20:24:08 +0000 (21:24 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 4 Dec 2020 15:24:19 +0000 (16:24 +0100)
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@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Tested-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Tested-by: Han Han <hhan@redhat.com>
src/conf/domain_conf.c
src/conf/domain_conf.h
src/qemu/qemu_command.c
src/qemu/qemu_domain.c
src/security/security_apparmor.c
src/security/security_dac.c
src/security/security_selinux.c

index da14760e2df4726ebf75a2ee213ea7d88c38efd4..2a2cfd24e005c8c5a7ec831c5af8791c9c01f4f1 100644 (file)
@@ -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)))
index 34cde22965052a0c3a52bd2ab6f34e632907c75c..5853e3b290329be14dc1c8f720fcd096dc30cf08 100644 (file)
@@ -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 */
index 5aff89188a95e275018fe1070689eaa9c0ec6063..10798933910daa6d9bd88f482d0cb899c0a75b04 100644 (file)
@@ -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:
 
index 663c0af86788de09cc38f743744653f41353c871..19a699540ff33f4067c524fafe1fe6d3367faff7 100644 (file)
@@ -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;
index f306af8dd31f5b1fab21971f7f08983ed7b19ca1..eed66e460f97457a81f885250d06f3fa50f8fd39 100644 (file)
@@ -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,
index 258d246659933e92dc3222f5791347dfe51027bd..4f4a0a069e0a573a5b797cd75bc0bcd1b21f0d96 100644 (file)
@@ -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)
index c0e76b2222ac2ff2c06d50c7a6df37e7b14329b3..e9cd95916e66bf173740ead517b1f2b093aef120 100644 (file)
@@ -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)