Skip to contentSkip to conversation

block: fix physical_block_size calculation

PATCH Superseded Christoph Hellwig 2 participants 3 messages Jun 15, 2010

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block: fix physical_block_size calculation

Both SCSI and virtio expect the physical block size relative to the logical block size. So get the factor first before calculating the log2.

block_int.h +3 -1
Index: qemu/block_int.h
===================================================================
@@ -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++;
     }
 
#1 lore raw

Am 15.06.2010 14:39, schrieb Christoph Hellwig:

Quoted 12 lines

Both SCSI and virtio expect the physical block size relative to the logical block size. So get the factor first before calculating the log2.

Index: qemu/block_int.h
===================================================================

block_int.h static inline unsigned int get_physical_ · line 227

Quoted 6 lines
block_int.h +2 -1
@@ -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

Quoted 5 lines
block_int.h +1 -0
+	 size >>= 1) {
         exp++;
     }
 
#2 lore raw
Quoted 1 line

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.