From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43510) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQ9o1-0008Kl-7s for qemu-devel@nongnu.org; Thu, 21 Jul 2016 04:58:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bQ9nz-0007Kh-A2 for qemu-devel@nongnu.org; Thu, 21 Jul 2016 04:58:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46475) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQ9nz-0007Ka-4C for qemu-devel@nongnu.org; Thu, 21 Jul 2016 04:58:07 -0400 From: marcandre.lureau@redhat.com Date: Thu, 21 Jul 2016 12:57:23 +0400 Message-Id: <20160721085750.30008-5-marcandre.lureau@redhat.com> In-Reply-To: <20160721085750.30008-1-marcandre.lureau@redhat.com> References: <20160721085750.30008-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 v5 04/31] 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