From nobody Mon Feb 9 00:30:46 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=1681908003; cv=none; d=zohomail.com; s=zohoarc; b=k9+0VUbzrir+6kAgLkjVTBGFGgQTAOxJuBYDrWTsuf4kqdSZ6bm9yNrXKWwxGLllSUuWhsciP893k9O5UdR5hd81mGCh1yqbW8he+auwT+lQISODXg66SqEXa7kGc9pY/BBDaxjxjuAx5FQbRH5GnYeiAQVJRKJoWrPDJO3JLkc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681908003; 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=G6ZMZb/fAeCIhCKIH0Du8hmiyiDz3jK0xZ2piQ/7Wf0=; b=ZX1bQVNr4nYYltjptC55/Q9feZAUJULpMzYnf9SFoKfpYoCQREbt8OA3tla+VS5WTfcab+EJWwgnjhp+QNG5NePA5FmvqOhdyqxWRaaj6GMMkzjoK0ya02gB/qYFvhlt6cFZPVA2+wylohXK1yItf/OwTW8o8UFgUHYhYz+8sLQ= 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 16819080033801015.3004639011081; Wed, 19 Apr 2023 05:40:03 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-325-3PZ6qqWROZCxcgV9UFh0Cg-1; Wed, 19 Apr 2023 08:39:26 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2243B823D46; Wed, 19 Apr 2023 12:39:24 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0F59840C2064; Wed, 19 Apr 2023 12:39:24 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 987D919465B9; Wed, 19 Apr 2023 12:39:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 5CD4019465A0 for ; Wed, 19 Apr 2023 12:05:01 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 43475492B06; Wed, 19 Apr 2023 12:05:01 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id BBDC0492B04 for ; Wed, 19 Apr 2023 12:05:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681908002; 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=G6ZMZb/fAeCIhCKIH0Du8hmiyiDz3jK0xZ2piQ/7Wf0=; b=XaVodI71/sAsxqYocF+qjcMg3KmHLWhECs5aJytKsmZXunj/XvNXgSxQ9P0BLushAxT5TV IL+Wtb1Ea5/eG6brdZp9je9rqjXy/fC+anEH9Hp3XmlsQSVr0+pfq5NvDUyox+dT1uROzn kIueFajzgXd+y1rSkfZt7m/dPCA6QA4= X-MC-Unique: 3PZ6qqWROZCxcgV9UFh0Cg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH v3 19/25] virTypedParamsValidate: Allow typed params to be both _UINT and _ULLONG Date: Wed, 19 Apr 2023 14:04:36 +0200 Message-Id: <9bd6878d910680d67f16d259f279f401df29bee4.1681905482.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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: 1681908005183100001 Content-Type: text/plain; charset="utf-8" For certain typed parameters we want to extend the supproted range by switching to VIR_TYPED_PARAM_ULLONG. To preserve compatibility we've added APIs such as 'virTypedParamsGetUnsigned' and 'virTypedParamListAddUnsigned' which automatically select the bigger type if necessary. This patch adds a new internal macro VIR_TYPED_PARAM_UNSIGNED which is used with virTypedParamsValidate to allow both types and adjusts the code to handle it properly. Signed-off-by: Peter Krempa --- src/util/virtypedparam.c | 19 ++++++++++++++----- src/util/virtypedparam.h | 9 +++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/util/virtypedparam.c b/src/util/virtypedparam.c index c71d4415a1..c3bc1237c1 100644 --- a/src/util/virtypedparam.c +++ b/src/util/virtypedparam.c @@ -63,7 +63,6 @@ virTypedParamsValidate(virTypedParameterPtr params, int n= params, ...) size_t j; const char *name; const char *last_name =3D NULL; - int type; size_t nkeys =3D 0; size_t nkeysalloc =3D 0; g_autofree virTypedParameterPtr sorted =3D NULL; @@ -79,7 +78,7 @@ virTypedParamsValidate(virTypedParameterPtr params, int n= params, ...) name =3D va_arg(ap, const char *); while (name) { - type =3D va_arg(ap, int); + int type =3D va_arg(ap, int); VIR_RESIZE_N(keys, nkeysalloc, nkeys, 1); if (virStrcpyStatic(keys[nkeys].field, name) < 0) { @@ -105,6 +104,9 @@ virTypedParamsValidate(virTypedParameterPtr params, int= nparams, ...) if (STRNEQ(sorted[i].field, keys[j].field)) { j++; } else { + const char *expecttype =3D virTypedParameterTypeToString(keys[= j].type); + int type =3D sorted[i].type; + if (STREQ_NULLABLE(last_name, sorted[i].field) && !(keys[j].value.i & VIR_TYPED_PARAM_MULTIPLE)) { virReportError(VIR_ERR_INVALID_ARG, @@ -112,7 +114,15 @@ virTypedParamsValidate(virTypedParameterPtr params, in= t nparams, ...) sorted[i].field); return -1; } - if (sorted[i].type !=3D keys[j].type) { + + if (keys[j].type =3D=3D VIR_TYPED_PARAM_UNSIGNED && + (type =3D=3D VIR_TYPED_PARAM_UINT || + type =3D=3D VIR_TYPED_PARAM_ULLONG)) { + type =3D VIR_TYPED_PARAM_UNSIGNED; + expecttype =3D "uint, ullong"; + } + + if (type !=3D keys[j].type) { const char *badtype; badtype =3D virTypedParameterTypeToString(sorted[i].type); @@ -120,8 +130,7 @@ virTypedParamsValidate(virTypedParameterPtr params, int= nparams, ...) badtype =3D virTypedParameterTypeToString(0); virReportError(VIR_ERR_INVALID_ARG, _("invalid type '%1$s' for parameter '%2$s'= , expected '%3$s'"), - badtype, sorted[i].field, - virTypedParameterTypeToString(keys[j].type)= ); + badtype, sorted[i].field, expecttype); return -1; } last_name =3D sorted[i].field; diff --git a/src/util/virtypedparam.h b/src/util/virtypedparam.h index c2f58e994c..7454ef3ce0 100644 --- a/src/util/virtypedparam.h +++ b/src/util/virtypedparam.h @@ -24,6 +24,15 @@ #include "internal.h" #include "virenum.h" + +/** + * VIR_TYPED_PARAM_UNSIGNED: + * + * Special typed parameter type only used with virTypedParamsValidate to + * indicate that both VIR_TYPED_PARAM_UINT and VIR_TYPED_PARAM_ULLONG types + * are acceptable for given value. + */ +#define VIR_TYPED_PARAM_UNSIGNED (VIR_TYPED_PARAM_LAST + 1) /** * VIR_TYPED_PARAM_MULTIPLE: * --=20 2.39.2