From patchwork Thu Mar 7 07:22:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elena Ufimtseva X-Patchwork-Id: 10842319 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AD3D414E1 for ; Thu, 7 Mar 2019 07:43:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 99B832E8F0 for ; Thu, 7 Mar 2019 07:43:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8C1FD2E925; Thu, 7 Mar 2019 07:43:22 +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=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 095A32E8F0 for ; Thu, 7 Mar 2019 07:43:22 +0000 (UTC) Received: from localhost ([127.0.0.1]:46854 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1ngX-00037M-7S for patchwork-qemu-devel@patchwork.kernel.org; Thu, 07 Mar 2019 02:43:21 -0500 Received: from eggs.gnu.org ([209.51.188.92]:60173) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nMc-0002nM-Rm for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1nMa-0005ke-Hm for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:45 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:48758) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h1nMY-0005hc-I8 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:43 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x277JFbk037804; Thu, 7 Mar 2019 07:22:35 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=fd/GUhEGvfP5hsOnpn7HBT74UTo6vyuTOlwbtjMbBxc=; b=1SJWQ9+4g/k2s21X0/l9YeASPo0zcQlk7mrju0mZPAjmjHo5lozoW77LP3AcE88pVbII QfXr5cYAo2ATso9vF4zolwh2slrNEPVfts6WBGKwUkzlN6cGqZFNbh7cx5H92CfrEWRG JJcG45s9Uh5pl05Xyr+7pfAjrddHPPOhz82AZyoQm/TdqRBwZg2eVFkyqPvbceNfMn0y 9HcbLt7ZaRFHPuHpxmMOoX88ijGSlFuLWe3OlfPnMOPPeFzTJ1z661fZ7QrEqJoWOBoL lRxlrviWKfushtnY4NFdNbSEpVzBbpWbUAMyb/5SDNpVE4U6nxKzglywJl3Nk3Lc6Htf Rw== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2130.oracle.com with ESMTP id 2qyh8ug992-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Mar 2019 07:22:35 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x277MYPw017273 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 7 Mar 2019 07:22:34 GMT Received: from abhmp0020.oracle.com (abhmp0020.oracle.com [141.146.116.26]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x277MYRf004397; Thu, 7 Mar 2019 07:22:34 GMT Received: from heatpipe.hsd1.ca.comcast.net (/73.170.27.202) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Mar 2019 23:22:33 -0800 From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Date: Wed, 6 Mar 2019 23:22:31 -0800 Message-Id: <20190307072231.9457-1-elena.ufimtseva@oracle.com> X-Mailer: git-send-email 2.17.1 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9187 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903070053 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.86 Subject: [Qemu-devel] [multiprocess RFC PATCH 27/37] multi-process: remote: add setup_devices and setup_drive msg processing 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: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, sstabellini@kernel.org, jag.raman@oracle.com, konrad.wilk@oracle.com, ross.lagerwall@citrix.com, liran.alon@oracle.com, stefanha@redhat.com, kanth.ghatraju@oracle.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Elena Ufimtseva Receive by remote side the configuration messages and build the device object from JSON device descriptions. Signed-off-by: Elena Ufimtseva Signed-off-by: Jagannathan Raman Signed-off-by: John G Johnson --- remote/remote-main.c | 126 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) diff --git a/remote/remote-main.c b/remote/remote-main.c index a9c12a9..52da3c8 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -54,6 +54,15 @@ #include "qemu/config-file.h" #include "monitor/qdev.h" #include "qapi/qmp/qdict.h" +#include "sysemu/sysemu.h" +#include "sysemu/blockdev.h" +#include "block/block.h" +#include "qapi/qmp/qstring.h" +#include "hw/qdev-properties.h" +#include "hw/scsi/scsi.h" +#include "block/qdict.h" +#include "qapi/qmp/qlist.h" +#include "qemu/log.h" static ProxyLinkState *proxy_link; PCIDevice *remote_pci_dev; @@ -223,6 +232,107 @@ fail: PUT_REMOTE_WAIT(wait); } +static int init_drive(QDict *rqdict, Error **errp) +{ + QemuOpts *opts; + Error *local_error = NULL; + + if (rqdict != NULL && qdict_size(rqdict) > 0) { + opts = qemu_opts_from_qdict(&qemu_drive_opts, + rqdict, &local_error); + if (!opts) { + error_propagate(errp, local_error); + return -EINVAL; + } + } else { + return -EINVAL; + } + if (drive_new(opts, IF_IDE, &local_error) == NULL) { + error_propagate(errp, local_error); + return -EINVAL; + } + + return 0; +} + +static int setup_drive(ProcMsg *msg, Error **errp) +{ + QObject *obj; + QDict *qdict; + QString *qstr; + Error *local_error = NULL; + int rc = -EINVAL; + + if (!msg->data2) { + return rc; + } + + qstr = qstring_from_str((char *)msg->data2); + obj = qobject_from_json(qstring_get_str(qstr), errp); + if (!obj) { + return rc; + } + + qdict = qobject_to(QDict, obj); + if (!qdict) { + return rc; + } + + qdict_del(qdict, "rid"); + if (init_drive(qdict, &local_error)) { + error_propagate(errp, local_error); + return rc; + } + + return 0; +} + +static int setup_device(ProcMsg *msg, Error **errp) +{ + QObject *obj; + QDict *qdict; + QString *qstr; + QemuOpts *opts; + DeviceState *dev = NULL; + int rc = -EINVAL; + + if (!msg->data2) { + return rc; + } + + qstr = qstring_from_str((char *)msg->data2); + + obj = qobject_from_json(qstring_get_str(qstr), errp); + if (!obj) { + error_setg(errp, "Could not convert to json object."); + return rc; + } + + qdict = qobject_to(QDict, obj); + if (!qdict) { + return rc; + } + + g_assert(qdict_size(qdict) > 1); + + qdict_del(qdict, "command"); + qdict_del(qdict, "rid"); + + opts = qemu_opts_from_qdict(&qemu_device_opts, qdict, errp); + + dev = qdev_device_add(opts, errp); + if (!dev) { + error_setg(errp, "Could not add device %s.", qstring_get_str(qstr)); + return rc; + } + if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) { + remote_pci_dev = PCI_DEVICE(dev); + } + qemu_opts_del(opts); + + return 0; +} + static void process_msg(GIOCondition cond) { ProcMsg *msg = NULL; @@ -268,11 +378,27 @@ static void process_msg(GIOCondition cond) */ remote_sysmem_reconfig(msg, &err); if (err) { + error_report_err(err); goto finalize_loop; } break; case SET_IRQFD: process_set_irqfd_msg(remote_pci_dev, msg); + qdev_machine_creation_done(); + qemu_mutex_lock_iothread(); + qemu_run_machine_init_done_notifiers(); + qemu_mutex_unlock_iothread(); + + break; + case DRIVE_OPTS: + if (setup_drive(msg, &err)) { + error_report_err(err); + } + break; + case DEV_OPTS: + if (setup_device(msg, &err)) { + error_report_err(err); + } break; case DEVICE_ADD: process_device_add_msg(msg);