From nobody Sun May 5 20:53:19 2024 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=1563526138; cv=none; d=zoho.com; s=zohoarc; b=j3L5utRtKkJa4DOVoKjrRnu++cYDhIHgClUSzyjav+qK4LgPKiEp5EzEgwG9++rnF+CUI91OnNOoqGYxieoA34xMtb3HNBEoLnQho3usQQmE9orVflKfx4uiOseRjviUz3q3LJgGeDVv9tx24EMuBzBSz1JMQqIYrONmNbOxZfw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563526138; 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=Rj34uCYBL03eKqYGJ6PkmdHn2WDkHwdsuSOdcvhydPQ=; b=Bnd1oHlC4PJwSW7rzoeYWBrgjSflHokLC5QwqD5jfY65+kzHxN9y5ldIu5dKYzVEtBXoChe5A0nAs7YtyuKFyPIInhuxFwJJ42RpYyEVeUhCaRzITWC3wGu3hx3O9G15K9RFZp/ApdeF+ZTOuNFGQUlflc+bOlm2jYfR1DdyLrQ= 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 15635261388245.607079439211361; Fri, 19 Jul 2019 01:48:58 -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 F24818831E; Fri, 19 Jul 2019 08:48:56 +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 C24F06136A; 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 7B8671800208; 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 x6J8mhS4005175 for ; Fri, 19 Jul 2019 04:48:43 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9D83660126; Fri, 19 Jul 2019 08:48:43 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2976461376 for ; Fri, 19 Jul 2019 08:48:43 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Fri, 19 Jul 2019 10:48:25 +0200 Message-Id: <079406baf747eafc12bacd71f0aeb893768a29a3.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 01/14] tools: s/Nodedev/NodeDevice/ 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.28]); Fri, 19 Jul 2019 08:48:57 +0000 (UTC) Content-Type: text/plain; charset="utf-8" The proper name is [vir|virsh]NodeDevice* and not Nodedev. Fortunately, there are only handful of offenders. Signed-off-by: Michal Privoznik --- tools/virsh-completer.c | 14 +++++++------- tools/virsh-completer.h | 12 ++++++------ tools/virsh-nodedev.c | 16 ++++++++-------- tools/virsh-nodedev.h | 6 +++--- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index 37f946d4b6..63e2fe17e6 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -953,9 +953,9 @@ virshDomainInterfaceStateCompleter(vshControl *ctl, =20 =20 char ** -virshNodedevEventNameCompleter(vshControl *ctl ATTRIBUTE_UNUSED, - const vshCmd *cmd ATTRIBUTE_UNUSED, - unsigned int flags) +virshNodeDeviceEventNameCompleter(vshControl *ctl ATTRIBUTE_UNUSED, + const vshCmd *cmd ATTRIBUTE_UNUSED, + unsigned int flags) { size_t i =3D 0; char **ret =3D NULL; @@ -967,7 +967,7 @@ virshNodedevEventNameCompleter(vshControl *ctl ATTRIBUT= E_UNUSED, return NULL; =20 for (i =3D 0; i < VIR_NODE_DEVICE_EVENT_ID_LAST; i++) { - if (VIR_STRDUP(tmp[i], virshNodedevEventCallbacks[i].name) < 0) + if (VIR_STRDUP(tmp[i], virshNodeDeviceEventCallbacks[i].name) < 0) return NULL; } =20 @@ -977,9 +977,9 @@ virshNodedevEventNameCompleter(vshControl *ctl ATTRIBUT= E_UNUSED, =20 =20 char ** -virshNodedevCapabilityNameCompleter(vshControl *ctl, - const vshCmd *cmd, - unsigned int flags) +virshNodeDeviceCapabilityNameCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags) { VIR_AUTOSTRINGLIST tmp =3D NULL; const char *cap_str =3D NULL; diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h index cb7aafcc8c..1b4694d44d 100644 --- a/tools/virsh-completer.h +++ b/tools/virsh-completer.h @@ -102,13 +102,13 @@ char ** virshDomainInterfaceStateCompleter(vshControl= *ctl, const vshCmd *cmd, unsigned int flags); =20 -char ** virshNodedevEventNameCompleter(vshControl *ctl, - const vshCmd *cmd, - unsigned int flags); +char ** virshNodeDeviceEventNameCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); =20 -char ** virshNodedevCapabilityNameCompleter(vshControl *ctl, - const vshCmd *cmd, - unsigned int flags); +char ** virshNodeDeviceCapabilityNameCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); =20 char ** virshDomainDeviceAliasCompleter(vshControl *ctl, const vshCmd *cmd, diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index e8372a4daf..b21e2e2fcc 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -375,7 +375,7 @@ static const vshCmdOptDef opts_node_list_devices[] =3D { }, {.name =3D "cap", .type =3D VSH_OT_STRING, - .completer =3D virshNodedevCapabilityNameCompleter, + .completer =3D virshNodeDeviceCapabilityNameCompleter, .help =3D N_("capability names, separated by comma") }, {.name =3D NULL} @@ -775,7 +775,7 @@ struct virshNodeDeviceEventData { bool loop; bool timestamp; int count; - virshNodedevEventCallback *cb; + virshNodeDeviceEventCallback *cb; }; typedef struct virshNodeDeviceEventData virshNodeDeviceEventData; =20 @@ -841,12 +841,12 @@ vshEventGenericPrint(virConnectPtr conn ATTRIBUTE_UNU= SED, vshEventDone(data->ctl); } =20 -virshNodedevEventCallback virshNodedevEventCallbacks[] =3D { +virshNodeDeviceEventCallback virshNodeDeviceEventCallbacks[] =3D { { "lifecycle", VIR_NODE_DEVICE_EVENT_CALLBACK(vshEventLifecyclePrint), }, { "update", vshEventGenericPrint, } }; -verify(VIR_NODE_DEVICE_EVENT_ID_LAST =3D=3D ARRAY_CARDINALITY(virshNodedev= EventCallbacks)); +verify(VIR_NODE_DEVICE_EVENT_ID_LAST =3D=3D ARRAY_CARDINALITY(virshNodeDev= iceEventCallbacks)); =20 =20 static const vshCmdInfo info_node_device_event[] =3D { @@ -867,7 +867,7 @@ static const vshCmdOptDef opts_node_device_event[] =3D { }, {.name =3D "event", .type =3D VSH_OT_STRING, - .completer =3D virshNodedevEventNameCompleter, + .completer =3D virshNodeDeviceEventNameCompleter, .help =3D N_("which event type to wait for") }, {.name =3D "loop", @@ -906,7 +906,7 @@ cmdNodeDeviceEvent(vshControl *ctl, const vshCmd *cmd) size_t i; =20 for (i =3D 0; i < VIR_NODE_DEVICE_EVENT_ID_LAST; i++) - vshPrint(ctl, "%s\n", virshNodedevEventCallbacks[i].name); + vshPrint(ctl, "%s\n", virshNodeDeviceEventCallbacks[i].name); return true; } =20 @@ -918,7 +918,7 @@ cmdNodeDeviceEvent(vshControl *ctl, const vshCmd *cmd) } =20 for (event =3D 0; event < VIR_NODE_DEVICE_EVENT_ID_LAST; event++) - if (STREQ(eventName, virshNodedevEventCallbacks[event].name)) + if (STREQ(eventName, virshNodeDeviceEventCallbacks[event].name)) break; if (event =3D=3D VIR_NODE_DEVICE_EVENT_ID_LAST) { vshError(ctl, _("unknown event type %s"), eventName); @@ -929,7 +929,7 @@ cmdNodeDeviceEvent(vshControl *ctl, const vshCmd *cmd) data.loop =3D vshCommandOptBool(cmd, "loop"); data.timestamp =3D vshCommandOptBool(cmd, "timestamp"); data.count =3D 0; - data.cb =3D &virshNodedevEventCallbacks[event]; + data.cb =3D &virshNodeDeviceEventCallbacks[event]; if (vshCommandOptTimeoutToMs(ctl, cmd, &timeout) < 0) return false; if (vshCommandOptStringReq(ctl, cmd, "device", &device_value) < 0) diff --git a/tools/virsh-nodedev.h b/tools/virsh-nodedev.h index 9691b0db4d..95ff3bf526 100644 --- a/tools/virsh-nodedev.h +++ b/tools/virsh-nodedev.h @@ -22,12 +22,12 @@ =20 #include "virsh.h" =20 -struct virshNodedevEventCallback { +struct virshNodeDeviceEventCallback { const char *name; virConnectNodeDeviceEventGenericCallback cb; }; -typedef struct virshNodedevEventCallback virshNodedevEventCallback; +typedef struct virshNodeDeviceEventCallback virshNodeDeviceEventCallback; =20 -extern virshNodedevEventCallback virshNodedevEventCallbacks[]; +extern virshNodeDeviceEventCallback virshNodeDeviceEventCallbacks[]; =20 extern const vshCmdDef nodedevCmds[]; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 20:53:19 2024 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=A8Gxjr1Syi/NKqM7dWg+DsVClEISLPVdklYb9P7l/BWGOoRTe0WisBM++i/j9UGuDYwquxwTlgWXlsjTCnBZhYJmzQpWK3g9a3mLFeC4evxII35aAFS3X0baI0xIkhbaRAy0vGTEzZYt9UfS0GWhQ/rRhm3wdC/wdSPwV9WzoCc= 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=CtA3ueJMD1z//mLTTd1Hi32KmMbhJtQ/eCTt/Ppm3Ps=; b=fao2ryqF7w5hrMuFJrOWi39KGKJ63Ic/ncXcrNLWEM2JRZmVPJSv5Z6nGNYaBqGx7jtKSH29TLKxWyWDp5nbzhOEzyk/7C46a4wcSZjd52jh8BClZGD7hdwbK35xdER9act79/BO63sg4kkOQCzPPSho2Un57daikd8N9n2U900= 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 1563526142230548.1614132145654; Fri, 19 Jul 2019 01:49:02 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8A5FC30860DB; Fri, 19 Jul 2019 08:49:00 +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 57EE55C57A; 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 157DA18045D2; 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 x6J8miDJ005183 for ; Fri, 19 Jul 2019 04:48:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id 682D8601A9; Fri, 19 Jul 2019 08:48:44 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id E8A4960126 for ; Fri, 19 Jul 2019 08:48:43 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Fri, 19 Jul 2019 10:48:26 +0200 Message-Id: <12ed3d2d3741d2ae6be635372bbbf5bb3b8f5267.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 02/14] tools: Expose virshCommaStringListComplete() 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Fri, 19 Jul 2019 08:49:01 +0000 (UTC) Content-Type: text/plain; charset="utf-8" In next commits the virsh-completer.c is going to be split into smaller files. Expose virshCommaStringListComplete() so that it can still be used from those new files. Signed-off-by: Michal Privoznik --- tools/virsh-completer.c | 2 +- tools/virsh-completer.h | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index 63e2fe17e6..f97bad75de 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -96,7 +96,7 @@ * Returns: string list of completions on success, * NULL otherwise. */ -static char ** +char ** virshCommaStringListComplete(const char *input, const char **options) { diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h index 1b4694d44d..2b51d5d84d 100644 --- a/tools/virsh-completer.h +++ b/tools/virsh-completer.h @@ -38,6 +38,9 @@ char ** virshDomainDiskTargetCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); =20 +char ** virshCommaStringListComplete(const char *input, + const char **options); + char ** virshStoragePoolNameCompleter(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 From nobody Sun May 5 20:53:19 2024 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=1563526131; cv=none; d=zoho.com; s=zohoarc; b=hYXVByb/8EwAl0fEEnlbs0WMZUjQljnqIOEMqcXRNtLfC3ZOp7QBgbrgrnMDS2wJtsZte1m/M+vsqGTeAXVzZIQrra2LbQeDV5ERuRuThO3B+Upvi3gIxfEV0mYzEUVVzhG8Q6L7rVlJKdxhKvk/PpJ0eHtHrXXCu53UK3XSXSw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563526131; 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=co3YfShTp9lK248wy0Z+fsPx2tlpcU8CT8LIzm2lwXw=; b=O0tM0z6HUwWWI9WgMm37tiaoJpXSsGWfKwtiynaX+47te7zKssnTZtrBKJmZpRIWrDD4YEnjvOyaNrOnKVDmj6AqRk3aC3FJPgkVKDmFL+es+RdFbcq4HFjcPKuabAM6MCKEgMm7DWoIDRTbDEsFnbBn3y2x3B3aSPZ5G6/HSLY= 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 1563526131606658.6432236887814; Fri, 19 Jul 2019 01:48:51 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7DCDF307D9CE; Fri, 19 Jul 2019 08:48:49 +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 4DE4E5D970; Fri, 19 Jul 2019 08:48:49 +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 AF73E4EA32; Fri, 19 Jul 2019 08:48:46 +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 x6J8mjjo005193 for ; Fri, 19 Jul 2019 04:48:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id 596C4601A9; Fri, 19 Jul 2019 08:48:45 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id B3BF560126 for ; Fri, 19 Jul 2019 08:48:44 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Fri, 19 Jul 2019 10:48:27 +0200 Message-Id: <847a3bac6740447d94a17fa9f5b8e170537c23fa.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 03/14] tools: Separate domain 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Fri, 19 Jul 2019 08:48:49 +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 domains (e.g. they complete various domain aspects) into virsh-completer-domain.c. Signed-off-by: Michal Privoznik --- tools/Makefile.am | 1 + tools/virsh-completer-domain.c | 314 +++++++++++++++++++++++++++++++++ tools/virsh-completer-domain.h | 55 ++++++ tools/virsh-completer.c | 285 ------------------------------ tools/virsh-completer.h | 32 +--- 5 files changed, 371 insertions(+), 316 deletions(-) create mode 100644 tools/virsh-completer-domain.c create mode 100644 tools/virsh-completer-domain.h diff --git a/tools/Makefile.am b/tools/Makefile.am index c6064dee08..8dbfba700a 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -217,6 +217,7 @@ virt_login_shell_CFLAGS =3D \ virsh_SOURCES =3D \ virsh.c virsh.h \ virsh-completer.c virsh-completer.h \ + virsh-completer-domain.c virsh-completer-domain.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-domain.c b/tools/virsh-completer-domain.c new file mode 100644 index 0000000000..9c10e38aba --- /dev/null +++ b/tools/virsh-completer-domain.c @@ -0,0 +1,314 @@ +/* + * virsh-completer-domain.c: virsh completer callbacks related to domains + * + * 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-domain.h" +#include "viralloc.h" +#include "virmacaddr.h" +#include "virsh-domain.h" +#include "virsh-util.h" +#include "virsh.h" +#include "virstring.h" +#include "virxml.h" + +char ** +virshDomainNameCompleter(vshControl *ctl, + const vshCmd *cmd ATTRIBUTE_UNUSED, + unsigned int flags) +{ + virshControlPtr priv =3D ctl->privData; + virDomainPtr *domains =3D NULL; + int ndomains =3D 0; + size_t i =3D 0; + char **ret =3D NULL; + VIR_AUTOSTRINGLIST tmp =3D NULL; + + virCheckFlags(VIR_CONNECT_LIST_DOMAINS_ACTIVE | + VIR_CONNECT_LIST_DOMAINS_INACTIVE | + VIR_CONNECT_LIST_DOMAINS_OTHER | + VIR_CONNECT_LIST_DOMAINS_PAUSED | + VIR_CONNECT_LIST_DOMAINS_PERSISTENT | + VIR_CONNECT_LIST_DOMAINS_RUNNING | + VIR_CONNECT_LIST_DOMAINS_SHUTOFF, + NULL); + + if (!priv->conn || virConnectIsAlive(priv->conn) <=3D 0) + return NULL; + + if ((ndomains =3D virConnectListAllDomains(priv->conn, &domains, flags= )) < 0) + return NULL; + + if (VIR_ALLOC_N(tmp, ndomains + 1) < 0) + goto cleanup; + + for (i =3D 0; i < ndomains; i++) { + const char *name =3D virDomainGetName(domains[i]); + + if (VIR_STRDUP(tmp[i], name) < 0) + goto cleanup; + } + + VIR_STEAL_PTR(ret, tmp); + + cleanup: + for (i =3D 0; i < ndomains; i++) + virshDomainFree(domains[i]); + VIR_FREE(domains); + return ret; +} + + +char ** +virshDomainInterfaceCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags) +{ + virshControlPtr priv =3D ctl->privData; + VIR_AUTOPTR(xmlDoc) xmldoc =3D NULL; + VIR_AUTOPTR(xmlXPathContext) ctxt =3D NULL; + int ninterfaces; + VIR_AUTOFREE(xmlNodePtr *) interfaces =3D NULL; + size_t i; + unsigned int domainXMLFlags =3D 0; + char **ret =3D NULL; + VIR_AUTOSTRINGLIST tmp =3D NULL; + + virCheckFlags(VIRSH_DOMAIN_INTERFACE_COMPLETER_MAC, NULL); + + if (!priv->conn || virConnectIsAlive(priv->conn) <=3D 0) + return NULL; + + if (vshCommandOptBool(cmd, "config")) + domainXMLFlags =3D VIR_DOMAIN_XML_INACTIVE; + + if (virshDomainGetXML(ctl, cmd, domainXMLFlags, &xmldoc, &ctxt) < 0) + return NULL; + + ninterfaces =3D virXPathNodeSet("./devices/interface", ctxt, &interfac= es); + if (ninterfaces < 0) + return NULL; + + if (VIR_ALLOC_N(tmp, ninterfaces + 1) < 0) + return NULL; + + for (i =3D 0; i < ninterfaces; i++) { + ctxt->node =3D interfaces[i]; + + if (!(flags & VIRSH_DOMAIN_INTERFACE_COMPLETER_MAC) && + (tmp[i] =3D virXPathString("string(./target/@dev)", ctxt))) + continue; + + /* In case we are dealing with inactive domain XML there's no + * . Offer MAC addresses then. */ + if (!(tmp[i] =3D virXPathString("string(./mac/@address)", ctxt))) + return NULL; + } + + VIR_STEAL_PTR(ret, tmp); + return ret; +} + + +char ** +virshDomainDiskTargetCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags) +{ + virshControlPtr priv =3D ctl->privData; + VIR_AUTOPTR(xmlDoc) xmldoc =3D NULL; + VIR_AUTOPTR(xmlXPathContext) ctxt =3D NULL; + VIR_AUTOFREE(xmlNodePtr *) disks =3D NULL; + int ndisks; + size_t i; + VIR_AUTOSTRINGLIST tmp =3D NULL; + char **ret =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; + + ndisks =3D virXPathNodeSet("./devices/disk", ctxt, &disks); + if (ndisks < 0) + return NULL; + + if (VIR_ALLOC_N(tmp, ndisks + 1) < 0) + return NULL; + + for (i =3D 0; i < ndisks; i++) { + ctxt->node =3D disks[i]; + if (!(tmp[i] =3D virXPathString("string(./target/@dev)", ctxt))) + return NULL; + } + + VIR_STEAL_PTR(ret, tmp); + return ret; +} + + +char ** +virshDomainEventNameCompleter(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_DOMAIN_EVENT_ID_LAST + 1) < 0) + return NULL; + + for (i =3D 0; i < VIR_DOMAIN_EVENT_ID_LAST; i++) { + if (VIR_STRDUP(tmp[i], virshDomainEventCallbacks[i].name) < 0) + return NULL; + } + + VIR_STEAL_PTR(ret, tmp); + return ret; +} + + +char ** +virshDomainInterfaceStateCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags) +{ + virshControlPtr priv =3D ctl->privData; + const char *iface =3D NULL; + char **ret =3D NULL; + VIR_AUTOPTR(xmlDoc) xml =3D NULL; + VIR_AUTOPTR(xmlXPathContext) ctxt =3D NULL; + virMacAddr macaddr; + char macstr[VIR_MAC_STRING_BUFLEN] =3D ""; + int ninterfaces; + VIR_AUTOFREE(xmlNodePtr *) interfaces =3D NULL; + VIR_AUTOFREE(char *) xpath =3D NULL; + VIR_AUTOFREE(char *) state =3D NULL; + VIR_AUTOSTRINGLIST tmp =3D NULL; + + virCheckFlags(0, NULL); + + if (!priv->conn || virConnectIsAlive(priv->conn) <=3D 0) + return NULL; + + if (virshDomainGetXML(ctl, cmd, flags, &xml, &ctxt) < 0) + return NULL; + + if (vshCommandOptStringReq(ctl, cmd, "interface", &iface) < 0) + return NULL; + + /* normalize the mac addr */ + if (virMacAddrParse(iface, &macaddr) =3D=3D 0) + virMacAddrFormat(&macaddr, macstr); + + if (virAsprintf(&xpath, "/domain/devices/interface[(mac/@address =3D '= %s') or " + " (target/@dev =3D '%= s')]", + macstr, iface) < 0) + return NULL; + + if ((ninterfaces =3D virXPathNodeSet(xpath, ctxt, &interfaces)) < 0) + return NULL; + + if (ninterfaces !=3D 1) + return NULL; + + ctxt->node =3D interfaces[0]; + + if (VIR_ALLOC_N(tmp, 2) < 0) + return NULL; + + if ((state =3D virXPathString("string(./link/@state)", ctxt)) && + STREQ(state, "down")) { + if (VIR_STRDUP(tmp[0], "up") < 0) + return NULL; + } else { + if (VIR_STRDUP(tmp[0], "down") < 0) + return NULL; + } + + VIR_STEAL_PTR(ret, tmp); + return ret; +} + + +char ** +virshDomainDeviceAliasCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags) +{ + virshControlPtr priv =3D ctl->privData; + VIR_AUTOPTR(xmlDoc) xmldoc =3D NULL; + VIR_AUTOPTR(xmlXPathContext) ctxt =3D NULL; + int naliases; + VIR_AUTOFREE(xmlNodePtr *) aliases =3D NULL; + size_t i; + unsigned int domainXMLFlags =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 (vshCommandOptBool(cmd, "config")) + domainXMLFlags =3D VIR_DOMAIN_XML_INACTIVE; + + if (virshDomainGetXML(ctl, cmd, domainXMLFlags, &xmldoc, &ctxt) < 0) + return NULL; + + naliases =3D virXPathNodeSet("./devices//alias/@name", ctxt, &aliases); + if (naliases < 0) + return NULL; + + if (VIR_ALLOC_N(tmp, naliases + 1) < 0) + return NULL; + + for (i =3D 0; i < naliases; i++) { + if (!(tmp[i] =3D virXMLNodeContentString(aliases[i]))) + return NULL; + } + + VIR_STEAL_PTR(ret, tmp); + return ret; +} + + +char ** +virshDomainShutdownModeCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags) +{ + const char *modes[] =3D {"acpi", "agent", "initctl", "signal", "paravi= rt", NULL}; + const char *mode =3D NULL; + + virCheckFlags(0, NULL); + + if (vshCommandOptStringQuiet(ctl, cmd, "mode", &mode) < 0) + return NULL; + + return virshCommaStringListComplete(mode, modes); +} diff --git a/tools/virsh-completer-domain.h b/tools/virsh-completer-domain.h new file mode 100644 index 0000000000..083ab327cc --- /dev/null +++ b/tools/virsh-completer-domain.h @@ -0,0 +1,55 @@ +/* + * virsh-completer-domain.h: virsh completer callbacks related to domains + * + * 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 ** virshDomainNameCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); + +enum { + VIRSH_DOMAIN_INTERFACE_COMPLETER_MAC =3D 1 << 0, /* Return just MACs */ +}; + +char ** virshDomainInterfaceCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); + +char ** virshDomainDiskTargetCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); + +char ** virshDomainEventNameCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); + +char ** virshDomainInterfaceStateCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); + +char ** virshDomainDeviceAliasCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); + +char ** virshDomainShutdownModeCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index f97bad75de..71796182b0 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -143,144 +143,6 @@ virshCommaStringListComplete(const char *input, } =20 =20 -char ** -virshDomainNameCompleter(vshControl *ctl, - const vshCmd *cmd ATTRIBUTE_UNUSED, - unsigned int flags) -{ - virshControlPtr priv =3D ctl->privData; - virDomainPtr *domains =3D NULL; - int ndomains =3D 0; - size_t i =3D 0; - char **ret =3D NULL; - VIR_AUTOSTRINGLIST tmp =3D NULL; - - virCheckFlags(VIR_CONNECT_LIST_DOMAINS_ACTIVE | - VIR_CONNECT_LIST_DOMAINS_INACTIVE | - VIR_CONNECT_LIST_DOMAINS_OTHER | - VIR_CONNECT_LIST_DOMAINS_PAUSED | - VIR_CONNECT_LIST_DOMAINS_PERSISTENT | - VIR_CONNECT_LIST_DOMAINS_RUNNING | - VIR_CONNECT_LIST_DOMAINS_SHUTOFF, - NULL); - - if (!priv->conn || virConnectIsAlive(priv->conn) <=3D 0) - return NULL; - - if ((ndomains =3D virConnectListAllDomains(priv->conn, &domains, flags= )) < 0) - return NULL; - - if (VIR_ALLOC_N(tmp, ndomains + 1) < 0) - goto cleanup; - - for (i =3D 0; i < ndomains; i++) { - const char *name =3D virDomainGetName(domains[i]); - - if (VIR_STRDUP(tmp[i], name) < 0) - goto cleanup; - } - - VIR_STEAL_PTR(ret, tmp); - - cleanup: - for (i =3D 0; i < ndomains; i++) - virshDomainFree(domains[i]); - VIR_FREE(domains); - return ret; -} - - -char ** -virshDomainInterfaceCompleter(vshControl *ctl, - const vshCmd *cmd, - unsigned int flags) -{ - virshControlPtr priv =3D ctl->privData; - VIR_AUTOPTR(xmlDoc) xmldoc =3D NULL; - VIR_AUTOPTR(xmlXPathContext) ctxt =3D NULL; - int ninterfaces; - VIR_AUTOFREE(xmlNodePtr *) interfaces =3D NULL; - size_t i; - unsigned int domainXMLFlags =3D 0; - char **ret =3D NULL; - VIR_AUTOSTRINGLIST tmp =3D NULL; - - virCheckFlags(VIRSH_DOMAIN_INTERFACE_COMPLETER_MAC, NULL); - - if (!priv->conn || virConnectIsAlive(priv->conn) <=3D 0) - return NULL; - - if (vshCommandOptBool(cmd, "config")) - domainXMLFlags =3D VIR_DOMAIN_XML_INACTIVE; - - if (virshDomainGetXML(ctl, cmd, domainXMLFlags, &xmldoc, &ctxt) < 0) - return NULL; - - ninterfaces =3D virXPathNodeSet("./devices/interface", ctxt, &interfac= es); - if (ninterfaces < 0) - return NULL; - - if (VIR_ALLOC_N(tmp, ninterfaces + 1) < 0) - return NULL; - - for (i =3D 0; i < ninterfaces; i++) { - ctxt->node =3D interfaces[i]; - - if (!(flags & VIRSH_DOMAIN_INTERFACE_COMPLETER_MAC) && - (tmp[i] =3D virXPathString("string(./target/@dev)", ctxt))) - continue; - - /* In case we are dealing with inactive domain XML there's no - * . Offer MAC addresses then. */ - if (!(tmp[i] =3D virXPathString("string(./mac/@address)", ctxt))) - return NULL; - } - - VIR_STEAL_PTR(ret, tmp); - return ret; -} - - -char ** -virshDomainDiskTargetCompleter(vshControl *ctl, - const vshCmd *cmd, - unsigned int flags) -{ - virshControlPtr priv =3D ctl->privData; - VIR_AUTOPTR(xmlDoc) xmldoc =3D NULL; - VIR_AUTOPTR(xmlXPathContext) ctxt =3D NULL; - VIR_AUTOFREE(xmlNodePtr *) disks =3D NULL; - int ndisks; - size_t i; - VIR_AUTOSTRINGLIST tmp =3D NULL; - char **ret =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; - - ndisks =3D virXPathNodeSet("./devices/disk", ctxt, &disks); - if (ndisks < 0) - return NULL; - - if (VIR_ALLOC_N(tmp, ndisks + 1) < 0) - return NULL; - - for (i =3D 0; i < ndisks; i++) { - ctxt->node =3D disks[i]; - if (!(tmp[i] =3D virXPathString("string(./target/@dev)", ctxt))) - return NULL; - } - - VIR_STEAL_PTR(ret, tmp); - return ret; -} - - char ** virshStoragePoolNameCompleter(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED, @@ -841,30 +703,6 @@ virshSecretEventNameCompleter(vshControl *ctl ATTRIBUT= E_UNUSED, } =20 =20 -char ** -virshDomainEventNameCompleter(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_DOMAIN_EVENT_ID_LAST + 1) < 0) - return NULL; - - for (i =3D 0; i < VIR_DOMAIN_EVENT_ID_LAST; i++) { - if (VIR_STRDUP(tmp[i], virshDomainEventCallbacks[i].name) < 0) - return NULL; - } - - VIR_STEAL_PTR(ret, tmp); - return ret; -} - - char ** virshPoolEventNameCompleter(vshControl *ctl ATTRIBUTE_UNUSED, const vshCmd *cmd ATTRIBUTE_UNUSED, @@ -889,69 +727,6 @@ virshPoolEventNameCompleter(vshControl *ctl ATTRIBUTE_= UNUSED, } =20 =20 -char ** -virshDomainInterfaceStateCompleter(vshControl *ctl, - const vshCmd *cmd, - unsigned int flags) -{ - virshControlPtr priv =3D ctl->privData; - const char *iface =3D NULL; - char **ret =3D NULL; - VIR_AUTOPTR(xmlDoc) xml =3D NULL; - VIR_AUTOPTR(xmlXPathContext) ctxt =3D NULL; - virMacAddr macaddr; - char macstr[VIR_MAC_STRING_BUFLEN] =3D ""; - int ninterfaces; - VIR_AUTOFREE(xmlNodePtr *) interfaces =3D NULL; - VIR_AUTOFREE(char *) xpath =3D NULL; - VIR_AUTOFREE(char *) state =3D NULL; - VIR_AUTOSTRINGLIST tmp =3D NULL; - - virCheckFlags(0, NULL); - - if (!priv->conn || virConnectIsAlive(priv->conn) <=3D 0) - return NULL; - - if (virshDomainGetXML(ctl, cmd, flags, &xml, &ctxt) < 0) - return NULL; - - if (vshCommandOptStringReq(ctl, cmd, "interface", &iface) < 0) - return NULL; - - /* normalize the mac addr */ - if (virMacAddrParse(iface, &macaddr) =3D=3D 0) - virMacAddrFormat(&macaddr, macstr); - - if (virAsprintf(&xpath, "/domain/devices/interface[(mac/@address =3D '= %s') or " - " (target/@dev =3D '%= s')]", - macstr, iface) < 0) - return NULL; - - if ((ninterfaces =3D virXPathNodeSet(xpath, ctxt, &interfaces)) < 0) - return NULL; - - if (ninterfaces !=3D 1) - return NULL; - - ctxt->node =3D interfaces[0]; - - if (VIR_ALLOC_N(tmp, 2) < 0) - return NULL; - - if ((state =3D virXPathString("string(./link/@state)", ctxt)) && - STREQ(state, "down")) { - if (VIR_STRDUP(tmp[0], "up") < 0) - return NULL; - } else { - if (VIR_STRDUP(tmp[0], "down") < 0) - return NULL; - } - - VIR_STEAL_PTR(ret, tmp); - return ret; -} - - char ** virshNodeDeviceEventNameCompleter(vshControl *ctl ATTRIBUTE_UNUSED, const vshCmd *cmd ATTRIBUTE_UNUSED, @@ -1043,63 +818,3 @@ virshCellnoCompleter(vshControl *ctl, VIR_STEAL_PTR(ret, tmp); return ret; } - - -char ** -virshDomainDeviceAliasCompleter(vshControl *ctl, - const vshCmd *cmd, - unsigned int flags) -{ - virshControlPtr priv =3D ctl->privData; - VIR_AUTOPTR(xmlDoc) xmldoc =3D NULL; - VIR_AUTOPTR(xmlXPathContext) ctxt =3D NULL; - int naliases; - VIR_AUTOFREE(xmlNodePtr *) aliases =3D NULL; - size_t i; - unsigned int domainXMLFlags =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 (vshCommandOptBool(cmd, "config")) - domainXMLFlags =3D VIR_DOMAIN_XML_INACTIVE; - - if (virshDomainGetXML(ctl, cmd, domainXMLFlags, &xmldoc, &ctxt) < 0) - return NULL; - - naliases =3D virXPathNodeSet("./devices//alias/@name", ctxt, &aliases); - if (naliases < 0) - return NULL; - - if (VIR_ALLOC_N(tmp, naliases + 1) < 0) - return NULL; - - for (i =3D 0; i < naliases; i++) { - if (!(tmp[i] =3D virXMLNodeContentString(aliases[i]))) - return NULL; - } - - VIR_STEAL_PTR(ret, tmp); - return ret; -} - - -char ** -virshDomainShutdownModeCompleter(vshControl *ctl, - const vshCmd *cmd, - unsigned int flags) -{ - const char *modes[] =3D {"acpi", "agent", "initctl", "signal", "paravi= rt", NULL}; - const char *mode =3D NULL; - - virCheckFlags(0, NULL); - - if (vshCommandOptStringQuiet(ctl, cmd, "mode", &mode) < 0) - return NULL; - - return virshCommaStringListComplete(mode, modes); -} diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h index 2b51d5d84d..0c6d993f8f 100644 --- a/tools/virsh-completer.h +++ b/tools/virsh-completer.h @@ -22,21 +22,7 @@ =20 #include "vsh.h" =20 -char ** virshDomainNameCompleter(vshControl *ctl, - const vshCmd *cmd, - unsigned int flags); - -enum { - VIRSH_DOMAIN_INTERFACE_COMPLETER_MAC =3D 1 << 0, /* Return just MACs */ -}; - -char ** virshDomainInterfaceCompleter(vshControl *ctl, - const vshCmd *cmd, - unsigned int flags); - -char ** virshDomainDiskTargetCompleter(vshControl *ctl, - const vshCmd *cmd, - unsigned int flags); +#include "virsh-completer-domain.h" =20 char ** virshCommaStringListComplete(const char *input, const char **options); @@ -93,18 +79,10 @@ char ** virshSecretEventNameCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); =20 -char ** virshDomainEventNameCompleter(vshControl *ctl, - const vshCmd *cmd, - unsigned int flags); - char ** virshPoolEventNameCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); =20 -char ** virshDomainInterfaceStateCompleter(vshControl *ctl, - const vshCmd *cmd, - unsigned int flags); - char ** virshNodeDeviceEventNameCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); @@ -113,14 +91,6 @@ char ** virshNodeDeviceCapabilityNameCompleter(vshContr= ol *ctl, const vshCmd *cmd, unsigned int flags); =20 -char ** virshDomainDeviceAliasCompleter(vshControl *ctl, - const vshCmd *cmd, - unsigned int flags); - char ** virshCellnoCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); - -char ** virshDomainShutdownModeCompleter(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 From nobody Sun May 5 20:53:19 2024 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=1563526147; cv=none; d=zoho.com; s=zohoarc; b=H7ieKSQFccQhgvdPxNkoHebEYSWdv0LOHd/GN4ZEP2YrM3vnBDZFfTgi299eleT8JK5BIplkSlS/qO4SbwkPEDLcXYugLJRWP9GUGKLLeqLGkc3X8LYw8xRdFwHD2UKntVP/lexJdxOuDwWnNHLNPoK0gDnw6NKp83e7KYDCSFA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563526147; 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=Uc1v/zDZlyu4kMCMe7ovE/ngP+gdF79Y9sNmbwShOTs=; b=a9E7J1ZS3N4n51UDoJJnG+qcR6lMFTP0b9kXmvVOGSp6lcXGF+LiBZ57av2U8aNFRLFbFgldxjtC/9DcjtAWnwezoOhOItmKrKQOzWcy9fvYOm4NjXyT/SPgTqdlWux+hut4+l8r9mw/nhydt/M7UDlyLGN6yWu5J3WEBtlz+YM= 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 1563526147138456.4258565987261; Fri, 19 Jul 2019 01:49:07 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6A65030BD1D1; Fri, 19 Jul 2019 08:49:04 +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 4585110190CE; Fri, 19 Jul 2019 08:49:04 +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 054F93CBC; Fri, 19 Jul 2019 08:49:04 +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 x6J8mkAY005201 for ; Fri, 19 Jul 2019 04:48:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 277A660126; 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 A67EF6136C for ; Fri, 19 Jul 2019 08:48:45 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Fri, 19 Jul 2019 10:48:28 +0200 Message-Id: <6a9c0af8646e5ab52e743243b4136386b3a3667b.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 04/14] tools: Separate storage pool 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.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Fri, 19 Jul 2019 08:49:04 +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 pools (e.g. they complete various storage pool aspects) into virsh-completer-pool.c. Signed-off-by: Michal Privoznik --- tools/Makefile.am | 1 + tools/virsh-completer-pool.c | 93 ++++++++++++++++++++++++++++++++++++ tools/virsh-completer-pool.h | 31 ++++++++++++ tools/virsh-completer.c | 67 -------------------------- tools/virsh-completer.h | 9 +--- 5 files changed, 126 insertions(+), 75 deletions(-) create mode 100644 tools/virsh-completer-pool.c create mode 100644 tools/virsh-completer-pool.h diff --git a/tools/Makefile.am b/tools/Makefile.am index 8dbfba700a..9724e8de53 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -218,6 +218,7 @@ virsh_SOURCES =3D \ virsh.c virsh.h \ virsh-completer.c virsh-completer.h \ virsh-completer-domain.c virsh-completer-domain.h \ + virsh-completer-pool.c virsh-completer-pool.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-pool.c b/tools/virsh-completer-pool.c new file mode 100644 index 0000000000..fc01550908 --- /dev/null +++ b/tools/virsh-completer-pool.c @@ -0,0 +1,93 @@ +/* + * virsh-completer-pool.c: virsh completer callbacks related to pools + * + * 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-pool.h" +#include "viralloc.h" +#include "virsh-pool.h" +#include "virsh.h" +#include "virstring.h" + +char ** +virshStoragePoolNameCompleter(vshControl *ctl, + const vshCmd *cmd ATTRIBUTE_UNUSED, + unsigned int flags) +{ + virshControlPtr priv =3D ctl->privData; + virStoragePoolPtr *pools =3D NULL; + int npools =3D 0; + size_t i =3D 0; + char **ret =3D NULL; + VIR_AUTOSTRINGLIST tmp =3D NULL; + + virCheckFlags(VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE | + VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE | + VIR_CONNECT_LIST_STORAGE_POOLS_PERSISTENT, + NULL); + + if (!priv->conn || virConnectIsAlive(priv->conn) <=3D 0) + return NULL; + + if ((npools =3D virConnectListAllStoragePools(priv->conn, &pools, flag= s)) < 0) + return NULL; + + if (VIR_ALLOC_N(tmp, npools + 1) < 0) + goto cleanup; + + for (i =3D 0; i < npools; i++) { + const char *name =3D virStoragePoolGetName(pools[i]); + + if (VIR_STRDUP(tmp[i], name) < 0) + goto cleanup; + } + + VIR_STEAL_PTR(ret, tmp); + + cleanup: + for (i =3D 0; i < npools; i++) + virStoragePoolFree(pools[i]); + VIR_FREE(pools); + return ret; +} + + +char ** +virshPoolEventNameCompleter(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_STORAGE_POOL_EVENT_ID_LAST + 1) < 0) + return NULL; + + for (i =3D 0; i < VIR_STORAGE_POOL_EVENT_ID_LAST; i++) { + if (VIR_STRDUP(tmp[i], virshPoolEventCallbacks[i].name) < 0) + return NULL; + } + + VIR_STEAL_PTR(ret, tmp); + return ret; +} diff --git a/tools/virsh-completer-pool.h b/tools/virsh-completer-pool.h new file mode 100644 index 0000000000..778ab25df2 --- /dev/null +++ b/tools/virsh-completer-pool.h @@ -0,0 +1,31 @@ +/* + * virsh-completer-pool.h: virsh completer callbacks related to pools + * + * 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 ** virshStoragePoolNameCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); + +char ** virshPoolEventNameCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index 71796182b0..b227b43290 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -143,49 +143,6 @@ virshCommaStringListComplete(const char *input, } =20 =20 -char ** -virshStoragePoolNameCompleter(vshControl *ctl, - const vshCmd *cmd ATTRIBUTE_UNUSED, - unsigned int flags) -{ - virshControlPtr priv =3D ctl->privData; - virStoragePoolPtr *pools =3D NULL; - int npools =3D 0; - size_t i =3D 0; - char **ret =3D NULL; - VIR_AUTOSTRINGLIST tmp =3D NULL; - - virCheckFlags(VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE | - VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE | - VIR_CONNECT_LIST_STORAGE_POOLS_PERSISTENT, - NULL); - - if (!priv->conn || virConnectIsAlive(priv->conn) <=3D 0) - return NULL; - - if ((npools =3D virConnectListAllStoragePools(priv->conn, &pools, flag= s)) < 0) - return NULL; - - if (VIR_ALLOC_N(tmp, npools + 1) < 0) - goto cleanup; - - for (i =3D 0; i < npools; i++) { - const char *name =3D virStoragePoolGetName(pools[i]); - - if (VIR_STRDUP(tmp[i], name) < 0) - goto cleanup; - } - - VIR_STEAL_PTR(ret, tmp); - - cleanup: - for (i =3D 0; i < npools; i++) - virStoragePoolFree(pools[i]); - VIR_FREE(pools); - return ret; -} - - char ** virshStorageVolNameCompleter(vshControl *ctl, const vshCmd *cmd, @@ -703,30 +660,6 @@ virshSecretEventNameCompleter(vshControl *ctl ATTRIBUT= E_UNUSED, } =20 =20 -char ** -virshPoolEventNameCompleter(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_STORAGE_POOL_EVENT_ID_LAST + 1) < 0) - return NULL; - - for (i =3D 0; i < VIR_STORAGE_POOL_EVENT_ID_LAST; i++) { - if (VIR_STRDUP(tmp[i], virshPoolEventCallbacks[i].name) < 0) - return NULL; - } - - VIR_STEAL_PTR(ret, tmp); - return ret; -} - - char ** virshNodeDeviceEventNameCompleter(vshControl *ctl ATTRIBUTE_UNUSED, const vshCmd *cmd ATTRIBUTE_UNUSED, diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h index 0c6d993f8f..aeb13da622 100644 --- a/tools/virsh-completer.h +++ b/tools/virsh-completer.h @@ -23,14 +23,11 @@ #include "vsh.h" =20 #include "virsh-completer-domain.h" +#include "virsh-completer-pool.h" =20 char ** virshCommaStringListComplete(const char *input, const char **options); =20 -char ** virshStoragePoolNameCompleter(vshControl *ctl, - const vshCmd *cmd, - unsigned int flags); - char ** virshStorageVolNameCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); @@ -79,10 +76,6 @@ char ** virshSecretEventNameCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); =20 -char ** virshPoolEventNameCompleter(vshControl *ctl, - const vshCmd *cmd, - unsigned int flags); - char ** virshNodeDeviceEventNameCompleter(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 From nobody Sun May 5 20:53:19 2024 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 From nobody Sun May 5 20:53:19 2024 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=1563526149; cv=none; d=zoho.com; s=zohoarc; b=PnT741XIPldsdW020IRHT/myhXVcaO7GR7bahhU9TuuJDqEfpZnRiCA8nBftNd19lWo2c5zQ/HZbC+vBK1KcG5n9fxAN3nAGFLZd9wdHOED4s5BpPHrQW9Km7AUko9YS8DZR9lttfbN83TGcmAG9/MksujwuT8+FoF7e/bTx/ig= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563526149; 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=HjVcO9y9H5irS04QkZWfIQG8Bxo1azQdwX7yKrjAeaw=; b=Yn1bDozngIN10Zs85SRclV+pzjb5e6P2bzF21taPVUnNd58tKDdt0LMQGCrgVgqUnEL3SQtsqvXDC/1Ud1e9Qi3OUE0ykrEakYm7iwez/08XdjrT6c8CmtsW+K8kAwpsJ5/Y68fNiyVDnOc/kb/kvw2M0qE9hKpdiNYBiYrbhLQ= 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 156352614989823.130462993051992; Fri, 19 Jul 2019 01:49:09 -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 42C2630860D3; Fri, 19 Jul 2019 08:49:08 +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 19B6D6266B; Fri, 19 Jul 2019 08:49:08 +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 CCAA518045D3; Fri, 19 Jul 2019 08:49:07 +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 x6J8mlxi005214 for ; Fri, 19 Jul 2019 04:48:47 -0400 Received: by smtp.corp.redhat.com (Postfix) id B54F5601A9; Fri, 19 Jul 2019 08:48:47 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3FEC960126 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:30 +0200 Message-Id: <10f07076cdf04c812484602c083b4d5ca35bcf56.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 06/14] tools: Separate interface 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.44]); Fri, 19 Jul 2019 08:49:08 +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 interfaces (e.g. they complete various interface aspects) into virsh-completer-interface.c Signed-off-by: Michal Privoznik --- tools/Makefile.am | 1 + tools/virsh-completer-interface.c | 67 +++++++++++++++++++++++++++++++ tools/virsh-completer-interface.h | 27 +++++++++++++ tools/virsh-completer.c | 42 ------------------- tools/virsh-completer.h | 5 +-- 5 files changed, 96 insertions(+), 46 deletions(-) create mode 100644 tools/virsh-completer-interface.c create mode 100644 tools/virsh-completer-interface.h diff --git a/tools/Makefile.am b/tools/Makefile.am index 583ba2f395..a86587f200 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -218,6 +218,7 @@ virsh_SOURCES =3D \ virsh.c virsh.h \ virsh-completer.c virsh-completer.h \ virsh-completer-domain.c virsh-completer-domain.h \ + virsh-completer-interface.c virsh-completer-interface.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-interface.c b/tools/virsh-completer-inte= rface.c new file mode 100644 index 0000000000..5dcdab8e92 --- /dev/null +++ b/tools/virsh-completer-interface.c @@ -0,0 +1,67 @@ +/* + * virsh-completer-interface.c: virsh completer callbacks related to inter= faces + * + * 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-interface.h" +#include "viralloc.h" +#include "virsh.h" +#include "virstring.h" + +char ** +virshInterfaceNameCompleter(vshControl *ctl, + const vshCmd *cmd ATTRIBUTE_UNUSED, + unsigned int flags) +{ + virshControlPtr priv =3D ctl->privData; + virInterfacePtr *ifaces =3D NULL; + int nifaces =3D 0; + size_t i =3D 0; + char **ret =3D NULL; + VIR_AUTOSTRINGLIST tmp =3D NULL; + + virCheckFlags(VIR_CONNECT_LIST_INTERFACES_ACTIVE | + VIR_CONNECT_LIST_INTERFACES_INACTIVE, + NULL); + + if (!priv->conn || virConnectIsAlive(priv->conn) <=3D 0) + return NULL; + + if ((nifaces =3D virConnectListAllInterfaces(priv->conn, &ifaces, flag= s)) < 0) + return NULL; + + if (VIR_ALLOC_N(tmp, nifaces + 1) < 0) + goto cleanup; + + for (i =3D 0; i < nifaces; i++) { + const char *name =3D virInterfaceGetName(ifaces[i]); + + if (VIR_STRDUP(tmp[i], name) < 0) + goto cleanup; + } + + VIR_STEAL_PTR(ret, tmp); + + cleanup: + for (i =3D 0; i < nifaces; i++) + virInterfaceFree(ifaces[i]); + VIR_FREE(ifaces); + return ret; +} diff --git a/tools/virsh-completer-interface.h b/tools/virsh-completer-inte= rface.h new file mode 100644 index 0000000000..893dee5a6b --- /dev/null +++ b/tools/virsh-completer-interface.h @@ -0,0 +1,27 @@ +/* + * virsh-completer-interface.h: virsh completer callbacks related to inter= faces + * + * 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 ** virshInterfaceNameCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index 29bccadc80..62df752962 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -143,48 +143,6 @@ virshCommaStringListComplete(const char *input, } =20 =20 -char ** -virshInterfaceNameCompleter(vshControl *ctl, - const vshCmd *cmd ATTRIBUTE_UNUSED, - unsigned int flags) -{ - virshControlPtr priv =3D ctl->privData; - virInterfacePtr *ifaces =3D NULL; - int nifaces =3D 0; - size_t i =3D 0; - char **ret =3D NULL; - VIR_AUTOSTRINGLIST tmp =3D NULL; - - virCheckFlags(VIR_CONNECT_LIST_INTERFACES_ACTIVE | - VIR_CONNECT_LIST_INTERFACES_INACTIVE, - NULL); - - if (!priv->conn || virConnectIsAlive(priv->conn) <=3D 0) - return NULL; - - if ((nifaces =3D virConnectListAllInterfaces(priv->conn, &ifaces, flag= s)) < 0) - return NULL; - - if (VIR_ALLOC_N(tmp, nifaces + 1) < 0) - goto cleanup; - - for (i =3D 0; i < nifaces; i++) { - const char *name =3D virInterfaceGetName(ifaces[i]); - - if (VIR_STRDUP(tmp[i], name) < 0) - goto cleanup; - } - - VIR_STEAL_PTR(ret, tmp); - - cleanup: - for (i =3D 0; i < nifaces; i++) - virInterfaceFree(ifaces[i]); - VIR_FREE(ifaces); - return ret; -} - - char ** virshNetworkNameCompleter(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED, diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h index 8da6f485e7..6170a87757 100644 --- a/tools/virsh-completer.h +++ b/tools/virsh-completer.h @@ -23,16 +23,13 @@ #include "vsh.h" =20 #include "virsh-completer-domain.h" +#include "virsh-completer-interface.h" #include "virsh-completer-pool.h" #include "virsh-completer-volume.h" =20 char ** virshCommaStringListComplete(const char *input, const char **options); =20 -char ** virshInterfaceNameCompleter(vshControl *ctl, - const vshCmd *cmd, - unsigned int flags); - char ** virshNetworkNameCompleter(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 From nobody Sun May 5 20:53:19 2024 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 From nobody Sun May 5 20:53:19 2024 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 From nobody Sun May 5 20:53:19 2024 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=1563526156; cv=none; d=zoho.com; s=zohoarc; b=GR/wqAhmR8WNdGUvrIkN4TOYs/jKrDZCau2Wgq7oo5GdYB04D14Wv5Qxn0clMAZPC7XNMLwMBfezuhHN84u3aXRios3sC48eiFjqjNtUGmuqIR4SeS9dW2Pd3UkMFKDey0lNcxv0exBLYPctoutlG4prwx59nrZjOIqkFK7XXOQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563526156; 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=WgVIAfu8my27mZ/8BTOKnTbP7FT5EmB+Iac4zK8Jvpo=; b=gA0SW0XEgfJ2Q5u67j7D5JcnBw2sU41t8YQVbZcqE2JXtvpNTy76ojgZcjV9t0Jlbr3Om60ucbGypWO8JwoUgnLB9cHMvy7RgWDHKX71SPNSIxoRXqkLLAgHuZ2BLDNj3zSFx3PffHRWJJ5OZTAW1qUkEhuYMjzgC8mpa7/RPbg= 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 156352615694532.11373615501998; Fri, 19 Jul 2019 01:49:16 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5BC1B5D674; Fri, 19 Jul 2019 08:49:15 +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 38072101E1CC; Fri, 19 Jul 2019 08:49:15 +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 EEFAE18045DD; Fri, 19 Jul 2019 08:49:14 +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 x6J8mo28005249 for ; Fri, 19 Jul 2019 04:48:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1FE7E6134E; Fri, 19 Jul 2019 08:48:50 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9BCE9601A9 for ; Fri, 19 Jul 2019 08:48:49 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Fri, 19 Jul 2019 10:48:33 +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 09/14] tools: Separate nwfilter 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.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 19 Jul 2019 08:49:15 +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 nwfilter (e.g. they complete various nwfilter aspects) into virsh-completer-nwfilter.c Signed-off-by: Michal Privoznik --- tools/Makefile.am | 1 + tools/virsh-completer-nwfilter.c | 105 +++++++++++++++++++++++++++++++ tools/virsh-completer-nwfilter.h | 31 +++++++++ tools/virsh-completer.c | 80 ----------------------- tools/virsh-completer.h | 9 +-- 5 files changed, 138 insertions(+), 88 deletions(-) create mode 100644 tools/virsh-completer-nwfilter.c create mode 100644 tools/virsh-completer-nwfilter.h diff --git a/tools/Makefile.am b/tools/Makefile.am index 22f476a1c2..513154729a 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -221,6 +221,7 @@ virsh_SOURCES =3D \ 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-nwfilter.c virsh-completer-nwfilter.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-nwfilter.c b/tools/virsh-completer-nwfil= ter.c new file mode 100644 index 0000000000..0942526f22 --- /dev/null +++ b/tools/virsh-completer-nwfilter.c @@ -0,0 +1,105 @@ +/* + * virsh-completer-nwfilter.c: virsh completer callbacks related to nwfilt= ers + * + * 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-nwfilter.h" +#include "viralloc.h" +#include "virsh.h" +#include "virstring.h" + +char ** +virshNWFilterNameCompleter(vshControl *ctl, + const vshCmd *cmd ATTRIBUTE_UNUSED, + unsigned int flags) +{ + virshControlPtr priv =3D ctl->privData; + virNWFilterPtr *nwfilters =3D NULL; + int nnwfilters =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 ((nnwfilters =3D virConnectListAllNWFilters(priv->conn, &nwfilters,= flags)) < 0) + return NULL; + + if (VIR_ALLOC_N(tmp, nnwfilters + 1) < 0) + goto cleanup; + + for (i =3D 0; i < nnwfilters; i++) { + const char *name =3D virNWFilterGetName(nwfilters[i]); + + if (VIR_STRDUP(tmp[i], name) < 0) + goto cleanup; + } + + VIR_STEAL_PTR(ret, tmp); + + cleanup: + for (i =3D 0; i < nnwfilters; i++) + virNWFilterFree(nwfilters[i]); + VIR_FREE(nwfilters); + return ret; +} + + +char ** +virshNWFilterBindingNameCompleter(vshControl *ctl, + const vshCmd *cmd ATTRIBUTE_UNUSED, + unsigned int flags) +{ + virshControlPtr priv =3D ctl->privData; + virNWFilterBindingPtr *bindings =3D NULL; + int nbindings =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 ((nbindings =3D virConnectListAllNWFilterBindings(priv->conn, &bind= ings, flags)) < 0) + return NULL; + + if (VIR_ALLOC_N(tmp, nbindings + 1) < 0) + goto cleanup; + + for (i =3D 0; i < nbindings; i++) { + const char *name =3D virNWFilterBindingGetPortDev(bindings[i]); + + if (VIR_STRDUP(tmp[i], name) < 0) + goto cleanup; + } + + VIR_STEAL_PTR(ret, tmp); + + cleanup: + for (i =3D 0; i < nbindings; i++) + virNWFilterBindingFree(bindings[i]); + VIR_FREE(bindings); + return ret; +} diff --git a/tools/virsh-completer-nwfilter.h b/tools/virsh-completer-nwfil= ter.h new file mode 100644 index 0000000000..86e7df7da4 --- /dev/null +++ b/tools/virsh-completer-nwfilter.h @@ -0,0 +1,31 @@ +/* + * virsh-completer-nwfilter.h: virsh completer callbacks related to nwfilt= ers + * + * 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 ** virshNWFilterNameCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); + +char ** virshNWFilterBindingNameCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index 0b99b3d578..174bd372ce 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -143,86 +143,6 @@ virshCommaStringListComplete(const char *input, } =20 =20 -char ** -virshNWFilterNameCompleter(vshControl *ctl, - const vshCmd *cmd ATTRIBUTE_UNUSED, - unsigned int flags) -{ - virshControlPtr priv =3D ctl->privData; - virNWFilterPtr *nwfilters =3D NULL; - int nnwfilters =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 ((nnwfilters =3D virConnectListAllNWFilters(priv->conn, &nwfilters,= flags)) < 0) - return NULL; - - if (VIR_ALLOC_N(tmp, nnwfilters + 1) < 0) - goto cleanup; - - for (i =3D 0; i < nnwfilters; i++) { - const char *name =3D virNWFilterGetName(nwfilters[i]); - - if (VIR_STRDUP(tmp[i], name) < 0) - goto cleanup; - } - - VIR_STEAL_PTR(ret, tmp); - - cleanup: - for (i =3D 0; i < nnwfilters; i++) - virNWFilterFree(nwfilters[i]); - VIR_FREE(nwfilters); - return ret; -} - - -char ** -virshNWFilterBindingNameCompleter(vshControl *ctl, - const vshCmd *cmd ATTRIBUTE_UNUSED, - unsigned int flags) -{ - virshControlPtr priv =3D ctl->privData; - virNWFilterBindingPtr *bindings =3D NULL; - int nbindings =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 ((nbindings =3D virConnectListAllNWFilterBindings(priv->conn, &bind= ings, flags)) < 0) - return NULL; - - if (VIR_ALLOC_N(tmp, nbindings + 1) < 0) - goto cleanup; - - for (i =3D 0; i < nbindings; i++) { - const char *name =3D virNWFilterBindingGetPortDev(bindings[i]); - - if (VIR_STRDUP(tmp[i], name) < 0) - goto cleanup; - } - - VIR_STEAL_PTR(ret, tmp); - - cleanup: - for (i =3D 0; i < nbindings; i++) - virNWFilterBindingFree(bindings[i]); - VIR_FREE(bindings); - return ret; -} - - char ** virshSecretUUIDCompleter(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED, diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h index 39896c13c5..20bf73b4e5 100644 --- a/tools/virsh-completer.h +++ b/tools/virsh-completer.h @@ -26,20 +26,13 @@ #include "virsh-completer-interface.h" #include "virsh-completer-network.h" #include "virsh-completer-nodedev.h" +#include "virsh-completer-nwfilter.h" #include "virsh-completer-pool.h" #include "virsh-completer-volume.h" =20 char ** virshCommaStringListComplete(const char *input, const char **options); =20 -char ** virshNWFilterNameCompleter(vshControl *ctl, - const vshCmd *cmd, - unsigned int flags); - -char ** virshNWFilterBindingNameCompleter(vshControl *ctl, - const vshCmd *cmd, - unsigned int flags); - char ** virshSecretUUIDCompleter(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 From nobody Sun May 5 20:53:19 2024 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=1563526137; cv=none; d=zoho.com; s=zohoarc; b=LCVN/hj7LJzcPh9/G/tNRMrq1i8dD5I8985eNiTId8jbVDukHMCoezL8Y7WSQVVSMhEwR0AEsdTs+adkHc+quCDUH5MxlZXzceUZbx4RLVDDSAdFqgc4WaV4xqxmunIEj6uT00T5sjWWpmb7pLKOV3BmzrsRQgv3+QbfSnvlgiU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563526137; 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=Bft73F5QgYphYrUPJZunR7PDW+gJYXU5EQmrqrhRfE4=; b=V/xtM2guKWSsADtKDY/EgVuZIjkHM5o9VUTblvX/NDxc7pamKtrAcdd/Yq2r6sI6djviPmUcA3ekecWCjy5S4+yJNHu1+g3sXlT5GZcsATB3vNZH0KIH6x8YPuN59uvreAnr5d9D+NKFm1wEFdCy0vELZLo0/tjTU5ftWVFFeDg= 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 1563526137494104.85079225457855; Fri, 19 Jul 2019 01:48:57 -0700 (PDT) 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 A6B34C057E29; Fri, 19 Jul 2019 08:48:55 +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 7EFB5643E1; Fri, 19 Jul 2019 08:48:55 +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 449571800205; Fri, 19 Jul 2019 08:48:55 +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 x6J8mqDO005267 for ; Fri, 19 Jul 2019 04:48:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id B382960126; Fri, 19 Jul 2019 08:48:52 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3E54B61369 for ; Fri, 19 Jul 2019 08:48:50 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Fri, 19 Jul 2019 10:48:34 +0200 Message-Id: <3cab0099a1740e5d37dac12c02afb193d196fdc2.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 10/14] tools: Separate secret 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 19 Jul 2019 08:48:56 +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 secret (e.g. they complete various secret aspects) into virsh-completer-secret.c Signed-off-by: Michal Privoznik --- tools/Makefile.am | 1 + tools/virsh-completer-secret.c | 91 ++++++++++++++++++++++++++++++++++ tools/virsh-completer-secret.h | 31 ++++++++++++ tools/virsh-completer.c | 65 ------------------------ tools/virsh-completer.h | 9 +--- 5 files changed, 124 insertions(+), 73 deletions(-) create mode 100644 tools/virsh-completer-secret.c create mode 100644 tools/virsh-completer-secret.h diff --git a/tools/Makefile.am b/tools/Makefile.am index 513154729a..c24cab80fd 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -223,6 +223,7 @@ virsh_SOURCES =3D \ virsh-completer-nodedev.c virsh-completer-nodedev.h \ virsh-completer-nwfilter.c virsh-completer-nwfilter.h \ virsh-completer-pool.c virsh-completer-pool.h \ + virsh-completer-secret.c virsh-completer-secret.h \ virsh-completer-volume.c virsh-completer-volume.h \ virsh-console.c virsh-console.h \ virsh-domain.c virsh-domain.h \ diff --git a/tools/virsh-completer-secret.c b/tools/virsh-completer-secret.c new file mode 100644 index 0000000000..a6924b6b8c --- /dev/null +++ b/tools/virsh-completer-secret.c @@ -0,0 +1,91 @@ +/* + * virsh-completer-secret.c: virsh completer callbacks related to secret + * + * 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-secret.h" +#include "viralloc.h" +#include "virsh-secret.h" +#include "virsh.h" +#include "virstring.h" + +char ** +virshSecretUUIDCompleter(vshControl *ctl, + const vshCmd *cmd ATTRIBUTE_UNUSED, + unsigned int flags) +{ + virshControlPtr priv =3D ctl->privData; + virSecretPtr *secrets =3D NULL; + int nsecrets =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 ((nsecrets =3D virConnectListAllSecrets(priv->conn, &secrets, flags= )) < 0) + return NULL; + + if (VIR_ALLOC_N(tmp, nsecrets + 1) < 0) + goto cleanup; + + for (i =3D 0; i < nsecrets; i++) { + char uuid[VIR_UUID_STRING_BUFLEN]; + + if (virSecretGetUUIDString(secrets[i], uuid) < 0 || + VIR_STRDUP(tmp[i], uuid) < 0) + goto cleanup; + } + + VIR_STEAL_PTR(ret, tmp); + + cleanup: + for (i =3D 0; i < nsecrets; i++) + virSecretFree(secrets[i]); + VIR_FREE(secrets); + return ret; +} + + +char ** +virshSecretEventNameCompleter(vshControl *ctl ATTRIBUTE_UNUSED, + const vshCmd *cmd ATTRIBUTE_UNUSED, + unsigned int flags) +{ + size_t i; + char **ret =3D NULL; + VIR_AUTOSTRINGLIST tmp =3D NULL; + + virCheckFlags(0, NULL); + + if (VIR_ALLOC_N(tmp, VIR_SECRET_EVENT_ID_LAST + 1) < 0) + return NULL; + + for (i =3D 0; i < VIR_SECRET_EVENT_ID_LAST; i++) { + if (VIR_STRDUP(tmp[i], virshSecretEventCallbacks[i].name) < 0) + return NULL; + } + + VIR_STEAL_PTR(ret, tmp); + return ret; +} diff --git a/tools/virsh-completer-secret.h b/tools/virsh-completer-secret.h new file mode 100644 index 0000000000..3ed6ba5198 --- /dev/null +++ b/tools/virsh-completer-secret.h @@ -0,0 +1,31 @@ +/* + * virsh-completer-secret.h: virsh completer callbacks related to secret + * + * 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 ** virshSecretUUIDCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); + +char ** virshSecretEventNameCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index 174bd372ce..04ca2c919c 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -143,47 +143,6 @@ virshCommaStringListComplete(const char *input, } =20 =20 -char ** -virshSecretUUIDCompleter(vshControl *ctl, - const vshCmd *cmd ATTRIBUTE_UNUSED, - unsigned int flags) -{ - virshControlPtr priv =3D ctl->privData; - virSecretPtr *secrets =3D NULL; - int nsecrets =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 ((nsecrets =3D virConnectListAllSecrets(priv->conn, &secrets, flags= )) < 0) - return NULL; - - if (VIR_ALLOC_N(tmp, nsecrets + 1) < 0) - goto cleanup; - - for (i =3D 0; i < nsecrets; i++) { - char uuid[VIR_UUID_STRING_BUFLEN]; - - if (virSecretGetUUIDString(secrets[i], uuid) < 0 || - VIR_STRDUP(tmp[i], uuid) < 0) - goto cleanup; - } - - VIR_STEAL_PTR(ret, tmp); - - cleanup: - for (i =3D 0; i < nsecrets; i++) - virSecretFree(secrets[i]); - VIR_FREE(secrets); - return ret; -} - - char ** virshSnapshotNameCompleter(vshControl *ctl, const vshCmd *cmd, @@ -308,30 +267,6 @@ virshAllocpagesPagesizeCompleter(vshControl *ctl, } =20 =20 -char ** -virshSecretEventNameCompleter(vshControl *ctl ATTRIBUTE_UNUSED, - const vshCmd *cmd ATTRIBUTE_UNUSED, - unsigned int flags) -{ - size_t i; - char **ret =3D NULL; - VIR_AUTOSTRINGLIST tmp =3D NULL; - - virCheckFlags(0, NULL); - - if (VIR_ALLOC_N(tmp, VIR_SECRET_EVENT_ID_LAST + 1) < 0) - return NULL; - - for (i =3D 0; i < VIR_SECRET_EVENT_ID_LAST; i++) { - if (VIR_STRDUP(tmp[i], virshSecretEventCallbacks[i].name) < 0) - return NULL; - } - - VIR_STEAL_PTR(ret, tmp); - return ret; -} - - char ** virshCellnoCompleter(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED, diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h index 20bf73b4e5..2dc9e95f1c 100644 --- a/tools/virsh-completer.h +++ b/tools/virsh-completer.h @@ -28,15 +28,12 @@ #include "virsh-completer-nodedev.h" #include "virsh-completer-nwfilter.h" #include "virsh-completer-pool.h" +#include "virsh-completer-secret.h" #include "virsh-completer-volume.h" =20 char ** virshCommaStringListComplete(const char *input, const char **options); =20 -char ** virshSecretUUIDCompleter(vshControl *ctl, - const vshCmd *cmd, - unsigned int flags); - char ** virshSnapshotNameCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); @@ -45,10 +42,6 @@ char ** virshAllocpagesPagesizeCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); =20 -char ** virshSecretEventNameCompleter(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 From nobody Sun May 5 20:53:19 2024 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=1563526160; cv=none; d=zoho.com; s=zohoarc; b=YOQZUwLicONFK8IeGcuD/J+bEmiR39GLvIutAK5IBlFIpdRKmtdonKAEM9bSmQ4hYqBY1sqcUaWa7nUYdR5sf4pOU+bxma+848L3MFQUOS07vj9JpFf12zKiViVZQ3Zi0txKc5tgqRFFvHQif4aOK8BqcK1f+6x4xCJHqyiWZ6M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563526160; 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=Jpqe8cDr41hselc2VXYe1UMnOySl5VbSS901MvAxFxM=; b=fu02M34P1bkG2VsCEegZc9ZmT9v0ZBEbXlGHstMxCNhle4eCch/wl+MOG42I48YNM2QvdYXcwmoJt1Lokdi8ITWRJZFDD+Y/TCeknoV/6LmmtA25j8rHPl8poXdWr6PhibAuO4amLVJcXJEdmLNMp4dbSfHn8Ra3gw4iv9DrElY= 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 1563526160697384.52262536596675; Fri, 19 Jul 2019 01:49:20 -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 1AA34307D974; Fri, 19 Jul 2019 08:49:19 +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 E1453610AF; Fri, 19 Jul 2019 08:49:18 +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 A050918045E0; Fri, 19 Jul 2019 08:49:18 +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 x6J8mrcY005277 for ; Fri, 19 Jul 2019 04:48:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7FE4C60126; Fri, 19 Jul 2019 08:48:53 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0ADA46134E for ; Fri, 19 Jul 2019 08:48:52 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Fri, 19 Jul 2019 10:48:35 +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 11/14] tools: Separate snapshot 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.48]); Fri, 19 Jul 2019 08:49:19 +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 snapshot (e.g. they complete various snapshot aspects) into virsh-completer-snapshot.c Signed-off-by: Michal Privoznik --- tools/Makefile.am | 1 + tools/virsh-completer-snapshot.c | 73 ++++++++++++++++++++++++++++++++ tools/virsh-completer-snapshot.h | 27 ++++++++++++ tools/virsh-completer.c | 48 --------------------- tools/virsh-completer.h | 5 +-- 5 files changed, 102 insertions(+), 52 deletions(-) create mode 100644 tools/virsh-completer-snapshot.c create mode 100644 tools/virsh-completer-snapshot.h diff --git a/tools/Makefile.am b/tools/Makefile.am index c24cab80fd..231ee0e0bd 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -224,6 +224,7 @@ virsh_SOURCES =3D \ virsh-completer-nwfilter.c virsh-completer-nwfilter.h \ virsh-completer-pool.c virsh-completer-pool.h \ virsh-completer-secret.c virsh-completer-secret.h \ + virsh-completer-snapshot.c virsh-completer-snapshot.h \ virsh-completer-volume.c virsh-completer-volume.h \ virsh-console.c virsh-console.h \ virsh-domain.c virsh-domain.h \ diff --git a/tools/virsh-completer-snapshot.c b/tools/virsh-completer-snaps= hot.c new file mode 100644 index 0000000000..cad56e2fba --- /dev/null +++ b/tools/virsh-completer-snapshot.c @@ -0,0 +1,73 @@ +/* + * virsh-completer-snapshot.c: virsh completer callbacks related to snapsh= ots + * + * 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-snapshot.h" +#include "viralloc.h" +#include "virsh-util.h" +#include "virsh.h" +#include "virstring.h" + +char ** +virshSnapshotNameCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags) +{ + virshControlPtr priv =3D ctl->privData; + virDomainPtr dom =3D NULL; + virDomainSnapshotPtr *snapshots =3D NULL; + int rc; + int nsnapshots =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 (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + return NULL; + + if ((rc =3D virDomainListAllSnapshots(dom, &snapshots, flags)) < 0) + goto cleanup; + nsnapshots =3D rc; + + if (VIR_ALLOC_N(tmp, nsnapshots + 1) < 0) + goto cleanup; + + for (i =3D 0; i < nsnapshots; i++) { + const char *name =3D virDomainSnapshotGetName(snapshots[i]); + + if (VIR_STRDUP(tmp[i], name) < 0) + goto cleanup; + } + + VIR_STEAL_PTR(ret, tmp); + + cleanup: + virshDomainFree(dom); + for (i =3D 0; i < nsnapshots; i++) + virshDomainSnapshotFree(snapshots[i]); + VIR_FREE(snapshots); + return ret; +} diff --git a/tools/virsh-completer-snapshot.h b/tools/virsh-completer-snaps= hot.h new file mode 100644 index 0000000000..1af32e28ca --- /dev/null +++ b/tools/virsh-completer-snapshot.h @@ -0,0 +1,27 @@ +/* + * virsh-completer-snapshot.h: virsh completer callbacks related to snapsh= ots + * + * 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 ** virshSnapshotNameCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index 04ca2c919c..fc46cb6575 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -141,54 +141,6 @@ virshCommaStringListComplete(const char *input, =20 VIR_RETURN_PTR(ret); } - - -char ** -virshSnapshotNameCompleter(vshControl *ctl, - const vshCmd *cmd, - unsigned int flags) -{ - virshControlPtr priv =3D ctl->privData; - virDomainPtr dom =3D NULL; - virDomainSnapshotPtr *snapshots =3D NULL; - int rc; - int nsnapshots =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 (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) - return NULL; - - if ((rc =3D virDomainListAllSnapshots(dom, &snapshots, flags)) < 0) - goto cleanup; - nsnapshots =3D rc; - - if (VIR_ALLOC_N(tmp, nsnapshots + 1) < 0) - goto cleanup; - - for (i =3D 0; i < nsnapshots; i++) { - const char *name =3D virDomainSnapshotGetName(snapshots[i]); - - if (VIR_STRDUP(tmp[i], name) < 0) - goto cleanup; - } - - VIR_STEAL_PTR(ret, tmp); - - cleanup: - virshDomainFree(dom); - for (i =3D 0; i < nsnapshots; i++) - virshDomainSnapshotFree(snapshots[i]); - VIR_FREE(snapshots); - return ret; -} - static char * virshPagesizeNodeToString(xmlNodePtr node) { diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h index 2dc9e95f1c..79a41c0a8a 100644 --- a/tools/virsh-completer.h +++ b/tools/virsh-completer.h @@ -29,15 +29,12 @@ #include "virsh-completer-nwfilter.h" #include "virsh-completer-pool.h" #include "virsh-completer-secret.h" +#include "virsh-completer-snapshot.h" #include "virsh-completer-volume.h" =20 char ** virshCommaStringListComplete(const char *input, const char **options); =20 -char ** virshSnapshotNameCompleter(vshControl *ctl, - const vshCmd *cmd, - unsigned int flags); - char ** virshAllocpagesPagesizeCompleter(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 From nobody Sun May 5 20:53:19 2024 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=1563526141; cv=none; d=zoho.com; s=zohoarc; b=GPduoIA8g/MobpDzFez/4sd1bICOmRXfYIDTxGwZ0Wpf61Q6HlWCGHSqJ4dCCg06qUIaYFqcm4prtVLGE6BJEOw2RCfIFbHico/WZgly6AIcEyCHLX/ku+pTjirlc/vG3G4UalKGph8Z/9Jd9z0ZXv2eQY0cmzXzlANzCZVd4hY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563526141; 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=iNWpPDMDIPfDDGWgpjcK6waYQFlU8oR/uk2ldA2zV68=; b=TCP5Zf5NRxtdkUzAI7gLmPF61YtPix7EIPh6tjmCIMJFjYU330wFr7dEuScHOPbconpBfuhhnmPfm67OoVhx4Gs0w8CQMIIUoFzzTJg/2t0gkThv48TiloJTM3eEjG+hQW0ZPGaAhJLU4FJayXkRE/bhaclOCfNq81KQsF2Cq/4= 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 1563526141486634.966343647617; Fri, 19 Jul 2019 01:49:01 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BF9FD30860D7; Fri, 19 Jul 2019 08:48:59 +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 948A061B6A; Fri, 19 Jul 2019 08:48:59 +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 518EF180020A; Fri, 19 Jul 2019 08:48:59 +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 x6J8muWv005293 for ; Fri, 19 Jul 2019 04:48:56 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3B235601A9; Fri, 19 Jul 2019 08:48:56 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id B9AB260126 for ; Fri, 19 Jul 2019 08:48:53 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Fri, 19 Jul 2019 10:48:36 +0200 Message-Id: <47074637045654218ac04a868ac20c043bee54e8.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 12/14] tools: Separate host 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Fri, 19 Jul 2019 08:49:00 +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 host (e.g. they complete various host aspects) into virsh-completer-host.c Signed-off-by: Michal Privoznik --- tools/Makefile.am | 1 + tools/virsh-completer-host.c | 148 +++++++++++++++++++++++++++++++++++ tools/virsh-completer-host.h | 31 ++++++++ tools/virsh-completer.c | 119 ---------------------------- tools/virsh-completer.h | 9 +-- 5 files changed, 181 insertions(+), 127 deletions(-) create mode 100644 tools/virsh-completer-host.c create mode 100644 tools/virsh-completer-host.h diff --git a/tools/Makefile.am b/tools/Makefile.am index 231ee0e0bd..2364812e73 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -218,6 +218,7 @@ virsh_SOURCES =3D \ virsh.c virsh.h \ virsh-completer.c virsh-completer.h \ virsh-completer-domain.c virsh-completer-domain.h \ + virsh-completer-host.c virsh-completer-host.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 \ diff --git a/tools/virsh-completer-host.c b/tools/virsh-completer-host.c new file mode 100644 index 0000000000..7e31ca2bf3 --- /dev/null +++ b/tools/virsh-completer-host.c @@ -0,0 +1,148 @@ +/* + * virsh-completer-host.c: virsh completer callbacks related to host + * + * 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-host.h" +#include "viralloc.h" +#include "virsh.h" +#include "virstring.h" +#include "virxml.h" +#include "virutil.h" + +static char * +virshPagesizeNodeToString(xmlNodePtr node) +{ + VIR_AUTOFREE(char *) pagesize =3D NULL; + VIR_AUTOFREE(char *) unit =3D NULL; + unsigned long long byteval =3D 0; + const char *suffix =3D NULL; + double size =3D 0; + char *ret; + + pagesize =3D virXMLPropString(node, "size"); + unit =3D virXMLPropString(node, "unit"); + if (virStrToLong_ull(pagesize, NULL, 10, &byteval) < 0) + return NULL; + if (virScaleInteger(&byteval, unit, 1024, UINT_MAX) < 0) + return NULL; + size =3D vshPrettyCapacity(byteval, &suffix); + if (virAsprintf(&ret, "%.0f%s", size, suffix) < 0) + return NULL; + return ret; +} + +char ** +virshAllocpagesPagesizeCompleter(vshControl *ctl, + const vshCmd *cmd ATTRIBUTE_UNUSED, + unsigned int flags) +{ + VIR_AUTOPTR(xmlXPathContext) ctxt =3D NULL; + virshControlPtr priv =3D ctl->privData; + unsigned int npages =3D 0; + VIR_AUTOFREE(xmlNodePtr *) pages =3D NULL; + VIR_AUTOPTR(xmlDoc) doc =3D NULL; + size_t i =3D 0; + const char *cellnum =3D NULL; + bool cellno =3D vshCommandOptBool(cmd, "cellno"); + VIR_AUTOFREE(char *) path =3D NULL; + VIR_AUTOFREE(char *) cap_xml =3D NULL; + char **ret =3D NULL; + VIR_AUTOSTRINGLIST tmp =3D NULL; + + virCheckFlags(0, NULL); + + if (!priv->conn || virConnectIsAlive(priv->conn) <=3D 0) + return NULL; + + if (!(cap_xml =3D virConnectGetCapabilities(priv->conn))) + return NULL; + + if (!(doc =3D virXMLParseStringCtxt(cap_xml, _("capabilities"), &ctxt)= )) + return NULL; + + if (cellno && vshCommandOptStringQuiet(ctl, cmd, "cellno", &cellnum) >= 0) { + if (virAsprintf(&path, + "/capabilities/host/topology/cells/cell[@id=3D\"%s= \"]/pages", + cellnum) < 0) + return NULL; + } else { + if (virAsprintf(&path, "/capabilities/host/cpu/pages") < 0) + return NULL; + } + + npages =3D virXPathNodeSet(path, ctxt, &pages); + if (npages <=3D 0) + return NULL; + + if (VIR_ALLOC_N(tmp, npages + 1) < 0) + return NULL; + + for (i =3D 0; i < npages; i++) { + if (!(tmp[i] =3D virshPagesizeNodeToString(pages[i]))) + return NULL; + } + + VIR_STEAL_PTR(ret, tmp); + return ret; +} + + +char ** +virshCellnoCompleter(vshControl *ctl, + const vshCmd *cmd ATTRIBUTE_UNUSED, + unsigned int flags) +{ + VIR_AUTOPTR(xmlXPathContext) ctxt =3D NULL; + virshControlPtr priv =3D ctl->privData; + unsigned int ncells =3D 0; + VIR_AUTOFREE(xmlNodePtr *) cells =3D NULL; + VIR_AUTOPTR(xmlDoc) doc =3D NULL; + size_t i =3D 0; + VIR_AUTOFREE(char *) cap_xml =3D NULL; + char **ret =3D NULL; + VIR_AUTOSTRINGLIST tmp =3D NULL; + + virCheckFlags(0, NULL); + + if (!priv->conn || virConnectIsAlive(priv->conn) <=3D 0) + return NULL; + + if (!(cap_xml =3D virConnectGetCapabilities(priv->conn))) + return NULL; + + if (!(doc =3D virXMLParseStringCtxt(cap_xml, _("capabilities"), &ctxt)= )) + return NULL; + + ncells =3D virXPathNodeSet("/capabilities/host/topology/cells/cell", c= txt, &cells); + if (ncells <=3D 0) + return NULL; + + if (VIR_ALLOC_N(tmp, ncells + 1)) + return NULL; + + for (i =3D 0; i < ncells; i++) { + if (!(tmp[i] =3D virXMLPropString(cells[i], "id"))) + return NULL; + } + + VIR_STEAL_PTR(ret, tmp); + return ret; +} diff --git a/tools/virsh-completer-host.h b/tools/virsh-completer-host.h new file mode 100644 index 0000000000..921beb7a2d --- /dev/null +++ b/tools/virsh-completer-host.h @@ -0,0 +1,31 @@ +/* + * virsh-completer-host.h: virsh completer callbacks related to host + * + * 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 ** virshAllocpagesPagesizeCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); + +char ** virshCellnoCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index fc46cb6575..0f1709b4ba 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -141,122 +141,3 @@ virshCommaStringListComplete(const char *input, =20 VIR_RETURN_PTR(ret); } -static char * -virshPagesizeNodeToString(xmlNodePtr node) -{ - VIR_AUTOFREE(char *) pagesize =3D NULL; - VIR_AUTOFREE(char *) unit =3D NULL; - unsigned long long byteval =3D 0; - const char *suffix =3D NULL; - double size =3D 0; - char *ret; - - pagesize =3D virXMLPropString(node, "size"); - unit =3D virXMLPropString(node, "unit"); - if (virStrToLong_ull(pagesize, NULL, 10, &byteval) < 0) - return NULL; - if (virScaleInteger(&byteval, unit, 1024, UINT_MAX) < 0) - return NULL; - size =3D vshPrettyCapacity(byteval, &suffix); - if (virAsprintf(&ret, "%.0f%s", size, suffix) < 0) - return NULL; - return ret; -} - -char ** -virshAllocpagesPagesizeCompleter(vshControl *ctl, - const vshCmd *cmd ATTRIBUTE_UNUSED, - unsigned int flags) -{ - VIR_AUTOPTR(xmlXPathContext) ctxt =3D NULL; - virshControlPtr priv =3D ctl->privData; - unsigned int npages =3D 0; - VIR_AUTOFREE(xmlNodePtr *) pages =3D NULL; - VIR_AUTOPTR(xmlDoc) doc =3D NULL; - size_t i =3D 0; - const char *cellnum =3D NULL; - bool cellno =3D vshCommandOptBool(cmd, "cellno"); - VIR_AUTOFREE(char *) path =3D NULL; - VIR_AUTOFREE(char *) cap_xml =3D NULL; - char **ret =3D NULL; - VIR_AUTOSTRINGLIST tmp =3D NULL; - - virCheckFlags(0, NULL); - - if (!priv->conn || virConnectIsAlive(priv->conn) <=3D 0) - return NULL; - - if (!(cap_xml =3D virConnectGetCapabilities(priv->conn))) - return NULL; - - if (!(doc =3D virXMLParseStringCtxt(cap_xml, _("capabilities"), &ctxt)= )) - return NULL; - - if (cellno && vshCommandOptStringQuiet(ctl, cmd, "cellno", &cellnum) >= 0) { - if (virAsprintf(&path, - "/capabilities/host/topology/cells/cell[@id=3D\"%s= \"]/pages", - cellnum) < 0) - return NULL; - } else { - if (virAsprintf(&path, "/capabilities/host/cpu/pages") < 0) - return NULL; - } - - npages =3D virXPathNodeSet(path, ctxt, &pages); - if (npages <=3D 0) - return NULL; - - if (VIR_ALLOC_N(tmp, npages + 1) < 0) - return NULL; - - for (i =3D 0; i < npages; i++) { - if (!(tmp[i] =3D virshPagesizeNodeToString(pages[i]))) - return NULL; - } - - VIR_STEAL_PTR(ret, tmp); - return ret; -} - - -char ** -virshCellnoCompleter(vshControl *ctl, - const vshCmd *cmd ATTRIBUTE_UNUSED, - unsigned int flags) -{ - VIR_AUTOPTR(xmlXPathContext) ctxt =3D NULL; - virshControlPtr priv =3D ctl->privData; - unsigned int ncells =3D 0; - VIR_AUTOFREE(xmlNodePtr *) cells =3D NULL; - VIR_AUTOPTR(xmlDoc) doc =3D NULL; - size_t i =3D 0; - VIR_AUTOFREE(char *) cap_xml =3D NULL; - char **ret =3D NULL; - VIR_AUTOSTRINGLIST tmp =3D NULL; - - virCheckFlags(0, NULL); - - if (!priv->conn || virConnectIsAlive(priv->conn) <=3D 0) - return NULL; - - if (!(cap_xml =3D virConnectGetCapabilities(priv->conn))) - return NULL; - - if (!(doc =3D virXMLParseStringCtxt(cap_xml, _("capabilities"), &ctxt)= )) - return NULL; - - ncells =3D virXPathNodeSet("/capabilities/host/topology/cells/cell", c= txt, &cells); - if (ncells <=3D 0) - return NULL; - - if (VIR_ALLOC_N(tmp, ncells + 1)) - return NULL; - - for (i =3D 0; i < ncells; i++) { - if (!(tmp[i] =3D virXMLPropString(cells[i], "id"))) - return NULL; - } - - VIR_STEAL_PTR(ret, tmp); - return ret; -} diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h index 79a41c0a8a..7ea3345973 100644 --- a/tools/virsh-completer.h +++ b/tools/virsh-completer.h @@ -23,6 +23,7 @@ #include "vsh.h" =20 #include "virsh-completer-domain.h" +#include "virsh-completer-host.h" #include "virsh-completer-interface.h" #include "virsh-completer-network.h" #include "virsh-completer-nodedev.h" @@ -34,11 +35,3 @@ =20 char ** virshCommaStringListComplete(const char *input, const char **options); - -char ** virshAllocpagesPagesizeCompleter(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 From nobody Sun May 5 20:53:19 2024 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=1563526164; cv=none; d=zoho.com; s=zohoarc; b=Uuy7zZoUcZL1TiTiNBB2vfAHlH7P8uHss0VPR//reLcA+nIvtXoFJpomTI79+FnvkFhqZeY4aLGMskit/wMlfnQjGwOvZIIhbvn5Hu7tVONHcdSjLJCiTMBHi7uP2y8o2O1IVUf0gyvmTCAraRIsD8NlyCGa3lltFHl8AM1s+EE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563526164; 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=zNfuCpMZvsK5BoqtXkUQ+5DQxT4/qY4j5uzwg+deB7Y=; b=CeEKhlWT41kRLUjJgi75CPrKkCrTHYP7QCRcbXTRgQrOSGPjLo2AEwLIlyjqPIiocxDNTjuVu0K4eIbKDz9/co4CGo5d4PMZAtsa/v6F5/3vv2Aj1NRdqdU3q5wb2eKCoOz09XhWz0ysIo4R07tDYLOx0NZHc5PZ59kbt2mQM3E= 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 1563526164252730.9436564721163; Fri, 19 Jul 2019 01:49:24 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A001730860DE; Fri, 19 Jul 2019 08:49:22 +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 7056219D7F; Fri, 19 Jul 2019 08:49:22 +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 2D53D1972D; Fri, 19 Jul 2019 08:49:22 +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 x6J8n009005311 for ; Fri, 19 Jul 2019 04:49:00 -0400 Received: by smtp.corp.redhat.com (Postfix) id E964560126; Fri, 19 Jul 2019 08:49:00 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7502A620AD for ; Fri, 19 Jul 2019 08:48:56 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Fri, 19 Jul 2019 10:48:37 +0200 Message-Id: <9a6d0d1923ceda7be09f5a88188204f36f955792.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 13/14] virsh-completer: Drop needless #include 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.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Fri, 19 Jul 2019 08:49:23 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Now that there is no code in virsh-completer.c it doesn't make much sense to keep those #include-s around. Delete them. Signed-off-by: Michal Privoznik --- tools/virsh-completer.c | 13 ------------- tools/virsh-completer.h | 2 -- 2 files changed, 15 deletions(-) diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index 0f1709b4ba..1fa66b4081 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -21,21 +21,8 @@ #include =20 #include "virsh-completer.h" -#include "virsh-domain.h" -#include "virsh.h" -#include "virsh-pool.h" -#include "virsh-nodedev.h" -#include "virsh-util.h" -#include "virsh-secret.h" -#include "virsh-network.h" -#include "internal.h" -#include "virutil.h" #include "viralloc.h" -#include "virmacaddr.h" #include "virstring.h" -#include "virxml.h" -#include "conf/node_device_conf.h" - =20 /** * A completer callback is a function that accepts three arguments: diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h index 7ea3345973..96fdee8ff2 100644 --- a/tools/virsh-completer.h +++ b/tools/virsh-completer.h @@ -20,8 +20,6 @@ =20 #pragma once =20 -#include "vsh.h" - #include "virsh-completer-domain.h" #include "virsh-completer-host.h" #include "virsh-completer-interface.h" --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 20:53:19 2024 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=1563526167; cv=none; d=zoho.com; s=zohoarc; b=j4HS7DSLUgr1Kh3JzoVvbtQAjTGdVJTy1ScgwNh+VK9fVuqAAiU1XpJxekQei0nZsKRJM5+xAyizxEiDdLW9k/6+jzMxNxf44AQxoKjG6kVXqvDR6PAJPPNJWPRTEwyN9zXDdvqs841UT4Tjanvqz3Aq3dFOqiLFgQaRGwBRBH8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563526167; 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=e2wHtygYwjqroJ1PbR0ezaMvy69Rtu8+aU65L0v6b6o=; b=hKIVbcNWM9uR34QtSicTBHrg8DYuLQoWys0BlKvNm9FIkyRkg6tywp9WhnwixW9CGKUFWRyKD943LzT/+yNhqiWnqof8E89YNBUIJCb4b+17GFiDy22VCNnnQYBo2ICXq2+IarbqzQ1eaEciTtNs30tVHYgmpYWDxkNQe8UNa/w= 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 1563526167534359.08135646236417; Fri, 19 Jul 2019 01:49:27 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E96013B71F; Fri, 19 Jul 2019 08:49:25 +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 BE990101E1CE; Fri, 19 Jul 2019 08:49:25 +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 8263319731; Fri, 19 Jul 2019 08:49:25 +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 x6J8n3VC005327 for ; Fri, 19 Jul 2019 04:49:03 -0400 Received: by smtp.corp.redhat.com (Postfix) id B4CAB620BF; Fri, 19 Jul 2019 08:49:03 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3F63B620AD for ; Fri, 19 Jul 2019 08:49:01 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Fri, 19 Jul 2019 10:48:38 +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 14/14] virsh: Introduce virshPoolTypeCompleter 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.84 on 10.5.11.22 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:26 +0000 (UTC) Content-Type: text/plain; charset="utf-8" This completer can be used to complete pool types. Signed-off-by: Michal Privoznik --- tools/virsh-completer-pool.c | 27 +++++++++++++++++++++++++++ tools/virsh-completer-pool.h | 4 ++++ tools/virsh-pool.c | 1 + 3 files changed, 32 insertions(+) diff --git a/tools/virsh-completer-pool.c b/tools/virsh-completer-pool.c index fc01550908..9703589522 100644 --- a/tools/virsh-completer-pool.c +++ b/tools/virsh-completer-pool.c @@ -21,6 +21,7 @@ #include =20 #include "virsh-completer-pool.h" +#include "conf/storage_conf.h" #include "viralloc.h" #include "virsh-pool.h" #include "virsh.h" @@ -91,3 +92,29 @@ virshPoolEventNameCompleter(vshControl *ctl ATTRIBUTE_UN= USED, VIR_STEAL_PTR(ret, tmp); return ret; } + + +char ** +virshPoolTypeCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags) +{ + VIR_AUTOSTRINGLIST tmp =3D NULL; + const char *type_str =3D NULL; + size_t i =3D 0; + + virCheckFlags(0, NULL); + + if (vshCommandOptStringQuiet(ctl, cmd, "type", &type_str) < 0) + return NULL; + + if (VIR_ALLOC_N(tmp, VIR_STORAGE_POOL_LAST + 1) < 0) + return NULL; + + for (i =3D 0; i < VIR_STORAGE_POOL_LAST; i++) { + if (VIR_STRDUP(tmp[i], virStoragePoolTypeToString(i)) < 0) + return NULL; + } + + return virshCommaStringListComplete(type_str, (const char **)tmp); +} diff --git a/tools/virsh-completer-pool.h b/tools/virsh-completer-pool.h index 778ab25df2..510233fb65 100644 --- a/tools/virsh-completer-pool.h +++ b/tools/virsh-completer-pool.h @@ -29,3 +29,7 @@ char ** virshStoragePoolNameCompleter(vshControl *ctl, char ** virshPoolEventNameCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); + +char ** virshPoolTypeCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c index 510d41b508..96ef626346 100644 --- a/tools/virsh-pool.c +++ b/tools/virsh-pool.c @@ -1095,6 +1095,7 @@ static const vshCmdOptDef opts_pool_list[] =3D { }, {.name =3D "type", .type =3D VSH_OT_STRING, + .completer =3D virshPoolTypeCompleter, .help =3D N_("only list pool of specified type(s) (if supported)") }, {.name =3D "details", --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list