From nobody Mon Feb 9 15:46:41 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1571910141; cv=none; d=zoho.com; s=zohoarc; b=b6k+Lc2w9QfpBvQOqq1ZLz2vuQS7C6qrx2L+A8bYMApCSsrj9t6RLS8ErXpobiPKaza0/khN2ig0Yqqmm+FwKqhsiA3pnDvva3lZLX8xezhlLIo7DeBCjtJ/HEHVaK5iWq695pqvBOCLEGgGYFKbA5pNSEoAQ99ihVRXgh3iRwQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571910141; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=iFiVcwKNR9jUbmKD8dfsLaSdKBy0NIJkJ5X8IrIg8Y4=; b=TbT4Lw9b/EvlArLQsw6EFnArkrOo521HCxLW0JLIWyKB2kB1FlboF9LvYXbmy2dSpVl9N2lYMiM7vwMNjudCtG7gCuvmcDMnooVlGVL7qFhJsT3VZpSlXIy7EGhibS6L/PuYGTdLwtVniodIMe6w1tsf0qd4dlp88lSsUfnW8Dw= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1571910141507928.426576220287; Thu, 24 Oct 2019 02:42:21 -0700 (PDT) Received: from localhost ([::1]:36588 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZMK-00033H-4M for importer@patchew.org; Thu, 24 Oct 2019 05:24:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43794) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZ8q-0006hX-U9 for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNZ8p-0004Iq-7X for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:48 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:60730) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNZ8o-0004II-VM for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:47 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O94NgN094929; Thu, 24 Oct 2019 09:10:42 GMT Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2120.oracle.com with ESMTP id 2vqu4r24ny-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:10:42 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O98mUY076167; Thu, 24 Oct 2019 09:10:41 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3030.oracle.com with ESMTP id 2vtjkj2xdt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:10:41 +0000 Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x9O9Aeo4002203; Thu, 24 Oct 2019 09:10:40 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Oct 2019 02:10:40 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2019-08-05; bh=iFiVcwKNR9jUbmKD8dfsLaSdKBy0NIJkJ5X8IrIg8Y4=; b=qscR0CGO61yiRoBMBf9aD83cxNFlOLB/mg7ifGzPj8oBWhmXPXoBtGpssONBGRIJ8MpE wTbNSnFlSfjxfiaWWfY2Rj2Sbi/B/7ZfepXYhU6lP0x76qAIUZ6e6VO7qW/dSAvcDTHy oxUj0cXbomo26CwOiopXdsVO/JWdKj9tWBUoT2SmZv7fjNsFbLMpmXDzCHxTcqYQMSIE /PlhG4zNTMNfAHIpEgdAVi5jFfg2PsJW41G1q+mZUeG3Du0CizCAIDBvCV18sEypCg2R ULFBgg5ibtEXWk8CLTwzNAi6RNCeumcvP0aUEeip7U2117u6Ehuf0aseFlZkekFPDwtj zQ== From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [RFC v4 PATCH 21/49] multi-process: remote: add setup_devices and setup_drive msg processing Date: Thu, 24 Oct 2019 05:09:02 -0400 Message-Id: <3b01965059d7a258317081c2e9ebbd8d2feca872.1571905346.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910240089 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 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-1908290000 definitions=main-1910240089 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 156.151.31.85 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: elena.ufimtseva@oracle.com, fam@euphon.net, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @oracle.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 --- v1 -> v2: - for new command line suboptions with libvirtd support, clean the options before creating drives/devices - use default pci bus/address for now include/hw/qdev-core.h | 2 + qdev-monitor.c | 2 +- remote/remote-main.c | 231 +++++++++++++++++++++++++++++++++++++++++++++= ++++ 3 files changed, 234 insertions(+), 1 deletion(-) diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index aa123f8..19b117d 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -357,6 +357,8 @@ BusState *qdev_get_parent_bus(DeviceState *dev); =20 DeviceState *qdev_find_recursive(BusState *bus, const char *id); =20 +DeviceState *find_device_state(const char *id, Error **errp); + /* Returns 0 to walk children, > 0 to skip walk, < 0 to terminate walk. */ typedef int (qbus_walkerfn)(BusState *bus, void *opaque); typedef int (qdev_walkerfn)(DeviceState *dev, void *opaque); diff --git a/qdev-monitor.c b/qdev-monitor.c index eeff43e..e1d05e4 100644 --- a/qdev-monitor.c +++ b/qdev-monitor.c @@ -1025,7 +1025,7 @@ void qmp_device_add(QDict *qdict, QObject **ret_data,= Error **errp) object_unref(OBJECT(dev)); } =20 -static DeviceState *find_device_state(const char *id, Error **errp) +DeviceState *find_device_state(const char *id, Error **errp) { Object *obj; =20 diff --git a/remote/remote-main.c b/remote/remote-main.c index cede97c..5b3ffd8 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -49,6 +49,21 @@ #include "exec/memattrs.h" #include "exec/address-spaces.h" #include "remote/iohub.h" +#include "qapi/qmp/qjson.h" +#include "qapi/qmp/qobject.h" +#include "qemu/option.h" +#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" =20 static MPQemuLinkState *mpqemu_link; PCIDevice *remote_pci_dev; @@ -139,6 +154,200 @@ fail: PUT_REMOTE_WAIT(wait); } =20 +static void process_device_add_msg(MPQemuMsg *msg) +{ + Error *local_err =3D NULL; + const char *json =3D (const char *)msg->data2; + int wait =3D msg->fds[0]; + QObject *qobj =3D NULL; + QDict *qdict =3D NULL; + QemuOpts *opts =3D NULL; + + qobj =3D qobject_from_json(json, &local_err); + if (local_err) { + goto fail; + } + + qdict =3D qobject_to(QDict, qobj); + assert(qdict); + + opts =3D qemu_opts_from_qdict(qemu_find_opts("device"), qdict, &local_= err); + if (local_err) { + goto fail; + } + + (void)qdev_device_add(opts, &local_err); + if (local_err) { + goto fail; + } + +fail: + if (local_err) { + error_report_err(local_err); + /* TODO: communicate the exact error message to proxy */ + } + + notify_proxy(wait, 1); + + PUT_REMOTE_WAIT(wait); +} + +static void process_device_del_msg(MPQemuMsg *msg) +{ + Error *local_err =3D NULL; + DeviceState *dev =3D NULL; + const char *json =3D (const char *)msg->data2; + int wait =3D msg->fds[0]; + QObject *qobj =3D NULL; + QDict *qdict =3D NULL; + const char *id; + + qobj =3D qobject_from_json(json, &local_err); + if (local_err) { + goto fail; + } + + qdict =3D qobject_to(QDict, qobj); + assert(qdict); + + id =3D qdict_get_try_str(qdict, "id"); + assert(id); + + dev =3D find_device_state(id, &local_err); + if (local_err) { + goto fail; + } + + if (dev) { + qdev_unplug(dev, &local_err); + } + +fail: + if (local_err) { + error_report_err(local_err); + /* TODO: communicate the exact error message to proxy */ + } + + notify_proxy(wait, 1); + + PUT_REMOTE_WAIT(wait); +} + +static int init_drive(QDict *rqdict, Error **errp) +{ + QemuOpts *opts; + Error *local_error =3D NULL; + + if (rqdict !=3D NULL && qdict_size(rqdict) > 0) { + opts =3D qemu_opts_from_qdict(&qemu_drive_opts, + rqdict, &local_error); + if (!opts) { + error_propagate(errp, local_error); + return -EINVAL; + } + } else { + return -EINVAL; + } + + qemu_opt_unset(opts, "rid"); + qemu_opt_unset(opts, "socket"); + qemu_opt_unset(opts, "remote"); + qemu_opt_unset(opts, "command"); + + if (drive_new(opts, IF_IDE, &local_error) =3D=3D NULL) { + error_propagate(errp, local_error); + return -EINVAL; + } + + return 0; +} + +static int setup_drive(MPQemuMsg *msg, Error **errp) +{ + QObject *obj; + QDict *qdict; + QString *qstr; + Error *local_error =3D NULL; + int rc =3D -EINVAL; + + if (!msg->data2) { + return rc; + } + + qstr =3D qstring_from_str((char *)msg->data2); + obj =3D qobject_from_json(qstring_get_str(qstr), &local_error); + if (!obj) { + error_propagate(errp, local_error); + return rc; + } + + qdict =3D qobject_to(QDict, obj); + if (!qdict) { + return rc; + } + + if (init_drive(qdict, &local_error)) { + error_setg(errp, "init_drive failed in setup_drive."); + return rc; + } + + return 0; +} + +static int setup_device(MPQemuMsg *msg, Error **errp) +{ + QObject *obj; + QDict *qdict; + QString *qstr; + QemuOpts *opts; + DeviceState *dev =3D NULL; + int rc =3D -EINVAL; + Error *local_error =3D NULL; + + if (!msg->data2) { + return rc; + } + + qstr =3D qstring_from_str((char *)msg->data2); + obj =3D qobject_from_json(qstring_get_str(qstr), &local_error); + if (!obj) { + error_setg(errp, "Could not get object!"); + return rc; + } + + qdict =3D qobject_to(QDict, obj); + if (!qdict) { + return rc; + } + + g_assert(qdict_size(qdict) > 1); + + opts =3D qemu_opts_from_qdict(&qemu_device_opts, qdict, &local_error); + qemu_opt_unset(opts, "rid"); + qemu_opt_unset(opts, "socket"); + qemu_opt_unset(opts, "remote"); + qemu_opt_unset(opts, "command"); + /* + * TODO: use the bus and addr from the device options. For now + * we use default value. + */ + qemu_opt_unset(opts, "bus"); + qemu_opt_unset(opts, "addr"); + + dev =3D qdev_device_add(opts, &local_error); + if (!dev) { + error_setg(errp, "Could not add device %s.", + qstring_get_str(qobject_to_json(QOBJECT(qdict)))); + return rc; + } + if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) { + remote_pci_dev =3D PCI_DEVICE(dev); + } + qemu_opts_del(opts); + + return 0; +} + static void process_msg(GIOCondition cond, MPQemuChannel *chan) { MPQemuMsg *msg =3D NULL; @@ -184,11 +393,33 @@ static void process_msg(GIOCondition cond, MPQemuChan= nel *chan) */ 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); + break; + case DEVICE_DEL: + process_device_del_msg(msg); break; default: error_setg(&err, "Unknown command"); --=20 1.8.3.1