From nobody Thu May 15 04:06:02 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1515767953582563.5408290281532; Fri, 12 Jan 2018 06:39:13 -0800 (PST) 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 mx1.redhat.com (Postfix) with ESMTPS id A85E65AFC4; Fri, 12 Jan 2018 14:39:01 +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 C0D1117DEC; Fri, 12 Jan 2018 14: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 1F4E018033DA; Fri, 12 Jan 2018 14:38:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w0CEc4bK025653 for ; Fri, 12 Jan 2018 09:38:06 -0500 Received: by smtp.corp.redhat.com (Postfix) id 175EA17B73; Fri, 12 Jan 2018 14:38:04 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8E5ED5D6A6 for ; Fri, 12 Jan 2018 14:38:03 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Fri, 12 Jan 2018 15:37:39 +0100 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 5/8] virsh: Introduce virshNodeDeviceNameCompleter 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 12 Jan 2018 14:39:12 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Yet again, we don't need listing by device capabilities, so flags are unused. Signed-off-by: Michal Privoznik Reviewed-by: John Ferlan --- tools/virsh-completer.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ tools/virsh-completer.h | 4 ++++ tools/virsh-nodedev.c | 16 +++++++++++----- 3 files changed, 60 insertions(+), 5 deletions(-) diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index 2c0d4f640..c50143142 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -348,3 +348,48 @@ virshNetworkNameCompleter(vshControl *ctl, VIR_FREE(ret); return NULL; } + + +char ** +virshNodeDeviceNameCompleter(vshControl *ctl, + const vshCmd *cmd ATTRIBUTE_UNUSED, + unsigned int flags) +{ + virshControlPtr priv =3D ctl->privData; + virNodeDevicePtr *devs =3D NULL; + int ndevs =3D 0; + size_t i =3D 0; + char **ret =3D NULL; + + virCheckFlags(0, NULL); + + if (!priv->conn || virConnectIsAlive(priv->conn) <=3D 0) + return NULL; + + if ((ndevs =3D virConnectListAllNodeDevices(priv->conn, &devs, flags))= < 0) + return NULL; + + if (VIR_ALLOC_N(ret, ndevs + 1) < 0) + goto error; + + for (i =3D 0; i < ndevs; i++) { + const char *name =3D virNodeDeviceGetName(devs[i]); + + if (VIR_STRDUP(ret[i], name) < 0) + goto error; + + virNodeDeviceFree(devs[i]); + } + VIR_FREE(devs); + + return ret; + + error: + for (; i < ndevs; i++) + virNodeDeviceFree(devs[i]); + VIR_FREE(devs); + for (i =3D 0; i < ndevs; i++) + VIR_FREE(ret[i]); + VIR_FREE(ret); + return NULL; +} diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h index 20ba4cb55..19fa2113d 100644 --- a/tools/virsh-completer.h +++ b/tools/virsh-completer.h @@ -54,4 +54,8 @@ char ** virshNetworkNameCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); =20 +char ** virshNodeDeviceNameCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); + #endif diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index c7ef6bfde..d25fe0e09 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -109,7 +109,8 @@ static const vshCmdOptDef opts_node_device_destroy[] = =3D { {.name =3D "device", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, - .help =3D N_("device name or wwn pair in 'wwnn,wwpn' format") + .help =3D N_("device name or wwn pair in 'wwnn,wwpn' format"), + .completer =3D virshNodeDeviceNameCompleter, }, {.name =3D NULL} }; @@ -534,6 +535,7 @@ static const vshCmdOptDef opts_node_device_dumpxml[] = =3D { .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, .help =3D N_("device name or wwn pair in 'wwnn,wwpn' format"), + .completer =3D virshNodeDeviceNameCompleter, }, {.name =3D NULL} }; @@ -604,7 +606,8 @@ static const vshCmdOptDef opts_node_device_detach[] =3D= { {.name =3D "device", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, - .help =3D N_("device key") + .help =3D N_("device key"), + .completer =3D virshNodeDeviceNameCompleter, }, {.name =3D "driver", .type =3D VSH_OT_STRING, @@ -670,7 +673,8 @@ static const vshCmdOptDef opts_node_device_reattach[] = =3D { {.name =3D "device", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, - .help =3D N_("device key") + .help =3D N_("device key"), + .completer =3D virshNodeDeviceNameCompleter, }, {.name =3D NULL} }; @@ -720,7 +724,8 @@ static const vshCmdOptDef opts_node_device_reset[] =3D { {.name =3D "device", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, - .help =3D N_("device key") + .help =3D N_("device key"), + .completer =3D virshNodeDeviceNameCompleter, }, {.name =3D NULL} }; @@ -866,7 +871,8 @@ static const vshCmdInfo info_node_device_event[] =3D { static const vshCmdOptDef opts_node_device_event[] =3D { {.name =3D "device", .type =3D VSH_OT_STRING, - .help =3D N_("filter by node device name") + .help =3D N_("filter by node device name"), + .completer =3D virshNodeDeviceNameCompleter, }, {.name =3D "event", .type =3D VSH_OT_STRING, --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list