From patchwork Mon Nov 19 14:58:31 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Lieven X-Patchwork-Id: 200023 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 8BD8B2C00D7 for ; Tue, 20 Nov 2012 01:58:54 +1100 (EST) Received: from localhost ([::1]:34402 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TaSoF-0000dp-9U for incoming@patchwork.ozlabs.org; Mon, 19 Nov 2012 09:58:51 -0500 Received: from eggs.gnu.org ([208.118.235.92]:46776) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TaSo3-0000dQ-Br for qemu-devel@nongnu.org; Mon, 19 Nov 2012 09:58:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TaSnx-0004IS-De for qemu-devel@nongnu.org; Mon, 19 Nov 2012 09:58:39 -0500 Received: from ssl.dlhnet.de ([91.198.192.8]:36177 helo=ssl.dlh.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TaSnx-0004I7-6P for qemu-devel@nongnu.org; Mon, 19 Nov 2012 09:58:33 -0500 Received: from localhost (localhost [127.0.0.1]) by ssl.dlh.net (Postfix) with ESMTP id BF36314BCB4; Mon, 19 Nov 2012 15:58:31 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at ssl.dlh.net Received: from ssl.dlh.net ([127.0.0.1]) by localhost (ssl.dlh.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id T7t8ePRMNz5L; Mon, 19 Nov 2012 15:58:31 +0100 (CET) Received: from [172.21.12.60] (unknown [82.141.1.226]) by ssl.dlh.net (Postfix) with ESMTPSA id A7A8E14B52F; Mon, 19 Nov 2012 15:58:31 +0100 (CET) Message-ID: <50AA4917.5000402@dlhnet.de> Date: Mon, 19 Nov 2012 15:58:31 +0100 From: Peter Lieven User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121028 Thunderbird/16.0.2 MIME-Version: 1.0 To: "qemu-devel@nongnu.org" X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 91.198.192.8 Cc: kwolf@redhat.com, Paolo Bonzini , ronnie sahlberg Subject: [Qemu-devel] [PATCH] iscsi: partly avoid iovec linearization in iscsi_aio_writev 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 libiscsi expects all write16 data in a linear buffer. If the iovec only contains one buffer we can skip the linearization step as well as the additional malloc/free and pass the buffer directly. Reported-by: Ronnie Sahlberg Signed-off-by: Peter Lieven Reviewed-by: Stefan Hajnoczi --- block/iscsi.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/block/iscsi.c b/block/iscsi.c index d0b1a10..f12148e 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -199,8 +199,10 @@ iscsi_aio_write16_cb(struct iscsi_context *iscsi, int status, trace_iscsi_aio_write16_cb(iscsi, status, acb, acb->canceled); - g_free(acb->buf); - + if (acb->buf != NULL) { + g_free(acb->buf); + } + if (acb->canceled != 0) { return; } @@ -244,11 +246,18 @@ iscsi_aio_writev(BlockDriverState *bs, int64_t sector_num, acb->bh = NULL; acb->status = -EINPROGRESS; - /* XXX we should pass the iovec to write16 to avoid the extra copy */ - /* this will allow us to get rid of 'buf' completely */ size = nb_sectors * BDRV_SECTOR_SIZE; - acb->buf = g_malloc(size); - qemu_iovec_to_buf(acb->qiov, 0, acb->buf, size); + data.size = size; + + /* if the iovec only contains one buffer we can pass it directly */ + if (acb->qiov->niov == 1) { + acb->buf = NULL; + data.data = acb->qiov->iov[0].iov_base; + } else { + acb->buf = g_malloc(size); + qemu_iovec_to_buf(acb->qiov, 0, acb->buf, size); + data.data = acb->buf; + } acb->task = malloc(sizeof(struct scsi_task)); if (acb->task == NULL) { @@ -269,9 +278,6 @@ iscsi_aio_writev(BlockDriverState *bs, int64_t sector_num, *(uint32_t *)&acb->task->cdb[10] = htonl(num_sectors); acb->task->expxferlen = size; - data.data = acb->buf; - data.size = size; - if (iscsi_scsi_command_async(iscsi, iscsilun->lun, acb->task, iscsi_aio_write16_cb, &data,