From patchwork Wed Jul 17 15:05:20 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 259703 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)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id C37972C0098 for ; Thu, 18 Jul 2013 01:09:32 +1000 (EST) Received: from localhost ([::1]:42421 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UzTMA-00054W-6h for incoming@patchwork.ozlabs.org; Wed, 17 Jul 2013 11:09:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37004) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UzTLj-0004ra-Ml for qemu-devel@nongnu.org; Wed, 17 Jul 2013 11:09:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UzTLh-00010m-NV for qemu-devel@nongnu.org; Wed, 17 Jul 2013 11:09:03 -0400 Received: from mail-ea0-x233.google.com ([2a00:1450:4013:c01::233]:58747) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UzTIM-0000HN-39; Wed, 17 Jul 2013 11:05:34 -0400 Received: by mail-ea0-f179.google.com with SMTP id b15so1117566eae.24 for ; Wed, 17 Jul 2013 08:05:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=A7dtrvINWxYSop6pRROLjb8WjJP2Wtmls4q0+sKoJ3Q=; b=OGSfOBJj8/lC/oST03Y0cfyKEH14h/amCEnBk4CZ6cFZUScYe7pDdJps4sMv9fvdsX F4HiXv+mbrlhq1+lKHgszgOFI4BZrhg1Rl3HilWU+VqaAz8tUaN4Q205gkMQmUv2bjj3 eu8zxTZtBe7O/KzLDJzZV5swDCQKrVmHAkNmnH99NwrEOtFlrwcYg2SgawqMlJM1u7Le 5zYIDurfzi8e1C7pPWcF7rNuFWPXhNdbipl1w4pwg18EbWOb3IcGIBF4C6T7yJLRF4Zf zypjqCXQqtdX+NALyoY5G7Ed72V4jbLpO8qr61LuHnMVt8nqtcIAQoPuQH+DcF5Flj07 RWdg== X-Received: by 10.14.149.2 with SMTP id w2mr6676750eej.126.1374073533135; Wed, 17 Jul 2013 08:05:33 -0700 (PDT) Received: from playground.lan (net-2-39-8-162.cust.dsl.vodafone.it. [2.39.8.162]) by mx.google.com with ESMTPSA id m1sm11365488eex.17.2013.07.17.08.05.30 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 17 Jul 2013 08:05:31 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 17 Jul 2013 17:05:20 +0200 Message-Id: <1374073524-8469-2-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.1.4 In-Reply-To: <1374073524-8469-1-git-send-email-pbonzini@redhat.com> References: <1374073524-8469-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4013:c01::233 Cc: qemu-stable@nongnu.org, Ronnie Sahlberg Subject: [Qemu-devel] [PULL 1/5] Fix iSCSI crash on SG_IO with an iovector 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: Ronnie Sahlberg Don't assume that SG_IO is always invoked with a simple buffer, check the iovec_count and if it is >= 1 then we need to pass an array of iovectors to libiscsi instead of just a plain buffer. Signed-off-by: Ronnie Sahlberg Cc: qemu-stable@nongnu.org Signed-off-by: Paolo Bonzini --- block/iscsi.c | 51 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 7 deletions(-) diff --git a/block/iscsi.c b/block/iscsi.c index 0bbf0b1..fa5252c 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -32,6 +32,7 @@ #include "block/block_int.h" #include "trace.h" #include "block/scsi.h" +#include "qemu/iov.h" #include #include @@ -651,6 +652,9 @@ iscsi_aio_ioctl_cb(struct iscsi_context *iscsi, int status, { IscsiAIOCB *acb = opaque; + g_free(acb->buf); + acb->buf = NULL; + if (acb->canceled != 0) { return; } @@ -727,14 +731,30 @@ static BlockDriverAIOCB *iscsi_aio_ioctl(BlockDriverState *bs, memcpy(&acb->task->cdb[0], acb->ioh->cmdp, acb->ioh->cmd_len); acb->task->expxferlen = acb->ioh->dxfer_len; + data.size = 0; if (acb->task->xfer_dir == SCSI_XFER_WRITE) { - data.data = acb->ioh->dxferp; - data.size = acb->ioh->dxfer_len; + if (acb->ioh->iovec_count == 0) { + data.data = acb->ioh->dxferp; + data.size = acb->ioh->dxfer_len; + } else { +#if defined(LIBISCSI_FEATURE_IOVECTOR) + scsi_task_set_iov_out(acb->task, + (struct scsi_iovec *) acb->ioh->dxferp, + acb->ioh->iovec_count); +#else + struct iovec *iov = (struct iovec *)acb->ioh->dxferp; + + acb->buf = g_malloc(acb->ioh->dxfer_len); + data.data = acb->buf; + data.size = iov_to_buf(iov, acb->ioh->iovec_count, 0, + acb->buf, acb->ioh->dxfer_len); +#endif + } } + if (iscsi_scsi_command_async(iscsi, iscsilun->lun, acb->task, iscsi_aio_ioctl_cb, - (acb->task->xfer_dir == SCSI_XFER_WRITE) ? - &data : NULL, + (data.size > 0) ? &data : NULL, acb) != 0) { scsi_free_scsi_task(acb->task); qemu_aio_release(acb); @@ -743,9 +763,26 @@ static BlockDriverAIOCB *iscsi_aio_ioctl(BlockDriverState *bs, /* tell libiscsi to read straight into the buffer we got from ioctl */ if (acb->task->xfer_dir == SCSI_XFER_READ) { - scsi_task_add_data_in_buffer(acb->task, - acb->ioh->dxfer_len, - acb->ioh->dxferp); + if (acb->ioh->iovec_count == 0) { + scsi_task_add_data_in_buffer(acb->task, + acb->ioh->dxfer_len, + acb->ioh->dxferp); + } else { +#if defined(LIBISCSI_FEATURE_IOVECTOR) + scsi_task_set_iov_in(acb->task, + (struct scsi_iovec *) acb->ioh->dxferp, + acb->ioh->iovec_count); +#else + int i; + for (i = 0; i < acb->ioh->iovec_count; i++) { + struct iovec *iov = (struct iovec *)acb->ioh->dxferp; + + scsi_task_add_data_in_buffer(acb->task, + iov[i].iov_len, + iov[i].iov_base); + } +#endif + } } iscsi_set_events(iscsilun);