From nobody Sun Feb 8 14:59:28 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=1563526142; cv=none; d=zoho.com; s=zohoarc; b=M9/sRYElMCFZylyYRdJKABqaC4rbwqr2juju5xAwph3WkjCd/bA2sJ7ZmapwLftBnu3Bp5uw2HEjSrA3KC6tpM1QWhb8lcf05Q7toBPTDWrMBo6E/3gzq4n3UuuOF6+fmhnitq0esAauqOHmjgLSkdsdTks48tBhATjzWGmoi3Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563526142; 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=e6yfC3bFROTIWEdBM3iqstdVyBwlQsOLV8nNF1DZtS8=; b=jYjUju+TC3cE2FiLdBIbt6LaL0nCcWU1SuYxp0e2pLR2ELt1FV6HqW0AqXBZwAz3fvxjLdeyoqm6o3FTQYn/lRq/3qqloRZaJlKT7NYOId7YTDEvSBgN9ulAe6HHZMEv5N4FD09rwarTxZxrGJAVR+BQF+13a3yx+rsTLnyv6d0= 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 156352614281139.996647695903334; Fri, 19 Jul 2019 01:49:02 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id A733F3179B49; Fri, 19 Jul 2019 08:49:00 +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 7041B620A5; Fri, 19 Jul 2019 08:49:00 +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 2A3AE264C8; Fri, 19 Jul 2019 08:49:00 +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 x6J8mnUs005242 for ; Fri, 19 Jul 2019 04:48:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id 500A8601A9; Fri, 19 Jul 2019 08:48:49 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id CFAF060126 for ; Fri, 19 Jul 2019 08:48:48 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Fri, 19 Jul 2019 10:48:32 +0200 Message-Id: <03da6f88ce738986a8927cbc157c8fd1ff2ce96f.1563525985.git.mprivozn@redhat.com> 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 08/14] tools: Separate nodedev 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Fri, 19 Jul 2019 08:49:01 +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 nodedev (e.g. they complete various nodedev aspects) into virsh-completer-nodedev.c Signed-off-by: Michal Privoznik --- tools/Makefile.am | 1 + tools/virsh-completer-nodedev.c | 117 ++++++++++++++++++++++++++++++++ tools/virsh-completer-nodedev.h | 35 ++++++++++ tools/virsh-completer.c | 90 ------------------------ tools/virsh-completer.h | 13 +--- 5 files changed, 154 insertions(+), 102 deletions(-) create mode 100644 tools/virsh-completer-nodedev.c create mode 100644 tools/virsh-completer-nodedev.h diff --git a/tools/Makefile.am b/tools/Makefile.am index 79e2ea7cd9..22f476a1c2 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -220,6 +220,7 @@ virsh_SOURCES =3D \ 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-nodedev.c virsh-completer-nodedev.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-nodedev.c b/tools/virsh-completer-nodede= v.c new file mode 100644 index 0000000000..36f38acd57 --- /dev/null +++ b/tools/virsh-completer-nodedev.c @@ -0,0 +1,117 @@ +/* + * virsh-completer-nodedev.c: virsh completer callbacks related to nodedev + * + * 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-nodedev.h" +#include "conf/node_device_conf.h" +#include "viralloc.h" +#include "virsh-nodedev.h" +#include "virsh.h" +#include "virstring.h" + +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; + VIR_AUTOSTRINGLIST tmp =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(tmp, ndevs + 1) < 0) + goto cleanup; + + for (i =3D 0; i < ndevs; i++) { + const char *name =3D virNodeDeviceGetName(devs[i]); + + if (VIR_STRDUP(tmp[i], name) < 0) + goto cleanup; + } + + VIR_STEAL_PTR(ret, tmp); + + cleanup: + for (i =3D 0; i < ndevs; i++) + virNodeDeviceFree(devs[i]); + VIR_FREE(devs); + return ret; +} + + +char ** +virshNodeDeviceEventNameCompleter(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_NODE_DEVICE_EVENT_ID_LAST + 1) < 0) + return NULL; + + for (i =3D 0; i < VIR_NODE_DEVICE_EVENT_ID_LAST; i++) { + if (VIR_STRDUP(tmp[i], virshNodeDeviceEventCallbacks[i].name) < 0) + return NULL; + } + + VIR_STEAL_PTR(ret, tmp); + return ret; +} + + +char ** +virshNodeDeviceCapabilityNameCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags) +{ + VIR_AUTOSTRINGLIST tmp =3D NULL; + const char *cap_str =3D NULL; + size_t i =3D 0; + + virCheckFlags(0, NULL); + + if (vshCommandOptStringQuiet(ctl, cmd, "cap", &cap_str) < 0) + return NULL; + + if (VIR_ALLOC_N(tmp, VIR_NODE_DEV_CAP_LAST + 1) < 0) + return NULL; + + for (i =3D 0; i < VIR_NODE_DEV_CAP_LAST; i++) { + if (VIR_STRDUP(tmp[i], virNodeDevCapTypeToString(i)) < 0) + return NULL; + } + + return virshCommaStringListComplete(cap_str, (const char **)tmp); +} diff --git a/tools/virsh-completer-nodedev.h b/tools/virsh-completer-nodede= v.h new file mode 100644 index 0000000000..45c0b73c8c --- /dev/null +++ b/tools/virsh-completer-nodedev.h @@ -0,0 +1,35 @@ +/* + * virsh-completer-nodedev.h: virsh completer callbacks related to nodedev + * + * 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 ** virshNodeDeviceNameCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); + +char ** virshNodeDeviceEventNameCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); + +char ** virshNodeDeviceCapabilityNameCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index 108596e24d..0b99b3d578 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -143,46 +143,6 @@ virshCommaStringListComplete(const char *input, } =20 =20 -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; - VIR_AUTOSTRINGLIST tmp =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(tmp, ndevs + 1) < 0) - goto cleanup; - - for (i =3D 0; i < ndevs; i++) { - const char *name =3D virNodeDeviceGetName(devs[i]); - - if (VIR_STRDUP(tmp[i], name) < 0) - goto cleanup; - } - - VIR_STEAL_PTR(ret, tmp); - - cleanup: - for (i =3D 0; i < ndevs; i++) - virNodeDeviceFree(devs[i]); - VIR_FREE(devs); - return ret; -} - - char ** virshNWFilterNameCompleter(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED, @@ -452,56 +412,6 @@ virshSecretEventNameCompleter(vshControl *ctl ATTRIBUT= E_UNUSED, } =20 =20 -char ** -virshNodeDeviceEventNameCompleter(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_NODE_DEVICE_EVENT_ID_LAST + 1) < 0) - return NULL; - - for (i =3D 0; i < VIR_NODE_DEVICE_EVENT_ID_LAST; i++) { - if (VIR_STRDUP(tmp[i], virshNodeDeviceEventCallbacks[i].name) < 0) - return NULL; - } - - VIR_STEAL_PTR(ret, tmp); - return ret; -} - - -char ** -virshNodeDeviceCapabilityNameCompleter(vshControl *ctl, - const vshCmd *cmd, - unsigned int flags) -{ - VIR_AUTOSTRINGLIST tmp =3D NULL; - const char *cap_str =3D NULL; - size_t i =3D 0; - - virCheckFlags(0, NULL); - - if (vshCommandOptStringQuiet(ctl, cmd, "cap", &cap_str) < 0) - return NULL; - - if (VIR_ALLOC_N(tmp, VIR_NODE_DEV_CAP_LAST + 1) < 0) - return NULL; - - for (i =3D 0; i < VIR_NODE_DEV_CAP_LAST; i++) { - if (VIR_STRDUP(tmp[i], virNodeDevCapTypeToString(i)) < 0) - return NULL; - } - - return virshCommaStringListComplete(cap_str, (const char **)tmp); -} - - char ** virshCellnoCompleter(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED, diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h index d4784105c1..39896c13c5 100644 --- a/tools/virsh-completer.h +++ b/tools/virsh-completer.h @@ -25,16 +25,13 @@ #include "virsh-completer-domain.h" #include "virsh-completer-interface.h" #include "virsh-completer-network.h" +#include "virsh-completer-nodedev.h" #include "virsh-completer-pool.h" #include "virsh-completer-volume.h" =20 char ** virshCommaStringListComplete(const char *input, const char **options); =20 -char ** virshNodeDeviceNameCompleter(vshControl *ctl, - const vshCmd *cmd, - unsigned int flags); - char ** virshNWFilterNameCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); @@ -59,14 +56,6 @@ char ** virshSecretEventNameCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); =20 -char ** virshNodeDeviceEventNameCompleter(vshControl *ctl, - const vshCmd *cmd, - unsigned int flags); - -char ** virshNodeDeviceCapabilityNameCompleter(vshControl *ctl, - const vshCmd *cmd, - unsigned int flags); - char ** virshCellnoCompleter(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