diff mbox

block: fix physical_block_size calculation

Message ID 20100615123936.GA25281@lst.de
State New
Headers show

Commit Message

Christoph Hellwig June 15, 2010, 12:39 p.m. UTC
Both SCSI and virtio expect the physical block size relative to the
logical block size.  So get the factor first before calculating the
log2.  

Reported-by: Mike Cao <bcao@redhat.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>

Comments

Kevin Wolf June 15, 2010, 1:48 p.m. UTC | #1
Am 15.06.2010 14:39, schrieb Christoph Hellwig:
> Both SCSI and virtio expect the physical block size relative to the
> logical block size.  So get the factor first before calculating the
> log2.  
> 
> Reported-by: Mike Cao <bcao@redhat.com>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> 
> Index: qemu/block_int.h
> ===================================================================
> --- qemu.orig/block_int.h	2010-06-15 14:29:42.593012221 +0200
> +++ qemu/block_int.h	2010-06-15 14:30:00.164034570 +0200
> @@ -223,7 +223,9 @@ static inline unsigned int get_physical_
>  {
>      unsigned int exp = 0, size;
>  
> -    for (size = conf->physical_block_size; size > 512; size >>= 1) {
> +    for (size = conf->physical_block_size / conf->logical_block_size;
> +         size > 512;

512 looks wrong now that size is the number of logical blocks.

Kevin

> +	 size >>= 1) {
>          exp++;
>      }
>  
>
Christoph Hellwig June 15, 2010, 3:52 p.m. UTC | #2
> 512 looks wrong now that size is the number of logical blocks.

The patch is entirely wrong, and only happen to work for the case
I was testing by accident.  I'll resend a fixed version after I
created a little userspace test harness for all useful values.
diff mbox

Patch

Index: qemu/block_int.h
===================================================================
--- qemu.orig/block_int.h	2010-06-15 14:29:42.593012221 +0200
+++ qemu/block_int.h	2010-06-15 14:30:00.164034570 +0200
@@ -223,7 +223,9 @@  static inline unsigned int get_physical_
 {
     unsigned int exp = 0, size;
 
-    for (size = conf->physical_block_size; size > 512; size >>= 1) {
+    for (size = conf->physical_block_size / conf->logical_block_size;
+         size > 512;
+	 size >>= 1) {
         exp++;
     }