From patchwork Thu Jul 26 17:49:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 142988 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp741495ljj; Thu, 26 Jul 2018 10:50:12 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcWZ0/+t9McFzcCs/ddPv5ORfavGERjsobd5CYVSubZUyZQ55z1e9AU9o/p5DSKhYzx1M8V X-Received: by 2002:a37:ae03:: with SMTP id x3-v6mr2768116qke.170.1532627412481; Thu, 26 Jul 2018 10:50:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532627412; cv=none; d=google.com; s=arc-20160816; b=F6ztZRyIaYuzOmvRq/PCHe1jb0Q4Saja4jgi1XSYcwbbNhuoLuTXcFhN9BU5O8SL6L n24NkxHbsLzIeCaLqAsaNWDz/0KYS9vPdCqihNAJ7PwcOwIuFYWHXIzz1C2yXxzS2PWm F9LEFPCh+OVPyXLR/EFMb5agzOBML98kbW6dlvqZ5iH2mJiImmDUgWJFc7PDAXyPyfj2 bBJCu912ezFzHRqjAnAsKdCmTH1n0wwWdD0rsPBSHafc3T/kkismJ7/q1tOSmqWbMTuR vJ1I7SZeeibJ0YtOREFkW1Q5osZW3lPKznBjTLgAykch3VgfAADzpvBRCSncU0gHxRiX j5Dw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:references :in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=72N994ul0WyNmX7pPUl81B3+1L3OtqQrKQfdHf4muHo=; b=LVnikqp/AnSCt8CYciHq43C9Wf+lfcR0+e34CZKeTWLVNm0pt53gypYacR1Mu3/EVc TE+Ugcvoc6/JsjuFzc8Aan4fvlk6Kh9y86E4sCPv4UNexi5M9j6yvBbZexBLkQoLwtzV r8sUAeT7huElp81LjW5hlhc6DDJ/5HJSfhsibJ2tmoHsLMGPF3phASbbqysJBT5tPESd 1TXl/Zkbyby52CLrpvGtELbFbYEalXkssROYDQSo6x/cjxDrBUimCZrsL5/geR5KKuyr JlaFyNxCNhoxEP9vm4MJoSXjPvNsvoWTGhvahxIRaFEUoWB2qvPI9DzYGQr0OlAi3xGX d3iQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id c40-v6si41135qtb.208.2018.07.26.10.50.12 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Jul 2018 10:50:12 -0700 (PDT) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com 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 mx1.redhat.com (Postfix) with ESMTPS id 76FDF30832EE; Thu, 26 Jul 2018 17:50:10 +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 3393F6047F; Thu, 26 Jul 2018 17:50:10 +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 93CCF18037ED; Thu, 26 Jul 2018 17:50:09 +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 w6QHo71d029332 for ; Thu, 26 Jul 2018 13:50:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1CEE31C5B0; Thu, 26 Jul 2018 17:50:07 +0000 (UTC) Delivered-To: libvirt-list@redhat.com Received: from worklaptop.bos.redhat.com (dhcp-17-157.bos.redhat.com [10.18.17.157]) by smtp.corp.redhat.com (Postfix) with ESMTP id 03D851C5A2; Thu, 26 Jul 2018 17:50:06 +0000 (UTC) From: Cole Robinson To: libvirt-list@redhat.com Date: Thu, 26 Jul 2018 13:49:54 -0400 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH RFC 1/2] util: Add VIR_ENUM_IMPL_LABEL 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: , MIME-Version: 1.0 Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Thu, 26 Jul 2018 17:50:11 +0000 (UTC) This allows passing in a string label describing the enum, which can be used to autogenerate error messages Signed-off-by: Cole Robinson --- src/util/virutil.c | 20 ++++++++++++++++---- src/util/virutil.h | 15 ++++++++++----- 2 files changed, 26 insertions(+), 9 deletions(-) -- 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list diff --git a/src/util/virutil.c b/src/util/virutil.c index a908422feb..6d23a26a74 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -444,16 +444,22 @@ virParseVersionString(const char *str, unsigned long *version, int virEnumFromString(const char *const*types, unsigned int ntypes, - const char *type) + const char *type, + const char * const label) { size_t i; if (!type) - return -1; + goto error; for (i = 0; i < ntypes; i++) if (STREQ(types[i], type)) return i; + error: + if (label) { + virReportError(VIR_ERR_INVALID_ARG, + _("Unknown '%s' value '%s'"), label, type); + } return -1; } @@ -540,10 +546,16 @@ virFormatIntPretty(unsigned long long val, const char *virEnumToString(const char *const*types, unsigned int ntypes, - int type) + int type, + const char * const label) { - if (type < 0 || type >= ntypes) + if (type < 0 || type >= ntypes) { + if (label) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unknown '%s' internal value %d"), label, type); + } return NULL; + } return types[type]; } diff --git a/src/util/virutil.h b/src/util/virutil.h index 1ba9635bd9..345c9e053d 100644 --- a/src/util/virutil.h +++ b/src/util/virutil.h @@ -76,26 +76,31 @@ char *virIndexToDiskName(int idx, const char *prefix); int virEnumFromString(const char *const*types, unsigned int ntypes, - const char *type); + const char *type, + const char *errmsg); const char *virEnumToString(const char *const*types, unsigned int ntypes, - int type); + int type, + const char *errmsg); -# define VIR_ENUM_IMPL(name, lastVal, ...) \ +# define VIR_ENUM_IMPL_LABEL(name, label, lastVal, ...) \ static const char *const name ## TypeList[] = { __VA_ARGS__ }; \ verify(ARRAY_CARDINALITY(name ## TypeList) == lastVal); \ const char *name ## TypeToString(int type) { \ return virEnumToString(name ## TypeList, \ ARRAY_CARDINALITY(name ## TypeList), \ - type); \ + type, label); \ } \ int name ## TypeFromString(const char *type) { \ return virEnumFromString(name ## TypeList, \ ARRAY_CARDINALITY(name ## TypeList), \ - type); \ + type, label); \ } +# define VIR_ENUM_IMPL(name, lastVal, ...) \ + VIR_ENUM_IMPL_LABEL(name, NULL, lastVal, __VA_ARGS__) + # define VIR_ENUM_DECL(name) \ const char *name ## TypeToString(int type); \ int name ## TypeFromString(const char*type); From patchwork Thu Jul 26 17:49:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 142990 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp741604ljj; Thu, 26 Jul 2018 10:50:18 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcTrrHqcWpWjRwSJHmieeTUUPHfqAKD41GlONj+WVsD++dbC/r1BrlWzQ3vxcDO+EsWIJmY X-Received: by 2002:aed:2a33:: with SMTP id c48-v6mr2950856qtd.147.1532627417992; Thu, 26 Jul 2018 10:50:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532627417; cv=none; d=google.com; s=arc-20160816; b=DJ7SKZDefk4nla5XBQJBglLy1/BqBRaSUWW2Gk8a/qZTVf8spO4eMZ0lr3Fux9GtVh 0bGvY+wup7RDWA1l9tTUqyz0YV6VQ6rlasc+lqJVOA0OUC5AN9rsmU4RyfIfsm0GUL+k yePtkX8sbOVlfu2/zMmSr0gkwUjLYrKBBEw6VcY3RFREps6SkDpY1pKfZRwjxddfmEuB M3WscOn4XSCvYfWyHdQhZcKcOmQP+iqt8DvacuYLby/Bie3/FdrrtScgYBJ7Przl+Lhj xdn5PuIkym5M+KPbyCu49BmoRmZZMG+WAhMLSoKqNilddGKVg2kGutIY18Eho3d+/orU mIYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:references :in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=J9jjBjIvJbmcWirGjsag1HQh7wVVEWMgLwhEy7nu0bo=; b=fy2EeBz2j7Iynmhh410cDc/WCGU+FamE+7NOhrffeRYuBaEIgpvTwY0eZCAKN7aLEO aDjt/C5ALKc+4oJ8PKU+vbRabWnfQf6KvTTWXbRJ8xacGy8tkOp7UYHd52VZmkLHWcZE rPUTjqdIFa0QFVaLHQA3jLDW5uG6MfeHtQwWVr6qUFK/kZDJhFNK03jBV/N8XMRpdEck PPmkai3WNIRl2g0RRIJuO6KIvmHLjrNVYMU6gBjGv0iS/jJPdR5DJrYgx+i64Av90Qva l9xF3ZTgvoWyV7OfaC/W6nbycSKY2MnijC2YyMbu//CmSZe2xkE4nXsCBRnMMmI4kuxD U/4w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id m82-v6si1804970qki.213.2018.07.26.10.50.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Jul 2018 10:50:17 -0700 (PDT) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com 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 mx1.redhat.com (Postfix) with ESMTPS id B25C2308214A; Thu, 26 Jul 2018 17:50:15 +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 6C40F600C5; Thu, 26 Jul 2018 17:50:15 +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 F0B0D18037F2; Thu, 26 Jul 2018 17:50:14 +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 w6QHo8Eq029341 for ; Thu, 26 Jul 2018 13:50:09 -0400 Received: by smtp.corp.redhat.com (Postfix) id D9ECC1C5B0; Thu, 26 Jul 2018 17:50:08 +0000 (UTC) Delivered-To: libvirt-list@redhat.com Received: from worklaptop.bos.redhat.com (dhcp-17-157.bos.redhat.com [10.18.17.157]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2653B1C5A2; Thu, 26 Jul 2018 17:50:07 +0000 (UTC) From: Cole Robinson To: libvirt-list@redhat.com Date: Thu, 26 Jul 2018 13:49:55 -0400 Message-Id: <8e2e9469e7aa25d03c95c92dec137fafc0b17f51.1532625483.git.crobinso@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH RFC 2/2] conf: Convert virDomainVirtType to VIR_ENUM_IMPL_LABEL 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: , MIME-Version: 1.0 Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Thu, 26 Jul 2018 17:50:17 +0000 (UTC) Signed-off-by: Cole Robinson --- src/conf/domain_conf.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) -- 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index f94a90fbcc..eb40b7f349 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -103,7 +103,7 @@ VIR_ENUM_IMPL(virDomainTaint, VIR_DOMAIN_TAINT_LAST, "custom-dtb", "custom-ga-command"); -VIR_ENUM_IMPL(virDomainVirt, VIR_DOMAIN_VIRT_LAST, +VIR_ENUM_IMPL_LABEL(virDomainVirt, "domain type", VIR_DOMAIN_VIRT_LAST, "none", "qemu", "kqemu", @@ -19141,10 +19141,7 @@ virDomainDefParseCaps(virDomainDefPtr def, goto cleanup; } if ((def->virtType = virDomainVirtTypeFromString(virttype)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("invalid domain type %s"), virttype); goto cleanup; - } if (!ostype) { if (def->os.bootloader) { @@ -27380,11 +27377,8 @@ virDomainDefFormatInternal(virDomainDefPtr def, VIR_DOMAIN_DEF_FORMAT_CLOCK_ADJUST, -1); - if (!(type = virDomainVirtTypeToString(def->virtType))) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected domain type %d"), def->virtType); + if (!(type = virDomainVirtTypeToString(def->virtType))) goto error; - } if (def->id == -1) flags |= VIR_DOMAIN_DEF_FORMAT_INACTIVE;