From patchwork Tue Aug 14 06:44:46 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Priebe - Profihost AG X-Patchwork-Id: 177173 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)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id CE4CA2C0091 for ; Tue, 14 Aug 2012 16:45:04 +1000 (EST) Received: from localhost ([::1]:42137 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T1AsA-0000U4-SK for incoming@patchwork.ozlabs.org; Tue, 14 Aug 2012 02:45:02 -0400 Received: from eggs.gnu.org ([208.118.235.92]:60430) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T1As2-0000Tw-SV for qemu-devel@nongnu.org; Tue, 14 Aug 2012 02:44:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T1As0-00073M-K9 for qemu-devel@nongnu.org; Tue, 14 Aug 2012 02:44:54 -0400 Received: from mail.profihost.ag ([85.158.179.208]:49907) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T1As0-00073E-92 for qemu-devel@nongnu.org; Tue, 14 Aug 2012 02:44:52 -0400 Received: (qmail 8244 invoked from network); 14 Aug 2012 08:44:48 +0200 Received: from fw-office.allied-internet.ag (HELO proxmox2.de-nserver.de) (85.158.179.66) by mail.profihost.ag (qpsmtpd/0.82) with ESMTP; Tue, 14 Aug 2012 08:44:48 +0200 From: Stefan Priebe To: qemu-devel@nongnu.org Date: Tue, 14 Aug 2012 08:44:46 +0200 Message-Id: <1344926686-9197-1-git-send-email-s.priebe@profihost.ag> X-Mailer: git-send-email 1.7.2.5 X-User-Auth: Auth by ip_allowed_85.158.179.66 through 85.158.179.66 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 85.158.179.208 Cc: spriebe Subject: [Qemu-devel] [PATCH] iscsi: fix race between task completition and task abortion 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 From: spriebe Acked-by: Ronnie Sahlberg --- block/iscsi.c | 36 ++++++++++++++++++++---------------- 1 files changed, 20 insertions(+), 16 deletions(-) diff --git a/block/iscsi.c b/block/iscsi.c index 12ca76d..257f97f 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -76,6 +76,10 @@ static void iscsi_abort_task_cb(struct iscsi_context *iscsi, int status, void *command_data, void *private_data) { + IscsiAIOCB *acb = (IscsiAIOCB *)private_data; + + scsi_free_scsi_task(acb->task); + acb->task = NULL; } static void @@ -85,14 +89,19 @@ iscsi_aio_cancel(BlockDriverAIOCB *blockacb) IscsiLun *iscsilun = acb->iscsilun; acb->common.cb(acb->common.opaque, -ECANCELED); - acb->canceled = 1; - /* send a task mgmt call to the target to cancel the task on the target */ - iscsi_task_mgmt_abort_task_async(iscsilun->iscsi, acb->task, - iscsi_abort_task_cb, NULL); + if (acb->canceled != 0) + return; + + acb->canceled = 1; - /* then also cancel the task locally in libiscsi */ - iscsi_scsi_task_cancel(iscsilun->iscsi, acb->task); + /* send a task mgmt call to the target to cancel the task on the target + * this also cancels the task in libiscsi + */ + if (acb->task) { + iscsi_task_mgmt_abort_task_async(iscsilun->iscsi, acb->task, + iscsi_abort_task_cb, &acb); + } } static AIOPool iscsi_aio_pool = { @@ -184,6 +193,11 @@ iscsi_readv_writev_bh_cb(void *p) } qemu_aio_release(acb); + + if (acb->task) { + scsi_free_scsi_task(acb->task); + acb->task = NULL; + } } @@ -212,8 +226,6 @@ iscsi_aio_write16_cb(struct iscsi_context *iscsi, int status, } iscsi_schedule_bh(iscsi_readv_writev_bh_cb, acb); - scsi_free_scsi_task(acb->task); - acb->task = NULL; } static int64_t sector_qemu2lun(int64_t sector, IscsiLun *iscsilun) @@ -313,8 +325,6 @@ iscsi_aio_read16_cb(struct iscsi_context *iscsi, int status, } iscsi_schedule_bh(iscsi_readv_writev_bh_cb, acb); - scsi_free_scsi_task(acb->task); - acb->task = NULL; } static BlockDriverAIOCB * @@ -429,8 +439,6 @@ iscsi_synccache10_cb(struct iscsi_context *iscsi, int status, } iscsi_schedule_bh(iscsi_readv_writev_bh_cb, acb); - scsi_free_scsi_task(acb->task); - acb->task = NULL; } static BlockDriverAIOCB * @@ -483,8 +491,6 @@ iscsi_unmap_cb(struct iscsi_context *iscsi, int status, } iscsi_schedule_bh(iscsi_readv_writev_bh_cb, acb); - scsi_free_scsi_task(acb->task); - acb->task = NULL; } static BlockDriverAIOCB * @@ -560,8 +566,6 @@ iscsi_aio_ioctl_cb(struct iscsi_context *iscsi, int status, } iscsi_schedule_bh(iscsi_readv_writev_bh_cb, acb); - scsi_free_scsi_task(acb->task); - acb->task = NULL; } static BlockDriverAIOCB *iscsi_aio_ioctl(BlockDriverState *bs,