From: Stefan Hajnoczi <stefanha@gmail.com>
To: Michael Roth <mdroth@linux.vnet.ibm.com>
Cc: aliguori@linux.vnet.ibm.com, agl@linux.vnet.ibm.com,
qemu-devel@nongnu.org, Jes.Sorensen@redhat.com
Subject: Re: [Qemu-devel] [RFC][PATCH v2 09/17] qmp proxy: core code for proxying qmp requests to guest
Date: Tue, 26 Apr 2011 14:21:19 +0100 [thread overview]
Message-ID: <BANLkTinSa4QK6ORVXcLRxsf-Goen6=KG_g@mail.gmail.com> (raw)
In-Reply-To: <1303138953-1334-10-git-send-email-mdroth@linux.vnet.ibm.com>
On Mon, Apr 18, 2011 at 4:02 PM, Michael Roth <mdroth@linux.vnet.ibm.com> wrote:
> +static int qmp_proxy_cancel_request(QmpProxy *p, QmpProxyRequest *r)
> +{
> + if (r && r->cb) {
> + r->cb(r->opaque, NULL, NULL);
> + }
> +
> + return 0;
> +}
> +
> +static int qmp_proxy_cancel_all(QmpProxy *p)
> +{
> + QmpProxyRequest *r, *tmp;
> + QTAILQ_FOREACH_SAFE(r, &p->requests, entry, tmp) {
> + qmp_proxy_cancel_request(p, r);
> + QTAILQ_REMOVE(&p->requests, r, entry);
> + }
> +
> + return 0;
> +}
qmp_proxy_cancel_all() will remove requests from the list.
qmp_proxy_cancel_request() will not remove it from the list. This
could cause confusion in the future if someone adds a call to
qmp_proxy_cancel_request() without realizing that it will not remove
the request from the list. The two function's names are similar, it
would be nice if they acted the same way.
> +static void qmp_proxy_process_event(JSONMessageParser *parser, QList *tokens)
> +{
> + QmpProxy *p = container_of(parser, QmpProxy, parser);
> + QmpProxyRequest *r;
> + QObject *obj;
> + QDict *qdict;
> + Error *err = NULL;
> +
> + fprintf(stderr, "qmp proxy: called\n");
> + obj = json_parser_parse_err(tokens, NULL, &err);
> + if (!obj) {
> + fprintf(stderr, "qmp proxy: failed to parse\n");
> + return;
> + } else {
> + fprintf(stderr, "qmp proxy: parse successful\n");
> + qdict = qobject_to_qdict(obj);
> + }
> +
> + if (qdict_haskey(qdict, "_control_event")) {
> + /* handle transport-level control event */
> + qmp_proxy_process_control_event(p, qdict);
> + } else if (qdict_haskey(qdict, "return")) {
> + /* handle proxied qmp command response */
> + fprintf(stderr, "received return\n");
> + r = QTAILQ_FIRST(&p->requests);
> + if (!r) {
> + fprintf(stderr, "received return, but no request queued\n");
QDECREF(qdict)?
> + return;
> + }
> + /* XXX: can't assume type here */
> + fprintf(stderr, "recieved response for cmd: %s\nreturn: %s\n",
> + r->name, qstring_get_str(qobject_to_json(QOBJECT(qdict))));
> + r->cb(r->opaque, qdict_get(qdict, "return"), NULL);
> + QTAILQ_REMOVE(&p->requests, r, entry);
> + qemu_free(r);
> + fprintf(stderr, "done handling response\n");
> + } else {
> + fprintf(stderr, "received invalid payload format\n");
> + }
> +
> + QDECREF(qdict);
> +}
> +void qmp_proxy_send_request(QmpProxy *p, const char *name,
> + const QDict *args, Error **errp,
> + QmpGuestCompletionFunc *cb, void *opaque)
> +{
> + QmpProxyRequest *r = qemu_mallocz(sizeof(QmpProxyRequest));
> + QDict *payload = qdict_new();
> + QString *json;
> +
> + /* TODO: don't really need to hold on to name/args after encoding */
> + r->name = name;
> + r->args = args;
> + r->cb = cb;
> + r->opaque = opaque;
> +
> + qdict_put_obj(payload, "execute", QOBJECT(qstring_from_str(r->name)));
> + /* TODO: casting a const so we can add it to our dictionary. bad. */
> + qdict_put_obj(payload, "arguments", QOBJECT((QDict *)args));
> +
> + json = qobject_to_json(QOBJECT((QDict *)payload));
> + if (!json) {
> + goto out_bad;
> + }
> +
> + QTAILQ_INSERT_TAIL(&p->requests, r, entry);
> + g_string_append(p->tx, qstring_get_str(json));
> + QDECREF(json);
> + qmp_proxy_write(p);
> + return;
> +
> +out_bad:
> + cb(opaque, NULL, NULL);
> + qemu_free(r);
Need to free payload?
> +}
> +
> +QmpProxy *qmp_proxy_new(CharDriverState *chr)
> +{
> + QmpProxy *p = qemu_mallocz(sizeof(QmpProxy));
> +
> + signal_init(&guest_agent_up_event);
> + signal_init(&guest_agent_reset_event);
> +
> + /* there's a reason for this madness */
Helpful comment :)
> + p->tx_timer = qemu_new_timer(rt_clock, qmp_proxy_write_handler, p);
> + p->tx_timer_interval = 10;
> + p->tx = g_string_new("");
> + p->chr = chr;
> + json_message_parser_init(&p->parser, qmp_proxy_process_event);
> + QTAILQ_INIT(&p->requests);
> +
> + return p;
> +}
> +
> +void qmp_proxy_close(QmpProxy *p)
> +{
> + qmp_proxy_cancel_all(p);
> + g_string_free(p->tx, TRUE);
Free tx_timer?
> + qemu_free(p);
> +}
next prev parent reply other threads:[~2011-04-26 13:21 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-18 15:02 [Qemu-devel] [RFC][PATCH v2 00/11] QEMU Guest Agent: QMP-based host/guest communication (virtagent) Michael Roth
2011-04-18 15:02 ` [Qemu-devel] [RFC][PATCH v2 01/17] json-lexer: make lexer error-recovery more deterministic Michael Roth
2011-04-18 15:02 ` [Qemu-devel] [RFC][PATCH v2 02/17] json-streamer: add handling for JSON_ERROR token/state Michael Roth
2011-04-18 15:02 ` [Qemu-devel] [RFC][PATCH v2 03/17] json-parser: add handling for NULL token list Michael Roth
2011-04-18 15:02 ` [Qemu-devel] [RFC][PATCH v2 04/17] qapi: fix function name typo in qmp-gen.py Michael Roth
2011-04-18 15:02 ` [Qemu-devel] [RFC][PATCH v2 05/17] qapi: fix handling for null-return async callbacks Michael Roth
2011-04-18 15:02 ` [Qemu-devel] [RFC][PATCH v2 06/17] qapi: fix memory leak for async marshalling code Michael Roth
2011-04-18 15:02 ` [Qemu-devel] [RFC][PATCH v2 07/17] qapi: qmp-gen.py, use basename of path for guard/core prefix Michael Roth
2011-04-18 15:02 ` [Qemu-devel] [RFC][PATCH v2 08/17] qapi: fix Error usage in qemu-sockets.c Michael Roth
2011-04-21 8:20 ` Jes Sorensen
2011-04-18 15:02 ` [Qemu-devel] [RFC][PATCH v2 09/17] qmp proxy: core code for proxying qmp requests to guest Michael Roth
2011-04-21 8:30 ` Jes Sorensen
2011-04-21 12:57 ` Michael Roth
2011-04-26 13:21 ` Stefan Hajnoczi [this message]
2011-04-26 14:38 ` Michael Roth
2011-04-18 15:02 ` [Qemu-devel] [RFC][PATCH v2 10/17] qmp proxy: add qmp_proxy chardev Michael Roth
2011-04-18 15:02 ` [Qemu-devel] [RFC][PATCH v2 11/17] qmp proxy: build QEMU with qmp proxy Michael Roth
2011-04-18 15:02 ` [Qemu-devel] [RFC][PATCH v2 12/17] guest agent: worker thread class Michael Roth
2011-04-21 8:44 ` Jes Sorensen
2011-04-21 13:15 ` Michael Roth
2011-04-21 13:19 ` Jes Sorensen
2011-04-18 15:02 ` [Qemu-devel] [RFC][PATCH v2 13/17] guest agent: command state class Michael Roth
2011-04-18 15:02 ` [Qemu-devel] [RFC][PATCH v2 14/17] guest agent: core marshal/dispatch interfaces Michael Roth
2011-04-18 15:02 ` [Qemu-devel] [RFC][PATCH v2 15/17] guest agent: qemu-ga daemon Michael Roth
2011-04-21 8:50 ` Jes Sorensen
2011-04-21 13:21 ` Michael Roth
2011-04-22 9:23 ` Ian Molton
2011-04-22 11:51 ` Jes Sorensen
2011-04-25 12:27 ` Ian Molton
2011-04-26 13:39 ` Jes Sorensen
2011-04-18 15:02 ` [Qemu-devel] [RFC][PATCH v2 16/17] guest agent: add guest agent RPCs/commands Michael Roth
2011-04-18 15:02 ` [Qemu-devel] [RFC][PATCH v2 17/17] guest agent: build qemu-ga, add QEMU-wide gio dep Michael Roth
2011-04-21 9:46 ` [Qemu-devel] [RFC][PATCH v2 00/11] QEMU Guest Agent: QMP-based host/guest communication (virtagent) Jes Sorensen
2011-04-21 13:55 ` Michael Roth
2011-05-03 12:51 ` Jes Sorensen
2011-05-03 13:53 ` Michael Roth
2011-05-03 14:12 ` Jes Sorensen
2011-05-03 14:56 ` Michael Roth
2011-04-21 14:10 ` Jes Sorensen
2011-04-21 20:58 ` Michael Roth
2011-04-26 6:57 ` Jes Sorensen
2011-04-26 14:27 ` Michael Roth
2011-04-26 14:34 ` Jes Sorensen
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='BANLkTinSa4QK6ORVXcLRxsf-Goen6=KG_g@mail.gmail.com' \
--to=stefanha@gmail.com \
--cc=Jes.Sorensen@redhat.com \
--cc=agl@linux.vnet.ibm.com \
--cc=aliguori@linux.vnet.ibm.com \
--cc=mdroth@linux.vnet.ibm.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).