From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51275) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cCTzM-0004f6-Sp for qemu-devel@nongnu.org; Thu, 01 Dec 2016 11:13:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cCTzI-0001iG-SV for qemu-devel@nongnu.org; Thu, 01 Dec 2016 11:13:36 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:55831) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cCTzI-0001hZ-KY for qemu-devel@nongnu.org; Thu, 01 Dec 2016 11:13:32 -0500 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id uB1G9ri5047692 for ; Thu, 1 Dec 2016 11:13:30 -0500 Received: from e37.co.us.ibm.com (e37.co.us.ibm.com [32.97.110.158]) by mx0a-001b2d01.pphosted.com with ESMTP id 272mra1vc9-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 01 Dec 2016 11:13:30 -0500 Received: from localhost by e37.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 1 Dec 2016 09:13:29 -0700 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Michael Roth In-Reply-To: <57ed5b82-2a1a-4318-d4ce-0c2eaa74d8e6@redhat.com> References: <1480547176-19349-1-git-send-email-mdroth@linux.vnet.ibm.com> <57ed5b82-2a1a-4318-d4ce-0c2eaa74d8e6@redhat.com> Date: Thu, 01 Dec 2016 10:09:21 -0600 Message-Id: <20161201160921.1725.55364@loki> 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: Eric Blake , qemu-devel@nongnu.org Cc: "Dr. David Alan Gilbert" , Markus Armbruster , Daniel Berrange Quoting Eric Blake (2016-11-30 20:33:56) > 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: > > = > > x86_64-softmmu/qemu-system-x86_64 -monitor stdio \ > > -object memory-backend-ram,id=3Dram1,size=3D256M > > = > > 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 > > = > > which can be an issue for use-cases like memory hotplug. > = > Nice analysis. > = > > = > > 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. > > = > > 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. > > = > > 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) > > = > > 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. > = > > } > > = > > 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. Ugh, I should know better by now. Thanks for the catch, will make sure this is done properly in v2. > = > > + QemuOptsList *opt_group =3D qemu_find_opts_err("object", errp); > > + if (opt_group) { > > + qemu_opts_del(qemu_opts_find(opt_group, id)); > > + } > > + } > > } > > = > > MemoryDeviceInfoList *qmp_query_memory_devices(Error **errp) > > = > = > -- = > Eric Blake eblake redhat com +1-919-301-3266 > Libvirt virtualization library http://libvirt.org >=20