domain_conf: Fix virDomainMemoryModel type

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>
This commit is contained in:
Michal Privoznik 2020-10-31 21:24:08 +01:00
parent 6e4fbc97ff
commit e43fa9c932
7 changed files with 14 additions and 13 deletions

View 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)))

View 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 */

View 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:

View 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;

View 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,

View 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)

View 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)