From nobody Sun Feb 8 19:40:12 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1605001911; cv=none; d=zohomail.com; s=zohoarc; b=iNpbPrFO/zI5WeStXe2nlX7kcx8bkJKY/k7823u5swyS7PIpblc779bhgi98LY8urnCk9sOxnTcN3cYDTCADWJCSOTBaAb59sxPpY0gpRM5NdtTpChU/gQ+j+N5EppJxjqwDLr5wNGLPz1+Jrzb2UJuijypB8DOLq3NREGrNoas= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605001911; h=Content-Type:Content-Transfer-Encoding:Cc: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=Iy4nG+sdHxcgKDJVoP3uHZIJLTI+A4fQX/OtSKfu9fE=; b=V1oshdnEtBBZens/bzUDus9vH5jPXRBp5bepaRrAsOxDhAA6GhFk2m4Yshf6DlWGO38MwPL995WLtq47U+3nz2XjbN4M3kCN3pxWzfscLPAqZ1M9oPYvz1E8WJMJh0owPK6RotBMKPOE5njIkgm6SXC4ElCR9V/PrL8H4k7mZ64= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1605001911795189.88176124865095; Tue, 10 Nov 2020 01:51:51 -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-367-HW3fEwvaMyuFq0KZo49pGg-1; Tue, 10 Nov 2020 04:51:47 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3A2631006CA2; Tue, 10 Nov 2020 09:51:42 +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 47AD810013DB; Tue, 10 Nov 2020 09:51:41 +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 B44A918095FF; Tue, 10 Nov 2020 09:51:40 +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 0AA9pcMH006566 for ; Tue, 10 Nov 2020 04:51:39 -0500 Received: by smtp.corp.redhat.com (Postfix) id C4B0D94585; Tue, 10 Nov 2020 09:51:38 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BD8BF946A0 for ; Tue, 10 Nov 2020 09:51:36 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 61D271021F89 for ; Tue, 10 Nov 2020 09:51:36 +0000 (UTC) Received: from de-smtp-delivery-52.mimecast.com (de-smtp-delivery-52.mimecast.com [51.163.158.52]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-476-5RPVs6FtMTimqwWwYHBEtg-1; Tue, 10 Nov 2020 04:51:32 -0500 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04lp2055.outbound.protection.outlook.com [104.47.13.55]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-39-kql-9m4TM3KUddZjPpcnAA-3; Tue, 10 Nov 2020 10:51:29 +0100 Received: from AM6PR04MB5782.eurprd04.prod.outlook.com (2603:10a6:20b:aa::17) by AS8PR04MB7734.eurprd04.prod.outlook.com (2603:10a6:20b:2a6::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3541.21; Tue, 10 Nov 2020 09:51:27 +0000 Received: from AM6PR04MB5782.eurprd04.prod.outlook.com ([fe80::8945:92d8:e72a:6245]) by AM6PR04MB5782.eurprd04.prod.outlook.com ([fe80::8945:92d8:e72a:6245%6]) with mapi id 15.20.3541.025; Tue, 10 Nov 2020 09:51:27 +0000 Received: from t440p.suse.asia (60.251.47.115) by AM4P190CA0015.EURP190.PROD.OUTLOOK.COM (2603:10a6:200:56::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3541.21 via Frontend Transport; Tue, 10 Nov 2020 09:51:25 +0000 X-MC-Unique: HW3fEwvaMyuFq0KZo49pGg-1 X-MC-Unique: 5RPVs6FtMTimqwWwYHBEtg-1 X-MC-Unique: kql-9m4TM3KUddZjPpcnAA-3 From: Lin Ma To: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 01/13] virsh: Add vcpu list completion to guestvcpus command Date: Tue, 10 Nov 2020 17:50:52 +0800 Message-ID: <20201110095104.10783-2-lma@suse.com> In-Reply-To: <20201110095104.10783-1-lma@suse.com> References: <20201110095104.10783-1-lma@suse.com> X-Originating-IP: [60.251.47.115] X-ClientProxiedBy: AM4P190CA0015.EURP190.PROD.OUTLOOK.COM (2603:10a6:200:56::25) To AM6PR04MB5782.eurprd04.prod.outlook.com (2603:10a6:20b:aa::17) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 190873e6-2c85-4496-60f1-08d8855e30f3 X-MS-TrafficTypeDiagnostic: AS8PR04MB7734: X-LD-Processed: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba,ExtFwd X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4125 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0 X-Microsoft-Antispam-Message-Info: 2STMKbhyrg9LDmcS4J2Cz9ERvpP24QTffWNl1Z9kYukygiXFL7W2lpAtWUd6uoJTJJBvU7lL7FS9vXLpW8fkHwjTLhn2mFKlsSOSMEF/63wK4FtzpFakD0Dj5sggImadzEgUxMRatKMVf84Fu2AYhJBGBcd/Bu2fpKT7+9RH3YrUL7ou1xVji4DW/TYNBaZXztWaTAjMBKyteAs1jgYdZFKdpZnS+gOspww/30zk0G9v96lF6CtyU1cOYPMrCvuI9JwCcbKxKP0T2EghJOrgP9wcAzCnaTGcV+leMI/EZaYLsmkxVAOeJmrMXVz8m6Wa X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM6PR04MB5782.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(396003)(39860400002)(346002)(366004)(376002)(136003)(8936002)(2906002)(8676002)(66556008)(6666004)(2616005)(52116002)(107886003)(55236004)(6506007)(956004)(83380400001)(4326008)(6512007)(86362001)(36756003)(5660300002)(316002)(1076003)(66476007)(66946007)(478600001)(450100002)(16526019)(6916009)(26005)(186003)(6486002); DIR:OUT; SFP:1101 X-MS-Exchange-AntiSpam-MessageData: rZdhMYVs0pRTzGcxvfJfA1Ujc7bHCHYocXPWWigscDhXlGM1XCUcT4JxaXzDYBVNA4Jt4AXmhI7u+jO/DTq6K3M2go6pUBTFL9JtSRlMx6xUbHPEtQ5UEh9tCxLI84RUqG2XpB4OoXLUm5kGYRsypi51lXT5GtDOQMq1Z8O0Iz7mDBw3mn4qRQNDjuBkwMNzSeoQcLDk9EDTDeDsoq/EXJI4z5Waf1zmDCkg9Gg0Az3DQ+tTquVTCBcDvu82CRSVfLZxcw0zvKg9xKsDns0AHxkxF7wFLIcwBr1+z+BJSxROyuBE7u+OMf0tLpUIya8gnKTVu5y+fMnztkWiJJb41TyA+/qkTVxgysei02kW/k8c1CSx+pzyfAVnFYvw7SvLQP6CjR2zkqqV6sNMLjaYtUNSwZABtC7dRNMNDDpt1WuJQIfYRXhGKTaQ1PH1pEBrhDbQBElec+OzKGVDzz3DyjcIav+OdFT2RCLdo4r139SRNW98/YSu+X1xGVLI5UFUz5PM1gOVn+99fBA48Y9GwIkui+cCzGMBgPIJSqCKBxZU0PQjdy3stc1HDtfCFjLRNtDZ1UycTPik+DmnJ0TCpnFMrCPn+b6A01wtLyG0zx/ifrRGicGFzIpVzP4nGoBi870tUs9OidC7Ch0LOEEcbDzg9j8a0n91PhczHHrU6ewzSCOJF7bn24yq0X3bJVb4q6Ea5Vr8HaAVr4PleYj/3v1srT0bPPadBG5tEfQTmdAwSqX5BEaM6RvkAB6EfXq0UTD/GizHWJd5SIQtd/G94dSBf6HUO7ck/nzbF9tOlCa5bZPFcudIrjIwAFJ2lbJzN6A9mdgOua8WxS5NFyEaWaZsZhf/+KBxAek6THt99e6Mt+GUaarfZHb3FmuXaMNDKt7OO/j5lQOcchnax53Cmw== X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 190873e6-2c85-4496-60f1-08d8855e30f3 X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB5782.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Nov 2020 09:51:27.1539 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: nIb1dyKRJv6cYN4ob3mOc6UcPROFjOnLVm4qr2xfvAhknRROfw4bGHKZ1KwD6kUE X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB7734 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 0AA9pcMH006566 X-loop: libvir-list@redhat.com Cc: mprivozn@redhat.com, Lin Ma 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.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Signed-off-by: Lin Ma --- tools/virsh-completer-domain.c | 75 ++++++++++++++++++++++++++++++++++ tools/virsh-completer-domain.h | 4 ++ tools/virsh-domain.c | 1 + 3 files changed, 80 insertions(+) diff --git a/tools/virsh-completer-domain.c b/tools/virsh-completer-domain.c index c657627ac1..f653471b89 100644 --- a/tools/virsh-completer-domain.c +++ b/tools/virsh-completer-domain.c @@ -30,6 +30,7 @@ #include "virstring.h" #include "virxml.h" #include "virperf.h" +#include "virbitmap.h" =20 char ** virshDomainNameCompleter(vshControl *ctl, @@ -581,3 +582,77 @@ virshDomainCpulistCompleter(vshControl *ctl, =20 return virshCommaStringListComplete(cpuid, (const char **)cpulist); } + +char ** +virshDomainVcpulistViaAgentCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags) +{ + virDomainPtr dom; + bool enable =3D vshCommandOptBool(cmd, "enable"); + bool disable =3D vshCommandOptBool(cmd, "disable"); + virTypedParameterPtr params =3D NULL; + unsigned int nparams =3D 0; + int dummy; + size_t i; + size_t offset =3D 0; + int nvcpus; + VIR_AUTOSTRINGLIST cpulist =3D NULL; + g_autoptr(virBitmap) vcpus =3D NULL; + g_autofree unsigned char *vcpumap =3D NULL; + g_autofree char *onlineVcpuStr =3D NULL; + const char *vcpuid =3D NULL; + char **ret =3D NULL; + + virCheckFlags(0, NULL); + + if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + return NULL; + + if (vshCommandOptStringQuiet(ctl, cmd, "cpulist", &vcpuid) < 0) + goto cleanup; + + /* retrieve vcpu count from the guest instead of the hypervisor */ + if ((nvcpus =3D virDomainGetVcpusFlags(dom, VIR_DOMAIN_VCPU_GUEST | + VIR_DOMAIN_VCPU_MAXIMUM)) < 0) + goto cleanup; + + if (!enable && !disable) { + cpulist =3D g_new0(char *, nvcpus + 1); + for (i =3D 0; i < nvcpus; i++) + cpulist[i] =3D g_strdup_printf("%zu", i); + } else { + if (virDomainGetGuestVcpus(dom, ¶ms, &nparams, 0) < 0) + goto cleanup; + onlineVcpuStr =3D vshGetTypedParamValue(ctl, ¶ms[1]); + if (virBitmapParse(onlineVcpuStr, &vcpus, nvcpus) < 0) + goto cleanup; + + if (virBitmapToData(vcpus, &vcpumap, &dummy) < 0) + goto cleanup; + if (enable) { + cpulist =3D g_new0(char *, nvcpus - virBitmapCountBits(vcpus) = + 1); + for (i =3D 0; i < nvcpus; i++) { + if (VIR_CPU_USED(vcpumap, i) !=3D 0) + continue; + + cpulist[offset++] =3D g_strdup_printf("%zu", i); + } + } else if (disable) { + cpulist =3D g_new0(char *, virBitmapCountBits(vcpus) + 1); + for (i =3D 0; i < nvcpus; i++) { + if (VIR_CPU_USED(vcpumap, i) =3D=3D 0) + continue; + + cpulist[offset++] =3D g_strdup_printf("%zu", i); + } + } + } + + ret =3D virshCommaStringListComplete(vcpuid, (const char **)cpulist); + + cleanup: + virTypedParamsFree(params, nparams); + virshDomainFree(dom); + return ret; +} diff --git a/tools/virsh-completer-domain.h b/tools/virsh-completer-domain.h index d38efd5ea8..d5021f6aa6 100644 --- a/tools/virsh-completer-domain.h +++ b/tools/virsh-completer-domain.h @@ -90,3 +90,7 @@ char ** virshDomainVcpulistCompleter(vshControl *ctl, char ** virshDomainCpulistCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); + +char ** virshDomainVcpulistViaAgentCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 1ae936c6b2..675d96440d 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -7436,6 +7436,7 @@ static const vshCmdOptDef opts_guestvcpus[] =3D { VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name =3D "cpulist", .type =3D VSH_OT_STRING, + .completer =3D virshDomainVcpulistViaAgentCompleter, .help =3D N_("list of cpus to enable or disable") }, {.name =3D "enable", --=20 2.26.0