From patchwork Thu Jun 20 18:20:09 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Lieven X-Patchwork-Id: 253059 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 9B3C82C00A2 for ; Fri, 21 Jun 2013 04:41:30 +1000 (EST) Received: from localhost ([::1]:43959 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UpjTs-0007Hk-0g for incoming@patchwork.ozlabs.org; Thu, 20 Jun 2013 14:21:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42675) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UpjTA-0006zd-DK for qemu-devel@nongnu.org; Thu, 20 Jun 2013 14:20:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UpjT7-0006M7-0I for qemu-devel@nongnu.org; Thu, 20 Jun 2013 14:20:28 -0400 Received: from ssl.dlhnet.de ([91.198.192.8]:43950 helo=ssl.dlh.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UpjT6-0006Lq-Qn for qemu-devel@nongnu.org; Thu, 20 Jun 2013 14:20:24 -0400 Received: from localhost (localhost [127.0.0.1]) by ssl.dlh.net (Postfix) with ESMTP id 7176814AF0F; Thu, 20 Jun 2013 20:20:24 +0200 (CEST) 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 oU6fLoWrRuO5; Thu, 20 Jun 2013 20:20:20 +0200 (CEST) Received: from trinity64-ssd (unknown [82.141.7.8]) by ssl.dlh.net (Postfix) with ESMTP id 66C4114AF13; Thu, 20 Jun 2013 20:20:16 +0200 (CEST) Received: by trinity64-ssd (Postfix, from userid 1000) id 590FC201F90; Thu, 20 Jun 2013 20:20:16 +0200 (CEST) From: Peter Lieven To: qemu-devel@nongnu.org Date: Thu, 20 Jun 2013 20:20:09 +0200 Message-Id: <1371752409-16313-3-git-send-email-pl@kamp.de> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1371752409-16313-1-git-send-email-pl@kamp.de> References: <1371752409-16313-1-git-send-email-pl@kamp.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 91.198.192.8 Cc: Kevin Wolf , pbonzini@redhat.com, Peter Lieven , ronniesahlberg@gmail.com, Stefan Hajnoczi Subject: [Qemu-devel] [PATCH 2/2] iscsi: add intelligent has_zero_init check 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 iscsi targets are not created by bdrv_create and thus we cannot blindly assume that a target is empty. to avoid writing and allocating blocks of zeroes we now check if all blocks of an existing target are unallocated and return 1 for bdrv_has_zero_init if the target is completely unalloacted and unallocated blocks read as zeroes. Signed-off-by: Peter Lieven --- block/iscsi.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/block/iscsi.c b/block/iscsi.c index e6b966d..fe41d9a 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -50,6 +50,7 @@ typedef struct IscsiLun { int events; QEMUTimer *nop_timer; uint8_t lbpme; + uint8_t lbprz; } IscsiLun; typedef struct IscsiAIOCB { @@ -1004,6 +1005,7 @@ static int iscsi_readcapacity_sync(IscsiLun *iscsilun) iscsilun->block_size = rc16->block_length; iscsilun->num_blocks = rc16->returned_lba + 1; iscsilun->lbpme = rc16->lbpme; + iscsilun->lbprz = rc16->lbprz; } } break; @@ -1249,7 +1251,28 @@ static int iscsi_truncate(BlockDriverState *bs, int64_t offset) static int iscsi_has_zero_init(BlockDriverState *bs) { - return 0; + IscsiLun *iscsilun = bs->opaque; + uint64_t lba; + int n, ret, nb_sectors; + + if (iscsilun->lbprz == 0) { + return 0; + } + + for (lba = 0; lba < iscsilun->num_blocks; lba += 1 << 26) { + nb_sectors = 1 << 26; + if (lba + nb_sectors > iscsilun->num_blocks) { + nb_sectors = iscsilun->num_blocks - lba; + } + nb_sectors *= (iscsilun->block_size / BDRV_SECTOR_SIZE); + n = 0; + ret = iscsi_co_is_allocated(bs, lba, nb_sectors, &n); + if (ret || n != nb_sectors) { + return 0; + } + } + + return 1; } static int iscsi_create(const char *filename, QEMUOptionParameter *options)