From patchwork Sat Jun 3 23:13:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 9764549 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3558A60363 for ; Sat, 3 Jun 2017 23:20:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 24B5B2843F for ; Sat, 3 Jun 2017 23:20:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 15B8928464; Sat, 3 Jun 2017 23:20:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9C0F12843F for ; Sat, 3 Jun 2017 23:20:40 +0000 (UTC) Received: from localhost ([::1]:55158 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dHILX-00068j-PL for patchwork-qemu-devel@patchwork.kernel.org; Sat, 03 Jun 2017 19:20:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53305) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dHIHv-0003gG-5e for qemu-devel@nongnu.org; Sat, 03 Jun 2017 19:16:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dHIHs-0002EV-14 for qemu-devel@nongnu.org; Sat, 03 Jun 2017 19:16:55 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:44699) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dHIHr-0002E6-OJ for qemu-devel@nongnu.org; Sat, 03 Jun 2017 19:16:51 -0400 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v53NDkH5131438 for ; Sat, 3 Jun 2017 19:16:50 -0400 Received: from e33.co.us.ibm.com (e33.co.us.ibm.com [32.97.110.151]) by mx0a-001b2d01.pphosted.com with ESMTP id 2auv447cy5-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Sat, 03 Jun 2017 19:16:50 -0400 Received: from localhost by e33.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Sat, 3 Jun 2017 17:16:49 -0600 Received: from b03cxnp07028.gho.boulder.ibm.com (9.17.130.15) by e33.co.us.ibm.com (192.168.1.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Sat, 3 Jun 2017 17:16:46 -0600 Received: from b03ledav002.gho.boulder.ibm.com (b03ledav002.gho.boulder.ibm.com [9.17.130.233]) by b03cxnp07028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v53NGkx921299234; Sat, 3 Jun 2017 16:16:46 -0700 Received: from b03ledav002.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3F5C913603C; Sat, 3 Jun 2017 17:16:46 -0600 (MDT) Received: from localhost (unknown [9.80.107.94]) by b03ledav002.gho.boulder.ibm.com (Postfix) with ESMTP id 0B9C713603A; Sat, 3 Jun 2017 17:16:45 -0600 (MDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Sat, 3 Jun 2017 18:13:32 -0500 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1496531612-22166-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1496531612-22166-1-git-send-email-mdroth@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17060323-0008-0000-0000-000007F1197A X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007167; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000212; SDB=6.00869725; UDB=6.00432389; IPR=6.00649701; BA=6.00005396; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00015696; XFM=3.00000015; UTC=2017-06-03 23:16:48 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17060323-0009-0000-0000-00004273E6FF Message-Id: <1496531612-22166-3-git-send-email-mdroth@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-06-03_09:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1706030446 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PATCH v5 2/2] monitor: fix object_del for command-line-created objects X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-stable@nongnu.org, armbru@redhat.com, "Dr. David Alan Gilbert" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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=ram1,size=256M 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=ram1,size=256M 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 a check in user_creatable_del(), which is called by both qmp_object_del() and hmp_object_del() to handle the actual object cleanup, 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 Cc: qemu-stable@nongnu.org Signed-off-by: Michael Roth Reviewed-by: Daniel P. Berrange Reviewed-by: Markus Armbruster --- qom/object_interfaces.c | 9 +++++++++ tests/check-qom-proplist.c | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c index d4253a8..ff27e06 100644 --- a/qom/object_interfaces.c +++ b/qom/object_interfaces.c @@ -4,6 +4,7 @@ #include "qemu/module.h" #include "qapi-visit.h" #include "qapi/opts-visitor.h" +#include "qemu/config-file.h" void user_creatable_complete(Object *obj, Error **errp) { @@ -181,6 +182,14 @@ void user_creatable_del(const char *id, Error **errp) error_setg(errp, "object '%s' is in use, can not be deleted", id); return; } + + /* + * if object was defined on the command-line, remove its corresponding + * option group entry + */ + qemu_opts_del(qemu_opts_find(qemu_find_opts_err("object", &error_abort), + id)); + object_unparent(obj); } diff --git a/tests/check-qom-proplist.c b/tests/check-qom-proplist.c index e3f56ca..ddec574 100644 --- a/tests/check-qom-proplist.c +++ b/tests/check-qom-proplist.c @@ -437,9 +437,9 @@ static void test_dummy_createcmdl(void) * check for this in user_creatable_del() and remove the QemuOpts if * it is present. * - * FIXME: add an assert to verify that the QemuOpts is cleaned up - * once the corresponding cleanup code is added. + * The below check ensures this works as expected. */ + g_assert_null(qemu_opts_find(&qemu_object_opts, "dev0")); } static void test_dummy_badenum(void)