From nobody Sun Feb 8 05:41:49 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1607466073; cv=none; d=zohomail.com; s=zohoarc; b=m5rtpEZq7EqPiigHgIMoxbJxVUPk9yPR3UkStiAyP4A2M+PUNo1JMDxydBaB99RNsmOwottMnqcFNij57/s2O0axQ0q/iAoXUCpwOhX+bLfB9Mygiu/pip6u1/U74MRhckpIjukf9DvJDPMq95M+k6GCPhrwdGP096IQPYFsgyA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1607466073; 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=hguOumYfPYevvJRjPnRVffoFQdM2brfNLVbeUZqC37c=; b=STQLE6H0hCAY/M7L/DAAKRd+7kOVZ9wushgdTp1PptZKUzBC9SsjVothmDsl6FojVWvwFuIhGA5nihXIg0DtFVnYQlWszzg9t3qNMb/EpYsjaB8Zr9KJo7IzJoQRbjDDFEMxuLMZEuu4bS7hI/hNkIwfFB3Hz7WmAMjbBHRcfSg= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1607466073934432.73290860973293; Tue, 8 Dec 2020 14:21:13 -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-526-xN-2vZaLP2q-Zkjff-E6vg-1; Tue, 08 Dec 2020 17:21:09 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 97296180A087; Tue, 8 Dec 2020 22:21:03 +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 747E150C0B; Tue, 8 Dec 2020 22:21:03 +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 35D671809CA2; Tue, 8 Dec 2020 22:21:03 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0B8MKwBQ017241 for ; Tue, 8 Dec 2020 17:20:58 -0500 Received: by smtp.corp.redhat.com (Postfix) id 8975BA9FBD; Tue, 8 Dec 2020 22:20:58 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 81DA8A9FDF for ; Tue, 8 Dec 2020 22:20:56 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 34347800C00 for ; Tue, 8 Dec 2020 22:20:56 +0000 (UTC) Received: from mail-qt1-f177.google.com (mail-qt1-f177.google.com [209.85.160.177]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-164-jUELdIPJNLiYxkQAoTO8XA-1; Tue, 08 Dec 2020 17:20:52 -0500 Received: by mail-qt1-f177.google.com with SMTP id l7so13142502qtp.8; Tue, 08 Dec 2020 14:20:51 -0800 (PST) Received: from rekt.redhat.com ([2804:431:c7c7:c1a:69c1:2b22:e880:fc49]) by smtp.gmail.com with ESMTPSA id c14sm75057qtg.85.2020.12.08.14.20.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 14:20:50 -0800 (PST) X-MC-Unique: xN-2vZaLP2q-Zkjff-E6vg-1 X-MC-Unique: jUELdIPJNLiYxkQAoTO8XA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hguOumYfPYevvJRjPnRVffoFQdM2brfNLVbeUZqC37c=; b=L+KciOz528iObglHAO/aVw8G5yIlz032wu/C5inyLsDz0xNpKmph79Bam5ad4ownKG GsKcIHEjC8jH14ARMhil+5G6iRYagqPCP2jOPKHxIMhtNmnn9e46mIXOJx/rh70HdMWk GPHCkurOFmI11vC2vE9LoKhhbYZTqoUEi+H9wP0zbuIOfynfEXX9CNy9yvmuD0fL43A6 5eFeuOu1gacekAu+uRf5GiF9fwGKpSzHWn0AoV9jt2P/Ru0I3ieuTpQHj+pnqETxl1Zq yGQqKjc6PgGeLpPYZJt/6rLBPvNMgXzf1V4ZslbOzMtrCbJARepDwDIY4CV96NoB22Pv oofQ== X-Gm-Message-State: AOAM530lPuYN7cjecbUSedfUvIUUqAwLB/1TAMZPtHj6nMwYmPzLw7mL 1JJTXc5CPfvXOQxbzMNwiBHnIAFweK0= X-Google-Smtp-Source: ABdhPJytHmp2DBRxO3/wbOseRoufHNmm8AFpz6+CISBsMlUZ8POW+HHufWVvkrVqYFuKTknjU1M4kQ== X-Received: by 2002:ac8:5911:: with SMTP id 17mr254968qty.218.1607466051211; Tue, 08 Dec 2020 14:20:51 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v3 01/14] domain_conf: move boot timeouts check to domain_validate.c Date: Tue, 8 Dec 2020 19:20:17 -0300 Message-Id: <20201208222030.1302229-2-danielhb413@gmail.com> In-Reply-To: <20201208222030.1302229-1-danielhb413@gmail.com> References: <20201208222030.1302229-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: Michal Privoznik , Daniel Henrique Barboza 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.79 on 10.5.11.11 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 Content-Type: text/plain; charset="utf-8" This patch creates a new function, virDomainDefBootValidate(), to host the validation of boot menu timeout and rebootTimeout outside of parse time. The checks in virDomainDefParseBootXML() were changed to throw VIR_ERR_XML_ERROR in case of parse error of those values. In an attempt to alleviate the amount of code being stacked inside domain_conf.c, let's put this new function in a new domain_validate.c file that will be used to place these validations. Suggested-by: Michal Privoznik Signed-off-by: Daniel Henrique Barboza --- po/POTFILES.in | 1 + src/conf/domain_conf.c | 20 +++++++-------- src/conf/domain_validate.c | 51 ++++++++++++++++++++++++++++++++++++++ src/conf/domain_validate.h | 27 ++++++++++++++++++++ src/conf/meson.build | 1 + tests/qemuxml2argvtest.c | 3 ++- 6 files changed, 92 insertions(+), 11 deletions(-) create mode 100644 src/conf/domain_validate.c create mode 100644 src/conf/domain_validate.h diff --git a/po/POTFILES.in b/po/POTFILES.in index 9782b2beb4..14636d4b93 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -26,6 +26,7 @@ @SRCDIR@src/conf/domain_capabilities.c @SRCDIR@src/conf/domain_conf.c @SRCDIR@src/conf/domain_event.c +@SRCDIR@src/conf/domain_validate.c @SRCDIR@src/conf/interface_conf.c @SRCDIR@src/conf/netdev_bandwidth_conf.c @SRCDIR@src/conf/netdev_vlan_conf.c diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 66ee658e7b..4a45c76cf1 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -33,6 +33,7 @@ #include "datatypes.h" #include "domain_addr.h" #include "domain_conf.h" +#include "domain_validate.h" #include "snapshot_conf.h" #include "viralloc.h" #include "virxml.h" @@ -7344,6 +7345,9 @@ virDomainDefValidateInternal(const virDomainDef *def, if (virDomainDefCputuneValidate(def) < 0) return -1; =20 + if (virDomainDefBootValidate(def) < 0) + return -1; + if (virDomainNumaDefValidate(def->numa) < 0) return -1; =20 @@ -18867,11 +18871,9 @@ virDomainDefParseBootXML(xmlXPathContextPtr ctxt, =20 tmp =3D virXMLPropString(node, "timeout"); if (tmp && def->os.bootmenu =3D=3D VIR_TRISTATE_BOOL_YES) { - if (virStrToLong_uip(tmp, NULL, 0, &def->os.bm_timeout) < 0 || - def->os.bm_timeout > 65535) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("invalid value for boot menu timeout, " - "must be in range [0,65535]")); + if (virStrToLong_uip(tmp, NULL, 0, &def->os.bm_timeout) < 0) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("invalid value for boot menu timeout")); return -1; } def->os.bm_timeout_set =3D true; @@ -18892,11 +18894,9 @@ virDomainDefParseBootXML(xmlXPathContextPtr ctxt, if (tmp) { /* that was really just for the check if it is there */ =20 - if (virStrToLong_i(tmp, NULL, 0, &def->os.bios.rt_delay) < 0 || - def->os.bios.rt_delay < -1 || def->os.bios.rt_delay > 6553= 5) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("invalid value for rebootTimeout, " - "must be in range [-1,65535]")); + if (virStrToLong_i(tmp, NULL, 0, &def->os.bios.rt_delay) < 0) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("invalid value for rebootTimeout")); return -1; } def->os.bios.rt_set =3D true; diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c new file mode 100644 index 0000000000..e4d947c553 --- /dev/null +++ b/src/conf/domain_validate.c @@ -0,0 +1,51 @@ +/* + * domain_validate.c: domain general validation functions + * + * Copyright IBM Corp, 2020 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#include + +#include "domain_validate.h" +#include "domain_conf.h" +#include "virlog.h" +#include "virutil.h" + +#define VIR_FROM_THIS VIR_FROM_DOMAIN + +VIR_LOG_INIT("conf.domain_validate"); + +int +virDomainDefBootValidate(const virDomainDef *def) +{ + if (def->os.bm_timeout_set && def->os.bm_timeout > 65535) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("invalid value for boot menu timeout, " + "must be in range [0,65535]")); + return -1; + } + + if (def->os.bios.rt_set && + (def->os.bios.rt_delay < -1 || def->os.bios.rt_delay > 65535)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("invalid value for rebootTimeout, " + "must be in range [-1,65535]")); + return -1; + } + + return 0; +} diff --git a/src/conf/domain_validate.h b/src/conf/domain_validate.h new file mode 100644 index 0000000000..2b558668a9 --- /dev/null +++ b/src/conf/domain_validate.h @@ -0,0 +1,27 @@ +/* + * domain_validate.h: domain general validation functions + * + * Copyright IBM Corp, 2020 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#pragma once + +#include + +#include "domain_conf.h" + +int virDomainDefBootValidate(const virDomainDef *def); diff --git a/src/conf/meson.build b/src/conf/meson.build index 03b90aa6f6..8ddcc9968d 100644 --- a/src/conf/meson.build +++ b/src/conf/meson.build @@ -14,6 +14,7 @@ domain_conf_sources =3D [ 'domain_capabilities.c', 'domain_conf.c', 'domain_nwfilter.c', + 'domain_validate.c', 'moment_conf.c', 'numa_conf.c', 'snapshot_conf.c', diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 7c9dc0e641..202fc83ccf 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1006,7 +1006,8 @@ mymain(void) DO_TEST("boot-menu-enable-with-timeout", QEMU_CAPS_SPLASH_TIMEOUT); DO_TEST_PARSE_ERROR("boot-menu-enable-with-timeout", NONE); - DO_TEST_PARSE_ERROR("boot-menu-enable-with-timeout-invalid", NONE); + DO_TEST_PARSE_ERROR("boot-menu-enable-with-timeout-invalid", + QEMU_CAPS_SPLASH_TIMEOUT); DO_TEST("boot-menu-disable", NONE); DO_TEST("boot-menu-disable-drive", NONE); DO_TEST_PARSE_ERROR("boot-dev+order", --=20 2.26.2