From patchwork Wed Jun 27 16:22:58 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 167702 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 E3E3F100828 for ; Thu, 28 Jun 2012 02:23:16 +1000 (EST) Received: from localhost ([::1]:37435 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sjv1N-0006mh-So for incoming@patchwork.ozlabs.org; Wed, 27 Jun 2012 12:23:13 -0400 Received: from eggs.gnu.org ([208.118.235.92]:37699) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sjv1H-0006mZ-7q for qemu-devel@nongnu.org; Wed, 27 Jun 2012 12:23:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sjv1A-0008SU-V3 for qemu-devel@nongnu.org; Wed, 27 Jun 2012 12:23:06 -0400 Received: from verein.lst.de ([213.95.11.211]:51047 helo=newverein.lst.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sjv1A-0008RI-Om for qemu-devel@nongnu.org; Wed, 27 Jun 2012 12:23:00 -0400 Received: by newverein.lst.de (Postfix, from userid 2407) id B9CF3146FA; Wed, 27 Jun 2012 18:22:58 +0200 (CEST) Date: Wed, 27 Jun 2012 18:22:58 +0200 From: Christoph Hellwig To: qemu-devel@nongnu.org, sheepdog@lists.wpkg.org Message-ID: <20120627162258.GA13391@lst.de> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.17 (2007-11-01) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 213.95.11.211 Subject: [Qemu-devel] [PATCH] sheepdog: do not blindly memset all read buffers 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 Only buffers that map to unallocated blocks need to be zeroed. Signed-off-by: Christoph Hellwig Index: qemu/block/sheepdog.c =================================================================== --- qemu.orig/block/sheepdog.c 2012-06-27 18:02:41.849867899 +0200 +++ qemu/block/sheepdog.c 2012-06-27 18:08:35.929865783 +0200 @@ -1556,18 +1556,24 @@ static int coroutine_fn sd_co_rw_vector( len = MIN(total - done, SD_DATA_OBJ_SIZE - offset); - if (!inode->data_vdi_id[idx]) { - if (acb->aiocb_type == AIOCB_READ_UDATA) { + + switch (acb->aiocb_type) { + case AIOCB_READ_UDATA: + if (!inode->data_vdi_id[idx]) { + qemu_iovec_memset_skip(acb->qiov, 0, len, offset); goto done; } - - create = 1; - } else if (acb->aiocb_type == AIOCB_WRITE_UDATA - && !is_data_obj_writable(inode, idx)) { - /* Copy-On-Write */ - create = 1; - old_oid = oid; - flags = SD_FLAG_CMD_COW; + break; + case AIOCB_WRITE_UDATA: + if (!inode->data_vdi_id[idx]) { + create = 1; + } else if (!is_data_obj_writable(inode, idx)) { + /* Copy-On-Write */ + create = 1; + old_oid = oid; + flags = SD_FLAG_CMD_COW; + } + break; } if (create) { @@ -1655,20 +1661,12 @@ static coroutine_fn int sd_co_readv(Bloc int nb_sectors, QEMUIOVector *qiov) { SheepdogAIOCB *acb; - int i, ret; + int ret; acb = sd_aio_setup(bs, qiov, sector_num, nb_sectors, NULL, NULL); acb->aiocb_type = AIOCB_READ_UDATA; acb->aio_done_func = sd_finish_aiocb; - /* - * TODO: we can do better; we don't need to initialize - * blindly. - */ - for (i = 0; i < qiov->niov; i++) { - memset(qiov->iov[i].iov_base, 0, qiov->iov[i].iov_len); - } - ret = sd_co_rw_vector(acb); if (ret <= 0) { qemu_aio_release(acb);