From patchwork Fri Aug 17 02:36:20 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ronnie sahlberg X-Patchwork-Id: 178134 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 384992C0089 for ; Fri, 17 Aug 2012 12:36:55 +1000 (EST) Received: from localhost ([::1]:55751 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T2CQf-0003Cr-Ar for incoming@patchwork.ozlabs.org; Thu, 16 Aug 2012 22:36:53 -0400 Received: from eggs.gnu.org ([208.118.235.92]:57275) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T2CQS-00031g-Q0 for qemu-devel@nongnu.org; Thu, 16 Aug 2012 22:36:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T2CQR-0005Wy-NZ for qemu-devel@nongnu.org; Thu, 16 Aug 2012 22:36:40 -0400 Received: from mail-gg0-f173.google.com ([209.85.161.173]:63358) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T2CQR-0005Ws-It for qemu-devel@nongnu.org; Thu, 16 Aug 2012 22:36:39 -0400 Received: by ggna5 with SMTP id a5so3589646ggn.4 for ; Thu, 16 Aug 2012 19:36:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=u1flb2Qp2M0A78KC5/iL5brFYbCOeGe4TpXUep2JPLI=; b=ERRWdNCWdP4UzVkUk9vpt4EZHhSj8XekU4v3wmmC8AYpPxQl29pI++Sz2uLKm4cvML OG7dXavM4v6+JDY8tXc75SRGjErpy+FvKV0FZk4iKVKKz6U+7hHWVgE9CQMHgQrDwfvA DS2S8Uz/b4BOeCQtCzSRN4G8upC073ke9LFjsuQaW/GyQIT+76HjFkJe+7rX/dUH6LJ2 Len9RK7pnGmZjAdbylcakHLp5vQSOJq3t3L7ghjhAacgx7nR/2U7h1TIqY6mRXnAmE0f 9/Jo+ygtpECXSOHgtcMwoIP0FMwNbn1QxzFiynDz7IsXp/klN7GnfR4ghWKXtigYTL1v hATQ== Received: by 10.66.87.138 with SMTP id ay10mr6210124pab.38.1345170998622; Thu, 16 Aug 2012 19:36:38 -0700 (PDT) Received: from ronniesahlberg@gmail.com (CPE-121-217-101-227.lnse2.cht.bigpond.net.au. [121.217.101.227]) by mx.google.com with ESMTPS id qx8sm3859318pbc.63.2012.08.16.19.36.34 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 16 Aug 2012 19:36:38 -0700 (PDT) Received: by ronniesahlberg@gmail.com (sSMTP sendmail emulation); Fri, 17 Aug 2012 12:36:32 +1000 From: Ronnie Sahlberg To: kwolf@redhat.com, qemu-devel@nongnu.org, pbonzini@redhat.com Date: Fri, 17 Aug 2012 12:36:20 +1000 Message-Id: <1345170981-7738-2-git-send-email-ronniesahlberg@gmail.com> X-Mailer: git-send-email 1.7.3.1 In-Reply-To: <1345170981-7738-1-git-send-email-ronniesahlberg@gmail.com> References: <1345170981-7738-1-git-send-email-ronniesahlberg@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.161.173 Cc: Ronnie Sahlberg Subject: [Qemu-devel] [PATCH 1/2] ISCSI: Set number of blocks to 0 for blank CDROM devices 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 The number of blocks of the device is used to compute the device size in bdrv_getlength()/iscsi_getlength(). For MMC devices, the ReturnedLogicalBlockAddress in the READCAPACITY10 has a special meaning when it is 0. In this case it does not mean that LBA 0 is the last accessible LBA, and thus the device has 1 readable block, but instead it means that the disc is blank and there are no readable blocks. This change ensures that when the iSCSI LUN is loaded with a blank DVD-R disk or similar that bdrv_getlength() will return the correct size of the device as 0 bytes. Signed-off-by: Ronnie Sahlberg --- block/iscsi.c | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-) diff --git a/block/iscsi.c b/block/iscsi.c index bb9cf82..fb420ea 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -717,7 +717,12 @@ iscsi_readcapacity10_cb(struct iscsi_context *iscsi, int status, } itask->iscsilun->block_size = rc10->block_size; - itask->iscsilun->num_blocks = rc10->lba + 1; + if (rc10->lba == 0) { + /* blank disk loaded */ + itask->iscsilun->num_blocks = 0; + } else { + itask->iscsilun->num_blocks = rc10->lba + 1; + } itask->bs->total_sectors = itask->iscsilun->num_blocks * itask->iscsilun->block_size / BDRV_SECTOR_SIZE ;