From nobody Wed Nov 5 13:48:13 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1498223069512118.23101485973336; Fri, 23 Jun 2017 06:04:29 -0700 (PDT) Received: from localhost ([::1]:35452 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dOOG6-0004Kb-12 for importer@patchew.org; Fri, 23 Jun 2017 09:04:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36405) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dOOEY-0003TA-Ey for qemu-devel@nongnu.org; Fri, 23 Jun 2017 09:02:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dOOEU-0001lM-G7 for qemu-devel@nongnu.org; Fri, 23 Jun 2017 09:02:46 -0400 Received: from mail-wr0-f179.google.com ([209.85.128.179]:35812) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dOOEU-0001lB-6Z for qemu-devel@nongnu.org; Fri, 23 Jun 2017 09:02:42 -0400 Received: by mail-wr0-f179.google.com with SMTP id k67so64663478wrc.2 for ; Fri, 23 Jun 2017 06:02:42 -0700 (PDT) Received: from fiorina.brq.redhat.com (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id 5sm3081897wrq.60.2017.06.23.06.02.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Jun 2017 06:02:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=podrBX9sPnDzuA8UxLlVFA2r9EkZLbCYTBBnHx9f6jw=; b=s8KDqxAMy2ajhj1diSwVCRaNd4K2ClaoRepkRjK2oQACmVUkeocx/4lF26pHg9BaWU PQgIc17MYF5jevsJY/hN5A0e/vm6/UJtRUe4Cm2LwAriVuMZF03ZC1s/5Fhh7UT8pzqL IHtwbJOE6fdfxGHbxMdbOWZVVjF/QUz5mWUmIW8j0dwcGO/VCNbtLCRvevv/FoR8475q IM+D5wdWoO3GtMHt+TcSxwciawUfHJYx+qmeKSik8QPh4qEwKOB6x/X2OzCTdP5WIeHU 8gjjOhjyAWX/wxcVku6ayJyBdXmnyUQ7xEbCLpqmIkWyucvad4SpOgG05BW4ay/k0ZYV 680Q== X-Gm-Message-State: AKS2vOxF6wNmCwrFZ0SI0IiZAEzfLeG83a95w8zFxWHVHZtH0e/vAyKB lhY2YfICW4tzNhUk X-Received: by 10.223.153.165 with SMTP id y34mr5622975wrb.41.1498222960857; Fri, 23 Jun 2017 06:02:40 -0700 (PDT) From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= To: Michael Roth Date: Fri, 23 Jun 2017 15:02:35 +0200 Message-Id: <7e2e1329dbe5a6d93c3d58eb2251b8862e2d1340.1498222907.git.tgolembi@redhat.com> X-Mailer: git-send-email 2.13.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.128.179 Subject: [Qemu-devel] [RFC 1/3] qemu-ga: add support for events X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Events can play an integral role when monitoring internal state of the guest OS. This patch adds the core functionality for adding events to QEMU Guest Agent. Signed-off-by: Tom=C3=A1=C5=A1 Golembiovsk=C3=BD --- Makefile | 7 +++++- qga/Makefile.objs | 2 +- qga/channel-posix.c | 8 +++++++ qga/channel-win32.c | 6 +++++ qga/channel.h | 1 + qga/guest-agent-core.h | 1 + qga/main.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++= ++++ qga/qapi-event.json | 2 ++ qga/qapi-schema.json | 2 ++ 9 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 qga/qapi-event.json diff --git a/Makefile b/Makefile index c830d7a46c..03e2174a18 100644 --- a/Makefile +++ b/Makefile @@ -408,6 +408,11 @@ $(SRC_PATH)/qga/qapi-schema.json $(SRC_PATH)/scripts/q= api-commands.py $(qapi-py) $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-commands.py \ $(gen-out-type) -o qga/qapi-generated -p "qga-" $<, \ "GEN","$@") +qga/qapi-generated/qga-qapi-event.c qga/qapi-generated/qga-qapi-event.h :\ +$(SRC_PATH)/qga/qapi-schema.json $(SRC_PATH)/scripts/qapi-event.py $(qapi-= py) + $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-event.py \ + $(gen-out-type) -o qga/qapi-generated -p "qga-" $<, \ + "GEN","$@") =20 qapi-modules =3D $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/qapi/common.json= \ $(SRC_PATH)/qapi/block.json $(SRC_PATH)/qapi/block-core.jso= n \ @@ -441,7 +446,7 @@ $(qapi-modules) $(SRC_PATH)/scripts/qapi-introspect.py = $(qapi-py) $(gen-out-type) -o "." $<, \ "GEN","$@") =20 -QGALIB_GEN=3D$(addprefix qga/qapi-generated/, qga-qapi-types.h qga-qapi-vi= sit.h qga-qmp-commands.h) +QGALIB_GEN=3D$(addprefix qga/qapi-generated/, qga-qapi-types.h qga-qapi-vi= sit.h qga-qmp-commands.h qga-qapi-event.h) $(qga-obj-y) qemu-ga.o: $(QGALIB_GEN) =20 qemu-ga$(EXESUF): $(qga-obj-y) $(COMMON_LDADDS) diff --git a/qga/Makefile.objs b/qga/Makefile.objs index 1c5986c0bb..24399b6325 100644 --- a/qga/Makefile.objs +++ b/qga/Makefile.objs @@ -3,6 +3,6 @@ qga-obj-$(CONFIG_POSIX) +=3D commands-posix.o channel-posix= .o qga-obj-$(CONFIG_WIN32) +=3D commands-win32.o channel-win32.o service-win3= 2.o qga-obj-$(CONFIG_WIN32) +=3D vss-win32.o qga-obj-y +=3D qapi-generated/qga-qapi-types.o qapi-generated/qga-qapi-vis= it.o -qga-obj-y +=3D qapi-generated/qga-qmp-marshal.o +qga-obj-y +=3D qapi-generated/qga-qmp-marshal.o qapi-generated/qga-qapi-ev= ent.o =20 qga-vss-dll-obj-$(CONFIG_QGA_VSS) +=3D vss-win32/ diff --git a/qga/channel-posix.c b/qga/channel-posix.c index 3f34465159..22e440724c 100644 --- a/qga/channel-posix.c +++ b/qga/channel-posix.c @@ -118,6 +118,14 @@ static int ga_channel_client_add(GAChannel *c, int fd) return 0; } =20 +gboolean ga_channel_client_attached(GAChannel *c) +{ + g_assert(c); + /* TODO: make this work with all methods. following works only with + * unix-listen */ + return c->client_channel !=3D NULL; +} + static gboolean ga_channel_open(GAChannel *c, const gchar *path, GAChannelMethod method, int fd) { diff --git a/qga/channel-win32.c b/qga/channel-win32.c index 7e6dc4d26f..b62a6a3859 100644 --- a/qga/channel-win32.c +++ b/qga/channel-win32.c @@ -315,6 +315,12 @@ static gboolean ga_channel_open(GAChannel *c, GAChanne= lMethod method, return true; } =20 +gboolean ga_channel_client_attached(GAChannel *c) +{ + /* TODO: make this work with all methods */ + return true; +} + GAChannel *ga_channel_new(GAChannelMethod method, const gchar *path, int listen_fd, GAChannelCallback cb, gpointer op= aque) { diff --git a/qga/channel.h b/qga/channel.h index 1778416115..030ec9e551 100644 --- a/qga/channel.h +++ b/qga/channel.h @@ -30,5 +30,6 @@ GAChannel *ga_channel_new(GAChannelMethod method, const g= char *path, void ga_channel_free(GAChannel *c); GIOStatus ga_channel_read(GAChannel *c, gchar *buf, gsize size, gsize *cou= nt); GIOStatus ga_channel_write_all(GAChannel *c, const gchar *buf, gsize size); +gboolean ga_channel_client_attached(GAChannel *c); =20 #endif diff --git a/qga/guest-agent-core.h b/qga/guest-agent-core.h index 3e8a4acff2..47d6c73458 100644 --- a/qga/guest-agent-core.h +++ b/qga/guest-agent-core.h @@ -13,6 +13,7 @@ #include "qapi/qmp/dispatch.h" #include "qemu-common.h" #include "qga-qmp-commands.h" +#include "qga-qapi-event.h" =20 #define QGA_READ_COUNT_DEFAULT 4096 =20 diff --git a/qga/main.c b/qga/main.c index cc58d2b53d..f16abb5cbb 100644 --- a/qga/main.c +++ b/qga/main.c @@ -23,6 +23,8 @@ #include "qapi/qmp/qjson.h" #include "qga/guest-agent-core.h" #include "qemu/module.h" +#include "qapi/qmp-event.h" +#include "qapi/qmp/qdict.h" #include "qapi/qmp/qerror.h" #include "qapi/qmp/dispatch.h" #include "qga/channel.h" @@ -674,6 +676,59 @@ static gboolean channel_event_cb(GIOCondition conditio= n, gpointer data) return true; } =20 +/* TODO: HACK HACK HACK... can't we get a GAstate somehow? */ +QDict *queued_event; +static void ga_event_emit(qga_QAPIEvent event, QDict *qdict, Error **errp) +{ + if (queued_event) { + error_setg(errp, "unsent event already waiting"); + } else { + QINCREF(qdict); + queued_event =3D qdict; + } +} +/* HACK HACK HACK!!! */ + +static gboolean monitoring_cb(gpointer data) +{ + Error *err =3D NULL; + GAState *s =3D (GAState *)data; + + g_assert(s->channel); + g_warning("monitoring!"); + + if (!ga_channel_client_attached(s->channel)) { + goto ok; + } + + /* TODO: call something */ + goto ok; + +/*fail:*/ + g_assert(err); + g_warning("%s", error_get_pretty(err)); + error_free(err); + +ok: + /* Always return true. False would remove this callback. */ + return true; +} + +static gboolean monitoring_init(GAState *s) +{ + if (g_timeout_add_seconds(5, monitoring_cb, (gpointer)s) <=3D 0) { + g_error("failed to create monitoring timer"); + goto fail; + } + g_debug("monitoring timer created"); + + qmp_event_set_func_emit(ga_event_emit); + return true; + +fail: + return false; +} + static gboolean channel_init(GAState *s, const gchar *method, const gchar = *path, int listen_fd) { @@ -1330,6 +1385,10 @@ static int run_agent(GAState *s, GAConfig *config, i= nt socket_activation) g_critical("failed to initialize guest agent channel"); return EXIT_FAILURE; } + + /* TODO: error handling? */ + monitoring_init(ga_state); + #ifndef _WIN32 g_main_loop_run(ga_state->main_loop); #else diff --git a/qga/qapi-event.json b/qga/qapi-event.json new file mode 100644 index 0000000000..9c14e4609e --- /dev/null +++ b/qga/qapi-event.json @@ -0,0 +1,2 @@ +# *-*- Mode: Python -*-* + diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json index 03743ab905..f30ba183bb 100644 --- a/qga/qapi-schema.json +++ b/qga/qapi-schema.json @@ -1,5 +1,7 @@ # *-*- Mode: Python -*-* =20 +{ 'include': 'qapi-event.json' } + ## # # General note concerning the use of guest agent interfaces: --=20 2.13.1