From nobody Tue Feb 10 11:12:36 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 150767274180433.69307951217286; Tue, 10 Oct 2017 14:59:01 -0700 (PDT) Received: from localhost ([::1]:37359 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e22Y6-0003YJ-17 for importer@patchew.org; Tue, 10 Oct 2017 17:58:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39587) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e22Ej-0004N8-G7 for qemu-devel@nongnu.org; Tue, 10 Oct 2017 17:38:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e22Eh-0002v1-Ak for qemu-devel@nongnu.org; Tue, 10 Oct 2017 17:38:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33536) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e22Eh-0002uh-2v for qemu-devel@nongnu.org; Tue, 10 Oct 2017 17:38:47 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 23D7E7E445; Tue, 10 Oct 2017 21:38:46 +0000 (UTC) Received: from localhost (unknown [10.36.112.15]) by smtp.corp.redhat.com (Postfix) with ESMTP id C28C01899A; Tue, 10 Oct 2017 21:38:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 23D7E7E445 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 10 Oct 2017 23:35:05 +0200 Message-Id: <20171010213506.22989-27-marcandre.lureau@redhat.com> In-Reply-To: <20171010213506.22989-1-marcandre.lureau@redhat.com> References: <20171010213506.22989-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 10 Oct 2017 21:38:46 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL v2 26/27] vhost-user-scsi: use libvhost-user glib helper 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: pbonzini@redhat.com, felipe@nutanix.com, changpeng.liu@intel.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , f4bug@amsat.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Paolo Bonzini --- contrib/vhost-user-scsi/vhost-user-scsi.c | 162 +++-----------------------= ---- 1 file changed, 16 insertions(+), 146 deletions(-) diff --git a/contrib/vhost-user-scsi/vhost-user-scsi.c b/contrib/vhost-user= -scsi/vhost-user-scsi.c index ff817d6643..615e2a76bb 100644 --- a/contrib/vhost-user-scsi/vhost-user-scsi.c +++ b/contrib/vhost-user-scsi/vhost-user-scsi.c @@ -11,7 +11,7 @@ */ =20 #include "qemu/osdep.h" -#include "contrib/libvhost-user/libvhost-user.h" +#include "contrib/libvhost-user/libvhost-user-glib.h" #include "standard-headers/linux/virtio_scsi.h" #include "iscsi/iscsi.h" #include "iscsi/scsi-lowlevel.h" @@ -26,95 +26,13 @@ typedef struct VusIscsiLun { } VusIscsiLun; =20 typedef struct VusDev { - VuDev vu_dev; + VugDev parent; + int server_sock; - GMainLoop *loop; - GHashTable *fdmap; /* fd -> gsource */ VusIscsiLun lun; + GMainLoop *loop; } VusDev; =20 -/** glib event loop integration for libvhost-user and misc callbacks **/ - -QEMU_BUILD_BUG_ON((int)G_IO_IN !=3D (int)VU_WATCH_IN); -QEMU_BUILD_BUG_ON((int)G_IO_OUT !=3D (int)VU_WATCH_OUT); -QEMU_BUILD_BUG_ON((int)G_IO_PRI !=3D (int)VU_WATCH_PRI); -QEMU_BUILD_BUG_ON((int)G_IO_ERR !=3D (int)VU_WATCH_ERR); -QEMU_BUILD_BUG_ON((int)G_IO_HUP !=3D (int)VU_WATCH_HUP); - -typedef struct vus_gsrc { - GSource parent; - VusDev *vdev_scsi; - GPollFD gfd; -} vus_gsrc_t; - -static gboolean vus_gsrc_prepare(GSource *src, gint *timeout) -{ - assert(timeout); - - *timeout =3D -1; - return FALSE; -} - -static gboolean vus_gsrc_check(GSource *src) -{ - vus_gsrc_t *vus_src =3D (vus_gsrc_t *)src; - - assert(vus_src); - - return vus_src->gfd.revents & vus_src->gfd.events; -} - -static gboolean vus_gsrc_dispatch(GSource *src, GSourceFunc cb, gpointer d= ata) -{ - VusDev *vdev_scsi; - vus_gsrc_t *vus_src =3D (vus_gsrc_t *)src; - - assert(vus_src); - - vdev_scsi =3D vus_src->vdev_scsi; - - assert(vdev_scsi); - - ((vu_watch_cb)cb)(&vdev_scsi->vu_dev, vus_src->gfd.revents, data); - - return G_SOURCE_CONTINUE; -} - -static GSourceFuncs vus_gsrc_funcs =3D { - vus_gsrc_prepare, - vus_gsrc_check, - vus_gsrc_dispatch, - NULL -}; - -static GSource *vus_gsrc_new(VusDev *vdev_scsi, int fd, GIOCondition cond, - vu_watch_cb vu_cb, GSourceFunc gsrc_cb, gpoin= ter data) -{ - GSource *vus_gsrc; - vus_gsrc_t *vus_src; - guint id; - - assert(vdev_scsi); - assert(fd >=3D 0); - assert(vu_cb || gsrc_cb); - assert(!(vu_cb && gsrc_cb)); - - vus_gsrc =3D g_source_new(&vus_gsrc_funcs, sizeof(vus_gsrc_t)); - g_source_set_callback(vus_gsrc, (GSourceFunc) vu_cb, data, NULL); - vus_src =3D (vus_gsrc_t *)vus_gsrc; - vus_src->vdev_scsi =3D vdev_scsi; - vus_src->gfd.fd =3D fd; - vus_src->gfd.events =3D cond; - - g_source_add_poll(vus_gsrc, &vus_src->gfd); - g_source_set_callback(vus_gsrc, gsrc_cb, data, NULL); - id =3D g_source_attach(vus_gsrc, NULL); - assert(id); - g_source_unref(vus_gsrc); - - return vus_gsrc; -} - /** libiscsi integration **/ =20 typedef struct virtio_scsi_cmd_req VirtIOSCSICmdReq; @@ -291,11 +209,13 @@ static int handle_cmd_sync(struct iscsi_context *ctx, =20 static void vus_panic_cb(VuDev *vu_dev, const char *buf) { + VugDev *gdev; VusDev *vdev_scsi; =20 assert(vu_dev); =20 - vdev_scsi =3D container_of(vu_dev, VusDev, vu_dev); + gdev =3D container_of(vu_dev, VugDev, parent); + vdev_scsi =3D container_of(gdev, VusDev, parent); if (buf) { g_warning("vu_panic: %s", buf); } @@ -303,40 +223,16 @@ static void vus_panic_cb(VuDev *vu_dev, const char *b= uf) g_main_loop_quit(vdev_scsi->loop); } =20 -static void vus_add_watch_cb(VuDev *vu_dev, int fd, int vu_evt, vu_watch_c= b cb, - void *pvt) -{ - GSource *src; - VusDev *vdev_scsi; - - assert(vu_dev); - assert(fd >=3D 0); - assert(cb); - - vdev_scsi =3D container_of(vu_dev, VusDev, vu_dev); - src =3D vus_gsrc_new(vdev_scsi, fd, vu_evt, cb, NULL, pvt); - g_hash_table_replace(vdev_scsi->fdmap, GINT_TO_POINTER(fd), src); -} - -static void vus_del_watch_cb(VuDev *vu_dev, int fd) -{ - VusDev *vdev_scsi; - - assert(vu_dev); - assert(fd >=3D 0); - - vdev_scsi =3D container_of(vu_dev, VusDev, vu_dev); - g_hash_table_remove(vdev_scsi->fdmap, GINT_TO_POINTER(fd)); -} - static void vus_proc_req(VuDev *vu_dev, int idx) { + VugDev *gdev; VusDev *vdev_scsi; VuVirtq *vq; =20 assert(vu_dev); =20 - vdev_scsi =3D container_of(vu_dev, VusDev, vu_dev); + gdev =3D container_of(vu_dev, VugDev, parent); + vdev_scsi =3D container_of(gdev, VusDev, parent); if (idx < 0 || idx >=3D VHOST_MAX_NR_VIRTQUEUE) { g_warning("VQ Index out of range: %d", idx); vus_panic_cb(vu_dev, NULL); @@ -420,21 +316,6 @@ static const VuDevIface vus_iface =3D { .queue_set_started =3D vus_queue_set_started, }; =20 -static gboolean vus_vhost_cb(gpointer data) -{ - VuDev *vu_dev =3D (VuDev *)data; - - assert(vu_dev); - - if (!vu_dispatch(vu_dev) !=3D 0) { - g_warning("Error processing vhost message"); - vus_panic_cb(vu_dev, NULL); - return G_SOURCE_REMOVE; - } - - return G_SOURCE_CONTINUE; -} - /** misc helpers **/ =20 static int unix_sock_new(char *unix_fn) @@ -482,7 +363,6 @@ static void vdev_scsi_free(VusDev *vdev_scsi) close(vdev_scsi->server_sock); } g_main_loop_unref(vdev_scsi->loop); - g_hash_table_unref(vdev_scsi->fdmap); g_free(vdev_scsi); } =20 @@ -493,9 +373,6 @@ static VusDev *vdev_scsi_new(int server_sock) vdev_scsi =3D g_new0(VusDev, 1); vdev_scsi->server_sock =3D server_sock; vdev_scsi->loop =3D g_main_loop_new(NULL, FALSE); - vdev_scsi->fdmap =3D - g_hash_table_new_full(NULL, NULL, NULL, - (GDestroyNotify) g_source_destroy); =20 return vdev_scsi; } @@ -503,11 +380,9 @@ static VusDev *vdev_scsi_new(int server_sock) static int vdev_scsi_run(VusDev *vdev_scsi) { int cli_sock; - int ret =3D 0; =20 assert(vdev_scsi); assert(vdev_scsi->server_sock >=3D 0); - assert(vdev_scsi->loop); =20 cli_sock =3D accept(vdev_scsi->server_sock, NULL, NULL); if (cli_sock < 0) { @@ -515,21 +390,16 @@ static int vdev_scsi_run(VusDev *vdev_scsi) return -1; } =20 - vu_init(&vdev_scsi->vu_dev, - cli_sock, - vus_panic_cb, - vus_add_watch_cb, - vus_del_watch_cb, - &vus_iface); - - vus_gsrc_new(vdev_scsi, cli_sock, G_IO_IN, NULL, vus_vhost_cb, - &vdev_scsi->vu_dev); + vug_init(&vdev_scsi->parent, + cli_sock, + vus_panic_cb, + &vus_iface); =20 g_main_loop_run(vdev_scsi->loop); =20 - vu_deinit(&vdev_scsi->vu_dev); + vug_deinit(&vdev_scsi->parent); =20 - return ret; + return 0; } =20 int main(int argc, char **argv) --=20 2.15.0.rc0.40.gaefcc5f6f