From patchwork Mon Feb 18 12:58:55 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Lieven X-Patchwork-Id: 221352 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 5FF212C1BBB for ; Mon, 18 Feb 2013 23:59:20 +1100 (EST) Received: from localhost ([::1]:35383 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U7QJS-0001k2-Mv for incoming@patchwork.ozlabs.org; Mon, 18 Feb 2013 07:59:18 -0500 Received: from eggs.gnu.org ([208.118.235.92]:41057) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U7QJA-0001iv-Do for qemu-devel@nongnu.org; Mon, 18 Feb 2013 07:59:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U7QJ6-00076p-Bx for qemu-devel@nongnu.org; Mon, 18 Feb 2013 07:59:00 -0500 Received: from ssl.dlhnet.de ([91.198.192.8]:37152 helo=ssl.dlh.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U7QJ6-00076e-1C for qemu-devel@nongnu.org; Mon, 18 Feb 2013 07:58:56 -0500 Received: from localhost (localhost [127.0.0.1]) by ssl.dlh.net (Postfix) with ESMTP id 3E84314D97F; Mon, 18 Feb 2013 13:58:55 +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 4XiyiyaTRCke; Mon, 18 Feb 2013 13:58:54 +0100 (CET) Received: from [172.21.12.60] (unknown [82.141.1.226]) by ssl.dlh.net (Postfix) with ESMTPSA id B000014D8F4; Mon, 18 Feb 2013 13:58:54 +0100 (CET) Message-ID: <5122258F.7070201@dlhnet.de> Date: Mon, 18 Feb 2013 13:58:55 +0100 From: Peter Lieven User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130106 Thunderbird/17.0.2 MIME-Version: 1.0 To: "qemu-devel@nongnu.org" References: <511E14D3.1080001@dlhnet.de> <511E1777.50101@redhat.com> <511E196A.205@dlhnet.de> <511E220B.2090207@redhat.com> <20130215121835.GA14477@dhcp-200-207.str.redhat.com> In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 91.198.192.8 Cc: Kevin Wolf , Paolo Bonzini , ronnie sahlberg Subject: [Qemu-devel] [PATCHv3] iscsi: add iscsi_truncate support 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 this patch adds iscsi_truncate which effectively allows for online resizing of iscsi volumes. for this to work you have to resize the volume on your storage and then call block_resize command in qemu which will issue a readcapacity16 to update the capacity. v3: - remove switch statement in iscsi_open - create separate patch for brdv_drain_all() in bdrv_truncate() v2: - add a general bdrv_drain_all() before bdrv_truncate() to avoid in-flight AIOs while the device is truncated - since no AIOs are in flight we can use a sync libiscsi call to re-read the capacity - factor out the readcapacity16 logic as it is redundant to iscsi_open() and iscsi_truncate(). Signed-off-by: Peter Lieven --- block/iscsi.c | 77 +++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 56 insertions(+), 21 deletions(-) diff --git a/block/iscsi.c b/block/iscsi.c index deb3b68..105533c 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -823,6 +823,35 @@ static void iscsi_nop_timed_event(void *opaque) } #endif +static int iscsi_disk_readcapacity16_sync(IscsiLun *iscsilun) { + struct scsi_task *task = NULL; + struct scsi_readcapacity16 *rc16 = NULL; + + task = iscsi_readcapacity16_sync(iscsilun->iscsi, iscsilun->lun); + if (task == NULL) { + error_report("iSCSI: failed to send readcapacity16 command."); + return -EINVAL; + } + if (task->status != SCSI_STATUS_GOOD) { + error_report("iSCSI: failed to send readcapacity16 command."); + scsi_free_scsi_task(task); + return -EINVAL; + } + rc16 = scsi_datain_unmarshall(task); + if (rc16 == NULL) { + error_report("iSCSI: Failed to unmarshall readcapacity16 data."); + scsi_free_scsi_task(task); + return -EINVAL; + } + + iscsilun->block_size = rc16->block_length; + iscsilun->num_blocks = rc16->returned_lba + 1; + + scsi_free_scsi_task(task); + + return 0; +} + /* * We support iscsi url's on the form * iscsi://[%@][:]// @@ -835,7 +864,6 @@ static int iscsi_open(BlockDriverState *bs, const char *filename, int flags) struct scsi_task *task = NULL; struct scsi_inquiry_standard *inq = NULL; struct scsi_readcapacity10 *rc10 = NULL; - struct scsi_readcapacity16 *rc16 = NULL; char *initiator_name = NULL; int ret; @@ -926,25 +954,14 @@ static int iscsi_open(BlockDriverState *bs, const char *filename, int flags) iscsilun->type = inq->periperal_device_type; scsi_free_scsi_task(task); + task = NULL; - switch (iscsilun->type) { - case TYPE_DISK: - task = iscsi_readcapacity16_sync(iscsi, iscsilun->lun); - if (task == NULL || task->status != SCSI_STATUS_GOOD) { - error_report("iSCSI: failed to send readcapacity16 command."); - ret = -EINVAL; - goto out; - } - rc16 = scsi_datain_unmarshall(task); - if (rc16 == NULL) { - error_report("iSCSI: Failed to unmarshall readcapacity16 data."); - ret = -EINVAL; + if (iscsilun->type == TYPE_DISK) { + if ((ret = iscsi_disk_readcapacity16_sync(iscsilun))) { goto out; } - iscsilun->block_size = rc16->block_length; - iscsilun->num_blocks = rc16->returned_lba + 1; - break; - case TYPE_ROM: + } + if (iscsilun->type == TYPE_ROM) { task = iscsi_readcapacity10_sync(iscsi, iscsilun->lun, 0, 0); if (task == NULL || task->status != SCSI_STATUS_GOOD) { error_report("iSCSI: failed to send readcapacity10 command."); @@ -964,10 +981,7 @@ static int iscsi_open(BlockDriverState *bs, const char *filename, int flags) } else { iscsilun->num_blocks = rc10->lba + 1; } - break; - default: - break; - } + } bs->total_sectors = iscsilun->num_blocks * iscsilun->block_size / BDRV_SECTOR_SIZE ; @@ -1023,6 +1037,26 @@ static void iscsi_close(BlockDriverState *bs) memset(iscsilun, 0, sizeof(IscsiLun)); } +static int iscsi_truncate(BlockDriverState *bs, int64_t offset) +{ + IscsiLun *iscsilun = bs->opaque; + int ret = 0; + + if (iscsilun->type != TYPE_DISK) { + return -ENOTSUP; + } + + if ((ret = iscsi_disk_readcapacity16_sync(iscsilun))) { + return ret; + } + + if (offset > iscsi_getlength(bs)) { + return -EINVAL; + } + + return 0; +} + static int iscsi_has_zero_init(BlockDriverState *bs) { return 0; @@ -1093,6 +1127,7 @@ static BlockDriver bdrv_iscsi = { .create_options = iscsi_create_options, .bdrv_getlength = iscsi_getlength, + .bdrv_truncate = iscsi_truncate, .bdrv_aio_readv = iscsi_aio_readv, .bdrv_aio_writev = iscsi_aio_writev,