mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-04 16:23:55 -06:00
block: Add backend_defaults property
backend_defaults property allow users to control if default block properties should be decided with backend information. If it is off, any backend information will be discarded, which is suitable if you plan to perform live migration to a different disk backend. If it is on, a block device may utilize backend information more aggressively. By default, it is auto, which uses backend information for block sizes and ignores the others, which is consistent with the older versions. Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com> Message-id: 20210705130458.97642-2-akihiko.odaki@gmail.com Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
parent
0dfc7af2b2
commit
12a521b56d
3 changed files with 79 additions and 4 deletions
|
@ -65,24 +65,58 @@ bool blkconf_blocksizes(BlockConf *conf, Error **errp)
|
|||
{
|
||||
BlockBackend *blk = conf->blk;
|
||||
BlockSizes blocksizes;
|
||||
int backend_ret;
|
||||
BlockDriverState *bs;
|
||||
bool use_blocksizes;
|
||||
bool use_bs;
|
||||
|
||||
switch (conf->backend_defaults) {
|
||||
case ON_OFF_AUTO_AUTO:
|
||||
use_blocksizes = !blk_probe_blocksizes(blk, &blocksizes);
|
||||
use_bs = false;
|
||||
break;
|
||||
|
||||
case ON_OFF_AUTO_ON:
|
||||
use_blocksizes = !blk_probe_blocksizes(blk, &blocksizes);
|
||||
bs = blk_bs(blk);
|
||||
use_bs = bs;
|
||||
break;
|
||||
|
||||
case ON_OFF_AUTO_OFF:
|
||||
use_blocksizes = false;
|
||||
use_bs = false;
|
||||
break;
|
||||
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
|
||||
backend_ret = blk_probe_blocksizes(blk, &blocksizes);
|
||||
/* fill in detected values if they are not defined via qemu command line */
|
||||
if (!conf->physical_block_size) {
|
||||
if (!backend_ret) {
|
||||
if (use_blocksizes) {
|
||||
conf->physical_block_size = blocksizes.phys;
|
||||
} else {
|
||||
conf->physical_block_size = BDRV_SECTOR_SIZE;
|
||||
}
|
||||
}
|
||||
if (!conf->logical_block_size) {
|
||||
if (!backend_ret) {
|
||||
if (use_blocksizes) {
|
||||
conf->logical_block_size = blocksizes.log;
|
||||
} else {
|
||||
conf->logical_block_size = BDRV_SECTOR_SIZE;
|
||||
}
|
||||
}
|
||||
if (use_bs) {
|
||||
if (!conf->opt_io_size) {
|
||||
conf->opt_io_size = bs->bl.opt_transfer;
|
||||
}
|
||||
if (conf->discard_granularity == -1) {
|
||||
if (bs->bl.pdiscard_alignment) {
|
||||
conf->discard_granularity = bs->bl.pdiscard_alignment;
|
||||
} else if (bs->bl.request_alignment != 1) {
|
||||
conf->discard_granularity = bs->bl.request_alignment;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (conf->logical_block_size > conf->physical_block_size) {
|
||||
error_setg(errp,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue