qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Dr. David Alan Gilbert (git)" <dgilbert@redhat.com>
To: qemu-devel@nongnu.org
Cc: vgoyal@redhat.com, miklos@szeredi.hu, stefanha@redhat.com,
	sweil@redhat.com, swhiteho@redhat.com
Subject: [Qemu-devel] [RFC PATCH 4/7] virtio-fs: Add vhost-user slave commands for mapping
Date: Mon, 10 Dec 2018 17:31:48 +0000	[thread overview]
Message-ID: <20181210173151.16629-5-dgilbert@redhat.com> (raw)
In-Reply-To: <20181210173151.16629-1-dgilbert@redhat.com>

From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>

The daemon may request that fd's be mapped into the virtio-fs cache
visible to the guest.
These mappings are triggered by commands sent over the slave fd
from the daemon.

Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
---
 contrib/libvhost-user/libvhost-user.h |  3 +++
 docs/interop/vhost-user.txt           | 35 +++++++++++++++++++++++++++
 hw/virtio/vhost-user-fs.c             | 20 +++++++++++++++
 hw/virtio/vhost-user.c                | 16 ++++++++++++
 include/hw/virtio/vhost-user-fs.h     | 24 ++++++++++++++++++
 5 files changed, 98 insertions(+)

diff --git a/contrib/libvhost-user/libvhost-user.h b/contrib/libvhost-user/libvhost-user.h
index 4aa55b4d2d..6cff0ff189 100644
--- a/contrib/libvhost-user/libvhost-user.h
+++ b/contrib/libvhost-user/libvhost-user.h
@@ -99,6 +99,9 @@ typedef enum VhostUserSlaveRequest {
     VHOST_USER_SLAVE_IOTLB_MSG = 1,
     VHOST_USER_SLAVE_CONFIG_CHANGE_MSG = 2,
     VHOST_USER_SLAVE_VRING_HOST_NOTIFIER_MSG = 3,
+    VHOST_USER_SLAVE_FS_MAP = 4,
+    VHOST_USER_SLAVE_FS_UNMAP = 5,
+    VHOST_USER_SLAVE_FS_SYNC = 6,
     VHOST_USER_SLAVE_MAX
 }  VhostUserSlaveRequest;
 
diff --git a/docs/interop/vhost-user.txt b/docs/interop/vhost-user.txt
index c2194711d9..29cdd74523 100644
--- a/docs/interop/vhost-user.txt
+++ b/docs/interop/vhost-user.txt
@@ -815,6 +815,41 @@ Slave message types
       This request should be sent only when VHOST_USER_PROTOCOL_F_HOST_NOTIFIER
       protocol feature has been successfully negotiated.
 
+ * VHOST_USER_SLAVE_FS_MAP
+
+      Id: 4
+      Equivalent ioctl: N/A
+      Slave payload: fd + n * (offset + address + len)
+      Master payload: N/A
+
+      Requests that the QEMU mmap the given fd into the virtio-fs cache;
+      multiple chunks can be mapped in one command.
+      A reply is generated indicating whether mapping succeeded.
+
+ * VHOST_USER_SLAVE_FS_UNMAP
+
+      Id: 5
+      Equivalent ioctl: N/A
+      Slave payload: n * (address + len)
+      Master payload: N/A
+
+      Requests that the QEMU un-mmap the given range in the virtio-fs cache;
+      multiple chunks can be unmapped in one command.
+      A reply is generated indicating whether unmapping succeeded.
+
+ * VHOST_USER_SLAVE_FS_SYNC
+
+      Id: 6
+      Equivalent ioctl: N/A
+      Slave payload: n * (address + len)
+      Master payload: N/A
+
+      Requests that the QEMU causes any changes to the virtio-fs cache to
+      be synchronised with the backing files.  Multiple chunks can be synced
+      in one command.
+      A reply is generated indicating whether syncing succeeded.
+      [Semantic details TBD]
+
 VHOST_USER_PROTOCOL_F_REPLY_ACK:
 -------------------------------
 The original vhost-user specification only demands replies for certain
diff --git a/hw/virtio/vhost-user-fs.c b/hw/virtio/vhost-user-fs.c
index 14ee922661..da70d9cd2c 100644
--- a/hw/virtio/vhost-user-fs.c
+++ b/hw/virtio/vhost-user-fs.c
@@ -21,6 +21,26 @@
 #include "hw/virtio/vhost-user-fs.h"
 #include "monitor/monitor.h"
 
+int vhost_user_fs_slave_map(struct vhost_dev *dev, VhostUserFSSlaveMsg *sm,
+                            int fd)
+{
+    /* TODO */
+    return -1;
+}
+
+int vhost_user_fs_slave_unmap(struct vhost_dev *dev, VhostUserFSSlaveMsg *sm)
+{
+    /* TODO */
+    return -1;
+}
+
+int vhost_user_fs_slave_sync(struct vhost_dev *dev, VhostUserFSSlaveMsg *sm)
+{
+    /* TODO */
+    return -1;
+}
+
+
 static void vuf_get_config(VirtIODevice *vdev, uint8_t *config)
 {
     VHostUserFS *fs = VHOST_USER_FS(vdev);
diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
index e09bed0e4a..beb028c7e2 100644
--- a/hw/virtio/vhost-user.c
+++ b/hw/virtio/vhost-user.c
@@ -12,6 +12,7 @@
 #include "qapi/error.h"
 #include "hw/virtio/vhost.h"
 #include "hw/virtio/vhost-user.h"
+#include "hw/virtio/vhost-user-fs.h"
 #include "hw/virtio/vhost-backend.h"
 #include "hw/virtio/virtio.h"
 #include "hw/virtio/virtio-net.h"
@@ -97,6 +98,9 @@ typedef enum VhostUserSlaveRequest {
     VHOST_USER_SLAVE_IOTLB_MSG = 1,
     VHOST_USER_SLAVE_CONFIG_CHANGE_MSG = 2,
     VHOST_USER_SLAVE_VRING_HOST_NOTIFIER_MSG = 3,
+    VHOST_USER_SLAVE_FS_MAP = 4,
+    VHOST_USER_SLAVE_FS_UNMAP = 5,
+    VHOST_USER_SLAVE_FS_SYNC = 6,
     VHOST_USER_SLAVE_MAX
 }  VhostUserSlaveRequest;
 
@@ -169,6 +173,7 @@ typedef union {
         VhostUserConfig config;
         VhostUserCryptoSession session;
         VhostUserVringArea area;
+        VhostUserFSSlaveMsg fs;
 } VhostUserPayload;
 
 typedef struct VhostUserMsg {
@@ -1010,6 +1015,17 @@ static void slave_read(void *opaque)
         ret = vhost_user_slave_handle_vring_host_notifier(dev, &payload.area,
                                                           fd[0]);
         break;
+#ifdef CONFIG_VHOST_USER_FS
+    case VHOST_USER_SLAVE_FS_MAP:
+        ret = vhost_user_fs_slave_map(dev, &payload.fs, fd[0]);
+        break;
+    case VHOST_USER_SLAVE_FS_UNMAP:
+        ret = vhost_user_fs_slave_unmap(dev, &payload.fs);
+        break;
+    case VHOST_USER_SLAVE_FS_SYNC:
+        ret = vhost_user_fs_slave_sync(dev, &payload.fs);
+        break;
+#endif
     default:
         error_report("Received unexpected msg type.");
         ret = -EINVAL;
diff --git a/include/hw/virtio/vhost-user-fs.h b/include/hw/virtio/vhost-user-fs.h
index be153e1c7a..9989bcd9e7 100644
--- a/include/hw/virtio/vhost-user-fs.h
+++ b/include/hw/virtio/vhost-user-fs.h
@@ -23,6 +23,24 @@
 #define VHOST_USER_FS(obj) \
         OBJECT_CHECK(VHostUserFS, (obj), TYPE_VHOST_USER_FS)
 
+/* Structures carried over the slave channel back to QEMU */
+#define VHOST_USER_FS_SLAVE_ENTRIES 8
+
+/* For the flags field of VhostUserFSSlaveMsg */
+#define VHOST_USER_FS_FLAG_MAP_R (1ull << 0)
+#define VHOST_USER_FS_FLAG_MAP_W (1ull << 1)
+
+typedef struct {
+    /* Offsets within the file being mapped */
+    uint64_t fd_offset[VHOST_USER_FS_SLAVE_ENTRIES];
+    /* Offsets within the cache */
+    uint64_t c_offset[VHOST_USER_FS_SLAVE_ENTRIES];
+    /* Lengths of sections */
+    uint64_t len[VHOST_USER_FS_SLAVE_ENTRIES];
+    /* Flags, from VHOST_USER_FS_FLAG_* */
+    uint64_t flags[VHOST_USER_FS_SLAVE_ENTRIES];
+} VhostUserFSSlaveMsg;
+
 typedef struct {
     CharBackend chardev;
     char *tag;
@@ -44,4 +62,10 @@ typedef struct {
     MemoryRegion cache;
 } VHostUserFS;
 
+/* Callbacks from the vhost-user code for slave commands */
+int vhost_user_fs_slave_map(struct vhost_dev *dev, VhostUserFSSlaveMsg *sm,
+                            int fd);
+int vhost_user_fs_slave_unmap(struct vhost_dev *dev, VhostUserFSSlaveMsg *sm);
+int vhost_user_fs_slave_sync(struct vhost_dev *dev, VhostUserFSSlaveMsg *sm);
+
 #endif /* _QEMU_VHOST_USER_FS_H */
-- 
2.19.2

  parent reply	other threads:[~2018-12-10 17:32 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-10 17:31 [Qemu-devel] [RFC PATCH 0/7] virtio-fs: shared file system for virtual machines3 Dr. David Alan Gilbert (git)
2018-12-10 17:31 ` [Qemu-devel] [RFC PATCH 1/7] virtio: Add shared memory capability Dr. David Alan Gilbert (git)
2018-12-10 21:03   ` Eric Blake
2018-12-11 10:24     ` Dr. David Alan Gilbert
2018-12-10 17:31 ` [Qemu-devel] [RFC PATCH 2/7] virtio: add vhost-user-fs-pci device Dr. David Alan Gilbert (git)
2018-12-10 17:31 ` [Qemu-devel] [RFC PATCH 3/7] virtio-fs: Add cache BAR Dr. David Alan Gilbert (git)
2018-12-10 21:10   ` Eric Blake
2018-12-11 10:25     ` Dr. David Alan Gilbert
2018-12-10 17:31 ` Dr. David Alan Gilbert (git) [this message]
2018-12-10 17:31 ` [Qemu-devel] [RFC PATCH 5/7] virtio-fs: Fill in slave commands for mapping Dr. David Alan Gilbert (git)
2018-12-10 17:31 ` [Qemu-devel] [RFC PATCH 6/7] virtio-fs: Allow mapping of meta data version table Dr. David Alan Gilbert (git)
2018-12-10 17:31 ` [Qemu-devel] [RFC PATCH 7/7] virtio-fs: Allow mapping of journal Dr. David Alan Gilbert (git)
2018-12-10 21:12   ` Eric Blake
2018-12-11 10:34     ` Dr. David Alan Gilbert
2018-12-10 20:26 ` [Qemu-devel] [RFC PATCH 0/7] virtio-fs: shared file system for virtual machines3 no-reply
2018-12-11 12:53 ` Stefan Hajnoczi
2018-12-12 12:30 ` Daniel P. Berrangé
2018-12-12 13:52   ` Dr. David Alan Gilbert
2018-12-12 13:58     ` Daniel P. Berrangé
2018-12-12 14:49       ` Stefan Hajnoczi
2018-12-22  9:27 ` jiangyiwen
2018-12-26 19:08   ` Vivek Goyal
2019-01-08  6:08     ` jiangyiwen
2019-04-04 13:24 ` Greg Kurz
2019-04-05  8:59   ` Dr. David Alan Gilbert
2019-04-05  8:59     ` Dr. David Alan Gilbert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181210173151.16629-5-dgilbert@redhat.com \
    --to=dgilbert@redhat.com \
    --cc=miklos@szeredi.hu \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=sweil@redhat.com \
    --cc=swhiteho@redhat.com \
    --cc=vgoyal@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).