mirror of
https://github.com/izzy2lost/xemu.git
synced 2026-07-06 00:20:22 -07:00
Merge remote-tracking branch 'remotes/kevin/tags/for-upstream' into staging
Block patches for 2.1.0-rc0 # gpg: Signature made Fri 27 Jun 2014 19:50:32 BST using RSA key ID C88F2FD6 # gpg: Good signature from "Kevin Wolf <kwolf@redhat.com>" * remotes/kevin/tags/for-upstream: (47 commits) iotests: Fix 083 for out-of-tree builds iotests: Drop Python version from 065's Shebang iotests: Use $PYTHON for Python scripts iotests: Source common.env configure: Enable out-of-tree iotests iotests: Allow out-of-tree run block.c: Don't return success for bdrv_append_temp_snapshot() failure qemu-iotests: Add TestRepairQuorum to 041 to test drive-mirror node-name mode. block: Add replaces argument to drive-mirror blockjob: Fix recent BLOCK_JOB_ERROR regression blockjob: Fix recent BLOCK_JOB_READY regression virtio-blk: Rename complete_request_early to complete_request_vring virtio-blk: Unify {non-,}dataplane's request handlings virtio-blk: Schedule BH in the right context virtio-blk: Export request handling functions to dataplane virtio-blk: Make request completion function virtual block: acquire AioContext in qmp_query_blockstats() block: make bdrv_query_stats() static virtio-blk: Fix and clean up the in_sg and out_sg check virtio-blk: Fill in VirtIOBlockReq.out in dataplane code ... Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
@@ -831,7 +831,7 @@ static int bdrv_open_flags(BlockDriverState *bs, int flags)
|
||||
* Clear flags that are internal to the block layer before opening the
|
||||
* image.
|
||||
*/
|
||||
open_flags &= ~(BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING);
|
||||
open_flags &= ~(BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING | BDRV_O_PROTOCOL);
|
||||
|
||||
/*
|
||||
* Snapshots should be writable.
|
||||
@@ -928,6 +928,7 @@ static int bdrv_open_common(BlockDriverState *bs, BlockDriverState *file,
|
||||
bs->zero_beyond_eof = true;
|
||||
open_flags = bdrv_open_flags(bs, flags);
|
||||
bs->read_only = !(open_flags & BDRV_O_RDWR);
|
||||
bs->growable = !!(flags & BDRV_O_PROTOCOL);
|
||||
|
||||
if (use_bdrv_whitelist && !bdrv_is_whitelisted(drv, bs->read_only)) {
|
||||
error_setg(errp,
|
||||
@@ -1005,94 +1006,124 @@ free_and_fail:
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Opens a file using a protocol (file, host_device, nbd, ...)
|
||||
*
|
||||
* options is an indirect pointer to a QDict of options to pass to the block
|
||||
* drivers, or pointer to NULL for an empty set of options. If this function
|
||||
* takes ownership of the QDict reference, it will set *options to NULL;
|
||||
* otherwise, it will contain unused/unrecognized options after this function
|
||||
* returns. Then, the caller is responsible for freeing it. If it intends to
|
||||
* reuse the QDict, QINCREF() should be called beforehand.
|
||||
*/
|
||||
static int bdrv_file_open(BlockDriverState *bs, const char *filename,
|
||||
QDict **options, int flags, Error **errp)
|
||||
static QDict *parse_json_filename(const char *filename, Error **errp)
|
||||
{
|
||||
BlockDriver *drv;
|
||||
const char *drvname;
|
||||
bool parse_filename = false;
|
||||
Error *local_err = NULL;
|
||||
QObject *options_obj;
|
||||
QDict *options;
|
||||
int ret;
|
||||
|
||||
ret = strstart(filename, "json:", &filename);
|
||||
assert(ret);
|
||||
|
||||
options_obj = qobject_from_json(filename);
|
||||
if (!options_obj) {
|
||||
error_setg(errp, "Could not parse the JSON options");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (qobject_type(options_obj) != QTYPE_QDICT) {
|
||||
qobject_decref(options_obj);
|
||||
error_setg(errp, "Invalid JSON object given");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
options = qobject_to_qdict(options_obj);
|
||||
qdict_flatten(options);
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
/*
|
||||
* Fills in default options for opening images and converts the legacy
|
||||
* filename/flags pair to option QDict entries.
|
||||
*/
|
||||
static int bdrv_fill_options(QDict **options, const char **pfilename, int flags,
|
||||
BlockDriver *drv, Error **errp)
|
||||
{
|
||||
const char *filename = *pfilename;
|
||||
const char *drvname;
|
||||
bool protocol = flags & BDRV_O_PROTOCOL;
|
||||
bool parse_filename = false;
|
||||
Error *local_err = NULL;
|
||||
|
||||
/* Parse json: pseudo-protocol */
|
||||
if (filename && g_str_has_prefix(filename, "json:")) {
|
||||
QDict *json_options = parse_json_filename(filename, &local_err);
|
||||
if (local_err) {
|
||||
error_propagate(errp, local_err);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Options given in the filename have lower priority than options
|
||||
* specified directly */
|
||||
qdict_join(*options, json_options, false);
|
||||
QDECREF(json_options);
|
||||
*pfilename = filename = NULL;
|
||||
}
|
||||
|
||||
/* Fetch the file name from the options QDict if necessary */
|
||||
if (!filename) {
|
||||
filename = qdict_get_try_str(*options, "filename");
|
||||
} else if (filename && !qdict_haskey(*options, "filename")) {
|
||||
qdict_put(*options, "filename", qstring_from_str(filename));
|
||||
parse_filename = true;
|
||||
} else {
|
||||
error_setg(errp, "Can't specify 'file' and 'filename' options at the "
|
||||
"same time");
|
||||
ret = -EINVAL;
|
||||
goto fail;
|
||||
if (protocol && filename) {
|
||||
if (!qdict_haskey(*options, "filename")) {
|
||||
qdict_put(*options, "filename", qstring_from_str(filename));
|
||||
parse_filename = true;
|
||||
} else {
|
||||
error_setg(errp, "Can't specify 'file' and 'filename' options at "
|
||||
"the same time");
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
/* Find the right block driver */
|
||||
filename = qdict_get_try_str(*options, "filename");
|
||||
drvname = qdict_get_try_str(*options, "driver");
|
||||
if (drvname) {
|
||||
drv = bdrv_find_format(drvname);
|
||||
if (!drv) {
|
||||
error_setg(errp, "Unknown driver '%s'", drvname);
|
||||
}
|
||||
qdict_del(*options, "driver");
|
||||
} else if (filename) {
|
||||
drv = bdrv_find_protocol(filename, parse_filename);
|
||||
if (!drv) {
|
||||
error_setg(errp, "Unknown protocol");
|
||||
|
||||
if (drv) {
|
||||
if (drvname) {
|
||||
error_setg(errp, "Driver specified twice");
|
||||
return -EINVAL;
|
||||
}
|
||||
drvname = drv->format_name;
|
||||
qdict_put(*options, "driver", qstring_from_str(drvname));
|
||||
} else {
|
||||
error_setg(errp, "Must specify either driver or file");
|
||||
drv = NULL;
|
||||
if (!drvname && protocol) {
|
||||
if (filename) {
|
||||
drv = bdrv_find_protocol(filename, parse_filename);
|
||||
if (!drv) {
|
||||
error_setg(errp, "Unknown protocol");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
drvname = drv->format_name;
|
||||
qdict_put(*options, "driver", qstring_from_str(drvname));
|
||||
} else {
|
||||
error_setg(errp, "Must specify either driver or file");
|
||||
return -EINVAL;
|
||||
}
|
||||
} else if (drvname) {
|
||||
drv = bdrv_find_format(drvname);
|
||||
if (!drv) {
|
||||
error_setg(errp, "Unknown driver '%s'", drvname);
|
||||
return -ENOENT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!drv) {
|
||||
/* errp has been set already */
|
||||
ret = -ENOENT;
|
||||
goto fail;
|
||||
}
|
||||
assert(drv || !protocol);
|
||||
|
||||
/* Parse the filename and open it */
|
||||
if (drv->bdrv_parse_filename && parse_filename) {
|
||||
/* Driver-specific filename parsing */
|
||||
if (drv && drv->bdrv_parse_filename && parse_filename) {
|
||||
drv->bdrv_parse_filename(filename, *options, &local_err);
|
||||
if (local_err) {
|
||||
error_propagate(errp, local_err);
|
||||
ret = -EINVAL;
|
||||
goto fail;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!drv->bdrv_needs_filename) {
|
||||
qdict_del(*options, "filename");
|
||||
} else {
|
||||
filename = qdict_get_str(*options, "filename");
|
||||
}
|
||||
}
|
||||
|
||||
if (!drv->bdrv_file_open) {
|
||||
ret = bdrv_open(&bs, filename, NULL, *options, flags, drv, &local_err);
|
||||
*options = NULL;
|
||||
} else {
|
||||
ret = bdrv_open_common(bs, NULL, *options, flags, drv, &local_err);
|
||||
}
|
||||
if (ret < 0) {
|
||||
error_propagate(errp, local_err);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
bs->growable = 1;
|
||||
return 0;
|
||||
|
||||
fail:
|
||||
return ret;
|
||||
}
|
||||
|
||||
void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd)
|
||||
@@ -1162,6 +1193,13 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp)
|
||||
bdrv_get_full_backing_filename(bs, backing_filename, PATH_MAX);
|
||||
}
|
||||
|
||||
if (!bs->drv || !bs->drv->supports_backing) {
|
||||
ret = -EINVAL;
|
||||
error_setg(errp, "Driver doesn't support backing files");
|
||||
QDECREF(options);
|
||||
goto free_exit;
|
||||
}
|
||||
|
||||
backing_hd = bdrv_new("", errp);
|
||||
|
||||
if (bs->backing_format[0] != '\0') {
|
||||
@@ -1240,7 +1278,7 @@ done:
|
||||
return ret;
|
||||
}
|
||||
|
||||
void bdrv_append_temp_snapshot(BlockDriverState *bs, int flags, Error **errp)
|
||||
int bdrv_append_temp_snapshot(BlockDriverState *bs, int flags, Error **errp)
|
||||
{
|
||||
/* TODO: extra byte is a hack to ensure MAX_PATH space on Windows. */
|
||||
char *tmp_filename = g_malloc0(PATH_MAX + 1);
|
||||
@@ -1258,6 +1296,7 @@ void bdrv_append_temp_snapshot(BlockDriverState *bs, int flags, Error **errp)
|
||||
/* Get the required size from the image */
|
||||
total_size = bdrv_getlength(bs);
|
||||
if (total_size < 0) {
|
||||
ret = total_size;
|
||||
error_setg_errno(errp, -total_size, "Could not get image size");
|
||||
goto out;
|
||||
}
|
||||
@@ -1304,33 +1343,7 @@ void bdrv_append_temp_snapshot(BlockDriverState *bs, int flags, Error **errp)
|
||||
|
||||
out:
|
||||
g_free(tmp_filename);
|
||||
}
|
||||
|
||||
static QDict *parse_json_filename(const char *filename, Error **errp)
|
||||
{
|
||||
QObject *options_obj;
|
||||
QDict *options;
|
||||
int ret;
|
||||
|
||||
ret = strstart(filename, "json:", &filename);
|
||||
assert(ret);
|
||||
|
||||
options_obj = qobject_from_json(filename);
|
||||
if (!options_obj) {
|
||||
error_setg(errp, "Could not parse the JSON options");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (qobject_type(options_obj) != QTYPE_QDICT) {
|
||||
qobject_decref(options_obj);
|
||||
error_setg(errp, "Invalid JSON object given");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
options = qobject_to_qdict(options_obj);
|
||||
qdict_flatten(options);
|
||||
|
||||
return options;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1396,77 +1409,62 @@ int bdrv_open(BlockDriverState **pbs, const char *filename,
|
||||
options = qdict_new();
|
||||
}
|
||||
|
||||
if (filename && g_str_has_prefix(filename, "json:")) {
|
||||
QDict *json_options = parse_json_filename(filename, &local_err);
|
||||
if (local_err) {
|
||||
ret = -EINVAL;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* Options given in the filename have lower priority than options
|
||||
* specified directly */
|
||||
qdict_join(options, json_options, false);
|
||||
QDECREF(json_options);
|
||||
filename = NULL;
|
||||
}
|
||||
|
||||
bs->options = options;
|
||||
options = qdict_clone_shallow(options);
|
||||
|
||||
if (flags & BDRV_O_PROTOCOL) {
|
||||
assert(!drv);
|
||||
ret = bdrv_file_open(bs, filename, &options, flags & ~BDRV_O_PROTOCOL,
|
||||
&local_err);
|
||||
if (!ret) {
|
||||
drv = bs->drv;
|
||||
goto done;
|
||||
} else if (bs->drv) {
|
||||
goto close_and_fail;
|
||||
} else {
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
/* Open image file without format layer */
|
||||
if (flags & BDRV_O_RDWR) {
|
||||
flags |= BDRV_O_ALLOW_RDWR;
|
||||
}
|
||||
if (flags & BDRV_O_SNAPSHOT) {
|
||||
snapshot_flags = bdrv_temp_snapshot_flags(flags);
|
||||
flags = bdrv_backing_flags(flags);
|
||||
}
|
||||
|
||||
assert(file == NULL);
|
||||
ret = bdrv_open_image(&file, filename, options, "file",
|
||||
bdrv_inherited_flags(flags),
|
||||
true, &local_err);
|
||||
if (ret < 0) {
|
||||
ret = bdrv_fill_options(&options, &filename, flags, drv, &local_err);
|
||||
if (local_err) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* Find the right image format driver */
|
||||
drv = NULL;
|
||||
drvname = qdict_get_try_str(options, "driver");
|
||||
if (drvname) {
|
||||
drv = bdrv_find_format(drvname);
|
||||
qdict_del(options, "driver");
|
||||
if (!drv) {
|
||||
error_setg(errp, "Invalid driver: '%s'", drvname);
|
||||
error_setg(errp, "Unknown driver: '%s'", drvname);
|
||||
ret = -EINVAL;
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
if (!drv) {
|
||||
if (file) {
|
||||
ret = find_image_format(file, filename, &drv, &local_err);
|
||||
} else {
|
||||
error_setg(errp, "Must specify either driver or file");
|
||||
ret = -EINVAL;
|
||||
assert(drvname || !(flags & BDRV_O_PROTOCOL));
|
||||
if (drv && !drv->bdrv_file_open) {
|
||||
/* If the user explicitly wants a format driver here, we'll need to add
|
||||
* another layer for the protocol in bs->file */
|
||||
flags &= ~BDRV_O_PROTOCOL;
|
||||
}
|
||||
|
||||
bs->options = options;
|
||||
options = qdict_clone_shallow(options);
|
||||
|
||||
/* Open image file without format layer */
|
||||
if ((flags & BDRV_O_PROTOCOL) == 0) {
|
||||
if (flags & BDRV_O_RDWR) {
|
||||
flags |= BDRV_O_ALLOW_RDWR;
|
||||
}
|
||||
if (flags & BDRV_O_SNAPSHOT) {
|
||||
snapshot_flags = bdrv_temp_snapshot_flags(flags);
|
||||
flags = bdrv_backing_flags(flags);
|
||||
}
|
||||
|
||||
assert(file == NULL);
|
||||
ret = bdrv_open_image(&file, filename, options, "file",
|
||||
bdrv_inherited_flags(flags),
|
||||
true, &local_err);
|
||||
if (ret < 0) {
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
if (!drv) {
|
||||
/* Image format probing */
|
||||
if (!drv && file) {
|
||||
ret = find_image_format(file, filename, &drv, &local_err);
|
||||
if (ret < 0) {
|
||||
goto fail;
|
||||
}
|
||||
} else if (!drv) {
|
||||
error_setg(errp, "Must specify either driver or file");
|
||||
ret = -EINVAL;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@@ -1495,15 +1493,12 @@ int bdrv_open(BlockDriverState **pbs, const char *filename,
|
||||
/* For snapshot=on, create a temporary qcow2 overlay. bs points to the
|
||||
* temporary snapshot afterwards. */
|
||||
if (snapshot_flags) {
|
||||
bdrv_append_temp_snapshot(bs, snapshot_flags, &local_err);
|
||||
ret = bdrv_append_temp_snapshot(bs, snapshot_flags, &local_err);
|
||||
if (local_err) {
|
||||
error_propagate(errp, local_err);
|
||||
goto close_and_fail;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
done:
|
||||
/* Check if any unknown options were used */
|
||||
if (options && (qdict_size(options) != 0)) {
|
||||
const QDictEntry *entry = qdict_first(options);
|
||||
@@ -3489,9 +3484,7 @@ int bdrv_truncate(BlockDriverState *bs, int64_t offset)
|
||||
return -ENOTSUP;
|
||||
if (bs->read_only)
|
||||
return -EACCES;
|
||||
if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_RESIZE, NULL)) {
|
||||
return -EBUSY;
|
||||
}
|
||||
|
||||
ret = drv->bdrv_truncate(bs, offset);
|
||||
if (ret == 0) {
|
||||
ret = refresh_total_sectors(bs, offset >> BDRV_SECTOR_BITS);
|
||||
@@ -5774,3 +5767,28 @@ bool bdrv_is_first_non_filter(BlockDriverState *candidate)
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
BlockDriverState *check_to_replace_node(const char *node_name, Error **errp)
|
||||
{
|
||||
BlockDriverState *to_replace_bs = bdrv_find_node(node_name);
|
||||
if (!to_replace_bs) {
|
||||
error_setg(errp, "Node name '%s' not found", node_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (bdrv_op_is_blocked(to_replace_bs, BLOCK_OP_TYPE_REPLACE, errp)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* We don't want arbitrary node of the BDS chain to be replaced only the top
|
||||
* most non filter in order to prevent data corruption.
|
||||
* Another benefit is that this tests exclude backing files which are
|
||||
* blocked by the backing blockers.
|
||||
*/
|
||||
if (!bdrv_is_first_non_filter(to_replace_bs)) {
|
||||
error_setg(errp, "Only top most non filter can be replaced");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return to_replace_bs;
|
||||
}
|
||||
|
||||
@@ -414,6 +414,7 @@ static BlockDriver bdrv_cow = {
|
||||
.bdrv_close = cow_close,
|
||||
.bdrv_create = cow_create,
|
||||
.bdrv_has_zero_init = bdrv_has_zero_init_1,
|
||||
.supports_backing = true,
|
||||
|
||||
.bdrv_read = cow_co_read,
|
||||
.bdrv_write = cow_co_write,
|
||||
|
||||
+57
-14
@@ -32,6 +32,12 @@ typedef struct MirrorBlockJob {
|
||||
RateLimit limit;
|
||||
BlockDriverState *target;
|
||||
BlockDriverState *base;
|
||||
/* The name of the graph node to replace */
|
||||
char *replaces;
|
||||
/* The BDS to replace */
|
||||
BlockDriverState *to_replace;
|
||||
/* Used to block operations on the drive-mirror-replace target */
|
||||
Error *replace_blocker;
|
||||
bool is_none_mode;
|
||||
BlockdevOnError on_source_error, on_target_error;
|
||||
bool synced;
|
||||
@@ -324,9 +330,18 @@ static void coroutine_fn mirror_run(void *opaque)
|
||||
}
|
||||
|
||||
s->common.len = bdrv_getlength(bs);
|
||||
if (s->common.len <= 0) {
|
||||
if (s->common.len < 0) {
|
||||
ret = s->common.len;
|
||||
goto immediate_exit;
|
||||
} else if (s->common.len == 0) {
|
||||
/* Report BLOCK_JOB_READY and wait for complete. */
|
||||
block_job_event_ready(&s->common);
|
||||
s->synced = true;
|
||||
while (!block_job_is_cancelled(&s->common) && !s->should_complete) {
|
||||
block_job_yield(&s->common);
|
||||
}
|
||||
s->common.cancelled = false;
|
||||
goto immediate_exit;
|
||||
}
|
||||
|
||||
length = DIV_ROUND_UP(s->common.len, s->granularity);
|
||||
@@ -491,10 +506,14 @@ immediate_exit:
|
||||
bdrv_release_dirty_bitmap(bs, s->dirty_bitmap);
|
||||
bdrv_iostatus_disable(s->target);
|
||||
if (s->should_complete && ret == 0) {
|
||||
if (bdrv_get_flags(s->target) != bdrv_get_flags(s->common.bs)) {
|
||||
bdrv_reopen(s->target, bdrv_get_flags(s->common.bs), NULL);
|
||||
BlockDriverState *to_replace = s->common.bs;
|
||||
if (s->to_replace) {
|
||||
to_replace = s->to_replace;
|
||||
}
|
||||
bdrv_swap(s->target, s->common.bs);
|
||||
if (bdrv_get_flags(s->target) != bdrv_get_flags(to_replace)) {
|
||||
bdrv_reopen(s->target, bdrv_get_flags(to_replace), NULL);
|
||||
}
|
||||
bdrv_swap(s->target, to_replace);
|
||||
if (s->common.driver->job_type == BLOCK_JOB_TYPE_COMMIT) {
|
||||
/* drop the bs loop chain formed by the swap: break the loop then
|
||||
* trigger the unref from the top one */
|
||||
@@ -503,6 +522,12 @@ immediate_exit:
|
||||
bdrv_unref(p);
|
||||
}
|
||||
}
|
||||
if (s->to_replace) {
|
||||
bdrv_op_unblock_all(s->to_replace, s->replace_blocker);
|
||||
error_free(s->replace_blocker);
|
||||
bdrv_unref(s->to_replace);
|
||||
}
|
||||
g_free(s->replaces);
|
||||
bdrv_unref(s->target);
|
||||
block_job_completed(&s->common, ret);
|
||||
}
|
||||
@@ -541,6 +566,20 @@ static void mirror_complete(BlockJob *job, Error **errp)
|
||||
return;
|
||||
}
|
||||
|
||||
/* check the target bs is not blocked and block all operations on it */
|
||||
if (s->replaces) {
|
||||
s->to_replace = check_to_replace_node(s->replaces, &local_err);
|
||||
if (!s->to_replace) {
|
||||
error_propagate(errp, local_err);
|
||||
return;
|
||||
}
|
||||
|
||||
error_setg(&s->replace_blocker,
|
||||
"block device is in use by block-job-complete");
|
||||
bdrv_op_block_all(s->to_replace, s->replace_blocker);
|
||||
bdrv_ref(s->to_replace);
|
||||
}
|
||||
|
||||
s->should_complete = true;
|
||||
block_job_resume(job);
|
||||
}
|
||||
@@ -563,14 +602,15 @@ static const BlockJobDriver commit_active_job_driver = {
|
||||
};
|
||||
|
||||
static void mirror_start_job(BlockDriverState *bs, BlockDriverState *target,
|
||||
int64_t speed, int64_t granularity,
|
||||
int64_t buf_size,
|
||||
BlockdevOnError on_source_error,
|
||||
BlockdevOnError on_target_error,
|
||||
BlockDriverCompletionFunc *cb,
|
||||
void *opaque, Error **errp,
|
||||
const BlockJobDriver *driver,
|
||||
bool is_none_mode, BlockDriverState *base)
|
||||
const char *replaces,
|
||||
int64_t speed, int64_t granularity,
|
||||
int64_t buf_size,
|
||||
BlockdevOnError on_source_error,
|
||||
BlockdevOnError on_target_error,
|
||||
BlockDriverCompletionFunc *cb,
|
||||
void *opaque, Error **errp,
|
||||
const BlockJobDriver *driver,
|
||||
bool is_none_mode, BlockDriverState *base)
|
||||
{
|
||||
MirrorBlockJob *s;
|
||||
|
||||
@@ -601,6 +641,7 @@ static void mirror_start_job(BlockDriverState *bs, BlockDriverState *target,
|
||||
return;
|
||||
}
|
||||
|
||||
s->replaces = g_strdup(replaces);
|
||||
s->on_source_error = on_source_error;
|
||||
s->on_target_error = on_target_error;
|
||||
s->target = target;
|
||||
@@ -622,6 +663,7 @@ static void mirror_start_job(BlockDriverState *bs, BlockDriverState *target,
|
||||
}
|
||||
|
||||
void mirror_start(BlockDriverState *bs, BlockDriverState *target,
|
||||
const char *replaces,
|
||||
int64_t speed, int64_t granularity, int64_t buf_size,
|
||||
MirrorSyncMode mode, BlockdevOnError on_source_error,
|
||||
BlockdevOnError on_target_error,
|
||||
@@ -633,7 +675,8 @@ void mirror_start(BlockDriverState *bs, BlockDriverState *target,
|
||||
|
||||
is_none_mode = mode == MIRROR_SYNC_MODE_NONE;
|
||||
base = mode == MIRROR_SYNC_MODE_TOP ? bs->backing_hd : NULL;
|
||||
mirror_start_job(bs, target, speed, granularity, buf_size,
|
||||
mirror_start_job(bs, target, replaces,
|
||||
speed, granularity, buf_size,
|
||||
on_source_error, on_target_error, cb, opaque, errp,
|
||||
&mirror_job_driver, is_none_mode, base);
|
||||
}
|
||||
@@ -681,7 +724,7 @@ void commit_active_start(BlockDriverState *bs, BlockDriverState *base,
|
||||
}
|
||||
|
||||
bdrv_ref(base);
|
||||
mirror_start_job(bs, base, speed, 0, 0,
|
||||
mirror_start_job(bs, base, NULL, speed, 0, 0,
|
||||
on_error, on_error, cb, opaque, &local_err,
|
||||
&commit_active_job_driver, false, base);
|
||||
if (local_err) {
|
||||
|
||||
+16
-6
@@ -304,17 +304,27 @@ static int64_t nfs_client_open(NFSClient *client, const char *filename,
|
||||
|
||||
qp = query_params_parse(uri->query);
|
||||
for (i = 0; i < qp->n; i++) {
|
||||
unsigned long long val;
|
||||
if (!qp->p[i].value) {
|
||||
error_setg(errp, "Value for NFS parameter expected: %s",
|
||||
qp->p[i].name);
|
||||
goto fail;
|
||||
}
|
||||
if (!strncmp(qp->p[i].name, "uid", 3)) {
|
||||
nfs_set_uid(client->context, atoi(qp->p[i].value));
|
||||
} else if (!strncmp(qp->p[i].name, "gid", 3)) {
|
||||
nfs_set_gid(client->context, atoi(qp->p[i].value));
|
||||
} else if (!strncmp(qp->p[i].name, "tcp-syncnt", 10)) {
|
||||
nfs_set_tcp_syncnt(client->context, atoi(qp->p[i].value));
|
||||
if (parse_uint_full(qp->p[i].value, &val, 0)) {
|
||||
error_setg(errp, "Illegal value for NFS parameter: %s",
|
||||
qp->p[i].name);
|
||||
goto fail;
|
||||
}
|
||||
if (!strcmp(qp->p[i].name, "uid")) {
|
||||
nfs_set_uid(client->context, val);
|
||||
} else if (!strcmp(qp->p[i].name, "gid")) {
|
||||
nfs_set_gid(client->context, val);
|
||||
} else if (!strcmp(qp->p[i].name, "tcp-syncnt")) {
|
||||
nfs_set_tcp_syncnt(client->context, val);
|
||||
#ifdef LIBNFS_FEATURE_READAHEAD
|
||||
} else if (!strcmp(qp->p[i].name, "readahead")) {
|
||||
nfs_set_readahead(client->context, val);
|
||||
#endif
|
||||
} else {
|
||||
error_setg(errp, "Unknown NFS parameter name: %s",
|
||||
qp->p[i].name);
|
||||
|
||||
+5
-1
@@ -293,7 +293,7 @@ void bdrv_query_info(BlockDriverState *bs,
|
||||
qapi_free_BlockInfo(info);
|
||||
}
|
||||
|
||||
BlockStats *bdrv_query_stats(const BlockDriverState *bs)
|
||||
static BlockStats *bdrv_query_stats(const BlockDriverState *bs)
|
||||
{
|
||||
BlockStats *s;
|
||||
|
||||
@@ -360,7 +360,11 @@ BlockStatsList *qmp_query_blockstats(Error **errp)
|
||||
|
||||
while ((bs = bdrv_next(bs))) {
|
||||
BlockStatsList *info = g_malloc0(sizeof(*info));
|
||||
AioContext *ctx = bdrv_get_aio_context(bs);
|
||||
|
||||
aio_context_acquire(ctx);
|
||||
info->value = bdrv_query_stats(bs);
|
||||
aio_context_release(ctx);
|
||||
|
||||
*p_next = info;
|
||||
p_next = &info->next;
|
||||
|
||||
@@ -941,6 +941,7 @@ static BlockDriver bdrv_qcow = {
|
||||
.bdrv_reopen_prepare = qcow_reopen_prepare,
|
||||
.bdrv_create = qcow_create,
|
||||
.bdrv_has_zero_init = bdrv_has_zero_init_1,
|
||||
.supports_backing = true,
|
||||
|
||||
.bdrv_co_readv = qcow_co_readv,
|
||||
.bdrv_co_writev = qcow_co_writev,
|
||||
|
||||
@@ -2418,6 +2418,7 @@ static BlockDriver bdrv_qcow2 = {
|
||||
.bdrv_save_vmstate = qcow2_save_vmstate,
|
||||
.bdrv_load_vmstate = qcow2_load_vmstate,
|
||||
|
||||
.supports_backing = true,
|
||||
.bdrv_change_backing_file = qcow2_change_backing_file,
|
||||
|
||||
.bdrv_refresh_limits = qcow2_refresh_limits,
|
||||
|
||||
@@ -1652,6 +1652,7 @@ static BlockDriver bdrv_qed = {
|
||||
.format_name = "qed",
|
||||
.instance_size = sizeof(BDRVQEDState),
|
||||
.create_opts = &qed_create_opts,
|
||||
.supports_backing = true,
|
||||
|
||||
.bdrv_probe = bdrv_qed_probe,
|
||||
.bdrv_rebind = bdrv_qed_rebind,
|
||||
|
||||
+91
-6
@@ -23,6 +23,7 @@
|
||||
|
||||
#define QUORUM_OPT_VOTE_THRESHOLD "vote-threshold"
|
||||
#define QUORUM_OPT_BLKVERIFY "blkverify"
|
||||
#define QUORUM_OPT_REWRITE "rewrite-corrupted"
|
||||
|
||||
/* This union holds a vote hash value */
|
||||
typedef union QuorumVoteValue {
|
||||
@@ -70,6 +71,9 @@ typedef struct BDRVQuorumState {
|
||||
* It is useful to debug other block drivers by
|
||||
* comparing them with a reference one.
|
||||
*/
|
||||
bool rewrite_corrupted;/* true if the driver must rewrite-on-read corrupted
|
||||
* block if Quorum is reached.
|
||||
*/
|
||||
} BDRVQuorumState;
|
||||
|
||||
typedef struct QuorumAIOCB QuorumAIOCB;
|
||||
@@ -105,13 +109,17 @@ struct QuorumAIOCB {
|
||||
int count; /* number of completed AIOCB */
|
||||
int success_count; /* number of successfully completed AIOCB */
|
||||
|
||||
int rewrite_count; /* number of replica to rewrite: count down to
|
||||
* zero once writes are fired
|
||||
*/
|
||||
|
||||
QuorumVotes votes;
|
||||
|
||||
bool is_read;
|
||||
int vote_ret;
|
||||
};
|
||||
|
||||
static void quorum_vote(QuorumAIOCB *acb);
|
||||
static bool quorum_vote(QuorumAIOCB *acb);
|
||||
|
||||
static void quorum_aio_cancel(BlockDriverAIOCB *blockacb)
|
||||
{
|
||||
@@ -183,6 +191,7 @@ static QuorumAIOCB *quorum_aio_get(BDRVQuorumState *s,
|
||||
acb->qcrs = g_new0(QuorumChildRequest, s->num_children);
|
||||
acb->count = 0;
|
||||
acb->success_count = 0;
|
||||
acb->rewrite_count = 0;
|
||||
acb->votes.compare = quorum_sha256_compare;
|
||||
QLIST_INIT(&acb->votes.vote_list);
|
||||
acb->is_read = false;
|
||||
@@ -232,11 +241,27 @@ static bool quorum_has_too_much_io_failed(QuorumAIOCB *acb)
|
||||
return false;
|
||||
}
|
||||
|
||||
static void quorum_rewrite_aio_cb(void *opaque, int ret)
|
||||
{
|
||||
QuorumAIOCB *acb = opaque;
|
||||
|
||||
/* one less rewrite to do */
|
||||
acb->rewrite_count--;
|
||||
|
||||
/* wait until all rewrite callbacks have completed */
|
||||
if (acb->rewrite_count) {
|
||||
return;
|
||||
}
|
||||
|
||||
quorum_aio_finalize(acb);
|
||||
}
|
||||
|
||||
static void quorum_aio_cb(void *opaque, int ret)
|
||||
{
|
||||
QuorumChildRequest *sacb = opaque;
|
||||
QuorumAIOCB *acb = sacb->parent;
|
||||
BDRVQuorumState *s = acb->common.bs->opaque;
|
||||
bool rewrite = false;
|
||||
|
||||
sacb->ret = ret;
|
||||
acb->count++;
|
||||
@@ -253,12 +278,15 @@ static void quorum_aio_cb(void *opaque, int ret)
|
||||
|
||||
/* Do the vote on read */
|
||||
if (acb->is_read) {
|
||||
quorum_vote(acb);
|
||||
rewrite = quorum_vote(acb);
|
||||
} else {
|
||||
quorum_has_too_much_io_failed(acb);
|
||||
}
|
||||
|
||||
quorum_aio_finalize(acb);
|
||||
/* if no rewrite is done the code will finish right away */
|
||||
if (!rewrite) {
|
||||
quorum_aio_finalize(acb);
|
||||
}
|
||||
}
|
||||
|
||||
static void quorum_report_bad_versions(BDRVQuorumState *s,
|
||||
@@ -278,6 +306,43 @@ static void quorum_report_bad_versions(BDRVQuorumState *s,
|
||||
}
|
||||
}
|
||||
|
||||
static bool quorum_rewrite_bad_versions(BDRVQuorumState *s, QuorumAIOCB *acb,
|
||||
QuorumVoteValue *value)
|
||||
{
|
||||
QuorumVoteVersion *version;
|
||||
QuorumVoteItem *item;
|
||||
int count = 0;
|
||||
|
||||
/* first count the number of bad versions: done first to avoid concurrency
|
||||
* issues.
|
||||
*/
|
||||
QLIST_FOREACH(version, &acb->votes.vote_list, next) {
|
||||
if (acb->votes.compare(&version->value, value)) {
|
||||
continue;
|
||||
}
|
||||
QLIST_FOREACH(item, &version->items, next) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
/* quorum_rewrite_aio_cb will count down this to zero */
|
||||
acb->rewrite_count = count;
|
||||
|
||||
/* now fire the correcting rewrites */
|
||||
QLIST_FOREACH(version, &acb->votes.vote_list, next) {
|
||||
if (acb->votes.compare(&version->value, value)) {
|
||||
continue;
|
||||
}
|
||||
QLIST_FOREACH(item, &version->items, next) {
|
||||
bdrv_aio_writev(s->bs[item->index], acb->sector_num, acb->qiov,
|
||||
acb->nb_sectors, quorum_rewrite_aio_cb, acb);
|
||||
}
|
||||
}
|
||||
|
||||
/* return true if any rewrite is done else false */
|
||||
return count;
|
||||
}
|
||||
|
||||
static void quorum_copy_qiov(QEMUIOVector *dest, QEMUIOVector *source)
|
||||
{
|
||||
int i;
|
||||
@@ -468,16 +533,17 @@ static int quorum_vote_error(QuorumAIOCB *acb)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void quorum_vote(QuorumAIOCB *acb)
|
||||
static bool quorum_vote(QuorumAIOCB *acb)
|
||||
{
|
||||
bool quorum = true;
|
||||
bool rewrite = false;
|
||||
int i, j, ret;
|
||||
QuorumVoteValue hash;
|
||||
BDRVQuorumState *s = acb->common.bs->opaque;
|
||||
QuorumVoteVersion *winner;
|
||||
|
||||
if (quorum_has_too_much_io_failed(acb)) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* get the index of the first successful read */
|
||||
@@ -505,7 +571,7 @@ static void quorum_vote(QuorumAIOCB *acb)
|
||||
/* Every successful read agrees */
|
||||
if (quorum) {
|
||||
quorum_copy_qiov(acb->qiov, &acb->qcrs[i].qiov);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* compute hashes for each successful read, also store indexes */
|
||||
@@ -538,9 +604,15 @@ static void quorum_vote(QuorumAIOCB *acb)
|
||||
/* some versions are bad print them */
|
||||
quorum_report_bad_versions(s, acb, &winner->value);
|
||||
|
||||
/* corruption correction is enabled */
|
||||
if (s->rewrite_corrupted) {
|
||||
rewrite = quorum_rewrite_bad_versions(s, acb, &winner->value);
|
||||
}
|
||||
|
||||
free_exit:
|
||||
/* free lists */
|
||||
quorum_free_vote_list(&acb->votes);
|
||||
return rewrite;
|
||||
}
|
||||
|
||||
static BlockDriverAIOCB *quorum_aio_readv(BlockDriverState *bs,
|
||||
@@ -705,6 +777,11 @@ static QemuOptsList quorum_runtime_opts = {
|
||||
.type = QEMU_OPT_BOOL,
|
||||
.help = "Trigger block verify mode if set",
|
||||
},
|
||||
{
|
||||
.name = QUORUM_OPT_REWRITE,
|
||||
.type = QEMU_OPT_BOOL,
|
||||
.help = "Rewrite corrupted block on read quorum",
|
||||
},
|
||||
{ /* end of list */ }
|
||||
},
|
||||
};
|
||||
@@ -766,6 +843,14 @@ static int quorum_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
"and using two files with vote_threshold=2\n");
|
||||
}
|
||||
|
||||
s->rewrite_corrupted = qemu_opt_get_bool(opts, QUORUM_OPT_REWRITE, false);
|
||||
if (s->rewrite_corrupted && s->is_blkverify) {
|
||||
error_setg(&local_err,
|
||||
"rewrite-corrupted=on cannot be used with blkverify=on");
|
||||
ret = -EINVAL;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* allocate the children BlockDriverState array */
|
||||
s->bs = g_new0(BlockDriverState *, s->num_children);
|
||||
opened = g_new0(bool, s->num_children);
|
||||
|
||||
@@ -2180,6 +2180,7 @@ static BlockDriver bdrv_vmdk = {
|
||||
.bdrv_detach_aio_context = vmdk_detach_aio_context,
|
||||
.bdrv_attach_aio_context = vmdk_attach_aio_context,
|
||||
|
||||
.supports_backing = true,
|
||||
.create_opts = &vmdk_create_opts,
|
||||
};
|
||||
|
||||
|
||||
+44
-3
@@ -1819,6 +1819,11 @@ void qmp_block_resize(bool has_device, const char *device,
|
||||
return;
|
||||
}
|
||||
|
||||
if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_RESIZE, NULL)) {
|
||||
error_set(errp, QERR_DEVICE_IN_USE, device);
|
||||
return;
|
||||
}
|
||||
|
||||
/* complete all in-flight operations before resizing the device */
|
||||
bdrv_drain_all();
|
||||
|
||||
@@ -2094,6 +2099,8 @@ BlockDeviceInfoList *qmp_query_named_block_nodes(Error **errp)
|
||||
|
||||
void qmp_drive_mirror(const char *device, const char *target,
|
||||
bool has_format, const char *format,
|
||||
bool has_node_name, const char *node_name,
|
||||
bool has_replaces, const char *replaces,
|
||||
enum MirrorSyncMode sync,
|
||||
bool has_mode, enum NewImageMode mode,
|
||||
bool has_speed, int64_t speed,
|
||||
@@ -2107,6 +2114,7 @@ void qmp_drive_mirror(const char *device, const char *target,
|
||||
BlockDriverState *source, *target_bs;
|
||||
BlockDriver *drv = NULL;
|
||||
Error *local_err = NULL;
|
||||
QDict *options = NULL;
|
||||
int flags;
|
||||
int64_t size;
|
||||
int ret;
|
||||
@@ -2180,6 +2188,29 @@ void qmp_drive_mirror(const char *device, const char *target,
|
||||
return;
|
||||
}
|
||||
|
||||
if (has_replaces) {
|
||||
BlockDriverState *to_replace_bs;
|
||||
|
||||
if (!has_node_name) {
|
||||
error_setg(errp, "a node-name must be provided when replacing a"
|
||||
" named node of the graph");
|
||||
return;
|
||||
}
|
||||
|
||||
to_replace_bs = check_to_replace_node(replaces, &local_err);
|
||||
|
||||
if (!to_replace_bs) {
|
||||
error_propagate(errp, local_err);
|
||||
return;
|
||||
}
|
||||
|
||||
if (size != bdrv_getlength(to_replace_bs)) {
|
||||
error_setg(errp, "cannot replace image with a mirror image of "
|
||||
"different size");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ((sync == MIRROR_SYNC_MODE_FULL || !source)
|
||||
&& mode != NEW_IMAGE_MODE_EXISTING)
|
||||
{
|
||||
@@ -2208,18 +2239,28 @@ void qmp_drive_mirror(const char *device, const char *target,
|
||||
return;
|
||||
}
|
||||
|
||||
if (has_node_name) {
|
||||
options = qdict_new();
|
||||
qdict_put(options, "node-name", qstring_from_str(node_name));
|
||||
}
|
||||
|
||||
/* Mirroring takes care of copy-on-write using the source's backing
|
||||
* file.
|
||||
*/
|
||||
target_bs = NULL;
|
||||
ret = bdrv_open(&target_bs, target, NULL, NULL, flags | BDRV_O_NO_BACKING,
|
||||
drv, &local_err);
|
||||
ret = bdrv_open(&target_bs, target, NULL, options,
|
||||
flags | BDRV_O_NO_BACKING, drv, &local_err);
|
||||
if (ret < 0) {
|
||||
error_propagate(errp, local_err);
|
||||
return;
|
||||
}
|
||||
|
||||
mirror_start(bs, target_bs, speed, granularity, buf_size, sync,
|
||||
/* pass the node name to replace to mirror start since it's loose coupling
|
||||
* and will allow to check whether the node still exist at mirror completion
|
||||
*/
|
||||
mirror_start(bs, target_bs,
|
||||
has_replaces ? replaces : NULL,
|
||||
speed, granularity, buf_size, sync,
|
||||
on_source_error, on_target_error,
|
||||
block_job_cb, bs, &local_err);
|
||||
if (local_err != NULL) {
|
||||
|
||||
+20
-2
@@ -210,6 +210,20 @@ void block_job_sleep_ns(BlockJob *job, QEMUClockType type, int64_t ns)
|
||||
job->busy = true;
|
||||
}
|
||||
|
||||
void block_job_yield(BlockJob *job)
|
||||
{
|
||||
assert(job->busy);
|
||||
|
||||
/* Check cancellation *before* setting busy = false, too! */
|
||||
if (block_job_is_cancelled(job)) {
|
||||
return;
|
||||
}
|
||||
|
||||
job->busy = false;
|
||||
qemu_coroutine_yield();
|
||||
job->busy = true;
|
||||
}
|
||||
|
||||
BlockJobInfo *block_job_query(BlockJob *job)
|
||||
{
|
||||
BlockJobInfo *info = g_new0(BlockJobInfo, 1);
|
||||
@@ -256,7 +270,11 @@ void block_job_event_completed(BlockJob *job, const char *msg)
|
||||
|
||||
void block_job_event_ready(BlockJob *job)
|
||||
{
|
||||
qapi_event_send_block_job_ready(bdrv_get_device_name(job->bs), &error_abort);
|
||||
qapi_event_send_block_job_ready(job->driver->job_type,
|
||||
bdrv_get_device_name(job->bs),
|
||||
job->len,
|
||||
job->offset,
|
||||
job->speed, &error_abort);
|
||||
}
|
||||
|
||||
BlockErrorAction block_job_error_action(BlockJob *job, BlockDriverState *bs,
|
||||
@@ -282,7 +300,7 @@ BlockErrorAction block_job_error_action(BlockJob *job, BlockDriverState *bs,
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
qapi_event_send_block_job_error(bdrv_get_device_name(bs),
|
||||
qapi_event_send_block_job_error(bdrv_get_device_name(job->bs),
|
||||
is_read ? IO_OPERATION_TYPE_READ :
|
||||
IO_OPERATION_TYPE_WRITE,
|
||||
action, &error_abort);
|
||||
|
||||
@@ -5273,6 +5273,18 @@ if test "$docs" = "yes" ; then
|
||||
mkdir -p QMP
|
||||
fi
|
||||
|
||||
# set up qemu-iotests in this build directory
|
||||
iotests_common_env="tests/qemu-iotests/common.env"
|
||||
iotests_check="tests/qemu-iotests/check"
|
||||
|
||||
echo "# Automatically generated by configure - do not modify" > "$iotests_common_env"
|
||||
echo >> "$iotests_common_env"
|
||||
echo "export PYTHON='$python'" >> "$iotests_common_env"
|
||||
|
||||
if [ ! -e "$iotests_check" ]; then
|
||||
symlink "$source_path/$iotests_check" "$iotests_check"
|
||||
fi
|
||||
|
||||
# Save the configure command line for later reuse.
|
||||
cat <<EOD >config.status
|
||||
#!/bin/sh
|
||||
|
||||
@@ -933,6 +933,7 @@ void hmp_drive_mirror(Monitor *mon, const QDict *qdict)
|
||||
}
|
||||
|
||||
qmp_drive_mirror(device, filename, !!format, format,
|
||||
false, NULL, false, NULL,
|
||||
full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
|
||||
true, mode, false, 0, false, 0, false, 0,
|
||||
false, 0, false, 0, &err);
|
||||
|
||||
+23
-223
@@ -24,16 +24,6 @@
|
||||
#include "hw/virtio/virtio-bus.h"
|
||||
#include "qom/object_interfaces.h"
|
||||
|
||||
typedef struct {
|
||||
VirtIOBlockDataPlane *s;
|
||||
QEMUIOVector *inhdr; /* iovecs for virtio_blk_inhdr */
|
||||
VirtQueueElement *elem; /* saved data from the virtqueue */
|
||||
QEMUIOVector qiov; /* original request iovecs */
|
||||
struct iovec bounce_iov; /* used if guest buffers are unaligned */
|
||||
QEMUIOVector bounce_qiov; /* bounce buffer iovecs */
|
||||
bool read; /* read or write? */
|
||||
} VirtIOBlockRequest;
|
||||
|
||||
struct VirtIOBlockDataPlane {
|
||||
bool started;
|
||||
bool starting;
|
||||
@@ -57,6 +47,8 @@ struct VirtIOBlockDataPlane {
|
||||
|
||||
/* Operation blocker on BDS */
|
||||
Error *blocker;
|
||||
void (*saved_complete_request)(struct VirtIOBlockReq *req,
|
||||
unsigned char status);
|
||||
};
|
||||
|
||||
/* Raise an interrupt to signal guest, if necessary */
|
||||
@@ -69,215 +61,14 @@ static void notify_guest(VirtIOBlockDataPlane *s)
|
||||
event_notifier_set(s->guest_notifier);
|
||||
}
|
||||
|
||||
static void complete_rdwr(void *opaque, int ret)
|
||||
static void complete_request_vring(VirtIOBlockReq *req, unsigned char status)
|
||||
{
|
||||
VirtIOBlockRequest *req = opaque;
|
||||
struct virtio_blk_inhdr hdr;
|
||||
int len;
|
||||
stb_p(&req->in->status, status);
|
||||
|
||||
if (likely(ret == 0)) {
|
||||
hdr.status = VIRTIO_BLK_S_OK;
|
||||
len = req->qiov.size;
|
||||
} else {
|
||||
hdr.status = VIRTIO_BLK_S_IOERR;
|
||||
len = 0;
|
||||
}
|
||||
|
||||
trace_virtio_blk_data_plane_complete_request(req->s, req->elem->index, ret);
|
||||
|
||||
if (req->read && req->bounce_iov.iov_base) {
|
||||
qemu_iovec_from_buf(&req->qiov, 0, req->bounce_iov.iov_base, len);
|
||||
}
|
||||
|
||||
if (req->bounce_iov.iov_base) {
|
||||
qemu_vfree(req->bounce_iov.iov_base);
|
||||
}
|
||||
|
||||
qemu_iovec_from_buf(req->inhdr, 0, &hdr, sizeof(hdr));
|
||||
qemu_iovec_destroy(req->inhdr);
|
||||
g_slice_free(QEMUIOVector, req->inhdr);
|
||||
|
||||
/* According to the virtio specification len should be the number of bytes
|
||||
* written to, but for virtio-blk it seems to be the number of bytes
|
||||
* transferred plus the status bytes.
|
||||
*/
|
||||
vring_push(&req->s->vring, req->elem, len + sizeof(hdr));
|
||||
notify_guest(req->s);
|
||||
g_slice_free(VirtIOBlockRequest, req);
|
||||
}
|
||||
|
||||
static void complete_request_early(VirtIOBlockDataPlane *s, VirtQueueElement *elem,
|
||||
QEMUIOVector *inhdr, unsigned char status)
|
||||
{
|
||||
struct virtio_blk_inhdr hdr = {
|
||||
.status = status,
|
||||
};
|
||||
|
||||
qemu_iovec_from_buf(inhdr, 0, &hdr, sizeof(hdr));
|
||||
qemu_iovec_destroy(inhdr);
|
||||
g_slice_free(QEMUIOVector, inhdr);
|
||||
|
||||
vring_push(&s->vring, elem, sizeof(hdr));
|
||||
notify_guest(s);
|
||||
}
|
||||
|
||||
/* Get disk serial number */
|
||||
static void do_get_id_cmd(VirtIOBlockDataPlane *s,
|
||||
struct iovec *iov, unsigned int iov_cnt,
|
||||
VirtQueueElement *elem, QEMUIOVector *inhdr)
|
||||
{
|
||||
char id[VIRTIO_BLK_ID_BYTES];
|
||||
|
||||
/* Serial number not NUL-terminated when longer than buffer */
|
||||
strncpy(id, s->blk->serial ? s->blk->serial : "", sizeof(id));
|
||||
iov_from_buf(iov, iov_cnt, 0, id, sizeof(id));
|
||||
complete_request_early(s, elem, inhdr, VIRTIO_BLK_S_OK);
|
||||
}
|
||||
|
||||
static void do_rdwr_cmd(VirtIOBlockDataPlane *s, bool read,
|
||||
struct iovec *iov, unsigned iov_cnt,
|
||||
int64_t sector_num, VirtQueueElement *elem,
|
||||
QEMUIOVector *inhdr)
|
||||
{
|
||||
VirtIOBlockRequest *req = g_slice_new0(VirtIOBlockRequest);
|
||||
QEMUIOVector *qiov;
|
||||
int nb_sectors;
|
||||
|
||||
/* Fill in virtio block metadata needed for completion */
|
||||
req->s = s;
|
||||
req->elem = elem;
|
||||
req->inhdr = inhdr;
|
||||
req->read = read;
|
||||
qemu_iovec_init_external(&req->qiov, iov, iov_cnt);
|
||||
|
||||
qiov = &req->qiov;
|
||||
|
||||
if (!bdrv_qiov_is_aligned(s->blk->conf.bs, qiov)) {
|
||||
void *bounce_buffer = qemu_blockalign(s->blk->conf.bs, qiov->size);
|
||||
|
||||
/* Populate bounce buffer with data for writes */
|
||||
if (!read) {
|
||||
qemu_iovec_to_buf(qiov, 0, bounce_buffer, qiov->size);
|
||||
}
|
||||
|
||||
/* Redirect I/O to aligned bounce buffer */
|
||||
req->bounce_iov.iov_base = bounce_buffer;
|
||||
req->bounce_iov.iov_len = qiov->size;
|
||||
qemu_iovec_init_external(&req->bounce_qiov, &req->bounce_iov, 1);
|
||||
qiov = &req->bounce_qiov;
|
||||
}
|
||||
|
||||
nb_sectors = qiov->size / BDRV_SECTOR_SIZE;
|
||||
|
||||
if (read) {
|
||||
bdrv_aio_readv(s->blk->conf.bs, sector_num, qiov, nb_sectors,
|
||||
complete_rdwr, req);
|
||||
} else {
|
||||
bdrv_aio_writev(s->blk->conf.bs, sector_num, qiov, nb_sectors,
|
||||
complete_rdwr, req);
|
||||
}
|
||||
}
|
||||
|
||||
static void complete_flush(void *opaque, int ret)
|
||||
{
|
||||
VirtIOBlockRequest *req = opaque;
|
||||
unsigned char status;
|
||||
|
||||
if (ret == 0) {
|
||||
status = VIRTIO_BLK_S_OK;
|
||||
} else {
|
||||
status = VIRTIO_BLK_S_IOERR;
|
||||
}
|
||||
|
||||
complete_request_early(req->s, req->elem, req->inhdr, status);
|
||||
g_slice_free(VirtIOBlockRequest, req);
|
||||
}
|
||||
|
||||
static void do_flush_cmd(VirtIOBlockDataPlane *s, VirtQueueElement *elem,
|
||||
QEMUIOVector *inhdr)
|
||||
{
|
||||
VirtIOBlockRequest *req = g_slice_new(VirtIOBlockRequest);
|
||||
req->s = s;
|
||||
req->elem = elem;
|
||||
req->inhdr = inhdr;
|
||||
|
||||
bdrv_aio_flush(s->blk->conf.bs, complete_flush, req);
|
||||
}
|
||||
|
||||
static void do_scsi_cmd(VirtIOBlockDataPlane *s, VirtQueueElement *elem,
|
||||
QEMUIOVector *inhdr)
|
||||
{
|
||||
int status;
|
||||
|
||||
status = virtio_blk_handle_scsi_req(VIRTIO_BLK(s->vdev), elem);
|
||||
complete_request_early(s, elem, inhdr, status);
|
||||
}
|
||||
|
||||
static int process_request(VirtIOBlockDataPlane *s, VirtQueueElement *elem)
|
||||
{
|
||||
struct iovec *iov = elem->out_sg;
|
||||
struct iovec *in_iov = elem->in_sg;
|
||||
unsigned out_num = elem->out_num;
|
||||
unsigned in_num = elem->in_num;
|
||||
struct virtio_blk_outhdr outhdr;
|
||||
QEMUIOVector *inhdr;
|
||||
size_t in_size;
|
||||
|
||||
/* Copy in outhdr */
|
||||
if (unlikely(iov_to_buf(iov, out_num, 0, &outhdr,
|
||||
sizeof(outhdr)) != sizeof(outhdr))) {
|
||||
error_report("virtio-blk request outhdr too short");
|
||||
return -EFAULT;
|
||||
}
|
||||
iov_discard_front(&iov, &out_num, sizeof(outhdr));
|
||||
|
||||
/* Grab inhdr for later */
|
||||
in_size = iov_size(in_iov, in_num);
|
||||
if (in_size < sizeof(struct virtio_blk_inhdr)) {
|
||||
error_report("virtio_blk request inhdr too short");
|
||||
return -EFAULT;
|
||||
}
|
||||
inhdr = g_slice_new(QEMUIOVector);
|
||||
qemu_iovec_init(inhdr, 1);
|
||||
qemu_iovec_concat_iov(inhdr, in_iov, in_num,
|
||||
in_size - sizeof(struct virtio_blk_inhdr),
|
||||
sizeof(struct virtio_blk_inhdr));
|
||||
iov_discard_back(in_iov, &in_num, sizeof(struct virtio_blk_inhdr));
|
||||
|
||||
/* TODO Linux sets the barrier bit even when not advertised! */
|
||||
outhdr.type &= ~VIRTIO_BLK_T_BARRIER;
|
||||
|
||||
switch (outhdr.type) {
|
||||
case VIRTIO_BLK_T_IN:
|
||||
do_rdwr_cmd(s, true, in_iov, in_num,
|
||||
outhdr.sector * 512 / BDRV_SECTOR_SIZE,
|
||||
elem, inhdr);
|
||||
return 0;
|
||||
|
||||
case VIRTIO_BLK_T_OUT:
|
||||
do_rdwr_cmd(s, false, iov, out_num,
|
||||
outhdr.sector * 512 / BDRV_SECTOR_SIZE,
|
||||
elem, inhdr);
|
||||
return 0;
|
||||
|
||||
case VIRTIO_BLK_T_SCSI_CMD:
|
||||
do_scsi_cmd(s, elem, inhdr);
|
||||
return 0;
|
||||
|
||||
case VIRTIO_BLK_T_FLUSH:
|
||||
do_flush_cmd(s, elem, inhdr);
|
||||
return 0;
|
||||
|
||||
case VIRTIO_BLK_T_GET_ID:
|
||||
do_get_id_cmd(s, in_iov, in_num, elem, inhdr);
|
||||
return 0;
|
||||
|
||||
default:
|
||||
error_report("virtio-blk unsupported request type %#x", outhdr.type);
|
||||
qemu_iovec_destroy(inhdr);
|
||||
g_slice_free(QEMUIOVector, inhdr);
|
||||
return -EFAULT;
|
||||
}
|
||||
vring_push(&req->dev->dataplane->vring, req->elem,
|
||||
req->qiov.size + sizeof(*req->in));
|
||||
notify_guest(req->dev->dataplane);
|
||||
g_slice_free(VirtIOBlockReq, req);
|
||||
}
|
||||
|
||||
static void handle_notify(EventNotifier *e)
|
||||
@@ -286,7 +77,11 @@ static void handle_notify(EventNotifier *e)
|
||||
host_notifier);
|
||||
|
||||
VirtQueueElement *elem;
|
||||
VirtIOBlockReq *req;
|
||||
int ret;
|
||||
MultiReqBuffer mrb = {
|
||||
.num_writes = 0,
|
||||
};
|
||||
|
||||
event_notifier_test_and_clear(&s->host_notifier);
|
||||
for (;;) {
|
||||
@@ -303,14 +98,14 @@ static void handle_notify(EventNotifier *e)
|
||||
trace_virtio_blk_data_plane_process_request(s, elem->out_num,
|
||||
elem->in_num, elem->index);
|
||||
|
||||
if (process_request(s, elem) < 0) {
|
||||
vring_set_broken(&s->vring);
|
||||
vring_free_element(elem);
|
||||
ret = -EFAULT;
|
||||
break;
|
||||
}
|
||||
req = g_slice_new(VirtIOBlockReq);
|
||||
req->dev = VIRTIO_BLK(s->vdev);
|
||||
req->elem = elem;
|
||||
virtio_blk_handle_request(req, &mrb);
|
||||
}
|
||||
|
||||
virtio_submit_multiwrite(s->blk->conf.bs, &mrb);
|
||||
|
||||
if (likely(ret == -EAGAIN)) { /* vring emptied */
|
||||
/* Re-enable guest->host notifies and stop processing the vring.
|
||||
* But if the guest has snuck in more descriptors, keep processing.
|
||||
@@ -330,6 +125,7 @@ void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *blk,
|
||||
Error **errp)
|
||||
{
|
||||
VirtIOBlockDataPlane *s;
|
||||
VirtIOBlock *vblk = VIRTIO_BLK(vdev);
|
||||
Error *local_err = NULL;
|
||||
|
||||
*dataplane = NULL;
|
||||
@@ -372,6 +168,8 @@ void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *blk,
|
||||
bdrv_op_block_all(blk->conf.bs, s->blocker);
|
||||
|
||||
*dataplane = s;
|
||||
s->saved_complete_request = vblk->complete_request;
|
||||
vblk->complete_request = complete_request_vring;
|
||||
}
|
||||
|
||||
/* Context: QEMU global mutex held */
|
||||
@@ -446,10 +244,12 @@ void virtio_blk_data_plane_stop(VirtIOBlockDataPlane *s)
|
||||
{
|
||||
BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(s->vdev)));
|
||||
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
|
||||
VirtIOBlock *vblk = VIRTIO_BLK(s->vdev);
|
||||
if (!s->started || s->stopping) {
|
||||
return;
|
||||
}
|
||||
s->stopping = true;
|
||||
vblk->complete_request = s->saved_complete_request;
|
||||
trace_virtio_blk_data_plane_stop(s);
|
||||
|
||||
aio_context_acquire(s->ctx);
|
||||
|
||||
+76
-63
@@ -12,6 +12,7 @@
|
||||
*/
|
||||
|
||||
#include "qemu-common.h"
|
||||
#include "qemu/iov.h"
|
||||
#include "qemu/error-report.h"
|
||||
#include "trace.h"
|
||||
#include "hw/block/block.h"
|
||||
@@ -27,18 +28,24 @@
|
||||
#endif
|
||||
#include "hw/virtio/virtio-bus.h"
|
||||
|
||||
typedef struct VirtIOBlockReq
|
||||
static VirtIOBlockReq *virtio_blk_alloc_request(VirtIOBlock *s)
|
||||
{
|
||||
VirtIOBlock *dev;
|
||||
VirtQueueElement elem;
|
||||
struct virtio_blk_inhdr *in;
|
||||
struct virtio_blk_outhdr *out;
|
||||
QEMUIOVector qiov;
|
||||
struct VirtIOBlockReq *next;
|
||||
BlockAcctCookie acct;
|
||||
} VirtIOBlockReq;
|
||||
VirtIOBlockReq *req = g_slice_new0(VirtIOBlockReq);
|
||||
req->dev = s;
|
||||
req->elem = g_slice_new0(VirtQueueElement);
|
||||
return req;
|
||||
}
|
||||
|
||||
static void virtio_blk_req_complete(VirtIOBlockReq *req, int status)
|
||||
static void virtio_blk_free_request(VirtIOBlockReq *req)
|
||||
{
|
||||
if (req) {
|
||||
g_slice_free(VirtQueueElement, req->elem);
|
||||
g_slice_free(VirtIOBlockReq, req);
|
||||
}
|
||||
}
|
||||
|
||||
static void virtio_blk_complete_request(VirtIOBlockReq *req,
|
||||
unsigned char status)
|
||||
{
|
||||
VirtIOBlock *s = req->dev;
|
||||
VirtIODevice *vdev = VIRTIO_DEVICE(s);
|
||||
@@ -46,10 +53,15 @@ static void virtio_blk_req_complete(VirtIOBlockReq *req, int status)
|
||||
trace_virtio_blk_req_complete(req, status);
|
||||
|
||||
stb_p(&req->in->status, status);
|
||||
virtqueue_push(s->vq, &req->elem, req->qiov.size + sizeof(*req->in));
|
||||
virtqueue_push(s->vq, req->elem, req->qiov.size + sizeof(*req->in));
|
||||
virtio_notify(vdev, s->vq);
|
||||
}
|
||||
|
||||
static void virtio_blk_req_complete(VirtIOBlockReq *req, unsigned char status)
|
||||
{
|
||||
req->dev->complete_request(req, status);
|
||||
}
|
||||
|
||||
static int virtio_blk_handle_rw_error(VirtIOBlockReq *req, int error,
|
||||
bool is_read)
|
||||
{
|
||||
@@ -62,7 +74,7 @@ static int virtio_blk_handle_rw_error(VirtIOBlockReq *req, int error,
|
||||
} else if (action == BLOCK_ERROR_ACTION_REPORT) {
|
||||
virtio_blk_req_complete(req, VIRTIO_BLK_S_IOERR);
|
||||
bdrv_acct_done(s->bs, &req->acct);
|
||||
g_free(req);
|
||||
virtio_blk_free_request(req);
|
||||
}
|
||||
|
||||
bdrv_error_action(s->bs, action, is_read, error);
|
||||
@@ -76,14 +88,14 @@ static void virtio_blk_rw_complete(void *opaque, int ret)
|
||||
trace_virtio_blk_rw_complete(req, ret);
|
||||
|
||||
if (ret) {
|
||||
bool is_read = !(ldl_p(&req->out->type) & VIRTIO_BLK_T_OUT);
|
||||
bool is_read = !(ldl_p(&req->out.type) & VIRTIO_BLK_T_OUT);
|
||||
if (virtio_blk_handle_rw_error(req, -ret, is_read))
|
||||
return;
|
||||
}
|
||||
|
||||
virtio_blk_req_complete(req, VIRTIO_BLK_S_OK);
|
||||
bdrv_acct_done(req->dev->bs, &req->acct);
|
||||
g_free(req);
|
||||
virtio_blk_free_request(req);
|
||||
}
|
||||
|
||||
static void virtio_blk_flush_complete(void *opaque, int ret)
|
||||
@@ -98,27 +110,16 @@ static void virtio_blk_flush_complete(void *opaque, int ret)
|
||||
|
||||
virtio_blk_req_complete(req, VIRTIO_BLK_S_OK);
|
||||
bdrv_acct_done(req->dev->bs, &req->acct);
|
||||
g_free(req);
|
||||
}
|
||||
|
||||
static VirtIOBlockReq *virtio_blk_alloc_request(VirtIOBlock *s)
|
||||
{
|
||||
VirtIOBlockReq *req = g_malloc(sizeof(*req));
|
||||
req->dev = s;
|
||||
req->qiov.size = 0;
|
||||
req->next = NULL;
|
||||
return req;
|
||||
virtio_blk_free_request(req);
|
||||
}
|
||||
|
||||
static VirtIOBlockReq *virtio_blk_get_request(VirtIOBlock *s)
|
||||
{
|
||||
VirtIOBlockReq *req = virtio_blk_alloc_request(s);
|
||||
|
||||
if (req != NULL) {
|
||||
if (!virtqueue_pop(s->vq, &req->elem)) {
|
||||
g_free(req);
|
||||
return NULL;
|
||||
}
|
||||
if (!virtqueue_pop(s->vq, req->elem)) {
|
||||
virtio_blk_free_request(req);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return req;
|
||||
@@ -247,17 +248,12 @@ static void virtio_blk_handle_scsi(VirtIOBlockReq *req)
|
||||
{
|
||||
int status;
|
||||
|
||||
status = virtio_blk_handle_scsi_req(req->dev, &req->elem);
|
||||
status = virtio_blk_handle_scsi_req(req->dev, req->elem);
|
||||
virtio_blk_req_complete(req, status);
|
||||
g_free(req);
|
||||
virtio_blk_free_request(req);
|
||||
}
|
||||
|
||||
typedef struct MultiReqBuffer {
|
||||
BlockRequest blkreq[32];
|
||||
unsigned int num_writes;
|
||||
} MultiReqBuffer;
|
||||
|
||||
static void virtio_submit_multiwrite(BlockDriverState *bs, MultiReqBuffer *mrb)
|
||||
void virtio_submit_multiwrite(BlockDriverState *bs, MultiReqBuffer *mrb)
|
||||
{
|
||||
int i, ret;
|
||||
|
||||
@@ -293,7 +289,7 @@ static void virtio_blk_handle_write(VirtIOBlockReq *req, MultiReqBuffer *mrb)
|
||||
BlockRequest *blkreq;
|
||||
uint64_t sector;
|
||||
|
||||
sector = ldq_p(&req->out->sector);
|
||||
sector = ldq_p(&req->out.sector);
|
||||
|
||||
bdrv_acct_start(req->dev->bs, &req->acct, req->qiov.size, BDRV_ACCT_WRITE);
|
||||
|
||||
@@ -327,7 +323,7 @@ static void virtio_blk_handle_read(VirtIOBlockReq *req)
|
||||
{
|
||||
uint64_t sector;
|
||||
|
||||
sector = ldq_p(&req->out->sector);
|
||||
sector = ldq_p(&req->out.sector);
|
||||
|
||||
bdrv_acct_start(req->dev->bs, &req->acct, req->qiov.size, BDRV_ACCT_READ);
|
||||
|
||||
@@ -346,26 +342,39 @@ static void virtio_blk_handle_read(VirtIOBlockReq *req)
|
||||
virtio_blk_rw_complete, req);
|
||||
}
|
||||
|
||||
static void virtio_blk_handle_request(VirtIOBlockReq *req,
|
||||
MultiReqBuffer *mrb)
|
||||
void virtio_blk_handle_request(VirtIOBlockReq *req, MultiReqBuffer *mrb)
|
||||
{
|
||||
uint32_t type;
|
||||
struct iovec *in_iov = req->elem->in_sg;
|
||||
struct iovec *iov = req->elem->out_sg;
|
||||
unsigned in_num = req->elem->in_num;
|
||||
unsigned out_num = req->elem->out_num;
|
||||
|
||||
if (req->elem.out_num < 1 || req->elem.in_num < 1) {
|
||||
if (req->elem->out_num < 1 || req->elem->in_num < 1) {
|
||||
error_report("virtio-blk missing headers");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (req->elem.out_sg[0].iov_len < sizeof(*req->out) ||
|
||||
req->elem.in_sg[req->elem.in_num - 1].iov_len < sizeof(*req->in)) {
|
||||
error_report("virtio-blk header not in correct element");
|
||||
if (unlikely(iov_to_buf(iov, out_num, 0, &req->out,
|
||||
sizeof(req->out)) != sizeof(req->out))) {
|
||||
error_report("virtio-blk request outhdr too short");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
req->out = (void *)req->elem.out_sg[0].iov_base;
|
||||
req->in = (void *)req->elem.in_sg[req->elem.in_num - 1].iov_base;
|
||||
iov_discard_front(&iov, &out_num, sizeof(req->out));
|
||||
|
||||
type = ldl_p(&req->out->type);
|
||||
if (in_num < 1 ||
|
||||
in_iov[in_num - 1].iov_len < sizeof(struct virtio_blk_inhdr)) {
|
||||
error_report("virtio-blk request inhdr too short");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
req->in = (void *)in_iov[in_num - 1].iov_base
|
||||
+ in_iov[in_num - 1].iov_len
|
||||
- sizeof(struct virtio_blk_inhdr);
|
||||
iov_discard_back(in_iov, &in_num, sizeof(struct virtio_blk_inhdr));
|
||||
|
||||
type = ldl_p(&req->out.type);
|
||||
|
||||
if (type & VIRTIO_BLK_T_FLUSH) {
|
||||
virtio_blk_handle_flush(req, mrb);
|
||||
@@ -378,23 +387,23 @@ static void virtio_blk_handle_request(VirtIOBlockReq *req,
|
||||
* NB: per existing s/n string convention the string is
|
||||
* terminated by '\0' only when shorter than buffer.
|
||||
*/
|
||||
strncpy(req->elem.in_sg[0].iov_base,
|
||||
strncpy(req->elem->in_sg[0].iov_base,
|
||||
s->blk.serial ? s->blk.serial : "",
|
||||
MIN(req->elem.in_sg[0].iov_len, VIRTIO_BLK_ID_BYTES));
|
||||
MIN(req->elem->in_sg[0].iov_len, VIRTIO_BLK_ID_BYTES));
|
||||
virtio_blk_req_complete(req, VIRTIO_BLK_S_OK);
|
||||
g_free(req);
|
||||
virtio_blk_free_request(req);
|
||||
} else if (type & VIRTIO_BLK_T_OUT) {
|
||||
qemu_iovec_init_external(&req->qiov, &req->elem.out_sg[1],
|
||||
req->elem.out_num - 1);
|
||||
qemu_iovec_init_external(&req->qiov, &req->elem->out_sg[1],
|
||||
req->elem->out_num - 1);
|
||||
virtio_blk_handle_write(req, mrb);
|
||||
} else if (type == VIRTIO_BLK_T_IN || type == VIRTIO_BLK_T_BARRIER) {
|
||||
/* VIRTIO_BLK_T_IN is 0, so we can't just & it. */
|
||||
qemu_iovec_init_external(&req->qiov, &req->elem.in_sg[0],
|
||||
req->elem.in_num - 1);
|
||||
qemu_iovec_init_external(&req->qiov, &req->elem->in_sg[0],
|
||||
req->elem->in_num - 1);
|
||||
virtio_blk_handle_read(req);
|
||||
} else {
|
||||
virtio_blk_req_complete(req, VIRTIO_BLK_S_UNSUPP);
|
||||
g_free(req);
|
||||
virtio_blk_free_request(req);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -460,7 +469,8 @@ static void virtio_blk_dma_restart_cb(void *opaque, int running,
|
||||
}
|
||||
|
||||
if (!s->bh) {
|
||||
s->bh = qemu_bh_new(virtio_blk_dma_restart_bh, s);
|
||||
s->bh = aio_bh_new(bdrv_get_aio_context(s->blk.conf.bs),
|
||||
virtio_blk_dma_restart_bh, s);
|
||||
qemu_bh_schedule(s->bh);
|
||||
}
|
||||
}
|
||||
@@ -609,7 +619,8 @@ static void virtio_blk_save(QEMUFile *f, void *opaque)
|
||||
|
||||
while (req) {
|
||||
qemu_put_sbyte(f, 1);
|
||||
qemu_put_buffer(f, (unsigned char*)&req->elem, sizeof(req->elem));
|
||||
qemu_put_buffer(f, (unsigned char *)req->elem,
|
||||
sizeof(VirtQueueElement));
|
||||
req = req->next;
|
||||
}
|
||||
qemu_put_sbyte(f, 0);
|
||||
@@ -631,14 +642,15 @@ static int virtio_blk_load(QEMUFile *f, void *opaque, int version_id)
|
||||
|
||||
while (qemu_get_sbyte(f)) {
|
||||
VirtIOBlockReq *req = virtio_blk_alloc_request(s);
|
||||
qemu_get_buffer(f, (unsigned char*)&req->elem, sizeof(req->elem));
|
||||
qemu_get_buffer(f, (unsigned char *)req->elem,
|
||||
sizeof(VirtQueueElement));
|
||||
req->next = s->rq;
|
||||
s->rq = req;
|
||||
|
||||
virtqueue_map_sg(req->elem.in_sg, req->elem.in_addr,
|
||||
req->elem.in_num, 1);
|
||||
virtqueue_map_sg(req->elem.out_sg, req->elem.out_addr,
|
||||
req->elem.out_num, 0);
|
||||
virtqueue_map_sg(req->elem->in_sg, req->elem->in_addr,
|
||||
req->elem->in_num, 1);
|
||||
virtqueue_map_sg(req->elem->out_sg, req->elem->out_addr,
|
||||
req->elem->out_num, 0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -729,6 +741,7 @@ static void virtio_blk_device_realize(DeviceState *dev, Error **errp)
|
||||
s->sector_mask = (s->conf->logical_block_size / BDRV_SECTOR_SIZE) - 1;
|
||||
|
||||
s->vq = virtio_add_queue(vdev, 128, virtio_blk_handle_output);
|
||||
s->complete_request = virtio_blk_complete_request;
|
||||
#ifdef CONFIG_VIRTIO_BLK_DATA_PLANE
|
||||
virtio_blk_data_plane_create(vdev, blk, &s->dataplane, &err);
|
||||
if (err != NULL) {
|
||||
|
||||
@@ -175,6 +175,7 @@ typedef enum BlockOpType {
|
||||
BLOCK_OP_TYPE_MIRROR,
|
||||
BLOCK_OP_TYPE_RESIZE,
|
||||
BLOCK_OP_TYPE_STREAM,
|
||||
BLOCK_OP_TYPE_REPLACE,
|
||||
BLOCK_OP_TYPE_MAX,
|
||||
} BlockOpType;
|
||||
|
||||
@@ -213,7 +214,7 @@ int bdrv_open_image(BlockDriverState **pbs, const char *filename,
|
||||
bool allow_none, Error **errp);
|
||||
void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd);
|
||||
int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp);
|
||||
void bdrv_append_temp_snapshot(BlockDriverState *bs, int flags, Error **errp);
|
||||
int bdrv_append_temp_snapshot(BlockDriverState *bs, int flags, Error **errp);
|
||||
int bdrv_open(BlockDriverState **pbs, const char *filename,
|
||||
const char *reference, QDict *options, int flags,
|
||||
BlockDriver *drv, Error **errp);
|
||||
@@ -314,6 +315,9 @@ bool bdrv_recurse_is_first_non_filter(BlockDriverState *bs,
|
||||
BlockDriverState *candidate);
|
||||
bool bdrv_is_first_non_filter(BlockDriverState *candidate);
|
||||
|
||||
/* check if a named node can be replaced when doing drive-mirror */
|
||||
BlockDriverState *check_to_replace_node(const char *node_name, Error **errp);
|
||||
|
||||
/* async block I/O */
|
||||
typedef void BlockDriverDirtyHandler(BlockDriverState *bs, int64_t sector,
|
||||
int sector_num);
|
||||
|
||||
@@ -100,6 +100,9 @@ struct BlockDriver {
|
||||
*/
|
||||
bool bdrv_needs_filename;
|
||||
|
||||
/* Set if a driver can support backing files */
|
||||
bool supports_backing;
|
||||
|
||||
/* For handling image reopen for split or non-split files */
|
||||
int (*bdrv_reopen_prepare)(BDRVReopenState *reopen_state,
|
||||
BlockReopenQueue *queue, Error **errp);
|
||||
@@ -486,6 +489,8 @@ void commit_active_start(BlockDriverState *bs, BlockDriverState *base,
|
||||
* mirror_start:
|
||||
* @bs: Block device to operate on.
|
||||
* @target: Block device to write to.
|
||||
* @replaces: Block graph node name to replace once the mirror is done. Can
|
||||
* only be used when full mirroring is selected.
|
||||
* @speed: The maximum speed, in bytes per second, or 0 for unlimited.
|
||||
* @granularity: The chosen granularity for the dirty bitmap.
|
||||
* @buf_size: The amount of data that can be in flight at one time.
|
||||
@@ -502,6 +507,7 @@ void commit_active_start(BlockDriverState *bs, BlockDriverState *base,
|
||||
* @bs will be switched to read from @target.
|
||||
*/
|
||||
void mirror_start(BlockDriverState *bs, BlockDriverState *target,
|
||||
const char *replaces,
|
||||
int64_t speed, int64_t granularity, int64_t buf_size,
|
||||
MirrorSyncMode mode, BlockdevOnError on_source_error,
|
||||
BlockdevOnError on_target_error,
|
||||
|
||||
@@ -146,6 +146,14 @@ void *block_job_create(const BlockJobDriver *driver, BlockDriverState *bs,
|
||||
*/
|
||||
void block_job_sleep_ns(BlockJob *job, QEMUClockType type, int64_t ns);
|
||||
|
||||
/**
|
||||
* block_job_yield:
|
||||
* @job: The job that calls the function.
|
||||
*
|
||||
* Yield the block job coroutine.
|
||||
*/
|
||||
void block_job_yield(BlockJob *job);
|
||||
|
||||
/**
|
||||
* block_job_completed:
|
||||
* @job: The job being completed.
|
||||
|
||||
@@ -39,7 +39,6 @@ void bdrv_query_image_info(BlockDriverState *bs,
|
||||
void bdrv_query_info(BlockDriverState *bs,
|
||||
BlockInfo **p_info,
|
||||
Error **errp);
|
||||
BlockStats *bdrv_query_stats(const BlockDriverState *bs);
|
||||
|
||||
void bdrv_snapshot_dump(fprintf_function func_fprintf, void *f,
|
||||
QEMUSnapshotInfo *sn);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user