From nobody Mon Feb 9 04:14:16 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1604305652; cv=none; d=zohomail.com; s=zohoarc; b=lhGslodYWfYAQjVreOGN17qeiXopKq3czAx5n1dp3gFOiCIosmOvfgXBNh6/ItWdRag+UjlFwpURwKIMIHrSNfAXKTV8f2oj3mBNiMLH8wwnb9BbLzrTjuq2eQuLfor670NkIC/RRmSytmv4ZutAom8BeXHqKcWXihJaK3Yl6Uc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604305652; 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=ZDOiF0m7g8qlW1y0EaJlJodUNM41088kchIUZXMlAf4=; b=PoUSmMfBRSCyojje4eJZfk7yYkxMlXgcrBD2og4J8DtEb/qxmnkVhV4pv9W20mdFdESmMhyf6k0+QTNn7KvqQeDQQdXvn2PRdVePnxpPe8jbpO/apGPzJyPQFnNqipj+vtmrX/3J/joL4FCKMgRjOoywQmpq4fy5hymvaCsTBbc= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1604305652846757.1189726085177; Mon, 2 Nov 2020 00:27:32 -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-58-ToHYkBQuNVufxuHFs_VNhA-1; Mon, 02 Nov 2020 03:27:29 -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 82F491084C8B; Mon, 2 Nov 2020 08:27:17 +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 5CF096716C; Mon, 2 Nov 2020 08:27:17 +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 264BB8C7B8; Mon, 2 Nov 2020 08:27:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0A28QvwV031214 for ; Mon, 2 Nov 2020 03:26:58 -0500 Received: by smtp.corp.redhat.com (Postfix) id D1F2B2156A37; Mon, 2 Nov 2020 08:26:57 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CB9582157F26 for ; Mon, 2 Nov 2020 08:26:55 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (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 8778F811E76 for ; Mon, 2 Nov 2020 08:26:55 +0000 (UTC) Received: from de-smtp-delivery-102.mimecast.com (de-smtp-delivery-102.mimecast.com [51.163.158.102]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-57-7LXj4K_tNuix4RNiCWKkqw-1; Mon, 02 Nov 2020 03:26:51 -0500 Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01lp2054.outbound.protection.outlook.com [104.47.1.54]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-23-diTxNvpdNQiclerCnidd6w-5; Mon, 02 Nov 2020 09:26:46 +0100 Received: from AM6PR04MB5782.eurprd04.prod.outlook.com (2603:10a6:20b:aa::17) by AM6PR0402MB3624.eurprd04.prod.outlook.com (2603:10a6:209:4::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.30; Mon, 2 Nov 2020 08:26:43 +0000 Received: from AM6PR04MB5782.eurprd04.prod.outlook.com ([fe80::b5ca:e454:9fad:8712]) by AM6PR04MB5782.eurprd04.prod.outlook.com ([fe80::b5ca:e454:9fad:8712%7]) with mapi id 15.20.3499.030; Mon, 2 Nov 2020 08:26:43 +0000 Received: from t440p.suse.asia (60.251.47.115) by AM9P191CA0007.EURP191.PROD.OUTLOOK.COM (2603:10a6:20b:21c::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.19 via Frontend Transport; Mon, 2 Nov 2020 08:26:41 +0000 X-MC-Unique: ToHYkBQuNVufxuHFs_VNhA-1 X-MC-Unique: 7LXj4K_tNuix4RNiCWKkqw-1 X-MC-Unique: diTxNvpdNQiclerCnidd6w-5 From: Lin Ma To: libvir-list@redhat.com Subject: [libvirt] [PATCH 02/19] virsh: Add logical CPU IDs completion for nodecpustats command Date: Mon, 2 Nov 2020 16:26:04 +0800 Message-ID: <20201102082621.13228-3-lma@suse.com> In-Reply-To: <20201102082621.13228-1-lma@suse.com> References: <20201102082621.13228-1-lma@suse.com> X-Originating-IP: [60.251.47.115] X-ClientProxiedBy: AM9P191CA0007.EURP191.PROD.OUTLOOK.COM (2603:10a6:20b:21c::12) 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: 440b12f6-57a4-4c46-bf90-08d87f09079d X-MS-TrafficTypeDiagnostic: AM6PR0402MB3624: 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:200 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0 X-Microsoft-Antispam-Message-Info: 8gHQKWrtkzHgyjxn5U1IS/oq/rixn9CkYWWl3NZVWV1nQ1ohyyXTZQr3EKLREy7FQCiuaYJz7AVuBuh7Iuomu9SVndGFXUWbsNT/N6qtroU5T/4lMv4QsFZSTxPFbkwXoQ3H7AihNb8r1MCcpUhbzR065im1CtS4AkjAzfhJEznkClj2+UrcQAWUzWpNVrz9YYVjON3Kwv1hb5HQAjPSV8PSlANLdGmKZ+h/T+w5fiWOlByNLxVtMgFPILO+V9KZIPQ/8koQfXwQ6DvCs2HnaIJlHTB/j1HrwyXlZmvUQzu5+LniZXOnEDu8Gq4IPMt/XV+Ypf7VngOvd5tY2e+oPA== 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:(346002)(39860400002)(396003)(376002)(136003)(366004)(107886003)(6666004)(5660300002)(16526019)(66556008)(66946007)(66476007)(2616005)(956004)(8676002)(6506007)(186003)(316002)(450100002)(4326008)(52116002)(26005)(478600001)(8936002)(2906002)(36756003)(55236004)(86362001)(1076003)(6916009)(6486002)(83380400001)(6512007); DIR:OUT; SFP:1101 X-MS-Exchange-AntiSpam-MessageData: pNvRK8ZigYu1o8y2dzGqU08wI6OKCi/t7HloqQ01pWJmiTASmHwuWMwldb9D/0aTYzEmM9UoqN8UsTrMCbRdQV6ekxnZ+zi3F53rESVXClXdz3dMtbaZHYtgUuyoescRnLRoCjW9eEeKrtu7s6d/YDp6VRuc/ubdx5Mi722tD/sbrO0oFTG5556+1bjoZO6Z1LMpMxLpRZqxnGTzfdKZfwScSEi/QeXm0m1TyeW3LjGoDK7fRvAnXIhs7UTIxcll9SmZLMy+nAie9pqbQT7WSyNUrSLWvFtBNDow7wUxE9Xn8NWlrsRwxsF46XlFVdrVLFgk1dR2Q5Z/1nUb4kxIAjxKfmek1a78olGzBsqVobBF7+JDG94iFda7mkbaNqZeRIxp5TxOIkJHZXDvoJyYqk62wqAAA9n7g72hUZhM0rc4PkunYuuawtiSGScxQiEypLgfROP7dhSanL74aCYTpHv135DYpGBrakH3smB4aDbxQG8q3vZiy24Qp6t9xzgbu2zS2fOoQ2RM1LesxQIrHdNXHNbi+7T1i9WIPht8udqdoaL8aU6bFGkekOWu2QIEHUi9rriFTmkq4fcAwYG6sbqjJRuxbh/69QBgxIOSKTqeoTbgFXZvXc6wVI7Zx8WTOIfupjq6NW+TN6EBdlvJqA== X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 440b12f6-57a4-4c46-bf90-08d87f09079d X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB5782.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Nov 2020 08:26:43.5864 (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: dw12Dj/JEQMiTlGR3lOIgxrsoV/PxXMQEsGxfq03FFin/49BEBnS37iF+S6leQY0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR0402MB3624 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.78 on 10.11.54.6 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 0A28QvwV031214 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.79 on 10.5.11.12 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-host.c | 35 +++++++++++++++++++++++++++++++++++ tools/virsh-completer-host.h | 4 ++++ tools/virsh-host.c | 1 + 3 files changed, 40 insertions(+) diff --git a/tools/virsh-completer-host.c b/tools/virsh-completer-host.c index 339390aa00..a74578d2e2 100644 --- a/tools/virsh-completer-host.c +++ b/tools/virsh-completer-host.c @@ -136,3 +136,38 @@ virshCellnoCompleter(vshControl *ctl, =20 return g_steal_pointer(&tmp); } + + +char ** +virshCpuCompleter(vshControl *ctl, + const vshCmd *cmd G_GNUC_UNUSED, + unsigned int flags) +{ + int i, cpuid =3D 0, cpunum, offset =3D 0; + unsigned int online; + g_autofree unsigned char *cpumap =3D NULL; + char **ret =3D NULL; + VIR_AUTOSTRINGLIST tmp =3D NULL; + virshControlPtr priv =3D ctl->privData; + + virCheckFlags(0, NULL); + + if ((cpunum =3D virNodeGetCPUMap(priv->conn, &cpumap, &online, 0)) < 0) + return NULL; + + tmp =3D g_new0(char *, online + 1); + + for (i =3D 0; i < cpunum; i++) { + if (VIR_CPU_USED(cpumap, cpuid) =3D=3D 0) { + offset +=3D 1; + cpuid +=3D 1; + continue; + } else { + tmp[i - offset] =3D g_strdup_printf("%u", cpuid++); + } + } + + ret =3D g_steal_pointer(&tmp); + + return ret; +} diff --git a/tools/virsh-completer-host.h b/tools/virsh-completer-host.h index 921beb7a2d..777783b908 100644 --- a/tools/virsh-completer-host.h +++ b/tools/virsh-completer-host.h @@ -29,3 +29,7 @@ char ** virshAllocpagesPagesizeCompleter(vshControl *ctl, char ** virshCellnoCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); + +char ** virshCpuCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); diff --git a/tools/virsh-host.c b/tools/virsh-host.c index cda2ef4ac1..4774f76ed8 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -751,6 +751,7 @@ static const vshCmdInfo info_nodecpustats[] =3D { static const vshCmdOptDef opts_node_cpustats[] =3D { {.name =3D "cpu", .type =3D VSH_OT_INT, + .completer =3D virshCpuCompleter, .help =3D N_("prints specified cpu statistics only.") }, {.name =3D "percent", --=20 2.26.0