mirror of
https://github.com/izzy2lost/xemu.git
synced 2026-07-06 00:20:22 -07:00
Merge tag 'for-upstream' of https://repo.or.cz/qemu/kevin into staging
Block layer patches - virtio-blk: use blk_io_plug_call() instead of notification BH - mirror: allow switching from background to active mode - qemu-img rebase: add compression support - Fix locking in media change monitor commands - Fix a few blockjob-related deadlocks when using iothread # -----BEGIN PGP SIGNATURE----- # # iQJFBAABCAAvFiEE3D3rFZqa+V09dFb+fwmycsiPL9YFAmVBTkERHGt3b2xmQHJl # ZGhhdC5jb20ACgkQfwmycsiPL9ZiqRAAqvsWbblmEGJ7TBKYQK3f8QshJ66RxzbC # 4eSjKHrciWNTeeIeU8r8OvFcPPoTcPXxpcmasD2gsAxG5W5N8vkPbBkW+YT4YdDJ # pWJXrbJ15nILC4DmnR1ARVtvxKgv9zy5LSm5bjss1K+OSYJl/nx+ILjmfVZnYDF7 # z1dP/G0JxKKm4JzAIdBE3uZS+6Q5kx/wGYlJv8EQmlH3DYfsJfy6Lthe9jfw8ijg # lSqLoQ+D0lEd6Bk4XbkUqqBxFcYBWTfU6qPZoyIO94zCTwTG9yIjmoivxmmfwQZq # cJUTGGZjcxpJYnvcC6P13WgcWBtcD9L2kYFVH0JyjpwcSg9cCGHMF66n9pSlyEGq # DUikwVzbTwOotwzYQyM88v4ET+2+Qdcwn8pRbv9PllEczh0kAsUAEuxSgtz4NEcN # bZrap/16xHFybNOKkMZcmpqxspT5NXKbDODUP0IvbSYMOYpWS983nBTxwMRpyHog # 2TFDZu4DjNiPkI2BcYM5VOKk6diNowZFShcEKvoaOLX/n9EBhP0tjoH9VUn1800F # myHrhF2jpIf9GhErMWB7N2W3/0aK0pqdQgbpVnd1ARDdIdYkr7G/S+50D9K80b6n # 0q2E7br4S5bcsY0HQzBL9YARSayY+lVOssLoolCWEsYzijdBQmAvs5THajFKcism # /idI6nlp2Vs= # =RdxS # -----END PGP SIGNATURE----- # gpg: Signature made Wed 01 Nov 2023 03:58:09 JST # 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: (27 commits) iotests: add test for changing mirror's copy_mode mirror: return mirror-specific information upon query blockjob: query driver-specific info via a new 'query' driver method qapi/block-core: turn BlockJobInfo into a union qapi/block-core: use JobType for BlockJobInfo's type mirror: implement mirror_change method block/mirror: determine copy_to_target only once block/mirror: move dirty bitmap to filter block/mirror: set actively_synced even after the job is ready blockjob: introduce block-job-change QMP command virtio-blk: remove batch notification BH virtio: use defer_call() in virtio_irqfd_notify() util/defer-call: move defer_call() to util/ block: rename blk_io_plug_call() API to defer_call() blockdev: mirror: avoid potential deadlock when using iothread block: avoid potential deadlock during bdrv_graph_wrlock() in bdrv_close() blockjob: drop AioContext lock before calling bdrv_graph_wrlock() iotests: Test media change with iothreads block: Fix locking in media change monitor commands iotests: add tests for "qemu-img rebase" with compression ... Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
+2
-1
@@ -2755,12 +2755,13 @@ S: Supported
|
||||
F: util/async.c
|
||||
F: util/aio-*.c
|
||||
F: util/aio-*.h
|
||||
F: util/defer-call.c
|
||||
F: util/fdmon-*.c
|
||||
F: block/io.c
|
||||
F: block/plug.c
|
||||
F: migration/block*
|
||||
F: include/block/aio.h
|
||||
F: include/block/aio-wait.h
|
||||
F: include/qemu/defer-call.h
|
||||
F: scripts/qemugdb/aio.py
|
||||
F: tests/unit/test-fdmon-epoll.c
|
||||
T: git https://github.com/stefanha/qemu.git block
|
||||
|
||||
@@ -5200,7 +5200,7 @@ static void bdrv_close(BlockDriverState *bs)
|
||||
bs->drv = NULL;
|
||||
}
|
||||
|
||||
bdrv_graph_wrlock(NULL);
|
||||
bdrv_graph_wrlock(bs);
|
||||
QLIST_FOREACH_SAFE(child, &bs->children, next, next) {
|
||||
bdrv_unref_child(bs, child);
|
||||
}
|
||||
|
||||
+5
-4
@@ -13,6 +13,7 @@
|
||||
#include "block/block_int.h"
|
||||
#include "exec/memory.h"
|
||||
#include "exec/cpu-common.h" /* for qemu_ram_get_fd() */
|
||||
#include "qemu/defer-call.h"
|
||||
#include "qapi/error.h"
|
||||
#include "qemu/error-report.h"
|
||||
#include "qapi/qmp/qdict.h"
|
||||
@@ -312,10 +313,10 @@ static void blkio_detach_aio_context(BlockDriverState *bs)
|
||||
}
|
||||
|
||||
/*
|
||||
* Called by blk_io_unplug() or immediately if not plugged. Called without
|
||||
* blkio_lock.
|
||||
* Called by defer_call_end() or immediately if not in a deferred section.
|
||||
* Called without blkio_lock.
|
||||
*/
|
||||
static void blkio_unplug_fn(void *opaque)
|
||||
static void blkio_deferred_fn(void *opaque)
|
||||
{
|
||||
BDRVBlkioState *s = opaque;
|
||||
|
||||
@@ -332,7 +333,7 @@ static void blkio_submit_io(BlockDriverState *bs)
|
||||
{
|
||||
BDRVBlkioState *s = bs->opaque;
|
||||
|
||||
blk_io_plug_call(blkio_unplug_fn, s);
|
||||
defer_call(blkio_deferred_fn, s);
|
||||
}
|
||||
|
||||
static int coroutine_fn
|
||||
|
||||
+9
-2
@@ -15,6 +15,7 @@
|
||||
#include "block/block.h"
|
||||
#include "block/raw-aio.h"
|
||||
#include "qemu/coroutine.h"
|
||||
#include "qemu/defer-call.h"
|
||||
#include "qapi/error.h"
|
||||
#include "sysemu/block-backend.h"
|
||||
#include "trace.h"
|
||||
@@ -124,6 +125,9 @@ static void luring_process_completions(LuringState *s)
|
||||
{
|
||||
struct io_uring_cqe *cqes;
|
||||
int total_bytes;
|
||||
|
||||
defer_call_begin();
|
||||
|
||||
/*
|
||||
* Request completion callbacks can run the nested event loop.
|
||||
* Schedule ourselves so the nested event loop will "see" remaining
|
||||
@@ -216,7 +220,10 @@ end:
|
||||
aio_co_wake(luringcb->co);
|
||||
}
|
||||
}
|
||||
|
||||
qemu_bh_cancel(s->completion_bh);
|
||||
|
||||
defer_call_end();
|
||||
}
|
||||
|
||||
static int ioq_submit(LuringState *s)
|
||||
@@ -306,7 +313,7 @@ static void ioq_init(LuringQueue *io_q)
|
||||
io_q->blocked = false;
|
||||
}
|
||||
|
||||
static void luring_unplug_fn(void *opaque)
|
||||
static void luring_deferred_fn(void *opaque)
|
||||
{
|
||||
LuringState *s = opaque;
|
||||
trace_luring_unplug_fn(s, s->io_q.blocked, s->io_q.in_queue,
|
||||
@@ -367,7 +374,7 @@ static int luring_do_submit(int fd, LuringAIOCB *luringcb, LuringState *s,
|
||||
return ret;
|
||||
}
|
||||
|
||||
blk_io_plug_call(luring_unplug_fn, s);
|
||||
defer_call(luring_deferred_fn, s);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
+7
-2
@@ -14,6 +14,7 @@
|
||||
#include "block/raw-aio.h"
|
||||
#include "qemu/event_notifier.h"
|
||||
#include "qemu/coroutine.h"
|
||||
#include "qemu/defer-call.h"
|
||||
#include "qapi/error.h"
|
||||
#include "sysemu/block-backend.h"
|
||||
|
||||
@@ -204,6 +205,8 @@ static void qemu_laio_process_completions(LinuxAioState *s)
|
||||
{
|
||||
struct io_event *events;
|
||||
|
||||
defer_call_begin();
|
||||
|
||||
/* Reschedule so nested event loops see currently pending completions */
|
||||
qemu_bh_schedule(s->completion_bh);
|
||||
|
||||
@@ -230,6 +233,8 @@ static void qemu_laio_process_completions(LinuxAioState *s)
|
||||
* own `for` loop. If we are the last all counters dropped to zero. */
|
||||
s->event_max = 0;
|
||||
s->event_idx = 0;
|
||||
|
||||
defer_call_end();
|
||||
}
|
||||
|
||||
static void qemu_laio_process_completions_and_submit(LinuxAioState *s)
|
||||
@@ -353,7 +358,7 @@ static uint64_t laio_max_batch(LinuxAioState *s, uint64_t dev_max_batch)
|
||||
return max_batch;
|
||||
}
|
||||
|
||||
static void laio_unplug_fn(void *opaque)
|
||||
static void laio_deferred_fn(void *opaque)
|
||||
{
|
||||
LinuxAioState *s = opaque;
|
||||
|
||||
@@ -393,7 +398,7 @@ static int laio_do_submit(int fd, struct qemu_laiocb *laiocb, off_t offset,
|
||||
if (s->io_q.in_queue >= laio_max_batch(s, dev_max_batch)) {
|
||||
ioq_submit(s);
|
||||
} else {
|
||||
blk_io_plug_call(laio_unplug_fn, s);
|
||||
defer_call(laio_deferred_fn, s);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ block_ss.add(files(
|
||||
'mirror.c',
|
||||
'nbd.c',
|
||||
'null.c',
|
||||
'plug.c',
|
||||
'preallocate.c',
|
||||
'progress_meter.c',
|
||||
'qapi.c',
|
||||
|
||||
+94
-37
@@ -55,10 +55,18 @@ typedef struct MirrorBlockJob {
|
||||
BlockMirrorBackingMode backing_mode;
|
||||
/* Whether the target image requires explicit zero-initialization */
|
||||
bool zero_target;
|
||||
/*
|
||||
* To be accesssed with atomics. Written only under the BQL (required by the
|
||||
* current implementation of mirror_change()).
|
||||
*/
|
||||
MirrorCopyMode copy_mode;
|
||||
BlockdevOnError on_source_error, on_target_error;
|
||||
/* Set when the target is synced (dirty bitmap is clean, nothing
|
||||
* in flight) and the job is running in active mode */
|
||||
/*
|
||||
* To be accessed with atomics.
|
||||
*
|
||||
* Set when the target is synced (dirty bitmap is clean, nothing in flight)
|
||||
* and the job is running in active mode.
|
||||
*/
|
||||
bool actively_synced;
|
||||
bool should_complete;
|
||||
int64_t granularity;
|
||||
@@ -122,7 +130,7 @@ typedef enum MirrorMethod {
|
||||
static BlockErrorAction mirror_error_action(MirrorBlockJob *s, bool read,
|
||||
int error)
|
||||
{
|
||||
s->actively_synced = false;
|
||||
qatomic_set(&s->actively_synced, false);
|
||||
if (read) {
|
||||
return block_job_error_action(&s->common, s->on_source_error,
|
||||
true, error);
|
||||
@@ -962,7 +970,7 @@ static int coroutine_fn mirror_run(Job *job, Error **errp)
|
||||
if (s->bdev_length == 0) {
|
||||
/* Transition to the READY state and wait for complete. */
|
||||
job_transition_to_ready(&s->common.job);
|
||||
s->actively_synced = true;
|
||||
qatomic_set(&s->actively_synced, true);
|
||||
while (!job_cancel_requested(&s->common.job) && !s->should_complete) {
|
||||
job_yield(&s->common.job);
|
||||
}
|
||||
@@ -1074,9 +1082,9 @@ static int coroutine_fn mirror_run(Job *job, Error **errp)
|
||||
* the target in a consistent state.
|
||||
*/
|
||||
job_transition_to_ready(&s->common.job);
|
||||
if (s->copy_mode != MIRROR_COPY_MODE_BACKGROUND) {
|
||||
s->actively_synced = true;
|
||||
}
|
||||
}
|
||||
if (qatomic_read(&s->copy_mode) != MIRROR_COPY_MODE_BACKGROUND) {
|
||||
qatomic_set(&s->actively_synced, true);
|
||||
}
|
||||
|
||||
should_complete = s->should_complete ||
|
||||
@@ -1246,6 +1254,48 @@ static bool commit_active_cancel(Job *job, bool force)
|
||||
return force || !job_is_ready(job);
|
||||
}
|
||||
|
||||
static void mirror_change(BlockJob *job, BlockJobChangeOptions *opts,
|
||||
Error **errp)
|
||||
{
|
||||
MirrorBlockJob *s = container_of(job, MirrorBlockJob, common);
|
||||
BlockJobChangeOptionsMirror *change_opts = &opts->u.mirror;
|
||||
MirrorCopyMode current;
|
||||
|
||||
/*
|
||||
* The implementation relies on the fact that copy_mode is only written
|
||||
* under the BQL. Otherwise, further synchronization would be required.
|
||||
*/
|
||||
|
||||
GLOBAL_STATE_CODE();
|
||||
|
||||
if (qatomic_read(&s->copy_mode) == change_opts->copy_mode) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (change_opts->copy_mode != MIRROR_COPY_MODE_WRITE_BLOCKING) {
|
||||
error_setg(errp, "Change to copy mode '%s' is not implemented",
|
||||
MirrorCopyMode_str(change_opts->copy_mode));
|
||||
return;
|
||||
}
|
||||
|
||||
current = qatomic_cmpxchg(&s->copy_mode, MIRROR_COPY_MODE_BACKGROUND,
|
||||
change_opts->copy_mode);
|
||||
if (current != MIRROR_COPY_MODE_BACKGROUND) {
|
||||
error_setg(errp, "Expected current copy mode '%s', got '%s'",
|
||||
MirrorCopyMode_str(MIRROR_COPY_MODE_BACKGROUND),
|
||||
MirrorCopyMode_str(current));
|
||||
}
|
||||
}
|
||||
|
||||
static void mirror_query(BlockJob *job, BlockJobInfo *info)
|
||||
{
|
||||
MirrorBlockJob *s = container_of(job, MirrorBlockJob, common);
|
||||
|
||||
info->u.mirror = (BlockJobInfoMirror) {
|
||||
.actively_synced = qatomic_read(&s->actively_synced),
|
||||
};
|
||||
}
|
||||
|
||||
static const BlockJobDriver mirror_job_driver = {
|
||||
.job_driver = {
|
||||
.instance_size = sizeof(MirrorBlockJob),
|
||||
@@ -1260,6 +1310,8 @@ static const BlockJobDriver mirror_job_driver = {
|
||||
.cancel = mirror_cancel,
|
||||
},
|
||||
.drained_poll = mirror_drained_poll,
|
||||
.change = mirror_change,
|
||||
.query = mirror_query,
|
||||
};
|
||||
|
||||
static const BlockJobDriver commit_active_job_driver = {
|
||||
@@ -1378,7 +1430,7 @@ do_sync_target_write(MirrorBlockJob *job, MirrorMethod method,
|
||||
bitmap_end = QEMU_ALIGN_UP(offset + bytes, job->granularity);
|
||||
bdrv_set_dirty_bitmap(job->dirty_bitmap, bitmap_offset,
|
||||
bitmap_end - bitmap_offset);
|
||||
job->actively_synced = false;
|
||||
qatomic_set(&job->actively_synced, false);
|
||||
|
||||
action = mirror_error_action(job, false, -ret);
|
||||
if (action == BLOCK_ERROR_ACTION_REPORT) {
|
||||
@@ -1437,7 +1489,8 @@ static void coroutine_fn GRAPH_RDLOCK active_write_settle(MirrorOp *op)
|
||||
uint64_t end_chunk = DIV_ROUND_UP(op->offset + op->bytes,
|
||||
op->s->granularity);
|
||||
|
||||
if (!--op->s->in_active_write_counter && op->s->actively_synced) {
|
||||
if (!--op->s->in_active_write_counter &&
|
||||
qatomic_read(&op->s->actively_synced)) {
|
||||
BdrvChild *source = op->s->mirror_top_bs->backing;
|
||||
|
||||
if (QLIST_FIRST(&source->bs->parents) == source &&
|
||||
@@ -1463,21 +1516,21 @@ bdrv_mirror_top_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes,
|
||||
return bdrv_co_preadv(bs->backing, offset, bytes, qiov, flags);
|
||||
}
|
||||
|
||||
static bool should_copy_to_target(MirrorBDSOpaque *s)
|
||||
{
|
||||
return s->job && s->job->ret >= 0 &&
|
||||
!job_is_cancelled(&s->job->common.job) &&
|
||||
qatomic_read(&s->job->copy_mode) == MIRROR_COPY_MODE_WRITE_BLOCKING;
|
||||
}
|
||||
|
||||
static int coroutine_fn GRAPH_RDLOCK
|
||||
bdrv_mirror_top_do_write(BlockDriverState *bs, MirrorMethod method,
|
||||
uint64_t offset, uint64_t bytes, QEMUIOVector *qiov,
|
||||
int flags)
|
||||
bool copy_to_target, uint64_t offset, uint64_t bytes,
|
||||
QEMUIOVector *qiov, int flags)
|
||||
{
|
||||
MirrorOp *op = NULL;
|
||||
MirrorBDSOpaque *s = bs->opaque;
|
||||
int ret = 0;
|
||||
bool copy_to_target = false;
|
||||
|
||||
if (s->job) {
|
||||
copy_to_target = s->job->ret >= 0 &&
|
||||
!job_is_cancelled(&s->job->common.job) &&
|
||||
s->job->copy_mode == MIRROR_COPY_MODE_WRITE_BLOCKING;
|
||||
}
|
||||
|
||||
if (copy_to_target) {
|
||||
op = active_write_prepare(s->job, offset, bytes);
|
||||
@@ -1500,6 +1553,11 @@ bdrv_mirror_top_do_write(BlockDriverState *bs, MirrorMethod method,
|
||||
abort();
|
||||
}
|
||||
|
||||
if (!copy_to_target && s->job && s->job->dirty_bitmap) {
|
||||
qatomic_set(&s->job->actively_synced, false);
|
||||
bdrv_set_dirty_bitmap(s->job->dirty_bitmap, offset, bytes);
|
||||
}
|
||||
|
||||
if (ret < 0) {
|
||||
goto out;
|
||||
}
|
||||
@@ -1519,17 +1577,10 @@ static int coroutine_fn GRAPH_RDLOCK
|
||||
bdrv_mirror_top_pwritev(BlockDriverState *bs, int64_t offset, int64_t bytes,
|
||||
QEMUIOVector *qiov, BdrvRequestFlags flags)
|
||||
{
|
||||
MirrorBDSOpaque *s = bs->opaque;
|
||||
QEMUIOVector bounce_qiov;
|
||||
void *bounce_buf;
|
||||
int ret = 0;
|
||||
bool copy_to_target = false;
|
||||
|
||||
if (s->job) {
|
||||
copy_to_target = s->job->ret >= 0 &&
|
||||
!job_is_cancelled(&s->job->common.job) &&
|
||||
s->job->copy_mode == MIRROR_COPY_MODE_WRITE_BLOCKING;
|
||||
}
|
||||
bool copy_to_target = should_copy_to_target(bs->opaque);
|
||||
|
||||
if (copy_to_target) {
|
||||
/* The guest might concurrently modify the data to write; but
|
||||
@@ -1546,8 +1597,8 @@ bdrv_mirror_top_pwritev(BlockDriverState *bs, int64_t offset, int64_t bytes,
|
||||
flags &= ~BDRV_REQ_REGISTERED_BUF;
|
||||
}
|
||||
|
||||
ret = bdrv_mirror_top_do_write(bs, MIRROR_METHOD_COPY, offset, bytes, qiov,
|
||||
flags);
|
||||
ret = bdrv_mirror_top_do_write(bs, MIRROR_METHOD_COPY, copy_to_target,
|
||||
offset, bytes, qiov, flags);
|
||||
|
||||
if (copy_to_target) {
|
||||
qemu_iovec_destroy(&bounce_qiov);
|
||||
@@ -1570,15 +1621,17 @@ static int coroutine_fn GRAPH_RDLOCK
|
||||
bdrv_mirror_top_pwrite_zeroes(BlockDriverState *bs, int64_t offset,
|
||||
int64_t bytes, BdrvRequestFlags flags)
|
||||
{
|
||||
return bdrv_mirror_top_do_write(bs, MIRROR_METHOD_ZERO, offset, bytes, NULL,
|
||||
flags);
|
||||
bool copy_to_target = should_copy_to_target(bs->opaque);
|
||||
return bdrv_mirror_top_do_write(bs, MIRROR_METHOD_ZERO, copy_to_target,
|
||||
offset, bytes, NULL, flags);
|
||||
}
|
||||
|
||||
static int coroutine_fn GRAPH_RDLOCK
|
||||
bdrv_mirror_top_pdiscard(BlockDriverState *bs, int64_t offset, int64_t bytes)
|
||||
{
|
||||
return bdrv_mirror_top_do_write(bs, MIRROR_METHOD_DISCARD, offset, bytes,
|
||||
NULL, 0);
|
||||
bool copy_to_target = should_copy_to_target(bs->opaque);
|
||||
return bdrv_mirror_top_do_write(bs, MIRROR_METHOD_DISCARD, copy_to_target,
|
||||
offset, bytes, NULL, 0);
|
||||
}
|
||||
|
||||
static void bdrv_mirror_top_refresh_filename(BlockDriverState *bs)
|
||||
@@ -1813,7 +1866,7 @@ static BlockJob *mirror_start_job(
|
||||
s->is_none_mode = is_none_mode;
|
||||
s->backing_mode = backing_mode;
|
||||
s->zero_target = zero_target;
|
||||
s->copy_mode = copy_mode;
|
||||
qatomic_set(&s->copy_mode, copy_mode);
|
||||
s->base = base;
|
||||
s->base_overlay = bdrv_find_overlay(bs, base);
|
||||
s->granularity = granularity;
|
||||
@@ -1823,13 +1876,17 @@ static BlockJob *mirror_start_job(
|
||||
s->should_complete = true;
|
||||
}
|
||||
|
||||
s->dirty_bitmap = bdrv_create_dirty_bitmap(bs, granularity, NULL, errp);
|
||||
s->dirty_bitmap = bdrv_create_dirty_bitmap(s->mirror_top_bs, granularity,
|
||||
NULL, errp);
|
||||
if (!s->dirty_bitmap) {
|
||||
goto fail;
|
||||
}
|
||||
if (s->copy_mode == MIRROR_COPY_MODE_WRITE_BLOCKING) {
|
||||
bdrv_disable_dirty_bitmap(s->dirty_bitmap);
|
||||
}
|
||||
|
||||
/*
|
||||
* The dirty bitmap is set by bdrv_mirror_top_do_write() when not in active
|
||||
* mode.
|
||||
*/
|
||||
bdrv_disable_dirty_bitmap(s->dirty_bitmap);
|
||||
|
||||
ret = block_job_add_bdrv(&s->common, "source", bs, 0,
|
||||
BLK_PERM_WRITE_UNCHANGED | BLK_PERM_WRITE |
|
||||
|
||||
@@ -846,7 +846,7 @@ void hmp_info_block_jobs(Monitor *mon, const QDict *qdict)
|
||||
}
|
||||
|
||||
while (list) {
|
||||
if (strcmp(list->value->type, "stream") == 0) {
|
||||
if (list->value->type == JOB_TYPE_STREAM) {
|
||||
monitor_printf(mon, "Streaming device %s: Completed %" PRId64
|
||||
" of %" PRId64 " bytes, speed limit %" PRId64
|
||||
" bytes/s\n",
|
||||
@@ -858,7 +858,7 @@ void hmp_info_block_jobs(Monitor *mon, const QDict *qdict)
|
||||
monitor_printf(mon, "Type %s, device %s: Completed %" PRId64
|
||||
" of %" PRId64 " bytes, speed limit %" PRId64
|
||||
" bytes/s\n",
|
||||
list->value->type,
|
||||
JobType_str(list->value->type),
|
||||
list->value->device,
|
||||
list->value->offset,
|
||||
list->value->len,
|
||||
|
||||
+3
-2
@@ -16,6 +16,7 @@
|
||||
#include "qapi/error.h"
|
||||
#include "qapi/qmp/qdict.h"
|
||||
#include "qapi/qmp/qstring.h"
|
||||
#include "qemu/defer-call.h"
|
||||
#include "qemu/error-report.h"
|
||||
#include "qemu/main-loop.h"
|
||||
#include "qemu/module.h"
|
||||
@@ -476,7 +477,7 @@ static void nvme_trace_command(const NvmeCmd *cmd)
|
||||
}
|
||||
}
|
||||
|
||||
static void nvme_unplug_fn(void *opaque)
|
||||
static void nvme_deferred_fn(void *opaque)
|
||||
{
|
||||
NVMeQueuePair *q = opaque;
|
||||
|
||||
@@ -503,7 +504,7 @@ static void nvme_submit_command(NVMeQueuePair *q, NVMeRequest *req,
|
||||
q->need_kick++;
|
||||
qemu_mutex_unlock(&q->lock);
|
||||
|
||||
blk_io_plug_call(nvme_unplug_fn, q);
|
||||
defer_call(nvme_deferred_fn, q);
|
||||
}
|
||||
|
||||
static void nvme_admin_cmd_sync_cb(void *opaque, int ret)
|
||||
|
||||
-159
@@ -1,159 +0,0 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
/*
|
||||
* Block I/O plugging
|
||||
*
|
||||
* Copyright Red Hat.
|
||||
*
|
||||
* This API defers a function call within a blk_io_plug()/blk_io_unplug()
|
||||
* section, allowing multiple calls to batch up. This is a performance
|
||||
* optimization that is used in the block layer to submit several I/O requests
|
||||
* at once instead of individually:
|
||||
*
|
||||
* blk_io_plug(); <-- start of plugged region
|
||||
* ...
|
||||
* blk_io_plug_call(my_func, my_obj); <-- deferred my_func(my_obj) call
|
||||
* blk_io_plug_call(my_func, my_obj); <-- another
|
||||
* blk_io_plug_call(my_func, my_obj); <-- another
|
||||
* ...
|
||||
* blk_io_unplug(); <-- end of plugged region, my_func(my_obj) is called once
|
||||
*
|
||||
* This code is actually generic and not tied to the block layer. If another
|
||||
* subsystem needs this functionality, it could be renamed.
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "qemu/coroutine-tls.h"
|
||||
#include "qemu/notify.h"
|
||||
#include "qemu/thread.h"
|
||||
#include "sysemu/block-backend.h"
|
||||
|
||||
/* A function call that has been deferred until unplug() */
|
||||
typedef struct {
|
||||
void (*fn)(void *);
|
||||
void *opaque;
|
||||
} UnplugFn;
|
||||
|
||||
/* Per-thread state */
|
||||
typedef struct {
|
||||
unsigned count; /* how many times has plug() been called? */
|
||||
GArray *unplug_fns; /* functions to call at unplug time */
|
||||
} Plug;
|
||||
|
||||
/* Use get_ptr_plug() to fetch this thread-local value */
|
||||
QEMU_DEFINE_STATIC_CO_TLS(Plug, plug);
|
||||
|
||||
/* Called at thread cleanup time */
|
||||
static void blk_io_plug_atexit(Notifier *n, void *value)
|
||||
{
|
||||
Plug *plug = get_ptr_plug();
|
||||
g_array_free(plug->unplug_fns, TRUE);
|
||||
}
|
||||
|
||||
/* This won't involve coroutines, so use __thread */
|
||||
static __thread Notifier blk_io_plug_atexit_notifier;
|
||||
|
||||
/**
|
||||
* blk_io_plug_call:
|
||||
* @fn: a function pointer to be invoked
|
||||
* @opaque: a user-defined argument to @fn()
|
||||
*
|
||||
* Call @fn(@opaque) immediately if not within a blk_io_plug()/blk_io_unplug()
|
||||
* section.
|
||||
*
|
||||
* Otherwise defer the call until the end of the outermost
|
||||
* blk_io_plug()/blk_io_unplug() section in this thread. If the same
|
||||
* @fn/@opaque pair has already been deferred, it will only be called once upon
|
||||
* blk_io_unplug() so that accumulated calls are batched into a single call.
|
||||
*
|
||||
* The caller must ensure that @opaque is not freed before @fn() is invoked.
|
||||
*/
|
||||
void blk_io_plug_call(void (*fn)(void *), void *opaque)
|
||||
{
|
||||
Plug *plug = get_ptr_plug();
|
||||
|
||||
/* Call immediately if we're not plugged */
|
||||
if (plug->count == 0) {
|
||||
fn(opaque);
|
||||
return;
|
||||
}
|
||||
|
||||
GArray *array = plug->unplug_fns;
|
||||
if (!array) {
|
||||
array = g_array_new(FALSE, FALSE, sizeof(UnplugFn));
|
||||
plug->unplug_fns = array;
|
||||
blk_io_plug_atexit_notifier.notify = blk_io_plug_atexit;
|
||||
qemu_thread_atexit_add(&blk_io_plug_atexit_notifier);
|
||||
}
|
||||
|
||||
UnplugFn *fns = (UnplugFn *)array->data;
|
||||
UnplugFn new_fn = {
|
||||
.fn = fn,
|
||||
.opaque = opaque,
|
||||
};
|
||||
|
||||
/*
|
||||
* There won't be many, so do a linear search. If this becomes a bottleneck
|
||||
* then a binary search (glib 2.62+) or different data structure could be
|
||||
* used.
|
||||
*/
|
||||
for (guint i = 0; i < array->len; i++) {
|
||||
if (memcmp(&fns[i], &new_fn, sizeof(new_fn)) == 0) {
|
||||
return; /* already exists */
|
||||
}
|
||||
}
|
||||
|
||||
g_array_append_val(array, new_fn);
|
||||
}
|
||||
|
||||
/**
|
||||
* blk_io_plug: Defer blk_io_plug_call() functions until blk_io_unplug()
|
||||
*
|
||||
* blk_io_plug/unplug are thread-local operations. This means that multiple
|
||||
* threads can simultaneously call plug/unplug, but the caller must ensure that
|
||||
* each unplug() is called in the same thread of the matching plug().
|
||||
*
|
||||
* Nesting is supported. blk_io_plug_call() functions are only called at the
|
||||
* outermost blk_io_unplug().
|
||||
*/
|
||||
void blk_io_plug(void)
|
||||
{
|
||||
Plug *plug = get_ptr_plug();
|
||||
|
||||
assert(plug->count < UINT32_MAX);
|
||||
|
||||
plug->count++;
|
||||
}
|
||||
|
||||
/**
|
||||
* blk_io_unplug: Run any pending blk_io_plug_call() functions
|
||||
*
|
||||
* There must have been a matching blk_io_plug() call in the same thread prior
|
||||
* to this blk_io_unplug() call.
|
||||
*/
|
||||
void blk_io_unplug(void)
|
||||
{
|
||||
Plug *plug = get_ptr_plug();
|
||||
|
||||
assert(plug->count > 0);
|
||||
|
||||
if (--plug->count > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
GArray *array = plug->unplug_fns;
|
||||
if (!array) {
|
||||
return;
|
||||
}
|
||||
|
||||
UnplugFn *fns = (UnplugFn *)array->data;
|
||||
|
||||
for (guint i = 0; i < array->len; i++) {
|
||||
fns[i].fn(fns[i].opaque);
|
||||
}
|
||||
|
||||
/*
|
||||
* This resets the array without freeing memory so that appending is cheap
|
||||
* in the future.
|
||||
*/
|
||||
g_array_set_size(array, 0);
|
||||
}
|
||||
@@ -237,6 +237,7 @@ static void qmp_blockdev_insert_anon_medium(BlockBackend *blk,
|
||||
BlockDriverState *bs, Error **errp)
|
||||
{
|
||||
Error *local_err = NULL;
|
||||
AioContext *ctx;
|
||||
bool has_device;
|
||||
int ret;
|
||||
|
||||
@@ -258,7 +259,11 @@ static void qmp_blockdev_insert_anon_medium(BlockBackend *blk,
|
||||
return;
|
||||
}
|
||||
|
||||
ctx = bdrv_get_aio_context(bs);
|
||||
aio_context_acquire(ctx);
|
||||
ret = blk_insert_bs(blk, bs, errp);
|
||||
aio_context_release(ctx);
|
||||
|
||||
if (ret < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
+26
-2
@@ -2968,6 +2968,7 @@ static void blockdev_mirror_common(const char *job_id, BlockDriverState *bs,
|
||||
|
||||
if (replaces) {
|
||||
BlockDriverState *to_replace_bs;
|
||||
AioContext *aio_context;
|
||||
AioContext *replace_aio_context;
|
||||
int64_t bs_size, replace_size;
|
||||
|
||||
@@ -2982,10 +2983,19 @@ static void blockdev_mirror_common(const char *job_id, BlockDriverState *bs,
|
||||
return;
|
||||
}
|
||||
|
||||
aio_context = bdrv_get_aio_context(bs);
|
||||
replace_aio_context = bdrv_get_aio_context(to_replace_bs);
|
||||
aio_context_acquire(replace_aio_context);
|
||||
/*
|
||||
* bdrv_getlength() is a co-wrapper and uses AIO_WAIT_WHILE. Be sure not
|
||||
* to acquire the same AioContext twice.
|
||||
*/
|
||||
if (replace_aio_context != aio_context) {
|
||||
aio_context_acquire(replace_aio_context);
|
||||
}
|
||||
replace_size = bdrv_getlength(to_replace_bs);
|
||||
aio_context_release(replace_aio_context);
|
||||
if (replace_aio_context != aio_context) {
|
||||
aio_context_release(replace_aio_context);
|
||||
}
|
||||
|
||||
if (replace_size < 0) {
|
||||
error_setg_errno(errp, -replace_size,
|
||||
@@ -3382,6 +3392,20 @@ void qmp_block_job_dismiss(const char *id, Error **errp)
|
||||
job_dismiss_locked(&job, errp);
|
||||
}
|
||||
|
||||
void qmp_block_job_change(BlockJobChangeOptions *opts, Error **errp)
|
||||
{
|
||||
BlockJob *job;
|
||||
|
||||
JOB_LOCK_GUARD();
|
||||
job = find_block_job_locked(opts->id, errp);
|
||||
|
||||
if (!job) {
|
||||
return;
|
||||
}
|
||||
|
||||
block_job_change_locked(job, opts, errp);
|
||||
}
|
||||
|
||||
void qmp_change_backing_file(const char *device,
|
||||
const char *image_node_name,
|
||||
const char *backing_file,
|
||||
|
||||
+29
-1
@@ -198,7 +198,9 @@ void block_job_remove_all_bdrv(BlockJob *job)
|
||||
* one to make sure that such a concurrent access does not attempt
|
||||
* to process an already freed BdrvChild.
|
||||
*/
|
||||
aio_context_release(job->job.aio_context);
|
||||
bdrv_graph_wrlock(NULL);
|
||||
aio_context_acquire(job->job.aio_context);
|
||||
while (job->nodes) {
|
||||
GSList *l = job->nodes;
|
||||
BdrvChild *c = l->data;
|
||||
@@ -328,6 +330,26 @@ static bool block_job_set_speed(BlockJob *job, int64_t speed, Error **errp)
|
||||
return block_job_set_speed_locked(job, speed, errp);
|
||||
}
|
||||
|
||||
void block_job_change_locked(BlockJob *job, BlockJobChangeOptions *opts,
|
||||
Error **errp)
|
||||
{
|
||||
const BlockJobDriver *drv = block_job_driver(job);
|
||||
|
||||
GLOBAL_STATE_CODE();
|
||||
|
||||
if (job_apply_verb_locked(&job->job, JOB_VERB_CHANGE, errp)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (drv->change) {
|
||||
job_unlock();
|
||||
drv->change(job, opts, errp);
|
||||
job_lock();
|
||||
} else {
|
||||
error_setg(errp, "Job type does not support change");
|
||||
}
|
||||
}
|
||||
|
||||
void block_job_ratelimit_processed_bytes(BlockJob *job, uint64_t n)
|
||||
{
|
||||
IO_CODE();
|
||||
@@ -356,6 +378,7 @@ BlockJobInfo *block_job_query_locked(BlockJob *job, Error **errp)
|
||||
{
|
||||
BlockJobInfo *info;
|
||||
uint64_t progress_current, progress_total;
|
||||
const BlockJobDriver *drv = block_job_driver(job);
|
||||
|
||||
GLOBAL_STATE_CODE();
|
||||
|
||||
@@ -368,7 +391,7 @@ BlockJobInfo *block_job_query_locked(BlockJob *job, Error **errp)
|
||||
&progress_total);
|
||||
|
||||
info = g_new0(BlockJobInfo, 1);
|
||||
info->type = g_strdup(job_type_str(&job->job));
|
||||
info->type = job_type(&job->job);
|
||||
info->device = g_strdup(job->job.id);
|
||||
info->busy = job->job.busy;
|
||||
info->paused = job->job.pause_count > 0;
|
||||
@@ -385,6 +408,11 @@ BlockJobInfo *block_job_query_locked(BlockJob *job, Error **errp)
|
||||
g_strdup(error_get_pretty(job->job.err)) :
|
||||
g_strdup(strerror(-job->job.ret));
|
||||
}
|
||||
if (drv->query) {
|
||||
job_unlock();
|
||||
drv->query(job, info);
|
||||
job_lock();
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
@@ -667,7 +667,7 @@ Command description:
|
||||
|
||||
List, apply, create or delete snapshots in image *FILENAME*.
|
||||
|
||||
.. option:: rebase [--object OBJECTDEF] [--image-opts] [-U] [-q] [-f FMT] [-t CACHE] [-T SRC_CACHE] [-p] [-u] -b BACKING_FILE [-F BACKING_FMT] FILENAME
|
||||
.. option:: rebase [--object OBJECTDEF] [--image-opts] [-U] [-q] [-f FMT] [-t CACHE] [-T SRC_CACHE] [-p] [-u] [-c] -b BACKING_FILE [-F BACKING_FMT] FILENAME
|
||||
|
||||
Changes the backing file of an image. Only the formats ``qcow2`` and
|
||||
``qed`` support changing the backing file.
|
||||
@@ -694,7 +694,9 @@ Command description:
|
||||
|
||||
In order to achieve this, any clusters that differ between
|
||||
*BACKING_FILE* and the old backing file of *FILENAME* are merged
|
||||
into *FILENAME* before actually changing the backing file.
|
||||
into *FILENAME* before actually changing the backing file. With the
|
||||
``-c`` option specified, the clusters which are being merged (but not
|
||||
the entire *FILENAME* image) are compressed when written.
|
||||
|
||||
Note that the safe mode is an expensive operation, comparable to
|
||||
converting an image. It only works if the old backing file still
|
||||
|
||||
@@ -31,9 +31,6 @@ struct VirtIOBlockDataPlane {
|
||||
|
||||
VirtIOBlkConf *conf;
|
||||
VirtIODevice *vdev;
|
||||
QEMUBH *bh; /* bh for guest notification */
|
||||
unsigned long *batch_notify_vqs;
|
||||
bool batch_notifications;
|
||||
|
||||
/* Note that these EventNotifiers are assigned by value. This is
|
||||
* fine as long as you do not call event_notifier_cleanup on them
|
||||
@@ -47,36 +44,7 @@ struct VirtIOBlockDataPlane {
|
||||
/* Raise an interrupt to signal guest, if necessary */
|
||||
void virtio_blk_data_plane_notify(VirtIOBlockDataPlane *s, VirtQueue *vq)
|
||||
{
|
||||
if (s->batch_notifications) {
|
||||
set_bit(virtio_get_queue_index(vq), s->batch_notify_vqs);
|
||||
qemu_bh_schedule(s->bh);
|
||||
} else {
|
||||
virtio_notify_irqfd(s->vdev, vq);
|
||||
}
|
||||
}
|
||||
|
||||
static void notify_guest_bh(void *opaque)
|
||||
{
|
||||
VirtIOBlockDataPlane *s = opaque;
|
||||
unsigned nvqs = s->conf->num_queues;
|
||||
unsigned long bitmap[BITS_TO_LONGS(nvqs)];
|
||||
unsigned j;
|
||||
|
||||
memcpy(bitmap, s->batch_notify_vqs, sizeof(bitmap));
|
||||
memset(s->batch_notify_vqs, 0, sizeof(bitmap));
|
||||
|
||||
for (j = 0; j < nvqs; j += BITS_PER_LONG) {
|
||||
unsigned long bits = bitmap[j / BITS_PER_LONG];
|
||||
|
||||
while (bits != 0) {
|
||||
unsigned i = j + ctzl(bits);
|
||||
VirtQueue *vq = virtio_get_queue(s->vdev, i);
|
||||
|
||||
virtio_notify_irqfd(s->vdev, vq);
|
||||
|
||||
bits &= bits - 1; /* clear right-most bit */
|
||||
}
|
||||
}
|
||||
virtio_notify_irqfd(s->vdev, vq);
|
||||
}
|
||||
|
||||
/* Context: QEMU global mutex held */
|
||||
@@ -126,9 +94,6 @@ bool virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *conf,
|
||||
} else {
|
||||
s->ctx = qemu_get_aio_context();
|
||||
}
|
||||
s->bh = aio_bh_new_guarded(s->ctx, notify_guest_bh, s,
|
||||
&DEVICE(vdev)->mem_reentrancy_guard);
|
||||
s->batch_notify_vqs = bitmap_new(conf->num_queues);
|
||||
|
||||
*dataplane = s;
|
||||
|
||||
@@ -146,8 +111,6 @@ void virtio_blk_data_plane_destroy(VirtIOBlockDataPlane *s)
|
||||
|
||||
vblk = VIRTIO_BLK(s->vdev);
|
||||
assert(!vblk->dataplane_started);
|
||||
g_free(s->batch_notify_vqs);
|
||||
qemu_bh_delete(s->bh);
|
||||
if (s->iothread) {
|
||||
object_unref(OBJECT(s->iothread));
|
||||
}
|
||||
@@ -173,12 +136,6 @@ int virtio_blk_data_plane_start(VirtIODevice *vdev)
|
||||
|
||||
s->starting = true;
|
||||
|
||||
if (!virtio_vdev_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX)) {
|
||||
s->batch_notifications = true;
|
||||
} else {
|
||||
s->batch_notifications = false;
|
||||
}
|
||||
|
||||
/* Set up guest notifier (irq) */
|
||||
r = k->set_guest_notifiers(qbus->parent, nvqs, true);
|
||||
if (r != 0) {
|
||||
@@ -370,9 +327,6 @@ void virtio_blk_data_plane_stop(VirtIODevice *vdev)
|
||||
|
||||
aio_context_release(s->ctx);
|
||||
|
||||
qemu_bh_cancel(s->bh);
|
||||
notify_guest_bh(s); /* final chance to notify guest */
|
||||
|
||||
/* Clean up guest notifier (irq) */
|
||||
k->set_guest_notifiers(qbus->parent, nvqs, false);
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "qemu/defer-call.h"
|
||||
#include "qemu/error-report.h"
|
||||
#include "qemu/main-loop.h"
|
||||
#include "qemu/memalign.h"
|
||||
@@ -509,7 +510,7 @@ static int xen_block_get_request(XenBlockDataPlane *dataplane,
|
||||
|
||||
/*
|
||||
* Threshold of in-flight requests above which we will start using
|
||||
* blk_io_plug()/blk_io_unplug() to batch requests.
|
||||
* defer_call_begin()/defer_call_end() to batch requests.
|
||||
*/
|
||||
#define IO_PLUG_THRESHOLD 1
|
||||
|
||||
@@ -537,7 +538,7 @@ static bool xen_block_handle_requests(XenBlockDataPlane *dataplane)
|
||||
* is below us.
|
||||
*/
|
||||
if (inflight_atstart > IO_PLUG_THRESHOLD) {
|
||||
blk_io_plug();
|
||||
defer_call_begin();
|
||||
}
|
||||
while (rc != rp) {
|
||||
/* pull request from ring */
|
||||
@@ -577,12 +578,12 @@ static bool xen_block_handle_requests(XenBlockDataPlane *dataplane)
|
||||
|
||||
if (inflight_atstart > IO_PLUG_THRESHOLD &&
|
||||
batched >= inflight_atstart) {
|
||||
blk_io_unplug();
|
||||
defer_call_end();
|
||||
}
|
||||
xen_block_do_aio(request);
|
||||
if (inflight_atstart > IO_PLUG_THRESHOLD) {
|
||||
if (batched >= inflight_atstart) {
|
||||
blk_io_plug();
|
||||
defer_call_begin();
|
||||
batched = 0;
|
||||
} else {
|
||||
batched++;
|
||||
@@ -590,7 +591,7 @@ static bool xen_block_handle_requests(XenBlockDataPlane *dataplane)
|
||||
}
|
||||
}
|
||||
if (inflight_atstart > IO_PLUG_THRESHOLD) {
|
||||
blk_io_unplug();
|
||||
defer_call_end();
|
||||
}
|
||||
|
||||
return done_something;
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "qemu/defer-call.h"
|
||||
#include "qapi/error.h"
|
||||
#include "qemu/iov.h"
|
||||
#include "qemu/module.h"
|
||||
@@ -1134,7 +1135,7 @@ void virtio_blk_handle_vq(VirtIOBlock *s, VirtQueue *vq)
|
||||
bool suppress_notifications = virtio_queue_get_notification(vq);
|
||||
|
||||
aio_context_acquire(blk_get_aio_context(s->blk));
|
||||
blk_io_plug();
|
||||
defer_call_begin();
|
||||
|
||||
do {
|
||||
if (suppress_notifications) {
|
||||
@@ -1158,7 +1159,7 @@ void virtio_blk_handle_vq(VirtIOBlock *s, VirtQueue *vq)
|
||||
virtio_blk_submit_multireq(s, &mrb);
|
||||
}
|
||||
|
||||
blk_io_unplug();
|
||||
defer_call_end();
|
||||
aio_context_release(blk_get_aio_context(s->blk));
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "standard-headers/linux/virtio_ids.h"
|
||||
#include "hw/virtio/virtio-scsi.h"
|
||||
#include "migration/qemu-file-types.h"
|
||||
#include "qemu/defer-call.h"
|
||||
#include "qemu/error-report.h"
|
||||
#include "qemu/iov.h"
|
||||
#include "qemu/module.h"
|
||||
@@ -799,7 +800,7 @@ static int virtio_scsi_handle_cmd_req_prepare(VirtIOSCSI *s, VirtIOSCSIReq *req)
|
||||
return -ENOBUFS;
|
||||
}
|
||||
scsi_req_ref(req->sreq);
|
||||
blk_io_plug();
|
||||
defer_call_begin();
|
||||
object_unref(OBJECT(d));
|
||||
return 0;
|
||||
}
|
||||
@@ -810,7 +811,7 @@ static void virtio_scsi_handle_cmd_req_submit(VirtIOSCSI *s, VirtIOSCSIReq *req)
|
||||
if (scsi_req_enqueue(sreq)) {
|
||||
scsi_req_continue(sreq);
|
||||
}
|
||||
blk_io_unplug();
|
||||
defer_call_end();
|
||||
scsi_req_unref(sreq);
|
||||
}
|
||||
|
||||
@@ -836,7 +837,7 @@ static void virtio_scsi_handle_cmd_vq(VirtIOSCSI *s, VirtQueue *vq)
|
||||
while (!QTAILQ_EMPTY(&reqs)) {
|
||||
req = QTAILQ_FIRST(&reqs);
|
||||
QTAILQ_REMOVE(&reqs, req, next);
|
||||
blk_io_unplug();
|
||||
defer_call_end();
|
||||
scsi_req_unref(req->sreq);
|
||||
virtqueue_detach_element(req->vq, &req->elem, 0);
|
||||
virtio_scsi_free_req(req);
|
||||
|
||||
@@ -73,6 +73,7 @@ virtqueue_fill(void *vq, const void *elem, unsigned int len, unsigned int idx) "
|
||||
virtqueue_flush(void *vq, unsigned int count) "vq %p count %u"
|
||||
virtqueue_pop(void *vq, void *elem, unsigned int in_num, unsigned int out_num) "vq %p elem %p in_num %u out_num %u"
|
||||
virtio_queue_notify(void *vdev, int n, void *vq) "vdev %p n %d vq %p"
|
||||
virtio_notify_irqfd_deferred_fn(void *vdev, void *vq) "vdev %p vq %p"
|
||||
virtio_notify_irqfd(void *vdev, void *vq) "vdev %p vq %p"
|
||||
virtio_notify(void *vdev, void *vq) "vdev %p vq %p"
|
||||
virtio_set_status(void *vdev, uint8_t val) "vdev %p val %u"
|
||||
|
||||
+12
-1
@@ -15,6 +15,7 @@
|
||||
#include "qapi/error.h"
|
||||
#include "qapi/qapi-commands-virtio.h"
|
||||
#include "trace.h"
|
||||
#include "qemu/defer-call.h"
|
||||
#include "qemu/error-report.h"
|
||||
#include "qemu/log.h"
|
||||
#include "qemu/main-loop.h"
|
||||
@@ -2445,6 +2446,16 @@ static bool virtio_should_notify(VirtIODevice *vdev, VirtQueue *vq)
|
||||
}
|
||||
}
|
||||
|
||||
/* Batch irqs while inside a defer_call_begin()/defer_call_end() section */
|
||||
static void virtio_notify_irqfd_deferred_fn(void *opaque)
|
||||
{
|
||||
EventNotifier *notifier = opaque;
|
||||
VirtQueue *vq = container_of(notifier, VirtQueue, guest_notifier);
|
||||
|
||||
trace_virtio_notify_irqfd_deferred_fn(vq->vdev, vq);
|
||||
event_notifier_set(notifier);
|
||||
}
|
||||
|
||||
void virtio_notify_irqfd(VirtIODevice *vdev, VirtQueue *vq)
|
||||
{
|
||||
WITH_RCU_READ_LOCK_GUARD() {
|
||||
@@ -2471,7 +2482,7 @@ void virtio_notify_irqfd(VirtIODevice *vdev, VirtQueue *vq)
|
||||
* to an atomic operation.
|
||||
*/
|
||||
virtio_set_isr(vq->vdev, 0x1);
|
||||
event_notifier_set(&vq->guest_notifier);
|
||||
defer_call(virtio_notify_irqfd_deferred_fn, &vq->guest_notifier);
|
||||
}
|
||||
|
||||
static void virtio_irq(VirtQueue *vq)
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user