From nobody Fri Mar 29 02:31:53 2024 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; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=quarantine dis=quarantine) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1619087984; cv=none; d=zohomail.com; s=zohoarc; b=j6IQXrV6nHczBY/nwRXBJAoCmdbx3domO7UCTOMgoxySbNe8nT5b/Jlg/YOw6odEGsVTqoS0VHiMEMWweBbW530Djx0f2inSU7zA499WH8Dn1T971iYi8T+ii3kfWXs03w0tgMnm70xL0svcKIgKIiLCAQiODJsh33tdY4qZVtA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619087984; 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=yKFwcGDm2YajvyQtRPzuFhAs/M02Jo6rfHvFU6gHMNA=; b=K9WKtbhu2+p2qzyJ2Yz/AwVGfl9SypTIgdeDCvUBjhTWMnjdK6kST6cHyMwnDTXAzDldG0kLa/m/UoMsVsRYOkhji6p3cMGfOwt6bzXlYqTh4m6dLH8wfLMOEDBVPVwgEz7hHqQdmNGzm7pcwJLyXJzHz0Go9QQZ1v8qlHR68ks= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=quarantine dis=quarantine) header.from= 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 1619087984038214.38003218702772; Thu, 22 Apr 2021 03:39:44 -0700 (PDT) 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-376-U8cLNWpXMnqlsKQ9MVFgdQ-1; Thu, 22 Apr 2021 06:39:40 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 80AB3108DEA9; Thu, 22 Apr 2021 10:38:58 +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 5D51B5B4A0; Thu, 22 Apr 2021 10:38:58 +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 D6B5244A5B; Thu, 22 Apr 2021 10:38:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 13MActos010611 for ; Thu, 22 Apr 2021 06:38:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6037C2126737; Thu, 22 Apr 2021 10:38:55 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 562FC2126735 for ; Thu, 22 Apr 2021 10:38:52 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CEABF81D79F for ; Thu, 22 Apr 2021 10:38:52 +0000 (UTC) Received: from de-smtp-delivery-102.mimecast.com (de-smtp-delivery-102.mimecast.com [194.104.111.102]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-215-uthkAxmcNfGxJQycCiL0FA-1; Thu, 22 Apr 2021 06:38:50 -0400 Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-db5eur01lp2051.outbound.protection.outlook.com [104.47.2.51]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-4-gUvyKBHtMAGbXQhk8Zkprg-1; Thu, 22 Apr 2021 12:38:48 +0200 Received: from AM6PR04MB5782.eurprd04.prod.outlook.com (2603:10a6:20b:aa::17) by AS8PR04MB8388.eurprd04.prod.outlook.com (2603:10a6:20b:3f8::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.21; Thu, 22 Apr 2021 10:38:47 +0000 Received: from AM6PR04MB5782.eurprd04.prod.outlook.com ([fe80::8c4c:a6f6:3e91:2a52]) by AM6PR04MB5782.eurprd04.prod.outlook.com ([fe80::8c4c:a6f6:3e91:2a52%7]) with mapi id 15.20.4042.024; Thu, 22 Apr 2021 10:38:47 +0000 Received: from p15.suse.asia (60.251.47.115) by PR3P191CA0030.EURP191.PROD.OUTLOOK.COM (2603:10a6:102:54::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.22 via Frontend Transport; Thu, 22 Apr 2021 10:38:44 +0000 X-MC-Unique: U8cLNWpXMnqlsKQ9MVFgdQ-1 X-MC-Unique: uthkAxmcNfGxJQycCiL0FA-1 X-MC-Unique: gUvyKBHtMAGbXQhk8Zkprg-1 From: Lin Ma To: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/2] virsh: Add mountpoint completion to domfsfreeze/domfsthaw command Date: Thu, 22 Apr 2021 18:38:18 +0800 Message-ID: <20210422103819.22753-2-lma@suse.com> In-Reply-To: <20210422103819.22753-1-lma@suse.com> References: <20210422103819.22753-1-lma@suse.com> X-Originating-IP: [60.251.47.115] X-ClientProxiedBy: PR3P191CA0030.EURP191.PROD.OUTLOOK.COM (2603:10a6:102:54::35) 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: 8b9814f3-b9c5-4e47-db1a-08d9057acee5 X-MS-TrafficTypeDiagnostic: AS8PR04MB8388: 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:1850 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0 X-Microsoft-Antispam-Message-Info: PPlXd4081do/bQYYvvQKSuGaeusLtGYTMC0L2CQf2blk9PS9mA2IW7H+v5b95p+znhoVSZggPX+/DzEGxtw2Nn31lI7njbzZhPJQgp4AFTsruDSlYN5PFCN1N0wZl2ZUYb2vbFL6iscrTR38bbaHBTZkA0pdbEG8KyfrmDAqu9PvZJOYY/Jy8gVj/D4IpXXJxvM1X5/fjAVGzthVzh++97R878Li6i8Oi2OXeMOnUFdNyfipazQWq6SsPdBbMP8JUYhZ8jVfMESPFDedsF1g3cyV2AmifDbhRDbKpHL9sIvBAVc4jtuC6I+4+/8ZDjBo/BOEop7RVUrmqCo3Kcm7Y4QOHey6CtQb5ckOxmI1QfBU19oBgmubLv9pykpbR5SstXUjFUtRXUB9W0VKuWI+nqnqnxzuBtQK6L0pWKmjb5SzWllN5xmSCFtxc72D2hblJrcCwDsAMFEB2KnRmd5uQ+Q9HFgqo9CayHDXPUaTkiNm1k4oaB+QW9imiCTPLv8jxdqcFvKcmy8kwKY+2uIcBJoBHHDFFyGvD00dcwfBy8ao/U1wDAvkWpt0y5JssTFjThLKyiFn5O7z66dVv39LJfupXfD/02VSKFrp0Z2lfM9k0WdI+Of4EonAYzQtlewmHEUuJQmJzS/k3o+lpYZv3Q== 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:(136003)(376002)(346002)(366004)(39860400002)(396003)(66556008)(316002)(186003)(38100700002)(1076003)(478600001)(16526019)(52116002)(956004)(2616005)(107886003)(2906002)(38350700002)(86362001)(55236004)(6486002)(6666004)(26005)(66946007)(6916009)(5660300002)(8676002)(450100002)(36756003)(8936002)(6512007)(4326008)(6506007)(66476007); DIR:OUT; SFP:1101 X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?ISDTIqtipunuXzC8clclpzQD5M9m9PLQJEJjVv/8dVGH5px2pfnsUds7AJEF?= =?us-ascii?Q?3Bkfs48NfrqwRthoPlDzpjB8P22f3rGVndmkNxF0TwqDPyeN68q9AkenR5cr?= =?us-ascii?Q?P58gv4o8liBylOtTd1dP4ReNb/to2qWcqTuimWAmiiQBuBPNDsiiyJzI3Jiz?= =?us-ascii?Q?7eWcRTMCFl8TKBYkLXgcIzFCfaid/C4luPyrL4Mn9nmuRha8H2XEmp/66zSC?= =?us-ascii?Q?zBVjxDq1VQGkQq95ioVJ2Fxu08tu+cr6yzRCZxnvtT4hbKHs86R1kvuYwc4h?= =?us-ascii?Q?BWkOEm/lrtwmScq3BNOVb7qLq1TY7kRSmeDn5g4tCY/tskEUVg0XTA+XW6d/?= =?us-ascii?Q?dVasUtc6GDNTM1wueHu1IH360r4fu4GNxNnsE8rwGIqKYlTwcnsdxIgFTsQM?= =?us-ascii?Q?LLT9CRFH6SLNTAUEtH3JcsftluNZec+H8j+unJjbQGJ26RJTBlL8IbLmSns4?= =?us-ascii?Q?NQJJNfHZp8yBRHwbH7Zj+uaWezoHmAKfkcNkk9CuIyB0kcxrqLHIr+EoNbFa?= =?us-ascii?Q?ZgIhHBctQTOph3YR4mZTJQqDobGi9E58hybLwmcN742HLbEzFSnGUuRw01u8?= =?us-ascii?Q?UxBeVfRRFLI2UMIxVpadyzUJT5sqKCOy+Ds+MO/xz6fF1ZLaS53aPMTc51B0?= =?us-ascii?Q?qUCDxSq71QnKy2FZnT4HyQpAEgAvaPtphwmmD34z4bIrBBWcVbPYkhpl38s6?= =?us-ascii?Q?S55Td1+fVdMrR7y/bX4vAYh5Zcbeu6lTBU8grjRBX0QvQUaZbzIAmJmVWBFc?= =?us-ascii?Q?MdgH6H/cyx0vGtAYLvUkJ2KxIWF2gR+mbhFhyN6w8HtDvEpX8yXEcPS/NA6l?= =?us-ascii?Q?fphwIu+mDTYMK6lw2+WmE+/WK1VyWEK56PrIY+pliFlOW2D51BJ1v0ajLxk/?= =?us-ascii?Q?A3IQZb7UuthZ76LOO3qH9htDqyvgNwSBS/NTXntLTrEiIDS2ytuyUVQPXiZ/?= =?us-ascii?Q?Hik10fEUIw9DA/zlUVy0235m9NXISBXVCT87JtXNWp5shW8VRMDX9LulV9g7?= =?us-ascii?Q?yoEHYSrNofz5FMEAQvLAPHiiEryB1tY+6qea46hvuKlY1dgODQjLJd8pFYFz?= =?us-ascii?Q?6SbV1vZ5wTFFoXZ5Ak2nTsQ4iQSgSWkQ6rbS+l4Akv8dZBM01q4ka+uF+GWG?= =?us-ascii?Q?VOF4KUm4bI1Q/7uDf5B1VLC83oSGTeG7j7iSeLR3iS3iXFSywA5bqKJmd9ey?= =?us-ascii?Q?ImFWmUOdsne8+MP3+kfw3D+QqqqF4kz1RbRaQkGUd9+ZmXpgAXigVr3WYZHj?= =?us-ascii?Q?tUGV2pwMqCr3rWEjVSFXXurO2P3hLzLBIVx4t2RineTKsVaA/heVNWAcCmXt?= =?us-ascii?Q?nyBC/tIpUA11HSq9hvCIr7l/?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8b9814f3-b9c5-4e47-db1a-08d9057acee5 X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB5782.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2021 10:38:46.9682 (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: tYWLCsww8JYHSe/K75ENV1ilMjKSnvdPeS5eNHwfTUn53HLfymEHvo1DkGpSqMs4 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB8388 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.4 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 13MActos010611 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.11 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 Reviewed-by: Michal Privoznik --- tools/virsh-completer-domain.c | 43 ++++++++++++++++++++++++++++++++++ tools/virsh-completer-domain.h | 4 ++++ tools/virsh-domain.c | 2 ++ 3 files changed, 49 insertions(+) diff --git a/tools/virsh-completer-domain.c b/tools/virsh-completer-domain.c index 99b36a2f9f..f56dc40125 100644 --- a/tools/virsh-completer-domain.c +++ b/tools/virsh-completer-domain.c @@ -872,3 +872,46 @@ virshKeycodeNameCompleter(vshControl *ctl, =20 return g_steal_pointer(&tmp); } + + +char ** +virshDomainFSMountpointsCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags) +{ + g_auto(GStrv) tmp =3D NULL; + virDomainPtr dom =3D NULL; + int rc =3D -1; + size_t i; + virDomainFSInfoPtr *info =3D NULL; + size_t ninfos =3D 0; + char **ret =3D NULL; + + virCheckFlags(0, NULL); + + if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + return NULL; + + rc =3D virDomainGetFSInfo(dom, &info, 0); + if (rc <=3D 0) { + goto cleanup; + } + ninfos =3D rc; + + if (info) { + tmp =3D g_new0(char *, ninfos + 1); + for (i =3D 0; i < ninfos; i++) { + tmp[i] =3D g_strdup(info[i]->mountpoint); + } + ret =3D g_steal_pointer(&tmp); + } + + cleanup: + if (info) { + for (i =3D 0; i < ninfos; i++) + virDomainFSInfoFree(info[i]); + VIR_FREE(info); + } + virshDomainFree(dom); + return ret; +} diff --git a/tools/virsh-completer-domain.h b/tools/virsh-completer-domain.h index 04a3705ff9..ef242d0c68 100644 --- a/tools/virsh-completer-domain.h +++ b/tools/virsh-completer-domain.h @@ -118,3 +118,7 @@ char ** virshCodesetNameCompleter(vshControl *ctl, char ** virshKeycodeNameCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); + +char ** virshDomainFSMountpointsCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index fac590fbc6..9d315bdbcf 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -13920,6 +13920,7 @@ static const vshCmdOptDef opts_domfsfreeze[] =3D { VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name =3D "mountpoint", .type =3D VSH_OT_ARGV, + .completer =3D virshDomainFSMountpointsCompleter, .help =3D N_("mountpoint path to be frozen") }, {.name =3D NULL} @@ -13969,6 +13970,7 @@ static const vshCmdOptDef opts_domfsthaw[] =3D { VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name =3D "mountpoint", .type =3D VSH_OT_ARGV, + .completer =3D virshDomainFSMountpointsCompleter, .help =3D N_("mountpoint path to be thawed") }, {.name =3D NULL} --=20 2.26.2 From nobody Fri Mar 29 02:31:53 2024 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; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=quarantine dis=quarantine) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1619087990; cv=none; d=zohomail.com; s=zohoarc; b=mNDltpA8xRTbXhKPAV7IIn9E5/lQ5U/a7KE1zgtErnjfy3sAC3gStQu+KJR9qWh8yoKxybvQN3UmKoJL773n3sHlzkg/CUfJhHaXovOhb5WrdXd16e3jQJ7WJ4llJjTRWODHBdKwAT7FhZk52iJuPr+CbYs1GhsCGuEvPVLp57A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619087990; 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=VK4qPp5lyWpUWAecvZG3Iy80eEt7SebhK5Z2rLbtsiA=; b=niRzSEMgEIewsA2xmu7fAnAfCChcV2obm39cJUEmES/9wvxO5fbN9oM51UXQ5Uvzh5OxxcxTI+SQTwBsUbu39boDOI/ap5TpfPOTBN6VFo6ZyTZLQG9SJn0aJXQQ2LIm8BefSH2WEgSWXB6RKPP8EB57gqInl0EZNLDk959qE+8= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=quarantine dis=quarantine) header.from= 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 1619087990622288.72327412649463; Thu, 22 Apr 2021 03:39:50 -0700 (PDT) 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-232-hmU8gIODN92t9XoijBivTw-1; Thu, 22 Apr 2021 06:39:47 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6D2D4108BC82; Thu, 22 Apr 2021 10:39:03 +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 4BB2760CFB; Thu, 22 Apr 2021 10:39:03 +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 1079B1806D1A; Thu, 22 Apr 2021 10:39:03 +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 13MAcxYK010627 for ; Thu, 22 Apr 2021 06:38:59 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2B589FDCC2; Thu, 22 Apr 2021 10:38:59 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 266C2FED35 for ; Thu, 22 Apr 2021 10:38:56 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6A5B585A5BB for ; Thu, 22 Apr 2021 10:38:56 +0000 (UTC) Received: from de-smtp-delivery-102.mimecast.com (de-smtp-delivery-102.mimecast.com [194.104.111.102]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-579-7bt1o_NVMoOWtWc1pOUt6A-1; Thu, 22 Apr 2021 06:38:52 -0400 Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-db5eur01lp2051.outbound.protection.outlook.com [104.47.2.51]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-4-1psy6YPYNwSiVE4FD-0T0Q-3; Thu, 22 Apr 2021 12:38:49 +0200 Received: from AM6PR04MB5782.eurprd04.prod.outlook.com (2603:10a6:20b:aa::17) by AS8PR04MB8388.eurprd04.prod.outlook.com (2603:10a6:20b:3f8::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.21; Thu, 22 Apr 2021 10:38:49 +0000 Received: from AM6PR04MB5782.eurprd04.prod.outlook.com ([fe80::8c4c:a6f6:3e91:2a52]) by AM6PR04MB5782.eurprd04.prod.outlook.com ([fe80::8c4c:a6f6:3e91:2a52%7]) with mapi id 15.20.4042.024; Thu, 22 Apr 2021 10:38:49 +0000 Received: from p15.suse.asia (60.251.47.115) by PR3P191CA0030.EURP191.PROD.OUTLOOK.COM (2603:10a6:102:54::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.22 via Frontend Transport; Thu, 22 Apr 2021 10:38:47 +0000 X-MC-Unique: hmU8gIODN92t9XoijBivTw-1 X-MC-Unique: 7bt1o_NVMoOWtWc1pOUt6A-1 X-MC-Unique: 1psy6YPYNwSiVE4FD-0T0Q-3 From: Lin Ma To: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/2] virsh: Fix completion logic to guestvcpus command Date: Thu, 22 Apr 2021 18:38:19 +0800 Message-ID: <20210422103819.22753-3-lma@suse.com> In-Reply-To: <20210422103819.22753-1-lma@suse.com> References: <20210422103819.22753-1-lma@suse.com> X-Originating-IP: [60.251.47.115] X-ClientProxiedBy: PR3P191CA0030.EURP191.PROD.OUTLOOK.COM (2603:10a6:102:54::35) 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: 37bc7338-d0b1-4335-aac2-08d9057ad03e X-MS-TrafficTypeDiagnostic: AS8PR04MB8388: 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: xCeBGYB60fks7VDSPtxifs39uFp2SOM1NL3ZHimRzHUspV3BzT6CnsCZxxxG/RMzGsydNYLa7GFV7fCrQEwkMi95cSzGV9OmDEV7b+T6ICdfOOgHz+m0z50yp8pKU5c7UoH9iyMUgCZrhvW9Jx4yBjflH03MZkzAgHDR4ZjAvVLhLBNp4ZU3OFmWm1lLOZfARPnhzcaloq4Tf90oBftie0DAI6/Sc2Q4wYDgFG+MCCTuvhmcANw/Ms4tcwVOqSXVp7Ad2PgIDfnXVc0WD59K+4JVq7q03JP9z1AD6FCDFFLRVk/5I0QI2w80rusxZZ9WZ31uqqImF0Q6qhq3OyjaYkONM1Iy6aBUc0dEOAY9cFMK5fV1+KHwbNiVGbaNDUVpEsjp2UbSx51DWSDdSBtM8TOcbuBk1K0+QWNOU34u9XkR0xdpq9Gyi8p6iasIMwLqnnovgRzX9h2nyAmnvXm6Zp+NCqqw6tO9R8N8uS8ag/VeXKMIL2y0nAaStrSu1h+Klyzo4nHl/YA9JsfAmNWb+kMvXlTaMXJq4J9edz3B+bRY3O25Zhx/gRRUp6LzbDsbEx3arV4w006dCUwz6Tppk9n9sM27lmwBaVZ0/P2hbGwP2erQ2BizUUjbQ8XFMjBloTqg/7nCBqSOj4fgttY05+hXL0eyUVdo4jjWstlSNpo= 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:(136003)(376002)(346002)(366004)(39860400002)(396003)(66556008)(316002)(186003)(38100700002)(1076003)(83380400001)(478600001)(16526019)(52116002)(956004)(2616005)(107886003)(2906002)(38350700002)(86362001)(55236004)(6486002)(6666004)(26005)(66946007)(6916009)(5660300002)(8676002)(450100002)(36756003)(8936002)(6512007)(4326008)(6506007)(66476007); DIR:OUT; SFP:1101 X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?7Apj0fm3ws+2+nyvhg5xdpJYIGudeGM+wdgWMoOMPGrWBg4H9dwu0H0uRcBd?= =?us-ascii?Q?0hdiVibT0NG0MG5S3QUgZ7mxmn6t7JEAhWbdgjYWCcFbV5sDPZlNnNYrjHRQ?= =?us-ascii?Q?0/Y0sw47ln0K7idXbIFqmaWXfiWiNIz2WrC8bok0nqJc/RZ+o0AvCGqzcAQg?= =?us-ascii?Q?x3VDOTqr6q1TQPnMGg9sOLTfLilfAD9CumkiisC5Q4kZnehdWwcR5kCDiLO0?= =?us-ascii?Q?D3IFwXONP1pHHbaQRRIboJemqxJF4uKVxWJhlYgoBq2sZub12cf8k0b9iOD9?= =?us-ascii?Q?S1TegBiBSh559dRH2Oj5gWBv5tC/KkGmLl2ULKLjsU8pS/lGljGjth/S4+B4?= =?us-ascii?Q?9lYdwm88o6XZ7QtVFf2WGWgphSMB6pAXWIy668CC1pQViW5eQOoQV8MjTYi+?= =?us-ascii?Q?Ox/Pktvgo348lJStuKoIoFpG01a7GZ8L8JUJMnyS2D3nao4uNH7qhzuqsqsv?= =?us-ascii?Q?wssanhA8o7yfDpxne7ACDnPWmOcoj9EL3jDz8hhIP3NNZQirVOOpx7qNJc50?= =?us-ascii?Q?YRUS+iG7Eo/TBXO90pmiPfnBGvgBCpf7x72l2GsJPJPXqSaUcoOHnGVLBDl9?= =?us-ascii?Q?KIVASUvDwzu3Yd0CjImnRCnM90xUF0FRQWk7cIF7fVJ1QLfX+VuY7BUM7RBC?= =?us-ascii?Q?njoGrf4h2TaXLcE/Jtyav3ni+zsb9v2nw3BnWHUULf+UNJWxIJC45QJPKmSQ?= =?us-ascii?Q?97+n7OLaJzXmpJ47Ur1CDM7WRk5HJit2Obq/jNoSjSTTrhjXxDCP9XVtH+qf?= =?us-ascii?Q?LDJUpYjMAIGmmSmMAwjsVc4EPEi/pmw9niW+y5w9RM1BbOGkD4xc6Kkk6kFt?= =?us-ascii?Q?FXaEKnjturWCRWtLRHjbwA0FlT5VLbrzJcmoONWLtsTQQoMqK7J8iNhC5JD6?= =?us-ascii?Q?JxNe4+kmKLe2RYONVGCQopMnKDhqUvn6odnvj3mB9gUWCeu08VfEV1YYaoEB?= =?us-ascii?Q?99txQUidiKKTPOPpSQOn1DIICtjTwvIJ7DevJHNbiNKyJ0wIrP0ZKpD/SfHp?= =?us-ascii?Q?svMACTMK4qL+HviaMUZI/A71smkNvH97ZuqJKox4zLRM/vZHPEcV7kTwVyII?= =?us-ascii?Q?LauYcNO/8c3T8zZCO7bNMcdzPd+MJZEoueLmjTZo9f0YX9FImUEXAX+p2R74?= =?us-ascii?Q?C7jM7YLUTXULxqRX3ge3FTttE8y03TzzDXn0fh9kl2lrTR3/KMKrBxmXPtyv?= =?us-ascii?Q?4wqQsk6jmnbcQZ3N6SfSAkdAB715mAotzca9cRUwuL2DqWLGbdHyVf0znmgT?= =?us-ascii?Q?qCuWCmMY7NaW+FJo0CanpYUAXxixRWR7Cu8iTMzxVuActrxlAG7aqGEbzeer?= =?us-ascii?Q?tvu/PZpv9Pi15CuOU6jR8kW+?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 37bc7338-d0b1-4335-aac2-08d9057ad03e X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB5782.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2021 10:38:49.0760 (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: YfXGOvvTXMAIs1Hi04nLWh0sypS4gEoZzDQUYhlX2PVVzwbOumyeJEM2h4OmgrLk X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB8388 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 13MAcxYK010627 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.13 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" In case of non-continuous vCPU topology, We can't infer the bitmap size from the combination of onlineVcpuStr and nvcpus. We should use virBitmapParseUnlimited here instead of virBitmapParse due to the bitmap size is unknown. e.g.: # virsh guestvcpus --domain VM vcpus : 0-5 online : 0-5 offlinable : 1-5 # virsh setvcpu --domain VM --disable --vcpulist 2 # virsh guestvcpus --domain VM --disable --cpulist 4,5 # virsh guestvcpus --domain VM vcpus : 0-1,3-5 online : 0-1,3 offlinable : 1,3-5 Before: # virsh guestvcpus --domain VM --enable --cpulist 2 4 After: # virsh guestvcpus --domain VM --enable --cpulist 4 5 Signed-off-by: Lin Ma Reviewed-by: Michal Privoznik --- tools/virsh-completer-domain.c | 61 ++++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 17 deletions(-) diff --git a/tools/virsh-completer-domain.c b/tools/virsh-completer-domain.c index f56dc40125..998aa5d646 100644 --- a/tools/virsh-completer-domain.c +++ b/tools/virsh-completer-domain.c @@ -624,36 +624,63 @@ virshDomainVcpulistViaAgentCompleter(vshControl *ctl, cpulist[i] =3D g_strdup_printf("%zu", i); } else { g_autofree char *onlineVcpuStr =3D NULL; - g_autofree unsigned char *vcpumap =3D NULL; - g_autoptr(virBitmap) vcpus =3D NULL; - size_t offset =3D 0; + g_autofree char *offlinableVcpuStr =3D NULL; + g_autofree unsigned char *onlineVcpumap =3D NULL; + g_autofree unsigned char *offlinableVcpumap =3D NULL; + g_autoptr(virBitmap) onlineVcpus =3D NULL; + g_autoptr(virBitmap) offlinableVcpus =3D NULL; + size_t j =3D 0; + int lastcpu; int dummy; =20 if (virDomainGetGuestVcpus(dom, ¶ms, &nparams, 0) < 0) goto cleanup; =20 onlineVcpuStr =3D vshGetTypedParamValue(ctl, ¶ms[1]); - if (virBitmapParse(onlineVcpuStr, &vcpus, nvcpus) < 0) + if (!(onlineVcpus =3D virBitmapParseUnlimited(onlineVcpuStr))) goto cleanup; =20 - if (virBitmapToData(vcpus, &vcpumap, &dummy) < 0) + if (virBitmapToData(onlineVcpus, &onlineVcpumap, &dummy) < 0) goto cleanup; =20 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); + offlinableVcpuStr =3D vshGetTypedParamValue(ctl, ¶ms[2]); + + if (!(offlinableVcpus =3D virBitmapParseUnlimited(offlinableVc= puStr))) + goto cleanup; + + if (virBitmapToData(offlinableVcpus, &offlinableVcpumap, &dumm= y) < 0) + goto cleanup; + + lastcpu =3D virBitmapLastSetBit(offlinableVcpus); + cpulist =3D g_new0(char *, nvcpus - virBitmapCountBits(onlineV= cpus) + 1); + for (i =3D 0; i < nvcpus - virBitmapCountBits(onlineVcpus); i+= +) { + while (j <=3D lastcpu) { + if (VIR_CPU_USED(onlineVcpumap, j) !=3D 0 || + VIR_CPU_USED(offlinableVcpumap, j) =3D=3D 0) { + j +=3D 1; + continue; + } else { + break; + } + } + + cpulist[i] =3D g_strdup_printf("%zu", j++); } } 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); + lastcpu =3D virBitmapLastSetBit(onlineVcpus); + cpulist =3D g_new0(char *, virBitmapCountBits(onlineVcpus) + 1= ); + for (i =3D 0; i < virBitmapCountBits(onlineVcpus); i++) { + while (j <=3D lastcpu) { + if (VIR_CPU_USED(onlineVcpumap, j) =3D=3D 0) { + j +=3D 1; + continue; + } else { + break; + } + } + + cpulist[i] =3D g_strdup_printf("%zu", j++); } } } --=20 2.26.2