From nobody Mon Feb 9 10:27:09 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1643018955; cv=none; d=zohomail.com; s=zohoarc; b=mt0Y/rIPYpWvNAhae59EKjAFa8n+N+ITXNt2a5eojijZhWG09Ek/1huki31TEk4EFIa6s4MiwCiBsKcoKq3UNHIb2GbnVsay+On2MZ3A5jRZJM6Mb9xzY0yWnyDJ3MuD7jbWYe0Q9EX/akiXAKRNHSn5Mte9PBeC1jCG41DKzeY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1643018955; h=Content-Type:Content-Transfer-Encoding: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=znYDeMNs68cBZYSQl3CkJWmxHCBJIGFGZWaSX1AiMW8=; b=T/Kjyrd2+0QXbgI7rQuQ71f1fSyKRS+p4Ff64OXSHwf9tUOWE/S5ocftFQ5ib/WyfjuizD9+k75c1sbqHbXwL0+QZZaBdWNWv6qxBhFm7PVhyV+n+d5eeXlg7JL/akQiyNXBWDbqHlHDwtRkvY75YtX8WYJcl5L7EcXdBQ3R+Dk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1643018955192344.0365825390844; Mon, 24 Jan 2022 02:09:15 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-424-SKfcDSYnPAuZVjvmoW1K5w-1; Mon, 24 Jan 2022 05:09:12 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 92591192CC47; Mon, 24 Jan 2022 10:09:07 +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 7073510595B9; Mon, 24 Jan 2022 10:09:07 +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 4086F180B617; Mon, 24 Jan 2022 10:09:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 20OA7vWx021096 for ; Mon, 24 Jan 2022 05:07:57 -0500 Received: by smtp.corp.redhat.com (Postfix) id C33BF6F120; Mon, 24 Jan 2022 10:07:57 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.195.147]) by smtp.corp.redhat.com (Postfix) with ESMTP id 361306D03D for ; Mon, 24 Jan 2022 10:07:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643018954; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to: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=znYDeMNs68cBZYSQl3CkJWmxHCBJIGFGZWaSX1AiMW8=; b=h0pRfdL32DzlB84X8q+ealOpe3t9VeJnaT8oCtBRUq7HKP025uxePIEBW5szHFakNBheCT 8ppfoCq6exrMaS2MqHAeFGGEZcRuYaJhGV/hm2924nkobtsOUvy59WHt756iw55eVRuJyI 6dvHDQs4TkKjotgdVy7vKktxDtRmJq0= X-MC-Unique: SKfcDSYnPAuZVjvmoW1K5w-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 05/11] conf: Fix type of @present in _virDomainTimerDef struct Date: Mon, 24 Jan 2022 11:07:27 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@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.22 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) X-ZM-MESSAGEID: 1643018958307100001 Content-Type: text/plain; charset="utf-8" In the _virDomainTimerDef structure we have @present member which is like virTristateBool, except it's an integer and has values shifted by one. This is harder to read. Retype the member to virTristateBool which we are familiar with. Signed-off-by: Michal Privoznik --- src/conf/domain_conf.c | 27 ++++++++++----------------- src/conf/domain_conf.h | 2 +- src/libxl/libxl_conf.c | 2 +- src/libxl/xen_common.c | 13 +++++++++---- src/lxc/lxc_cgroup.c | 2 +- src/lxc/lxc_controller.c | 2 +- src/qemu/qemu_command.c | 20 ++++++++++---------- src/qemu/qemu_validate.c | 6 +++--- 8 files changed, 36 insertions(+), 38 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index bb887d4a3b..fbe21c4fd2 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -11998,7 +11998,6 @@ virDomainTimerDefParseXML(xmlNodePtr node, xmlNodePtr catchup; int ret; g_autofree char *name =3D NULL; - g_autofree char *present =3D NULL; g_autofree char *tickpolicy =3D NULL; g_autofree char *track =3D NULL; g_autofree char *mode =3D NULL; @@ -12019,16 +12018,10 @@ virDomainTimerDefParseXML(xmlNodePtr node, goto error; } =20 - def->present =3D -1; /* unspecified */ - if ((present =3D virXMLPropString(node, "present")) !=3D NULL) { - bool state =3D false; - if (virStringParseYesNo(present, &state) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unknown timer present value '%s'"), present); - goto error; - } - def->present =3D state ? 1 : 0; - } + if (virXMLPropTristateBool(node, "present", + VIR_XML_PROP_NONE, + &def->present) < 0) + goto error; =20 def->tickpolicy =3D -1; tickpolicy =3D virXMLPropString(node, "tickpolicy"); @@ -20481,8 +20474,9 @@ virDomainTimerDefCheckABIStability(virDomainTimerDe= f *src, =20 if (src->present !=3D dst->present) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Target timer presence %d does not match source %= d"), - dst->present, src->present); + _("Target timer presence %s does not match source %= s"), + virTristateBoolTypeToString(dst->present), + virTristateBoolTypeToString(src->present)); return false; } =20 @@ -26119,10 +26113,9 @@ virDomainTimerDefFormat(virBuffer *buf, } virBufferAsprintf(buf, "present =3D=3D 0) { - virBufferAddLit(buf, " present=3D'no'"); - } else if (def->present =3D=3D 1) { - virBufferAddLit(buf, " present=3D'yes'"); + if (def->present) { + virBufferAsprintf(buf, " present=3D'%s'", + virTristateBoolTypeToString(def->present)); } =20 if (def->tickpolicy !=3D -1) { diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 764e025448..f995cbc045 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2409,7 +2409,7 @@ struct _virDomainTimerCatchupDef { =20 struct _virDomainTimerDef { int name; - int present; /* unspecified =3D -1, no =3D 0, yes =3D 1 */ + virTristateBool present; int tickpolicy; /* none|catchup|merge|discard */ =20 virDomainTimerCatchupDef catchup; diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index 561171126c..5d87b999f2 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -423,7 +423,7 @@ libxlMakeDomBuildInfo(virDomainDef *def, virDomainTimerNameTypeToString(clock.timers= [i]->name)); return -1; } - if (clock.timers[i]->present =3D=3D 1) + if (clock.timers[i]->present =3D=3D VIR_TRISTATE_BOOL_YES) libxl_defbool_set(&b_info->u.hvm.hpet, 1); break; =20 diff --git a/src/libxl/xen_common.c b/src/libxl/xen_common.c index c3fa98b71d..0679f441cc 100644 --- a/src/libxl/xen_common.c +++ b/src/libxl/xen_common.c @@ -553,7 +553,7 @@ xenParseHypervisorFeatures(virConf *conf, virDomainDef = *def) =20 timer =3D g_new0(virDomainTimerDef, 1); timer->name =3D VIR_DOMAIN_TIMER_NAME_TSC; - timer->present =3D 1; + timer->present =3D VIR_TRISTATE_BOOL_YES; timer->tickpolicy =3D -1; timer->mode =3D VIR_DOMAIN_TIMER_MODE_AUTO; timer->track =3D -1; @@ -625,7 +625,11 @@ xenParseHypervisorFeatures(virConf *conf, virDomainDef= *def) =20 timer =3D g_new0(virDomainTimerDef, 1); timer->name =3D VIR_DOMAIN_TIMER_NAME_HPET; - timer->present =3D val; + if (val =3D=3D 1) { + timer->present =3D VIR_TRISTATE_BOOL_YES; + } else { + timer->present =3D VIR_TRISTATE_BOOL_NO; + } timer->tickpolicy =3D -1; timer->mode =3D -1; timer->track =3D -1; @@ -2112,9 +2116,10 @@ xenFormatHypervisorFeatures(virConf *conf, virDomain= Def *def) =20 case VIR_DOMAIN_TIMER_NAME_HPET: if (hvm) { - int enable_hpet =3D def->clock.timers[i]->present !=3D 0; + int enable_hpet =3D def->clock.timers[i]->present !=3D VIR= _TRISTATE_BOOL_NO; =20 - /* disable hpet if 'present' is 0, enable otherwise */ + /* disable hpet if 'present' is VIR_TRISTATE_BOOL_NO, enab= le + * otherwise */ if (xenConfigSetInt(conf, "hpet", enable_hpet) < 0) return -1; } else { diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c index 736b2000ff..d31fff5f98 100644 --- a/src/lxc/lxc_cgroup.c +++ b/src/lxc/lxc_cgroup.c @@ -332,7 +332,7 @@ static int virLXCCgroupSetupDeviceACL(virDomainDef *def, const char *dev =3D NULL; =20 /* Check if "present" is set to "no" otherwise enable it. */ - if (!timer->present) + if (timer->present =3D=3D VIR_TRISTATE_BOOL_NO) continue; =20 switch ((virDomainTimerNameType)timer->name) { diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index 3c930eaacd..c4e3b66751 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -1510,7 +1510,7 @@ virLXCControllerSetupTimers(virLXCController *ctrl) dev_t dev; =20 /* Check if "present" is set to "no" otherwise enable it. */ - if (!timer->present) + if (timer->present =3D=3D VIR_TRISTATE_BOOL_NO) continue; =20 switch ((virDomainTimerNameType)timer->name) { diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 52ea148a0f..a62d3f36ae 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -6293,15 +6293,14 @@ qemuBuildClockCommandLine(virCommand *cmd, break; =20 case VIR_DOMAIN_TIMER_NAME_HPET: - /* the only meaningful attribute for hpet is "present". If - * present is -1, that means it wasn't specified, and - * should be left at the default for the - * hypervisor. "default" when -no-hpet exists is "yes", - * and when -no-hpet doesn't exist is "no". "confusing"? - * "yes"! */ + /* the only meaningful attribute for hpet is "present". If pre= sent + * is VIR_TRISTATE_BOOL_ABSENT, that means it wasn't specified= , and + * should be left at the default for the hypervisor. "default"= when + * -no-hpet exists is VIR_TRISTATE_BOOL_YES, and when -no-hpet + * doesn't exist is VIR_TRISTATE_BOOL_NO. "confusing"? "yes"= ! */ =20 if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_NO_HPET)) { - if (def->clock.timers[i]->present =3D=3D 0) + if (def->clock.timers[i]->present =3D=3D VIR_TRISTATE_BOOL= _NO) virCommandAddArg(cmd, "-no-hpet"); } break; @@ -6638,13 +6637,14 @@ qemuBuildCpuCommandLine(virCommand *cmd, =20 switch ((virDomainTimerNameType)timer->name) { case VIR_DOMAIN_TIMER_NAME_KVMCLOCK: - if (timer->present !=3D -1) { + if (timer->present !=3D VIR_TRISTATE_BOOL_ABSENT) { + /* QEMU expects on/off -> virTristateSwitch. */ virBufferAsprintf(&buf, ",kvmclock=3D%s", - timer->present ? "on" : "off"); + virTristateSwitchTypeToString(timer->pre= sent)); } break; case VIR_DOMAIN_TIMER_NAME_HYPERVCLOCK: - if (timer->present =3D=3D 1) + if (timer->present =3D=3D VIR_TRISTATE_BOOL_YES) virBufferAddLit(&buf, ",hv-time=3Don"); break; case VIR_DOMAIN_TIMER_NAME_TSC: diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index 0a879f0115..b62e49a5bc 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -411,7 +411,7 @@ qemuValidateDomainDefClockTimers(const virDomainDef *de= f, case VIR_DOMAIN_TIMER_NAME_TSC: case VIR_DOMAIN_TIMER_NAME_KVMCLOCK: case VIR_DOMAIN_TIMER_NAME_HYPERVCLOCK: - if (!ARCH_IS_X86(def->os.arch) && timer->present =3D=3D 1) { + if (!ARCH_IS_X86(def->os.arch) && timer->present =3D=3D VIR_TR= ISTATE_BOOL_YES) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Configuring the '%s' timer is not suppor= ted " "for virtType=3D%s arch=3D%s machine=3D%s= guests"), @@ -489,7 +489,7 @@ qemuValidateDomainDefClockTimers(const virDomainDef *de= f, /* no hpet timer available. The only possible action is to raise an error if present=3D"yes" */ if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_NO_HPET) && - timer->present =3D=3D 1) { + timer->present =3D=3D VIR_TRISTATE_BOOL_YES) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("hpet timer is not supported")); return -1; @@ -508,7 +508,7 @@ qemuValidateDomainDefClockTimers(const virDomainDef *de= f, def->os.machine); return -1; } - if (timer->present =3D=3D 0) { + if (timer->present =3D=3D VIR_TRISTATE_BOOL_NO) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("The '%s' timer can't be disabled"), virDomainTimerNameTypeToString(timer->name)= ); --=20 2.34.1