From nobody Wed Nov 5 11:34:31 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 From nobody Wed Nov 5 11:34:31 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 1498223066417272.8802621125909; Fri, 23 Jun 2017 06:04:26 -0700 (PDT) Received: from localhost ([::1]:35451 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dOOG4-0004Jq-Vg for importer@patchew.org; Fri, 23 Jun 2017 09:04:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36412) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dOOEZ-0003Ta-DE 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 1dOOEV-0001le-Ge for qemu-devel@nongnu.org; Fri, 23 Jun 2017 09:02:47 -0400 Received: from mail-wr0-f172.google.com ([209.85.128.172]:35825) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dOOEV-0001lK-9N for qemu-devel@nongnu.org; Fri, 23 Jun 2017 09:02:43 -0400 Received: by mail-wr0-f172.google.com with SMTP id k67so64664095wrc.2 for ; Fri, 23 Jun 2017 06:02:43 -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.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Jun 2017 06:02:41 -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=67Lq8npGRWUiYFHkSZKWv+7bmYJg50XXI/MU6S9QAQs=; b=qyV8VWHDun0MwhcUDdleDIBuNyhucYdd29NGMR/ol24P2hnI8J/f/1G1pgKpkKBFy9 EGNJF2alatOESczfh6kSIREF2GYcJyzO3DP9URAElvvGtfONsbUEJXZnVt7pB2snYVJd kOWu+eZQ17Sdd2uZWYdoNz0QD6XE5pVw/KRlm9X0T0apHOZQLb2nZJ17RtTviKMufQVC 0hjDx5oZ3XXxEtKI4IiFtTtb+tUaRHXnenoYZS0sQPYNarBBhZQDrPmjOzzyHsndCm4G TQjfpofzGg42UR1THPBOrSBYwyLlu3QZtIWW8EKIPVAbKtsXRL+zsK4yMsdLaf34RGs/ EZMg== X-Gm-Message-State: AKS2vOyBjSjnV4xiwaF5f0pONF+3bMpc08t+CPiFCzvwMCrAX4Iq77/u hCeEBk8mvttbEVLuWBGQ+0M8 X-Received: by 10.223.139.87 with SMTP id v23mr5555408wra.145.1498222961865; Fri, 23 Jun 2017 06:02:41 -0700 (PDT) From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= To: Michael Roth Date: Fri, 23 Jun 2017 15:02:36 +0200 Message-Id: <0d9a013bd8f1ac8211758a0f9b0d35ba0a2eec3d.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.172 Subject: [Qemu-devel] [RFC 2/3] qemu-ga: add simple event reporting memory statistics 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 work in progress Signed-off-by: Tom=C3=A1=C5=A1 Golembiovsk=C3=BD --- qga/main.c | 19 ++++++++++++++++--- qga/qapi-event.json | 16 ++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/qga/main.c b/qga/main.c index f16abb5cbb..a9586e7513 100644 --- a/qga/main.c +++ b/qga/main.c @@ -695,16 +695,29 @@ static gboolean monitoring_cb(gpointer data) GAState *s =3D (GAState *)data; =20 g_assert(s->channel); - g_warning("monitoring!"); =20 if (!ga_channel_client_attached(s->channel)) { goto ok; } =20 - /* TODO: call something */ + /* Fire an event */ + qapi_event_send_guest_heartbeat(12345, &err); + if (err) { + goto fail; + } + + if (queued_event) { + int ret; + ret =3D send_response(s, QOBJECT(queued_event)); + QDECREF(queued_event); + queued_event =3D NULL; + if (ret < 0) { + g_warning("error sending event: %s", strerror(-ret)); + } + } goto ok; =20 -/*fail:*/ +fail: g_assert(err); g_warning("%s", error_get_pretty(err)); error_free(err); diff --git a/qga/qapi-event.json b/qga/qapi-event.json index 9c14e4609e..3d48ddb214 100644 --- a/qga/qapi-event.json +++ b/qga/qapi-event.json @@ -1,2 +1,18 @@ # *-*- Mode: Python -*-* =20 +## +# @GUEST_HEARTBEAT: +# +# Mostrly returns memory statistics. TODO +# +# @free-ram: Amount of free memory in kB +# +# Since: 2.10 +# +# Example: +# +# <- { "event": "GUEST_HEARTBEAT", "data": { "free-ram": "12345" }, +# "timestamp": { "seconds": 1267040730, "microseconds": 682951 } } +# +## +{ 'event': 'GUEST_HEARTBEAT', 'data': { 'free-ram': 'size' } } --=20 2.13.1 From nobody Wed Nov 5 11:34:31 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 1498223153918841.6664837351133; Fri, 23 Jun 2017 06:05:53 -0700 (PDT) Received: from localhost ([::1]:35459 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dOOHV-0005PL-FG for importer@patchew.org; Fri, 23 Jun 2017 09:05:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36428) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dOOEa-0003Tw-HW for qemu-devel@nongnu.org; Fri, 23 Jun 2017 09:02:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dOOEW-0001m2-Di for qemu-devel@nongnu.org; Fri, 23 Jun 2017 09:02:48 -0400 Received: from mail-wr0-f170.google.com ([209.85.128.170]:33650) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dOOEW-0001lo-7r for qemu-devel@nongnu.org; Fri, 23 Jun 2017 09:02:44 -0400 Received: by mail-wr0-f170.google.com with SMTP id r103so65098022wrb.0 for ; Fri, 23 Jun 2017 06:02:44 -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.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Jun 2017 06:02:42 -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=HDQ3pXAJgHE6N43sdiIlXyx0V0Afa7w2sdQ91Vy9s3Y=; b=PraBOmdHCRJWj7YhX9gyuQLCRdLFR3eVLRwxa6QkeVSFXqaExDwdOlGcw4yASATwMv AqHtKDEzJ86E1KPRp09nH2Z49qelKYe1Gg0A3orn854MYidCrEx872sZoiLe9f+NFEyX hG2KBgksE+Kw8Wgzoz7IceP9cw8EmLwUv98axzBcXYcsDHtEA8DpIHIWOtkpLBkZF6n0 6G4j46gBZn71ZFQpxAzE9DkYaynJmYkeVPjB12oqg/rAj+p/VrBHcmPOxSNAnp9Cwl3J 72Uig7AW/nxJT/DBtrLNV5ZAKAS/gSXq4g1Ll5aJ+heHgQ1KHIKkLRrTOc7/c9X4HsuQ qbfg== X-Gm-Message-State: AKS2vOzgYW/R18RmypPHdjDumzBM8svi3320/q7LJck0RfWblVdBuw9v yI1KxgCRUZ+AZmOL X-Received: by 10.223.160.40 with SMTP id k37mr5404518wrk.91.1498222963128; Fri, 23 Jun 2017 06:02:43 -0700 (PDT) From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= To: Michael Roth Date: Fri, 23 Jun 2017 15:02:37 +0200 Message-Id: <56b491683542b03a5d4b6c1bf805eda8e06404ec.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.170 Subject: [Qemu-devel] [RFC 3/3] qemu-ga: add support for periodic command runner 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 This adds a support for periodicaly triggering arbitrary command reporting its output. Signed-off-by: Tom=C3=A1=C5=A1 Golembiovsk=C3=BD --- qga/main.c | 26 ++++++++++++++++++++++++++ qga/qapi-event.json | 17 +++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/qga/main.c b/qga/main.c index a9586e7513..612a6646e4 100644 --- a/qga/main.c +++ b/qga/main.c @@ -715,6 +715,32 @@ static gboolean monitoring_cb(gpointer data) g_warning("error sending event: %s", strerror(-ret)); } } + + /* Run arbitrary command */ + const char *command =3D "guest-get-users"; + QDict *args =3D qdict_new(); + + QmpCommand *cmd =3D qmp_find_command(&ga_commands, command); + g_assert(cmd); + g_assert(cmd->fn); + QObject *ret; + qmp_marshal_guest_get_users(args, &ret, &err); + QDECREF(args); + if (err) { + goto fail; + } + qapi_event_send_guest_monitor_command(command, ret, &err); + + if (queued_event) { + int ret; + ret =3D send_response(s, QOBJECT(queued_event)); + QDECREF(queued_event); + queued_event =3D NULL; + if (ret < 0) { + g_warning("error sending event: %s", strerror(-ret)); + } + } + goto ok; =20 fail: diff --git a/qga/qapi-event.json b/qga/qapi-event.json index 3d48ddb214..e31ea0f0e9 100644 --- a/qga/qapi-event.json +++ b/qga/qapi-event.json @@ -16,3 +16,20 @@ # ## { 'event': 'GUEST_HEARTBEAT', 'data': { 'free-ram': 'size' } } + +## +# @GUEST_MONITOR_COMMAND: +# +# Run periodicaly arbitrary command and return it's result. +# +# @command: The executed command. +# @return: Returned value. +# +# Since: 2.10 +# +# Example: +# +# TODO +# +## +{ 'event': 'GUEST_MONITOR_COMMAND', 'data': { 'command': 'str', 'return': = 'any' } } --=20 2.13.1