5d360b
From e5f537a8b3821b68040eada7a964b2dd1b17d3d3 Mon Sep 17 00:00:00 2001
5d360b
From: Fam Zheng <famz@redhat.com>
5d360b
Date: Tue, 21 Nov 2017 03:21:45 +0100
5d360b
Subject: [PATCH 2/9] linux-aio: Fix laio resource leak
5d360b
5d360b
RH-Author: Fam Zheng <famz@redhat.com>
5d360b
Message-id: <20171121032145.5681-3-famz@redhat.com>
5d360b
Patchwork-id: 77767
5d360b
O-Subject: [RHEL-7.5 qemu-kvm PATCH v2 2/2] linux-aio: Fix laio resource leak
5d360b
Bugzilla: 1491434
5d360b
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
5d360b
RH-Acked-by: John Snow <jsnow@redhat.com>
5d360b
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
5d360b
5d360b
From: Gonglei <arei.gonglei@huawei.com>
5d360b
5d360b
when hotplug virtio-scsi disks using laio, the aio_nr will
5d360b
increase in laio_init() by io_setup(), we can see the number by
5d360b
  # cat /proc/sys/fs/aio-nr
5d360b
  128
5d360b
if the aio_nr attach the maxnum, which found from
5d360b
  # cat /proc/sys/fs/aio-max-nr
5d360b
  65536
5d360b
the hotplug process will fail because of aio context leak.
5d360b
5d360b
Fix it by io_destroy in laio_cleanup().
5d360b
5d360b
Reported-by: daifulai <daifulai@huawei.com>
5d360b
Signed-off-by: Gonglei <arei.gonglei@huawei.com>
5d360b
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
5d360b
(cherry picked from commit a1abf40d6be2fc4b40d90ae3b46442f4a671776b)
5d360b
Signed-off-by: Fam Zheng <famz@redhat.com>
5d360b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
5d360b
5d360b
Conflicts:
5d360b
	block/linux-aio.c
5d360b
5d360b
Contextual conflict because of the previous patch's necessary deviation
5d360b
from upstream.
5d360b
---
5d360b
 block/linux-aio.c | 5 +++++
5d360b
 1 file changed, 5 insertions(+)
5d360b
5d360b
diff --git a/block/linux-aio.c b/block/linux-aio.c
5d360b
index 43f14f3..e1d2593 100644
5d360b
--- a/block/linux-aio.c
5d360b
+++ b/block/linux-aio.c
5d360b
@@ -232,5 +232,10 @@ void laio_cleanup(void *s_)
5d360b
 
5d360b
     qemu_aio_set_fd_handler(s->efd, NULL, NULL, NULL, NULL);
5d360b
     close(s->efd);
5d360b
+
5d360b
+    if (io_destroy(s->ctx) != 0) {
5d360b
+        fprintf(stderr, "%s: destroy AIO context %p failed\n",
5d360b
+                        __func__, &s->ctx);
5d360b
+    }
5d360b
     g_free(s);
5d360b
 }
5d360b
-- 
5d360b
1.8.3.1
5d360b