From nobody Mon Apr 29 16:50:49 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 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=1573565648; cv=none; d=zoho.com; s=zohoarc; b=k2tEzVM4DhNTyLtRL9weT314Oi5frJXGBDaXfCTzvgQZRivuRZExuqNIZFyaBxho3Zg5A9L6WwAOId6vFK1dnHEZjQ7zM1euDg3zrdwl0b5ItVcBr+cuegDUiL0C20XU6cIzTiu6qvT0NWWwCnge60VdIJTyaxyfcQF5eRM2f1w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573565648; 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=K6AQzBD7aqKb7qTX2x8hGuBd0pbJes+IAmhQ3LzVMBI=; b=lNXTRPwZOynFCADmZcdM4dlDIlGvVSNoy+QGLDgw9x1hXthW+SFNnpAtei+3gTcCtIbVhkvpRba7MDVFRLNoAXTdgyKkfB3NXTXpm74+8jV4zK6VNST1pfUEWtV4/PuSBjzmSo0SyN0NNtYzCSDNSvPjzAOh168m2dh6gbsVT+8= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1573565648677425.8825602380916; Tue, 12 Nov 2019 05:34:08 -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-172-TPHmokolMn-GKKS_sGZtpg-1; Tue, 12 Nov 2019 08:34:06 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1E5C41800D63; Tue, 12 Nov 2019 13:34:00 +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 E134B9F70; Tue, 12 Nov 2019 13:33:59 +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 97F144BB78; Tue, 12 Nov 2019 13:33:59 +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 xACDXpBO031541 for ; Tue, 12 Nov 2019 08:33:51 -0500 Received: by smtp.corp.redhat.com (Postfix) id 07EC0100EBAC; Tue, 12 Nov 2019 13:33:51 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 87DC010027B3 for ; Tue, 12 Nov 2019 13:33:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573565647; 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=K6AQzBD7aqKb7qTX2x8hGuBd0pbJes+IAmhQ3LzVMBI=; b=NfzloHNfyHPDSFR6rq3Apt215UXE3xDhE2NmVU/BwdGtNV61Fo1IXuiUzfTQMLndFowXQu lrZ0Z5DWhPfj5aWSTdQy3TiMzBVoq2eMw8ls5PnhnX1y7p35IplFvlz3D4NWI8ghsCkWzE k1p4IkgrianMBzD36hObsnbLGYv10MY= From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 12 Nov 2019 14:33:44 +0100 Message-Id: <081b93ff1dfa20da7e3faebd22dbea702ec1ee4b.1573565579.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/3] schema: capabilities: Add 'hap' feature flag 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.12 X-MC-Unique: TPHmokolMn-GKKS_sGZtpg-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The libxl driver exposes a 'hap' feature in the capability XML but our schema didn't cover it. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- docs/schemas/capability.rng | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/schemas/capability.rng b/docs/schemas/capability.rng index 8f3266b9f1..26d313d652 100644 --- a/docs/schemas/capability.rng +++ b/docs/schemas/capability.rng @@ -546,6 +546,12 @@ + + + + + + --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 16:50:49 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 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=1573565641; cv=none; d=zoho.com; s=zohoarc; b=cPqd89q88J4SHUDhRC8Q2teEGfj51EFdvKZAuFH6wdBHR0skkkCIzcZber6vJaxD2p5vDDFP+CHzUauNUcjzR6dXPM3ivsIZcRbzpmFBGlq8E7ZseFB7TsM20//fyIKP2aj3IeVHgVOXk28E9sWF7AkUor1sTY6aGjVwmqFBVEI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573565641; 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=U2aZ4bznTXo9AVo7fvrIolP57QzqBxPZB7jv/F6yxs8=; b=oppzGHt9vrqilNRfH6E6OZj3sS2ylF1GE41CciIFaQmGpS6H9uTG9jY5URtPLWGEUaM8ni7W8ejTZI7JfmsRjKNecar0Z/8fIcUuIj94dqSZfeLDAneh+VJRAMKzuuWO8r54FnWe+dcZVOBEilz/Vt4vMafMIbn8+/FwqLV9v/I= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1573565641055742.3259796809573; Tue, 12 Nov 2019 05:34:01 -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-178-494E_SRUMY-b3fSdY1F84w-1; Tue, 12 Nov 2019 08:33:58 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8DE1A18A07C1; Tue, 12 Nov 2019 13:33:53 +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 6682E5DDA8; Tue, 12 Nov 2019 13:33:53 +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 1917F1819AD0; Tue, 12 Nov 2019 13:33:53 +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 xACDXpa0031550 for ; Tue, 12 Nov 2019 08:33:52 -0500 Received: by smtp.corp.redhat.com (Postfix) id EF119100EBAC; Tue, 12 Nov 2019 13:33:51 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 54CB610027B3 for ; Tue, 12 Nov 2019 13:33:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573565639; 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=U2aZ4bznTXo9AVo7fvrIolP57QzqBxPZB7jv/F6yxs8=; b=Qi4p0eY2U4IAoH9A+fG9GqNDFq/S3lKCzpKwS0T6LwzqTaKrFewHNGFmGWLddM+i+gfzpe UQ2U0LbwtsAkecxVkcZ45x14asOIvnsXF0t4O8j2Mv0iM52uPCVMzAkGtX2HrDVMFSwsLN jmvqj3uVg4fe1f/6WyHwE7+TqVZzpmo= From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 12 Nov 2019 14:33:45 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/3] conf: Refactor storage of guest capabilities 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.14 X-MC-Unique: 494E_SRUMY-b3fSdY1F84w-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The capabilities are declared in the XML schema so passing feature names as strings from hypervisor drivers makes no sense. Additionally some of the features expose so called 'toggles' while others not. This knowledge was encoded by a bunch of 'STREQ's in the formatter. Change all of this by declaring the features as an enum and use it instead of a dynamically allocated array. Presence of 'toggles' is encoded together with the conversion strings rather than in the formatter directly. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/conf/capabilities.c | 123 +++++++++++++-------- src/conf/capabilities.h | 24 +++- tests/qemucaps2xmloutdata/caps.aarch64.xml | 2 +- tests/qemucaps2xmloutdata/caps.x86_64.xml | 4 +- 4 files changed, 95 insertions(+), 58 deletions(-) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 953464b09d..1666e1e496 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -150,15 +150,6 @@ virCapabilitiesFreeGuestDomain(virCapsGuestDomainPtr d= om) VIR_FREE(dom); } -static void -virCapabilitiesFreeGuestFeature(virCapsGuestFeaturePtr feature) -{ - if (feature =3D=3D NULL) - return; - VIR_FREE(feature->name); - VIR_FREE(feature); -} - void virCapabilitiesFreeGuest(virCapsGuestPtr guest) { @@ -176,10 +167,6 @@ virCapabilitiesFreeGuest(virCapsGuestPtr guest) virCapabilitiesFreeGuestDomain(guest->arch.domains[i]); VIR_FREE(guest->arch.domains); - for (i =3D 0; i < guest->nfeatures; i++) - virCapabilitiesFreeGuestFeature(guest->features[i]); - VIR_FREE(guest->features); - VIR_FREE(guest); } @@ -552,6 +539,24 @@ virCapabilitiesAddGuestDomain(virCapsGuestPtr guest, } +struct virCapsGuestFeatureInfo { + const char *name; + bool togglesRequired; +}; + +static const struct virCapsGuestFeatureInfo virCapsGuestFeatureInfos[VIR_C= APS_GUEST_FEATURE_TYPE_LAST] =3D { + [VIR_CAPS_GUEST_FEATURE_TYPE_PAE] =3D { "pae", false }, + [VIR_CAPS_GUEST_FEATURE_TYPE_NONPAE] =3D { "nonpae", false }, + [VIR_CAPS_GUEST_FEATURE_TYPE_IA64_BE] =3D { "ia64_be", false }, + [VIR_CAPS_GUEST_FEATURE_TYPE_ACPI] =3D { "acpi", true }, + [VIR_CAPS_GUEST_FEATURE_TYPE_APIC] =3D { "apic", true }, + [VIR_CAPS_GUEST_FEATURE_TYPE_CPUSELECTION] =3D { "cpuselection", false= }, + [VIR_CAPS_GUEST_FEATURE_TYPE_DEVICEBOOT] =3D { "deviceboot", false }, + [VIR_CAPS_GUEST_FEATURE_TYPE_DISKSNAPSHOT] =3D { "disksnapshot", true = }, + [VIR_CAPS_GUEST_FEATURE_TYPE_HAP] =3D { "hap", true }, +}; + + /** * virCapabilitiesAddGuestFeature: * @guest: guest to associate feature with @@ -567,25 +572,32 @@ virCapabilitiesAddGuestFeature(virCapsGuestPtr guest, bool defaultOn, bool toggle) { - virCapsGuestFeaturePtr feature; + virCapsGuestFeaturePtr feature =3D NULL; + bool togglesRequired =3D false; + size_t i; - if (VIR_ALLOC(feature) < 0) - goto no_memory; + for (i =3D 0; i < VIR_CAPS_GUEST_FEATURE_TYPE_LAST; i++) { + if (STRNEQ(name, virCapsGuestFeatureInfos[i].name)) + continue; - feature->name =3D g_strdup(name); - feature->defaultOn =3D defaultOn; - feature->toggle =3D toggle; + feature =3D guest->features + i; + togglesRequired =3D virCapsGuestFeatureInfos[i].togglesRequired; + } - if (VIR_RESIZE_N(guest->features, guest->nfeatures_max, - guest->nfeatures, 1) < 0) - goto no_memory; - guest->features[guest->nfeatures++] =3D feature; + if (!feature) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("invalid feature '%s'"), name); + return NULL; + } - return feature; + feature->present =3D true; - no_memory: - virCapabilitiesFreeGuestFeature(feature); - return NULL; + if (togglesRequired) { + feature->defaultOn =3D virTristateSwitchFromBool(defaultOn); + feature->toggle =3D virTristateBoolFromBool(toggle); + } + + return feature; } /** @@ -1204,6 +1216,40 @@ virCapabilitiesFormatHostXML(virCapsHostPtr host, } +static void +virCapabilitiesFormatGuestFeatures(virCapsGuestPtr guest, + virBufferPtr buf) +{ + g_auto(virBuffer) childBuf =3D VIR_BUFFER_INITIALIZER; + size_t i; + + virBufferSetChildIndent(&childBuf, buf); + + for (i =3D 0; i < VIR_CAPS_GUEST_FEATURE_TYPE_LAST; i++) { + virCapsGuestFeaturePtr feature =3D guest->features + i; + + if (!feature->present) + continue; + + virBufferAsprintf(&childBuf, "<%s", virCapsGuestFeatureInfos[i].na= me); + + if (feature->defaultOn) { + virBufferAsprintf(&childBuf, " default=3D'%s'", + virTristateSwitchTypeToString(feature->defau= ltOn)); + } + + if (feature->toggle) { + virBufferAsprintf(&childBuf, " toggle=3D'%s'", + virTristateBoolTypeToString(feature->toggle)= ); + } + + virBufferAddLit(&childBuf, "/>\n"); + } + + virXMLFormatElement(buf, "features", NULL, &childBuf); +} + + static void virCapabilitiesFormatGuestXML(virCapsGuestPtr *guests, size_t nguests, @@ -1273,29 +1319,8 @@ virCapabilitiesFormatGuestXML(virCapsGuestPtr *guest= s, virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "\n"); - if (guests[i]->nfeatures) { - virBufferAddLit(buf, "\n"); - virBufferAdjustIndent(buf, 2); + virCapabilitiesFormatGuestFeatures(guests[i], buf); - for (j =3D 0; j < guests[i]->nfeatures; j++) { - if (STREQ(guests[i]->features[j]->name, "pae") || - STREQ(guests[i]->features[j]->name, "nonpae") || - STREQ(guests[i]->features[j]->name, "ia64_be") || - STREQ(guests[i]->features[j]->name, "cpuselection") || - STREQ(guests[i]->features[j]->name, "deviceboot")) { - virBufferAsprintf(buf, "<%s/>\n", - guests[i]->features[j]->name); - } else { - virBufferAsprintf(buf, "<%s default=3D'%s' toggle=3D'%= s'/>\n", - guests[i]->features[j]->name, - guests[i]->features[j]->defaultOn ? = "on" : "off", - guests[i]->features[j]->toggle ? "ye= s" : "no"); - } - } - - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "\n"); - } virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "\n\n"); } diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h index 4abd3dcabd..dd972b1a67 100644 --- a/src/conf/capabilities.h +++ b/src/conf/capabilities.h @@ -32,10 +32,24 @@ #include +typedef enum { + VIR_CAPS_GUEST_FEATURE_TYPE_PAE =3D 0, + VIR_CAPS_GUEST_FEATURE_TYPE_NONPAE, + VIR_CAPS_GUEST_FEATURE_TYPE_IA64_BE, + VIR_CAPS_GUEST_FEATURE_TYPE_ACPI, + VIR_CAPS_GUEST_FEATURE_TYPE_APIC, + VIR_CAPS_GUEST_FEATURE_TYPE_CPUSELECTION, + VIR_CAPS_GUEST_FEATURE_TYPE_DEVICEBOOT, + VIR_CAPS_GUEST_FEATURE_TYPE_DISKSNAPSHOT, + VIR_CAPS_GUEST_FEATURE_TYPE_HAP, + + VIR_CAPS_GUEST_FEATURE_TYPE_LAST +} virCapsGuestFeatureType; + struct _virCapsGuestFeature { - char *name; - bool defaultOn; - bool toggle; + bool present; + virTristateSwitch defaultOn; + virTristateBool toggle; }; struct _virCapsGuestMachine { @@ -68,9 +82,7 @@ struct _virCapsGuestArch { struct _virCapsGuest { int ostype; virCapsGuestArch arch; - size_t nfeatures; - size_t nfeatures_max; - virCapsGuestFeaturePtr *features; + virCapsGuestFeature features[VIR_CAPS_GUEST_FEATURE_TYPE_LAST]; }; struct _virCapsHostNUMACellCPU { diff --git a/tests/qemucaps2xmloutdata/caps.aarch64.xml b/tests/qemucaps2xm= loutdata/caps.aarch64.xml index f6572c8ecd..5dca6d3102 100644 --- a/tests/qemucaps2xmloutdata/caps.aarch64.xml +++ b/tests/qemucaps2xmloutdata/caps.aarch64.xml @@ -17,10 +17,10 @@ + - diff --git a/tests/qemucaps2xmloutdata/caps.x86_64.xml b/tests/qemucaps2xml= outdata/caps.x86_64.xml index d41693a001..35359780c4 100644 --- a/tests/qemucaps2xmloutdata/caps.x86_64.xml +++ b/tests/qemucaps2xmloutdata/caps.x86_64.xml @@ -17,11 +17,11 @@ + + - - --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 16:50:49 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 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=1573565707; cv=none; d=zoho.com; s=zohoarc; b=awyu6Qe9GZdw4f0WJpHBGHWuxV0kuDoVE7YsJpdhUdnQUJhq4Xji8ay9jm0hWfdAMGfCgYHh1+BMNcwLFa6+MddElr5nMDZ9sVEfzEK+Jz9idGPICCUKZNCKeJt3SetN5dgaZkxTy8kEhQedrcwY7rt97fDnD/BTynLxqyu3ENk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573565707; 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=IlkoNGTuWMeizSISCv+00bbdBbWTZkJrOeZQDN9JHvk=; b=GPtMsiVkC5xHtGkp8fPfTSYTVnJ0EeBue9NCDuV9sDCaDZeAGWndTwxvKhMrjazUZxzlY7OFfya54jPePm8D/WPkttMX/RZKNihMMhH5TeKAwz4zFG756VAYmX++hHOkcpouLWromVFoAEQIbwacw1SITDIuTy4RzrC8zOVuK20= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1573565707765772.8567513171271; Tue, 12 Nov 2019 05:35:07 -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-440-U2LgySe9N8uHugk0AhejNw-1; Tue, 12 Nov 2019 08:34:05 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2982F1005500; Tue, 12 Nov 2019 13:34:00 +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 EE1F929159; Tue, 12 Nov 2019 13:33:59 +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 A092D1819AD4; Tue, 12 Nov 2019 13:33:59 +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 xACDXqVu031558 for ; Tue, 12 Nov 2019 08:33:52 -0500 Received: by smtp.corp.redhat.com (Postfix) id BDE38100EBCB; Tue, 12 Nov 2019 13:33:52 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 48A6B10027B3 for ; Tue, 12 Nov 2019 13:33:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573565702; 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=IlkoNGTuWMeizSISCv+00bbdBbWTZkJrOeZQDN9JHvk=; b=DdgKhAl2y9InBDJXBnX60hfyVNGDAmpTSYva2s5En7sgJrgPlYH8j6xc3tqhUp7eedg/fR 3BFz3x/gp84nXMwOtN2H+jq4/7VaTWN2vS1eO2oRddVgrmVBPn6x7kvu+Q3i1tfKKW/Nzr BpAzOOjW4Wkf+sWRyWpHY/SZuYFgJBs= From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 12 Nov 2019 14:33:46 +0100 Message-Id: <19f76f08053c49eb09a3aed042294a08dc40f3cf.1573565579.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/3] conf: capabilities: Refactor API for setting guest capability features 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.14 X-MC-Unique: U2LgySe9N8uHugk0AhejNw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Remove the need to pass around strings and switch to the enum values instead. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/conf/capabilities.c | 68 ++++++++++++++++++---------------- src/conf/capabilities.h | 11 ++++-- src/libvirt_private.syms | 1 + src/libxl/libxl_capabilities.c | 46 +++++++---------------- src/qemu/qemu_capabilities.c | 34 +++++++---------- src/test/test_driver.c | 6 +-- tests/testutilsqemu.c | 6 +-- 7 files changed, 76 insertions(+), 96 deletions(-) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 1666e1e496..6e5dde7394 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -557,49 +557,55 @@ static const struct virCapsGuestFeatureInfo virCapsGu= estFeatureInfos[VIR_CAPS_GU }; +static void +virCapabilitiesAddGuestFeatureInternal(virCapsGuestPtr guest, + virCapsGuestFeatureType feature, + bool defaultOn, + bool toggle) +{ + guest->features[feature].present =3D true; + + if (virCapsGuestFeatureInfos[feature].togglesRequired) { + guest->features[feature].defaultOn =3D virTristateSwitchFromBool(d= efaultOn); + guest->features[feature].toggle =3D virTristateBoolFromBool(toggle= ); + } +} + + /** * virCapabilitiesAddGuestFeature: * @guest: guest to associate feature with - * @name: name of feature ('pae', 'acpi', 'apic') - * @defaultOn: true if it defaults to on - * @toggle: true if its state can be toggled + * @feature: feature to add * * Registers a feature for a guest domain. */ -virCapsGuestFeaturePtr +void virCapabilitiesAddGuestFeature(virCapsGuestPtr guest, - const char *name, - bool defaultOn, - bool toggle) + virCapsGuestFeatureType feature) { - virCapsGuestFeaturePtr feature =3D NULL; - bool togglesRequired =3D false; - size_t i; - - for (i =3D 0; i < VIR_CAPS_GUEST_FEATURE_TYPE_LAST; i++) { - if (STRNEQ(name, virCapsGuestFeatureInfos[i].name)) - continue; - - feature =3D guest->features + i; - togglesRequired =3D virCapsGuestFeatureInfos[i].togglesRequired; - } - - if (!feature) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("invalid feature '%s'"), name); - return NULL; - } - - feature->present =3D true; + virCapabilitiesAddGuestFeatureInternal(guest, feature, false, false); +} - if (togglesRequired) { - feature->defaultOn =3D virTristateSwitchFromBool(defaultOn); - feature->toggle =3D virTristateBoolFromBool(toggle); - } - return feature; +/** + * virCapabilitiesAddGuestFeatureToggle: + * @guest: guest to associate feature with + * @feature: feature to add + * @defaultOn: true if it defaults to on + * @toggle: true if its state can be toggled + * + * Registers a feature with toggles for a guest domain. + */ +void +virCapabilitiesAddGuestFeatureToggle(virCapsGuestPtr guest, + virCapsGuestFeatureType feature, + bool defaultOn, + bool toggle) +{ + virCapabilitiesAddGuestFeatureInternal(guest, feature, defaultOn, togg= le); } + /** * virCapabilitiesHostSecModelAddBaseLabel * @secmodel: Security model to add a base label for diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h index dd972b1a67..2d33adddeb 100644 --- a/src/conf/capabilities.h +++ b/src/conf/capabilities.h @@ -283,11 +283,14 @@ virCapabilitiesAddGuestDomain(virCapsGuestPtr guest, int nmachines, virCapsGuestMachinePtr *machines); -virCapsGuestFeaturePtr +void virCapabilitiesAddGuestFeature(virCapsGuestPtr guest, - const char *name, - bool defaultOn, - bool toggle); + virCapsGuestFeatureType feature); +void +virCapabilitiesAddGuestFeatureToggle(virCapsGuestPtr guest, + virCapsGuestFeatureType feature, + bool defaultOn, + bool toggle); int virCapabilitiesAddStoragePool(virCapsPtr caps, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 94509d6f43..f764837688 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -46,6 +46,7 @@ virAccessPermStorageVolTypeToString; virCapabilitiesAddGuest; virCapabilitiesAddGuestDomain; virCapabilitiesAddGuestFeature; +virCapabilitiesAddGuestFeatureToggle; virCapabilitiesAddHostFeature; virCapabilitiesAddHostMigrateTransport; virCapabilitiesAddHostNUMACell; diff --git a/src/libxl/libxl_capabilities.c b/src/libxl/libxl_capabilities.c index 3b88121dca..ce1c63d518 100644 --- a/src/libxl/libxl_capabilities.c +++ b/src/libxl/libxl_capabilities.c @@ -547,46 +547,26 @@ libxlCapsInitGuests(libxl_ctx *ctx, virCapsPtr caps) NULL) =3D=3D NULL) return -1; - if (guest_archs[i].pae && - virCapabilitiesAddGuestFeature(guest, - "pae", - 1, - 0) =3D=3D NULL) - return -1; + if (guest_archs[i].pae) + virCapabilitiesAddGuestFeature(guest, VIR_CAPS_GUEST_FEATURE_T= YPE_PAE); - if (guest_archs[i].nonpae && - virCapabilitiesAddGuestFeature(guest, - "nonpae", - 1, - 0) =3D=3D NULL) - return -1; + if (guest_archs[i].nonpae) + virCapabilitiesAddGuestFeature(guest, VIR_CAPS_GUEST_FEATURE_T= YPE_NONPAE); - if (guest_archs[i].ia64_be && - virCapabilitiesAddGuestFeature(guest, - "ia64_be", - 1, - 0) =3D=3D NULL) - return -1; + if (guest_archs[i].ia64_be) + virCapabilitiesAddGuestFeature(guest, VIR_CAPS_GUEST_FEATURE_T= YPE_IA64_BE); if (guest_archs[i].hvm) { - if (virCapabilitiesAddGuestFeature(guest, - "acpi", - 1, - 1) =3D=3D NULL) - return -1; - - if (virCapabilitiesAddGuestFeature(guest, "apic", - 1, - 0) =3D=3D NULL) - return -1; + virCapabilitiesAddGuestFeatureToggle(guest, VIR_CAPS_GUEST_FEA= TURE_TYPE_ACPI, + true, true); + + virCapabilitiesAddGuestFeatureToggle(guest, VIR_CAPS_GUEST_FEA= TURE_TYPE_APIC, + true, false); } if (guest_archs[i].hvm || guest_archs[i].pvh) { - if (virCapabilitiesAddGuestFeature(guest, - "hap", - 1, - 1) =3D=3D NULL) - return -1; + virCapabilitiesAddGuestFeatureToggle(guest, VIR_CAPS_GUEST_FEA= TURE_TYPE_HAP, + true, true); } } diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index fc6473651c..ab14e0fdfe 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -850,14 +850,10 @@ virQEMUCapsInitGuestFromBinary(virCapsPtr caps, /* CPU selection is always available, because all QEMU versions * we support can use at least '-cpu host' */ - if (!virCapabilitiesAddGuestFeature(guest, "cpuselection", true, false= )) - goto cleanup; - - if (!virCapabilitiesAddGuestFeature(guest, "deviceboot", true, false)) - goto cleanup; - - if (!virCapabilitiesAddGuestFeature(guest, "disksnapshot", true, false= )) - goto cleanup; + virCapabilitiesAddGuestFeature(guest, VIR_CAPS_GUEST_FEATURE_TYPE_CPUS= ELECTION); + virCapabilitiesAddGuestFeature(guest, VIR_CAPS_GUEST_FEATURE_TYPE_DEVI= CEBOOT); + virCapabilitiesAddGuestFeatureToggle(guest, VIR_CAPS_GUEST_FEATURE_TYP= E_DISKSNAPSHOT, + true, false); if (virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_QEMU, @@ -878,20 +874,18 @@ virQEMUCapsInitGuestFromBinary(virCapsPtr caps, } } - if ((ARCH_IS_X86(guestarch) || guestarch =3D=3D VIR_ARCH_AARCH64) && - virCapabilitiesAddGuestFeature(guest, "acpi", true, true) =3D=3D N= ULL) { - goto cleanup; - } + if ((ARCH_IS_X86(guestarch) || guestarch =3D=3D VIR_ARCH_AARCH64)) + virCapabilitiesAddGuestFeatureToggle(guest, VIR_CAPS_GUEST_FEATURE= _TYPE_ACPI, + true, true); - if (ARCH_IS_X86(guestarch) && - virCapabilitiesAddGuestFeature(guest, "apic", true, false) =3D=3D = NULL) { - goto cleanup; - } + if (ARCH_IS_X86(guestarch)) + virCapabilitiesAddGuestFeatureToggle(guest, VIR_CAPS_GUEST_FEATURE= _TYPE_APIC, + true, false); - if ((guestarch =3D=3D VIR_ARCH_I686) && - (virCapabilitiesAddGuestFeature(guest, "pae", true, false) =3D=3D = NULL || - virCapabilitiesAddGuestFeature(guest, "nonpae", true, false) =3D= =3D NULL)) - goto cleanup; + if (guestarch =3D=3D VIR_ARCH_I686) { + virCapabilitiesAddGuestFeature(guest, VIR_CAPS_GUEST_FEATURE_TYPE_= PAE); + virCapabilitiesAddGuestFeature(guest, VIR_CAPS_GUEST_FEATURE_TYPE_= NONPAE); + } ret =3D 0; diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 6c1c56d446..d1a83ffa3c 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -350,10 +350,8 @@ testBuildCapabilities(virConnectPtr conn) NULL) =3D=3D NULL) goto error; - if (virCapabilitiesAddGuestFeature(guest, "pae", true, true) =3D= =3D NULL) - goto error; - if (virCapabilitiesAddGuestFeature(guest, "nonpae", true, true) = =3D=3D NULL) - goto error; + virCapabilitiesAddGuestFeature(guest, VIR_CAPS_GUEST_FEATURE_TYPE_= PAE); + virCapabilitiesAddGuestFeature(guest, VIR_CAPS_GUEST_FEATURE_TYPE_= NONPAE); } caps->host.nsecModels =3D 1; diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c index 34a6bd2653..ca35e4ee75 100644 --- a/tests/testutilsqemu.c +++ b/tests/testutilsqemu.c @@ -110,8 +110,7 @@ testQemuAddI686Guest(virCapsPtr caps) machines))) goto error; - if (!virCapabilitiesAddGuestFeature(guest, "cpuselection", true, false= )) - goto error; + virCapabilitiesAddGuestFeature(guest, VIR_CAPS_GUEST_FEATURE_TYPE_CPUS= ELECTION); machines =3D NULL; @@ -161,8 +160,7 @@ testQemuAddX86_64Guest(virCapsPtr caps) machines))) goto error; - if (!virCapabilitiesAddGuestFeature(guest, "cpuselection", true, false= )) - goto error; + virCapabilitiesAddGuestFeature(guest, VIR_CAPS_GUEST_FEATURE_TYPE_CPUS= ELECTION); machines =3D NULL; --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list