linux-aio: Fix laio resource leak
authorGonglei <arei.gonglei@huawei.com>
Sat, 12 Jul 2014 03:43:37 +0000 (11:43 +0800)
committerStefan Hajnoczi <stefanha@redhat.com>
Tue, 15 Jul 2014 13:34:13 +0000 (15:34 +0200)
when hotplug virtio-scsi disks using laio, the aio_nr will
increase in laio_init() by io_setup(), we can see the number by
  # cat /proc/sys/fs/aio-nr
  128
if the aio_nr attach the maxnum, which found from
  # cat /proc/sys/fs/aio-max-nr
  65536
the hotplug process will fail because of aio context leak.

Fix it by io_destroy in laio_cleanup().

Reported-by: daifulai <daifulai@huawei.com>
Signed-off-by: Gonglei <arei.gonglei@huawei.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
block/linux-aio.c

index 48673690ac91d259607c1f96b8944321cc7b0e34..7ac7e8c99c72f6e6e2c7b8fb176835e8c6a8e95d 100644 (file)
@@ -310,5 +310,10 @@ void laio_cleanup(void *s_)
     struct qemu_laio_state *s = s_;
 
     event_notifier_cleanup(&s->e);
+
+    if (io_destroy(s->ctx) != 0) {
+        fprintf(stderr, "%s: destroy AIO context %p failed\n",
+                        __func__, &s->ctx);
+    }
     g_free(s);
 }