Received: from eggs.gnu.org ([2001:4830:134:3::10]:56518) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKxge-0004Cy-7E for qemu-devel@nongnu.org; Wed, 06 Jul 2016 21:01:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bKxgd-0006WG-Ay for qemu-devel@nongnu.org; Wed, 06 Jul 2016 21:01:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52389) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKxgd-0006W6-5T for qemu-devel@nongnu.org; Wed, 06 Jul 2016 21:01:03 -0400 From: marcandre.lureau@redhat.com Date: Thu, 7 Jul 2016 03:00:28 +0200 Message-Id: <20160707010053.28008-5-marcandre.lureau@redhat.com> In-Reply-To: <20160707010053.28008-1-marcandre.lureau@redhat.com> References: <20160707010053.28008-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH v4 04/29] vhost: make vhost_log_put() idempotent List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: mukawa@igel.co.jp, yuanhan.liu@linux.intel.com, victork@redhat.com, jonshin@cisco.com, mst@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= From: Marc-Andr=C3=A9 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=C3=A9 Lureau --- 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 dbb4deb..2753bb4 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); @@ -1290,7 +1290,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 2.9.0