From nobody Thu Mar 28 20:06:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1552535728402727.5285160078901; Wed, 13 Mar 2019 20:55:28 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2BE4A2DE417; Thu, 14 Mar 2019 03:55:26 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5CD8C6B8E8; Thu, 14 Mar 2019 03:55:24 +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 562B241F3C; Thu, 14 Mar 2019 03:55:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2E3tKgJ027236 for ; Wed, 13 Mar 2019 23:55:20 -0400 Received: by smtp.corp.redhat.com (Postfix) id 40C861001DDC; Thu, 14 Mar 2019 03:55:20 +0000 (UTC) Received: from mx1.redhat.com (ext-mx03.extmail.prod.ext.phx2.redhat.com [10.5.110.27]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3B7901001DD4 for ; Thu, 14 Mar 2019 03:55:18 +0000 (UTC) Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CF4BC8AE57 for ; Thu, 14 Mar 2019 03:55:16 +0000 (UTC) Received: by mail-pg1-f196.google.com with SMTP id q206so3049844pgq.4 for ; Wed, 13 Mar 2019 20:55:16 -0700 (PDT) Received: from localhost.localdomain.localdomain ([150.135.165.10]) by smtp.gmail.com with ESMTPSA id o1sm10772340pgp.76.2019.03.13.20.55.14 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 13 Mar 2019 20:55:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=R4IgdYJOdp3Jt6CWaENlyQvO32Bz0rv0Jno2RHty6iw=; b=N+bHzgIGIKJX55McVG/zR8AzAVkWRsdjGTEr11NQy/75v5VdgcciiwXjXCnMrXwyrG sD3xqc2oIGFN9BHSL8U6ec5RfrYn8krf1YPYg2a8KxBaExyuedKpNHqOABaLoZGDz/oT OSrfbHpvNy+EZ89IOxwGyF69BHe2lB9XqtksxCsyOx23pI+vv5qlZd4V1C7w/FrDml1I HD9R7Yp1BkQZDtOq8sguhnCWNC+NyR9GesEZW29qCv9HifxFGxZjNxTCwq8JLcIIuGZR BxKJhtl4DNGHG6DbVO5tfRPkJ6Ur2jFplcTcCH/VFX/wcwN2pI6ktniHshfNJROtbBgO yUEw== 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:mime-version :content-transfer-encoding; bh=R4IgdYJOdp3Jt6CWaENlyQvO32Bz0rv0Jno2RHty6iw=; b=glV8s4skqFTGmpj9p5xC/6fsW8SvdOk7Z99XSSZljS17Q7yFnJVb+ODvc3tLZbbqSE Qg8Zn4sZt1TY4L9i1LszQQZFJBTqo2qBqqE+GDGlBg0Hpa+WaAh+okag4RxGqPNWHxgX DWkBSRyBv4wsB+BpbJE1ciGZR8rbFGFjOY9/ZJonnxfqTn+R3mcesPz2sspRNxL+xpHc KkOor6ZyPg2Yao/ceOlK9t4YvCk4TDJTkBaiYeepfxgnucRR1T+S7R/phLPCw4mtWU0X HmgJt9nJV3f7nZpfl+CqX2CFVF7klekBAuaMnm240OYvqkceiV/41Ak2XuWGJfdYGAAy AMAQ== X-Gm-Message-State: APjAAAV/HBCnyCKU7sScizoS3nUdEx+0i0PppBoI8GGF3lSawmfcPcph V2rUcYfhOvU6tn62ccxus5DwnDXi X-Google-Smtp-Source: APXvYqy0qmgEF9ZFGXC4px7tC0LF9WIHy3z6Qdw1Jnmpkb/RQQcOhuTTpzpOI2UPVpH7bl7ulbC8Vg== X-Received: by 2002:a63:fd07:: with SMTP id d7mr42833180pgh.199.1552535715954; Wed, 13 Mar 2019 20:55:15 -0700 (PDT) From: Suyang Chen To: libvir-list@redhat.com Date: Wed, 13 Mar 2019 21:54:31 -0600 Message-Id: <20190314035431.52411-1-dawson0xff@gmail.com> MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 14 Mar 2019 03:55:17 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 14 Mar 2019 03:55:17 +0000 (UTC) for IP:'209.85.215.196' DOMAIN:'mail-pg1-f196.google.com' HELO:'mail-pg1-f196.google.com' FROM:'dawson0xff@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.108 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 209.85.215.196 mail-pg1-f196.google.com 209.85.215.196 mail-pg1-f196.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.27 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: Suyang Chen Subject: [libvirt] [PATCH] conf: Introduce virDomainDefCputuneValidate helper 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 14 Mar 2019 03:55:27 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" move all the def->cputune 'period must be in range' and 'quota must be in range' errors into two macros and called in virDomainDefCputuneValidate function and have it called from virDomainDefValidateInternal function Reason: Two macros maybe easier to debug and change in the future Solve the first two small tasks in bitsizedtask: "Move validation checks out of domain XML parsing" Signed-off-by: Suyang Chen Reviewed-by: Erik Skultety --- src/conf/domain_conf.c | 109 +++++++++++++++-------------------------- 1 file changed, 40 insertions(+), 69 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 356a9ae56c..c159cffa05 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -6565,6 +6565,43 @@ virDomainDefLifecycleActionValidate(const virDomainD= ef *def) return 0; } =20 +#define CPUTUNE_VALIDATE_PERIOD(name) \ + if (def->cputune.name > 0 && \ + (def->cputune.name < 1000 || def->cputune.name > 1000000)) { \ + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, \ + _("Value of cputune '%s' must be in range " \ + "[1000, 1000000]"), #name); \ + return -1; \ + } + +#define CPUTUNE_VALIDATE_QUOTA(name) \ + if (def->cputune.name > 0 && \ + (def->cputune.name < 1000 || \ + def->cputune.name > 18446744073709551LL)) { \ + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, \ + _("Value of cputune '%s' must be in range " \ + "[1000, 18446744073709551]"), #name); \ + return -1; \ + } + +static int +virDomainDefCputuneValidate(const virDomainDef *def) +{ + CPUTUNE_VALIDATE_PERIOD(period) + CPUTUNE_VALIDATE_PERIOD(global_period) + CPUTUNE_VALIDATE_PERIOD(emulator_period) + CPUTUNE_VALIDATE_PERIOD(iothread_period) + + CPUTUNE_VALIDATE_QUOTA(quota) + CPUTUNE_VALIDATE_QUOTA(global_quota) + CPUTUNE_VALIDATE_QUOTA(emulator_quota) + CPUTUNE_VALIDATE_QUOTA(iothread_quota) + + return 0; +} + +#undef CPUTUNE_VALIDATE_PERIOD +#undef CPUTUNE_VALIDATE_QUOTA =20 static int virDomainDefMemtuneValidate(const virDomainDef *def) @@ -6685,6 +6722,9 @@ virDomainDefValidateInternal(const virDomainDef *def, if (virDomainDefOSValidate(def, xmlopt) < 0) return -1; =20 + if (virDomainDefCputuneValidate(def) < 0) + return -1; + return 0; } =20 @@ -19673,14 +19713,6 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; } =20 - if (def->cputune.period > 0 && - (def->cputune.period < 1000 || def->cputune.period > 1000000)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("Value of cputune period must be in range " - "[1000, 1000000]")); - goto error; - } - if (virXPathLongLong("string(./cputune/quota[1])", ctxt, &def->cputune.quota) < -1) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -19688,15 +19720,6 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; } =20 - if (def->cputune.quota > 0 && - (def->cputune.quota < 1000 || - def->cputune.quota > 18446744073709551LL)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("Value of cputune quota must be in range " - "[1000, 18446744073709551]")); - goto error; - } - if (virXPathULongLong("string(./cputune/global_period[1])", ctxt, &def->cputune.global_period) < -1) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -19704,14 +19727,6 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; } =20 - if (def->cputune.global_period > 0 && - (def->cputune.global_period < 1000 || def->cputune.global_period >= 1000000)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("Value of cputune global period must be in range " - "[1000, 1000000]")); - goto error; - } - if (virXPathLongLong("string(./cputune/global_quota[1])", ctxt, &def->cputune.global_quota) < -1) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -19719,15 +19734,6 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; } =20 - if (def->cputune.global_quota > 0 && - (def->cputune.global_quota < 1000 || - def->cputune.global_quota > 18446744073709551LL)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("Value of cputune global quota must be in range " - "[1000, 18446744073709551]")); - goto error; - } - if (virXPathULongLong("string(./cputune/emulator_period[1])", ctxt, &def->cputune.emulator_period) < -1) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -19735,15 +19741,6 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; } =20 - if (def->cputune.emulator_period > 0 && - (def->cputune.emulator_period < 1000 || - def->cputune.emulator_period > 1000000)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("Value of cputune emulator_period must be in rang= e " - "[1000, 1000000]")); - goto error; - } - if (virXPathLongLong("string(./cputune/emulator_quota[1])", ctxt, &def->cputune.emulator_quota) < -1) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -19751,14 +19748,6 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; } =20 - if (def->cputune.emulator_quota > 0 && - (def->cputune.emulator_quota < 1000 || - def->cputune.emulator_quota > 18446744073709551LL)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("Value of cputune emulator_quota must be in range= " - "[1000, 18446744073709551]")); - goto error; - } =20 if (virXPathULongLong("string(./cputune/iothread_period[1])", ctxt, &def->cputune.iothread_period) < -1) { @@ -19767,15 +19756,6 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; } =20 - if (def->cputune.iothread_period > 0 && - (def->cputune.iothread_period < 1000 || - def->cputune.iothread_period > 1000000)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("Value of cputune iothread_period must be in rang= e " - "[1000, 1000000]")); - goto error; - } - if (virXPathLongLong("string(./cputune/iothread_quota[1])", ctxt, &def->cputune.iothread_quota) < -1) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -19783,15 +19763,6 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; } =20 - if (def->cputune.iothread_quota > 0 && - (def->cputune.iothread_quota < 1000 || - def->cputune.iothread_quota > 18446744073709551LL)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("Value of cputune iothread_quota must be in range= " - "[1000, 18446744073709551]")); - goto error; - } - if ((n =3D virXPathNodeSet("./cputune/vcpupin", ctxt, &nodes)) < 0) goto error; =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list