All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Mark Wu <wudxw@linux.vnet.ibm.com>
Cc: Michael Roth <mdroth@linux.vnet.ibm.com>,
	Qemu-devel@nongnu.org, Luiz Capitulino <lcapitulino@redhat.com>
Subject: Re: [Qemu-devel] [PATCH] Add interface to traverse the qmp command list by QmpCommand
Date: Wed, 25 Sep 2013 20:57:39 -0600	[thread overview]
Message-ID: <5243A2A3.2000502@redhat.com> (raw)
In-Reply-To: <1380160599-15659-1-git-send-email-wudxw@linux.vnet.ibm.com>

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

On 09/25/2013 07:56 PM, Mark Wu wrote:
> In the original code, qmp_get_command_list is used to construct
> a list of all commands' name. To get the information of all qga
> commands, it traverses the name list and search the command info
> with its name.  So it can cause O(n^2) in the number of commands.
> 
> This patch adds an interface to traverse the qmp command list by
> QmpCommand to replace qmp_get_command_list. It can decrease the
> complexity from O(n) to O(n^2)

from O(n^2) to O(n)

> 
> Signed-off-by: Mark Wu <wudxw@linux.vnet.ibm.com>
> ---
>  include/qapi/qmp/dispatch.h |  3 +-
>  qapi/qmp-registry.c         | 28 ++-----------------
>  qga/commands.c              | 39 ++++++++++----------------
>  qga/main.c                  | 68 +++++++++++++++++----------------------------
>  4 files changed, 45 insertions(+), 93 deletions(-)
> 

>  
> -bool qmp_command_is_enabled(const char *name)

I think one of Michael's suggestions was that you may still want
qmp_command_is_enabled, but with a new signature:

bool qmp_command_is_enabled(const QmpCommand *cmd)
{
    return cmd->enabled;
}

> -struct GuestAgentInfo *qmp_guest_info(Error **err)
> +static void qmp_command_info(QmpCommand *cmd, void *opaque)
>   {
> -    GuestAgentInfo *info = g_malloc0(sizeof(GuestAgentInfo));
> +    GuestAgentInfo *info = (GuestAgentInfo *)opaque; 

This is C, not C++.  The cast is not necessary.

> -        cmd_info->enabled = qmp_command_is_enabled(cmd_info->name);
>  
> -        cmd_info_list = g_malloc0(sizeof(GuestAgentCommandInfoList));
> -        cmd_info_list->value = cmd_info;
> -        cmd_info_list->next = info->supported_commands;
> -        info->supported_commands = cmd_info_list;
> +    cmd_info = g_malloc0(sizeof(GuestAgentCommandInfo));
> +    cmd_info->name = g_strdup(cmd->name);
> +    cmd_info->enabled = cmd->enabled;

I guess it all depends on whether we want QmpCommand to be an opaque
type outside of a single file.  But I don't have a strong argument for
making it opaque, and your approach works if we don't mind exposing the
details of QmpCommand across multiple files.  So I can live with your
patch as-is.


> +static void ga_enable_non_blacklisted(QmpCommand *cmd, void *opaque)
>  {

> +    GList *blacklist = (GList *)opaque;

Again, the cast is not necessary.

Overall, I like the patch.  Just a few tweaks suggested, but I can live
with you adding:

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 621 bytes --]

  parent reply	other threads:[~2013-09-26  2:57 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-26  1:56 [Qemu-devel] [PATCH] Add interface to traverse the qmp command list by QmpCommand Mark Wu
2013-09-26  2:36 ` Mark Wu
2013-09-26  2:57 ` Eric Blake [this message]
2013-09-27 16:07   ` Michael Roth
2013-09-27 16:16 ` Michael Roth

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=5243A2A3.2000502@redhat.com \
    --to=eblake@redhat.com \
    --cc=Qemu-devel@nongnu.org \
    --cc=lcapitulino@redhat.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=wudxw@linux.vnet.ibm.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.