Received: from eggs.gnu.org ([2001:4830:134:3::10]:33589) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cCHCE-0007hv-Kl for qemu-devel@nongnu.org; Wed, 30 Nov 2016 21:34:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cCHCB-0001Ee-I0 for qemu-devel@nongnu.org; Wed, 30 Nov 2016 21:34:02 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48442) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cCHCB-0001Dr-8v for qemu-devel@nongnu.org; Wed, 30 Nov 2016 21:33:59 -0500 References: <1480547176-19349-1-git-send-email-mdroth@linux.vnet.ibm.com> From: Eric Blake Message-ID: <57ed5b82-2a1a-4318-d4ce-0c2eaa74d8e6@redhat.com> Date: Wed, 30 Nov 2016 20:33:56 -0600 MIME-Version: 1.0 In-Reply-To: <1480547176-19349-1-git-send-email-mdroth@linux.vnet.ibm.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="1AuXg4OaxPJfQsvixUfHgAA2KA8neuUt7" Subject: Re: [Qemu-devel] [PATCH for-2.8] monitor: fix object_del for command-line-created objects List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Michael Roth , qemu-devel@nongnu.org Cc: "Dr. David Alan Gilbert" , Markus Armbruster , Daniel Berrange This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --1AuXg4OaxPJfQsvixUfHgAA2KA8neuUt7 From: Eric Blake To: Michael Roth , qemu-devel@nongnu.org Cc: "Dr. David Alan Gilbert" , Markus Armbruster , Daniel Berrange Message-ID: <57ed5b82-2a1a-4318-d4ce-0c2eaa74d8e6@redhat.com> Subject: Re: [PATCH for-2.8] monitor: fix object_del for command-line-created objects References: <1480547176-19349-1-git-send-email-mdroth@linux.vnet.ibm.com> In-Reply-To: <1480547176-19349-1-git-send-email-mdroth@linux.vnet.ibm.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 11/30/2016 05:06 PM, Michael Roth wrote: > Currently objects specified on the command-line are only partially > cleaned up when 'object_del' is issued in either HMP or QMP: the > object itself is fully finalized, but the QemuOpts are not removed. > This results in the following behavior: >=20 > x86_64-softmmu/qemu-system-x86_64 -monitor stdio \ > -object memory-backend-ram,id=3Dram1,size=3D256M >=20 > QEMU 2.7.91 monitor - type 'help' for more information > (qemu) object_del ram1 > (qemu) object_del ram1 > object 'ram1' not found > (qemu) object_add memory-backend-ram,id=3Dram1,size=3D256M > Duplicate ID 'ram1' for object > Try "help object_add" for more information >=20 > which can be an issue for use-cases like memory hotplug. Nice analysis. >=20 > This happens on the HMP side because hmp_object_add() attempts to > create a temporary QemuOpts entry with ID 'ram1', which ends up > conflicting with the command-line-created entry, since it was never > cleaned up during the previous hmp_object_del() call. >=20 > We address this by adding checks in {qmp,hmp}_object_del to determine > whether an option group entry matching the object's ID is present, > and removing it if it is. >=20 > Note that qmp_object_add() never attempts to create a temporary > QemuOpts entry, so it does not encounter the duplicate ID error, > which is why this isn't generally visible in libvirt. Phew. Yeah, libvirt avoiding HMP where possible saves a lot of hassles. > +++ b/hmp.c > @@ -2072,6 +2072,16 @@ void hmp_object_del(Monitor *mon, const QDict *q= dict) > =20 > user_creatable_del(id, &err); > hmp_handle_error(mon, &err); > + > + /* if object was defined on the command-line, remove its correspon= ding > + * option group entry > + */ > + if (err =3D=3D NULL) { > + QemuOptsList *opt_group =3D qemu_find_opts_err("object", &err)= ; > + if (opt_group) { > + qemu_opts_del(qemu_opts_find(opt_group, id)); > + } > + } This one looks okay. > } > =20 > void hmp_info_memdev(Monitor *mon, const QDict *qdict) > diff --git a/qmp.c b/qmp.c > index 0028f0b..87c545d 100644 > --- a/qmp.c > +++ b/qmp.c > @@ -686,6 +686,16 @@ void qmp_object_add(const char *type, const char *= id, > void qmp_object_del(const char *id, Error **errp) > { > user_creatable_del(id, errp); > + > + /* if object was defined on the command-line, remove its correspon= ding > + * option group entry > + */ > + if (!(errp && *errp)) { But this is wrong. Please spin a v2 that uses a local Error object, then use error_propagate(err, errp). Making anything conditional on whether an error occurred requires a local object, since the caller can pass in NULL, but you want your cleanup to happen even when the caller doesn't care about errors. > + QemuOptsList *opt_group =3D qemu_find_opts_err("object", errp)= ; > + if (opt_group) { > + qemu_opts_del(qemu_opts_find(opt_group, id)); > + } > + } > } > =20 > MemoryDeviceInfoList *qmp_query_memory_devices(Error **errp) >=20 --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --1AuXg4OaxPJfQsvixUfHgAA2KA8neuUt7 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJYP4wUAAoJEKeha0olJ0Nqr8AH/2tGyEPZ8m/B3YByGiV7er0F DK2cxF6KRgtsB5oLYUA5P5owB1d2DMiPb765QPACEGCNqxR6nQ9N/kdoa/lsebZe jJcoAfD5fMweaJOxvC5UcKlKl6P7GDnzSHnZOgW04Sf9M9OsWMYgXnVuoncyHKy9 ruw87S62nZxRSriFEhxInL8sRpqm1Lvregk2WX4qV4yvLvd+/OdKDljCQkN/EpH+ aG9v9SFQTJBoa/ClyrsPBEhFOpfsrvy2ppzpzaCKO5ou0idhWzhyLl4wDY4r2gfU KUpjOr99tnKbpKxZB9jm8C/+mzMm9OWpoCCxFxf+84bZHBvROTu8zt3AjIAQxC0= =wRR+ -----END PGP SIGNATURE----- --1AuXg4OaxPJfQsvixUfHgAA2KA8neuUt7--