From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33299) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1alx4Y-0005o9-Eu for qemu-devel@nongnu.org; Fri, 01 Apr 2016 07:17:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1alx4X-0001oK-F0 for qemu-devel@nongnu.org; Fri, 01 Apr 2016 07:17:02 -0400 Received: from mail-qg0-x236.google.com ([2607:f8b0:400d:c04::236]:35189) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1alx4X-0001o3-Ah for qemu-devel@nongnu.org; Fri, 01 Apr 2016 07:17:01 -0400 Received: by mail-qg0-x236.google.com with SMTP id y89so93621136qge.2 for ; Fri, 01 Apr 2016 04:17:01 -0700 (PDT) Sender: =?UTF-8?B?TWFyYy1BbmRyw6kgTHVyZWF1?= From: marcandre.lureau@redhat.com Date: Fri, 1 Apr 2016 13:16:21 +0200 Message-Id: <1459509388-6185-12-git-send-email-marcandre.lureau@redhat.com> In-Reply-To: <1459509388-6185-1-git-send-email-marcandre.lureau@redhat.com> References: <1459509388-6185-1-git-send-email-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [Qemu-devel] [PATCH 11/18] vhost-user: add shutdown support List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Yuanhan Liu , "Michael S. Tsirkin" , Ilya Maximets , jonshin@cisco.com, Tetsuya Mukawa , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= From: Marc-André Lureau Signed-off-by: Marc-André Lureau --- 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