From patchwork Thu Jun 20 18:20:08 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Lieven X-Patchwork-Id: 253057 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 C8F0D2C007B for ; Fri, 21 Jun 2013 04:24:41 +1000 (EST) Received: from localhost ([::1]:43741 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UpjTn-00071U-HS for incoming@patchwork.ozlabs.org; Thu, 20 Jun 2013 14:21:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42639) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UpjT7-0006r4-O1 for qemu-devel@nongnu.org; Thu, 20 Jun 2013 14:20:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UpjT4-0006LX-PM for qemu-devel@nongnu.org; Thu, 20 Jun 2013 14:20:25 -0400 Received: from ssl.dlhnet.de ([91.198.192.8]:43937 helo=ssl.dlh.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UpjT4-0006JU-JY for qemu-devel@nongnu.org; Thu, 20 Jun 2013 14:20:22 -0400 Received: from localhost (localhost [127.0.0.1]) by ssl.dlh.net (Postfix) with ESMTP id 6996714AF14; Thu, 20 Jun 2013 20:20:20 +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 FJThzXCE05tx; Thu, 20 Jun 2013 20:20:16 +0200 (CEST) Received: from trinity64-ssd (unknown [82.141.7.8]) by ssl.dlh.net (Postfix) with ESMTP id 62D3914AF10; Thu, 20 Jun 2013 20:20:16 +0200 (CEST) Received: by trinity64-ssd (Postfix, from userid 1000) id 53B4A201F8F; Thu, 20 Jun 2013 20:20:16 +0200 (CEST) From: Peter Lieven To: qemu-devel@nongnu.org Date: Thu, 20 Jun 2013 20:20:08 +0200 Message-Id: <1371752409-16313-2-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 1/2] iscsi: add support for bdrv_co_is_allocated() 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 Signed-off-by: Peter Lieven --- block/iscsi.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/block/iscsi.c b/block/iscsi.c index 0bbf0b1..e6b966d 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -49,6 +49,7 @@ typedef struct IscsiLun { uint64_t num_blocks; int events; QEMUTimer *nop_timer; + uint8_t lbpme; } IscsiLun; typedef struct IscsiAIOCB { @@ -800,6 +801,60 @@ iscsi_getlength(BlockDriverState *bs) return len; } +static int coroutine_fn iscsi_co_is_allocated(BlockDriverState *bs, + int64_t sector_num, + int nb_sectors, int *pnum) +{ + IscsiLun *iscsilun = bs->opaque; + struct scsi_task *task = NULL; + struct scsi_get_lba_status *lbas = NULL; + struct scsi_lba_status_descriptor *lbasd = NULL; + int ret; + + *pnum = nb_sectors; + + if (iscsilun->lbpme == 0) { + return 1; + } + + /* in-flight requests could invalidate the lba status result */ + while (iscsi_process_flush(iscsilun)) { + qemu_aio_wait(); + } + + task = iscsi_get_lba_status_sync(iscsilun->iscsi, iscsilun->lun, + sector_qemu2lun(sector_num, iscsilun), + 8+16); + + if (task == NULL || task->status != SCSI_STATUS_GOOD) { + scsi_free_scsi_task(task); + return 1; + } + + lbas = scsi_datain_unmarshall(task); + if (lbas == NULL) { + scsi_free_scsi_task(task); + return 1; + } + + lbasd = &lbas->descriptors[0]; + + if (sector_qemu2lun(sector_num, iscsilun) != lbasd->lba) { + return 1; + } + + *pnum = lbasd->num_blocks * (iscsilun->block_size / BDRV_SECTOR_SIZE); + if (*pnum > nb_sectors) { + *pnum = nb_sectors; + } + + ret = (lbasd->provisioning == SCSI_PROVISIONING_TYPE_MAPPED) ? 1 : 0; + + scsi_free_scsi_task(task); + + return ret; +} + static int parse_chap(struct iscsi_context *iscsi, const char *target) { QemuOptsList *list; @@ -948,6 +1003,7 @@ static int iscsi_readcapacity_sync(IscsiLun *iscsilun) } else { iscsilun->block_size = rc16->block_length; iscsilun->num_blocks = rc16->returned_lba + 1; + iscsilun->lbpme = rc16->lbpme; } } break; @@ -1274,6 +1330,7 @@ static BlockDriver bdrv_iscsi = { .bdrv_aio_discard = iscsi_aio_discard, .bdrv_has_zero_init = iscsi_has_zero_init, + .bdrv_co_is_allocated = iscsi_co_is_allocated, #ifdef __linux__ .bdrv_ioctl = iscsi_ioctl,