From patchwork Wed May 21 16:28:12 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 351252 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 1533014008E for ; Thu, 22 May 2014 02:36:17 +1000 (EST) Received: from localhost ([::1]:60903 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wn9V0-0002vv-Tz for incoming@patchwork.ozlabs.org; Wed, 21 May 2014 12:36:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55086) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wn9Np-0001Dx-HZ for qemu-devel@nongnu.org; Wed, 21 May 2014 12:28:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wn9Nj-0002IA-E5 for qemu-devel@nongnu.org; Wed, 21 May 2014 12:28:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36713) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wn9Nj-0002Hx-6v for qemu-devel@nongnu.org; Wed, 21 May 2014 12:28:43 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s4LGSgxG000780 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 21 May 2014 12:28:42 -0400 Received: from noname.redhat.com (ovpn-116-42.ams2.redhat.com [10.36.116.42]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s4LGSJZu017108; Wed, 21 May 2014 12:28:41 -0400 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Wed, 21 May 2014 18:28:12 +0200 Message-Id: <1400689698-3096-15-git-send-email-kwolf@redhat.com> In-Reply-To: <1400689698-3096-1-git-send-email-kwolf@redhat.com> References: <1400689698-3096-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, stefanha@redhat.com Subject: [Qemu-devel] [PATCH 14/20] raw-win32: Handle failure for potentially large allocations 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 Some code in the block layer makes potentially huge allocations. Failure is not completely unexpected there, so avoid aborting qemu and handle out-of-memory situations gracefully. This patch addresses the allocations in the raw-win32 block driver. Signed-off-by: Kevin Wolf Reviewed-by: Stefan Hajnoczi --- block/win32-aio.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/block/win32-aio.c b/block/win32-aio.c index 5d1d199..b8320ce 100644 --- a/block/win32-aio.c +++ b/block/win32-aio.c @@ -138,7 +138,10 @@ BlockDriverAIOCB *win32_aio_submit(BlockDriverState *bs, waiocb->is_read = (type == QEMU_AIO_READ); if (qiov->niov > 1) { - waiocb->buf = qemu_blockalign(bs, qiov->size); + waiocb->buf = qemu_try_blockalign(bs, qiov->size); + if (waiocb->buf == NULL) { + goto out; + } if (type & QEMU_AIO_WRITE) { iov_to_buf(qiov->iov, qiov->niov, 0, waiocb->buf, qiov->size); } @@ -167,6 +170,7 @@ BlockDriverAIOCB *win32_aio_submit(BlockDriverState *bs, out_dec_count: aio->count--; +out: qemu_aio_release(waiocb); return NULL; }