Patchwork [16/17] block: default physical block size to host block size

login
register
mail settings
Submitter Paolo Bonzini
Date Dec. 13, 2011, 12:37 p.m.
Message ID <1323779840-4235-17-git-send-email-pbonzini@redhat.com>
Download mbox | patch
Permalink /patch/131082/
State New
Headers show

Comments

Paolo Bonzini - Dec. 13, 2011, 12:37 p.m.
Hopefully, this will help operating systems and they will make less
misaligned I/O operations.  Or on Linux, at least fdisk will tell the
user that they should try and align partitions.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 block.c |   17 +++++++++++++++++
 block.h |   15 ++-------------
 2 files changed, 19 insertions(+), 13 deletions(-)

Patch

diff --git a/block.c b/block.c
index 44f5d83..1bfadaf 100644
--- a/block.c
+++ b/block.c
@@ -4041,3 +4041,20 @@  out:
 
     return ret;
 }
+
+unsigned int get_physical_block_exp(BlockConf *conf)
+{
+    unsigned int exp = 0, size;
+
+    if (conf->bs && !conf->physical_block_size) {
+        size = conf->bs->host_block_size;
+    } else {
+        size = conf->physical_block_size;
+    }
+
+    for (; size > conf->logical_block_size; size >>= 1) {
+        exp++;
+    }
+
+    return exp;
+}
diff --git a/block.h b/block.h
index e088146..67594d4 100644
--- a/block.h
+++ b/block.h
@@ -401,25 +401,14 @@  typedef struct BlockConf {
     uint32_t discard_granularity;
 } BlockConf;
 
-static inline unsigned int get_physical_block_exp(BlockConf *conf)
-{
-    unsigned int exp = 0, size;
-
-    for (size = conf->physical_block_size;
-        size > conf->logical_block_size;
-        size >>= 1) {
-        exp++;
-    }
-
-    return exp;
-}
+unsigned int get_physical_block_exp(BlockConf *conf);
 
 #define DEFINE_BLOCK_PROPERTIES(_state, _conf)                          \
     DEFINE_PROP_DRIVE("drive", _state, _conf.bs),                       \
     DEFINE_PROP_UINT16("logical_block_size", _state,                    \
                        _conf.logical_block_size, 512),                  \
     DEFINE_PROP_UINT16("physical_block_size", _state,                   \
-                       _conf.physical_block_size, 512),                 \
+                       _conf.physical_block_size, 0),                 \
     DEFINE_PROP_UINT16("min_io_size", _state, _conf.min_io_size, 0),  \
     DEFINE_PROP_UINT32("opt_io_size", _state, _conf.opt_io_size, 0),    \
     DEFINE_PROP_INT32("bootindex", _state, _conf.bootindex, -1),        \