qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] QMP command implementation help
@ 2012-12-17  5:51 Shraddha Kamat
  2012-12-17 12:09 ` Luiz Capitulino
  0 siblings, 1 reply; 2+ messages in thread
From: Shraddha Kamat @ 2012-12-17  5:51 UTC (permalink / raw)
  To: qemu-devel; +Cc: Adam Litke, Markus Armbruster, Luiz Capitulino

I am implementing couple of QMP commands to Qemu - so trying a 
hello-world command first as shown here
https://github.com/qemu/qemu/blob/master/docs/writing-qmp-commands.txt

Step 1 :
========
Added to qapi-schema.json file this :
{ 'command': 'hello-world' }

Step 2:
=======
Added to qmp.c :

void qmp_hello_world(Error **errp)
{
    printf("Hello, world!\n");
}

Step 3 :
========
Added to qmp-commands.hx :
   {
        .name = "hello-world",
        .args_type = "",
        .mhandler.cmd_new = qmp_marshal_input_hello_world,
   },

and build upstream Qemu-kvm : 


Then tried to test the command hello-world :

# telnet localhost 4444
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
{
    "QMP": {
        "version": {
            "qemu": {
                "micro": 50, 
                "minor": 2, 
                "major": 1
            }, 
            "package": " (qemu-kvm-devel)"
        }, 
        "capabilities": [
        ]
    }
}
{ "execute": "qmp_capabilities" }
{
    "return": {
    }
}
{ "execute": "hello-world" }
{
    "error": {
        "class": "CommandNotFound", 
        "desc": "The command hello-world has not been found"
    }
}
------------------------------------------------------

I debugged a bit - 

qemu-kvm/x86_64-softmmu/qmp-commands-old.h
has this entry :
{
.name       = "hello-world",
.args_type  = "",
.mhandler.cmd_new = qmp_marshal_input_hello_world,
},

but in monitor.c/qmp_find_cmd() - qmp_cmds doesn't have 
this entry and hence the error !!

Note that qemu_cmds is defined as 

static const mon_cmd_t qmp_cmds[] = {
#include "qmp-commands-old.h"
    { /* NULL */ },
};

in monitor.c. 

What might be causing qmp-commands-old.h not to load qmp_cmds[] with
hello-world command entry ? Please help.

-- Shraddha

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Qemu-devel] QMP command implementation help
  2012-12-17  5:51 [Qemu-devel] QMP command implementation help Shraddha Kamat
@ 2012-12-17 12:09 ` Luiz Capitulino
  0 siblings, 0 replies; 2+ messages in thread
From: Luiz Capitulino @ 2012-12-17 12:09 UTC (permalink / raw)
  To: Shraddha Kamat; +Cc: Adam Litke, qemu-devel, Markus Armbruster

On Mon, 17 Dec 2012 11:21:10 +0530
Shraddha Kamat <sh2008ka@gmail.com> wrote:

> I am implementing couple of QMP commands to Qemu - so trying a 
> hello-world command first as shown here
> https://github.com/qemu/qemu/blob/master/docs/writing-qmp-commands.txt
> 
> Step 1 :
> ========
> Added to qapi-schema.json file this :
> { 'command': 'hello-world' }
> 
> Step 2:
> =======
> Added to qmp.c :
> 
> void qmp_hello_world(Error **errp)
> {
>     printf("Hello, world!\n");
> }
> 
> Step 3 :
> ========
> Added to qmp-commands.hx :
>    {
>         .name = "hello-world",
>         .args_type = "",
>         .mhandler.cmd_new = qmp_marshal_input_hello_world,
>    },
> 
> and build upstream Qemu-kvm : 

Shraddha, I've just followed the three steps above and things just worked
for me:

{
    "QMP": {
        "version": {
            "qemu": {
                "micro": 50, 
                "minor": 3, 
                "major": 1
            }, 
            "package": ""
        }, 
        "capabilities": [
        ]
    }
}
{ "execute": "qmp_capabilities" }
{
    "return": {
    }
}
{ "execute": "hello-world" }
{
    "return": {
    }
}

Patch below. There must something wrong with your tree. What's the qemu
version you're using?

diff --git a/qapi-schema.json b/qapi-schema.json
index 5dfa052..717d201 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -3017,3 +3017,5 @@
 # Since: 1.3.0
 ##
 { 'command': 'nbd-server-stop' }
+
+{ 'command': 'hello-world' }
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 5c692d0..50db26e 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -2654,3 +2654,9 @@ EQMP
         .args_type  = "",
         .mhandler.cmd_new = qmp_marshal_input_query_target,
     },
+
+	{
+		.name = "hello-world",
+		.args_type = "",
+		.mhandler.cmd_new = qmp_marshal_input_hello_world,
+	},
diff --git a/qmp.c b/qmp.c
index e3a7f0b..e5bfc35 100644
--- a/qmp.c
+++ b/qmp.c
@@ -519,3 +519,8 @@ void qmp_add_client(const char *protocol, const char *fdname,
     error_setg(errp, "protocol '%s' is invalid", protocol);
     close(fd);
 }
+
+void qmp_hello_world(Error **errp)
+{
+    printf("Hello, world!\n");
+}

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-12-17 12:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-17  5:51 [Qemu-devel] QMP command implementation help Shraddha Kamat
2012-12-17 12:09 ` Luiz Capitulino

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).