From nobody Sun Feb 8 08:27:45 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 15444634491369.427292667027473; Mon, 10 Dec 2018 09:37:29 -0800 (PST) Received: from localhost ([::1]:33984 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWPUl-0002aJ-54 for importer@patchew.org; Mon, 10 Dec 2018 12:37:27 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46116) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWPPb-0006TT-HT for qemu-devel@nongnu.org; Mon, 10 Dec 2018 12:32:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gWPPZ-0003fX-Sl for qemu-devel@nongnu.org; Mon, 10 Dec 2018 12:32:07 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52630) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gWPPZ-0003fI-Jw for qemu-devel@nongnu.org; Mon, 10 Dec 2018 12:32:05 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EA14430024E0; Mon, 10 Dec 2018 17:32:04 +0000 (UTC) Received: from dgilbert-t530.redhat.com (unknown [10.36.118.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 858CF1001F5E; Mon, 10 Dec 2018 17:32:03 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org Date: Mon, 10 Dec 2018 17:31:50 +0000 Message-Id: <20181210173151.16629-7-dgilbert@redhat.com> In-Reply-To: <20181210173151.16629-1-dgilbert@redhat.com> References: <20181210173151.16629-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Mon, 10 Dec 2018 17:32:04 +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] [RFC PATCH 6/7] virtio-fs: Allow mapping of meta data version table 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: sweil@redhat.com, swhiteho@redhat.com, stefanha@redhat.com, vgoyal@redhat.com, miklos@szeredi.hu 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 'meta data version table' is a block of shared memory mapped between multiple QEMUs and fuse daemons, so that they can be informed of metadata updates. It's typically a shmfs file, and it's specified as : -device vhost-user-fs-pci,chardev=3Dchar0,tag=3Dmyfs,cache-size=3D1G,ver= siontable=3D/dev/shm/mdvt1 It gets mapped into the PCI bar after the data cache; it's read only. Signed-off-by: Dr. David Alan Gilbert --- hw/virtio/vhost-user-fs.c | 36 ++++++++++++++++++++++ hw/virtio/virtio-pci.c | 16 ++++++++-- include/hw/virtio/vhost-user-fs.h | 4 +++ include/standard-headers/linux/virtio_fs.h | 1 + 4 files changed, 55 insertions(+), 2 deletions(-) diff --git a/hw/virtio/vhost-user-fs.c b/hw/virtio/vhost-user-fs.c index bbb15477e5..a39ecd3a16 100644 --- a/hw/virtio/vhost-user-fs.c +++ b/hw/virtio/vhost-user-fs.c @@ -296,6 +296,7 @@ static void vuf_device_realize(DeviceState *dev, Error = **errp) unsigned int i; size_t len; int ret; + int mdvtfd =3D -1; =20 if (!fs->conf.chardev.chr) { error_setg(errp, "missing chardev"); @@ -338,6 +339,31 @@ static void vuf_device_realize(DeviceState *dev, Error= **errp) "no smaller than the page size"); return; } + + if (fs->conf.mdvtpath) { + struct stat statbuf; + + mdvtfd =3D open(fs->conf.mdvtpath, O_RDWR); + if (mdvtfd < 0) { + error_setg_errno(errp, errno, + "Failed to open meta-data version table '%s'", + fs->conf.mdvtpath); + + return; + } + if (fstat(mdvtfd, &statbuf) =3D=3D -1) { + error_setg_errno(errp, errno, + "Failed to stat meta-data version table '%s'", + fs->conf.mdvtpath); + close(mdvtfd); + return; + } + + fs->mdvt_size =3D statbuf.st_size; + } + fprintf(stderr, "%s: cachesize=3D%zd mdvt_size=3D%zd\n", __func__, + fs->conf.cache_size, fs->mdvt_size); + /* We need a region with some host memory, 'ram' is the easiest */ memory_region_init_ram_nomigrate(&fs->cache, OBJECT(vdev), "virtio-fs-cache", @@ -348,6 +374,15 @@ static void vuf_device_realize(DeviceState *dev, Error= **errp) mprotect(memory_region_get_ram_ptr(&fs->cache), fs->conf.cache_size, PROT_NONE); =20 + + if (mdvtfd) { + memory_region_init_ram_from_fd(&fs->mdvt, OBJECT(vdev), + "virtio-fs-mdvt", + fs->mdvt_size, true, mdvtfd, NULL); + /* The version table is read-only by the guest */ + memory_region_set_readonly(&fs->mdvt, true); + } + fs->vhost_user =3D vhost_user_init(); if (!fs->vhost_user) { error_setg(errp, "failed to initialize vhost-user"); @@ -416,6 +451,7 @@ static Property vuf_properties[] =3D { DEFINE_PROP_UINT16("queue-size", VHostUserFS, conf.queue_size, 128), DEFINE_PROP_STRING("vhostfd", VHostUserFS, conf.vhostfd), DEFINE_PROP_SIZE("cache-size", VHostUserFS, conf.cache_size, 1ull << 3= 0), + DEFINE_PROP_STRING("versiontable", VHostUserFS, conf.mdvtpath), DEFINE_PROP_END_OF_LIST(), }; =20 diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index e819a29fb1..d8785b78bf 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -2680,20 +2680,32 @@ static void vhost_user_fs_pci_realize(VirtIOPCIProx= y *vpci_dev, Error **errp) VHostUserFSPCI *dev =3D VHOST_USER_FS_PCI(vpci_dev); DeviceState *vdev =3D DEVICE(&dev->vdev); uint64_t cachesize; + uint64_t totalsize; =20 qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)); object_property_set_bool(OBJECT(vdev), true, "realized", errp); cachesize =3D memory_region_size(&dev->vdev.cache); =20 + /* PCIe bar needs to be a power of 2 */ + totalsize =3D pow2ceil(cachesize + dev->vdev.mdvt_size); + /* The bar starts with the data/DAX cache - * Others will be added later. + * followed by the metadata cache. */ memory_region_init(&dev->cachebar, OBJECT(vpci_dev), - "vhost-fs-pci-cachebar", cachesize); + "vhost-fs-pci-cachebar", totalsize); memory_region_add_subregion(&dev->cachebar, 0, &dev->vdev.cache); virtio_pci_add_shm_cap(vpci_dev, VIRTIO_FS_PCI_CACHE_BAR, 0, cachesize, VIRTIO_FS_PCI_SHMCAP_ID_CACHE); =20 + if (dev->vdev.mdvt_size) { + memory_region_add_subregion(&dev->cachebar, cachesize, + &dev->vdev.mdvt); + virtio_pci_add_shm_cap(vpci_dev, VIRTIO_FS_PCI_CACHE_BAR, + cachesize, dev->vdev.mdvt_size, + VIRTIO_FS_PCI_SHMCAP_ID_VERTAB); + } + /* After 'realized' so the memory region exists */ pci_register_bar(&vpci_dev->pci_dev, VIRTIO_FS_PCI_CACHE_BAR, PCI_BASE_ADDRESS_SPACE_MEMORY | diff --git a/include/hw/virtio/vhost-user-fs.h b/include/hw/virtio/vhost-us= er-fs.h index 9989bcd9e7..281ae0a52d 100644 --- a/include/hw/virtio/vhost-user-fs.h +++ b/include/hw/virtio/vhost-user-fs.h @@ -48,6 +48,7 @@ typedef struct { uint16_t queue_size; char *vhostfd; size_t cache_size; + char *mdvtpath; } VHostUserFSConf; =20 typedef struct { @@ -60,6 +61,9 @@ typedef struct { =20 /*< public >*/ MemoryRegion cache; + /* Metadata version table */ + size_t mdvt_size; + MemoryRegion mdvt; } VHostUserFS; =20 /* Callbacks from the vhost-user code for slave commands */ diff --git a/include/standard-headers/linux/virtio_fs.h b/include/standard-= headers/linux/virtio_fs.h index b5f137ca79..77fa651073 100644 --- a/include/standard-headers/linux/virtio_fs.h +++ b/include/standard-headers/linux/virtio_fs.h @@ -42,5 +42,6 @@ struct virtio_fs_config { =20 /* For the id field in virtio_pci_shm_cap */ #define VIRTIO_FS_PCI_SHMCAP_ID_CACHE 0 +#define VIRTIO_FS_PCI_SHMCAP_ID_VERTAB 1 =20 #endif /* _LINUX_VIRTIO_FS_H */ --=20 2.19.2