diff mbox

[12/21] qapi: Convert query-version

Message ID 1317221085-5825-13-git-send-email-lcapitulino@redhat.com
State New
Headers show

Commit Message

Luiz Capitulino Sept. 28, 2011, 2:44 p.m. UTC
The original conversion was done by Anthony Liguori. This commit
is just a rebase.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 hmp.c            |   13 +++++++++++++
 hmp.h            |    1 +
 monitor.c        |   46 +++-------------------------------------------
 qapi-schema.json |   37 +++++++++++++++++++++++++++++++++++++
 qmp-commands.hx  |    6 ++++++
 qmp.c            |   16 ++++++++++++++++
 6 files changed, 76 insertions(+), 43 deletions(-)

Comments

Anthony Liguori Sept. 29, 2011, 12:54 p.m. UTC | #1
On 09/28/2011 09:44 AM, Luiz Capitulino wrote:
> The original conversion was done by Anthony Liguori. This commit
> is just a rebase.

For all of the rest of the patches, you can add my Signed-off-by: before your 
SoB.  Then you don't need to have the disclaimer in the commit message.

Regards,

Anthony Liguori

>
> Signed-off-by: Luiz Capitulino<lcapitulino@redhat.com>
> ---
>   hmp.c            |   13 +++++++++++++
>   hmp.h            |    1 +
>   monitor.c        |   46 +++-------------------------------------------
>   qapi-schema.json |   37 +++++++++++++++++++++++++++++++++++++
>   qmp-commands.hx  |    6 ++++++
>   qmp.c            |   16 ++++++++++++++++
>   6 files changed, 76 insertions(+), 43 deletions(-)
>
> diff --git a/hmp.c b/hmp.c
> index 47e1ff7..bb6c86f 100644
> --- a/hmp.c
> +++ b/hmp.c
> @@ -24,3 +24,16 @@ void hmp_info_name(Monitor *mon)
>       }
>       qapi_free_NameInfo(info);
>   }
> +
> +void hmp_info_version(Monitor *mon)
> +{
> +    VersionInfo *info;
> +
> +    info = qmp_query_version(NULL);
> +
> +    monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
> +                   info->qemu.major, info->qemu.minor, info->qemu.micro,
> +                   info->package);
> +
> +    qapi_free_VersionInfo(info);
> +}
> diff --git a/hmp.h b/hmp.h
> index 5fe73f1..2aa75a2 100644
> --- a/hmp.h
> +++ b/hmp.h
> @@ -18,5 +18,6 @@
>   #include "qapi-types.h"
>
>   void hmp_info_name(Monitor *mon);
> +void hmp_info_version(Monitor *mon);
>
>   #endif
> diff --git a/monitor.c b/monitor.c
> index 8af0e27..9edc38c 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -730,37 +730,6 @@ help:
>       help_cmd(mon, "info");
>   }
>
> -static void do_info_version_print(Monitor *mon, const QObject *data)
> -{
> -    QDict *qdict;
> -    QDict *qemu;
> -
> -    qdict = qobject_to_qdict(data);
> -    qemu = qdict_get_qdict(qdict, "qemu");
> -
> -    monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
> -                  qdict_get_int(qemu, "major"),
> -                  qdict_get_int(qemu, "minor"),
> -                  qdict_get_int(qemu, "micro"),
> -                  qdict_get_str(qdict, "package"));
> -}
> -
> -static void do_info_version(Monitor *mon, QObject **ret_data)
> -{
> -    const char *version = QEMU_VERSION;
> -    int major = 0, minor = 0, micro = 0;
> -    char *tmp;
> -
> -    major = strtol(version,&tmp, 10);
> -    tmp++;
> -    minor = strtol(tmp,&tmp, 10);
> -    tmp++;
> -    micro = strtol(tmp,&tmp, 10);
> -
> -    *ret_data = qobject_from_jsonf("{ 'qemu': { 'major': %d, 'minor': %d, \
> -        'micro': %d }, 'package': %s }", major, minor, micro, QEMU_PKGVERSION);
> -}
> -
>   static QObject *get_cmd_dict(const char *name)
>   {
>       const char *p;
> @@ -2866,8 +2835,7 @@ static const mon_cmd_t info_cmds[] = {
>           .args_type  = "",
>           .params     = "",
>           .help       = "show the version of QEMU",
> -        .user_print = do_info_version_print,
> -        .mhandler.info_new = do_info_version,
> +        .mhandler.info = hmp_info_version,
>       },
>       {
>           .name       = "network",
> @@ -3159,14 +3127,6 @@ static const mon_cmd_t qmp_cmds[] = {
>
>   static const mon_cmd_t qmp_query_cmds[] = {
>       {
> -        .name       = "version",
> -        .args_type  = "",
> -        .params     = "",
> -        .help       = "show the version of QEMU",
> -        .user_print = do_info_version_print,
> -        .mhandler.info_new = do_info_version,
> -    },
> -    {
>           .name       = "commands",
>           .args_type  = "",
>           .params     = "",
> @@ -5172,9 +5132,9 @@ void monitor_resume(Monitor *mon)
>
>   static QObject *get_qmp_greeting(void)
>   {
> -    QObject *ver;
> +    QObject *ver = NULL;
>
> -    do_info_version(NULL,&ver);
> +    qmp_marshal_input_query_version(NULL, NULL,&ver);
>       return qobject_from_jsonf("{'QMP':{'version': %p,'capabilities': []}}",ver);
>   }
>
> diff --git a/qapi-schema.json b/qapi-schema.json
> index 3585324..3c0ac4e 100644
> --- a/qapi-schema.json
> +++ b/qapi-schema.json
> @@ -23,3 +23,40 @@
>   # Since 0.14.0
>   ##
>   { 'command': 'query-name', 'returns': 'NameInfo' }
> +
> +##
> +# @VersionInfo:
> +#
> +# A description of QEMU's version.
> +#
> +# @qemu.major:  The major version of QEMU
> +#
> +# @qemu.minor:  The minor version of QEMU
> +#
> +# @qemu.micro:  The micro version of QEMU.  By current convention, a micro
> +#               version of 50 signifies a development branch.  A micro version
> +#               greater than or equal to 90 signifies a release candidate for
> +#               the next minor version.  A micro version of less than 50
> +#               signifies a stable release.
> +#
> +# @package:     QEMU will always set this field to an empty string.  Downstream
> +#               versions of QEMU should set this to a non-empty string.  The
> +#               exact format depends on the downstream however it highly
> +#               recommended that a unique name is used.
> +#
> +# Since: 0.14.0
> +##
> +{ 'type': 'VersionInfo',
> +  'data': {'qemu': {'major': 'int', 'minor': 'int', 'micro': 'int'},
> +           'package': 'str'} }
> +
> +##
> +# @query-version:
> +#
> +# Returns the current version of QEMU.
> +#
> +# Returns:  A @VersionInfo object describing the current version of QEMU.
> +#
> +# Since: 0.14.0
> +##
> +{ 'command': 'query-version', 'returns': 'VersionInfo' }
> diff --git a/qmp-commands.hx b/qmp-commands.hx
> index 7b3839e..9f067ea 100644
> --- a/qmp-commands.hx
> +++ b/qmp-commands.hx
> @@ -1053,6 +1053,12 @@ Example:
>
>   EQMP
>
> +    {
> +        .name       = "query-version",
> +        .args_type  = "",
> +        .mhandler.cmd_new = qmp_marshal_input_query_version,
> +    },
> +
>   SQMP
>   query-commands
>   --------------
> diff --git a/qmp.c b/qmp.c
> index 8aa9c66..f978ea4 100644
> --- a/qmp.c
> +++ b/qmp.c
> @@ -26,3 +26,19 @@ NameInfo *qmp_query_name(Error **errp)
>
>       return info;
>   }
> +
> +VersionInfo *qmp_query_version(Error **err)
> +{
> +    VersionInfo *info = g_malloc0(sizeof(*info));
> +    const char *version = QEMU_VERSION;
> +    char *tmp;
> +
> +    info->qemu.major = strtol(version,&tmp, 10);
> +    tmp++;
> +    info->qemu.minor = strtol(tmp,&tmp, 10);
> +    tmp++;
> +    info->qemu.micro = strtol(tmp,&tmp, 10);
> +    info->package = g_strdup(QEMU_PKGVERSION);
> +
> +    return info;
> +}
Luiz Capitulino Sept. 29, 2011, 2:32 p.m. UTC | #2
On Thu, 29 Sep 2011 07:54:57 -0500
Anthony Liguori <aliguori@us.ibm.com> wrote:

> On 09/28/2011 09:44 AM, Luiz Capitulino wrote:
> > The original conversion was done by Anthony Liguori. This commit
> > is just a rebase.
> 
> For all of the rest of the patches, you can add my Signed-off-by: before your 
> SoB.  Then you don't need to have the disclaimer in the commit message.

And I let the author as being me?

> 
> Regards,
> 
> Anthony Liguori
> 
> >
> > Signed-off-by: Luiz Capitulino<lcapitulino@redhat.com>
> > ---
> >   hmp.c            |   13 +++++++++++++
> >   hmp.h            |    1 +
> >   monitor.c        |   46 +++-------------------------------------------
> >   qapi-schema.json |   37 +++++++++++++++++++++++++++++++++++++
> >   qmp-commands.hx  |    6 ++++++
> >   qmp.c            |   16 ++++++++++++++++
> >   6 files changed, 76 insertions(+), 43 deletions(-)
> >
> > diff --git a/hmp.c b/hmp.c
> > index 47e1ff7..bb6c86f 100644
> > --- a/hmp.c
> > +++ b/hmp.c
> > @@ -24,3 +24,16 @@ void hmp_info_name(Monitor *mon)
> >       }
> >       qapi_free_NameInfo(info);
> >   }
> > +
> > +void hmp_info_version(Monitor *mon)
> > +{
> > +    VersionInfo *info;
> > +
> > +    info = qmp_query_version(NULL);
> > +
> > +    monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
> > +                   info->qemu.major, info->qemu.minor, info->qemu.micro,
> > +                   info->package);
> > +
> > +    qapi_free_VersionInfo(info);
> > +}
> > diff --git a/hmp.h b/hmp.h
> > index 5fe73f1..2aa75a2 100644
> > --- a/hmp.h
> > +++ b/hmp.h
> > @@ -18,5 +18,6 @@
> >   #include "qapi-types.h"
> >
> >   void hmp_info_name(Monitor *mon);
> > +void hmp_info_version(Monitor *mon);
> >
> >   #endif
> > diff --git a/monitor.c b/monitor.c
> > index 8af0e27..9edc38c 100644
> > --- a/monitor.c
> > +++ b/monitor.c
> > @@ -730,37 +730,6 @@ help:
> >       help_cmd(mon, "info");
> >   }
> >
> > -static void do_info_version_print(Monitor *mon, const QObject *data)
> > -{
> > -    QDict *qdict;
> > -    QDict *qemu;
> > -
> > -    qdict = qobject_to_qdict(data);
> > -    qemu = qdict_get_qdict(qdict, "qemu");
> > -
> > -    monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
> > -                  qdict_get_int(qemu, "major"),
> > -                  qdict_get_int(qemu, "minor"),
> > -                  qdict_get_int(qemu, "micro"),
> > -                  qdict_get_str(qdict, "package"));
> > -}
> > -
> > -static void do_info_version(Monitor *mon, QObject **ret_data)
> > -{
> > -    const char *version = QEMU_VERSION;
> > -    int major = 0, minor = 0, micro = 0;
> > -    char *tmp;
> > -
> > -    major = strtol(version,&tmp, 10);
> > -    tmp++;
> > -    minor = strtol(tmp,&tmp, 10);
> > -    tmp++;
> > -    micro = strtol(tmp,&tmp, 10);
> > -
> > -    *ret_data = qobject_from_jsonf("{ 'qemu': { 'major': %d, 'minor': %d, \
> > -        'micro': %d }, 'package': %s }", major, minor, micro, QEMU_PKGVERSION);
> > -}
> > -
> >   static QObject *get_cmd_dict(const char *name)
> >   {
> >       const char *p;
> > @@ -2866,8 +2835,7 @@ static const mon_cmd_t info_cmds[] = {
> >           .args_type  = "",
> >           .params     = "",
> >           .help       = "show the version of QEMU",
> > -        .user_print = do_info_version_print,
> > -        .mhandler.info_new = do_info_version,
> > +        .mhandler.info = hmp_info_version,
> >       },
> >       {
> >           .name       = "network",
> > @@ -3159,14 +3127,6 @@ static const mon_cmd_t qmp_cmds[] = {
> >
> >   static const mon_cmd_t qmp_query_cmds[] = {
> >       {
> > -        .name       = "version",
> > -        .args_type  = "",
> > -        .params     = "",
> > -        .help       = "show the version of QEMU",
> > -        .user_print = do_info_version_print,
> > -        .mhandler.info_new = do_info_version,
> > -    },
> > -    {
> >           .name       = "commands",
> >           .args_type  = "",
> >           .params     = "",
> > @@ -5172,9 +5132,9 @@ void monitor_resume(Monitor *mon)
> >
> >   static QObject *get_qmp_greeting(void)
> >   {
> > -    QObject *ver;
> > +    QObject *ver = NULL;
> >
> > -    do_info_version(NULL,&ver);
> > +    qmp_marshal_input_query_version(NULL, NULL,&ver);
> >       return qobject_from_jsonf("{'QMP':{'version': %p,'capabilities': []}}",ver);
> >   }
> >
> > diff --git a/qapi-schema.json b/qapi-schema.json
> > index 3585324..3c0ac4e 100644
> > --- a/qapi-schema.json
> > +++ b/qapi-schema.json
> > @@ -23,3 +23,40 @@
> >   # Since 0.14.0
> >   ##
> >   { 'command': 'query-name', 'returns': 'NameInfo' }
> > +
> > +##
> > +# @VersionInfo:
> > +#
> > +# A description of QEMU's version.
> > +#
> > +# @qemu.major:  The major version of QEMU
> > +#
> > +# @qemu.minor:  The minor version of QEMU
> > +#
> > +# @qemu.micro:  The micro version of QEMU.  By current convention, a micro
> > +#               version of 50 signifies a development branch.  A micro version
> > +#               greater than or equal to 90 signifies a release candidate for
> > +#               the next minor version.  A micro version of less than 50
> > +#               signifies a stable release.
> > +#
> > +# @package:     QEMU will always set this field to an empty string.  Downstream
> > +#               versions of QEMU should set this to a non-empty string.  The
> > +#               exact format depends on the downstream however it highly
> > +#               recommended that a unique name is used.
> > +#
> > +# Since: 0.14.0
> > +##
> > +{ 'type': 'VersionInfo',
> > +  'data': {'qemu': {'major': 'int', 'minor': 'int', 'micro': 'int'},
> > +           'package': 'str'} }
> > +
> > +##
> > +# @query-version:
> > +#
> > +# Returns the current version of QEMU.
> > +#
> > +# Returns:  A @VersionInfo object describing the current version of QEMU.
> > +#
> > +# Since: 0.14.0
> > +##
> > +{ 'command': 'query-version', 'returns': 'VersionInfo' }
> > diff --git a/qmp-commands.hx b/qmp-commands.hx
> > index 7b3839e..9f067ea 100644
> > --- a/qmp-commands.hx
> > +++ b/qmp-commands.hx
> > @@ -1053,6 +1053,12 @@ Example:
> >
> >   EQMP
> >
> > +    {
> > +        .name       = "query-version",
> > +        .args_type  = "",
> > +        .mhandler.cmd_new = qmp_marshal_input_query_version,
> > +    },
> > +
> >   SQMP
> >   query-commands
> >   --------------
> > diff --git a/qmp.c b/qmp.c
> > index 8aa9c66..f978ea4 100644
> > --- a/qmp.c
> > +++ b/qmp.c
> > @@ -26,3 +26,19 @@ NameInfo *qmp_query_name(Error **errp)
> >
> >       return info;
> >   }
> > +
> > +VersionInfo *qmp_query_version(Error **err)
> > +{
> > +    VersionInfo *info = g_malloc0(sizeof(*info));
> > +    const char *version = QEMU_VERSION;
> > +    char *tmp;
> > +
> > +    info->qemu.major = strtol(version,&tmp, 10);
> > +    tmp++;
> > +    info->qemu.minor = strtol(tmp,&tmp, 10);
> > +    tmp++;
> > +    info->qemu.micro = strtol(tmp,&tmp, 10);
> > +    info->package = g_strdup(QEMU_PKGVERSION);
> > +
> > +    return info;
> > +}
>
Anthony Liguori Sept. 29, 2011, 2:42 p.m. UTC | #3
On 09/29/2011 09:32 AM, Luiz Capitulino wrote:
> On Thu, 29 Sep 2011 07:54:57 -0500
> Anthony Liguori<aliguori@us.ibm.com>  wrote:
>
>> On 09/28/2011 09:44 AM, Luiz Capitulino wrote:
>>> The original conversion was done by Anthony Liguori. This commit
>>> is just a rebase.
>>
>> For all of the rest of the patches, you can add my Signed-off-by: before your
>> SoB.  Then you don't need to have the disclaimer in the commit message.
>
> And I let the author as being me?

Sure.

Regards,

Anthony Liguori

>
>>
>> Regards,
>>
>> Anthony Liguori
>>
>>>
>>> Signed-off-by: Luiz Capitulino<lcapitulino@redhat.com>
>>> ---
>>>    hmp.c            |   13 +++++++++++++
>>>    hmp.h            |    1 +
>>>    monitor.c        |   46 +++-------------------------------------------
>>>    qapi-schema.json |   37 +++++++++++++++++++++++++++++++++++++
>>>    qmp-commands.hx  |    6 ++++++
>>>    qmp.c            |   16 ++++++++++++++++
>>>    6 files changed, 76 insertions(+), 43 deletions(-)
>>>
>>> diff --git a/hmp.c b/hmp.c
>>> index 47e1ff7..bb6c86f 100644
>>> --- a/hmp.c
>>> +++ b/hmp.c
>>> @@ -24,3 +24,16 @@ void hmp_info_name(Monitor *mon)
>>>        }
>>>        qapi_free_NameInfo(info);
>>>    }
>>> +
>>> +void hmp_info_version(Monitor *mon)
>>> +{
>>> +    VersionInfo *info;
>>> +
>>> +    info = qmp_query_version(NULL);
>>> +
>>> +    monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
>>> +                   info->qemu.major, info->qemu.minor, info->qemu.micro,
>>> +                   info->package);
>>> +
>>> +    qapi_free_VersionInfo(info);
>>> +}
>>> diff --git a/hmp.h b/hmp.h
>>> index 5fe73f1..2aa75a2 100644
>>> --- a/hmp.h
>>> +++ b/hmp.h
>>> @@ -18,5 +18,6 @@
>>>    #include "qapi-types.h"
>>>
>>>    void hmp_info_name(Monitor *mon);
>>> +void hmp_info_version(Monitor *mon);
>>>
>>>    #endif
>>> diff --git a/monitor.c b/monitor.c
>>> index 8af0e27..9edc38c 100644
>>> --- a/monitor.c
>>> +++ b/monitor.c
>>> @@ -730,37 +730,6 @@ help:
>>>        help_cmd(mon, "info");
>>>    }
>>>
>>> -static void do_info_version_print(Monitor *mon, const QObject *data)
>>> -{
>>> -    QDict *qdict;
>>> -    QDict *qemu;
>>> -
>>> -    qdict = qobject_to_qdict(data);
>>> -    qemu = qdict_get_qdict(qdict, "qemu");
>>> -
>>> -    monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
>>> -                  qdict_get_int(qemu, "major"),
>>> -                  qdict_get_int(qemu, "minor"),
>>> -                  qdict_get_int(qemu, "micro"),
>>> -                  qdict_get_str(qdict, "package"));
>>> -}
>>> -
>>> -static void do_info_version(Monitor *mon, QObject **ret_data)
>>> -{
>>> -    const char *version = QEMU_VERSION;
>>> -    int major = 0, minor = 0, micro = 0;
>>> -    char *tmp;
>>> -
>>> -    major = strtol(version,&tmp, 10);
>>> -    tmp++;
>>> -    minor = strtol(tmp,&tmp, 10);
>>> -    tmp++;
>>> -    micro = strtol(tmp,&tmp, 10);
>>> -
>>> -    *ret_data = qobject_from_jsonf("{ 'qemu': { 'major': %d, 'minor': %d, \
>>> -        'micro': %d }, 'package': %s }", major, minor, micro, QEMU_PKGVERSION);
>>> -}
>>> -
>>>    static QObject *get_cmd_dict(const char *name)
>>>    {
>>>        const char *p;
>>> @@ -2866,8 +2835,7 @@ static const mon_cmd_t info_cmds[] = {
>>>            .args_type  = "",
>>>            .params     = "",
>>>            .help       = "show the version of QEMU",
>>> -        .user_print = do_info_version_print,
>>> -        .mhandler.info_new = do_info_version,
>>> +        .mhandler.info = hmp_info_version,
>>>        },
>>>        {
>>>            .name       = "network",
>>> @@ -3159,14 +3127,6 @@ static const mon_cmd_t qmp_cmds[] = {
>>>
>>>    static const mon_cmd_t qmp_query_cmds[] = {
>>>        {
>>> -        .name       = "version",
>>> -        .args_type  = "",
>>> -        .params     = "",
>>> -        .help       = "show the version of QEMU",
>>> -        .user_print = do_info_version_print,
>>> -        .mhandler.info_new = do_info_version,
>>> -    },
>>> -    {
>>>            .name       = "commands",
>>>            .args_type  = "",
>>>            .params     = "",
>>> @@ -5172,9 +5132,9 @@ void monitor_resume(Monitor *mon)
>>>
>>>    static QObject *get_qmp_greeting(void)
>>>    {
>>> -    QObject *ver;
>>> +    QObject *ver = NULL;
>>>
>>> -    do_info_version(NULL,&ver);
>>> +    qmp_marshal_input_query_version(NULL, NULL,&ver);
>>>        return qobject_from_jsonf("{'QMP':{'version': %p,'capabilities': []}}",ver);
>>>    }
>>>
>>> diff --git a/qapi-schema.json b/qapi-schema.json
>>> index 3585324..3c0ac4e 100644
>>> --- a/qapi-schema.json
>>> +++ b/qapi-schema.json
>>> @@ -23,3 +23,40 @@
>>>    # Since 0.14.0
>>>    ##
>>>    { 'command': 'query-name', 'returns': 'NameInfo' }
>>> +
>>> +##
>>> +# @VersionInfo:
>>> +#
>>> +# A description of QEMU's version.
>>> +#
>>> +# @qemu.major:  The major version of QEMU
>>> +#
>>> +# @qemu.minor:  The minor version of QEMU
>>> +#
>>> +# @qemu.micro:  The micro version of QEMU.  By current convention, a micro
>>> +#               version of 50 signifies a development branch.  A micro version
>>> +#               greater than or equal to 90 signifies a release candidate for
>>> +#               the next minor version.  A micro version of less than 50
>>> +#               signifies a stable release.
>>> +#
>>> +# @package:     QEMU will always set this field to an empty string.  Downstream
>>> +#               versions of QEMU should set this to a non-empty string.  The
>>> +#               exact format depends on the downstream however it highly
>>> +#               recommended that a unique name is used.
>>> +#
>>> +# Since: 0.14.0
>>> +##
>>> +{ 'type': 'VersionInfo',
>>> +  'data': {'qemu': {'major': 'int', 'minor': 'int', 'micro': 'int'},
>>> +           'package': 'str'} }
>>> +
>>> +##
>>> +# @query-version:
>>> +#
>>> +# Returns the current version of QEMU.
>>> +#
>>> +# Returns:  A @VersionInfo object describing the current version of QEMU.
>>> +#
>>> +# Since: 0.14.0
>>> +##
>>> +{ 'command': 'query-version', 'returns': 'VersionInfo' }
>>> diff --git a/qmp-commands.hx b/qmp-commands.hx
>>> index 7b3839e..9f067ea 100644
>>> --- a/qmp-commands.hx
>>> +++ b/qmp-commands.hx
>>> @@ -1053,6 +1053,12 @@ Example:
>>>
>>>    EQMP
>>>
>>> +    {
>>> +        .name       = "query-version",
>>> +        .args_type  = "",
>>> +        .mhandler.cmd_new = qmp_marshal_input_query_version,
>>> +    },
>>> +
>>>    SQMP
>>>    query-commands
>>>    --------------
>>> diff --git a/qmp.c b/qmp.c
>>> index 8aa9c66..f978ea4 100644
>>> --- a/qmp.c
>>> +++ b/qmp.c
>>> @@ -26,3 +26,19 @@ NameInfo *qmp_query_name(Error **errp)
>>>
>>>        return info;
>>>    }
>>> +
>>> +VersionInfo *qmp_query_version(Error **err)
>>> +{
>>> +    VersionInfo *info = g_malloc0(sizeof(*info));
>>> +    const char *version = QEMU_VERSION;
>>> +    char *tmp;
>>> +
>>> +    info->qemu.major = strtol(version,&tmp, 10);
>>> +    tmp++;
>>> +    info->qemu.minor = strtol(tmp,&tmp, 10);
>>> +    tmp++;
>>> +    info->qemu.micro = strtol(tmp,&tmp, 10);
>>> +    info->package = g_strdup(QEMU_PKGVERSION);
>>> +
>>> +    return info;
>>> +}
>>
>
>
diff mbox

Patch

diff --git a/hmp.c b/hmp.c
index 47e1ff7..bb6c86f 100644
--- a/hmp.c
+++ b/hmp.c
@@ -24,3 +24,16 @@  void hmp_info_name(Monitor *mon)
     }
     qapi_free_NameInfo(info);
 }
+
+void hmp_info_version(Monitor *mon)
+{
+    VersionInfo *info;
+
+    info = qmp_query_version(NULL);
+
+    monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
+                   info->qemu.major, info->qemu.minor, info->qemu.micro,
+                   info->package);
+
+    qapi_free_VersionInfo(info);
+}
diff --git a/hmp.h b/hmp.h
index 5fe73f1..2aa75a2 100644
--- a/hmp.h
+++ b/hmp.h
@@ -18,5 +18,6 @@ 
 #include "qapi-types.h"
 
 void hmp_info_name(Monitor *mon);
+void hmp_info_version(Monitor *mon);
 
 #endif
diff --git a/monitor.c b/monitor.c
index 8af0e27..9edc38c 100644
--- a/monitor.c
+++ b/monitor.c
@@ -730,37 +730,6 @@  help:
     help_cmd(mon, "info");
 }
 
-static void do_info_version_print(Monitor *mon, const QObject *data)
-{
-    QDict *qdict;
-    QDict *qemu;
-
-    qdict = qobject_to_qdict(data);
-    qemu = qdict_get_qdict(qdict, "qemu");
-
-    monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
-                  qdict_get_int(qemu, "major"),
-                  qdict_get_int(qemu, "minor"),
-                  qdict_get_int(qemu, "micro"),
-                  qdict_get_str(qdict, "package"));
-}
-
-static void do_info_version(Monitor *mon, QObject **ret_data)
-{
-    const char *version = QEMU_VERSION;
-    int major = 0, minor = 0, micro = 0;
-    char *tmp;
-
-    major = strtol(version, &tmp, 10);
-    tmp++;
-    minor = strtol(tmp, &tmp, 10);
-    tmp++;
-    micro = strtol(tmp, &tmp, 10);
-
-    *ret_data = qobject_from_jsonf("{ 'qemu': { 'major': %d, 'minor': %d, \
-        'micro': %d }, 'package': %s }", major, minor, micro, QEMU_PKGVERSION);
-}
-
 static QObject *get_cmd_dict(const char *name)
 {
     const char *p;
@@ -2866,8 +2835,7 @@  static const mon_cmd_t info_cmds[] = {
         .args_type  = "",
         .params     = "",
         .help       = "show the version of QEMU",
-        .user_print = do_info_version_print,
-        .mhandler.info_new = do_info_version,
+        .mhandler.info = hmp_info_version,
     },
     {
         .name       = "network",
@@ -3159,14 +3127,6 @@  static const mon_cmd_t qmp_cmds[] = {
 
 static const mon_cmd_t qmp_query_cmds[] = {
     {
-        .name       = "version",
-        .args_type  = "",
-        .params     = "",
-        .help       = "show the version of QEMU",
-        .user_print = do_info_version_print,
-        .mhandler.info_new = do_info_version,
-    },
-    {
         .name       = "commands",
         .args_type  = "",
         .params     = "",
@@ -5172,9 +5132,9 @@  void monitor_resume(Monitor *mon)
 
 static QObject *get_qmp_greeting(void)
 {
-    QObject *ver;
+    QObject *ver = NULL;
 
-    do_info_version(NULL, &ver);
+    qmp_marshal_input_query_version(NULL, NULL, &ver);
     return qobject_from_jsonf("{'QMP':{'version': %p,'capabilities': []}}",ver);
 }
 
diff --git a/qapi-schema.json b/qapi-schema.json
index 3585324..3c0ac4e 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -23,3 +23,40 @@ 
 # Since 0.14.0
 ##
 { 'command': 'query-name', 'returns': 'NameInfo' }
+
+##
+# @VersionInfo:
+#
+# A description of QEMU's version.
+#
+# @qemu.major:  The major version of QEMU
+#
+# @qemu.minor:  The minor version of QEMU
+#
+# @qemu.micro:  The micro version of QEMU.  By current convention, a micro
+#               version of 50 signifies a development branch.  A micro version
+#               greater than or equal to 90 signifies a release candidate for
+#               the next minor version.  A micro version of less than 50
+#               signifies a stable release.
+#
+# @package:     QEMU will always set this field to an empty string.  Downstream
+#               versions of QEMU should set this to a non-empty string.  The
+#               exact format depends on the downstream however it highly
+#               recommended that a unique name is used.
+#
+# Since: 0.14.0
+##
+{ 'type': 'VersionInfo',
+  'data': {'qemu': {'major': 'int', 'minor': 'int', 'micro': 'int'},
+           'package': 'str'} }
+
+##
+# @query-version:
+#
+# Returns the current version of QEMU.
+#
+# Returns:  A @VersionInfo object describing the current version of QEMU.
+#
+# Since: 0.14.0
+##
+{ 'command': 'query-version', 'returns': 'VersionInfo' }
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 7b3839e..9f067ea 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -1053,6 +1053,12 @@  Example:
 
 EQMP
 
+    {
+        .name       = "query-version",
+        .args_type  = "",
+        .mhandler.cmd_new = qmp_marshal_input_query_version,
+    },
+
 SQMP
 query-commands
 --------------
diff --git a/qmp.c b/qmp.c
index 8aa9c66..f978ea4 100644
--- a/qmp.c
+++ b/qmp.c
@@ -26,3 +26,19 @@  NameInfo *qmp_query_name(Error **errp)
 
     return info;
 }
+
+VersionInfo *qmp_query_version(Error **err)
+{
+    VersionInfo *info = g_malloc0(sizeof(*info));
+    const char *version = QEMU_VERSION;
+    char *tmp;
+
+    info->qemu.major = strtol(version, &tmp, 10);
+    tmp++;
+    info->qemu.minor = strtol(tmp, &tmp, 10);
+    tmp++;
+    info->qemu.micro = strtol(tmp, &tmp, 10);
+    info->package = g_strdup(QEMU_PKGVERSION);
+
+    return info;
+}