Received: from eggs.gnu.org ([2001:4830:134:3::10]:59892) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bS9hg-0002HD-60 for qemu-devel@nongnu.org; Tue, 26 Jul 2016 17:15:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bS9he-00029M-5s for qemu-devel@nongnu.org; Tue, 26 Jul 2016 17:15:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46952) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bS9he-00029E-03 for qemu-devel@nongnu.org; Tue, 26 Jul 2016 17:15:50 -0400 From: marcandre.lureau@redhat.com Date: Wed, 27 Jul 2016 01:14:59 +0400 Message-Id: <20160726211527.28510-6-marcandre.lureau@redhat.com> In-Reply-To: <20160726211527.28510-1-marcandre.lureau@redhat.com> References: <20160726211527.28510-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 v6 05/33] 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 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 2.9.0