From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53194) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZS1v-0003qa-Rh for qemu-devel@nongnu.org; Tue, 08 Sep 2015 19:10:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZZS1v-0003ao-0f for qemu-devel@nongnu.org; Tue, 08 Sep 2015 19:10:23 -0400 Received: from mail-wi0-x233.google.com ([2a00:1450:400c:c05::233]:34847) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZS1u-0003ae-NP for qemu-devel@nongnu.org; Tue, 08 Sep 2015 19:10:22 -0400 Received: by wicge5 with SMTP id ge5so134306853wic.0 for ; Tue, 08 Sep 2015 16:10:22 -0700 (PDT) Sender: =?UTF-8?B?TWFyYy1BbmRyw6kgTHVyZWF1?= From: marcandre.lureau@redhat.com Date: Wed, 9 Sep 2015 01:10:00 +0200 Message-Id: <1441753806-14225-9-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 08/14] vhost: add vhost_dev stop callback 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 vhost backend may want to stop the device, for example if it wants to restart itself (translates to a link down for vhost-net). Signed-off-by: Marc-André Lureau --- hw/net/vhost_net.c | 13 +++++++++++++ include/hw/virtio/vhost.h | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index ea15220..f977e2d 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -134,6 +134,18 @@ static int vhost_net_get_fd(NetClientState *backend) } } +static void vhost_net_backend_stop(struct vhost_dev *dev) +{ + struct vhost_net *net = container_of(dev, struct vhost_net, dev); + NetClientState *nc = net->nc; + NetClientState *peer = nc->peer; + + peer->link_down = 1; + if (peer->info->link_status_changed) { + peer->info->link_status_changed(peer); + } +} + struct vhost_net *vhost_net_init(VhostNetOptions *options) { int r; @@ -163,6 +175,7 @@ struct vhost_net *vhost_net_init(VhostNetOptions *options) net->dev.nvqs = 2; net->dev.vqs = net->vqs; + net->dev.stop = vhost_net_backend_stop; r = vhost_dev_init(&net->dev, options->opaque, options->backend_type); diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index ab1dcac..48efd87 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -35,6 +35,8 @@ struct vhost_log { vhost_log_chunk_t *log; }; +typedef void (*vhost_stop)(struct vhost_dev *dev); + struct vhost_memory; struct vhost_dev { MemoryListener memory_listener; @@ -59,6 +61,8 @@ struct vhost_dev { const VhostOps *vhost_ops; void *opaque; struct vhost_log *log; + /* backend request to stop */ + vhost_stop stop; }; int vhost_dev_init(struct vhost_dev *hdev, void *opaque, -- 2.4.3