From nobody Wed May 14 09:54:59 2025 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1525789433480220.2439895486591; Tue, 8 May 2018 07:23:53 -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 BDFF4C04BD28; Tue, 8 May 2018 14:23:51 +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 8255116E24; Tue, 8 May 2018 14:23:51 +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 34B1E180BAE9; Tue, 8 May 2018 14:23:51 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w48ENfY6003935 for ; Tue, 8 May 2018 10:23:41 -0400 Received: by smtp.corp.redhat.com (Postfix) id 235C96012A; Tue, 8 May 2018 14:23:41 +0000 (UTC) Received: from mx1.redhat.com (ext-mx04.extmail.prod.ext.phx2.redhat.com [10.5.110.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 14D8E600D2; Tue, 8 May 2018 14:23:40 +0000 (UTC) Received: from prv3-mh.provo.novell.com (victor.provo.novell.com [137.65.250.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4FD7480468; Tue, 8 May 2018 14:23:23 +0000 (UTC) Received: from localhost.localdomain (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by prv3-mh.provo.novell.com with ESMTP (NOT encrypted); Tue, 08 May 2018 08:23:10 -0600 From: Lin Ma To: libvir-list@redhat.com Date: Tue, 8 May 2018 22:20:38 +0800 Message-Id: <20180508142040.18593-11-lma@suse.com> In-Reply-To: <20180508142040.18593-1-lma@suse.com> References: <20180508142040.18593-1-lma@suse.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 207 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 08 May 2018 14:23:38 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 08 May 2018 14:23:38 +0000 (UTC) for IP:'137.65.250.26' DOMAIN:'victor.provo.novell.com' HELO:'prv3-mh.provo.novell.com' FROM:'lma@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 137.65.250.26 victor.provo.novell.com 137.65.250.26 victor.provo.novell.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.28 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: mprivozn@redhat.com, pkrempa@redhat.com Subject: [libvirt] [PATCH v2 10/12] virsh: Enable multiple --event flags to 'event' command 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: , MIME-Version: 1.0 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.31]); Tue, 08 May 2018 14:23:52 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Lin Ma --- tools/virsh-domain.c | 107 +++++++++++++++++++++++++++--------------------= ---- 1 file changed, 57 insertions(+), 50 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 30da953446..36278ebc1c 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -13335,10 +13335,6 @@ static const vshCmdInfo info_event[] =3D { static const vshCmdOptDef opts_event[] =3D { VIRSH_COMMON_OPT_DOMAIN_OT_STRING(N_("filter by domain name, id or uui= d"), 0), - {.name =3D "event", - .type =3D VSH_OT_STRING, - .help =3D N_("which event type to wait for") - }, {.name =3D "all", .type =3D VSH_OT_BOOL, .help =3D N_("wait for all events instead of just one type") @@ -13359,6 +13355,10 @@ static const vshCmdOptDef opts_event[] =3D { .type =3D VSH_OT_BOOL, .help =3D N_("show timestamp for each printed event") }, + {.name =3D "event", + .type =3D VSH_OT_ARGV, + .help =3D N_("which event type to wait for") + }, {.name =3D NULL} }; =20 @@ -13368,58 +13368,64 @@ cmdEvent(vshControl *ctl, const vshCmd *cmd) virDomainPtr dom =3D NULL; bool ret =3D false; int timeout =3D 0; - virshDomEventData *data =3D NULL; + virshDomEventData *dataList =3D NULL; size_t i; - const char *eventName =3D NULL; - int event =3D -1; + int *eventIdxList =3D NULL; + size_t nevents =3D 0; + int eventid =3D -1; bool all =3D vshCommandOptBool(cmd, "all"); bool loop =3D vshCommandOptBool(cmd, "loop"); bool timestamp =3D vshCommandOptBool(cmd, "timestamp"); + bool event =3D vshCommandOptBool(cmd, "event"); int count =3D 0; + const vshCmdOpt *opt =3D NULL; virshControlPtr priv =3D ctl->privData; =20 if (vshCommandOptBool(cmd, "list")) { - for (event =3D 0; event < VIR_DOMAIN_EVENT_ID_LAST; event++) - vshPrint(ctl, "%s\n", vshEventCallbacks[event].name); + for (eventid =3D 0; eventid < VIR_DOMAIN_EVENT_ID_LAST; eventid++) + vshPrint(ctl, "%s\n", vshEventCallbacks[eventid].name); return true; } =20 - if (vshCommandOptStringReq(ctl, cmd, "event", &eventName) < 0) - return false; - if (eventName) { - for (event =3D 0; event < VIR_DOMAIN_EVENT_ID_LAST; event++) - if (STREQ(eventName, vshEventCallbacks[event].name)) - break; - if (event =3D=3D VIR_DOMAIN_EVENT_ID_LAST) { - vshError(ctl, _("unknown event type %s"), eventName); - return false; + if (event) { + while ((opt =3D vshCommandOptArgv(ctl, cmd, opt))) { + if (opt->data) { + for (eventid =3D 0; eventid < VIR_DOMAIN_EVENT_ID_LAST; ev= entid++) + if (STREQ(opt->data, vshEventCallbacks[eventid].name)) + break; + if (eventid =3D=3D VIR_DOMAIN_EVENT_ID_LAST) { + vshError(ctl, _("unknown event type %s"), opt->data); + goto cleanup; + } + size_t n =3D nevents; + virshDomEventData data; + data.ctl =3D ctl; + data.loop =3D loop; + data.count =3D &count; + data.timestamp =3D timestamp; + data.cb =3D &vshEventCallbacks[eventid]; + data.id =3D -1; + if (VIR_APPEND_ELEMENT(dataList, nevents, data) < 0) + goto cleanup; + if (VIR_APPEND_ELEMENT(eventIdxList, n, eventid) < 0) + goto cleanup; + } } - } else if (!all) { - vshError(ctl, "%s", - _("one of --list, --all, or --event is required")); - return false; - } - - if (all) { - if (VIR_ALLOC_N(data, VIR_DOMAIN_EVENT_ID_LAST) < 0) + } else if (all) { + if (VIR_ALLOC_N(dataList, VIR_DOMAIN_EVENT_ID_LAST) < 0) goto cleanup; for (i =3D 0; i < VIR_DOMAIN_EVENT_ID_LAST; i++) { - data[i].ctl =3D ctl; - data[i].loop =3D loop; - data[i].count =3D &count; - data[i].timestamp =3D timestamp; - data[i].cb =3D &vshEventCallbacks[i]; - data[i].id =3D -1; + dataList[i].ctl =3D ctl; + dataList[i].loop =3D loop; + dataList[i].count =3D &count; + dataList[i].timestamp =3D timestamp; + dataList[i].cb =3D &vshEventCallbacks[i]; + dataList[i].id =3D -1; } } else { - if (VIR_ALLOC_N(data, 1) < 0) - goto cleanup; - data[0].ctl =3D ctl; - data[0].loop =3D vshCommandOptBool(cmd, "loop"); - data[0].count =3D &count; - data[0].timestamp =3D timestamp; - data[0].cb =3D &vshEventCallbacks[event]; - data[0].id =3D -1; + vshError(ctl, "%s", + _("one of --list, --all, or --event is required")); + return false; } if (vshCommandOptTimeoutToMs(ctl, cmd, &timeout) < 0) goto cleanup; @@ -13431,11 +13437,11 @@ cmdEvent(vshControl *ctl, const vshCmd *cmd) if (vshEventStart(ctl, timeout) < 0) goto cleanup; =20 - for (i =3D 0; i < (all ? VIR_DOMAIN_EVENT_ID_LAST : 1); i++) { - if ((data[i].id =3D virConnectDomainEventRegisterAny(priv->conn, d= om, - all ? i : event, - data[i].cb->cb, - &data[i], + for (i =3D 0; i < (event ? nevents : VIR_DOMAIN_EVENT_ID_LAST); i++) { + if ((dataList[i].id =3D virConnectDomainEventRegisterAny(priv->con= n, dom, + event ? eventId= xList[i] : i, + dataList[i].cb-= >cb, + &dataList[i], NULL)) < 0) { /* When registering for all events: if the first * registration succeeds, silently ignore failures on all @@ -13465,14 +13471,15 @@ cmdEvent(vshControl *ctl, const vshCmd *cmd) =20 cleanup: vshEventCleanup(ctl); - if (data) { - for (i =3D 0; i < (all ? VIR_DOMAIN_EVENT_ID_LAST : 1); i++) { - if (data[i].id >=3D 0 && - virConnectDomainEventDeregisterAny(priv->conn, data[i].id)= < 0) + if (dataList) { + for (i =3D 0; i < (event ? nevents : VIR_DOMAIN_EVENT_ID_LAST); i+= +) { + if (dataList[i].id >=3D 0 && + virConnectDomainEventDeregisterAny(priv->conn, dataList[i]= .id) < 0) ret =3D false; } - VIR_FREE(data); + VIR_FREE(dataList); } + VIR_FREE(eventIdxList); virshDomainFree(dom); return ret; } --=20 2.15.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list