All of lore.kernel.org
 help / color / mirror / Atom feed
From: marcandre.lureau@redhat.com
To: qemu-devel@nongnu.org
Cc: "Yuanhan Liu" <yuanhan.liu@linux.intel.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Ilya Maximets" <i.maximets@samsung.com>,
	jonshin@cisco.com, "Tetsuya Mukawa" <mukawa@igel.co.jp>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: [Qemu-devel] [PATCH 18/18] test: add shutdown support vubr test
Date: Fri,  1 Apr 2016 13:16:28 +0200	[thread overview]
Message-ID: <1459509388-6185-19-git-send-email-marcandre.lureau@redhat.com> (raw)
In-Reply-To: <1459509388-6185-1-git-send-email-marcandre.lureau@redhat.com>

From: Marc-André Lureau <marcandre.lureau@redhat.com>

The bridge can now be interrupted with ctrl-c. Once the slave channel is
up, it will request a shutdown, and wait for success reply to exit.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 tests/vhost-user-bridge.c | 102 ++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 99 insertions(+), 3 deletions(-)

diff --git a/tests/vhost-user-bridge.c b/tests/vhost-user-bridge.c
index 42450a6..ea123be 100644
--- a/tests/vhost-user-bridge.c
+++ b/tests/vhost-user-bridge.c
@@ -135,6 +135,9 @@ dispatcher_wait(Dispatcher *dispr, uint32_t timeout)
     int rc = select(dispr->max_sock + 1, &fdset, 0, 0, &tv);
 
     if (rc == -1) {
+        if (errno == EINTR) {
+            return 0;
+        }
         vubr_die("select");
     }
 
@@ -186,6 +189,7 @@ enum VhostUserProtocolFeature {
     VHOST_USER_PROTOCOL_F_MQ = 0,
     VHOST_USER_PROTOCOL_F_LOG_SHMFD = 1,
     VHOST_USER_PROTOCOL_F_RARP = 2,
+    VHOST_USER_PROTOCOL_F_SLAVE_CHANNEL = 3,
 
     VHOST_USER_PROTOCOL_F_MAX
 };
@@ -213,9 +217,16 @@ typedef enum VhostUserRequest {
     VHOST_USER_GET_QUEUE_NUM = 17,
     VHOST_USER_SET_VRING_ENABLE = 18,
     VHOST_USER_SEND_RARP = 19,
+    VHOST_USER_SET_SLAVE_FD = 20,
     VHOST_USER_MAX
 } VhostUserRequest;
 
+typedef enum VhostUserSlaveRequest {
+    VHOST_USER_SLAVE_NONE = 0,
+    VHOST_USER_SLAVE_SHUTDOWN = 1,
+    VHOST_USER_SLAVE_MAX
+} VhostUserSlaveRequest;
+
 typedef struct VhostUserMemoryRegion {
     uint64_t guest_phys_addr;
     uint64_t memory_size;
@@ -288,6 +299,8 @@ typedef struct VubrDev {
     int ready;
     uint64_t features;
     int hdrlen;
+    int slave_fd;
+    bool shutdown_requested;
 } VubrDev;
 
 static const char *vubr_request_str[] = {
@@ -311,7 +324,14 @@ static const char *vubr_request_str[] = {
     [VHOST_USER_GET_QUEUE_NUM]          =  "VHOST_USER_GET_QUEUE_NUM",
     [VHOST_USER_SET_VRING_ENABLE]       =  "VHOST_USER_SET_VRING_ENABLE",
     [VHOST_USER_SEND_RARP]              =  "VHOST_USER_SEND_RARP",
-    [VHOST_USER_MAX]                    =  "VHOST_USER_MAX",
+    [VHOST_USER_SET_SLAVE_FD]           =  "VHOST_USER_SET_SLAVE_FD",
+    [VHOST_USER_MAX]                    =  "VHOST_USER_MAX"
+};
+
+static const char *vubr_slave_request_str[] = {
+    [VHOST_USER_SLAVE_NONE]             =  "VHOST_USER_SLAVE_NONE",
+    [VHOST_USER_SLAVE_SHUTDOWN]         =  "VHOST_USER_SLAVE_SHUTDOWN",
+    [VHOST_USER_SLAVE_MAX]              =  "VHOST_USER_SLAVE_MAX"
 };
 
 static void
@@ -638,7 +658,7 @@ vubr_process_desc(VubrDev *dev, VubrVirtq *vq)
     size_t buf_size = 4096;
     uint8_t buf[4096];
 
-    DPRINT("Chunks: ");
+    DPRINT("Chunks: aidx:%d   ", a_index);
     i = d_index;
     do {
         void *chunk_start = (void *)(uintptr_t)gpa_to_va(dev, desc[i].addr);
@@ -1063,7 +1083,9 @@ vubr_set_vring_err_exec(VubrDev *dev, VhostUserMsg *vmsg)
 static int
 vubr_get_protocol_features_exec(VubrDev *dev, VhostUserMsg *vmsg)
 {
-    vmsg->payload.u64 = 1ULL << VHOST_USER_PROTOCOL_F_LOG_SHMFD;
+    vmsg->payload.u64 =
+        1ULL << VHOST_USER_PROTOCOL_F_LOG_SHMFD |
+        1ULL << VHOST_USER_PROTOCOL_F_SLAVE_CHANNEL;
     DPRINT("u64: 0x%016"PRIx64"\n", vmsg->payload.u64);
     vmsg->size = sizeof(vmsg->payload.u64);
 
@@ -1105,6 +1127,46 @@ vubr_send_rarp_exec(VubrDev *dev, VhostUserMsg *vmsg)
     return 0;
 }
 
+static void
+vubr_handle_slave_reply(VhostUserMsg *vmsg)
+{
+    DPRINT(
+        "==================   Vhost slave reply from QEMU   ==================\n");
+    DPRINT("Request: %s (%d)\n", vubr_slave_request_str[vmsg->request],
+           vmsg->request);
+    DPRINT("Flags:   0x%x\n", vmsg->flags);
+    DPRINT("Size:    %d\n", vmsg->size);
+
+    switch (vmsg->request) {
+    case VHOST_USER_SLAVE_SHUTDOWN:
+        DPRINT("Shutdown success: 0x%016"PRIx64"\n", vmsg->payload.u64);
+        if (vmsg->payload.u64 == 0) {
+            exit(0);
+        }
+    default:
+        DPRINT("Invalid slave reply");
+    };
+}
+
+static void
+slave_receive_cb(int sock, void *ctx)
+{
+    VhostUserMsg vmsg;
+
+    vubr_message_read(sock, &vmsg);
+    vubr_handle_slave_reply(&vmsg);
+}
+
+static int
+vubr_set_slave_fd_exec(VubrDev *dev, VhostUserMsg *vmsg)
+{
+    assert(vmsg->fd_num == 1);
+    dev->slave_fd = vmsg->fds[0];
+    DPRINT("Got slave_fd: %d\n", vmsg->fds[0]);
+    dispatcher_add(&dev->dispatcher, dev->slave_fd, dev, slave_receive_cb);
+    return 0;
+}
+
 static int
 vubr_execute_request(VubrDev *dev, VhostUserMsg *vmsg)
 {
@@ -1166,6 +1228,8 @@ vubr_execute_request(VubrDev *dev, VhostUserMsg *vmsg)
         return vubr_set_vring_enable_exec(dev, vmsg);
     case VHOST_USER_SEND_RARP:
         return vubr_send_rarp_exec(dev, vmsg);
+    case VHOST_USER_SET_SLAVE_FD:
+        return vubr_set_slave_fd_exec(dev, vmsg);
 
     case VHOST_USER_MAX:
         assert(vmsg->request != VHOST_USER_MAX);
@@ -1226,6 +1290,7 @@ vubr_new(const char *path)
         };
     }
 
+    dev->slave_fd = -1;
     /* Init log */
     dev->log_call_fd = -1;
     dev->log_size = 0;
@@ -1333,12 +1398,42 @@ vubr_backend_udp_setup(VubrDev *dev,
 }
 
 static void
+vubr_request_shutdown(VubrDev *dev)
+{
+    VhostUserMsg vmsg = {
+        .request = VHOST_USER_SLAVE_SHUTDOWN,
+        .flags = VHOST_USER_VERSION
+    };
+
+    DPRINT("requesting shutdown\n");
+    vubr_message_write(dev->slave_fd, &vmsg);
+}
+
+static volatile int interrupted;
+
+static void interrupt_handler(int dummy)
+{
+    interrupted = 1;
+}
+
+static void
 vubr_run(VubrDev *dev)
 {
     while (1) {
         /* timeout 200ms */
         dispatcher_wait(&dev->dispatcher, 200000);
         /* Here one can try polling strategy. */
+
+        if (interrupted) {
+            if (dev->slave_fd == -1) {
+                return;
+            }
+
+            if (!dev->shutdown_requested) {
+                vubr_request_shutdown(dev);
+                dev->shutdown_requested = 1;
+            }
+        }
     }
 }
 
@@ -1405,6 +1500,7 @@ main(int argc, char *argv[])
     }
 
     vubr_backend_udp_setup(dev, lhost, lport, rhost, rport);
+    signal(SIGINT, interrupt_handler);
     vubr_run(dev);
     return 0;
 
-- 
2.5.5

  parent reply	other threads:[~2016-04-01 11:17 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-01 11:16 [Qemu-devel] [PATCH 00/18] RFCv2: vhost-user: shutdown and reconnection marcandre.lureau
2016-04-01 11:16 ` [Qemu-devel] [PATCH 01/18] tests: append i386 tests marcandre.lureau
2016-04-01 20:30   ` [Qemu-devel] [PATCH 01/18 for-2.6] " Eric Blake
2016-04-01 11:16 ` [Qemu-devel] [PATCH 02/18] char: lower reconnect error to trace event marcandre.lureau
2016-04-01 11:16 ` [Qemu-devel] [PATCH 03/18] char: use a trace for when the char is waiting marcandre.lureau
2016-04-01 11:16 ` [Qemu-devel] [PATCH 04/18] char: add wait support for reconnect marcandre.lureau
2016-04-28  4:33   ` Yuanhan Liu
2016-04-01 11:16 ` [Qemu-devel] [PATCH 05/18] vhost-user: check reconnect comes with wait marcandre.lureau
2016-04-01 11:16 ` [Qemu-devel] [PATCH 06/18] vhost-user: add ability to know vhost-user backend disconnection marcandre.lureau
2016-04-01 11:16 ` [Qemu-devel] [PATCH 07/18] vhost: add vhost_dev stop callback marcandre.lureau
2016-04-01 11:16 ` [Qemu-devel] [PATCH 08/18] vhost-user: add vhost_user to hold the chr marcandre.lureau
2016-04-01 11:16 ` [Qemu-devel] [PATCH 09/18] qemu-char: add qemu_chr_disconnect to close a fd accepted by listen fd marcandre.lureau
2016-04-01 11:16 ` [Qemu-devel] [PATCH 10/18] vhost-user: add slave-fd support marcandre.lureau
2016-04-01 20:33   ` Eric Blake
2016-04-01 11:16 ` [Qemu-devel] [PATCH 11/18] vhost-user: add shutdown support marcandre.lureau
2016-04-13  2:49   ` Yuanhan Liu
2016-04-13  9:51     ` Marc-André Lureau
2016-04-13 17:32       ` Yuanhan Liu
2016-04-13 21:43         ` Marc-André Lureau
2016-04-13 21:57           ` Yuanhan Liu
2016-04-28  5:23   ` Yuanhan Liu
2016-04-29 10:40     ` Marc-André Lureau
2016-04-29 17:48       ` Yuanhan Liu
2016-05-01 11:37         ` Michael S. Tsirkin
2016-05-01 21:04           ` Yuanhan Liu
2016-05-02 10:45             ` Michael S. Tsirkin
2016-05-02 11:29               ` Marc-André Lureau
2016-05-02 12:04                 ` Michael S. Tsirkin
2016-05-02 17:50                   ` Yuanhan Liu
2016-05-04 13:16                   ` Marc-André Lureau
2016-05-04 19:13                     ` Michael S. Tsirkin
2016-05-05  3:44                       ` Yuanhan Liu
2016-05-05 13:42                         ` Michael S. Tsirkin
2016-05-02 17:37               ` Yuanhan Liu
2016-04-01 11:16 ` [Qemu-devel] [PATCH 12/18] vhost-user: disconnect on start failure marcandre.lureau
2016-04-01 11:16 ` [Qemu-devel] [PATCH 13/18] vhost-net: do not crash if backend is not present marcandre.lureau
2016-04-01 11:16 ` [Qemu-devel] [PATCH 14/18] vhost-net: save & restore vhost-user acked features marcandre.lureau
2016-04-01 11:16 ` [Qemu-devel] [PATCH 15/18] vhost-net: save & restore vring enable state marcandre.lureau
2016-04-01 11:16 ` [Qemu-devel] [PATCH 16/18] test: vubr check " marcandre.lureau
2016-04-01 11:16 ` [Qemu-devel] [PATCH 17/18] test: start vhost-user reconnect test marcandre.lureau
2016-04-01 11:16 ` marcandre.lureau [this message]
2016-04-13  2:52   ` [Qemu-devel] [PATCH 18/18] test: add shutdown support vubr test Yuanhan Liu

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=1459509388-6185-19-git-send-email-marcandre.lureau@redhat.com \
    --to=marcandre.lureau@redhat.com \
    --cc=i.maximets@samsung.com \
    --cc=jonshin@cisco.com \
    --cc=mst@redhat.com \
    --cc=mukawa@igel.co.jp \
    --cc=qemu-devel@nongnu.org \
    --cc=yuanhan.liu@linux.intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.