From nobody Mon Feb 9 02:27:25 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=1604305643; cv=none; d=zohomail.com; s=zohoarc; b=Vj6TL+OsBfYUPfskBsDp1nAdCEgzyL2JXClJnSiltli7q5kdOsYWDJG60xCB3GpTFbVMV3sHACjsfqGahbz8amkSx9gC697zv1moxQM6R1MB1ghHx0xK1qWgndk3Dw4K4pWGXmCV+JAD/ItA6/1Zsjl3IbDY+HyU3/faLRIbYyo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604305643; 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=RNlTsv9EqxnOQGDEXmJztSFNYXKbrZ9Sbvpjd4TcQXQ=; b=Qx2jNo6sUA7NyeexPvxqIZOs89rzf2Fc9sHSjKuht9Kjm4RfUZLVLd4czqGzsHKJwdSDU8EerjqFRgVwZxDR0WaCgZWYurnUF5RuvPHw+wT8tzqBFG9f/Cg8sFnBJ4h23Z42oFWW8jxgJbK63+PlE4yqA9texmAIA9VuUXA9HW4= 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 1604305643847109.79274852563435; Mon, 2 Nov 2020 00:27:23 -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-207-156hiSG8McKUP0Ez7A11sg-1; Mon, 02 Nov 2020 03:27:20 -0500 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 9C23C809DC6; Mon, 2 Nov 2020 08:27:14 +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 790A76EF7F; Mon, 2 Nov 2020 08:27:14 +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 454D6181A07C; Mon, 2 Nov 2020 08:27:14 +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 0A28QvBd031212 for ; Mon, 2 Nov 2020 03:26:58 -0500 Received: by smtp.corp.redhat.com (Postfix) id B9A44205EB1A; Mon, 2 Nov 2020 08:26:57 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B35B0205EB18 for ; Mon, 2 Nov 2020 08:26:54 +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-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 66C5D8007A4 for ; Mon, 2 Nov 2020 08:26:54 +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-413-PSdMRx4WN7S4gG5wHUJ5HA-1; Mon, 02 Nov 2020 03:26:52 -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-Oo3LG4zuOrudtnAcoZWpcA-6; Mon, 02 Nov 2020 09:26:49 +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:45 +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:45 +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:43 +0000 X-MC-Unique: 156hiSG8McKUP0Ez7A11sg-1 X-MC-Unique: PSdMRx4WN7S4gG5wHUJ5HA-1 X-MC-Unique: Oo3LG4zuOrudtnAcoZWpcA-6 From: Lin Ma To: libvir-list@redhat.com Subject: [libvirt] [PATCH 03/19] virsh: Add serial/parallel device name completion to console command Date: Mon, 2 Nov 2020 16:26:05 +0800 Message-ID: <20201102082621.13228-4-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: 8ff5c6b8-0ffe-4164-b2b6-08d87f0908d4 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:494 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0 X-Microsoft-Antispam-Message-Info: Q3q91OY8ykLWvHCEVP/SNzQapYUJIeroZKELN+SI6wsVdD1poPOl6FqSwMJ01j+I+BcRCAN+yW1dCorT8/P3naLvGRrzXt4zf14SBDo1U0FnCvZ86QUmz/nq9LjhoD3jH4p8P3UoswyLSLqvHjF6NKHRbz6V/wxlPx19uxgd5hueu6I09AhUG7+iK7j2KhWRtUr0SN6Fn6BaehxJSQTxP1djuiS605cGb29lza3XOffcKVZbuSd6mEghwhm/QrpzjdKLcOs7hWvGKBsFWIkSUzt3Iqw6Q3TwdkMtuQ5is/dCz3SFt7Jak87DcLOhn4BhXfX7u1HoxsQE10BUusa6qQ== 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)(6512007); DIR:OUT; SFP:1101 X-MS-Exchange-AntiSpam-MessageData: sU5GYBL/e0+jZWTbNkKo0bDRnyGw06mJNiCOREFDVYJh3xldoQyMAupScjbdsBDrGOFkELKADmWUwx3TaBx+a2ELgy6jq07G77j91o/yf8JwVf0EJFXTNjmfGe277Qt0wGmVbn5E5wL7eA09F7eZ7Ko+IoMS5Y+9L7NAZQ033aWrY7mfK1THeJ1HKK/TfHiI6T302tuFaehYV7VaYElUrPtI64mpo5cd0TfUSKF3/9WRGWmvC9abJPjSnb2T4imDzlx7Og7UETYTUtkbZX2Dfc8tqc8SnPEiispGjyABSFla6fLeNkFoyaqYTTiM53NRJvimlV5tXbwv5lM+u4xkyY+hnWO6H1tjTYYPpr850033KIWGKj7+6BFLKL8egmVAIvMt0twLppu0436q83ch1JqSQQqGKKhPVM1cR1o2oB28r8wI4mFFb4Ei+9dB8kC5CUuYUlMSP+ho9yg/ZER3KifgwnHdMqijOR05iREuqdD+HG1xTLipz0UqV0DS40Flwo67qJ5kEyeb6VM99xa/NyoqVe6Du/jNcZPiw2zg4b1sstIcxlNgLJ6pZI71KU7b2JScLProIePp4aL4PyYvooConkr/hmYG2cnVUI/3+8HLbam70O2Cxo04KopFCquMEBLcwHznl8UMiZQkBG1tdQ== X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8ff5c6b8-0ffe-4164-b2b6-08d87f0908d4 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:45.6253 (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: hhUnuk7KMpArDI5kP2e1LZ/vwmbH4f3smoBR2arOx9oFesktRbD7t9/4skQIlAIW 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.4 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 0A28QvBd031212 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" Signed-off-by: Lin Ma --- tools/virsh-completer-domain.c | 54 ++++++++++++++++++++++++++++++++++ tools/virsh-completer-domain.h | 4 +++ tools/virsh-domain.c | 1 + 3 files changed, 59 insertions(+) diff --git a/tools/virsh-completer-domain.c b/tools/virsh-completer-domain.c index 6f67c91746..ab81a0dcfe 100644 --- a/tools/virsh-completer-domain.c +++ b/tools/virsh-completer-domain.c @@ -617,3 +617,57 @@ virshDomainVcpulistViaAgentCompleter(vshControl *ctl, virshDomainFree(dom); return ret; } + +char ** +virshDomainConsoleCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags) +{ + virshControlPtr priv =3D ctl->privData; + g_autoptr(xmlDoc) xmldoc =3D NULL; + g_autoptr(xmlXPathContext) ctxt =3D NULL; + int nserials, nparallels, offset =3D 0, head; + g_autofree xmlNodePtr *serials =3D NULL; + g_autofree xmlNodePtr *parallels =3D NULL; + size_t i; + VIR_AUTOSTRINGLIST tmp =3D NULL; + + virCheckFlags(0, NULL); + + if (!priv->conn || virConnectIsAlive(priv->conn) <=3D 0) + return NULL; + + if (virshDomainGetXML(ctl, cmd, 0, &xmldoc, &ctxt) < 0) + return NULL; + + nserials =3D virXPathNodeSet("./devices/serial", ctxt, &serials); + if (nserials < 0) + return NULL; + + nparallels =3D virXPathNodeSet("./devices/parallel", ctxt, ¶llels); + if (nparallels < 0) + return NULL; + + tmp =3D g_new0(char *, nserials + nparallels + 1); + + for (i =3D 0; i < nserials; i++) { + ctxt->node =3D serials[i]; + if (STRNEQ(virXPathString("string(./@type)", ctxt), "pty")) + offset +=3D 1; + else + tmp[i - offset] =3D virXPathString("string(./alias/@name)", ct= xt); + } + + head =3D i - offset; + offset =3D 0; + + for (i =3D 0; i < nparallels; i++) { + ctxt->node =3D parallels[i]; + if (STRNEQ(virXPathString("string(./@type)", ctxt), "pty")) + offset +=3D 1; + else + tmp[head + i - offset] =3D virXPathString("string(./alias/@nam= e)", ctxt); + } + + return g_steal_pointer(&tmp); +} diff --git a/tools/virsh-completer-domain.h b/tools/virsh-completer-domain.h index d5021f6aa6..02fea2fe94 100644 --- a/tools/virsh-completer-domain.h +++ b/tools/virsh-completer-domain.h @@ -94,3 +94,7 @@ char ** virshDomainCpulistCompleter(vshControl *ctl, char ** virshDomainVcpulistViaAgentCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); + +char ** virshDomainConsoleCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index c051b047ea..7189c8c826 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -2960,6 +2960,7 @@ static const vshCmdOptDef opts_console[] =3D { VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name =3D "devname", /* sc_prohibit_devname */ .type =3D VSH_OT_STRING, + .completer =3D virshDomainConsoleCompleter, .help =3D N_("character device name") }, {.name =3D "force", --=20 2.26.0