From patchwork Sun Mar 27 10:25:49 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Feiran Zheng X-Patchwork-Id: 88505 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id D6DA6B6F9E for ; Sun, 27 Mar 2011 21:26:53 +1100 (EST) Received: from localhost ([127.0.0.1]:43943 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q3nBJ-0004fE-RK for incoming@patchwork.ozlabs.org; Sun, 27 Mar 2011 06:26:49 -0400 Received: from [140.186.70.92] (port=43325 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q3nAh-0004f9-5J for qemu-devel@nongnu.org; Sun, 27 Mar 2011 06:26:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q3nAg-0003E9-1S for qemu-devel@nongnu.org; Sun, 27 Mar 2011 06:26:11 -0400 Received: from mail-vx0-f173.google.com ([209.85.220.173]:39286) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q3nAf-0003E3-Ub for qemu-devel@nongnu.org; Sun, 27 Mar 2011 06:26:10 -0400 Received: by vxb41 with SMTP id 41so1915878vxb.4 for ; Sun, 27 Mar 2011 03:26:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:from:date:message-id:subject:to:cc :content-type; bh=88MLC7SdNFSuWxV9bQjj+Q4A0MYeOtviG1Puyt+/TIQ=; b=CVipv4FVcQqgdFW4yEdHgOAnHtqxgixPQCAVQB1Iyd9GSsxjThuTGR7KvGT3NzadM4 z/bTzPUm4Uu4L+NK4fPAiBbc/5Y6l8BVd1bUJ1GffJFr2gXBwBjYaIj/4sKprOz815yC qC3RN3YcjVi84WR636+PkhDQVSgWOAt5Rsptg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:from:date:message-id:subject:to:cc:content-type; b=JrMg4kt9cF8Tbb0MyH5EexAWTnWsHvGyx/V4aZIVZPrSijrdp6fRAc4olaeB0Jc4pv HCT/GQU9BEieWtNEz2DZKvnQXDyasIhO0AxVmTVR6Vqcz/q02R5s50akASjNdNQycI4j pxCD/2r+6DKI+UHrdicPb9HDtzhwN3oxG09/M= Received: by 10.52.92.161 with SMTP id cn1mr3880430vdb.253.1301221569102; Sun, 27 Mar 2011 03:26:09 -0700 (PDT) MIME-Version: 1.0 Received: by 10.52.161.8 with HTTP; Sun, 27 Mar 2011 03:25:49 -0700 (PDT) From: Feiran Zheng Date: Sun, 27 Mar 2011 18:25:49 +0800 Message-ID: To: qemu-devel@nongnu.org X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.220.173 Cc: Anthony PERARD , Kevin Wolf , Gerd Hoffmann , Stefano Stabellini Subject: [Qemu-devel] [PATCH]hw/xen_disk: ioreq not finished on error X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Bug fix: routines 'ioreq_runio_qemu_sync' and 'ioreq_runio_qemu_aio' won't call 'ioreq_unmap' or 'ioreq_finish' on errors, leaving ioreq in the blkdev->inflight list and a leak. Signed-off-by: Feiran Zheng --- hw/xen_disk.c | 22 +++++++++++++++++----- 1 files changed, 17 insertions(+), 5 deletions(-) diff --git a/hw/xen_disk.c b/hw/xen_disk.c index 445bf03..7940fab 100644 --- a/hw/xen_disk.c +++ b/hw/xen_disk.c @@ -309,8 +309,10 @@ static int ioreq_runio_qemu_sync(struct ioreq *ioreq) int i, rc, len = 0; off_t pos; - if (ioreq->req.nr_segments && ioreq_map(ioreq) == -1) - goto err; + if (ioreq->req.nr_segments) { + if (ioreq_map(ioreq) == -1) + goto err_no_map; + } if (ioreq->presync) bdrv_flush(blkdev->bs); @@ -364,6 +366,9 @@ static int ioreq_runio_qemu_sync(struct ioreq *ioreq) return 0; err: + ioreq_unmap(ioreq); +err_no_map: + ioreq_finish(ioreq); ioreq->status = BLKIF_RSP_ERROR; return -1; } @@ -392,8 +397,10 @@ static int ioreq_runio_qemu_aio(struct ioreq *ioreq) { struct XenBlkDev *blkdev = ioreq->blkdev; - if (ioreq->req.nr_segments && ioreq_map(ioreq) == -1) - goto err; + if (ioreq->req.nr_segments) { + if (ioreq_map(ioreq) == -1) + goto err_no_map; + } ioreq->aio_inflight++; if (ioreq->presync) @@ -425,9 +432,14 @@ static int ioreq_runio_qemu_aio(struct ioreq *ioreq) qemu_aio_complete(ioreq, 0); return 0; + +err_no_map: + ioreq_finish(ioreq); + ioreq->status = BLKIF_RSP_ERROR; + return -1; err: - ioreq->status = BLKIF_RSP_ERROR; + qemu_aio_complete(ioreq, -1); return -1; }