From patchwork Thu Jul 11 12:16:18 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Lieven X-Patchwork-Id: 258433 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 ACE502C02BF for ; Thu, 11 Jul 2013 22:19:16 +1000 (EST) Received: from localhost ([::1]:58406 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UxFq6-0006Fu-9b for incoming@patchwork.ozlabs.org; Thu, 11 Jul 2013 08:19:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48414) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UxFoE-0003YN-7K for qemu-devel@nongnu.org; Thu, 11 Jul 2013 08:17:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UxFoA-0005MF-N0 for qemu-devel@nongnu.org; Thu, 11 Jul 2013 08:17:18 -0400 Received: from mx.ipv6.kamp.de ([2a02:248:0:51::16]:46558 helo=mx01.kamp.de) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1UxFoA-0005L1-BL for qemu-devel@nongnu.org; Thu, 11 Jul 2013 08:17:14 -0400 Received: (qmail 12371 invoked by uid 89); 11 Jul 2013 12:17:12 -0000 Received: from [82.141.1.145] by client-16-kamp (envelope-from , uid 89) with qmail-scanner-2.01 (clamdscan: 0.97.8/17487. hbedv: 8.2.12.74/7.11.89.254. spamassassin: 3.3.1. Clear:RC:1(82.141.1.145):SA:0(-1.2/5.0):. Processed in 1.408502 secs); 11 Jul 2013 12:17:12 -0000 Received: from ns.kamp-intra.net (HELO dns.kamp-intra.net) ([82.141.1.145]) by mx01.kamp.de with SMTP; 11 Jul 2013 12:17:10 -0000 X-GL_Whitelist: yes Received: from lieven-pc.kamp-intra.net (lieven-pc.kamp-intra.net [172.21.12.60]) by dns.kamp-intra.net (Postfix) with ESMTP id BA5E220695; Thu, 11 Jul 2013 14:16:30 +0200 (CEST) Received: by lieven-pc.kamp-intra.net (Postfix, from userid 1000) id 87A776117F; Thu, 11 Jul 2013 14:16:34 +0200 (CEST) From: Peter Lieven To: qemu-devel@nongnu.org Date: Thu, 11 Jul 2013 14:16:18 +0200 Message-Id: <1373544987-20613-2-git-send-email-pl@kamp.de> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1373544987-20613-1-git-send-email-pl@kamp.de> References: <1373544987-20613-1-git-send-email-pl@kamp.de> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a02:248:0:51::16 Cc: kwolf@redhat.com, pbonzini@redhat.com, Peter Lieven , ronniesahlberg@gmail.com, stefanha@redhat.com Subject: [Qemu-devel] [PATCHv3 01/10] iscsi: add logical block provisioning information to iscsilun 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 | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/block/iscsi.c b/block/iscsi.c index 0bbf0b1..c802e38 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -49,6 +49,12 @@ typedef struct IscsiLun { uint64_t num_blocks; int events; QEMUTimer *nop_timer; + uint8_t lbpme; + uint8_t lbprz; + uint8_t lbpu; + uint8_t lbpws; + uint8_t lbpws10; + uint32_t max_unmap; } IscsiLun; typedef struct IscsiAIOCB { @@ -73,6 +79,7 @@ typedef struct IscsiAIOCB { #define NOP_INTERVAL 5000 #define MAX_NOP_FAILURES 3 #define ISCSI_CMD_RETRIES 5 +#define ISCSI_MAX_UNMAP 131072 static void iscsi_bh_cb(void *p) @@ -948,6 +955,8 @@ 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; + iscsilun->lbprz = rc16->lbprz; } } break; @@ -1000,6 +1009,37 @@ static QemuOptsList runtime_opts = { }, }; +static struct scsi_task *iscsi_do_inquiry(struct iscsi_context *iscsi, + int lun, int evpd, int pc) { + int full_size; + struct scsi_task *task = NULL; + task = iscsi_inquiry_sync(iscsi, lun, evpd, pc, 64); + if (task == NULL || task->status != SCSI_STATUS_GOOD) { + goto fail; + } + full_size = scsi_datain_getfullsize(task); + if (full_size > task->datain.size) { + scsi_free_scsi_task(task); + + /* we need more data for the full list */ + task = iscsi_inquiry_sync(iscsi, lun, evpd, pc, full_size); + if (task == NULL || task->status != SCSI_STATUS_GOOD) { + goto fail; + } + } + + return task; + +fail: + error_report("iSCSI: Inquiry command failed : %s", + iscsi_get_error(iscsi)); + if (task) { + scsi_free_scsi_task(task); + return NULL; + } + return NULL; +} + /* * We support iscsi url's on the form * iscsi://[%@][:]// @@ -1130,6 +1170,49 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags) bs->sg = 1; } + if (iscsilun->lbpme) { + struct scsi_inquiry_logical_block_provisioning *inq_lbp; + task = iscsi_do_inquiry(iscsilun->iscsi, iscsilun->lun, 1, + SCSI_INQUIRY_PAGECODE_LOGICAL_BLOCK_PROVISIONING); + if (task == NULL) { + ret = -EINVAL; + goto out; + } + inq_lbp = scsi_datain_unmarshall(task); + if (inq_lbp == NULL) { + error_report("iSCSI: failed to unmarshall inquiry datain blob"); + ret = -EINVAL; + goto out; + } + iscsilun->lbpu = inq_lbp->lbpu; + iscsilun->lbpws = inq_lbp->lbpws; + iscsilun->lbpws10 = inq_lbp->lbpws10; + scsi_free_scsi_task(task); + task = NULL; + } + + if (iscsilun->lbpu) { + struct scsi_inquiry_block_limits *inq_bl; + task = iscsi_do_inquiry(iscsilun->iscsi, iscsilun->lun, 1, + SCSI_INQUIRY_PAGECODE_BLOCK_LIMITS); + if (task == NULL) { + ret = -EINVAL; + goto out; + } + inq_bl = scsi_datain_unmarshall(task); + if (inq_bl == NULL) { + error_report("iSCSI: failed to unmarshall inquiry datain blob"); + ret = -EINVAL; + goto out; + } + iscsilun->max_unmap = inq_bl->max_unmap; + if (iscsilun->max_unmap == 0xffffffff) { + iscsilun->max_unmap = ISCSI_MAX_UNMAP; + } + scsi_free_scsi_task(task); + task = NULL; + } + #if defined(LIBISCSI_FEATURE_NOP_COUNTER) /* Set up a timer for sending out iSCSI NOPs */ iscsilun->nop_timer = qemu_new_timer_ms(rt_clock, iscsi_nop_timed_event, iscsilun);