OSDN Git Service

vhost-user: add vhost_user_requires_shm_log()
authorMarc-André Lureau <marcandre.lureau@redhat.com>
Fri, 9 Oct 2015 15:17:24 +0000 (17:17 +0200)
committerMichael S. Tsirkin <mst@redhat.com>
Thu, 22 Oct 2015 11:34:49 +0000 (14:34 +0300)
Check if the backend has VHOST_USER_PROTOCOL_F_LOG_SHMFD feature and
require a shared log.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Tested-by: Thibaut Collet <thibaut.collet@6wind.com>
hw/virtio/vhost-user.c
include/hw/virtio/vhost-backend.h

index 5d51289..e10ce87 100644 (file)
 
 #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,
@@ -458,6 +459,14 @@ static int vhost_user_memslots_limit(struct vhost_dev *dev)
     return VHOST_MEMORY_MAX_NREGIONS;
 }
 
+static bool vhost_user_requires_shm_log(struct vhost_dev *dev)
+{
+    assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_USER);
+
+    return virtio_has_feature(dev->protocol_features,
+                              VHOST_USER_PROTOCOL_F_LOG_SHMFD);
+}
+
 const VhostOps user_ops = {
         .backend_type = VHOST_BACKEND_TYPE_USER,
         .vhost_call = vhost_user_call,
@@ -467,4 +476,5 @@ const VhostOps user_ops = {
         .vhost_backend_set_vring_enable = vhost_user_set_vring_enable,
         .vhost_backend_memslots_limit = vhost_user_memslots_limit,
         .vhost_set_log_base = vhost_set_log_base,
+        .vhost_requires_shm_log = vhost_user_requires_shm_log,
 };
index c903573..c33570a 100644 (file)
@@ -11,6 +11,8 @@
 #ifndef VHOST_BACKEND_H_
 #define VHOST_BACKEND_H_
 
+#include <stdbool.h>
+
 typedef enum VhostBackendType {
     VHOST_BACKEND_TYPE_NONE = 0,
     VHOST_BACKEND_TYPE_KERNEL = 1,
@@ -29,6 +31,7 @@ typedef int (*vhost_backend_set_vring_enable)(struct vhost_dev *dev, int enable)
 typedef int (*vhost_backend_memslots_limit)(struct vhost_dev *dev);
 
 typedef int (*vhost_set_log_base_op)(struct vhost_dev *dev, uint64_t base);
+typedef bool (*vhost_requires_shm_log_op)(struct vhost_dev *dev);
 
 typedef struct VhostOps {
     VhostBackendType backend_type;
@@ -39,6 +42,7 @@ typedef struct VhostOps {
     vhost_backend_set_vring_enable vhost_backend_set_vring_enable;
     vhost_backend_memslots_limit vhost_backend_memslots_limit;
     vhost_set_log_base_op vhost_set_log_base;
+    vhost_requires_shm_log_op vhost_requires_shm_log;
 } VhostOps;
 
 extern const VhostOps user_ops;