qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Gerd Hoffmann <kraxel@redhat.com>
To: Luiz Capitulino <lcapitulino@redhat.com>
Cc: Anthony Liguori <aliguori@us.ibm.com>,
	alevy@redhat.com, qemu-devel@nongnu.org,
	Markus Armbruster <armbru@redhat.com>
Subject: Re: [Qemu-devel] [RfC PATCH 2/2] console: add screendump-device qmp cmd
Date: Tue, 18 Jun 2013 11:24:54 +0200	[thread overview]
Message-ID: <51C02766.5020301@redhat.com> (raw)
In-Reply-To: <20130617105018.26c2eadc@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 788 bytes --]

On 06/17/13 16:50, Luiz Capitulino wrote:
>>> > > +struct screendump_job {
>>> > > +    QEMUBH *bh;
>>> > > +    QemuConsole *con;
>>> > > +    char *filename;
>>> > > +};
>> > 
>> > We have a job API in the block layer.  Would it make sense to have a
>> > QMP-level job interface?
> I'd agree with this.

Something like the attached patch?  Which is just the bare minimum I'll
need for screendump.  Basically a one-off bottom half with some monitor
infrastructure (job id, error handling).  So it isn't for big jobs, but
for small jobs which have to wait for something before they execute
(spice-server, guest action, whatever).

If you wanna some more context: screendump on top of that is here:
https://www.kraxel.org/cgit/qemu/log/?h=rebase/pixman

[ not tested yet ]

cheers,
  Gerd

[-- Attachment #2: 0001-draft-monitor-job.patch --]
[-- Type: text/plain, Size: 3882 bytes --]

>From bf1f7ec8a2baacc497e188ac38b24e5b0387b143 Mon Sep 17 00:00:00 2001
From: Gerd Hoffmann <kraxel@redhat.com>
Date: Tue, 18 Jun 2013 09:21:03 +0200
Subject: [PATCH 1/3] [draft] monitor job

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 include/monitor/monitor.h |   10 +++++++
 monitor.c                 |   66 +++++++++++++++++++++++++++++++++++++++++++++
 qapi-schema.json          |   10 +++++++
 3 files changed, 86 insertions(+)

diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h
index 1a6cfcf..6f5ec7e 100644
--- a/include/monitor/monitor.h
+++ b/include/monitor/monitor.h
@@ -47,6 +47,7 @@ typedef enum MonitorEvent {
     QEVENT_BALLOON_CHANGE,
     QEVENT_SPICE_MIGRATE_COMPLETED,
     QEVENT_GUEST_PANICKED,
+    QEVENT_JOB_COMPLETED,
 
     /* Add to 'monitor_event_names' array in monitor.c when
      * defining new events here */
@@ -100,4 +101,13 @@ int monitor_fdset_dup_fd_add(int64_t fdset_id, int dup_fd);
 int monitor_fdset_dup_fd_remove(int dup_fd);
 int monitor_fdset_dup_fd_find(int dup_fd);
 
+typedef struct monitor_job monitor_job;
+typedef void (*monitor_job_func)(void *opaque, Error **errp);
+
+uint64_t monitor_job_new_id(void);
+monitor_job *monitor_job_alloc(uint64_t id, monitor_job_func func,
+                               void *opaque);
+void monitor_job_queue(monitor_job *job);
+void monitor_job_cancel(monitor_job *job);
+
 #endif /* !MONITOR_H */
diff --git a/monitor.c b/monitor.c
index 70ae8f5..9a25c1e 100644
--- a/monitor.c
+++ b/monitor.c
@@ -496,6 +496,7 @@ static const char *monitor_event_names[] = {
     [QEVENT_BALLOON_CHANGE] = "BALLOON_CHANGE",
     [QEVENT_SPICE_MIGRATE_COMPLETED] = "SPICE_MIGRATE_COMPLETED",
     [QEVENT_GUEST_PANICKED] = "GUEST_PANICKED",
+    [QEVENT_JOB_COMPLETED] = "JOB_COMPLETED",
 };
 QEMU_BUILD_BUG_ON(ARRAY_SIZE(monitor_event_names) != QEVENT_MAX)
 
@@ -4863,3 +4864,68 @@ QemuOptsList qemu_mon_opts = {
         { /* end of list */ }
     },
 };
+
+struct monitor_job {
+    uint64_t id;
+    monitor_job_func func;
+    void *opaque;
+    QEMUBH *bh;
+};
+
+static void monitor_job_event(monitor_job *job, const char *result, Error *err)
+{
+    QObject *data;
+
+    data = qobject_from_jsonf("{ 'job-id': %" PRId64 ", 'result': %s }",
+                              job->id, result);
+    if (error_is_set(&err)) {
+        /* TODO: add error details */
+    }
+    monitor_protocol_event(QEVENT_JOB_COMPLETED, data);
+    qobject_decref(data);
+}
+
+static void monitor_job_bh(void *opaque)
+{
+    monitor_job *job = opaque;
+    Error *local_err = NULL;
+    const char *result;
+
+    job->func(job->opaque, &local_err);
+    result = error_is_set(&local_err) ? "success" : "failure";
+    monitor_job_event(job, result, local_err);
+    qemu_bh_delete(job->bh);
+    g_free(job);
+}
+
+uint64_t monitor_job_new_id(void)
+{
+    static uint64_t nextid = 1;
+    return nextid++;
+}
+
+monitor_job *monitor_job_alloc(uint64_t id, monitor_job_func func,
+                               void *opaque)
+{
+    monitor_job *job = g_new0(monitor_job, 1);
+
+    job->id = id;
+    job->func = func;
+    job->opaque = opaque;
+    return job;
+}
+
+void monitor_job_queue(monitor_job *job)
+{
+    job->bh = qemu_bh_new(monitor_job_bh, job);
+    qemu_bh_schedule(job->bh);
+}
+
+void monitor_job_cancel(monitor_job *job)
+{
+    monitor_job_event(job, "canceled", NULL);
+    if (job->bh) {
+        qemu_bh_delete(job->bh);
+    }
+    g_free(job);
+}
diff --git a/qapi-schema.json b/qapi-schema.json
index aced724..a449a43 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -2515,6 +2515,16 @@
     'str': 'str' } }
 
 ##
+# @MonitorJob
+#
+# Monitor job id.
+#
+# Since 1.6
+##
+{ 'type': 'MonitorJob',
+  'data': { 'job-id': 'int' } }
+
+##
 # @NetdevUserOptions
 #
 # Use the user mode network stack which requires no administrator privilege to
-- 
1.7.9.7


  reply	other threads:[~2013-06-18  9:25 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-17 14:01 [Qemu-devel] [RfC PATCH 0/2] new screendump qmp command Gerd Hoffmann
2013-06-17 14:01 ` [Qemu-devel] [RfC PATCH 1/2] display update with notification Gerd Hoffmann
2013-06-17 14:39   ` Anthony Liguori
2013-06-17 14:01 ` [Qemu-devel] [RfC PATCH 2/2] console: add screendump-device qmp cmd Gerd Hoffmann
2013-06-17 14:43   ` Anthony Liguori
2013-06-17 14:50     ` Luiz Capitulino
2013-06-18  9:24       ` Gerd Hoffmann [this message]
2013-06-18 13:13         ` Luiz Capitulino
2013-06-18 13:24           ` Gerd Hoffmann
2013-06-18 14:47             ` Stefan Hajnoczi
2013-06-25 10:28               ` Gerd Hoffmann
2013-07-12 17:01         ` Eric Blake
2013-07-12 17:06   ` Eric Blake

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=51C02766.5020301@redhat.com \
    --to=kraxel@redhat.com \
    --cc=alevy@redhat.com \
    --cc=aliguori@us.ibm.com \
    --cc=armbru@redhat.com \
    --cc=lcapitulino@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).