From nobody Sun Feb 8 09:37:32 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=1665163338; cv=none; d=zohomail.com; s=zohoarc; b=CrJTsYLQF7YPR0lEXA7pG2pMX0ts1/s3tTiJZVcGVkBfnkGSuyMmZgkRPFAuUB+YRRBRzWZ4wHt2aqV8Jo5mEpsa7y/ex3LWAMm75j+6fDSDuLXPmbepyUfow2o4un0f8ddGFMShfz5a/qKFk18X0xkZzzxR+n8iI1sNcXeE7rE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665163338; 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=xOJv5/ebFotvPwKqcTNjhJ75A+MPycbkCPMAZJnbhs4=; b=ccX0pqOp9PEexLr0LxrRQ6eo4Ofv3R9wB7ygVwS0WJ7SPD7zTCggMOhGFNkZMnV/7EG1fwm44KI1ItMIarHp5+sGJwg/JuYoDMtj9+6zfzr5oOE7JqxuRKe6cgVzWE8ZvNTVD8+WKwCLaozZRa5U7ZgSnAJLEJ1Ru98uZ/sGMCs= 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 1665163338849456.2715700849342; Fri, 7 Oct 2022 10:22:18 -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-436-ucwlvAk8O2Gz6oIorAwG_A-1; Fri, 07 Oct 2022 13:22:11 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2ED06805AC8; Fri, 7 Oct 2022 17:22:02 +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 19FA540C955C; Fri, 7 Oct 2022 17:22:02 +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 BBE881947B93; Fri, 7 Oct 2022 17:21:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 5FD2F1946A69 for ; Fri, 7 Oct 2022 17:21:57 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 52C29112C067; Fri, 7 Oct 2022 17:21:57 +0000 (UTC) Received: from rein.int.mamuti.net (unknown [10.40.194.60]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1295F112C069 for ; Fri, 7 Oct 2022 17:21:57 +0000 (UTC) Received: by rein.int.mamuti.net (Postfix, from userid 500) id 3899918010B; Fri, 7 Oct 2022 19:21:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665163338; 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=xOJv5/ebFotvPwKqcTNjhJ75A+MPycbkCPMAZJnbhs4=; b=Hvnug0tI3qeXcdA+gh5ADyKdOziPx5dn+Sc5/z4P394ai7G0wD0nE5qxcmjKH8sTd4vU73 WvCvEKtxzS7BBFDJQEEiMUJ6aW7NJDSO1JkhaaNF5izx12EVls9euaTLi+bwetaAc+1Eyr yjI8uMiQ0qTyvFpMdZ2AhoBb5SfK50g= X-MC-Unique: ucwlvAk8O2Gz6oIorAwG_A-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jiri Denemark To: libvir-list@redhat.com Subject: [libvirt PATCH v2 12/14] virsh: Add --model option for hypervisor-cpu-baseline Date: Fri, 7 Oct 2022 19:21:49 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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.2 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: 1665163340822100019 Content-Type: text/plain; charset="utf-8" This option can be used as a shortcut for creating a single XML with just a CPU model name and no features: $ virsh hypervisor-cpu-baseline --model Skylake-Server Skylake-Server Signed-off-by: Jiri Denemark Reviewed-by: J=C3=A1n Tomko --- Notes: Version 2: - new patch docs/manpages/virsh.rst | 14 +++++++++++--- tools/virsh-host.c | 23 +++++++++++++++++++---- tools/virsh.h | 7 +++++-- tools/vsh.h | 27 +++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 9 deletions(-) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index 5d11c48803..61fcb2e9ca 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -962,13 +962,18 @@ hypervisor-cpu-baseline =20 :: =20 - hypervisor-cpu-baseline FILE [virttype] [emulator] [arch] [machine] [--= features] [--migratable] + hypervisor-cpu-baseline [FILE] [virttype] [emulator] [arch] [machine] + [--features] [--migratable] [model] =20 Compute a baseline CPU which will be compatible with all CPUs defined in a= n XML *file* and with the CPU the hypervisor is able to provide on the host. (Th= is is different from ``cpu-baseline`` which does not consider any hypervisor abilities when computing the baseline CPU.) =20 +As an alternative for *FILE* in case the XML would only contain a CPU model +with no additional features the CPU model name itself can be passed as *mo= del*. +Exactly one of *FILE* and *model* must be used. + The XML *FILE* may contain either host or guest CPU definitions describing= the host CPU model. The host CPU definition is the element and its conte= nts as printed by ``capabilities`` command. The guest CPU definition may be cr= eated @@ -981,10 +986,13 @@ fail or provide unexpected results. =20 When *FILE* contains only a single CPU definition, the command will print = the same CPU with restrictions imposed by the capabilities of the hypervisor. -Specifically, running th ``virsh hypervisor-cpu-baseline`` command with no +Specifically, running the ``virsh hypervisor-cpu-baseline`` command with no additional options on the result of ``virsh domcapabilities`` will transfo= rm the host CPU model from domain capabilities XML to a form directly usable in d= omain -XML. +XML. Running the command with *model* (or *FILE* containing just a single = CPU +definition with model and no feature elements) which is marked as unusable= in +``virsh domcapabilities`` will provide a list of features that block this = CPU +model from being usable. =20 The *virttype* option specifies the virtualization type (usable in the 'ty= pe' attribute of the top level element from the domain XML). *emulato= r* diff --git a/tools/virsh-host.c b/tools/virsh-host.c index ead966b500..16c3585a1a 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -1689,7 +1689,8 @@ static const vshCmdInfo info_hypervisor_cpu_baseline[= ] =3D { }; =20 static const vshCmdOptDef opts_hypervisor_cpu_baseline[] =3D { - VIRSH_COMMON_OPT_FILE(N_("file containing XML CPU descriptions")), + VIRSH_COMMON_OPT_FILE_FULL(N_("file containing XML CPU descriptions"), + false), {.name =3D "virttype", .type =3D VSH_OT_STRING, .completer =3D virshDomainVirtTypeCompleter, @@ -1716,6 +1717,11 @@ static const vshCmdOptDef opts_hypervisor_cpu_baseli= ne[] =3D { .type =3D VSH_OT_BOOL, .help =3D N_("Do not include features that block migration") }, + {.name =3D "model", + .type =3D VSH_OT_STRING, + .help =3D N_("Shortcut for calling the command with a single CPU mode= l " + "and no additional features") + }, {.name =3D NULL} }; =20 @@ -1728,6 +1734,7 @@ cmdHypervisorCPUBaseline(vshControl *ctl, const char *emulator =3D NULL; const char *arch =3D NULL; const char *machine =3D NULL; + const char *model =3D NULL; bool ret =3D false; g_autofree char *result =3D NULL; g_auto(GStrv) list =3D NULL; @@ -1743,11 +1750,19 @@ cmdHypervisorCPUBaseline(vshControl *ctl, vshCommandOptStringReq(ctl, cmd, "virttype", &virttype) < 0 || vshCommandOptStringReq(ctl, cmd, "emulator", &emulator) < 0 || vshCommandOptStringReq(ctl, cmd, "arch", &arch) < 0 || - vshCommandOptStringReq(ctl, cmd, "machine", &machine) < 0) + vshCommandOptStringReq(ctl, cmd, "machine", &machine) < 0 || + vshCommandOptStringReq(ctl, cmd, "model", &model) < 0) return false; =20 - if (!(list =3D vshExtractCPUDefXMLs(ctl, from))) - return false; + VSH_ALTERNATIVE_OPTIONS_EXPR("file", from, "model", model); + + if (from) { + if (!(list =3D vshExtractCPUDefXMLs(ctl, from))) + return false; + } else { + list =3D g_new0(char *, 2); + list[0] =3D g_strdup_printf("%s", model); + } =20 result =3D virConnectBaselineHypervisorCPU(priv->conn, emulator, arch, machine, virttype, diff --git a/tools/virsh.h b/tools/virsh.h index f9841c8da2..6acefa7f9d 100644 --- a/tools/virsh.h +++ b/tools/virsh.h @@ -96,9 +96,12 @@ =20 /* Use this only for files which are existing and used locally by virsh */ #define VIRSH_COMMON_OPT_FILE(_helpstr) \ + VIRSH_COMMON_OPT_FILE_FULL(_helpstr, true) + +#define VIRSH_COMMON_OPT_FILE_FULL(_helpstr, required) \ {.name =3D "file", \ - .type =3D VSH_OT_DATA, \ - .flags =3D VSH_OFLAG_REQ, \ + .type =3D required ? VSH_OT_DATA : VSH_OT_STRING, \ + .flags =3D required ? VSH_OFLAG_REQ : VSH_OFLAG_NONE, \ .completer =3D virshCompletePathLocalExisting, \ .help =3D _helpstr \ } diff --git a/tools/vsh.h b/tools/vsh.h index a43660b63d..657a1e7a93 100644 --- a/tools/vsh.h +++ b/tools/vsh.h @@ -520,6 +520,33 @@ void vshReadlineHistoryAdd(const char *cmd); #define VSH_EXCLUSIVE_OPTIONS_VAR(VARNAME1, VARNAME2) \ VSH_EXCLUSIVE_OPTIONS_EXPR(#VARNAME1, VARNAME1, #VARNAME2, VARNAME2) =20 +/* Macros to help dealing with alternative mutually exclusive options. */ + +/* VSH_ALTERNATIVE_OPTIONS_EXPR: + * + * @NAME1: String containing the name of the option. + * @EXPR1: Expression to validate the variable (must evaluate to bool). + * @NAME2: String containing the name of the option. + * @EXPR2: Expression to validate the variable (must evaluate to bool). + * + * Require exactly one of the command options in virsh. Use the provided + * expression to check the variables. + * + * This helper does an early return and therefore it has to be called + * before anything that would require cleanup. + */ +#define VSH_ALTERNATIVE_OPTIONS_EXPR(NAME1, EXPR1, NAME2, EXPR2) \ + do { \ + bool _expr1 =3D EXPR1; \ + bool _expr2 =3D EXPR2; \ + VSH_EXCLUSIVE_OPTIONS_EXPR(NAME1, _expr1, NAME2, _expr2); \ + if (!_expr1 && !_expr2) { \ + vshError(ctl, _("Either --%s or --%s must be provided"), \ + NAME1, NAME2); \ + return false; \ + } \ + } while (0) + /* Macros to help dealing with required options. */ =20 /* VSH_REQUIRE_OPTION_EXPR: --=20 2.38.0