From patchwork Mon Dec 10 17:31:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Dr. David Alan Gilbert" X-Patchwork-Id: 1010566 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43D9Nt2VStz9s3Z for ; Tue, 11 Dec 2018 04:41:34 +1100 (AEDT) Received: from localhost ([::1]:34008 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWPYh-0006Lr-NF for incoming@patchwork.ozlabs.org; Mon, 10 Dec 2018 12:41:31 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46089) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWPPZ-0006RJ-0p for qemu-devel@nongnu.org; Mon, 10 Dec 2018 12:32:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gWPPX-0003eS-Ix for qemu-devel@nongnu.org; Mon, 10 Dec 2018 12:32:04 -0500 Received: from mx1.redhat.com ([209.132.183.28]:26824) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gWPPX-0003dh-9f for qemu-devel@nongnu.org; Mon, 10 Dec 2018 12:32:03 -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 9336230224BE; Mon, 10 Dec 2018 17:32:01 +0000 (UTC) Received: from dgilbert-t530.redhat.com (unknown [10.36.118.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 39B341001914; Mon, 10 Dec 2018 17:32:00 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org Date: Mon, 10 Dec 2018 17:31:48 +0000 Message-Id: <20181210173151.16629-5-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.49]); Mon, 10 Dec 2018 17:32:01 +0000 (UTC) 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 4/7] virtio-fs: Add vhost-user slave commands for mapping 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: "Dr. David Alan Gilbert" 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 --- 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 */