From nobody Sun Feb 8 02:08:40 2026 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1563526154; cv=none; d=zoho.com; s=zohoarc; b=fUKHAtthLraU9M3u/mkEC6TULoAOCDnDewOHARK+IRUCzYY8uFcG9t8dzxdDxgImksKmW7Hf/+5t0k/UuEMW2/R9lKq13gOkpQH3iqY6swtX20m8G4PVzOcBQUNsuaODHRkPA+5hzzTHCB4CNDV+Gl5RP8AFN0dqxKp3PqMsVlk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563526154; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=KqTw7svrOYdtjNhzgARp8VOZf/5eCb6H05l5vwaI5dU=; b=SZSgq+EZpj3Ba892isQBhO3SiIqgzzrw2Biolw/faVBVyARNXY9SFd4m/veRJvAalGyFGmeHsllDymRFjzVgHywF4TSMWiVv8pnjiTTx7Uo4tB+MtEVHmBQO+QixXFz6OVWJ3rfoliZXQxn0DThPAZ/ST9WqWyFK4eMpmwNGtXw= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1563526153999787.394842140489; Fri, 19 Jul 2019 01:49:13 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E28FCA3EA3; Fri, 19 Jul 2019 08:49:11 +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 B577F1838E; Fri, 19 Jul 2019 08:49:11 +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 6FA3418045DA; Fri, 19 Jul 2019 08:49:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x6J8mmdN005232 for ; Fri, 19 Jul 2019 04:48:48 -0400 Received: by smtp.corp.redhat.com (Postfix) id 83F3C60126; Fri, 19 Jul 2019 08:48:48 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0F54761369 for ; Fri, 19 Jul 2019 08:48:47 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Fri, 19 Jul 2019 10:48:31 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 07/14] tools: Separate network related completers into a file 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: , 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 19 Jul 2019 08:49:12 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Mixing all completers in one file does not support maintainability. Separate those completers which relate to networks (e.g. they complete various network aspects) into virsh-completer-network.c Signed-off-by: Michal Privoznik --- tools/Makefile.am | 1 + tools/virsh-completer-network.c | 145 ++++++++++++++++++++++++++++++++ tools/virsh-completer-network.h | 35 ++++++++ tools/virsh-completer.c | 119 -------------------------- tools/virsh-completer.h | 13 +-- 5 files changed, 182 insertions(+), 131 deletions(-) create mode 100644 tools/virsh-completer-network.c create mode 100644 tools/virsh-completer-network.h diff --git a/tools/Makefile.am b/tools/Makefile.am index a86587f200..79e2ea7cd9 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -219,6 +219,7 @@ virsh_SOURCES =3D \ virsh-completer.c virsh-completer.h \ virsh-completer-domain.c virsh-completer-domain.h \ virsh-completer-interface.c virsh-completer-interface.h \ + virsh-completer-network.c virsh-completer-network.h \ virsh-completer-pool.c virsh-completer-pool.h \ virsh-completer-volume.c virsh-completer-volume.h \ virsh-console.c virsh-console.h \ diff --git a/tools/virsh-completer-network.c b/tools/virsh-completer-networ= k.c new file mode 100644 index 0000000000..6f92780feb --- /dev/null +++ b/tools/virsh-completer-network.c @@ -0,0 +1,145 @@ +/* + * virsh-completer-network.c: virsh completer callbacks related to networks + * + * Copyright (C) 2019 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#include + +#include "virsh-completer-network.h" +#include "viralloc.h" +#include "virsh-network.h" +#include "virsh.h" +#include "virstring.h" + +char ** +virshNetworkNameCompleter(vshControl *ctl, + const vshCmd *cmd ATTRIBUTE_UNUSED, + unsigned int flags) +{ + virshControlPtr priv =3D ctl->privData; + virNetworkPtr *nets =3D NULL; + int nnets =3D 0; + size_t i =3D 0; + char **ret =3D NULL; + VIR_AUTOSTRINGLIST tmp =3D NULL; + + virCheckFlags(VIR_CONNECT_LIST_NETWORKS_INACTIVE | + VIR_CONNECT_LIST_NETWORKS_ACTIVE | + VIR_CONNECT_LIST_NETWORKS_PERSISTENT, + NULL); + + if (!priv->conn || virConnectIsAlive(priv->conn) <=3D 0) + return NULL; + + if ((nnets =3D virConnectListAllNetworks(priv->conn, &nets, flags)) < = 0) + return NULL; + + if (VIR_ALLOC_N(tmp, nnets + 1) < 0) + goto cleanup; + + for (i =3D 0; i < nnets; i++) { + const char *name =3D virNetworkGetName(nets[i]); + + if (VIR_STRDUP(tmp[i], name) < 0) + goto cleanup; + } + + VIR_STEAL_PTR(ret, tmp); + + cleanup: + for (i =3D 0; i < nnets; i++) + virNetworkFree(nets[i]); + VIR_FREE(nets); + return ret; +} + + +char ** +virshNetworkEventNameCompleter(vshControl *ctl ATTRIBUTE_UNUSED, + const vshCmd *cmd ATTRIBUTE_UNUSED, + unsigned int flags) +{ + size_t i =3D 0; + char **ret =3D NULL; + VIR_AUTOSTRINGLIST tmp =3D NULL; + + virCheckFlags(0, NULL); + + if (VIR_ALLOC_N(tmp, VIR_NETWORK_EVENT_ID_LAST + 1) < 0) + goto cleanup; + + for (i =3D 0; i < VIR_NETWORK_EVENT_ID_LAST; i++) { + if (VIR_STRDUP(tmp[i], virshNetworkEventCallbacks[i].name) < 0) + goto cleanup; + } + + VIR_STEAL_PTR(ret, tmp); + + cleanup: + return ret; +} + + +char ** +virshNetworkPortUUIDCompleter(vshControl *ctl, + const vshCmd *cmd ATTRIBUTE_UNUSED, + unsigned int flags) +{ + virshControlPtr priv =3D ctl->privData; + virNetworkPtr net =3D NULL; + virNetworkPortPtr *ports =3D NULL; + int nports =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 (!(net =3D virshCommandOptNetwork(ctl, cmd, NULL))) + return false; + + if ((nports =3D virNetworkListAllPorts(net, &ports, flags)) < 0) + return NULL; + + if (VIR_ALLOC_N(ret, nports + 1) < 0) + goto error; + + for (i =3D 0; i < nports; i++) { + char uuid[VIR_UUID_STRING_BUFLEN]; + + if (virNetworkPortGetUUIDString(ports[i], uuid) < 0 || + VIR_STRDUP(ret[i], uuid) < 0) + goto error; + + virNetworkPortFree(ports[i]); + } + VIR_FREE(ports); + + return ret; + + error: + for (; i < nports; i++) + virNetworkPortFree(ports[i]); + VIR_FREE(ports); + for (i =3D 0; i < nports; i++) + VIR_FREE(ret[i]); + VIR_FREE(ret); + return NULL; +} diff --git a/tools/virsh-completer-network.h b/tools/virsh-completer-networ= k.h new file mode 100644 index 0000000000..e317e483c1 --- /dev/null +++ b/tools/virsh-completer-network.h @@ -0,0 +1,35 @@ +/* + * virsh-completer-network.h: virsh completer callbacks related to networks + * + * Copyright (C) 2019 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#pragma once + +#include "vsh.h" + +char ** virshNetworkNameCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); + +char ** virshNetworkEventNameCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); + +char ** virshNetworkPortUUIDCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index 62df752962..108596e24d 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -143,125 +143,6 @@ virshCommaStringListComplete(const char *input, } =20 =20 -char ** -virshNetworkNameCompleter(vshControl *ctl, - const vshCmd *cmd ATTRIBUTE_UNUSED, - unsigned int flags) -{ - virshControlPtr priv =3D ctl->privData; - virNetworkPtr *nets =3D NULL; - int nnets =3D 0; - size_t i =3D 0; - char **ret =3D NULL; - VIR_AUTOSTRINGLIST tmp =3D NULL; - - virCheckFlags(VIR_CONNECT_LIST_NETWORKS_INACTIVE | - VIR_CONNECT_LIST_NETWORKS_ACTIVE | - VIR_CONNECT_LIST_NETWORKS_PERSISTENT, - NULL); - - if (!priv->conn || virConnectIsAlive(priv->conn) <=3D 0) - return NULL; - - if ((nnets =3D virConnectListAllNetworks(priv->conn, &nets, flags)) < = 0) - return NULL; - - if (VIR_ALLOC_N(tmp, nnets + 1) < 0) - goto cleanup; - - for (i =3D 0; i < nnets; i++) { - const char *name =3D virNetworkGetName(nets[i]); - - if (VIR_STRDUP(tmp[i], name) < 0) - goto cleanup; - } - - VIR_STEAL_PTR(ret, tmp); - - cleanup: - for (i =3D 0; i < nnets; i++) - virNetworkFree(nets[i]); - VIR_FREE(nets); - return ret; -} - - -char ** -virshNetworkEventNameCompleter(vshControl *ctl ATTRIBUTE_UNUSED, - const vshCmd *cmd ATTRIBUTE_UNUSED, - unsigned int flags) -{ - size_t i =3D 0; - char **ret =3D NULL; - VIR_AUTOSTRINGLIST tmp =3D NULL; - - virCheckFlags(0, NULL); - - if (VIR_ALLOC_N(tmp, VIR_NETWORK_EVENT_ID_LAST + 1) < 0) - goto cleanup; - - for (i =3D 0; i < VIR_NETWORK_EVENT_ID_LAST; i++) { - if (VIR_STRDUP(tmp[i], virshNetworkEventCallbacks[i].name) < 0) - goto cleanup; - } - - VIR_STEAL_PTR(ret, tmp); - - cleanup: - return ret; -} - - -char ** -virshNetworkPortUUIDCompleter(vshControl *ctl, - const vshCmd *cmd ATTRIBUTE_UNUSED, - unsigned int flags) -{ - virshControlPtr priv =3D ctl->privData; - virNetworkPtr net =3D NULL; - virNetworkPortPtr *ports =3D NULL; - int nports =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 (!(net =3D virshCommandOptNetwork(ctl, cmd, NULL))) - return false; - - if ((nports =3D virNetworkListAllPorts(net, &ports, flags)) < 0) - return NULL; - - if (VIR_ALLOC_N(ret, nports + 1) < 0) - goto error; - - for (i =3D 0; i < nports; i++) { - char uuid[VIR_UUID_STRING_BUFLEN]; - - if (virNetworkPortGetUUIDString(ports[i], uuid) < 0 || - VIR_STRDUP(ret[i], uuid) < 0) - goto error; - - virNetworkPortFree(ports[i]); - } - VIR_FREE(ports); - - return ret; - - error: - for (; i < nports; i++) - virNetworkPortFree(ports[i]); - VIR_FREE(ports); - for (i =3D 0; i < nports; i++) - VIR_FREE(ret[i]); - VIR_FREE(ret); - return NULL; -} - - char ** virshNodeDeviceNameCompleter(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED, diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h index 6170a87757..d4784105c1 100644 --- a/tools/virsh-completer.h +++ b/tools/virsh-completer.h @@ -24,24 +24,13 @@ =20 #include "virsh-completer-domain.h" #include "virsh-completer-interface.h" +#include "virsh-completer-network.h" #include "virsh-completer-pool.h" #include "virsh-completer-volume.h" =20 char ** virshCommaStringListComplete(const char *input, const char **options); =20 -char ** virshNetworkNameCompleter(vshControl *ctl, - const vshCmd *cmd, - unsigned int flags); - -char ** virshNetworkEventNameCompleter(vshControl *ctl, - const vshCmd *cmd, - unsigned int flags); - -char ** virshNetworkPortUUIDCompleter(vshControl *ctl, - const vshCmd *cmd, - unsigned int flags); - char ** virshNodeDeviceNameCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list