From nobody Fri Nov 29 19:39:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1632328107702412.4028249409041; Wed, 22 Sep 2021 09:28:27 -0700 (PDT) Received: from localhost ([::1]:49904 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mT56g-0006ZQ-Jn for importer@patchew.org; Wed, 22 Sep 2021 12:28:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44622) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mT4ua-0002hi-TS; Wed, 22 Sep 2021 12:15:56 -0400 Received: from beetle.greensocs.com ([5.135.226.135]:39020) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mT4uY-0005Ld-C6; Wed, 22 Sep 2021 12:15:56 -0400 Received: from crumble.bar.greensocs.com (unknown [172.17.10.6]) by beetle.greensocs.com (Postfix) with ESMTPS id 4B88C21EC3; Wed, 22 Sep 2021 16:15:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1632327352; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pOou7ntZwf6jxxWFcKHppVKqRu0dT3fZc00S/uH+MyA=; b=5bk6PS2OqJmvZzhaI9CocH6KgDJLjQ0sST8dAep+XnkbKqazJzdfin3fRbNcoCFIIJ4LDG GoegIeSg8nXubLp4NmRiWtEy9I5diF4x3MSZmpTdsP6bl5Lp7T8uGdnf7mcsqHi+kAZIk3 qGWjcdZLReG9SyIDa9sXiR3hURGJtcE= From: Damien Hedde To: qemu-devel@nongnu.org Subject: [RFC PATCH v2 06/16] qapi: Allow device_add to execute in machine initialized phase Date: Wed, 22 Sep 2021 18:13:55 +0200 Message-Id: <20210922161405.140018-7-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210922161405.140018-1-damien.hedde@greensocs.com> References: <20210922161405.140018-1-damien.hedde@greensocs.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam: Yes Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=5.135.226.135; envelope-from=damien.hedde@greensocs.com; helo=beetle.greensocs.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , "Michael S. Tsirkin" , David Hildenbrand , Peter Xu , mirela.grujic@greensocs.com, Alistair Francis , Gerd Hoffmann , Ani Sinha , Eric Blake , Stefano Stabellini , xen-devel@lists.xenproject.org, Paul Durrant , Markus Armbruster , Anthony Perard , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Eduardo Habkost , "Dr. David Alan Gilbert" , Eric Auger , Paolo Bonzini , qemu-riscv@nongnu.org, Damien Hedde , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , mark.burton@greensocs.com, edgari@xilinx.com, Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1632328108778100001 Content-Type: text/plain; charset="utf-8" From: Mirela Grujic To configure a machine using QMP we need the device_add command to execute at machine initialized phase. Note: for device_add command in qdev.json adding the 'allow-init-config' option has no effect because the command appears to bypass QAPI (see TODO at qapi/qdev.json:61). The option is added there solely to document the intent. For the same reason, the flags have to be explicitly set in monitor_init_qmp_commands() when the device_add command is registered. Signed-off-by: Mirela Grujic Acked-by: Alistair Francis --- The commit is fine, but we may add intermediate commits before this one in order to add or change the condition for a device type to be accepted in the 'initialized' state (see the cover-letter of the series). --- qapi/qdev.json | 3 ++- monitor/misc.c | 2 +- softmmu/qdev-monitor.c | 6 ++++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/qapi/qdev.json b/qapi/qdev.json index b83178220b..ad669ae175 100644 --- a/qapi/qdev.json +++ b/qapi/qdev.json @@ -67,7 +67,8 @@ ## { 'command': 'device_add', 'data': {'driver': 'str', '*bus': 'str', '*id': 'str'}, - 'gen': false } # so we can get the additional arguments + 'gen': false, # so we can get the additional arguments + 'allow-preconfig': true } =20 ## # @device_del: diff --git a/monitor/misc.c b/monitor/misc.c index ffe7966870..2c476de316 100644 --- a/monitor/misc.c +++ b/monitor/misc.c @@ -231,7 +231,7 @@ static void monitor_init_qmp_commands(void) qmp_init_marshal(&qmp_commands); =20 qmp_register_command(&qmp_commands, "device_add", qmp_device_add, - QCO_NO_OPTIONS); + QCO_ALLOW_PRECONFIG); =20 QTAILQ_INIT(&qmp_cap_negotiation_commands); qmp_register_command(&qmp_cap_negotiation_commands, "qmp_capabilities", diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c index 834f2b56b5..47ccd90be8 100644 --- a/softmmu/qdev-monitor.c +++ b/softmmu/qdev-monitor.c @@ -824,6 +824,12 @@ void qmp_device_add(QDict *qdict, QObject **ret_data, = Error **errp) QemuOpts *opts; DeviceState *dev; =20 + if (!phase_check(MACHINE_INIT_PHASE_INITIALIZED)) { + error_setg(errp, "The command is permitted only after " + "the machine is initialized"); + return; + } + opts =3D qemu_opts_from_qdict(qemu_find_opts("device"), qdict, errp); if (!opts) { return; --=20 2.33.0