Hopefully, this will help operating systems in making less misaligned I/O operations. Not really true for Linux, but why not try.
Signed-off-by: Paolo Bonzini <pbonz...@redhat.com> --- block.c | 17 +++++++++++++++++ block.h | 15 ++------------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/block.c b/block.c index 33ccc23..0fce655 100644 --- a/block.c +++ b/block.c @@ -4136,3 +4136,20 @@ bool block_job_is_cancelled(BlockJob *job) { return job->cancelled; } + +unsigned int get_physical_block_exp(BlockConf *conf) +{ + unsigned int exp = 0, size; + + if (conf->physical_block_size || !conf->bs) { + size = conf->physical_block_size; + } else { + size = conf->bs->host_block_size; + } + + for (; size > conf->logical_block_size; size >>= 1) { + exp++; + } + + return exp; +} diff --git a/block.h b/block.h index 34dc925..4270f67 100644 --- a/block.h +++ b/block.h @@ -405,25 +405,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), \ -- 1.7.7.6