From patchwork Wed May 7 10:27:31 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 346517 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 72CAA14011E for ; Wed, 7 May 2014 20:31:18 +1000 (EST) Received: from localhost ([::1]:40204 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Whz88-0007ul-AU for incoming@patchwork.ozlabs.org; Wed, 07 May 2014 06:31:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49462) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Whz5M-00037v-4d for qemu-devel@nongnu.org; Wed, 07 May 2014 06:28:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Whz5F-0005ns-W7 for qemu-devel@nongnu.org; Wed, 07 May 2014 06:28:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:20415) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Whz5F-0005ng-NV for qemu-devel@nongnu.org; Wed, 07 May 2014 06:28:17 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s47ASGjK025031 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 7 May 2014 06:28:17 -0400 Received: from localhost (dhcp-64-106.muc.redhat.com [10.32.64.106]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s47ASFiu029642; Wed, 7 May 2014 06:28:16 -0400 From: Stefan Hajnoczi To: Date: Wed, 7 May 2014 12:27:31 +0200 Message-Id: <1399458461-3997-16-git-send-email-stefanha@redhat.com> In-Reply-To: <1399458461-3997-1-git-send-email-stefanha@redhat.com> References: <1399458461-3997-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Kevin Wolf , Paolo Bonzini , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH v2 15/25] block/linux-aio: fix memory and fd leak X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Hot unplugging -drive aio=native,file=test.img,format=raw images leaves the Linux AIO event notifier and struct qemu_laio_state allocated. Luckily nothing will use the event notifier after the BlockDriverState has been closed so the handler function is never called. It's still worth fixing this resource leak. Signed-off-by: Stefan Hajnoczi --- block/linux-aio.c | 8 ++++++++ block/raw-aio.h | 1 + block/raw-posix.c | 5 +++++ 3 files changed, 14 insertions(+) diff --git a/block/linux-aio.c b/block/linux-aio.c index 7ff3897..f0a2c08 100644 --- a/block/linux-aio.c +++ b/block/linux-aio.c @@ -212,3 +212,11 @@ out_free_state: g_free(s); return NULL; } + +void laio_cleanup(void *s_) +{ + struct qemu_laio_state *s = s_; + + event_notifier_cleanup(&s->e); + g_free(s); +} diff --git a/block/raw-aio.h b/block/raw-aio.h index 9a761ee..55e0ccc 100644 --- a/block/raw-aio.h +++ b/block/raw-aio.h @@ -34,6 +34,7 @@ /* linux-aio.c - Linux native implementation */ #ifdef CONFIG_LINUX_AIO void *laio_init(void); +void laio_cleanup(void *s); BlockDriverAIOCB *laio_submit(BlockDriverState *bs, void *aio_ctx, int fd, int64_t sector_num, QEMUIOVector *qiov, int nb_sectors, BlockDriverCompletionFunc *cb, void *opaque, int type); diff --git a/block/raw-posix.c b/block/raw-posix.c index 7881f12..7d0325a 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -1084,6 +1084,11 @@ static void raw_close(BlockDriverState *bs) raw_detach_aio_context(bs); +#ifdef CONFIG_LINUX_AIO + if (s->use_aio) { + laio_cleanup(s->aio_ctx); + } +#endif if (s->fd >= 0) { qemu_close(s->fd); s->fd = -1;