From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58948) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZkIYv-0005zE-Ro for qemu-devel@nongnu.org; Thu, 08 Oct 2015 17:17:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZkIYu-0007Ep-Nh for qemu-devel@nongnu.org; Thu, 08 Oct 2015 17:17:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48320) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZkIYu-0007El-GS for qemu-devel@nongnu.org; Thu, 08 Oct 2015 17:17:16 -0400 Date: Fri, 9 Oct 2015 00:17:12 +0300 From: "Michael S. Tsirkin" Message-ID: <1444338957-15293-11-git-send-email-mst@redhat.com> References: <1444338957-15293-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <1444338957-15293-1-git-send-email-mst@redhat.com> Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL 10/25] vhost-user: send log shm fd along with log_base List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell , =?us-ascii?B?PT9VVEYtOD9xP01hcmMtQW5kcj1DMz1BOT0yMEx1cmVhdT89?= From: Marc-Andr=E9 Lureau Send the shm for the dirty pages logging if the backend supports VHOST_USER_PROTOCOL_F_LOG_SHMFD. Wait for a reply to make sure the old log is no longer used. Signed-off-by: Marc-Andr=E9 Lureau Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/virtio/vhost-backend.h | 4 +++- hw/virtio/vhost-backend.c | 3 ++- hw/virtio/vhost-user.c | 27 +++++++++++++++++++++++++-- hw/virtio/vhost.c | 5 +++-- 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-= backend.h index 649766a..7064a12 100644 --- a/include/hw/virtio/vhost-backend.h +++ b/include/hw/virtio/vhost-backend.h @@ -21,6 +21,7 @@ typedef enum VhostBackendType { } VhostBackendType; =20 struct vhost_dev; +struct vhost_log; =20 typedef int (*vhost_call)(struct vhost_dev *dev, unsigned long int reque= st, void *arg); @@ -29,7 +30,8 @@ typedef int (*vhost_backend_cleanup)(struct vhost_dev *= dev); typedef int (*vhost_backend_get_vq_index)(struct vhost_dev *dev, int idx= ); typedef int (*vhost_backend_set_vring_enable)(struct vhost_dev *dev, int= enable); =20 -typedef int (*vhost_set_log_base_op)(struct vhost_dev *dev, uint64_t bas= e); +typedef int (*vhost_set_log_base_op)(struct vhost_dev *dev, uint64_t bas= e, + struct vhost_log *log); typedef bool (*vhost_requires_shm_log_op)(struct vhost_dev *dev); =20 typedef struct VhostOps { diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.c index 88d33fd..87ab028 100644 --- a/hw/virtio/vhost-backend.c +++ b/hw/virtio/vhost-backend.c @@ -50,7 +50,8 @@ static int vhost_kernel_get_vq_index(struct vhost_dev *= dev, int idx) return idx - dev->vq_index; } =20 -static int vhost_set_log_base(struct vhost_dev *dev, uint64_t base) +static int vhost_set_log_base(struct vhost_dev *dev, uint64_t base, + struct vhost_log *log) { return vhost_kernel_call(dev, VHOST_SET_LOG_BASE, &base); } diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 01e51a0..cf14e38 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -367,8 +367,13 @@ static int vhost_user_call(struct vhost_dev *dev, un= signed long int request, return 0; } =20 -static int vhost_set_log_base(struct vhost_dev *dev, uint64_t base) +static int vhost_set_log_base(struct vhost_dev *dev, uint64_t base, + struct vhost_log *log) { + int fds[VHOST_MEMORY_MAX_NREGIONS]; + size_t fd_num =3D 0; + bool shmfd =3D virtio_has_feature(dev->protocol_features, + VHOST_USER_PROTOCOL_F_LOG_SHMFD); VhostUserMsg msg =3D { .request =3D VHOST_USER_SET_LOG_BASE, .flags =3D VHOST_USER_VERSION, @@ -376,7 +381,25 @@ static int vhost_set_log_base(struct vhost_dev *dev,= uint64_t base) .size =3D sizeof(m.u64), }; =20 - vhost_user_write(dev, &msg, NULL, 0); + if (shmfd && log->fd !=3D -1) { + fds[fd_num++] =3D log->fd; + } + + vhost_user_write(dev, &msg, fds, fd_num); + + if (shmfd) { + msg.size =3D 0; + if (vhost_user_read(dev, &msg) < 0) { + return 0; + } + + if (msg.request !=3D VHOST_USER_SET_LOG_BASE) { + error_report("Received unexpected msg type. " + "Expected %d received %d", + VHOST_USER_SET_LOG_BASE, msg.request); + return -1; + } + } =20 return 0; } diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 63fa2bf..d1c0367 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -372,7 +372,7 @@ static inline void vhost_dev_log_resize(struct vhost_= dev *dev, uint64_t size) =20 /* inform backend of log switching, this must be done before releasing the current log, to ensure no logging is lost */ - r =3D dev->vhost_ops->vhost_set_log_base(dev, log_base); + r =3D dev->vhost_ops->vhost_set_log_base(dev, log_base, log); assert(r >=3D 0); vhost_log_put(dev, true); dev->log =3D log; @@ -1178,7 +1178,8 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIOD= evice *vdev) vhost_dev_log_is_shared(hdev)); log_base =3D (uintptr_t)hdev->log->log; r =3D hdev->vhost_ops->vhost_set_log_base(hdev, - hdev->log_size ? log_bas= e : 0); + hdev->log_size ? log_bas= e : 0, + hdev->log); if (r < 0) { r =3D -errno; goto fail_log; --=20 MST