block: Use 'detect-zeroes' option for 'blockdev-change-medium'
Instead of modifying the new BDS after it has been opened, use the newly supported 'detect-zeroes' option in bdrv_open_common() so that all requirements are checked (detect-zeroes=unmap requires discard=unmap). Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com>
This commit is contained in:
parent
692e01a27c
commit
b85114f8cf
|
@ -1592,13 +1592,12 @@ void blk_update_root_state(BlockBackend *blk)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Applies the information in the root state to the given BlockDriverState. This
|
* Returns the detect-zeroes setting to be used for bdrv_open() of a
|
||||||
* does not include the flags which have to be specified for bdrv_open(), use
|
* BlockDriverState which is supposed to inherit the root state.
|
||||||
* blk_get_open_flags_from_root_state() to inquire them.
|
|
||||||
*/
|
*/
|
||||||
void blk_apply_root_state(BlockBackend *blk, BlockDriverState *bs)
|
bool blk_get_detect_zeroes_from_root_state(BlockBackend *blk)
|
||||||
{
|
{
|
||||||
bs->detect_zeroes = blk->root_state.detect_zeroes;
|
return blk->root_state.detect_zeroes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -2546,6 +2546,7 @@ void qmp_blockdev_change_medium(bool has_device, const char *device,
|
||||||
BlockBackend *blk;
|
BlockBackend *blk;
|
||||||
BlockDriverState *medium_bs = NULL;
|
BlockDriverState *medium_bs = NULL;
|
||||||
int bdrv_flags;
|
int bdrv_flags;
|
||||||
|
bool detect_zeroes;
|
||||||
int rc;
|
int rc;
|
||||||
QDict *options = NULL;
|
QDict *options = NULL;
|
||||||
Error *err = NULL;
|
Error *err = NULL;
|
||||||
|
@ -2585,8 +2586,12 @@ void qmp_blockdev_change_medium(bool has_device, const char *device,
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
options = qdict_new();
|
||||||
|
detect_zeroes = blk_get_detect_zeroes_from_root_state(blk);
|
||||||
|
qdict_put(options, "detect-zeroes",
|
||||||
|
qstring_from_str(detect_zeroes ? "on" : "off"));
|
||||||
|
|
||||||
if (has_format) {
|
if (has_format) {
|
||||||
options = qdict_new();
|
|
||||||
qdict_put(options, "driver", qstring_from_str(format));
|
qdict_put(options, "driver", qstring_from_str(format));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2623,8 +2628,6 @@ void qmp_blockdev_change_medium(bool has_device, const char *device,
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
blk_apply_root_state(blk, medium_bs);
|
|
||||||
|
|
||||||
qmp_blockdev_close_tray(has_device, device, has_id, id, errp);
|
qmp_blockdev_close_tray(has_device, device, has_id, id, errp);
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
|
|
|
@ -198,7 +198,7 @@ void blk_io_unplug(BlockBackend *blk);
|
||||||
BlockAcctStats *blk_get_stats(BlockBackend *blk);
|
BlockAcctStats *blk_get_stats(BlockBackend *blk);
|
||||||
BlockBackendRootState *blk_get_root_state(BlockBackend *blk);
|
BlockBackendRootState *blk_get_root_state(BlockBackend *blk);
|
||||||
void blk_update_root_state(BlockBackend *blk);
|
void blk_update_root_state(BlockBackend *blk);
|
||||||
void blk_apply_root_state(BlockBackend *blk, BlockDriverState *bs);
|
bool blk_get_detect_zeroes_from_root_state(BlockBackend *blk);
|
||||||
int blk_get_open_flags_from_root_state(BlockBackend *blk);
|
int blk_get_open_flags_from_root_state(BlockBackend *blk);
|
||||||
|
|
||||||
void *blk_aio_get(const AIOCBInfo *aiocb_info, BlockBackend *blk,
|
void *blk_aio_get(const AIOCBInfo *aiocb_info, BlockBackend *blk,
|
||||||
|
|
Loading…
Reference in New Issue