[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v5 08/21] vhost-user: send log shm fd along with log
From: |
marcandre . lureau |
Subject: |
[Qemu-devel] [PATCH v5 08/21] vhost-user: send log shm fd along with log_base |
Date: |
Thu, 24 Sep 2015 18:22:08 +0200 |
From: Marc-André Lureau <address@hidden>
Send the shm for the dirty pages logging if the backend supports
VHOST_USER_PROTOCOL_F_LOG_SHMFD. Wait for a reply to make sure
the old log is no longer used.
Signed-off-by: Marc-André Lureau <address@hidden>
---
hw/virtio/vhost-backend.c | 3 ++-
hw/virtio/vhost-user.c | 32 ++++++++++++++++++++++++++++----
hw/virtio/vhost.c | 5 +++--
include/hw/virtio/vhost-backend.h | 4 +++-
4 files changed, 36 insertions(+), 8 deletions(-)
diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.c
index 88d33fd..87ab028 100644
--- a/hw/virtio/vhost-backend.c
+++ b/hw/virtio/vhost-backend.c
@@ -50,7 +50,8 @@ static int vhost_kernel_get_vq_index(struct vhost_dev *dev,
int idx)
return idx - dev->vq_index;
}
-static int vhost_set_log_base(struct vhost_dev *dev, uint64_t base)
+static int vhost_set_log_base(struct vhost_dev *dev, uint64_t base,
+ struct vhost_log *log)
{
return vhost_kernel_call(dev, VHOST_SET_LOG_BASE, &base);
}
diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
index fd4fcbf..6420efd 100644
--- a/hw/virtio/vhost-user.c
+++ b/hw/virtio/vhost-user.c
@@ -25,9 +25,10 @@
#define VHOST_MEMORY_MAX_NREGIONS 8
#define VHOST_USER_F_PROTOCOL_FEATURES 30
-#define VHOST_USER_PROTOCOL_FEATURE_MASK 0x1ULL
-#define VHOST_USER_PROTOCOL_F_MQ 0
+#define VHOST_USER_PROTOCOL_FEATURE_MASK 0x3ULL
+#define VHOST_USER_PROTOCOL_F_MQ 0
+#define VHOST_USER_PROTOCOL_F_LOG_SHMFD 1
typedef enum VhostUserRequest {
VHOST_USER_NONE = 0,
@@ -366,8 +367,13 @@ static int vhost_user_call(struct vhost_dev *dev, unsigned
long int request,
return 0;
}
-static int vhost_set_log_base(struct vhost_dev *dev, uint64_t base)
+static int vhost_set_log_base(struct vhost_dev *dev, uint64_t base,
+ struct vhost_log *log)
{
+ int fds[VHOST_MEMORY_MAX_NREGIONS];
+ size_t fd_num = 0;
+ bool shmfd = virtio_has_feature(dev->protocol_features,
+ VHOST_USER_PROTOCOL_F_LOG_SHMFD);
VhostUserMsg msg = {
.request = VHOST_USER_SET_LOG_BASE,
.flags = VHOST_USER_VERSION,
@@ -375,7 +381,25 @@ static int vhost_set_log_base(struct vhost_dev *dev,
uint64_t base)
.size = sizeof(m.u64),
};
- vhost_user_write(dev, &msg, NULL, 0);
+ if (shmfd && log->fd != -1) {
+ fds[fd_num++] = log->fd;
+ }
+
+ vhost_user_write(dev, &msg, fds, fd_num);
+
+ if (shmfd) {
+ msg.size = 0;
+ if (vhost_user_read(dev, &msg) < 0) {
+ return 0;
+ }
+
+ if (msg.request != VHOST_USER_SET_LOG_BASE) {
+ error_report("Received unexpected msg type. "
+ "Expected %d received %d",
+ VHOST_USER_SET_LOG_BASE, msg.request);
+ return -1;
+ }
+ }
return 0;
}
diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
index 7f01cd6..9b73f83 100644
--- a/hw/virtio/vhost.c
+++ b/hw/virtio/vhost.c
@@ -366,7 +366,7 @@ static inline void vhost_dev_log_resize(struct vhost_dev*
dev, uint64_t size)
/* inform backend of log switching, this must be done before
releasing the current log, to ensure no logging is lost */
- r = dev->vhost_ops->vhost_set_log_base(dev, log_base);
+ r = dev->vhost_ops->vhost_set_log_base(dev, log_base, log);
assert(r >= 0);
vhost_log_put(dev, true);
dev->log = log;
@@ -1172,7 +1172,8 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice
*vdev)
hdev->log = vhost_log_get(hdev->log_size, share);
log_base = (uintptr_t)hdev->log->log;
r = hdev->vhost_ops->vhost_set_log_base(hdev,
- hdev->log_size ? log_base : 0);
+ hdev->log_size ? log_base : 0,
+ hdev->log);
if (r < 0) {
r = -errno;
goto fail_log;
diff --git a/include/hw/virtio/vhost-backend.h
b/include/hw/virtio/vhost-backend.h
index c6b688a..485279b 100644
--- a/include/hw/virtio/vhost-backend.h
+++ b/include/hw/virtio/vhost-backend.h
@@ -19,6 +19,7 @@ typedef enum VhostBackendType {
} VhostBackendType;
struct vhost_dev;
+struct vhost_log;
typedef int (*vhost_call)(struct vhost_dev *dev, unsigned long int request,
void *arg);
@@ -27,7 +28,8 @@ typedef int (*vhost_backend_cleanup)(struct vhost_dev *dev);
typedef int (*vhost_backend_get_vq_index)(struct vhost_dev *dev, int idx);
typedef int (*vhost_backend_set_vring_enable)(struct vhost_dev *dev, int
enable);
-typedef int (*vhost_set_log_base_op)(struct vhost_dev *dev, uint64_t base);
+typedef int (*vhost_set_log_base_op)(struct vhost_dev *dev, uint64_t base,
+ struct vhost_log *log);
typedef struct VhostOps {
VhostBackendType backend_type;
--
2.4.3
- [Qemu-devel] [PATCH v5 00/21] vhost-user: add migration support, marcandre . lureau, 2015/09/24
- [Qemu-devel] [PATCH v5 01/21] vhost-user: unit test for new messages, marcandre . lureau, 2015/09/24
- [Qemu-devel] [PATCH v5 02/21] configure: probe for memfd, marcandre . lureau, 2015/09/24
- [Qemu-devel] [PATCH v5 03/21] util: add linux-only memfd fallback, marcandre . lureau, 2015/09/24
- [Qemu-devel] [PATCH v5 04/21] util: add memfd helpers, marcandre . lureau, 2015/09/24
- [Qemu-devel] [PATCH v5 05/21] vhost: alloc shareable log, marcandre . lureau, 2015/09/24
- [Qemu-devel] [PATCH v5 06/21] vhost: document log resizing, marcandre . lureau, 2015/09/24
- [Qemu-devel] [PATCH v5 07/21] vhost: add vhost_set_log_base op, marcandre . lureau, 2015/09/24
- [Qemu-devel] [PATCH v5 09/21] vhost-user: add a migration blocker, marcandre . lureau, 2015/09/24
- [Qemu-devel] [PATCH v5 08/21] vhost-user: send log shm fd along with log_base,
marcandre . lureau <=
- [Qemu-devel] [PATCH v5 11/21] vhost: only use shared log if in use by backend, marcandre . lureau, 2015/09/24
- [Qemu-devel] [PATCH v5 12/21] vhost-user: document migration log, marcandre . lureau, 2015/09/24
- [Qemu-devel] [PATCH v5 13/21] net: add trace_vhost_user_event, marcandre . lureau, 2015/09/24
- [Qemu-devel] [PATCH v5 10/21] vhost: use a function for each call, marcandre . lureau, 2015/09/24
- [Qemu-devel] [PATCH v5 14/21] vhost user: add support of live migration, marcandre . lureau, 2015/09/24
- [Qemu-devel] [PATCH v5 16/21] vhost-user-test: move wait_for_fds() out, marcandre . lureau, 2015/09/24
- [Qemu-devel] [PATCH v5 15/21] vhost user: add rarp sending after live migration for legacy guest, marcandre . lureau, 2015/09/24