qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCH 11/18] vhost-user: add shutdown support


From: marcandre . lureau
Subject: [Qemu-devel] [PATCH 11/18] vhost-user: add shutdown support
Date: Fri, 1 Apr 2016 13:16:21 +0200

From: Marc-André Lureau <address@hidden>

Signed-off-by: Marc-André Lureau <address@hidden>
---
 docs/specs/vhost-user.txt | 15 +++++++++++++++
 hw/virtio/vhost-user.c    | 16 ++++++++++++++++
 2 files changed, 31 insertions(+)

diff --git a/docs/specs/vhost-user.txt b/docs/specs/vhost-user.txt
index 8a635fa..60d6d13 100644
--- a/docs/specs/vhost-user.txt
+++ b/docs/specs/vhost-user.txt
@@ -487,3 +487,18 @@ Message types
       request to the master. It is passed in the ancillary data.
       This message is only sent if VHOST_USER_PROTOCOL_F_SLAVE_CHANNEL
       feature is available.
+
+Slave message types
+-------------------
+
+ * VHOST_USER_SLAVE_SHUTDOWN:
+      Id: 1
+      Master payload: N/A
+      Slave payload: u64
+
+      Request the master to shutdown the slave. A 0 reply is for
+      success, in which case the slave may close all connections
+      immediately and quit. A non-zero reply cancels the request.
+
+      Before a reply comes, the master may make other requests in
+      order to flush or sync state.
diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
index 890c1bd..f91baee 100644
--- a/hw/virtio/vhost-user.c
+++ b/hw/virtio/vhost-user.c
@@ -67,6 +67,8 @@ typedef enum VhostUserRequest {
 
 typedef enum VhostUserSlaveRequest {
     VHOST_USER_SLAVE_NONE = 0,
+    VHOST_USER_SLAVE_SHUTDOWN = 1,
+
     VHOST_USER_SLAVE_MAX
 }  VhostUserSlaveRequest;
 
@@ -539,6 +541,20 @@ static void slave_read(void *opaque)
     }
 
     switch (msg.request) {
+    case VHOST_USER_SLAVE_SHUTDOWN: {
+        uint64_t success = 1; /* 0 is for success */
+        if (dev->stop) {
+            dev->stop(dev);
+            success = 0;
+        }
+        msg.payload.u64 = success;
+        msg.size = sizeof(msg.payload.u64);
+        size = send(u->slave_fd, &msg, VHOST_USER_HDR_SIZE + msg.size, 0);
+        if (size != VHOST_USER_HDR_SIZE + msg.size) {
+            error_report("Failed to write reply.");
+        }
+        break;
+    }
     default:
         error_report("Received unexpected msg type.");
     }
-- 
2.5.5




reply via email to

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