qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: marcandre.lureau@redhat.com
To: qemu-devel@nongnu.org
Cc: thibaut.collet@6wind.com, jasowang@redhat.com, mst@redhat.com,
	haifeng.lin@huawei.com, pbonzini@redhat.com
Subject: [Qemu-devel] [PATCH v4 01/22] vhost-user: refactor ioctl translation
Date: Sat, 19 Sep 2015 12:11:52 +0200	[thread overview]
Message-ID: <1442657533-13030-2-git-send-email-marcandre.lureau@redhat.com> (raw)
In-Reply-To: <1442657533-13030-1-git-send-email-marcandre.lureau@redhat.com>

From: "Michael S. Tsirkin" <mst@redhat.com>

translate at the outset, have rest of code use vhost-user features
exclusively.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/virtio/vhost-user.c | 87 ++++++++++++++++++++++++++------------------------
 1 file changed, 46 insertions(+), 41 deletions(-)

diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
index e7ab829..5a83d00 100644
--- a/hw/virtio/vhost-user.c
+++ b/hw/virtio/vhost-user.c
@@ -89,35 +89,40 @@ static bool ioeventfd_enabled(void)
     return kvm_enabled() && kvm_eventfds_enabled();
 }
 
-static unsigned long int ioctl_to_vhost_user_request[VHOST_USER_MAX] = {
-    -1,                     /* VHOST_USER_NONE */
-    VHOST_GET_FEATURES,     /* VHOST_USER_GET_FEATURES */
-    VHOST_SET_FEATURES,     /* VHOST_USER_SET_FEATURES */
-    VHOST_SET_OWNER,        /* VHOST_USER_SET_OWNER */
-    VHOST_RESET_OWNER,      /* VHOST_USER_RESET_OWNER */
-    VHOST_SET_MEM_TABLE,    /* VHOST_USER_SET_MEM_TABLE */
-    VHOST_SET_LOG_BASE,     /* VHOST_USER_SET_LOG_BASE */
-    VHOST_SET_LOG_FD,       /* VHOST_USER_SET_LOG_FD */
-    VHOST_SET_VRING_NUM,    /* VHOST_USER_SET_VRING_NUM */
-    VHOST_SET_VRING_ADDR,   /* VHOST_USER_SET_VRING_ADDR */
-    VHOST_SET_VRING_BASE,   /* VHOST_USER_SET_VRING_BASE */
-    VHOST_GET_VRING_BASE,   /* VHOST_USER_GET_VRING_BASE */
-    VHOST_SET_VRING_KICK,   /* VHOST_USER_SET_VRING_KICK */
-    VHOST_SET_VRING_CALL,   /* VHOST_USER_SET_VRING_CALL */
-    VHOST_SET_VRING_ERR     /* VHOST_USER_SET_VRING_ERR */
-};
-
 static VhostUserRequest vhost_user_request_translate(unsigned long int request)
 {
-    VhostUserRequest idx;
-
-    for (idx = 0; idx < VHOST_USER_MAX; idx++) {
-        if (ioctl_to_vhost_user_request[idx] == request) {
-            break;
-        }
+    switch (request) {
+    case VHOST_GET_FEATURES:
+        return VHOST_USER_GET_FEATURES;
+    case VHOST_SET_FEATURES:
+        return VHOST_USER_SET_FEATURES;
+    case VHOST_SET_OWNER:
+        return VHOST_USER_SET_OWNER;
+    case VHOST_RESET_OWNER:
+        return VHOST_USER_RESET_OWNER;
+    case VHOST_SET_MEM_TABLE:
+        return VHOST_USER_SET_MEM_TABLE;
+    case VHOST_SET_LOG_BASE:
+        return VHOST_USER_SET_LOG_BASE;
+    case VHOST_SET_LOG_FD:
+        return VHOST_USER_SET_LOG_FD;
+    case VHOST_SET_VRING_NUM:
+        return VHOST_USER_SET_VRING_NUM;
+    case VHOST_SET_VRING_ADDR:
+        return VHOST_USER_SET_VRING_ADDR;
+    case VHOST_SET_VRING_BASE:
+        return VHOST_USER_SET_VRING_BASE;
+    case VHOST_GET_VRING_BASE:
+        return VHOST_USER_GET_VRING_BASE;
+    case VHOST_SET_VRING_KICK:
+        return VHOST_USER_SET_VRING_KICK;
+    case VHOST_SET_VRING_CALL:
+        return VHOST_USER_SET_VRING_CALL;
+    case VHOST_SET_VRING_ERR:
+        return VHOST_USER_SET_VRING_ERR;
+    default:
+        return VHOST_USER_MAX;
     }
-
-    return (idx == VHOST_USER_MAX) ? VHOST_USER_NONE : idx;
 }
 
 static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg)
@@ -198,22 +203,22 @@ static int vhost_user_call(struct vhost_dev *dev, unsigned long int request,
     msg.flags = VHOST_USER_VERSION;
     msg.size = 0;
 
-    switch (request) {
-    case VHOST_GET_FEATURES:
+    switch (msg_request) {
+    case VHOST_USER_GET_FEATURES:
         need_reply = 1;
         break;
 
-    case VHOST_SET_FEATURES:
-    case VHOST_SET_LOG_BASE:
+    case VHOST_USER_SET_FEATURES:
+    case VHOST_USER_SET_LOG_BASE:
         msg.u64 = *((__u64 *) arg);
         msg.size = sizeof(m.u64);
         break;
 
-    case VHOST_SET_OWNER:
-    case VHOST_RESET_OWNER:
+    case VHOST_USER_SET_OWNER:
+    case VHOST_USER_RESET_OWNER:
         break;
 
-    case VHOST_SET_MEM_TABLE:
+    case VHOST_USER_SET_MEM_TABLE:
         for (i = 0; i < dev->mem->nregions; ++i) {
             struct vhost_memory_region *reg = dev->mem->regions + i;
             ram_addr_t ram_addr;
@@ -246,30 +251,30 @@ static int vhost_user_call(struct vhost_dev *dev, unsigned long int request,
 
         break;
 
-    case VHOST_SET_LOG_FD:
+    case VHOST_USER_SET_LOG_FD:
         fds[fd_num++] = *((int *) arg);
         break;
 
-    case VHOST_SET_VRING_NUM:
-    case VHOST_SET_VRING_BASE:
+    case VHOST_USER_SET_VRING_NUM:
+    case VHOST_USER_SET_VRING_BASE:
         memcpy(&msg.state, arg, sizeof(struct vhost_vring_state));
         msg.size = sizeof(m.state);
         break;
 
-    case VHOST_GET_VRING_BASE:
+    case VHOST_USER_GET_VRING_BASE:
         memcpy(&msg.state, arg, sizeof(struct vhost_vring_state));
         msg.size = sizeof(m.state);
         need_reply = 1;
         break;
 
-    case VHOST_SET_VRING_ADDR:
+    case VHOST_USER_SET_VRING_ADDR:
         memcpy(&msg.addr, arg, sizeof(struct vhost_vring_addr));
         msg.size = sizeof(m.addr);
         break;
 
-    case VHOST_SET_VRING_KICK:
-    case VHOST_SET_VRING_CALL:
-    case VHOST_SET_VRING_ERR:
+    case VHOST_USER_SET_VRING_KICK:
+    case VHOST_USER_SET_VRING_CALL:
+    case VHOST_USER_SET_VRING_ERR:
         file = arg;
         msg.u64 = file->index & VHOST_USER_VRING_IDX_MASK;
         msg.size = sizeof(m.u64);
-- 
2.4.3

  reply	other threads:[~2015-09-19 10:12 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-19 10:11 [Qemu-devel] [PATCH v4 00/22] vhost-user: add migration support marcandre.lureau
2015-09-19 10:11 ` marcandre.lureau [this message]
2015-09-19 10:11 ` [Qemu-devel] [PATCH v4 02/22] vhost-user: add protocol feature negotiation marcandre.lureau
2015-09-19 10:11 ` [Qemu-devel] [PATCH v4 03/22] vhost-user: unit test for new messages marcandre.lureau
2015-09-19 10:11 ` [Qemu-devel] [PATCH v4 04/22] configure: probe for memfd marcandre.lureau
2015-09-19 10:11 ` [Qemu-devel] [PATCH v4 05/22] util: add linux-only memfd fallback marcandre.lureau
2015-09-19 10:11 ` [Qemu-devel] [PATCH v4 06/22] util: add memfd helpers marcandre.lureau
2015-09-19 10:11 ` [Qemu-devel] [PATCH v4 07/22] vhost: alloc shareable log marcandre.lureau
2015-09-21  8:44   ` Michael S. Tsirkin
2015-09-21 14:02     ` Marc-André Lureau
2015-09-21 19:29       ` Michael S. Tsirkin
2015-09-21 21:44         ` Marc-André Lureau
2015-09-22 10:12           ` Michael S. Tsirkin
2015-09-22 11:01             ` Marc-André Lureau
2015-09-22 11:41               ` Michael S. Tsirkin
2015-09-22 11:50                 ` Marc-André Lureau
2015-09-22 11:54                   ` Michael S. Tsirkin
2015-09-19 10:11 ` [Qemu-devel] [PATCH v4 08/22] vhost: document log resizing marcandre.lureau
2015-09-19 10:12 ` [Qemu-devel] [PATCH v4 09/22] vhost: use a function for each call marcandre.lureau
2015-09-21  7:33   ` Thibaut Collet
2015-09-21  8:56     ` Michael S. Tsirkin
2015-09-21  8:58   ` Michael S. Tsirkin
2015-09-21 14:05     ` Marc-André Lureau
2015-09-19 10:12 ` [Qemu-devel] [PATCH v4 10/22] vhost-user: remove vhost_user_request_translate() marcandre.lureau
2015-09-19 10:12 ` [Qemu-devel] [PATCH v4 11/22] vhost-user: send log shm fd along with log_base marcandre.lureau
2015-09-21  8:49   ` Michael S. Tsirkin
2015-09-21 14:05     ` Marc-André Lureau
2015-09-21 19:30       ` Michael S. Tsirkin
2015-09-19 10:12 ` [Qemu-devel] [PATCH v4 12/22] vhost: only use shared log if in use by backend marcandre.lureau
2015-09-21  8:46   ` Michael S. Tsirkin
2015-09-21 14:03     ` Marc-André Lureau
2015-09-19 10:12 ` [Qemu-devel] [PATCH v4 13/22] vhost-user: document migration log marcandre.lureau
2015-09-19 10:12 ` [Qemu-devel] [PATCH v4 14/22] net: add trace_vhost_user_event marcandre.lureau
2015-09-19 10:12 ` [Qemu-devel] [PATCH v4 15/22] vhost user: add support of live migration marcandre.lureau
2015-09-19 10:12 ` [Qemu-devel] [PATCH v4 16/22] vhost user: add rarp sending after live migration for legacy guest marcandre.lureau
2015-09-19 10:12 ` [Qemu-devel] [PATCH v4 17/22] vhost-user-test: move wait_for_fds() out marcandre.lureau
2015-09-19 10:12 ` [Qemu-devel] [PATCH v4 18/22] vhost-user-test: remove useless static check marcandre.lureau
2015-09-19 10:12 ` [Qemu-devel] [PATCH v4 19/22] vhost-user-test: wrap server in TestServer struct marcandre.lureau
2015-09-19 10:12 ` [Qemu-devel] [PATCH v4 20/22] vhost-user-test: learn to tweak various qemu arguments marcandre.lureau
2015-09-19 10:12 ` [Qemu-devel] [PATCH v4 21/22] vhost-user-test: add live-migration test marcandre.lureau
2015-09-19 10:12 ` [Qemu-devel] [PATCH v4 22/22] vhost-user-test: check ownership during migration marcandre.lureau

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=1442657533-13030-2-git-send-email-marcandre.lureau@redhat.com \
    --to=marcandre.lureau@redhat.com \
    --cc=haifeng.lin@huawei.com \
    --cc=jasowang@redhat.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=thibaut.collet@6wind.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).