2016-03-14 10:45:10 +03:00
|
|
|
/*
|
|
|
|
* Block protocol for record/replay
|
|
|
|
*
|
|
|
|
* Copyright (c) 2010-2016 Institute for System Programming
|
|
|
|
* of the Russian Academy of Sciences.
|
|
|
|
*
|
|
|
|
* 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"
|
2019-05-23 17:35:07 +03:00
|
|
|
#include "qemu/module.h"
|
2016-03-14 10:45:10 +03:00
|
|
|
#include "block/block_int.h"
|
|
|
|
#include "sysemu/replay.h"
|
|
|
|
#include "qapi/error.h"
|
|
|
|
|
|
|
|
typedef struct Request {
|
|
|
|
Coroutine *co;
|
|
|
|
QEMUBH *bh;
|
|
|
|
} Request;
|
|
|
|
|
|
|
|
static int blkreplay_open(BlockDriverState *bs, QDict *options, int flags,
|
|
|
|
Error **errp)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Open the image file */
|
2020-05-13 14:05:36 +03:00
|
|
|
bs->file = bdrv_open_child(NULL, options, "image", bs, &child_of_bds,
|
|
|
|
BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY,
|
2021-02-02 15:49:45 +03:00
|
|
|
false, errp);
|
|
|
|
if (!bs->file) {
|
2016-03-14 10:45:10 +03:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2018-04-21 16:29:26 +03:00
|
|
|
bs->supported_write_flags = BDRV_REQ_WRITE_UNCHANGED;
|
|
|
|
bs->supported_zero_flags = BDRV_REQ_WRITE_UNCHANGED;
|
|
|
|
|
2016-03-14 10:45:10 +03:00
|
|
|
ret = 0;
|
|
|
|
fail:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int64_t blkreplay_getlength(BlockDriverState *bs)
|
|
|
|
{
|
|
|
|
return bdrv_getlength(bs->file->bs);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This bh is used for synchronization of return from coroutines.
|
|
|
|
It continues yielded coroutine which then finishes its execution.
|
|
|
|
BH is called adjusted to some replay checkpoint, therefore
|
|
|
|
record and replay will always finish coroutines deterministically.
|
|
|
|
*/
|
|
|
|
static void blkreplay_bh_cb(void *opaque)
|
|
|
|
{
|
|
|
|
Request *req = opaque;
|
2017-02-13 16:52:31 +03:00
|
|
|
aio_co_wake(req->co);
|
2016-03-14 10:45:10 +03:00
|
|
|
qemu_bh_delete(req->bh);
|
|
|
|
g_free(req);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void block_request_create(uint64_t reqid, BlockDriverState *bs,
|
|
|
|
Coroutine *co)
|
|
|
|
{
|
|
|
|
Request *req = g_new(Request, 1);
|
|
|
|
*req = (Request) {
|
|
|
|
.co = co,
|
|
|
|
.bh = aio_bh_new(bdrv_get_aio_context(bs), blkreplay_bh_cb, req),
|
|
|
|
};
|
|
|
|
replay_block_event(req->bh, reqid);
|
|
|
|
}
|
|
|
|
|
2016-05-30 15:31:59 +03:00
|
|
|
static int coroutine_fn blkreplay_co_preadv(BlockDriverState *bs,
|
block: use int64_t instead of uint64_t in driver read handlers
We are generally moving to int64_t for both offset and bytes parameters
on all io paths.
Main motivation is realization of 64-bit write_zeroes operation for
fast zeroing large disk chunks, up to the whole disk.
We chose signed type, to be consistent with off_t (which is signed) and
with possibility for signed return type (where negative value means
error).
So, convert driver read handlers parameters which are already 64bit to
signed type.
While being here, convert also flags parameter to be BdrvRequestFlags.
Now let's consider all callers. Simple
git grep '\->bdrv_\(aio\|co\)_preadv\(_part\)\?'
shows that's there three callers of driver function:
bdrv_driver_preadv() in block/io.c, passes int64_t, checked by
bdrv_check_qiov_request() to be non-negative.
qcow2_load_vmstate() does bdrv_check_qiov_request().
do_perform_cow_read() has uint64_t argument. And a lot of things in
qcow2 driver are uint64_t, so converting it is big job. But we must
not work with requests that don't satisfy bdrv_check_qiov_request(),
so let's just assert it here.
Still, the functions may be called directly, not only by drv->...
Let's check:
git grep '\.bdrv_\(aio\|co\)_preadv\(_part\)\?\s*=' | \
awk '{print $4}' | sed 's/,//' | sed 's/&//' | sort | uniq | \
while read func; do git grep "$func(" | \
grep -v "$func(BlockDriverState"; done
The only one such caller:
QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, &data, 1);
...
ret = bdrv_replace_test_co_preadv(bs, 0, 1, &qiov, 0);
in tests/unit/test-bdrv-drain.c, and it's OK obviously.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20210903102807.27127-4-vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
[eblake: fix typos]
Signed-off-by: Eric Blake <eblake@redhat.com>
2021-09-03 13:27:59 +03:00
|
|
|
int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags)
|
2016-03-14 10:45:10 +03:00
|
|
|
{
|
2016-09-26 11:08:16 +03:00
|
|
|
uint64_t reqid = blkreplay_next_id();
|
2016-06-20 22:31:46 +03:00
|
|
|
int ret = bdrv_co_preadv(bs->file, offset, bytes, qiov, flags);
|
2016-03-14 10:45:10 +03:00
|
|
|
block_request_create(reqid, bs, qemu_coroutine_self());
|
|
|
|
qemu_coroutine_yield();
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-05-30 15:31:59 +03:00
|
|
|
static int coroutine_fn blkreplay_co_pwritev(BlockDriverState *bs,
|
|
|
|
uint64_t offset, uint64_t bytes, QEMUIOVector *qiov, int flags)
|
2016-03-14 10:45:10 +03:00
|
|
|
{
|
2016-09-26 11:08:16 +03:00
|
|
|
uint64_t reqid = blkreplay_next_id();
|
2016-06-20 22:31:46 +03:00
|
|
|
int ret = bdrv_co_pwritev(bs->file, offset, bytes, qiov, flags);
|
2016-03-14 10:45:10 +03:00
|
|
|
block_request_create(reqid, bs, qemu_coroutine_self());
|
|
|
|
qemu_coroutine_yield();
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-06-02 00:10:07 +03:00
|
|
|
static int coroutine_fn blkreplay_co_pwrite_zeroes(BlockDriverState *bs,
|
2017-06-09 13:18:08 +03:00
|
|
|
int64_t offset, int bytes, BdrvRequestFlags flags)
|
2016-03-14 10:45:10 +03:00
|
|
|
{
|
2016-09-26 11:08:16 +03:00
|
|
|
uint64_t reqid = blkreplay_next_id();
|
2017-06-09 13:18:08 +03:00
|
|
|
int ret = bdrv_co_pwrite_zeroes(bs->file, offset, bytes, flags);
|
2016-03-14 10:45:10 +03:00
|
|
|
block_request_create(reqid, bs, qemu_coroutine_self());
|
|
|
|
qemu_coroutine_yield();
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-07-16 02:22:59 +03:00
|
|
|
static int coroutine_fn blkreplay_co_pdiscard(BlockDriverState *bs,
|
2017-06-09 13:18:08 +03:00
|
|
|
int64_t offset, int bytes)
|
2016-03-14 10:45:10 +03:00
|
|
|
{
|
2016-09-26 11:08:16 +03:00
|
|
|
uint64_t reqid = blkreplay_next_id();
|
2018-07-10 09:31:17 +03:00
|
|
|
int ret = bdrv_co_pdiscard(bs->file, offset, bytes);
|
2016-03-14 10:45:10 +03:00
|
|
|
block_request_create(reqid, bs, qemu_coroutine_self());
|
|
|
|
qemu_coroutine_yield();
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int coroutine_fn blkreplay_co_flush(BlockDriverState *bs)
|
|
|
|
{
|
2016-09-26 11:08:16 +03:00
|
|
|
uint64_t reqid = blkreplay_next_id();
|
2016-03-14 10:45:10 +03:00
|
|
|
int ret = bdrv_co_flush(bs->file->bs);
|
|
|
|
block_request_create(reqid, bs, qemu_coroutine_self());
|
|
|
|
qemu_coroutine_yield();
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-09-17 14:57:51 +03:00
|
|
|
static int blkreplay_snapshot_goto(BlockDriverState *bs,
|
|
|
|
const char *snapshot_id)
|
|
|
|
{
|
|
|
|
return bdrv_snapshot_goto(bs->file->bs, snapshot_id, NULL);
|
|
|
|
}
|
|
|
|
|
2016-03-14 10:45:10 +03:00
|
|
|
static BlockDriver bdrv_blkreplay = {
|
|
|
|
.format_name = "blkreplay",
|
|
|
|
.instance_size = 0,
|
2020-05-13 14:05:11 +03:00
|
|
|
.is_filter = true,
|
2016-03-14 10:45:10 +03:00
|
|
|
|
2018-03-13 01:07:52 +03:00
|
|
|
.bdrv_open = blkreplay_open,
|
2020-05-13 14:05:39 +03:00
|
|
|
.bdrv_child_perm = bdrv_default_perms,
|
2016-03-14 10:45:10 +03:00
|
|
|
.bdrv_getlength = blkreplay_getlength,
|
|
|
|
|
2016-05-30 15:31:59 +03:00
|
|
|
.bdrv_co_preadv = blkreplay_co_preadv,
|
|
|
|
.bdrv_co_pwritev = blkreplay_co_pwritev,
|
2016-03-14 10:45:10 +03:00
|
|
|
|
2016-06-02 00:10:07 +03:00
|
|
|
.bdrv_co_pwrite_zeroes = blkreplay_co_pwrite_zeroes,
|
2016-07-16 02:22:59 +03:00
|
|
|
.bdrv_co_pdiscard = blkreplay_co_pdiscard,
|
2016-03-14 10:45:10 +03:00
|
|
|
.bdrv_co_flush = blkreplay_co_flush,
|
2019-09-17 14:57:51 +03:00
|
|
|
|
|
|
|
.bdrv_snapshot_goto = blkreplay_snapshot_goto,
|
2016-03-14 10:45:10 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static void bdrv_blkreplay_init(void)
|
|
|
|
{
|
|
|
|
bdrv_register(&bdrv_blkreplay);
|
|
|
|
}
|
|
|
|
|
|
|
|
block_init(bdrv_blkreplay_init);
|