From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48703) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VTX9i-0001LH-Mn for Qemu-devel@nongnu.org; Tue, 08 Oct 2013 09:16:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VTX9d-000746-P4 for Qemu-devel@nongnu.org; Tue, 08 Oct 2013 09:16:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44610) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VTX9d-00073z-Hk for Qemu-devel@nongnu.org; Tue, 08 Oct 2013 09:16:49 -0400 Message-ID: <52540574.6060602@redhat.com> Date: Tue, 08 Oct 2013 07:15:32 -0600 From: Eric Blake MIME-Version: 1.0 References: <1381213389-11440-1-git-send-email-wudxw@linux.vnet.ibm.com> In-Reply-To: <1381213389-11440-1-git-send-email-wudxw@linux.vnet.ibm.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="5vlVTG5tD2PXCule3NWq0mUIgqADcoMPg" Subject: Re: [Qemu-devel] [PATCH v2] Add interface to traverse the qmp command list by QmpCommand List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Mark Wu Cc: Michael Roth , Qemu-devel@nongnu.org, Luiz Capitulino This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --5vlVTG5tD2PXCule3NWq0mUIgqADcoMPg Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 10/08/2013 12:23 AM, 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. >=20 > 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^2) to O(n). >=20 > Signed-off-by: Mark Wu > --- > Changes: > v2: > 1. Keep the signature of qmp_command_is_enabled (per Eric and Michael)= > 2. Remove the unnecessary pointer castings (per Eric) >=20 > include/qapi/qmp/dispatch.h | 5 ++-- > qapi/qmp-registry.c | 27 +++--------------- > qga/commands.c | 38 ++++++++++--------------- > qga/main.c | 68 +++++++++++++++++--------------------= -------- > 4 files changed, 48 insertions(+), 90 deletions(-) Reviewed-by: Eric Blake > +++ b/qga/main.c > @@ -347,48 +347,34 @@ static gint ga_strcmp(gconstpointer str1, gconstp= ointer str2) > } > =20 > /* disable commands that aren't safe for fsfreeze */ > -static void ga_disable_non_whitelisted(void) > +static void ga_disable_non_whitelisted(QmpCommand *cmd, void *opaque) > { > - char **list_head, **list; > bool whitelisted; > int i; > =20 > - list_head =3D list =3D qmp_get_command_list(); > - while (*list !=3D NULL) { > - whitelisted =3D false; > - i =3D 0; > - while (ga_freeze_whitelist[i] !=3D NULL) { > - if (strcmp(*list, ga_freeze_whitelist[i]) =3D=3D 0) { > - whitelisted =3D true; > - } > - i++; > - } > - if (!whitelisted) { > - g_debug("disabling command: %s", *list); > - qmp_disable_command(*list); > + whitelisted =3D false; > + i =3D 0; > + while (ga_freeze_whitelist[i] !=3D NULL) { > + if (strcmp(cmd->name, ga_freeze_whitelist[i]) =3D=3D 0) { This (and several other instances) accesses cmd->name directly where we were formally using the string from the returned list. Should these spots be modified to go through an accessor method instead, similar to qmp_command_is_enabled, so that QmpCommand can be treated as an opaque type from this file? --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --5vlVTG5tD2PXCule3NWq0mUIgqADcoMPg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.14 (GNU/Linux) Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJSVAV0AAoJEKeha0olJ0NqRLEH/19ruvDnttouWfjMMd5AN6Y7 10KMVhsH95lWj2aZ4DOMvHgPRxDtAtXkwqH/9kmp7y1CHmJLy1dnx9CIFP375hDc o8lGgGgTth+83DLYfIH57lNO1s6HwAA3PxonKyjj/eE94d/s5kgAvJmuJTlPAmLG V3fPyZ6JTUaQoUl9ptCAYf06NGRyHE29JYdUCoxOFwx2Sr3IZNTeKQLVb7keIzBQ plmgCzZPlVdeW4IsaILD+LdmvkUxKHd6kAVNiMzk9e3BLIsYfZqbR3oUMwnyH1RO keI0SQ5G+spUB/T3mKtpfQvEO7r25DEdWHPb+OYxNter2oK8wz34IQk5vOW8urE= =8Y59 -----END PGP SIGNATURE----- --5vlVTG5tD2PXCule3NWq0mUIgqADcoMPg--