mirror of
https://github.com/xemu-project/xemu.git
synced 2024-11-23 11:39:53 +00:00
d5ab9490cd
- Cleanup bs->backing and bs->file handling - Refactor bdrv_try_set_aio_context using transactions - Changes for improved coroutine_fn consistency - vhost-user-blk: fix the resize crash - io_uring: Use of io_uring_register_ring_fd() led to breakage, revert - vvfat: Fix some problems with r/w mode - Code cleanup - MAINTAINERS: Fold "Block QAPI, monitor, ..." into "Block layer core" -----BEGIN PGP SIGNATURE----- iQJFBAABCAAvFiEE3D3rFZqa+V09dFb+fwmycsiPL9YFAmNazhIRHGt3b2xmQHJl ZGhhdC5jb20ACgkQfwmycsiPL9ZyTw/8Dfck/SuxfyeLlnQItkjaV4cnqWOU8vHs 9x0KhlptCs+HXdF/3iicpA0lHojn7mNnbdFGjPRY4E0LriQv91TQ5ycdEmrseFPf sgeQlgdKCVU/pHjZ2wYarm2pE43Cx85a5xuufmw+7w49dNNZn14l4t+DgviuClVM nuVaogfZFbYyetre+Qd2TgLl+gJ+0d4o7Zs5lSWLrT8t0L9AGkcWPA7Nrbl6loIE dOautV4G7jLjuMiCeJZOGcnuRVe3gCQ5rCGBFzzH4DUtz4BmiYx4hd3LMEsP0PMM CrsfDZS04Ztybl9M7TmJuwkAm1gx1JDMOuJuh18lbJocIOBvhkKKxY2wI5LIdZVI ZntmU36RowkX+GGu/PYpYyMjBDClJppZCl7vnjyLYsVt6r0Vu6SmlHpJhcRYabhe 96Kv1LXH9A6+ogKPU3Layw6JGjg01GNr1ALuT7PO3pGto/JshmOuBEJJDucoF84M 5AfxFCohMROVldwblA6M0eKnlQBgtr5BvtgbV54BBo88VlFJgDJFQn7R09cTFUEo UwaJoS+nIaiZ0bQQVZhZloVppUaTdVJojzfVRCZZctga96/tu1HSFnGLnbEFpUN3 KOf+XnVNS6Ro+nPSDf9bMjbIom2JicGFfV+6yMgIoxY/d5UA2dTZfefil4TAlSod 6PsTgg+jrm8= =/Fw0 -----END PGP SIGNATURE----- Merge tag 'for-upstream' of https://repo.or.cz/qemu/kevin into staging Block layer patches - Cleanup bs->backing and bs->file handling - Refactor bdrv_try_set_aio_context using transactions - Changes for improved coroutine_fn consistency - vhost-user-blk: fix the resize crash - io_uring: Use of io_uring_register_ring_fd() led to breakage, revert - vvfat: Fix some problems with r/w mode - Code cleanup - MAINTAINERS: Fold "Block QAPI, monitor, ..." into "Block layer core" # -----BEGIN PGP SIGNATURE----- # # iQJFBAABCAAvFiEE3D3rFZqa+V09dFb+fwmycsiPL9YFAmNazhIRHGt3b2xmQHJl # ZGhhdC5jb20ACgkQfwmycsiPL9ZyTw/8Dfck/SuxfyeLlnQItkjaV4cnqWOU8vHs # 9x0KhlptCs+HXdF/3iicpA0lHojn7mNnbdFGjPRY4E0LriQv91TQ5ycdEmrseFPf # sgeQlgdKCVU/pHjZ2wYarm2pE43Cx85a5xuufmw+7w49dNNZn14l4t+DgviuClVM # nuVaogfZFbYyetre+Qd2TgLl+gJ+0d4o7Zs5lSWLrT8t0L9AGkcWPA7Nrbl6loIE # dOautV4G7jLjuMiCeJZOGcnuRVe3gCQ5rCGBFzzH4DUtz4BmiYx4hd3LMEsP0PMM # CrsfDZS04Ztybl9M7TmJuwkAm1gx1JDMOuJuh18lbJocIOBvhkKKxY2wI5LIdZVI # ZntmU36RowkX+GGu/PYpYyMjBDClJppZCl7vnjyLYsVt6r0Vu6SmlHpJhcRYabhe # 96Kv1LXH9A6+ogKPU3Layw6JGjg01GNr1ALuT7PO3pGto/JshmOuBEJJDucoF84M # 5AfxFCohMROVldwblA6M0eKnlQBgtr5BvtgbV54BBo88VlFJgDJFQn7R09cTFUEo # UwaJoS+nIaiZ0bQQVZhZloVppUaTdVJojzfVRCZZctga96/tu1HSFnGLnbEFpUN3 # KOf+XnVNS6Ro+nPSDf9bMjbIom2JicGFfV+6yMgIoxY/d5UA2dTZfefil4TAlSod # 6PsTgg+jrm8= # =/Fw0 # -----END PGP SIGNATURE----- # gpg: Signature made Thu 27 Oct 2022 14:29:38 EDT # gpg: using RSA key DC3DEB159A9AF95D3D7456FE7F09B272C88F2FD6 # gpg: issuer "kwolf@redhat.com" # gpg: Good signature from "Kevin Wolf <kwolf@redhat.com>" [full] # Primary key fingerprint: DC3D EB15 9A9A F95D 3D74 56FE 7F09 B272 C88F 2FD6 * tag 'for-upstream' of https://repo.or.cz/qemu/kevin: (58 commits) block/block-backend: blk_set_enable_write_cache is IO_CODE monitor: switch to *_co_* functions vmdk: switch to *_co_* functions vhdx: switch to *_co_* functions vdi: switch to *_co_* functions qed: switch to *_co_* functions qcow2: switch to *_co_* functions qcow: switch to *_co_* functions parallels: switch to *_co_* functions mirror: switch to *_co_* functions block: switch to *_co_* functions commit: switch to *_co_* functions vmdk: manually add more coroutine_fn annotations qcow2: manually add more coroutine_fn annotations qcow: manually add more coroutine_fn annotations blkdebug: add missing coroutine_fn annotation for indirect-called functions qcow2: add coroutine_fn annotation for indirect-called functions block: add missing coroutine_fn annotation to BlockDriverState callbacks coroutine-io: add missing coroutine_fn annotation to prototypes coroutine-lock: add missing coroutine_fn annotation to prototypes ... Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
334 lines
9.8 KiB
C
334 lines
9.8 KiB
C
/*
|
|
* Block protocol for block driver correctness testing
|
|
*
|
|
* Copyright (C) 2010 IBM, Corp.
|
|
*
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
* See the COPYING file in the top-level directory.
|
|
*/
|
|
|
|
#include "qemu/osdep.h"
|
|
#include "qapi/error.h"
|
|
#include "qemu/sockets.h" /* for EINPROGRESS on Windows */
|
|
#include "block/block_int.h"
|
|
#include "qapi/qmp/qdict.h"
|
|
#include "qapi/qmp/qstring.h"
|
|
#include "qemu/cutils.h"
|
|
#include "qemu/module.h"
|
|
#include "qemu/option.h"
|
|
#include "qemu/memalign.h"
|
|
|
|
typedef struct {
|
|
BdrvChild *test_file;
|
|
} BDRVBlkverifyState;
|
|
|
|
typedef struct BlkverifyRequest {
|
|
Coroutine *co;
|
|
BlockDriverState *bs;
|
|
|
|
/* Request metadata */
|
|
bool is_write;
|
|
uint64_t offset;
|
|
uint64_t bytes;
|
|
int flags;
|
|
|
|
int (*request_fn)(BdrvChild *, int64_t, int64_t, QEMUIOVector *,
|
|
BdrvRequestFlags);
|
|
|
|
int ret; /* test image result */
|
|
int raw_ret; /* raw image result */
|
|
|
|
unsigned int done; /* completion counter */
|
|
|
|
QEMUIOVector *qiov; /* user I/O vector */
|
|
QEMUIOVector *raw_qiov; /* cloned I/O vector for raw file */
|
|
} BlkverifyRequest;
|
|
|
|
static void G_GNUC_PRINTF(2, 3) blkverify_err(BlkverifyRequest *r,
|
|
const char *fmt, ...)
|
|
{
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
fprintf(stderr, "blkverify: %s offset=%" PRId64 " bytes=%" PRId64 " ",
|
|
r->is_write ? "write" : "read", r->offset, r->bytes);
|
|
vfprintf(stderr, fmt, ap);
|
|
fprintf(stderr, "\n");
|
|
va_end(ap);
|
|
exit(1);
|
|
}
|
|
|
|
/* Valid blkverify filenames look like blkverify:path/to/raw_image:path/to/image */
|
|
static void blkverify_parse_filename(const char *filename, QDict *options,
|
|
Error **errp)
|
|
{
|
|
const char *c;
|
|
QString *raw_path;
|
|
|
|
|
|
/* Parse the blkverify: prefix */
|
|
if (!strstart(filename, "blkverify:", &filename)) {
|
|
/* There was no prefix; therefore, all options have to be already
|
|
present in the QDict (except for the filename) */
|
|
qdict_put_str(options, "x-image", filename);
|
|
return;
|
|
}
|
|
|
|
/* Parse the raw image filename */
|
|
c = strchr(filename, ':');
|
|
if (c == NULL) {
|
|
error_setg(errp, "blkverify requires raw copy and original image path");
|
|
return;
|
|
}
|
|
|
|
/* TODO Implement option pass-through and set raw.filename here */
|
|
raw_path = qstring_from_substr(filename, 0, c - filename);
|
|
qdict_put(options, "x-raw", raw_path);
|
|
|
|
/* TODO Allow multi-level nesting and set file.filename here */
|
|
filename = c + 1;
|
|
qdict_put_str(options, "x-image", filename);
|
|
}
|
|
|
|
static QemuOptsList runtime_opts = {
|
|
.name = "blkverify",
|
|
.head = QTAILQ_HEAD_INITIALIZER(runtime_opts.head),
|
|
.desc = {
|
|
{
|
|
.name = "x-raw",
|
|
.type = QEMU_OPT_STRING,
|
|
.help = "[internal use only, will be removed]",
|
|
},
|
|
{
|
|
.name = "x-image",
|
|
.type = QEMU_OPT_STRING,
|
|
.help = "[internal use only, will be removed]",
|
|
},
|
|
{ /* end of list */ }
|
|
},
|
|
};
|
|
|
|
static int blkverify_open(BlockDriverState *bs, QDict *options, int flags,
|
|
Error **errp)
|
|
{
|
|
BDRVBlkverifyState *s = bs->opaque;
|
|
QemuOpts *opts;
|
|
int ret;
|
|
|
|
opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
|
|
if (!qemu_opts_absorb_qdict(opts, options, errp)) {
|
|
ret = -EINVAL;
|
|
goto fail;
|
|
}
|
|
|
|
/* Open the raw file */
|
|
ret = bdrv_open_file_child(qemu_opt_get(opts, "x-raw"), options, "raw",
|
|
bs, errp);
|
|
if (ret < 0) {
|
|
goto fail;
|
|
}
|
|
|
|
/* Open the test file */
|
|
s->test_file = bdrv_open_child(qemu_opt_get(opts, "x-image"), options,
|
|
"test", bs, &child_of_bds, BDRV_CHILD_DATA,
|
|
false, errp);
|
|
if (!s->test_file) {
|
|
ret = -EINVAL;
|
|
goto fail;
|
|
}
|
|
|
|
bs->supported_write_flags = BDRV_REQ_WRITE_UNCHANGED;
|
|
bs->supported_zero_flags = BDRV_REQ_WRITE_UNCHANGED;
|
|
|
|
ret = 0;
|
|
fail:
|
|
qemu_opts_del(opts);
|
|
return ret;
|
|
}
|
|
|
|
static void blkverify_close(BlockDriverState *bs)
|
|
{
|
|
BDRVBlkverifyState *s = bs->opaque;
|
|
|
|
bdrv_unref_child(bs, s->test_file);
|
|
s->test_file = NULL;
|
|
}
|
|
|
|
static int64_t blkverify_getlength(BlockDriverState *bs)
|
|
{
|
|
BDRVBlkverifyState *s = bs->opaque;
|
|
|
|
return bdrv_getlength(s->test_file->bs);
|
|
}
|
|
|
|
static void coroutine_fn blkverify_do_test_req(void *opaque)
|
|
{
|
|
BlkverifyRequest *r = opaque;
|
|
BDRVBlkverifyState *s = r->bs->opaque;
|
|
|
|
r->ret = r->request_fn(s->test_file, r->offset, r->bytes, r->qiov,
|
|
r->flags);
|
|
r->done++;
|
|
qemu_coroutine_enter_if_inactive(r->co);
|
|
}
|
|
|
|
static void coroutine_fn blkverify_do_raw_req(void *opaque)
|
|
{
|
|
BlkverifyRequest *r = opaque;
|
|
|
|
r->raw_ret = r->request_fn(r->bs->file, r->offset, r->bytes, r->raw_qiov,
|
|
r->flags);
|
|
r->done++;
|
|
qemu_coroutine_enter_if_inactive(r->co);
|
|
}
|
|
|
|
static int coroutine_fn
|
|
blkverify_co_prwv(BlockDriverState *bs, BlkverifyRequest *r, uint64_t offset,
|
|
uint64_t bytes, QEMUIOVector *qiov, QEMUIOVector *raw_qiov,
|
|
int flags, bool is_write)
|
|
{
|
|
Coroutine *co_a, *co_b;
|
|
|
|
*r = (BlkverifyRequest) {
|
|
.co = qemu_coroutine_self(),
|
|
.bs = bs,
|
|
.offset = offset,
|
|
.bytes = bytes,
|
|
.qiov = qiov,
|
|
.raw_qiov = raw_qiov,
|
|
.flags = flags,
|
|
.is_write = is_write,
|
|
.request_fn = is_write ? bdrv_co_pwritev : bdrv_co_preadv,
|
|
};
|
|
|
|
co_a = qemu_coroutine_create(blkverify_do_test_req, r);
|
|
co_b = qemu_coroutine_create(blkverify_do_raw_req, r);
|
|
|
|
qemu_coroutine_enter(co_a);
|
|
qemu_coroutine_enter(co_b);
|
|
|
|
while (r->done < 2) {
|
|
qemu_coroutine_yield();
|
|
}
|
|
|
|
if (r->ret != r->raw_ret) {
|
|
blkverify_err(r, "return value mismatch %d != %d", r->ret, r->raw_ret);
|
|
}
|
|
|
|
return r->ret;
|
|
}
|
|
|
|
static int coroutine_fn
|
|
blkverify_co_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes,
|
|
QEMUIOVector *qiov, BdrvRequestFlags flags)
|
|
{
|
|
BlkverifyRequest r;
|
|
QEMUIOVector raw_qiov;
|
|
void *buf;
|
|
ssize_t cmp_offset;
|
|
int ret;
|
|
|
|
buf = qemu_blockalign(bs->file->bs, qiov->size);
|
|
qemu_iovec_init(&raw_qiov, qiov->niov);
|
|
qemu_iovec_clone(&raw_qiov, qiov, buf);
|
|
|
|
ret = blkverify_co_prwv(bs, &r, offset, bytes, qiov, &raw_qiov,
|
|
flags & ~BDRV_REQ_REGISTERED_BUF, false);
|
|
|
|
cmp_offset = qemu_iovec_compare(qiov, &raw_qiov);
|
|
if (cmp_offset != -1) {
|
|
blkverify_err(&r, "contents mismatch at offset %" PRId64,
|
|
offset + cmp_offset);
|
|
}
|
|
|
|
qemu_iovec_destroy(&raw_qiov);
|
|
qemu_vfree(buf);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static int coroutine_fn
|
|
blkverify_co_pwritev(BlockDriverState *bs, int64_t offset, int64_t bytes,
|
|
QEMUIOVector *qiov, BdrvRequestFlags flags)
|
|
{
|
|
BlkverifyRequest r;
|
|
return blkverify_co_prwv(bs, &r, offset, bytes, qiov, qiov, flags, true);
|
|
}
|
|
|
|
static int coroutine_fn blkverify_co_flush(BlockDriverState *bs)
|
|
{
|
|
BDRVBlkverifyState *s = bs->opaque;
|
|
|
|
/* Only flush test file, the raw file is not important */
|
|
return bdrv_co_flush(s->test_file->bs);
|
|
}
|
|
|
|
static bool blkverify_recurse_can_replace(BlockDriverState *bs,
|
|
BlockDriverState *to_replace)
|
|
{
|
|
BDRVBlkverifyState *s = bs->opaque;
|
|
|
|
/*
|
|
* blkverify quits the whole qemu process if there is a mismatch
|
|
* between bs->file->bs and s->test_file->bs. Therefore, we know
|
|
* know that both must match bs and we can recurse down to either.
|
|
*/
|
|
return bdrv_recurse_can_replace(bs->file->bs, to_replace) ||
|
|
bdrv_recurse_can_replace(s->test_file->bs, to_replace);
|
|
}
|
|
|
|
static void blkverify_refresh_filename(BlockDriverState *bs)
|
|
{
|
|
BDRVBlkverifyState *s = bs->opaque;
|
|
|
|
if (bs->file->bs->exact_filename[0]
|
|
&& s->test_file->bs->exact_filename[0])
|
|
{
|
|
int ret = snprintf(bs->exact_filename, sizeof(bs->exact_filename),
|
|
"blkverify:%s:%s",
|
|
bs->file->bs->exact_filename,
|
|
s->test_file->bs->exact_filename);
|
|
if (ret >= sizeof(bs->exact_filename)) {
|
|
/* An overflow makes the filename unusable, so do not report any */
|
|
bs->exact_filename[0] = 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
static char *blkverify_dirname(BlockDriverState *bs, Error **errp)
|
|
{
|
|
/* In general, there are two BDSs with different dirnames below this one;
|
|
* so there is no unique dirname we could return (unless both are equal by
|
|
* chance). Therefore, to be consistent, just always return NULL. */
|
|
error_setg(errp, "Cannot generate a base directory for blkverify nodes");
|
|
return NULL;
|
|
}
|
|
|
|
static BlockDriver bdrv_blkverify = {
|
|
.format_name = "blkverify",
|
|
.protocol_name = "blkverify",
|
|
.instance_size = sizeof(BDRVBlkverifyState),
|
|
|
|
.bdrv_parse_filename = blkverify_parse_filename,
|
|
.bdrv_file_open = blkverify_open,
|
|
.bdrv_close = blkverify_close,
|
|
.bdrv_child_perm = bdrv_default_perms,
|
|
.bdrv_getlength = blkverify_getlength,
|
|
.bdrv_refresh_filename = blkverify_refresh_filename,
|
|
.bdrv_dirname = blkverify_dirname,
|
|
|
|
.bdrv_co_preadv = blkverify_co_preadv,
|
|
.bdrv_co_pwritev = blkverify_co_pwritev,
|
|
.bdrv_co_flush = blkverify_co_flush,
|
|
|
|
.is_filter = true,
|
|
.bdrv_recurse_can_replace = blkverify_recurse_can_replace,
|
|
};
|
|
|
|
static void bdrv_blkverify_init(void)
|
|
{
|
|
bdrv_register(&bdrv_blkverify);
|
|
}
|
|
|
|
block_init(bdrv_blkverify_init);
|