From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33192) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1alx4N-0005Vd-T1 for qemu-devel@nongnu.org; Fri, 01 Apr 2016 07:16:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1alx4M-0001lT-VG for qemu-devel@nongnu.org; Fri, 01 Apr 2016 07:16:51 -0400 Received: from mail-qg0-x22d.google.com ([2607:f8b0:400d:c04::22d]:36277) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1alx4M-0001lN-NI for qemu-devel@nongnu.org; Fri, 01 Apr 2016 07:16:50 -0400 Received: by mail-qg0-x22d.google.com with SMTP id w104so87980448qge.3 for ; Fri, 01 Apr 2016 04:16:50 -0700 (PDT) Sender: =?UTF-8?B?TWFyYy1BbmRyw6kgTHVyZWF1?= From: marcandre.lureau@redhat.com Date: Fri, 1 Apr 2016 13:16:17 +0200 Message-Id: <1459509388-6185-8-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 07/18] vhost: add vhost_dev stop callback 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 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 | 14 ++++++++++++++ include/hw/virtio/vhost.h | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 6e1032f..1e4710d 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -131,6 +131,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; @@ -165,6 +177,8 @@ struct vhost_net *vhost_net_init(VhostNetOptions *options) net->dev.vq_index = net->nc->queue_index * net->dev.nvqs; } + net->dev.stop = vhost_net_backend_stop; + r = vhost_dev_init(&net->dev, options->opaque, options->backend_type); if (r < 0) { diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index b60d758..859be64 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; @@ -61,6 +63,8 @@ struct vhost_dev { void *opaque; struct vhost_log *log; QLIST_ENTRY(vhost_dev) entry; + /* backend request to stop */ + vhost_stop stop; }; int vhost_dev_init(struct vhost_dev *hdev, void *opaque, -- 2.5.5