From nobody Sun Feb 8 21:06:41 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=1563526139; cv=none; d=zoho.com; s=zohoarc; b=aL+pptZ6zknGszENBusowkWSqRpwfgJh+rPBS1IliMXTfFQA82Xxifvu2D4xm44Jd5xK1vx2M0EPIa3OMMqsNZ9uoD+AOow0/dDC3Ai2gHZjWiuMMAzqiqLUx8wsezLZgc682f2JXYbCbbPT3x/EMGuWRJkXfkbm9iai6+ONumM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563526139; 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=iQNx4Lc6jebhHSjyjNSXfWRoZc0kpS8gtJ2mS1o9g5U=; b=MbedlaxFhFR/4UWsfF7BI7/Y457Gtm50Mj6qdocslW5JEpfZtTm+fldvc+sa+u4eFdA0JRyB9ntMoZEBR0w6gOUurpLMQiJOaSqo1vXkbJsfqv2+5zd3JkSbzTqZUr1HKcsYpMz9HHjgkTHbL8e+/pmjlyiz6rTQj7RiaW6Q2vU= 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 1563526139031237.186090210835; Fri, 19 Jul 2019 01:48:59 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4615580F7C; Fri, 19 Jul 2019 08:48:57 +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 C795060CD7; Fri, 19 Jul 2019 08:48:56 +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 7BB4841F63; Fri, 19 Jul 2019 08:48:56 +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 x6J8mkUf005207 for ; Fri, 19 Jul 2019 04:48:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id E89416134E; Fri, 19 Jul 2019 08:48:46 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 72AB860126 for ; Fri, 19 Jul 2019 08:48:46 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Fri, 19 Jul 2019 10:48:29 +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 05/14] tools: Separate storage volume 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 19 Jul 2019 08:48:57 +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 storage volumes (e.g. they complete various storage volume aspects) into virsh-completer-volume.c Signed-off-by: Michal Privoznik --- tools/Makefile.am | 1 + tools/virsh-completer-volume.c | 73 ++++++++++++++++++++++++++++++++++ tools/virsh-completer-volume.h | 28 +++++++++++++ tools/virsh-completer.c | 47 ---------------------- tools/virsh-completer.h | 5 +-- 5 files changed, 103 insertions(+), 51 deletions(-) create mode 100644 tools/virsh-completer-volume.c create mode 100644 tools/virsh-completer-volume.h diff --git a/tools/Makefile.am b/tools/Makefile.am index 9724e8de53..583ba2f395 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-pool.c virsh-completer-pool.h \ + virsh-completer-volume.c virsh-completer-volume.h \ virsh-console.c virsh-console.h \ virsh-domain.c virsh-domain.h \ virsh-domain-monitor.c virsh-domain-monitor.h \ diff --git a/tools/virsh-completer-volume.c b/tools/virsh-completer-volume.c new file mode 100644 index 0000000000..2df0077d7a --- /dev/null +++ b/tools/virsh-completer-volume.c @@ -0,0 +1,73 @@ +/* + * virsh-completer-volume.c: virsh completer callbacks related to volumes + * + * 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-volume.h" +#include "viralloc.h" +#include "virsh-pool.h" +#include "virsh.h" +#include "virstring.h" + +char ** +virshStorageVolNameCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags) +{ + virshControlPtr priv =3D ctl->privData; + virStoragePoolPtr pool =3D NULL; + virStorageVolPtr *vols =3D NULL; + int rc; + int nvols =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 (!(pool =3D virshCommandOptPool(ctl, cmd, "pool", NULL))) + return NULL; + + if ((rc =3D virStoragePoolListAllVolumes(pool, &vols, flags)) < 0) + goto cleanup; + nvols =3D rc; + + if (VIR_ALLOC_N(tmp, nvols + 1) < 0) + goto cleanup; + + for (i =3D 0; i < nvols; i++) { + const char *name =3D virStorageVolGetName(vols[i]); + + if (VIR_STRDUP(tmp[i], name) < 0) + goto cleanup; + } + + VIR_STEAL_PTR(ret, tmp); + + cleanup: + virStoragePoolFree(pool); + for (i =3D 0; i < nvols; i++) + virStorageVolFree(vols[i]); + VIR_FREE(vols); + return ret; +} diff --git a/tools/virsh-completer-volume.h b/tools/virsh-completer-volume.h new file mode 100644 index 0000000000..6591e13fdf --- /dev/null +++ b/tools/virsh-completer-volume.h @@ -0,0 +1,28 @@ +/* + * virsh-completer-volume.h: virsh completer callbacks related to volumes + * + * 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 ** virshStorageVolNameCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index b227b43290..29bccadc80 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -143,53 +143,6 @@ virshCommaStringListComplete(const char *input, } =20 =20 -char ** -virshStorageVolNameCompleter(vshControl *ctl, - const vshCmd *cmd, - unsigned int flags) -{ - virshControlPtr priv =3D ctl->privData; - virStoragePoolPtr pool =3D NULL; - virStorageVolPtr *vols =3D NULL; - int rc; - int nvols =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 (!(pool =3D virshCommandOptPool(ctl, cmd, "pool", NULL))) - return NULL; - - if ((rc =3D virStoragePoolListAllVolumes(pool, &vols, flags)) < 0) - goto cleanup; - nvols =3D rc; - - if (VIR_ALLOC_N(tmp, nvols + 1) < 0) - goto cleanup; - - for (i =3D 0; i < nvols; i++) { - const char *name =3D virStorageVolGetName(vols[i]); - - if (VIR_STRDUP(tmp[i], name) < 0) - goto cleanup; - } - - VIR_STEAL_PTR(ret, tmp); - - cleanup: - virStoragePoolFree(pool); - for (i =3D 0; i < nvols; i++) - virStorageVolFree(vols[i]); - VIR_FREE(vols); - return ret; -} - - char ** virshInterfaceNameCompleter(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED, diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h index aeb13da622..8da6f485e7 100644 --- a/tools/virsh-completer.h +++ b/tools/virsh-completer.h @@ -24,14 +24,11 @@ =20 #include "virsh-completer-domain.h" #include "virsh-completer-pool.h" +#include "virsh-completer-volume.h" =20 char ** virshCommaStringListComplete(const char *input, const char **options); =20 -char ** virshStorageVolNameCompleter(vshControl *ctl, - const vshCmd *cmd, - unsigned int flags); - char ** virshInterfaceNameCompleter(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