From nobody Sun Feb 8 20:13:05 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1606489492; cv=none; d=zohomail.com; s=zohoarc; b=BoB2nPZfknugARJy/NVBxJQUW3o0B2Yi+D/CgOkebiwd/oJibJV/NpQxYzQARaj+kfL9SYYyDQlnARtwLomr3DjpRVNU4Qzly9CVFDq7/KzoIuBGzQfGw9Oz9I5hjmjk8hhqSsiTZvNng37nZf3G37HlvI1qGU4ETi873HwGVjs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606489492; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dInkNmEMO5zs21q1hLu99CEyQ25lD/S1GbOFXK4f76o=; b=fx8+zWe7MrHQMeb/9esPrn3Zr9a0Yvbkr/BtLu3DyCXJXunbtfYmwi8rLih5y+XWF2V9Oj+Zp75DCVqkhAGVqBPrCwjqyUDzUJhIYNT6vybKGmrj/3382RnA1N4NSOH9CCNGMk4m9yhEo5YXXICSucBAEakYeruRvshOaZJIImw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1606489491920911.3107593106841; Fri, 27 Nov 2020 07:04:51 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-131-3eDskDBUMKC-uqamjuvsvw-1; Fri, 27 Nov 2020 10:04:46 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8C734185E49E; Fri, 27 Nov 2020 15:04:39 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 39B6C1A88F; Fri, 27 Nov 2020 15:04:39 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id CF5A81809CA8; Fri, 27 Nov 2020 15:04:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0ARF4bRv030821 for ; Fri, 27 Nov 2020 10:04:37 -0500 Received: by smtp.corp.redhat.com (Postfix) id 8F9615D9D5; Fri, 27 Nov 2020 15:04:37 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.195.47]) by smtp.corp.redhat.com (Postfix) with ESMTP id BDAE35D9CC; Fri, 27 Nov 2020 15:04:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606489488; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=dInkNmEMO5zs21q1hLu99CEyQ25lD/S1GbOFXK4f76o=; b=iCDrMI9AgGFzIy0nLCtKdkCKeEtQSXOvnNRxOxlTMcxSD3n/WnAQa/8gZnXFODGe8pZOmF AdUlUtsRw55Sf2NvmgC9WyWUK0LqDxsX3TELmuo9eDIZWZML5R9lTpkKuF01EywSovHWf8 P1iAYfOH/yXjtxfk1zUVLOejpENBZpw= X-MC-Unique: 3eDskDBUMKC-uqamjuvsvw-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v1 07/26] domain_conf: Fix virDomainMemoryModel type Date: Fri, 27 Nov 2020 16:02:53 +0100 Message-Id: <9a72b0342fb93dea6586b39f0c26bbf3ba6e28f1.1606489221.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: david@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" 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 --- 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 6c1fa93b0a..38ddbacd66 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -16699,7 +16699,7 @@ virDomainMemorySourceDefParseXML(xmlNodePtr node, =20 ctxt->node =3D node; =20 - switch ((virDomainMemoryModel) def->model) { + switch (def->model) { case VIR_DOMAIN_MEMORY_MODEL_DIMM: if (virDomainParseMemory("./pagesize", "./pagesize/@unit", ctxt, &def->pagesize, false, false) < 0) @@ -16920,12 +16920,13 @@ virDomainMemoryDefParseXML(virDomainXMLOptionPtr = xmlopt, goto error; } =20 - if ((def->model =3D virDomainMemoryModelTypeFromString(tmp)) <=3D 0) { + if ((val =3D virDomainMemoryModelTypeFromString(tmp)) <=3D 0) { virReportError(VIR_ERR_XML_ERROR, _("invalid memory model '%s'"), tmp); goto error; } VIR_FREE(tmp); + def->model =3D val; =20 if ((tmp =3D virXMLPropString(memdevNode, "access"))) { if ((val =3D virDomainMemoryAccessTypeFromString(tmp)) <=3D 0) { @@ -18598,7 +18599,7 @@ virDomainMemoryFindByDefInternal(virDomainDefPtr de= f, tmp->size !=3D mem->size) continue; =20 - switch ((virDomainMemoryModel) mem->model) { + switch (mem->model) { case VIR_DOMAIN_MEMORY_MODEL_DIMM: /* source stuff -> match with device */ if (tmp->pagesize !=3D mem->pagesize) @@ -27884,7 +27885,7 @@ virDomainMemorySourceDefFormat(virBufferPtr buf, virBufferAddLit(buf, "\n"); virBufferAdjustIndent(buf, 2); =20 - switch ((virDomainMemoryModel) def->model) { + switch (def->model) { case VIR_DOMAIN_MEMORY_MODEL_DIMM: if (def->sourceNodes) { if (!(bitmap =3D virBitmapFormat(def->sourceNodes))) diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 96e6c34553..8ac23fd7d9 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 */ =20 /* 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 479bcc0b0c..568c0f6054 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3263,7 +3263,7 @@ qemuBuildMemoryDeviceStr(virDomainMemoryDefPtr mem) return NULL; } =20 - switch ((virDomainMemoryModel) mem->model) { + switch (mem->model) { case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: case VIR_DOMAIN_MEMORY_MODEL_DIMM: =20 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 !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DIMM && @@ -8598,7 +8598,7 @@ qemuDomainDefValidateMemoryHotplug(const virDomainDef= *def, for (i =3D 0; i < def->nmems; i++) { hotplugMemory +=3D def->mems[i]->size; =20 - switch ((virDomainMemoryModel) def->mems[i]->model) { + switch (def->mems[i]->model) { case VIR_DOMAIN_MEMORY_MODEL_DIMM: needPCDimmCap =3D true; break; diff --git a/src/security/security_apparmor.c b/src/security/security_appar= mor.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 =3D=3D NULL) return 0; =20 - 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(virSecurityManagerPt= r mgr, { int ret =3D -1; =20 - switch ((virDomainMemoryModel) mem->model) { + switch (mem->model) { case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: ret =3D virSecurityDACRestoreFileLabel(mgr, mem->nvdimmPath); break; @@ -2060,7 +2060,7 @@ virSecurityDACSetMemoryLabel(virSecurityManagerPtr mg= r, uid_t user; gid_t group; =20 - switch ((virDomainMemoryModel) mem->model) { + switch (mem->model) { case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: seclabel =3D virDomainDefGetSecurityLabelDef(def, SECURITY_DAC_NAM= E); if (seclabel && !seclabel->relabel) diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index c0e76b2222..e9cd95916e 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -1571,7 +1571,7 @@ virSecuritySELinuxSetMemoryLabel(virSecurityManagerPt= r mgr, { virSecurityLabelDefPtr seclabel; =20 - switch ((virDomainMemoryModel) mem->model) { + switch (mem->model) { case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: seclabel =3D virDomainDefGetSecurityLabelDef(def, SECURITY_SELINUX= _NAME); if (!seclabel || !seclabel->relabel) @@ -1600,7 +1600,7 @@ virSecuritySELinuxRestoreMemoryLabel(virSecurityManag= erPtr mgr, int ret =3D -1; virSecurityLabelDefPtr seclabel; =20 - switch ((virDomainMemoryModel) mem->model) { + switch (mem->model) { case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: seclabel =3D virDomainDefGetSecurityLabelDef(def, SECURITY_SELINUX= _NAME); if (!seclabel || !seclabel->relabel) --=20 2.26.2