From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51280) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cCTzN-0004f7-3t for qemu-devel@nongnu.org; Thu, 01 Dec 2016 11:13:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cCTzI-0001iN-Tv for qemu-devel@nongnu.org; Thu, 01 Dec 2016 11:13:37 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:32879 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cCTzI-0001i1-PX for qemu-devel@nongnu.org; Thu, 01 Dec 2016 11:13:32 -0500 Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id uB1GAu36044481 for ; Thu, 1 Dec 2016 11:13:32 -0500 Received: from e32.co.us.ibm.com (e32.co.us.ibm.com [32.97.110.150]) by mx0b-001b2d01.pphosted.com with ESMTP id 272mvhhha4-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 01 Dec 2016 11:13:32 -0500 Received: from localhost by e32.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 1 Dec 2016 09:13:31 -0700 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Michael Roth In-Reply-To: <20161201123409.GA6700@work-vm> References: <1480547176-19349-1-git-send-email-mdroth@linux.vnet.ibm.com> <20161201092407.GB9191@redhat.com> <20161201123409.GA6700@work-vm> Date: Thu, 01 Dec 2016 10:13:18 -0600 Message-Id: <20161201161318.1725.78309@loki> Subject: Re: [Qemu-devel] [PATCH] monitor: fix object_del for command-line-created objects List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Dr. David Alan Gilbert" , "Daniel P. Berrange" Cc: qemu-devel@nongnu.org, Markus Armbruster , Eric Blake Quoting Dr. David Alan Gilbert (2016-12-01 06:34:10) > * Daniel P. Berrange (berrange@redhat.com) wrote: > > On Wed, Nov 30, 2016 at 05:06:16PM -0600, 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. > > > = > > > 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. > > > = > > > Cc: "Dr. David Alan Gilbert" > > > Cc: Markus Armbruster > > > Cc: Eric Blake > > > Cc: Daniel Berrange > > > Signed-off-by: Michael Roth > > > --- > > > hmp.c | 10 ++++++++++ > > > qmp.c | 10 ++++++++++ > > > 2 files changed, 20 insertions(+) > > > = > > > diff --git a/hmp.c b/hmp.c > > > index b869617..99b8bf3 100644 > > > --- a/hmp.c > > > +++ b/hmp.c > > > @@ -2072,6 +2072,16 @@ void hmp_object_del(Monitor *mon, const QDict = *qdict) > > > = > > > user_creatable_del(id, &err); > > > hmp_handle_error(mon, &err); > > > + > > > + /* if object was defined on the command-line, remove its corresp= onding > > > + * option group entry > > > + */ > > > + if (err =3D=3D NULL) { > > > + QemuOptsList *opt_group =3D qemu_find_opts_err("object", &er= r); > > > + if (opt_group) { > > > + qemu_opts_del(qemu_opts_find(opt_group, id)); > > > + } > > > + } > > > } > > > = > > > 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 corresp= onding > > > + * option group entry > > > + */ > > > + if (!(errp && *errp)) { > > > + QemuOptsList *opt_group =3D qemu_find_opts_err("object", err= p); > > > + if (opt_group) { > > > + qemu_opts_del(qemu_opts_find(opt_group, id)); > > > + } > > > + } > > > } > > = > > I rather feel like this code ought to be in user_creatable_del(), since > > all code paths which call user_creatable_del() need to do deal with > > this scenario. > = > Yes that seems cleaner; the cleanup that's being done is not the result > of either of the monitor's actions. It was also for similar reasons that I was hesitant to put it in user_creatable_del() :) Putting it higher up in the stack somehow felt less icky, but given that they both violate encapsulation somewhat I suppose it does makes sense to take the more practical/safer route and put it in a common path. Will take this approach for v2. > = > Dave > = > > Also I'd like to see a unit test added that exposes this problem and > > demonstrates the fix - could att it to tests/check-qom-proplist.c > > = > > Regards, > > Daniel > > -- = > > |: http://berrange.com -o- http://www.flickr.com/photos/dberran= ge/ :| > > |: http://libvirt.org -o- http://virt-manager.= org :| > > |: http://entangle-photo.org -o- http://search.cpan.org/~danbe= rr/ :| > -- > Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK >=20