From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53250) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZS23-0003xR-OC for qemu-devel@nongnu.org; Tue, 08 Sep 2015 19:10:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZZS22-0003cz-Qt for qemu-devel@nongnu.org; Tue, 08 Sep 2015 19:10:31 -0400 Received: from mail-wi0-x22d.google.com ([2a00:1450:400c:c05::22d]:36039) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZS21-0003cu-Ph for qemu-devel@nongnu.org; Tue, 08 Sep 2015 19:10:30 -0400 Received: by wicgb1 with SMTP id gb1so95762183wic.1 for ; Tue, 08 Sep 2015 16:10:29 -0700 (PDT) Sender: =?UTF-8?B?TWFyYy1BbmRyw6kgTHVyZWF1?= From: marcandre.lureau@redhat.com Date: Wed, 9 Sep 2015 01:10:04 +0200 Message-Id: <1441753806-14225-13-git-send-email-marcandre.lureau@redhat.com> In-Reply-To: <1441753806-14225-1-git-send-email-marcandre.lureau@redhat.com> References: <1441753806-14225-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 RFC 12/14] vhost-user: add shutdown support List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: mukawa@igel.co.jp, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , mst@redhat.com From: Marc-André Lureau Signed-off-by: Marc-André Lureau --- docs/specs/vhost-user.txt | 15 +++++++++++++++ hw/virtio/vhost-user.c | 30 +++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/docs/specs/vhost-user.txt b/docs/specs/vhost-user.txt index 5e00bd3..854493e 100644 --- a/docs/specs/vhost-user.txt +++ b/docs/specs/vhost-user.txt @@ -331,6 +331,21 @@ Message types This message is only sent if VHOST_USER_PROTOCOL_F_SLAVE_REQ 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. + Migration --------- diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 49f566c..949382c 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -55,6 +55,7 @@ typedef enum VhostUserRequest { typedef enum VhostUserSlaveRequest { VHOST_USER_SLAVE_NONE = 0, + VHOST_USER_SLAVE_SHUTDOWN = 1, VHOST_USER_SLAVE_MAX } VhostUserSlaveRequest; @@ -140,7 +141,7 @@ static VhostUserRequest vhost_user_request_translate(unsigned long int request) case VHOST_SET_VRING_ERR: return VHOST_USER_SET_VRING_ERR; default: - return VHOST_USER_MAX; + return request; } } @@ -375,6 +376,21 @@ static int slave_can_receive(void *opaque) return VHOST_USER_HDR_SIZE; } +static int vhost_user_slave_write(struct vhost_dev *dev, VhostUserMsg *msg, + int *fds, int fd_num) +{ + struct vhost_user *u = dev->opaque; + CharDriverState *chr = u->slave_chr; + int size = VHOST_USER_HDR_SIZE + msg->size; + + if (fd_num) { + qemu_chr_fe_set_msgfds(chr, fds, fd_num); + } + + return qemu_chr_fe_write_all(chr, (const uint8_t *) msg, size) == size ? + 0 : -1; +} + static void slave_receive(void *opaque, const uint8_t *buf, int size) { struct vhost_dev *dev = opaque; @@ -386,6 +402,18 @@ static void slave_receive(void *opaque, const uint8_t *buf, int size) } switch (msg->request) { + case VHOST_USER_SLAVE_SHUTDOWN: { + uint64_t success = 1; + + if (dev->stop) { + dev->stop(dev); + success = 0; + } + + msg->u64 = success; + vhost_user_slave_write(dev, msg, NULL, 0); + return; + } default: error_report("Received unexpected msg type."); } -- 2.4.3