From nobody Mon May 6 21:10:48 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=1565166711; cv=none; d=zoho.com; s=zohoarc; b=gsjMt69Zc32o2wYoxgk5OG5kOB/ee/0nUxw0olU9G6pKt+eHJpZMp+K/5RI0UWiFvrGu5IZMBFDXP5cemfeW+qSO8c4ChsrmJvYVPsKzrnu4EMFQNxlvT9Dbovp/PhaS3Nj1ZI6xNARrRm8ib0KbkPcKiI7ToDyDGiBicrrCDFc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565166711; 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=6y7sHfk0kONXvdITipAVVKaScxnoQBswmvEd42aNA+0=; b=FNITruHH9Odn4g7LL1L1vh0wfqQwKfYA09V4NkN0HpaYTZtVh4sRY5M3dATkoUkUfcoLus+KML5iKnawpoyxkYCLgpmEB/mPPNRx36RzQQxoaTD9w4bwAVXEblwVmcZatKeRSba1wq1f5lv8Mhw3XsFqDbXZcLvIgIXOjsjpSY4= 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 1565166711790202.73901989943852; Wed, 7 Aug 2019 01:31:51 -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 7002A30BA1C9; Wed, 7 Aug 2019 08:31:50 +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 461CD6012E; Wed, 7 Aug 2019 08:31:50 +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 025A724C0F; Wed, 7 Aug 2019 08:31:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x778VLFK024995 for ; Wed, 7 Aug 2019 04:31:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id 940061000343; Wed, 7 Aug 2019 08:31:21 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1E3E41000324 for ; Wed, 7 Aug 2019 08:31:20 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 7 Aug 2019 10:30:44 +0200 Message-Id: <72fb88562450a9e5d0d323bb023b8c7659898ff0.1565166420.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 01/15] 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.48]); Wed, 07 Aug 2019 08:31:51 +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 Reviewed-by: Jonathon Jongsma --- 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 4fa6b19225..957db16003 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -1004,9 +1004,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; @@ -1018,7 +1018,7 @@ virshNodedevEventNameCompleter(vshControl *ctl ATTRIB= UTE_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 @@ -1028,9 +1028,9 @@ virshNodedevEventNameCompleter(vshControl *ctl ATTRIB= UTE_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 2e54dddc05..fb41c2c89f 100644 --- a/tools/virsh-completer.h +++ b/tools/virsh-completer.h @@ -106,13 +106,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 Mon May 6 21:10:48 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=1565166687; cv=none; d=zoho.com; s=zohoarc; b=gOKv4fV7cOB1dhXMjsE8LtcgnM63NpnUfJb+x8uqVTWckX/OxoFF05gDYVl4PfR0I5aNy1fry8GxOvHZOTWzi6/LxNpcNSCOU5Jzp3kE4txrl9T1Xuu0q5qepuEmgsh1mHFmx0BAlD32wGjdZjYUvQ7QSUnjkju4L1NP7d/ZPTM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565166687; 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=8gMQGqQOPxCa9w68+ECjCxKE8U+B2/+P+nqdtXVqzC4=; b=cL16PwMSA2B62EyL703sMCL3cviDoQcBu2JIxSpB0La7yJVJLzzgkSxpebOHkbdi4gX6yuVZyiJBvBa4ERwxjOxgealDVvuo3YsTdjS6KY6512Kt8jObFhPn2aws6IYmTXnbkbSMdauWoXLzc8bjtQhREq18CZfVcQytu3uYoFM= 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 1565166687320507.87822559123924; Wed, 7 Aug 2019 01:31:27 -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 9EDD430DD076; Wed, 7 Aug 2019 08:31:25 +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 17BDF5D9E1; Wed, 7 Aug 2019 08:31:24 +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 5D40A18005C7; Wed, 7 Aug 2019 08:31:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x778VMvh025002 for ; Wed, 7 Aug 2019 04:31:22 -0400 Received: by smtp.corp.redhat.com (Postfix) id 619D41001284; Wed, 7 Aug 2019 08:31:22 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id DFC7B1000324 for ; Wed, 7 Aug 2019 08:31:21 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 7 Aug 2019 10:30:45 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 02/15] 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Wed, 07 Aug 2019 08:31:26 +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 Reviewed-by: Jonathon Jongsma --- 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 957db16003..476c3a95c4 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 fb41c2c89f..f7e638d67f 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 Mon May 6 21:10:48 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=1565166695; cv=none; d=zoho.com; s=zohoarc; b=jcXqmf3pgoG4N3XVyFDIzxQqzmM+VexktmJcd2utt3PQHqG8MRxdq+fmG6RknEbYkEqoZ/FAh++HhWTymkCoRUgjPfaXGLssRPmIZY3E03v0c+9oM46YrSEbN8WZZgJcMEv4zfAw0vwjk79mLV/3FItnuEAFNUJyLOGngv9psjk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565166695; 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=+pZSjRgWW+dGVIYcf5lWg5a6i4y+b0t2fKqmL3h+v6Y=; b=H1pxSeWZ/22TNam/kH1MXRI64dfH1/69nZaVx/9SdMdNwm4fhQgWnv5kBU6+ofVrrFnxhyszKSlKCFWuElSjlH0h03Qn35w7GEGcxRQTm9eMtyWiL1xyYvMdh/wCNuiUCu1d/HBVDATx0NngA1rJB/HDpIPKAQJYHAgIaUTXFlc= 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 1565166695683992.7022420266671; Wed, 7 Aug 2019 01:31:35 -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 F0B7230BA1BA; Wed, 7 Aug 2019 08:31:33 +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 C4C5010016E8; Wed, 7 Aug 2019 08:31:33 +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 854C11800B76; Wed, 7 Aug 2019 08:31:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x778VNdB025012 for ; Wed, 7 Aug 2019 04:31:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id 560F01001284; Wed, 7 Aug 2019 08:31:23 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id AEC3C1000324 for ; Wed, 7 Aug 2019 08:31:22 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 7 Aug 2019 10:30:46 +0200 Message-Id: <2c23dd0104cc0a145ac75ffd922589b7b3a66eb2.1565166420.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 03/15] 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.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.48]); Wed, 07 Aug 2019 08:31:34 +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 Reviewed-by: Jonathon Jongsma --- 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 2807b9f6fd..4a3f72b357 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -218,6 +218,7 @@ virsh_SOURCES =3D \ virsh.c virsh.h \ virsh-checkpoint.c virsh-checkpoint.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 476c3a95c4..787bac08f6 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, @@ -892,30 +754,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, @@ -940,69 +778,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, @@ -1094,63 +869,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 f7e638d67f..5a58bd797e 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); @@ -97,18 +83,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); @@ -117,14 +95,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 Mon May 6 21:10:48 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=1565166688; cv=none; d=zoho.com; s=zohoarc; b=RqKWvYl6pPwz7igefFt0BO7RQhZTTcRhVr4OVxO8clXMGqCAjJET8FgYJQUbpr56rud+WStJc/ycK6jkcAUbZwbPdzjY6BVVo3e0+iqA3d9b3WcV5431uupk9rI183Cwafl8fyYiTjHr/SRiLKMn9T9PnAfZJdCkKsBNUTRGq+Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565166688; 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=xnAMxCFnOErmZkPyLCSUbmeK8n/bg8IQmnRhxLR6bsA=; b=aQ7cRZZHYuHF30/1It86/ourTsZ8diWhjLaUvxcWMtgBoIdfBNASLKlr0LpJillvyNf/MylC6zOTuOJtnmxNiNs9+obsX5l/C64A4tFI9uqX8bt8FS3qiWmE9jkWKtSz6OexFJRu5r8nxB1xeEeodAsQW167kcV0jHmESacqR9U= 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 1565166688338509.70089116097677; Wed, 7 Aug 2019 01:31:28 -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 ABF383098444; Wed, 7 Aug 2019 08:31:26 +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 87FBB5D71C; Wed, 7 Aug 2019 08:31:26 +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 081132551C; Wed, 7 Aug 2019 08:31:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x778VO6P025021 for ; Wed, 7 Aug 2019 04:31:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id 245C710016E8; Wed, 7 Aug 2019 08:31:24 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id A2D661001284 for ; Wed, 7 Aug 2019 08:31:23 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 7 Aug 2019 10:30:47 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 04/15] 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.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.42]); Wed, 07 Aug 2019 08:31:27 +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 Reviewed-by: Jonathon Jongsma --- 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 4a3f72b357..a5ce6a45d4 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -219,6 +219,7 @@ virsh_SOURCES =3D \ virsh-checkpoint.c virsh-checkpoint.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 787bac08f6..3b22688562 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, @@ -754,30 +711,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 5a58bd797e..dcfc405331 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); @@ -83,10 +80,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 Mon May 6 21:10:48 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=1565166715; cv=none; d=zoho.com; s=zohoarc; b=eMzgicGzXC3otbPffiZavQKVqFHLbWQA0x8CO5gaYCjvNFs85nXtI9J4IeuLHd17TBiGGofavul5hBSRQM+TRKz7aaSMK3rrSVV/KvnJuxIuM4ijAZazhP8aOSQgzU1VWpox1h6h39bIdCwHcveWvCTAiNBpMZK5FnK3mol47kE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565166715; 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=o44oeB3Jkgv+K9iovm63MAxn18+cC29NoEOL1CtKAck=; b=Q+VoP1Q8csW8JFwYXy3PW7t2E9rjYEBdPTUt2vhBnpzIDgiwmu81XcvSwQVq3cnhQDmppm03GdKyUoatZp+yJHtAWhyJR925Joh7xUcrl42eLQqMip8UIEWqfiZ3pyHQNOILWoPyYZQP2MVYEsfVhHe+hLL5blFGelRFXou2Nkw= 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 1565166715566100.1608222143501; Wed, 7 Aug 2019 01:31:55 -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 DBF7330A00FF; Wed, 7 Aug 2019 08:31:53 +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 B39A05D784; Wed, 7 Aug 2019 08:31:53 +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 74EB6249B0; Wed, 7 Aug 2019 08:31:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x778VO0Z025028 for ; Wed, 7 Aug 2019 04:31:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id E6A0F10001BD; Wed, 7 Aug 2019 08:31:24 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7139D1001284 for ; Wed, 7 Aug 2019 08:31:24 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 7 Aug 2019 10:30:48 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 05/15] 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Wed, 07 Aug 2019 08:31:54 +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 Reviewed-by: Jonathon Jongsma --- 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 a5ce6a45d4..06c05303ed 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -220,6 +220,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 3b22688562..e6f04296a3 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 dcfc405331..e03724824a 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 Mon May 6 21:10:48 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=1565166697; cv=none; d=zoho.com; s=zohoarc; b=Wv3KGRO6O76aDPu/o/zet+ADbBWiL65KuAc8VsORHJdydVYJPJNqUtDC/42Mw7PVJX+OIE9yAGcWPNChF3+FgHdITi0zbm5L0CcpFBCWpGta1SS0VyyELldOkXIaPnr4DJFLVz1VP8SGKZx0VVD071mzyq/LN0vi/W061ouECpw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565166697; 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=v3YUkz/OqBVyFsKC0pZpLKZABJhM7NPXtpyM01Rin7c=; b=lzkkRh7z+8dYd2T+aOI4ymYVJfLHKsJCvK7fLBaLtqeGcGY9w8rCP7g6m8XutRKO6s7+o6jr5HooX8GRLTaNILgojTwSWJn3TaHy+8MTNxuE/zCvZx+ZABdStFcCzRY1PntZbt+wCgHeX5+yoO+Bkbl7S2vsArq7nmeI9RpeOj0= 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 1565166697741172.02463320285722; Wed, 7 Aug 2019 01:31:37 -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 5E69164040; Wed, 7 Aug 2019 08:31:36 +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 29DCC6017E; Wed, 7 Aug 2019 08:31:36 +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 E107F180BA9C; Wed, 7 Aug 2019 08:31:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x778VPQe025033 for ; Wed, 7 Aug 2019 04:31:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id B682E1001284; Wed, 7 Aug 2019 08:31:25 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3F3E810001BD for ; Wed, 7 Aug 2019 08:31:25 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 7 Aug 2019 10:30:49 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 06/15] 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 07 Aug 2019 08:31:36 +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 Reviewed-by: Jonathon Jongsma --- 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 06c05303ed..7e3c9c35c9 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -219,6 +219,7 @@ virsh_SOURCES =3D \ virsh-checkpoint.c virsh-checkpoint.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 e6f04296a3..563ee180b6 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 e03724824a..f50b91c6ed 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 Mon May 6 21:10:48 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=1565166701; cv=none; d=zoho.com; s=zohoarc; b=TrCpJ3tnkgeIGdjd+Uylaw+ndTmubs/VsabLFyCF+zdzK5cOFIB06OijsxCg7PXVIh6YUEw5xGwQl2KnQu22uDW/5BYMuITL4M282biQtnWDr5U/07CYOjVDk7pRTkPmswAhbGWrzCvGTaCu44XljX8ISpaH1vCGazZNvR9xLlk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565166701; 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=Bd5xMhqwQeAnez6PiG4oElOcZT8FVvK/qwlJ1RpeyHQ=; b=EhGnQcY7FPW/lMw5/4TETYe5gAptHciizOhGhCjZlWPbP8LHJtLip/hiIoysWwY4Oz3AL4jN6SoWtdCu54A49SpcOLTxpyyDgoZAe4snroCjBlotGpyE/Mg5O2x5AO5rABowu9fZbX0iTLx91PMhkAPetNaUAV+Wmj5B6vchq4E= 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 1565166701115375.63622983085656; Wed, 7 Aug 2019 01:31:41 -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 D385A30BA1C2; Wed, 7 Aug 2019 08:31:39 +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 AA77F1FD3D; Wed, 7 Aug 2019 08:31:39 +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 6E154180BA9F; Wed, 7 Aug 2019 08:31:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x778VQGY025043 for ; Wed, 7 Aug 2019 04:31:26 -0400 Received: by smtp.corp.redhat.com (Postfix) id 85AF31001938; Wed, 7 Aug 2019 08:31:26 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0E2F61001284 for ; Wed, 7 Aug 2019 08:31:25 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 7 Aug 2019 10:30:50 +0200 Message-Id: <7aeb4b41fafd61007bab674a5a16fb95e1ebaaeb.1565166420.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 07/15] 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.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.48]); Wed, 07 Aug 2019 08:31:40 +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 Reviewed-by: Jonathon Jongsma --- 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 7e3c9c35c9..fb42277269 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -220,6 +220,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 563ee180b6..cc2e92708c 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 f50b91c6ed..6fa5032458 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 Mon May 6 21:10:48 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=1565166718; cv=none; d=zoho.com; s=zohoarc; b=WEfF56YibvVTMbJPubLRsiktTJ47MtXzJsimuPZu8MtX5MBCwOcjBktghc5EYO9qu63OAWZSDYQmqOCqDuxxuAxtq4c6ECuKv2jJbgosdYxXNmy4XlIk42o/35GU5jCrdNZN9FNGZqhvNKPStTy8zVcF0gY80kxNvPTsU4Z7KGo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565166718; 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=TwvdndIsCKGmHCzr45BZ6qUYAr1BKDnZ0mGTJsG5Jv4=; b=aDRkSo1BukY3qPcheKqgOOh06oAKvrPa3XNC+R1BE7yTAJyrDuq2Q12kQ1MhR99w7k3HX/aJZNJw9w94SijRxa5EU09BLpGNGT0wMFvhmPSCRjwB9YFqbYPUb/XuWUN5Tzod9ThtQSDXwcZTFbsOHbXWtvNuo7gHwXnFE3QIKZs= 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 1565166718557232.34193881699036; Wed, 7 Aug 2019 01:31:58 -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 52DB730BA1BF; Wed, 7 Aug 2019 08:31: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 2601B10016E8; Wed, 7 Aug 2019 08:31:57 +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 DA36C206CE; Wed, 7 Aug 2019 08:31:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x778VRBk025058 for ; Wed, 7 Aug 2019 04:31:27 -0400 Received: by smtp.corp.redhat.com (Postfix) id 527AB10016E8; Wed, 7 Aug 2019 08:31:27 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id D158010001BD for ; Wed, 7 Aug 2019 08:31:26 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 7 Aug 2019 10:30:51 +0200 Message-Id: <817f7e55febd50b5fcafdf8891c12e7710c2f59a.1565166420.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 08/15] 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.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.48]); Wed, 07 Aug 2019 08:31: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 nodedev (e.g. they complete various nodedev aspects) into virsh-completer-nodedev.c Signed-off-by: Michal Privoznik Reviewed-by: Jonathon Jongsma --- 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 fb42277269..e31e0f636d 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -221,6 +221,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 cc2e92708c..c9374de97a 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, @@ -503,56 +463,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 6fa5032458..fac7a24dbb 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); @@ -63,14 +60,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 Mon May 6 21:10:48 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=1565166704; cv=none; d=zoho.com; s=zohoarc; b=P8WbMMYu/ZBupfK1CUKuVojNcOW17DKBVtCwHB5DIX5uXryNX0T5EG6QIzpS8dnENjNALnDSz5DqPLBWy0PEYD0OYcKOrx3cY/iZuEuc63+TsmoBFH0m1I7XH3aRrfH82UtKDYRSjuasNoncojktlosuzZoyGiqy1N6Z1gMPaUk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565166704; 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=19wUhjreUEaQbarG1OMCMK9Ooj0QIw6ikRSbrVHJh+U=; b=PyXcN/5bKkREsj6vAY6+AHn6m8q4ayV/f44wlodWH8YhqXJdwoR6ClGzrOh8w28dBdH76zcXSy0bVUwM8xRdeV8kOqKmlYqkOJqCZuczapcJCnBLOBraoDcCJ4zB+oHMehkGKpOaLiO6r3QImDrxXbQbdss8gbQy44KX6PW47oA= 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 15651667046591002.4968745266272; Wed, 7 Aug 2019 01:31:44 -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 5D80730BA1CB; Wed, 7 Aug 2019 08:31:43 +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 352F2546E0; Wed, 7 Aug 2019 08:31:43 +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 E0A0B180BAA3; Wed, 7 Aug 2019 08:31:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x778VSAT025064 for ; Wed, 7 Aug 2019 04:31:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1FF3010016E9; Wed, 7 Aug 2019 08:31:28 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9F3A810016E8 for ; Wed, 7 Aug 2019 08:31:27 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 7 Aug 2019 10:30:52 +0200 Message-Id: <1d26e3f0ccd6e7b8c816ea861ff2b6d1b426795f.1565166420.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 09/15] 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.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.48]); Wed, 07 Aug 2019 08:31:44 +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 Reviewed-by: Jonathon Jongsma --- 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 e31e0f636d..6e6d9a05cc 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -222,6 +222,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 c9374de97a..c985b86fa9 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 fac7a24dbb..5cc5794f58 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 Mon May 6 21:10:48 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=1565166722; cv=none; d=zoho.com; s=zohoarc; b=cpoGkdPqkU+YRobTUNjP7C/nbU08+aDwZf7gNtlVjJVvOYVTYcwesmh/kw5fxprRnzIl8NMVH+b7+BecYIV+1mB0MtmdWEFC3v2BZsbdUMTXr2l28X2iV2gh/9crOzKpxwKNkRlFUd+ikD0wag9q08nyhzZR9iy9eysd8BVbWE0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565166722; 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=scTxWgjKaVvTJmBNPoxVhc5YseCtK4Pf+JxJfGQWjq8=; b=kiZsmMn5dW75N2j7m7hMkx1cizKWmddhaZqnjX08RK912OZmVhLh9eR6lPO1vekit7lrUMGCusOcNp2Ec+fSeq/XuuyU+Pfmt9aOgdmhVVmsBhbOSzRNz7ER7RN6lh1HWartDvXELi83t8IQKd4+9LM9jDlXo4i30rGgKh9cTCE= 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 156516672240576.71548343893448; Wed, 7 Aug 2019 01:32:02 -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 119D730C3A17; Wed, 7 Aug 2019 08:32:01 +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 D53C31001284; Wed, 7 Aug 2019 08:32: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 8E897149F6; Wed, 7 Aug 2019 08:32:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x778VSe1025083 for ; Wed, 7 Aug 2019 04:31:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id E49C110016E9; Wed, 7 Aug 2019 08:31:28 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6E53B10016E8 for ; Wed, 7 Aug 2019 08:31:28 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 7 Aug 2019 10:30:53 +0200 Message-Id: <5b5d3f7d4bc4a1e740ca2f0c80c24041269b2369.1565166420.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 10/15] 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.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]); Wed, 07 Aug 2019 08:32: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 secret (e.g. they complete various secret aspects) into virsh-completer-secret.c Signed-off-by: Michal Privoznik Reviewed-by: Jonathon Jongsma --- 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 6e6d9a05cc..f229db39d8 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -224,6 +224,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 c985b86fa9..3489f8741a 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 ** virshCheckpointNameCompleter(vshControl *ctl, const vshCmd *cmd, @@ -359,30 +318,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 5cc5794f58..e27d58e536 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 ** virshCheckpointNameCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); @@ -49,10 +46,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 Mon May 6 21:10:48 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=1565166700; cv=none; d=zoho.com; s=zohoarc; b=ETOL6KLBjWIXSCfp8MO2fBHFDvNakBoNDXYDSY9j5Zc1JWzVN+dznuBo0/vqFCW3h6VqDDeePhfTnlUWIf/cI13KV1opfai7v5Rgqq+Il/oAvcJu+ZmO9HglitiK068niPnQPFjrR0hG+i5YFdJY9Th5n4glI+/2oNhdotAd+XI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565166700; 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=kxR26H48eWkkOLvvbnQ0HTAceYpC6uPGRV798NbuV4s=; b=jdTnz+HwSfMT9iU5Du0jlJkPs8o4RzVLyxdSuk9MAaDsZrFHmuF1RCuNJ6r3Z+9bSI/JcjwULACrLQ5a8JMtEpxxFwn6REGj5u9BWmRdFzWoUE3qr7redRI8gcRKYH0VAm2ilLOya/lz1vR23XaBTcq9HHDOGxjjG5/ToH5JWLQ= 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 1565166700132740.1138645216454; Wed, 7 Aug 2019 01:31:40 -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 3EBA42F30D8; Wed, 7 Aug 2019 08:31:38 +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 13D435D704; Wed, 7 Aug 2019 08:31:38 +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 C5E1F24F30; Wed, 7 Aug 2019 08:31:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x778VTPR025088 for ; Wed, 7 Aug 2019 04:31:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id B24CD10016F3; Wed, 7 Aug 2019 08:31:29 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3D28810016E9 for ; Wed, 7 Aug 2019 08:31:29 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 7 Aug 2019 10:30:54 +0200 Message-Id: <0a737cab0c2366b83fad1e3d4e5df8f47a433da6.1565166420.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 11/15] 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 07 Aug 2019 08:31:39 +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 Reviewed-by: Jonathon Jongsma --- tools/Makefile.am | 1 + tools/virsh-completer-snapshot.c | 73 ++++++++++++++++++++++++++++++++ tools/virsh-completer-snapshot.h | 27 ++++++++++++ tools/virsh-completer.c | 45 -------------------- tools/virsh-completer.h | 5 +-- 5 files changed, 102 insertions(+), 49 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 f229db39d8..3a89ec70a2 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -225,6 +225,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 3489f8741a..72223803dd 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -194,51 +194,6 @@ virshCheckpointNameCompleter(vshControl *ctl, return NULL; } =20 -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; -} =20 static char * virshPagesizeNodeToString(xmlNodePtr node) diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h index e27d58e536..4ebd61f3be 100644 --- a/tools/virsh-completer.h +++ b/tools/virsh-completer.h @@ -29,6 +29,7 @@ #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, @@ -38,10 +39,6 @@ char ** virshCheckpointNameCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); =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 Mon May 6 21:10:48 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=1565166703; cv=none; d=zoho.com; s=zohoarc; b=BhKpf24UOWdl7IILoDzFV0/kqMBsN0v776D53RFEl4fD6OkTmOaJ+ZpzXWLAzu7IrkFlKppalDJjxgSrvsWkCz2+hBqo+ti5nCgwpuwZyPvS5cwb4twhTvjGzbd4yHbTgPkbfjXGKw2TJOmSfy5XurtQ+QEXT8j81Br1XhTm6Eg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565166703; 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=srhlLMk1joF3zfoi4Rv0FV6RINufcdr+6RdkKGm8vjw=; b=FvP4XuCWwAM0zbUS1nlO26wu4UeXlw+JKFt1Kcw/mmlBID2Hu/8cQD8pD8RYV54kWMRCyZW+71F3zVpo1ftdXjbpDm1979k7Sci+9nXermSs9Ok2jvKlKFUMW/5s3MtYnIsULGAhpW2va4VRNIrge2cXq96312IVfYWjhOHhU/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 1565166703674696.2098591633363; Wed, 7 Aug 2019 01:31:43 -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 E955430607E5; Wed, 7 Aug 2019 08:31:41 +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 BB94160468; Wed, 7 Aug 2019 08:31:41 +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 7FC3824F33; Wed, 7 Aug 2019 08:31:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x778VUpw025093 for ; Wed, 7 Aug 2019 04:31:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id 80D751001938; Wed, 7 Aug 2019 08:31:30 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0B84D10016E9 for ; Wed, 7 Aug 2019 08:31:29 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 7 Aug 2019 10:30:55 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 12/15] 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Wed, 07 Aug 2019 08:31:42 +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 Reviewed-by: Jonathon Jongsma --- tools/Makefile.am | 1 + tools/virsh-completer-host.c | 148 +++++++++++++++++++++++++++++++++++ tools/virsh-completer-host.h | 31 ++++++++ tools/virsh-completer.c | 121 ---------------------------- tools/virsh-completer.h | 9 +-- 5 files changed, 181 insertions(+), 129 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 3a89ec70a2..43083f4afa 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -219,6 +219,7 @@ virsh_SOURCES =3D \ virsh-checkpoint.c virsh-checkpoint.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 72223803dd..ce42f62fc1 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -193,124 +193,3 @@ virshCheckpointNameCompleter(vshControl *ctl, virshDomainFree(dom); return NULL; } - - -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 4ebd61f3be..bfe304411b 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" @@ -38,11 +39,3 @@ char ** virshCommaStringListComplete(const char *input, char ** virshCheckpointNameCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); - -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 Mon May 6 21:10:48 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=1565166726; cv=none; d=zoho.com; s=zohoarc; b=IWLKOr9V9F7KaU3ufLN5wxVqbLQ5KUFWOkwbi1V9/mNioy4oahGTwFJ+LHEJSLYSVr8TReST4kvRcwtAkknfMb1KCJuCDnkEeFlkPgq9HvjRN9KJ9z46sp59heikbneFcENWrdVZh4ktsA03otEY4BpoIGwPDFYqvt9Fpi37oS0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565166726; 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=dQv2zCPqPQqYVRCpQt2R8l6XIlPGBENsBjMZbXfbIZw=; b=BeF4YDjUu658lxV+9XrHBjIjt2VPF8PyMZOUqJ9hbHn2Au2d/iCJSdEAa0mfIM+FMTOdiQ2wZPALGsU1qzNChX5en3Dv+s1wNcGQ18UPzQwztArWQxoYUiPTBhLhyMA+tVsDiW2z17VrZeT79aHo8FPIHllcmWgKlczbSp0SoyE= 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 1565166726591263.79406259972495; Wed, 7 Aug 2019 01:32:06 -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 3CB4931CD6C; Wed, 7 Aug 2019 08:32:05 +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 05BED67625; Wed, 7 Aug 2019 08:32:05 +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 B942918005C7; Wed, 7 Aug 2019 08:32:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x778VVjU025111 for ; Wed, 7 Aug 2019 04:31:31 -0400 Received: by smtp.corp.redhat.com (Postfix) id 503BC100194E; Wed, 7 Aug 2019 08:31:31 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id CE5121001938 for ; Wed, 7 Aug 2019 08:31:30 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 7 Aug 2019 10:30:56 +0200 Message-Id: <475715d6d47eab83330e82f339be492463009fc8.1565166420.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 13/15] tools: Separate checkpoint 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.29]); Wed, 07 Aug 2019 08:32:05 +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 checkpoint aspects) into virsh-completer-checkpoint.c Signed-off-by: Michal Privoznik Reviewed-by: Jonathon Jongsma --- tools/Makefile.am | 1 + tools/virsh-completer-checkpoint.c | 78 ++++++++++++++++++++++++++++++ tools/virsh-completer-checkpoint.h | 27 +++++++++++ tools/virsh-completer.c | 52 -------------------- 4 files changed, 106 insertions(+), 52 deletions(-) create mode 100644 tools/virsh-completer-checkpoint.c create mode 100644 tools/virsh-completer-checkpoint.h diff --git a/tools/Makefile.am b/tools/Makefile.am index 43083f4afa..274f941d74 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -219,6 +219,7 @@ virsh_SOURCES =3D \ virsh-checkpoint.c virsh-checkpoint.h \ virsh-completer.c virsh-completer.h \ virsh-completer-domain.c virsh-completer-domain.h \ + virsh-completer-checkpoint.c virsh-completer-checkpoint.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 \ diff --git a/tools/virsh-completer-checkpoint.c b/tools/virsh-completer-che= ckpoint.c new file mode 100644 index 0000000000..ce9d32844d --- /dev/null +++ b/tools/virsh-completer-checkpoint.c @@ -0,0 +1,78 @@ +/* + * virsh-completer-checkpoint.c: virsh completer callbacks related to chec= kpoints + * + * 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-checkpoint.h" +#include "viralloc.h" +#include "virsh-util.h" +#include "virsh.h" +#include "virstring.h" + +char ** +virshCheckpointNameCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags) +{ + virshControlPtr priv =3D ctl->privData; + virDomainPtr dom =3D NULL; + virDomainCheckpointPtr *checkpoints =3D NULL; + int ncheckpoints =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 (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + return NULL; + + if ((ncheckpoints =3D virDomainListAllCheckpoints(dom, &checkpoints, + flags)) < 0) + goto error; + + if (VIR_ALLOC_N(ret, ncheckpoints + 1) < 0) + goto error; + + for (i =3D 0; i < ncheckpoints; i++) { + const char *name =3D virDomainCheckpointGetName(checkpoints[i]); + + if (VIR_STRDUP(ret[i], name) < 0) + goto error; + + virshDomainCheckpointFree(checkpoints[i]); + } + VIR_FREE(checkpoints); + virshDomainFree(dom); + + return ret; + + error: + for (; i < ncheckpoints; i++) + virshDomainCheckpointFree(checkpoints[i]); + VIR_FREE(checkpoints); + for (i =3D 0; i < ncheckpoints; i++) + VIR_FREE(ret[i]); + VIR_FREE(ret); + virshDomainFree(dom); + return NULL; +} diff --git a/tools/virsh-completer-checkpoint.h b/tools/virsh-completer-che= ckpoint.h new file mode 100644 index 0000000000..c536a3ffda --- /dev/null +++ b/tools/virsh-completer-checkpoint.h @@ -0,0 +1,27 @@ +/* + * virsh-completer-checkpoint.h: virsh completer callbacks related to chec= kpoints + * + * 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 ** virshCheckpointNameCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index ce42f62fc1..0f1709b4ba 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -141,55 +141,3 @@ virshCommaStringListComplete(const char *input, =20 VIR_RETURN_PTR(ret); } - - -char ** -virshCheckpointNameCompleter(vshControl *ctl, - const vshCmd *cmd, - unsigned int flags) -{ - virshControlPtr priv =3D ctl->privData; - virDomainPtr dom =3D NULL; - virDomainCheckpointPtr *checkpoints =3D NULL; - int ncheckpoints =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 (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) - return NULL; - - if ((ncheckpoints =3D virDomainListAllCheckpoints(dom, &checkpoints, - flags)) < 0) - goto error; - - if (VIR_ALLOC_N(ret, ncheckpoints + 1) < 0) - goto error; - - for (i =3D 0; i < ncheckpoints; i++) { - const char *name =3D virDomainCheckpointGetName(checkpoints[i]); - - if (VIR_STRDUP(ret[i], name) < 0) - goto error; - - virshDomainCheckpointFree(checkpoints[i]); - } - VIR_FREE(checkpoints); - virshDomainFree(dom); - - return ret; - - error: - for (; i < ncheckpoints; i++) - virshDomainCheckpointFree(checkpoints[i]); - VIR_FREE(checkpoints); - for (i =3D 0; i < ncheckpoints; i++) - VIR_FREE(ret[i]); - VIR_FREE(ret); - virshDomainFree(dom); - return NULL; -} --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 6 21:10:48 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=1565166706; cv=none; d=zoho.com; s=zohoarc; b=dcSIrcdZvuvWZ53MqPJn5Ep31bzk1PYn5AmLgc1QAIeem8SLZzyZpu6xaC5RG7n11ODt7IB1GPBmvWanB3Bcau4p/XFJzjlDFqp+xV432vOWEKYgph+ksSlCq7L4uIdCaiVh7cjTDcvr6zEiML76KXseQ66yio5sjJNdsEYT5iI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565166706; 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=ZH+ARwtl5gY0gfvNiXURlfp2OfuN7fyYgfJxesrtSZ0=; b=SIJY49FZuSW0D7KDXxeNgkPfRf2e2SX6+GjnvOBHfUII5c5PebcJ6j7MwZ60BY29ivh41w2Rz8QmsrIQhi3DZ75mLhztIkPHTNYeXp6squaIaDKlHGTXzJlhxCKihAz9ZkOaK0axU9CR5rClo7od71mNU2IX9sYYoKd4E3lTmcE= 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 1565166706750778.2963808781996; Wed, 7 Aug 2019 01:31:46 -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 5B13E309BF23; Wed, 7 Aug 2019 08:31:45 +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 351175EE1D; Wed, 7 Aug 2019 08:31:45 +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 EC5AA24F36; Wed, 7 Aug 2019 08:31:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x778VWWD025123 for ; Wed, 7 Aug 2019 04:31:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id 212E61001938; Wed, 7 Aug 2019 08:31:32 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9FE5310016F3 for ; Wed, 7 Aug 2019 08:31:31 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 7 Aug 2019 10:30:57 +0200 Message-Id: <532731f0a77aeb08462a79efabd782d26ea78a86.1565166420.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 14/15] 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.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.45]); Wed, 07 Aug 2019 08:31:46 +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 Reviewed-by: Jonathon Jongsma --- 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 bfe304411b..7edb8e2f7e 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 Mon May 6 21:10:48 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=1565166730; cv=none; d=zoho.com; s=zohoarc; b=Qb44WHYfjnKuNI13WiRa98rWfUJTGrB00Ju4+nPY+ewebcELYc7Gv0MaA2Qm18aFUybvPr/l69g4I6CrwiGRNe++ZyRa7BtouVGPWQJA4zoQmwrlGA7ApMgbIOk9TvetrfjlZhyVLZTgHSgkcmyXalxzvnt19iMvCIuaYEeY9QY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565166730; 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=d9UQp2Wt6x4f8kiHe1u5FpwTHUl5clnB+7tie6M1//901Vf+PXOITF+UzyThq86oCAdaPtDpDqpDh2NKMy9Es6M5kVRqygintESrbannQilheUtCm/HyjVV+9WfylHpL9mnyVXS4G1kyDqpEF1dNgZa//W4peTMEdOc/3bd49X8= 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 1565166730091322.7826040829051; Wed, 7 Aug 2019 01:32:10 -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 F2CA030BCBBB; Wed, 7 Aug 2019 08:32: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 B6D5C1001B02; Wed, 7 Aug 2019 08:32: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 57A711802216; Wed, 7 Aug 2019 08:32:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x778Vf2K025481 for ; Wed, 7 Aug 2019 04:31:41 -0400 Received: by smtp.corp.redhat.com (Postfix) id 411DD100194E; Wed, 7 Aug 2019 08:31:41 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id BE4751001284 for ; Wed, 7 Aug 2019 08:31:32 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 7 Aug 2019 10:30:58 +0200 Message-Id: <4290771ae02eba30708bf09303a05d2220279f5d.1565166420.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 15/15] 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.49]); Wed, 07 Aug 2019 08:32:09 +0000 (UTC) Content-Type: text/plain; charset="utf-8" This completer can be used to complete pool types. Signed-off-by: Michal Privoznik Reviewed-by: Jonathon Jongsma --- 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