From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39390) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bSyHK-0005ZF-08 for qemu-devel@nongnu.org; Thu, 28 Jul 2016 23:16:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bSyHI-0002sh-CP for qemu-devel@nongnu.org; Thu, 28 Jul 2016 23:16:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43558) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bSyHI-0002sd-6z for qemu-devel@nongnu.org; Thu, 28 Jul 2016 23:16:00 -0400 Date: Fri, 29 Jul 2016 06:15:57 +0300 From: "Michael S. Tsirkin" Message-ID: <1469762011-7902-16-git-send-email-mst@redhat.com> References: <1469762011-7902-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: <1469762011-7902-1-git-send-email-mst@redhat.com> Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL 15/41] vhost: make vhost_log_put() idempotent List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell , =?iso-8859-1?Q?Marc-Andr=E9?= Lureau From: Marc-Andr=E9 Lureau Although not strictly required, it is nice to have vhost_log_put() safely callable multiple times. Clear dev->log* when calling vhost_log_put() to make the function idempotent. This also simplifies a bit the caller work. Signed-off-by: Marc-Andr=E9 Lureau Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/vhost.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 429499a..9bac163 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -362,6 +362,8 @@ static void vhost_log_put(struct vhost_dev *dev, bool= sync) if (!log) { return; } + dev->log =3D NULL; + dev->log_size =3D 0; =20 --log->refcnt; if (log->refcnt =3D=3D 0) { @@ -710,8 +712,6 @@ static int vhost_migration_log(MemoryListener *listen= er, int enable) return r; } vhost_log_put(dev, false); - dev->log =3D NULL; - dev->log_size =3D 0; } else { vhost_dev_log_resize(dev, vhost_get_log_size(dev)); r =3D vhost_dev_set_log(dev, true); @@ -1328,7 +1328,4 @@ void vhost_dev_stop(struct vhost_dev *hdev, VirtIOD= evice *vdev) =20 vhost_log_put(hdev, true); hdev->started =3D false; - hdev->log =3D NULL; - hdev->log_size =3D 0; } - --=20 MST