From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50523) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W1bDO-0005FO-Bj for qemu-devel@nongnu.org; Fri, 10 Jan 2014 07:29:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W1bDJ-0005EQ-DJ for qemu-devel@nongnu.org; Fri, 10 Jan 2014 07:29:30 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45093) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W1bDJ-0005EK-4o for qemu-devel@nongnu.org; Fri, 10 Jan 2014 07:29:25 -0500 Date: Fri, 10 Jan 2014 14:29:17 +0200 From: "Michael S. Tsirkin" Message-ID: <20140110122917.GB10700@redhat.com> References: <1389279601-1924-1-git-send-email-a.motakis@virtualopensystems.com> <1389279601-1924-8-git-send-email-a.motakis@virtualopensystems.com> <20140109161605.GF3485@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v5 7/7] Add vhost-user reconnection List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Antonios Motakis Cc: snabb-devel@googlegroups.com, Anthony Liguori , Jason Wang , qemu-devel qemu-devel , Nikolay Nikolaev , Stefan Hajnoczi , Luke Gorrie , Paolo Bonzini , VirtualOpenSystems Technical Team On Fri, Jan 10, 2014 at 11:59:24AM +0100, Antonios Motakis wrote: >=20 >=20 >=20 > On Thu, Jan 9, 2014 at 5:16 PM, Michael S. Tsirkin wro= te: >=20 > On Thu, Jan 09, 2014 at 04:00:01PM +0100, Antonios Motakis wrote: > > At runtime vhost-user netdev will detect if the vhost backend is = up or > down. > > Upon disconnection it will set link_down accordingly and notify > virtio-net. >=20 > And then what happens? >=20 >=20 > The virtio-net interface goes down. On the next polling cycle the conne= ction > will be re-attempted (see vhost_user_timer_handler). >=20 I'm guessing user should have control over how often to retry then, it's a policy thing. >=20 > > > > Signed-off-by: Antonios Motakis > > Signed-off-by: Nikolay Nikolaev > > --- > > =A0hw/net/vhost_net.c =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0| 16 +++++++= ++++ > > =A0hw/virtio/vhost-backend.c =A0 =A0 =A0 =A0 | 16 +++++++++++ > > =A0include/hw/virtio/vhost-backend.h | =A02 ++ > > =A0include/net/vhost_net.h =A0 =A0 =A0 =A0 =A0 | =A01 + > > =A0net/vhost-user.c =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0| 56 > +++++++++++++++++++++++++++++++++++++++ > > =A05 files changed, 91 insertions(+) > > > > diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c > > index e42f4d6..56c218e 100644 > > --- a/hw/net/vhost_net.c > > +++ b/hw/net/vhost_net.c > > @@ -304,6 +304,17 @@ void vhost_net_virtqueue_mask(VHostNetState = *net, > VirtIODevice *dev, > > =A0 =A0 =A0vhost_virtqueue_mask(&net->dev, dev, idx, mask); > > =A0} > > > > +int vhost_net_link_status(VHostNetState *net) > > +{ > > + =A0 =A0int r =3D 0; > > + > > + =A0 =A0if (net->dev.vhost_ops->vhost_status) { > > + =A0 =A0 =A0 =A0r =3D net->dev.vhost_ops->vhost_status(&net->dev= ); > > + =A0 =A0} > > + > > + =A0 =A0return r; > > +} > > + > > =A0VHostNetState *get_vhost_net(NetClientState *nc) > > =A0{ > > =A0 =A0 =A0VHostNetState *vhost_net =3D 0; > > @@ -372,6 +383,11 @@ void vhost_net_virtqueue_mask(VHostNetState = *net, > VirtIODevice *dev, > > =A0{ > > =A0} > > > > +int vhost_net_link_status(VHostNetState *net) > > +{ > > + =A0 =A0return 0; > > +} > > + > > =A0VHostNetState *get_vhost_net(NetClientState *nc) > > =A0{ > > =A0 =A0 =A0return 0; > > diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.= c > > index 50ea307..fcd274f 100644 > > --- a/hw/virtio/vhost-backend.c > > +++ b/hw/virtio/vhost-backend.c > > @@ -350,9 +350,23 @@ static int vhost_user_call(struct vhost_dev = *dev, > unsigned long int request, > > =A0 =A0 =A0 =A0 =A0} > > =A0 =A0 =A0} > > > > + =A0 =A0/* mark the backend non operational */ > > + =A0 =A0if (result < 0) { > > + =A0 =A0 =A0 =A0error_report("%s: Connection break detected\n", = __func__); > > + =A0 =A0 =A0 =A0vhost_user_cleanup(dev); > > + =A0 =A0 =A0 =A0return 0; > > + =A0 =A0} > > + > > =A0 =A0 =A0return result; > > =A0} > > > > +static int vhost_user_status(struct vhost_dev *dev) > > +{ > > + =A0 =A0vhost_user_echo(dev); > > + > > + =A0 =A0return (dev->control >=3D 0); > > +} > > + > > =A0static int vhost_user_init(struct vhost_dev *dev, const char *= devpath) > > =A0{ > > =A0 =A0 =A0int fd =3D -1; > > @@ -432,6 +446,7 @@ static int vhost_user_cleanup(struct vhost_de= v *dev) > > =A0static const VhostOps user_ops =3D { > > =A0 =A0 =A0 =A0 =A0.backend_type =3D VHOST_BACKEND_TYPE_USER, > > =A0 =A0 =A0 =A0 =A0.vhost_call =3D vhost_user_call, > > + =A0 =A0 =A0 =A0.vhost_status =3D vhost_user_status, > > =A0 =A0 =A0 =A0 =A0.vhost_backend_init =3D vhost_user_init, > > =A0 =A0 =A0 =A0 =A0.vhost_backend_cleanup =3D vhost_user_cleanup > > =A0}; > > @@ -464,6 +479,7 @@ static int vhost_kernel_cleanup(struct vhost_= dev > *dev) > > =A0static const VhostOps kernel_ops =3D { > > =A0 =A0 =A0 =A0 =A0.backend_type =3D VHOST_BACKEND_TYPE_KERNEL, > > =A0 =A0 =A0 =A0 =A0.vhost_call =3D vhost_kernel_call, > > + =A0 =A0 =A0 =A0.vhost_status =3D 0, > > =A0 =A0 =A0 =A0 =A0.vhost_backend_init =3D vhost_kernel_init, > > =A0 =A0 =A0 =A0 =A0.vhost_backend_cleanup =3D vhost_kernel_cleanu= p > > =A0}; > > diff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virti= o/ > vhost-backend.h > > index ef87ffa..f2b4a6c 100644 > > --- a/include/hw/virtio/vhost-backend.h > > +++ b/include/hw/virtio/vhost-backend.h > > @@ -22,12 +22,14 @@ struct vhost_dev; > > > > =A0typedef int (*vhost_call)(struct vhost_dev *dev, unsigned long= int > request, > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 void *arg); > > +typedef int (*vhost_status)(struct vhost_dev *dev); > > =A0typedef int (*vhost_backend_init)(struct vhost_dev *dev, const= char > *devpath); > > =A0typedef int (*vhost_backend_cleanup)(struct vhost_dev *dev); > > > > =A0typedef struct VhostOps { > > =A0 =A0 =A0VhostBackendType backend_type; > > =A0 =A0 =A0vhost_call vhost_call; > > + =A0 =A0vhost_status vhost_status; > > =A0 =A0 =A0vhost_backend_init vhost_backend_init; > > =A0 =A0 =A0vhost_backend_cleanup vhost_backend_cleanup; > > =A0} VhostOps; > > diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h > > index abd3d0b..6390907 100644 > > --- a/include/net/vhost_net.h > > +++ b/include/net/vhost_net.h > > @@ -31,5 +31,6 @@ void vhost_net_ack_features(VHostNetState *net, > unsigned features); > > =A0bool vhost_net_virtqueue_pending(VHostNetState *net, int n); > > =A0void vhost_net_virtqueue_mask(VHostNetState *net, VirtIODevice= *dev, > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0in= t idx, bool mask); > > +int vhost_net_link_status(VHostNetState *net); > > =A0VHostNetState *get_vhost_net(NetClientState *nc); > > =A0#endif > > diff --git a/net/vhost-user.c b/net/vhost-user.c > > index 6fd5afc..56f7dd4 100644 > > --- a/net/vhost-user.c > > +++ b/net/vhost-user.c > > @@ -12,6 +12,7 @@ > > =A0#include "net/vhost_net.h" > > =A0#include "net/vhost-user.h" > > =A0#include "qemu/error-report.h" > > +#include "qemu/timer.h" > > > > =A0typedef struct VhostUserState { > > =A0 =A0 =A0NetClientState nc; > > @@ -19,6 +20,9 @@ typedef struct VhostUserState { > > =A0 =A0 =A0char *devpath; > > =A0} VhostUserState; > > > > +static QEMUTimer *vhost_user_timer; > > +#define VHOST_USER_TIMEOUT =A0(1*1000) > > + > > =A0VHostNetState *vhost_user_get_vhost_net(NetClientState *nc) > > =A0{ > > =A0 =A0 =A0VhostUserState *s =3D DO_UPCAST(VhostUserState, nc, nc= ); > > @@ -31,6 +35,11 @@ static int vhost_user_running(VhostUserState *= s) > > =A0 =A0 =A0return (s->vhost_net) ? 1 : 0; > > =A0} > > > > +static int vhost_user_link_status(VhostUserState *s) > > +{ > > + =A0 =A0return (!s->nc.link_down) && vhost_net_link_status(s->vh= ost_net); > > +} > > + > > =A0static int vhost_user_start(VhostUserState *s) > > =A0{ > > =A0 =A0 =A0VhostNetOptions options; > > @@ -59,6 +68,48 @@ static void vhost_user_stop(VhostUserState *s) > > =A0 =A0 =A0s->vhost_net =3D 0; > > =A0} > > > > +static void vhost_user_timer_handler(void *opaque) > > +{ > > + =A0 =A0VhostUserState *s =3D opaque; > > + =A0 =A0int link_down =3D 0; > > + > > + =A0 =A0if (vhost_user_running(s)) { > > + =A0 =A0 =A0 =A0if (!vhost_user_link_status(s)) { > > + =A0 =A0 =A0 =A0 =A0 =A0link_down =3D 1; > > + =A0 =A0 =A0 =A0} > > + =A0 =A0} else { > > + =A0 =A0 =A0 =A0vhost_user_start(s); > > + =A0 =A0 =A0 =A0if (!vhost_user_running(s)) { > > + =A0 =A0 =A0 =A0 =A0 =A0link_down =3D 1; > > + =A0 =A0 =A0 =A0} > > + =A0 =A0} > > + > > + =A0 =A0if (link_down !=3D s->nc.link_down) { > > + > > + =A0 =A0 =A0 =A0s->nc.link_down =3D link_down; > > + > > + =A0 =A0 =A0 =A0if (s->nc.peer) { > > + =A0 =A0 =A0 =A0 =A0 =A0s->nc.peer->link_down =3D link_down; > > + =A0 =A0 =A0 =A0} > > + > > + =A0 =A0 =A0 =A0if (s->nc.info->link_status_changed) { > > + =A0 =A0 =A0 =A0 =A0 =A0s->nc.info->link_status_changed(&s->nc); > > + =A0 =A0 =A0 =A0} > > + > > + =A0 =A0 =A0 =A0if (s->nc.peer && s->nc.peer->info->link_status_= changed) { > > + =A0 =A0 =A0 =A0 =A0 =A0s->nc.peer->info->link_status_changed(s-= >nc.peer); > > + =A0 =A0 =A0 =A0} > > + > > + =A0 =A0 =A0 =A0if (link_down) { > > + =A0 =A0 =A0 =A0 =A0 =A0vhost_user_stop(s); > > + =A0 =A0 =A0 =A0} > > + =A0 =A0} > > + > > + =A0 =A0/* reschedule */ > > + =A0 =A0timer_mod(vhost_user_timer, > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0qemu_clock_get_ms(QEMU_CLOCK_REALTIM= E) + > VHOST_USER_TIMEOUT); > > +} > > + > > =A0static void vhost_user_cleanup(NetClientState *nc) > > =A0{ > > =A0 =A0 =A0VhostUserState *s =3D DO_UPCAST(VhostUserState, nc, nc= ); > > @@ -93,6 +144,11 @@ static int net_vhost_user_init(NetClientState= *peer, > const char *device, > > > > =A0 =A0 =A0r =3D vhost_user_start(s); > > > > + =A0 =A0vhost_user_timer =3D timer_new_ms(QEMU_CLOCK_REALTIME, > > + =A0 =A0 =A0 =A0 =A0 =A0vhost_user_timer_handler, s); > > + =A0 =A0timer_mod(vhost_user_timer, > > + =A0 =A0 =A0 =A0 =A0 =A0qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + > VHOST_USER_TIMEOUT); > > + > > =A0 =A0 =A0return r; > > =A0} > > > > -- > > 1.8.3.2 > > >=20 >=20