From nobody Mon Feb 9 00:39:04 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=1571916029; cv=none; d=zoho.com; s=zohoarc; b=mBBrNzNPYp1LqDnw1wczAO0KIiDcVgPusJlXPP+sExuksuS0MQHGFgNzXafJfVkQCho31ly3e7+ZJnqCAXSJsXNMg0Fq8HB3F15tXXhBqa39VcR0SBAVhTssf8LK7Bhx2BA/tBBIZaONy+goNb0JqxJ/SrhoqUUp1WTV+Y/BgRA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571916029; 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=F/E41FhsIR2e21OD7DpZqakoxt8Wz7+Qliiw0Bdlxt4=; b=LjadGAtdBF/CD28FHLtWk2RfP8VsF5Mq8S9PuOp2x2F6qevgFCbaamUgu+4ZsmmauSuaM12IG+rrT2XCzK/uxcf8GGVt0fGtmmq4jCnl6B8Rt+p+RMLkjGe/rWitlcUHdsFZIgF7l9rVp6THEw9vz/vHlQvSa6WqjvwbBGnXhog= 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 157191602952224.18098441873235; Thu, 24 Oct 2019 04:20:29 -0700 (PDT) Received: from localhost ([::1]:36842 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZbm-0002N0-UT for importer@patchew.org; Thu, 24 Oct 2019 05:40:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44312) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZAG-0001Si-5d for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:12:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNZAE-0005BE-2q for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:12:16 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:33846) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNZAD-0005Ag-QD for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:12:14 -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 x9O94Md7094848; Thu, 24 Oct 2019 09:12:07 GMT Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2120.oracle.com with ESMTP id 2vqu4r24ue-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:12:07 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O97j18170537; Thu, 24 Oct 2019 09:10:06 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3020.oracle.com with ESMTP id 2vtsk4857y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:10:06 +0000 Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x9O9A4Jk008991; Thu, 24 Oct 2019 09:10:04 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:04 -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=F/E41FhsIR2e21OD7DpZqakoxt8Wz7+Qliiw0Bdlxt4=; b=AS3kPjkgooLHwUyNncGazR/qm0hKD+BlEiL/1IN5RKzdPOeusv4yXrnp+UvdoRgoFHUx G3ZBGPDO+2U8jA+AznlEByFQFSTrn2zWF0TgTb2UhM3ullmfg018hg47zE9d5jIGzsMP 4v1DP/rK4axJzJ4BYicZduWNIOPvKUlIAewThWgiVbfIJgVRtAYOKkiyXAfiPmRzddiR VbGxwgD2YAqjB+Xe8L8BAbREfKrya9CsY+YdcMjE5WYWn1WLB3UX2+llp9cLCpvYwi66 EH5WNURHtqEVlRGHgfOXWKzGdiexFMTBeEumR1Q5gF5ff8oU1z5x+x4oSW/rLfr6+b27 YA== From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [RFC v4 PATCH 07/49] multi-process: define mpqemu-link object Date: Thu, 24 Oct 2019 05:08:48 -0400 Message-Id: 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" Defines mpqemu-link object which forms the communication link between QEMU & emulation program. Adds functions to configure members of mpqemu-link object instance. Adds functions to send and receive messages over the communication channel. Adds GMainLoop to handle events received on the communication channel. Signed-off-by: Jagannathan Raman Signed-off-by: John G Johnson Signed-off-by: Elena Ufimtseva --- v1 -> v2: - Use default context for main loop instead of a new context v2 -> v3: - Enabled multi-channel support in the communication link v3 -> v4: - Change the name of proxy-link to mpqemu-link - Use separate locks for sending and receiving messages include/io/mpqemu-link.h | 150 +++++++++++++++++++++++ io/Makefile.objs | 2 + io/mpqemu-link.c | 309 +++++++++++++++++++++++++++++++++++++++++++= ++++ 3 files changed, 461 insertions(+) create mode 100644 include/io/mpqemu-link.h create mode 100644 io/mpqemu-link.c diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h new file mode 100644 index 0000000..345c67e --- /dev/null +++ b/include/io/mpqemu-link.h @@ -0,0 +1,150 @@ +/* + * Communication channel between QEMU and remote device process + * + * Copyright 2019, Oracle and/or its affiliates. + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#ifndef MPQEMU_LINK_H +#define MPQEMU_LINK_H + +#include "qemu/osdep.h" +#include "qemu-common.h" + +#include +#include +#include + +#include "qom/object.h" +#include "qemu/thread.h" + +#define TYPE_MPQEMU_LINK "mpqemu-link" +#define MPQEMU_LINK(obj) \ + OBJECT_CHECK(MPQemuLinkState, (obj), TYPE_MPQEMU_LINK) + +#define REMOTE_MAX_FDS 8 + +#define MPQEMU_MSG_HDR_SIZE offsetof(MPQemuMsg, data1.u64) + +/** + * mpqemu_cmd_t: + * CONF_READ PCI config. space read + * CONF_WRITE PCI config. space write + * + * proc_cmd_t enum type to specify the command to be executed on the remote + * device. + */ +typedef enum { + INIT =3D 0, + CONF_READ, + CONF_WRITE, + MAX, +} mpqemu_cmd_t; + +/** + * MPQemuMsg: + * @cmd: The remote command + * @bytestream: Indicates if the data to be shared is structured (data1) + * or unstructured (data2) + * @size: Size of the data to be shared + * @data1: Structured data + * @fds: File descriptors to be shared with remote device + * @data2: Unstructured data + * + * MPQemuMsg Format of the message sent to the remote device from QEMU. + * + */ +typedef struct { + mpqemu_cmd_t cmd; + int bytestream; + size_t size; + + union { + uint64_t u64; + } data1; + + int fds[REMOTE_MAX_FDS]; + int num_fds; + + uint8_t *data2; +} MPQemuMsg; + +struct conf_data_msg { + uint32_t addr; + uint32_t val; + int l; +}; + +/** + * MPQemuChannel: + * @gsrc: GSource object to be used by loop + * @gpfd: GPollFD object containing the socket & events to monitor + * @sock: Socket to send/receive communication, same as the one in gpfd + * @send_lock: Mutex to synchronize access to the send stream + * @recv_lock: Mutex to synchronize access to the recv stream + * + * Defines the channel that make up the communication link + * between QEMU and remote process + */ + +typedef struct MPQemuChannel { + GSource gsrc; + GPollFD gpfd; + int sock; + QemuMutex send_lock; + QemuMutex recv_lock; +} MPQemuChannel; + +typedef void (*mpqemu_link_callback)(GIOCondition cond, MPQemuChannel *cha= n); + +/* + * MPQemuLinkState Instance info. of the communication + * link between QEMU and remote process. The Link could + * be made up of multiple channels. + * + * ctx GMainContext to be used for communication + * loop Main loop that would be used to poll for incoming data + * com Communication channel to transport control messages + * + */ + +typedef struct MPQemuLinkState { + Object obj; + + GMainContext *ctx; + GMainLoop *loop; + + MPQemuChannel *com; + + mpqemu_link_callback callback; +} MPQemuLinkState; + +MPQemuLinkState *mpqemu_link_create(void); +void mpqemu_link_finalize(MPQemuLinkState *s); + +void mpqemu_msg_send(MPQemuLinkState *s, MPQemuMsg *msg, MPQemuChannel *ch= an); +int mpqemu_msg_recv(MPQemuLinkState *s, MPQemuMsg *msg, MPQemuChannel *cha= n); + +void mpqemu_init_channel(MPQemuLinkState *s, MPQemuChannel **chan, int fd); +void mpqemu_destroy_channel(MPQemuChannel *chan); +void mpqemu_link_set_callback(MPQemuLinkState *s, mpqemu_link_callback cal= lback); +void mpqemu_start_coms(MPQemuLinkState *s); + +#endif diff --git a/io/Makefile.objs b/io/Makefile.objs index 9a20fce..5875ab0 100644 --- a/io/Makefile.objs +++ b/io/Makefile.objs @@ -10,3 +10,5 @@ io-obj-y +=3D channel-util.o io-obj-y +=3D dns-resolver.o io-obj-y +=3D net-listener.o io-obj-y +=3D task.o + +io-obj-$(CONFIG_MPQEMU) +=3D mpqemu-link.o diff --git a/io/mpqemu-link.c b/io/mpqemu-link.c new file mode 100644 index 0000000..b39f4d0 --- /dev/null +++ b/io/mpqemu-link.c @@ -0,0 +1,309 @@ +/* + * Communication channel between QEMU and remote device process + * + * Copyright 2019, Oracle and/or its affiliates. + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" +#include "qemu-common.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "qemu/module.h" +#include "io/mpqemu-link.h" +#include "qemu/log.h" + +GSourceFuncs gsrc_funcs; + +static void mpqemu_link_inst_init(Object *obj) +{ + MPQemuLinkState *s =3D MPQEMU_LINK(obj); + + s->ctx =3D g_main_context_default(); + s->loop =3D g_main_loop_new(s->ctx, FALSE); +} + +static const TypeInfo mpqemu_link_info =3D { + .name =3D TYPE_MPQEMU_LINK, + .parent =3D TYPE_OBJECT, + .instance_size =3D sizeof(MPQemuLinkState), + .instance_init =3D mpqemu_link_inst_init, +}; + +static void mpqemu_link_register_types(void) +{ + type_register_static(&mpqemu_link_info); +} + +type_init(mpqemu_link_register_types) + +MPQemuLinkState *mpqemu_link_create(void) +{ + return MPQEMU_LINK(object_new(TYPE_MPQEMU_LINK)); +} + +void mpqemu_link_finalize(MPQemuLinkState *s) +{ + g_main_loop_unref(s->loop); + g_main_context_unref(s->ctx); + g_main_loop_quit(s->loop); + + mpqemu_destroy_channel(s->com); + + object_unref(OBJECT(s)); +} + +void mpqemu_msg_send(MPQemuLinkState *s, MPQemuMsg *msg, MPQemuChannel *ch= an) +{ + int rc; + uint8_t *data; + union { + char control[CMSG_SPACE(REMOTE_MAX_FDS * sizeof(int))]; + struct cmsghdr align; + } u; + struct msghdr hdr; + struct cmsghdr *chdr; + int sock =3D chan->sock; + QemuMutex *lock =3D &chan->send_lock; + + struct iovec iov =3D { + .iov_base =3D (char *) msg, + .iov_len =3D MPQEMU_MSG_HDR_SIZE, + }; + + memset(&hdr, 0, sizeof(hdr)); + memset(&u, 0, sizeof(u)); + + hdr.msg_iov =3D &iov; + hdr.msg_iovlen =3D 1; + + if (msg->num_fds > REMOTE_MAX_FDS) { + qemu_log_mask(LOG_REMOTE_DEBUG, "%s: Max FDs exceeded\n", __func__= ); + return; + } + + if (msg->num_fds > 0) { + size_t fdsize =3D msg->num_fds * sizeof(int); + + hdr.msg_control =3D &u; + hdr.msg_controllen =3D sizeof(u); + + chdr =3D CMSG_FIRSTHDR(&hdr); + chdr->cmsg_len =3D CMSG_LEN(fdsize); + chdr->cmsg_level =3D SOL_SOCKET; + chdr->cmsg_type =3D SCM_RIGHTS; + memcpy(CMSG_DATA(chdr), msg->fds, fdsize); + hdr.msg_controllen =3D CMSG_SPACE(fdsize); + } + + qemu_mutex_lock(lock); + + do { + rc =3D sendmsg(sock, &hdr, 0); + } while (rc < 0 && (errno =3D=3D EINTR || errno =3D=3D EAGAIN)); + + if (rc < 0) { + qemu_log_mask(LOG_REMOTE_DEBUG, "%s - sendmsg rc is %d, errno is %= d," + " sock %d\n", __func__, rc, errno, sock); + qemu_mutex_unlock(lock); + return; + } + + if (msg->bytestream) { + data =3D msg->data2; + } else { + data =3D (uint8_t *)msg + MPQEMU_MSG_HDR_SIZE; + } + + do { + rc =3D write(sock, data, msg->size); + } while (rc < 0 && (errno =3D=3D EINTR || errno =3D=3D EAGAIN)); + + qemu_mutex_unlock(lock); +} + + +int mpqemu_msg_recv(MPQemuLinkState *s, MPQemuMsg *msg, MPQemuChannel *cha= n) +{ + int rc; + uint8_t *data; + union { + char control[CMSG_SPACE(REMOTE_MAX_FDS * sizeof(int))]; + struct cmsghdr align; + } u; + struct msghdr hdr; + struct cmsghdr *chdr; + size_t fdsize; + int sock =3D chan->sock; + QemuMutex *lock =3D &chan->recv_lock; + + struct iovec iov =3D { + .iov_base =3D (char *) msg, + .iov_len =3D MPQEMU_MSG_HDR_SIZE, + }; + + memset(&hdr, 0, sizeof(hdr)); + memset(&u, 0, sizeof(u)); + + hdr.msg_iov =3D &iov; + hdr.msg_iovlen =3D 1; + hdr.msg_control =3D &u; + hdr.msg_controllen =3D sizeof(u); + + qemu_mutex_lock(lock); + + do { + rc =3D recvmsg(sock, &hdr, 0); + } while (rc < 0 && (errno =3D=3D EINTR || errno =3D=3D EAGAIN)); + + if (rc < 0) { + qemu_log_mask(LOG_REMOTE_DEBUG, "%s - recvmsg rc is %d, errno is %= d," + " sock %d\n", __func__, rc, errno, sock); + qemu_mutex_unlock(lock); + return rc; + } + + msg->num_fds =3D 0; + for (chdr =3D CMSG_FIRSTHDR(&hdr); chdr !=3D NULL; + chdr =3D CMSG_NXTHDR(&hdr, chdr)) { + if ((chdr->cmsg_level =3D=3D SOL_SOCKET) && + (chdr->cmsg_type =3D=3D SCM_RIGHTS)) { + fdsize =3D chdr->cmsg_len - CMSG_LEN(0); + msg->num_fds =3D fdsize / sizeof(int); + if (msg->num_fds > REMOTE_MAX_FDS) { + /* + * TODO: Security issue detected. Sender never sends more + * than REMOTE_MAX_FDS. This condition should be signaled = to + * the admin + */ + qemu_log_mask(LOG_REMOTE_DEBUG, "%s: Max FDs exceeded\n", = __func__); + return -ERANGE; + } + + memcpy(msg->fds, CMSG_DATA(chdr), fdsize); + break; + } + } + + if (msg->size && msg->bytestream) { + msg->data2 =3D calloc(1, msg->size); + data =3D msg->data2; + } else { + data =3D (uint8_t *)&msg->data1; + } + + if (msg->size) { + do { + rc =3D read(sock, data, msg->size); + } while (rc < 0 && (errno =3D=3D EINTR || errno =3D=3D EAGAIN)); + } + + qemu_mutex_unlock(lock); + + return rc; +} + +static gboolean mpqemu_link_handler_prepare(GSource *gsrc, gint *timeout) +{ + g_assert(timeout); + + *timeout =3D -1; + + return FALSE; +} + +static gboolean mpqemu_link_handler_check(GSource *gsrc) +{ + MPQemuChannel *chan =3D (MPQemuChannel *)gsrc; + + return chan->gpfd.events & chan->gpfd.revents; +} + +static gboolean mpqemu_link_handler_dispatch(GSource *gsrc, GSourceFunc fu= nc, + gpointer data) +{ + MPQemuLinkState *s =3D (MPQemuLinkState *)data; + MPQemuChannel *chan =3D (MPQemuChannel *)gsrc; + + s->callback(chan->gpfd.revents, chan); + + if ((chan->gpfd.revents & G_IO_HUP) || (chan->gpfd.revents & G_IO_ERR)= ) { + return G_SOURCE_REMOVE; + } + + return G_SOURCE_CONTINUE; +} + +void mpqemu_link_set_callback(MPQemuLinkState *s, mpqemu_link_callback cal= lback) +{ + s->callback =3D callback; +} + +void mpqemu_init_channel(MPQemuLinkState *s, MPQemuChannel **chan, int fd) +{ + MPQemuChannel *src; + + gsrc_funcs =3D (GSourceFuncs){ + .prepare =3D mpqemu_link_handler_prepare, + .check =3D mpqemu_link_handler_check, + .dispatch =3D mpqemu_link_handler_dispatch, + .finalize =3D NULL, + }; + + src =3D (MPQemuChannel *)g_source_new(&gsrc_funcs, sizeof(MPQemuChanne= l)); + + src->sock =3D fd; + qemu_mutex_init(&src->send_lock); + qemu_mutex_init(&src->recv_lock); + + g_source_set_callback(&src->gsrc, NULL, (gpointer)s, NULL); + src->gpfd.fd =3D fd; + src->gpfd.events =3D G_IO_IN | G_IO_HUP | G_IO_ERR; + g_source_add_poll(&src->gsrc, &src->gpfd); + + *chan =3D src; +} + +void mpqemu_destroy_channel(MPQemuChannel *chan) +{ + g_source_unref(&chan->gsrc); + close(chan->sock); + qemu_mutex_destroy(&chan->send_lock); + qemu_mutex_destroy(&chan->recv_lock); +} + +void mpqemu_start_coms(MPQemuLinkState *s) +{ + + g_assert(g_source_attach(&s->com->gsrc, s->ctx)); + + g_main_loop_run(s->loop); +} --=20 1.8.3.1