]> git.proxmox.com Git - mirror_qemu.git/commitdiff
iscsi: Set number of blocks to 0 for blank CDROM devices
authorRonnie Sahlberg <ronniesahlberg@gmail.com>
Fri, 17 Aug 2012 02:36:20 +0000 (12:36 +1000)
committerPaolo Bonzini <pbonzini@redhat.com>
Tue, 28 Aug 2012 12:50:08 +0000 (14:50 +0200)
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 <ronniesahlberg@gmail.com>
block/iscsi.c

index 4828b83927614776249f9b0292c1145f934129cf..0b96165ec2fab100f2e26d6b26b7b0d8f79f7f89 100644 (file)
@@ -721,7 +721,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 ;