From nobody Wed May 15 01:50:35 2024 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; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1568736497; cv=none; d=zoho.com; s=zohoarc; b=KOdU+N757awlauuYCCwEDDoSqALyx/iYUuxl5DLw9zG9tGB+09LtyHFeA0SNIEROIyWMSTDytV2fpodXMgIgFQU7EdU1IrkCBYMdgCthqkiaT26yfsoJFzB0tcED15C8aHlXVnV4MvyqWDHc9U6YJaeFDJ2T6RM7Sybp8Nfkg/Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568736497; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=EPdtVwtQVsYBv904uSkx4cbjW2EbP9Nw5KTUhXvBBDg=; b=dWHbEmCvzJMXqO9Wzr1LTapHDD/AsrIKqacMjE4RcQ1sMfNnV3VZWERTSfcIWgibZmLmLaJbyzn0BhrWJ9Hal9Zitp2lomB276oGQh/JK5XTHAYs2jlWBF4P1eVg1XRSpNXFgxwP1h3tJBjHFM0Gz8sf1ZATOhUBxOnHo9fF5bs= ARC-Authentication-Results: i=1; mx.zoho.com; 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=fail 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 1568736497701245.50198587394345; Tue, 17 Sep 2019 09:08:17 -0700 (PDT) Received: from localhost ([::1]:47888 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iAG1X-0004SU-CK for importer@patchew.org; Tue, 17 Sep 2019 12:08:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39567) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iAFue-00008F-C1 for qemu-devel@nongnu.org; Tue, 17 Sep 2019 12:01:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iAFuc-0004va-Tu for qemu-devel@nongnu.org; Tue, 17 Sep 2019 12:01:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33908) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iAFuc-0004vM-Lu for qemu-devel@nongnu.org; Tue, 17 Sep 2019 12:01:06 -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 045068667D for ; Tue, 17 Sep 2019 16:01:06 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-116-53.ams2.redhat.com [10.36.116.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0CE576012E; Tue, 17 Sep 2019 16:01:03 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, cohuck@redhat.com, mst@redhat.com Date: Tue, 17 Sep 2019 17:00:55 +0100 Message-Id: <20190917160057.11847-2-dgilbert@redhat.com> In-Reply-To: <20190917160057.11847-1-dgilbert@redhat.com> References: <20190917160057.11847-1-dgilbert@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.26]); Tue, 17 Sep 2019 16:01:06 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 1/3] virtio: Add virito_fs linux headers 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: mszeredi@redhat.com, vgoyal@redhat.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" Pull in the virtio_fs.h linux header and the constant for the virtiofs ID. Signed-off-by: Stefan Hajnoczi Signed-off-by: Vivek Goyal Signed-off-by: Miklos Szeredi --- include/standard-headers/linux/virtio_fs.h | 41 +++++++++++++++++++++ include/standard-headers/linux/virtio_ids.h | 1 + 2 files changed, 42 insertions(+) create mode 100644 include/standard-headers/linux/virtio_fs.h diff --git a/include/standard-headers/linux/virtio_fs.h b/include/standard-= headers/linux/virtio_fs.h new file mode 100644 index 0000000000..00bd7a6fa7 --- /dev/null +++ b/include/standard-headers/linux/virtio_fs.h @@ -0,0 +1,41 @@ +#ifndef _LINUX_VIRTIO_FS_H +#define _LINUX_VIRTIO_FS_H +/* This header is BSD licensed so anyone can use the definitions to implem= ent + * compatible drivers/servers. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of IBM nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``A= S IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURP= OSE + * ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENT= IAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STR= ICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY W= AY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. */ +#include "standard-headers/linux/types.h" +#include "standard-headers/linux/virtio_ids.h" +#include "standard-headers/linux/virtio_config.h" +#include "standard-headers/linux/virtio_types.h" + +struct virtio_fs_config { + /* Filesystem name (UTF-8, not NUL-terminated, padded with NULs) */ + uint8_t tag[36]; + + /* Number of request queues */ + uint32_t num_request_queues; +} QEMU_PACKED; + +#endif /* _LINUX_VIRTIO_FS_H */ diff --git a/include/standard-headers/linux/virtio_ids.h b/include/standard= -headers/linux/virtio_ids.h index 32b2f94d1f..73fc004807 100644 --- a/include/standard-headers/linux/virtio_ids.h +++ b/include/standard-headers/linux/virtio_ids.h @@ -43,6 +43,7 @@ #define VIRTIO_ID_INPUT 18 /* virtio input */ #define VIRTIO_ID_VSOCK 19 /* virtio vsock transport */ #define VIRTIO_ID_CRYPTO 20 /* virtio crypto */ +#define VIRTIO_ID_FS 26 /* virtio filesystem */ #define VIRTIO_ID_PMEM 27 /* virtio pmem */ =20 #endif /* _LINUX_VIRTIO_IDS_H */ --=20 2.21.0 From nobody Wed May 15 01:50:35 2024 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; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1568736927; cv=none; d=zoho.com; s=zohoarc; b=lHSstPjm4bUVwLFAAKA8w2ucLoSSg0qrX7dqMMKtWyGZk2NlWMitVIRrhprYGNGkAHgm7PkYDPOgNIGjnCpGvGjtVW+QcoBTuFOSD56rTgIRBMc9u9nI3goOJYyfNUFW6W7mf+BeqZBXRw/lhDpWb+K+DvxFdJlWFvKMV66qoP8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568736927; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=gC//CVUJBe80ZD7bqOb6BZJjix49e/1VlV6YLUfM8AI=; b=VU6gGFcGQBET/ymez4H/gaUweiV5Tx6z9r1/NNohJJ/tFzKSsglSlue7e91GTSUoJHtRyt91vEt+1n1eBgYJlm8nORgWxuveFJHLtOEoIxRLI1uNOxsLvn3+n9xyD7Mng5UBRocM3QVaSyBS5Zx9fxmyDy1G0vqDlLVJXX/owW8= ARC-Authentication-Results: i=1; mx.zoho.com; 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=fail 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 156873692700517.27102713638635; Tue, 17 Sep 2019 09:15:27 -0700 (PDT) Received: from localhost ([::1]:48084 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iAG8S-00030Y-KV for importer@patchew.org; Tue, 17 Sep 2019 12:15:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39628) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iAFuo-0000GD-Vn for qemu-devel@nongnu.org; Tue, 17 Sep 2019 12:01:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iAFui-0004xc-Jy for qemu-devel@nongnu.org; Tue, 17 Sep 2019 12:01:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41486) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iAFui-0004xH-BM for qemu-devel@nongnu.org; Tue, 17 Sep 2019 12:01:12 -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 851E38553D for ; Tue, 17 Sep 2019 16:01:11 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-116-53.ams2.redhat.com [10.36.116.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4BEDF6013A; Tue, 17 Sep 2019 16:01:06 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, cohuck@redhat.com, mst@redhat.com Date: Tue, 17 Sep 2019 17:00:56 +0100 Message-Id: <20190917160057.11847-3-dgilbert@redhat.com> In-Reply-To: <20190917160057.11847-1-dgilbert@redhat.com> References: <20190917160057.11847-1-dgilbert@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.28]); Tue, 17 Sep 2019 16:01:11 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 2/3] virtio: add vhost-user-fs base device 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: mszeredi@redhat.com, vgoyal@redhat.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" The virtio-fs virtio device provides shared file system access using the FUSE protocol carried over virtio. The actual file server is implemented in an external vhost-user-fs device backend process. Signed-off-by: Stefan Hajnoczi Signed-off-by: Sebastien Boeuf Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Cornelia Huck --- configure | 13 ++ hw/virtio/Makefile.objs | 1 + hw/virtio/vhost-user-fs.c | 299 ++++++++++++++++++++++++++++++ include/hw/virtio/vhost-user-fs.h | 45 +++++ 4 files changed, 358 insertions(+) create mode 100644 hw/virtio/vhost-user-fs.c create mode 100644 include/hw/virtio/vhost-user-fs.h diff --git a/configure b/configure index 30aad233d1..1bd7b40d49 100755 --- a/configure +++ b/configure @@ -382,6 +382,7 @@ vhost_crypto=3D"" vhost_scsi=3D"" vhost_vsock=3D"" vhost_user=3D"" +vhost_user_fs=3D"" kvm=3D"no" hax=3D"no" hvf=3D"no" @@ -1294,6 +1295,10 @@ for opt do ;; --enable-vhost-vsock) vhost_vsock=3D"yes" ;; + --disable-vhost-user-fs) vhost_user_fs=3D"no" + ;; + --enable-vhost-user-fs) vhost_user_fs=3D"yes" + ;; --disable-opengl) opengl=3D"no" ;; --enable-opengl) opengl=3D"yes" @@ -2232,6 +2237,10 @@ test "$vhost_crypto" =3D "" && vhost_crypto=3D$vhost= _user if test "$vhost_crypto" =3D "yes" && test "$vhost_user" =3D "no"; then error_exit "--enable-vhost-crypto requires --enable-vhost-user" fi +test "$vhost_user_fs" =3D "" && vhost_user_fs=3D$vhost_user +if test "$vhost_user_fs" =3D "yes" && test "$vhost_user" =3D "no"; then + error_exit "--enable-vhost-user-fs requires --enable-vhost-user" +fi =20 # OR the vhost-kernel and vhost-user values for simplicity if test "$vhost_net" =3D ""; then @@ -6374,6 +6383,7 @@ echo "vhost-crypto support $vhost_crypto" echo "vhost-scsi support $vhost_scsi" echo "vhost-vsock support $vhost_vsock" echo "vhost-user support $vhost_user" +echo "vhost-user-fs support $vhost_user_fs" echo "Trace backends $trace_backends" if have_backend "simple"; then echo "Trace output file $trace_file-" @@ -6873,6 +6883,9 @@ fi if test "$vhost_user" =3D "yes" ; then echo "CONFIG_VHOST_USER=3Dy" >> $config_host_mak fi +if test "$vhost_user_fs" =3D "yes" ; then + echo "CONFIG_VHOST_USER_FS=3Dy" >> $config_host_mak +fi if test "$blobs" =3D "yes" ; then echo "INSTALL_BLOBS=3Dyes" >> $config_host_mak fi diff --git a/hw/virtio/Makefile.objs b/hw/virtio/Makefile.objs index 964ce78607..47ffbf22c4 100644 --- a/hw/virtio/Makefile.objs +++ b/hw/virtio/Makefile.objs @@ -11,6 +11,7 @@ common-obj-$(CONFIG_VIRTIO_PCI) +=3D virtio-pci.o common-obj-$(CONFIG_VIRTIO_MMIO) +=3D virtio-mmio.o obj-$(CONFIG_VIRTIO_BALLOON) +=3D virtio-balloon.o obj-$(CONFIG_VIRTIO_CRYPTO) +=3D virtio-crypto.o +obj-$(CONFIG_VHOST_USER_FS) +=3D vhost-user-fs.o obj-$(call land,$(CONFIG_VIRTIO_CRYPTO),$(CONFIG_VIRTIO_PCI)) +=3D virtio-= crypto-pci.o obj-$(CONFIG_VIRTIO_PMEM) +=3D virtio-pmem.o common-obj-$(call land,$(CONFIG_VIRTIO_PMEM),$(CONFIG_VIRTIO_PCI)) +=3D vi= rtio-pmem-pci.o diff --git a/hw/virtio/vhost-user-fs.c b/hw/virtio/vhost-user-fs.c new file mode 100644 index 0000000000..f0df7f4746 --- /dev/null +++ b/hw/virtio/vhost-user-fs.c @@ -0,0 +1,299 @@ +/* + * Vhost-user filesystem virtio device + * + * Copyright 2018-2019 Red Hat, Inc. + * + * Authors: + * Stefan Hajnoczi + * + * This work is licensed under the terms of the GNU GPL, version 2 or + * (at your option) any later version. See the COPYING file in the + * top-level directory. + */ + +#include "qemu/osdep.h" +#include +#include "standard-headers/linux/virtio_fs.h" +#include "qapi/error.h" +#include "hw/qdev-properties.h" +#include "hw/virtio/virtio-bus.h" +#include "hw/virtio/virtio-access.h" +#include "qemu/error-report.h" +#include "hw/virtio/vhost-user-fs.h" +#include "monitor/monitor.h" + +static void vuf_get_config(VirtIODevice *vdev, uint8_t *config) +{ + VHostUserFS *fs =3D VHOST_USER_FS(vdev); + struct virtio_fs_config fscfg =3D {}; + + memcpy((char *)fscfg.tag, fs->conf.tag, + MIN(strlen(fs->conf.tag) + 1, sizeof(fscfg.tag))); + + virtio_stl_p(vdev, &fscfg.num_request_queues, fs->conf.num_request_que= ues); + + memcpy(config, &fscfg, sizeof(fscfg)); +} + +static void vuf_start(VirtIODevice *vdev) +{ + VHostUserFS *fs =3D VHOST_USER_FS(vdev); + BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(vdev))); + VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); + int ret; + int i; + + if (!k->set_guest_notifiers) { + error_report("binding does not support guest notifiers"); + return; + } + + ret =3D vhost_dev_enable_notifiers(&fs->vhost_dev, vdev); + if (ret < 0) { + error_report("Error enabling host notifiers: %d", -ret); + return; + } + + ret =3D k->set_guest_notifiers(qbus->parent, fs->vhost_dev.nvqs, true); + if (ret < 0) { + error_report("Error binding guest notifier: %d", -ret); + goto err_host_notifiers; + } + + fs->vhost_dev.acked_features =3D vdev->guest_features; + ret =3D vhost_dev_start(&fs->vhost_dev, vdev); + if (ret < 0) { + error_report("Error starting vhost: %d", -ret); + goto err_guest_notifiers; + } + + /* + * guest_notifier_mask/pending not used yet, so just unmask + * everything here. virtio-pci will do the right thing by + * enabling/disabling irqfd. + */ + for (i =3D 0; i < fs->vhost_dev.nvqs; i++) { + vhost_virtqueue_mask(&fs->vhost_dev, vdev, i, false); + } + + return; + +err_guest_notifiers: + k->set_guest_notifiers(qbus->parent, fs->vhost_dev.nvqs, false); +err_host_notifiers: + vhost_dev_disable_notifiers(&fs->vhost_dev, vdev); +} + +static void vuf_stop(VirtIODevice *vdev) +{ + VHostUserFS *fs =3D VHOST_USER_FS(vdev); + BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(vdev))); + VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); + int ret; + + if (!k->set_guest_notifiers) { + return; + } + + vhost_dev_stop(&fs->vhost_dev, vdev); + + ret =3D k->set_guest_notifiers(qbus->parent, fs->vhost_dev.nvqs, false= ); + if (ret < 0) { + error_report("vhost guest notifier cleanup failed: %d", ret); + return; + } + + vhost_dev_disable_notifiers(&fs->vhost_dev, vdev); +} + +static void vuf_set_status(VirtIODevice *vdev, uint8_t status) +{ + VHostUserFS *fs =3D VHOST_USER_FS(vdev); + bool should_start =3D status & VIRTIO_CONFIG_S_DRIVER_OK; + + if (!vdev->vm_running) { + should_start =3D false; + } + + if (fs->vhost_dev.started =3D=3D should_start) { + return; + } + + if (should_start) { + vuf_start(vdev); + } else { + vuf_stop(vdev); + } +} + +static uint64_t vuf_get_features(VirtIODevice *vdev, + uint64_t requested_features, + Error **errp) +{ + /* No feature bits used yet */ + return requested_features; +} + +static void vuf_handle_output(VirtIODevice *vdev, VirtQueue *vq) +{ + /* + * Not normally called; it's the daemon that handles the queue; + * however virtio's cleanup path can call this. + */ +} + +static void vuf_guest_notifier_mask(VirtIODevice *vdev, int idx, + bool mask) +{ + VHostUserFS *fs =3D VHOST_USER_FS(vdev); + + vhost_virtqueue_mask(&fs->vhost_dev, vdev, idx, mask); +} + +static bool vuf_guest_notifier_pending(VirtIODevice *vdev, int idx) +{ + VHostUserFS *fs =3D VHOST_USER_FS(vdev); + + return vhost_virtqueue_pending(&fs->vhost_dev, idx); +} + +static void vuf_device_realize(DeviceState *dev, Error **errp) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VHostUserFS *fs =3D VHOST_USER_FS(dev); + unsigned int i; + size_t len; + int ret; + + if (!fs->conf.chardev.chr) { + error_setg(errp, "missing chardev"); + return; + } + + if (!fs->conf.tag) { + error_setg(errp, "missing tag property"); + return; + } + len =3D strlen(fs->conf.tag); + if (len =3D=3D 0) { + error_setg(errp, "tag property cannot be empty"); + return; + } + if (len > sizeof_field(struct virtio_fs_config, tag)) { + error_setg(errp, "tag property must be %zu bytes or less", + sizeof_field(struct virtio_fs_config, tag)); + return; + } + + if (fs->conf.num_request_queues =3D=3D 0) { + error_setg(errp, "num-request-queues property must be larger than = 0"); + return; + } + + if (!is_power_of_2(fs->conf.queue_size)) { + error_setg(errp, "queue-size property must be a power of 2"); + return; + } + + if (fs->conf.queue_size > VIRTQUEUE_MAX_SIZE) { + error_setg(errp, "queue-size property must be %u or smaller", + VIRTQUEUE_MAX_SIZE); + return; + } + + if (!vhost_user_init(&fs->vhost_user, &fs->conf.chardev, errp)) { + return; + } + + virtio_init(vdev, "vhost-user-fs", VIRTIO_ID_FS, + sizeof(struct virtio_fs_config)); + + /* Hiprio queue */ + virtio_add_queue(vdev, fs->conf.queue_size, vuf_handle_output); + + /* Request queues */ + for (i =3D 0; i < fs->conf.num_request_queues; i++) { + virtio_add_queue(vdev, fs->conf.queue_size, vuf_handle_output); + } + + /* 1 high prio queue, plus the number configured */ + fs->vhost_dev.nvqs =3D 1 + fs->conf.num_request_queues; + fs->vhost_dev.vqs =3D g_new0(struct vhost_virtqueue, fs->vhost_dev.nvq= s); + ret =3D vhost_dev_init(&fs->vhost_dev, &fs->vhost_user, + VHOST_BACKEND_TYPE_USER, 0); + if (ret < 0) { + error_setg_errno(errp, -ret, "vhost_dev_init failed"); + goto err_virtio; + } + + return; + +err_virtio: + vhost_user_cleanup(&fs->vhost_user); + virtio_cleanup(vdev); + g_free(fs->vhost_dev.vqs); + return; +} + +static void vuf_device_unrealize(DeviceState *dev, Error **errp) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VHostUserFS *fs =3D VHOST_USER_FS(dev); + + /* This will stop vhost backend if appropriate. */ + vuf_set_status(vdev, 0); + + vhost_dev_cleanup(&fs->vhost_dev); + + vhost_user_cleanup(&fs->vhost_user); + + virtio_cleanup(vdev); + g_free(fs->vhost_dev.vqs); + fs->vhost_dev.vqs =3D NULL; +} + +static const VMStateDescription vuf_vmstate =3D { + .name =3D "vhost-user-fs", + .unmigratable =3D 1, +}; + +static Property vuf_properties[] =3D { + DEFINE_PROP_CHR("chardev", VHostUserFS, conf.chardev), + DEFINE_PROP_STRING("tag", VHostUserFS, conf.tag), + DEFINE_PROP_UINT16("num-request-queues", VHostUserFS, + conf.num_request_queues, 1), + DEFINE_PROP_UINT16("queue-size", VHostUserFS, conf.queue_size, 128), + DEFINE_PROP_STRING("vhostfd", VHostUserFS, conf.vhostfd), + DEFINE_PROP_END_OF_LIST(), +}; + +static void vuf_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_CLASS(klass); + + dc->props =3D vuf_properties; + dc->vmsd =3D &vuf_vmstate; + set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); + vdc->realize =3D vuf_device_realize; + vdc->unrealize =3D vuf_device_unrealize; + vdc->get_features =3D vuf_get_features; + vdc->get_config =3D vuf_get_config; + vdc->set_status =3D vuf_set_status; + vdc->guest_notifier_mask =3D vuf_guest_notifier_mask; + vdc->guest_notifier_pending =3D vuf_guest_notifier_pending; +} + +static const TypeInfo vuf_info =3D { + .name =3D TYPE_VHOST_USER_FS, + .parent =3D TYPE_VIRTIO_DEVICE, + .instance_size =3D sizeof(VHostUserFS), + .class_init =3D vuf_class_init, +}; + +static void vuf_register_types(void) +{ + type_register_static(&vuf_info); +} + +type_init(vuf_register_types) diff --git a/include/hw/virtio/vhost-user-fs.h b/include/hw/virtio/vhost-us= er-fs.h new file mode 100644 index 0000000000..4a9186721a --- /dev/null +++ b/include/hw/virtio/vhost-user-fs.h @@ -0,0 +1,45 @@ +/* + * Vhost-user filesystem virtio device + * + * Copyright 2018-2019 Red Hat, Inc. + * + * Authors: + * Stefan Hajnoczi + * + * This work is licensed under the terms of the GNU GPL, version 2 or + * (at your option) any later version. See the COPYING file in the + * top-level directory. + */ + +#ifndef _QEMU_VHOST_USER_FS_H +#define _QEMU_VHOST_USER_FS_H + +#include "hw/virtio/virtio.h" +#include "hw/virtio/vhost.h" +#include "hw/virtio/vhost-user.h" +#include "chardev/char-fe.h" + +#define TYPE_VHOST_USER_FS "x-vhost-user-fs-device" +#define VHOST_USER_FS(obj) \ + OBJECT_CHECK(VHostUserFS, (obj), TYPE_VHOST_USER_FS) + +typedef struct { + CharBackend chardev; + char *tag; + uint16_t num_request_queues; + uint16_t queue_size; + char *vhostfd; +} VHostUserFSConf; + +typedef struct { + /*< private >*/ + VirtIODevice parent; + VHostUserFSConf conf; + struct vhost_virtqueue *vhost_vqs; + struct vhost_dev vhost_dev; + VhostUserState vhost_user; + + /*< public >*/ +} VHostUserFS; + +#endif /* _QEMU_VHOST_USER_FS_H */ --=20 2.21.0 From nobody Wed May 15 01:50:35 2024 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; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1568737284; cv=none; d=zoho.com; s=zohoarc; b=IqmvyuQyHbBFwr8l86Wu3g2RsuZ9cvPKTHRkCUm6CHxhQSAsTFhpt9f76u0B5dvIZHgjFAkV0u2QDf9bklPd6Q5Utk8S7XfKEvq1jDFjE++rqPRDY6E0KkJYDZG/rX30fMLf0x3gGYwh6cqzgi9blCUWpG+P9ngLGRT0Z/25gJk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568737284; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=h98py1jAAA88Amh/27mt/16zYRn7Q3ux/gOT4CSYoX4=; b=QBuDVHIIh5CBAzDdmiMhVWcvLVi1eJsz06UOESv3HJhC2olgZ+8hGwG/pVhdi4T5q0V8/QX9Sb2MiYcFD5/vbDyJu02d5QBSothV+tjQ2qHYqFuUSLSoKsB8X9DiXFmggMoI2dU0qVyJo/Tw44yu0/gXertexJCGECNdiA2k1hU= ARC-Authentication-Results: i=1; mx.zoho.com; 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=fail 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 1568737284875538.6729871497037; Tue, 17 Sep 2019 09:21:24 -0700 (PDT) Received: from localhost ([::1]:48206 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iAGE9-0000Ux-59 for importer@patchew.org; Tue, 17 Sep 2019 12:21:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39620) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iAFum-0000Eb-At for qemu-devel@nongnu.org; Tue, 17 Sep 2019 12:01:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iAFuk-0004yK-DE for qemu-devel@nongnu.org; Tue, 17 Sep 2019 12:01:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33134) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iAFuk-0004xt-1E for qemu-devel@nongnu.org; Tue, 17 Sep 2019 12:01:14 -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 3FA61A3D389 for ; Tue, 17 Sep 2019 16:01:13 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-116-53.ams2.redhat.com [10.36.116.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id E12E56012C; Tue, 17 Sep 2019 16:01:11 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, cohuck@redhat.com, mst@redhat.com Date: Tue, 17 Sep 2019 17:00:57 +0100 Message-Id: <20190917160057.11847-4-dgilbert@redhat.com> In-Reply-To: <20190917160057.11847-1-dgilbert@redhat.com> References: <20190917160057.11847-1-dgilbert@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.6.2 (mx1.redhat.com [10.5.110.68]); Tue, 17 Sep 2019 16:01:13 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 3/3] virtio: add vhost-user-fs-pci device 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: mszeredi@redhat.com, vgoyal@redhat.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" Add the PCI version of vhost-user-fs. Launch QEMU like this: qemu -chardev socket,path=3D/tmp/vhost-fs.sock,id=3Dchr0 -device x-vhost-user-fs-pci,tag=3Dmyfs,chardev=3Dchr0 Signed-off-by: Stefan Hajnoczi Signed-off-by: Sebastien Boeuf Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Cornelia Huck --- hw/virtio/Makefile.objs | 1 + hw/virtio/vhost-user-fs-pci.c | 85 +++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 hw/virtio/vhost-user-fs-pci.c diff --git a/hw/virtio/Makefile.objs b/hw/virtio/Makefile.objs index 47ffbf22c4..e2f70fbb89 100644 --- a/hw/virtio/Makefile.objs +++ b/hw/virtio/Makefile.objs @@ -15,6 +15,7 @@ obj-$(CONFIG_VHOST_USER_FS) +=3D vhost-user-fs.o obj-$(call land,$(CONFIG_VIRTIO_CRYPTO),$(CONFIG_VIRTIO_PCI)) +=3D virtio-= crypto-pci.o obj-$(CONFIG_VIRTIO_PMEM) +=3D virtio-pmem.o common-obj-$(call land,$(CONFIG_VIRTIO_PMEM),$(CONFIG_VIRTIO_PCI)) +=3D vi= rtio-pmem-pci.o +obj-$(call land,$(CONFIG_VHOST_USER_FS),$(CONFIG_VIRTIO_PCI)) +=3D vhost-u= ser-fs-pci.o obj-$(CONFIG_VHOST_VSOCK) +=3D vhost-vsock.o =20 ifeq ($(CONFIG_VIRTIO_PCI),y) diff --git a/hw/virtio/vhost-user-fs-pci.c b/hw/virtio/vhost-user-fs-pci.c new file mode 100644 index 0000000000..0e70985094 --- /dev/null +++ b/hw/virtio/vhost-user-fs-pci.c @@ -0,0 +1,85 @@ +/* + * Vhost-user filesystem virtio device PCI glue + * + * Copyright 2018-2019 Red Hat, Inc. + * + * Authors: + * Dr. David Alan Gilbert + * + * This work is licensed under the terms of the GNU GPL, version 2 or + * (at your option) any later version. See the COPYING file in the + * top-level directory. + */ + +#include "qemu/osdep.h" +#include "hw/qdev-properties.h" +#include "hw/virtio/vhost-user-fs.h" +#include "virtio-pci.h" + +struct VHostUserFSPCI { + VirtIOPCIProxy parent_obj; + VHostUserFS vdev; +}; + +typedef struct VHostUserFSPCI VHostUserFSPCI; + +#define TYPE_VHOST_USER_FS_PCI "vhost-user-fs-pci-base" + +#define VHOST_USER_FS_PCI(obj) \ + OBJECT_CHECK(VHostUserFSPCI, (obj), TYPE_VHOST_USER_FS_PCI) + +static Property vhost_user_fs_pci_properties[] =3D { + DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, + DEV_NVECTORS_UNSPECIFIED), + DEFINE_PROP_END_OF_LIST(), +}; + +static void vhost_user_fs_pci_realize(VirtIOPCIProxy *vpci_dev, Error **er= rp) +{ + VHostUserFSPCI *dev =3D VHOST_USER_FS_PCI(vpci_dev); + DeviceState *vdev =3D DEVICE(&dev->vdev); + + if (vpci_dev->nvectors =3D=3D DEV_NVECTORS_UNSPECIFIED) { + vpci_dev->nvectors =3D dev->vdev.conf.num_request_queues + 1; + } + + qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)); + object_property_set_bool(OBJECT(vdev), true, "realized", errp); +} + +static void vhost_user_fs_pci_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + VirtioPCIClass *k =3D VIRTIO_PCI_CLASS(klass); + PCIDeviceClass *pcidev_k =3D PCI_DEVICE_CLASS(klass); + k->realize =3D vhost_user_fs_pci_realize; + set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); + dc->props =3D vhost_user_fs_pci_properties; + pcidev_k->vendor_id =3D PCI_VENDOR_ID_REDHAT_QUMRANET; + pcidev_k->device_id =3D 0; /* Set by virtio-pci based on virtio id */ + pcidev_k->revision =3D 0x00; + pcidev_k->class_id =3D PCI_CLASS_STORAGE_OTHER; +} + +static void vhost_user_fs_pci_instance_init(Object *obj) +{ + VHostUserFSPCI *dev =3D VHOST_USER_FS_PCI(obj); + + virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), + TYPE_VHOST_USER_FS); +} + +static const VirtioPCIDeviceTypeInfo vhost_user_fs_pci_info =3D { + .base_name =3D TYPE_VHOST_USER_FS_PCI, + .non_transitional_name =3D "x-vhost-user-fs-pci", + .instance_size =3D sizeof(VHostUserFSPCI), + .instance_init =3D vhost_user_fs_pci_instance_init, + .class_init =3D vhost_user_fs_pci_class_init, +}; + +static void vhost_user_fs_pci_register(void) +{ + virtio_pci_types_register(&vhost_user_fs_pci_info); +} + +type_init(vhost_user_fs_pci_register); --=20 2.21.0