qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH v4 16/22] vhost user: add rarp sending after live mi


From: marcandre . lureau
Subject: [Qemu-devel] [PATCH v4 16/22] vhost user: add rarp sending after live migration for legacy guest
Date: Sat, 19 Sep 2015 12:12:07 +0200

From: Thibaut Collet <address@hidden>

A new vhost user message is added to allow QEMU to ask to vhost user backend to
broadcast a fake RARP after live migration for guest without GUEST_ANNOUNCE
capability.

This new message is sent only if the backend supports the new
VHOST_USER_PROTOCOL_F_RARP protocol feature.
The payload of this new message is the MAC address of the guest (not known by
the backend). The MAC address is copied in the first 6 bytes of a u64 to avoid
to create a new payload message type.

This new message has no equivalent ioctl so a new callback is added in the
userOps structure to send the request.

Upon reception of this new message the vhost user backend must generate and
broadcast a fake RARP request to notify the migration is terminated.

Signed-off-by: Thibaut Collet <address@hidden>
[Rebased and fixed checkpatch errors - Marc-André]
Signed-off-by: Marc-André Lureau <address@hidden>
---
 docs/specs/vhost-user.txt         | 15 +++++++++++++++
 hw/net/vhost_net.c                | 17 +++++++++++++++++
 hw/virtio/vhost-backend.c         |  1 +
 hw/virtio/vhost-user.c            | 32 +++++++++++++++++++++++++++++++-
 include/hw/virtio/vhost-backend.h |  3 +++
 include/net/vhost_net.h           |  1 +
 net/vhost-user.c                  | 24 ++++++++++++++++++++++--
 7 files changed, 90 insertions(+), 3 deletions(-)

diff --git a/docs/specs/vhost-user.txt b/docs/specs/vhost-user.txt
index 0322bcf..118ed55 100644
--- a/docs/specs/vhost-user.txt
+++ b/docs/specs/vhost-user.txt
@@ -140,6 +140,7 @@ Protocol features
 -----------------
 
 #define VHOST_USER_PROTOCOL_F_LOG_SHMFD 0
+#define VHOST_USER_PROTOCOL_F_RARP      1
 
 Message types
 -------------
@@ -308,6 +309,20 @@ Message types
       invalid FD flag. This flag is set when there is no file descriptor
       in the ancillary data.
 
+ * VHOST_USER_SEND_RARP
+
+      Id: 17
+      Equivalent ioctl: N/A
+      Master payload: u64
+
+      Ask vhost user backend to broadcast a fake RARP to notify the migration
+      is terminated for guest that does not support GUEST_ANNOUNCE.
+      Only legal if feature bit VHOST_USER_F_PROTOCOL_FEATURES is present in
+      VHOST_USER_GET_FEATURES and protocol feature bit 
VHOST_USER_PROTOCOL_F_RARP
+      is present in VHOST_USER_GET_PROTOCOL_FEATURES.
+      The first 6 bytes of the payload contain the mac address of the guest to
+      allow the vhost user backend to construct and broadcast the fake RARP.
+
 Migration
 ---------
 
diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
index 3de171b..bae5ab9 100644
--- a/hw/net/vhost_net.c
+++ b/hw/net/vhost_net.c
@@ -379,6 +379,18 @@ void vhost_net_cleanup(struct vhost_net *net)
     g_free(net);
 }
 
+int vhost_net_notify_migration_done(struct vhost_net *net, char* mac_addr)
+{
+    const VhostOps *vhost_ops = net->dev.vhost_ops;
+    int r = -1;
+
+    if (vhost_ops->vhost_backend_migration_done) {
+        r = vhost_ops->vhost_backend_migration_done(&net->dev, mac_addr);
+    }
+
+    return r;
+}
+
 bool vhost_net_virtqueue_pending(VHostNetState *net, int idx)
 {
     return vhost_virtqueue_pending(&net->dev, idx);
@@ -452,6 +464,11 @@ void vhost_net_virtqueue_mask(VHostNetState *net, 
VirtIODevice *dev,
 {
 }
 
+int vhost_net_notify_migration_done(struct vhost_net *net)
+{
+    return -1;
+}
+
 VHostNetState *get_vhost_net(NetClientState *nc)
 {
     return 0;
diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.c
index 3f2d6ea..182f6a8 100644
--- a/hw/virtio/vhost-backend.c
+++ b/hw/virtio/vhost-backend.c
@@ -146,6 +146,7 @@ static const VhostOps kernel_ops = {
         .backend_type = VHOST_BACKEND_TYPE_KERNEL,
         .vhost_backend_init = vhost_kernel_init,
         .vhost_backend_cleanup = vhost_kernel_cleanup,
+        .vhost_backend_migration_done = NULL,
 
         .vhost_net_set_backend = vhost_net_set_backend,
         .vhost_scsi_set_endpoint = vhost_scsi_set_endpoint,
diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
index d12cd66..a6a7ab2 100644
--- a/hw/virtio/vhost-user.c
+++ b/hw/virtio/vhost-user.c
@@ -10,6 +10,7 @@
 
 #include "hw/virtio/vhost.h"
 #include "hw/virtio/vhost-backend.h"
+#include "hw/virtio/virtio-net.h"
 #include "sysemu/char.h"
 #include "sysemu/kvm.h"
 #include "qemu/error-report.h"
@@ -27,8 +28,9 @@
 
 #define VHOST_USER_F_PROTOCOL_FEATURES 30
 
-#define VHOST_USER_PROTOCOL_FEATURE_MASK 0x1ULL
+#define VHOST_USER_PROTOCOL_FEATURE_MASK 0x3ULL
 #define VHOST_USER_PROTOCOL_F_LOG_SHMFD 0
+#define VHOST_USER_PROTOCOL_F_RARP      1
 
 typedef enum VhostUserRequest {
     VHOST_USER_NONE = 0,
@@ -48,6 +50,7 @@ typedef enum VhostUserRequest {
     VHOST_USER_SET_VRING_ERR = 14,
     VHOST_USER_GET_PROTOCOL_FEATURES = 15,
     VHOST_USER_SET_PROTOCOL_FEATURES = 16,
+    VHOST_USER_SEND_RARP = 17,
     VHOST_USER_MAX
 } VhostUserRequest;
 
@@ -516,11 +519,38 @@ static bool vhost_user_want_shm_log(struct vhost_dev *dev)
                               VHOST_USER_PROTOCOL_F_LOG_SHMFD);
 }
 
+static int vhost_user_migration_done(struct vhost_dev *dev, char* mac_addr)
+{
+    VhostUserMsg msg = { 0 };
+    int err;
+
+    assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_USER);
+
+    /* If guest supports GUEST_ANNOUNCE do nothing */
+    if (virtio_has_feature(dev->acked_features, VIRTIO_NET_F_GUEST_ANNOUNCE)) {
+        return 0;
+    }
+
+    /* if backend supports VHOST_USER_PROTOCOL_F_RARP ask it to send the RARP 
*/
+    if (virtio_has_feature(dev->protocol_features,
+                           VHOST_USER_PROTOCOL_F_RARP)) {
+        msg.request = VHOST_USER_SEND_RARP;
+        msg.flags = VHOST_USER_VERSION;
+        memcpy((char *)&msg.u64, mac_addr, 6);
+        msg.size = sizeof(m.u64);
+
+        err = vhost_user_write(dev, &msg, NULL, 0);
+        return err;
+    }
+    return -1;
+}
+
 const VhostOps user_ops = {
         .backend_type = VHOST_BACKEND_TYPE_USER,
         .vhost_backend_init = vhost_user_init,
         .vhost_backend_cleanup = vhost_user_cleanup,
         .vhost_backend_want_shm_log = vhost_user_want_shm_log,
+        .vhost_backend_migration_done = vhost_user_migration_done,
 
         .vhost_net_set_backend = vhost_net_set_backend,
         .vhost_scsi_set_endpoint = vhost_scsi_set_endpoint,
diff --git a/include/hw/virtio/vhost-backend.h 
b/include/hw/virtio/vhost-backend.h
index 44bf200..0c75ed6 100644
--- a/include/hw/virtio/vhost-backend.h
+++ b/include/hw/virtio/vhost-backend.h
@@ -31,6 +31,8 @@ struct vhost_scsi_target;
 typedef int (*vhost_backend_init)(struct vhost_dev *dev, void *opaque);
 typedef int (*vhost_backend_cleanup)(struct vhost_dev *dev);
 typedef bool (*vhost_backend_want_shm_log)(struct vhost_dev *dev);
+typedef int (*vhost_backend_migration_done)(struct vhost_dev *dev,
+                                            char *mac_addr);
 
 typedef int (*vhost_net_set_backend_op)(struct vhost_dev *dev,
                                         struct vhost_vring_file *file);
@@ -71,6 +73,7 @@ typedef struct VhostOps {
     vhost_backend_init vhost_backend_init;
     vhost_backend_cleanup vhost_backend_cleanup;
     vhost_backend_want_shm_log vhost_backend_want_shm_log;
+    vhost_backend_migration_done vhost_backend_migration_done;
 
     vhost_net_set_backend_op vhost_net_set_backend;
     vhost_scsi_set_endpoint_op vhost_scsi_set_endpoint;
diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h
index 840d4b1..8e5dfd4 100644
--- a/include/net/vhost_net.h
+++ b/include/net/vhost_net.h
@@ -26,5 +26,6 @@ void vhost_net_ack_features(VHostNetState *net, uint64_t 
features);
 bool vhost_net_virtqueue_pending(VHostNetState *net, int n);
 void vhost_net_virtqueue_mask(VHostNetState *net, VirtIODevice *dev,
                               int idx, bool mask);
+int vhost_net_notify_migration_done(VHostNetState *net, char* mac_addr);
 VHostNetState *get_vhost_net(NetClientState *nc);
 #endif
diff --git a/net/vhost-user.c b/net/vhost-user.c
index 555d80f..3c1b01c 100644
--- a/net/vhost-user.c
+++ b/net/vhost-user.c
@@ -69,9 +69,29 @@ static void vhost_user_stop(VhostUserState *s)
 static ssize_t vhost_user_receive(NetClientState *nc, const uint8_t *buf,
                                   size_t size)
 {
-    /* Discard the request that is received and managed by backend
-     * by an other way.
+    /* In case of RARP (message size is 60) notify backup to send a fake RARP.
+       This fake RARP will be sent by backend only for guest
+       without GUEST_ANNOUNCE capability.
      */
+    if (size == 60) {
+        VhostUserState *s = DO_UPCAST(VhostUserState, nc, nc);
+        int r;
+        static int display_rarp_failure = 1;
+        char mac_addr[6];
+
+        /* extract guest mac address from the RARP message */
+        memcpy(mac_addr, &buf[6], 6);
+
+        r = vhost_net_notify_migration_done(s->vhost_net, mac_addr);
+
+        if ((r != 0) && (display_rarp_failure)) {
+            fprintf(stderr,
+                    "Vhost user backend fails to broadcast fake RARP\n");
+            fflush(stderr);
+            display_rarp_failure = 0;
+        }
+    }
+
     return size;
 }
 
-- 
2.4.3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]