Merge tag 'pull-nbd-2026-11-02' of https://gitlab.com/ebblake/qemu into staging
block patches through 2026-11-02 - Denis V. Lunev: honor block size change on scsi child - Denis V. Lunev: cheaper zero handling in backup/commit # -----BEGIN PGP SIGNATURE----- # # iQEzBAABCAAdFiEEccLMIrHEYCkn0vOqp6FrSiUnQ2oFAmrpWqkACgkQp6FrSiUn # Q2oTaQf/TnHfweEw7qvJyKPBqaq5jhTq4k3kRs+t9ODhudSO6hxI44LOuEJLKj6V # 7nGekkxmhptgp9ESRxaGKPRSFdYRYCwu6zgSwBDAMdQCCxW4sUOrjKAp4ruWxdQU # XZbHeeN0lX95nXxfCC3Si5LqkHyzmzIRjLJkF4OTTVnCThtBhgYhwujjDlG5CfRO # 2yD9ZKsS/ZLi1CfBDeZm5j0yggG8NUEtV48zZYAXRtpSkjMb4iN0tr13T/Ov+8n+ # fjg75VkqdJHgli/7UKM8zXWGqGH5NFuj1Gf5vXRMH6CwDt/tvZs5zJ5wfqWRXZ6V # opm1rZKMh5Vx3LvhHGuhVis5sf4IDA== # =ZkE1 # -----END PGP SIGNATURE----- # gpg: Signature made Mon 02 Nov 2026 07:53:13 PM PST # gpg: using RSA key 71C2CC22B1C4602927D2F3AAA7A16B4A2527436A # gpg: Good signature from "Eric Blake <eblake@redhat.com>" [unknown] # gpg: aka "Eric Blake (Free Software Programmer) <ebb9@byu.net>" [unknown] # gpg: aka "[jpeg image of size 6874]" [unknown] # gpg: WARNING: This key is not certified with a trusted signature! # gpg: There is no indication that the signature belongs to the owner. # Primary key fingerprint: 71C2 CC22 B1C4 6029 27D2 F3AA A7A1 6B4A 2527 436A * tag 'pull-nbd-2026-11-02' of https://gitlab.com/ebblake/qemu: block/block-copy: coalesce write-zeroes tasks util/co-shared-resource: skip the mutex for an empty request block/block-copy: replace zero_bitmap_valid with scan_done block/block-copy: merge the two backup scan steps into block_copy_prescan() block/block-copy: rename block_copy_is_cluster_allocated() block/backup: pre-fill zero_bitmap for full/bitmap block/block-copy: track known-zero source clusters block/block-copy: extract block_copy_set_task_method() iotests/124: cover backup of zero clusters and holes block/commit: batch block-status queries iotests/040: cover large and fragmented commit runs block/commit: pass BDRV_WANT_PRECISE to block-status tests/qemu-iotests/qom-set-drive: replace with a differently sized node tests/qtest/virtio-scsi: cover a replacement that changes the size scsi-disk: refresh the cached capacity from the resize callback block: notify the parent when a replaced child has a different size Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
commit
99e6fa0053
16 files changed
+935
-125
No files matched your search
@@ -5562,9 +5562,12 @@ int bdrv_replace_child_bs(BdrvChild *child, BlockDriverState *new_bs,
|
||||
Transaction *tran = tran_new();
|
||||
g_autoptr(GSList) refresh_list = NULL;
|
||||
BlockDriverState *old_bs = child->bs;
|
||||
int64_t old_len;
|
||||
|
||||
GLOBAL_STATE_CODE();
|
||||
|
||||
old_len = bdrv_getlength(old_bs);
|
||||
|
||||
bdrv_ref(old_bs);
|
||||
bdrv_drained_begin(old_bs);
|
||||
bdrv_drained_begin(new_bs);
|
||||
@@ -5580,6 +5583,16 @@ int bdrv_replace_child_bs(BdrvChild *child, BlockDriverState *new_bs,
|
||||
tran_finalize(tran, ret);
|
||||
|
||||
bdrv_graph_wrunlock();
|
||||
|
||||
/* A parent caching the child size has to learn that it changed */
|
||||
if (ret == 0) {
|
||||
int64_t new_len = bdrv_getlength(new_bs);
|
||||
|
||||
if (new_len >= 0 && new_len != old_len) {
|
||||
bdrv_parent_cb_resize(new_bs);
|
||||
}
|
||||
}
|
||||
|
||||
bdrv_drained_end(old_bs);
|
||||
bdrv_drained_end(new_bs);
|
||||
bdrv_unref(old_bs);
|
||||
|
||||
+53
-35
@@ -247,6 +247,42 @@ static void backup_init_bcs_bitmap(BackupBlockJob *job)
|
||||
job_progress_set_remaining(&job->common.job, estimate);
|
||||
}
|
||||
|
||||
/*
|
||||
* Walk the source before copying starts: fill zero_bitmap and, for sync=top,
|
||||
* drop the clusters that are not allocated above the backing.
|
||||
*/
|
||||
static int coroutine_fn backup_scan_source(BackupBlockJob *s)
|
||||
{
|
||||
Job *job = &s->common.job;
|
||||
int64_t offset, cached_end = 0, count;
|
||||
int ret = 0;
|
||||
|
||||
for (offset = 0; offset < s->len; offset += count) {
|
||||
if (job_is_cancelled(job)) {
|
||||
return -ECANCELED;
|
||||
}
|
||||
|
||||
job_pause_point(job);
|
||||
|
||||
if (job_is_cancelled(job)) {
|
||||
return -ECANCELED;
|
||||
}
|
||||
|
||||
/* rdlock protects the block-status queries below */
|
||||
bdrv_graph_co_rdlock();
|
||||
ret = block_copy_prescan(s->bcs, offset, &cached_end, &count);
|
||||
bdrv_graph_co_rdunlock();
|
||||
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
block_copy_set_scan_done(s->bcs);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int coroutine_fn backup_run(Job *job, Error **errp)
|
||||
{
|
||||
BackupBlockJob *s = container_of(job, BackupBlockJob, common.job);
|
||||
@@ -254,51 +290,33 @@ static int coroutine_fn backup_run(Job *job, Error **errp)
|
||||
|
||||
backup_init_bcs_bitmap(s);
|
||||
|
||||
if (s->sync_mode == MIRROR_SYNC_MODE_TOP) {
|
||||
int64_t offset = 0;
|
||||
int64_t count;
|
||||
|
||||
for (offset = 0; offset < s->len; ) {
|
||||
if (job_is_cancelled(job)) {
|
||||
return -ECANCELED;
|
||||
}
|
||||
|
||||
job_pause_point(job);
|
||||
|
||||
if (job_is_cancelled(job)) {
|
||||
return -ECANCELED;
|
||||
}
|
||||
|
||||
/* rdlock protects the subsequent call to bdrv_is_allocated() */
|
||||
bdrv_graph_co_rdlock();
|
||||
ret = block_copy_reset_unallocated(s->bcs, offset, &count);
|
||||
bdrv_graph_co_rdunlock();
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
offset += count;
|
||||
switch (s->sync_mode) {
|
||||
case MIRROR_SYNC_MODE_TOP:
|
||||
case MIRROR_SYNC_MODE_FULL:
|
||||
case MIRROR_SYNC_MODE_BITMAP:
|
||||
ret = backup_scan_source(s);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
block_copy_set_skip_unallocated(s->bcs, false);
|
||||
}
|
||||
break;
|
||||
|
||||
if (s->sync_mode == MIRROR_SYNC_MODE_NONE) {
|
||||
case MIRROR_SYNC_MODE_NONE:
|
||||
/*
|
||||
* All bits are set in bcs bitmap to allow any cluster to be copied.
|
||||
* This does not actually require them to be copied.
|
||||
* This does not actually require them to be copied. Yield until the
|
||||
* job is cancelled and let the before_write notify callback service
|
||||
* CoW requests.
|
||||
*/
|
||||
while (!job_is_cancelled(job)) {
|
||||
/*
|
||||
* Yield until the job is cancelled. We just let our before_write
|
||||
* notify callback service CoW requests.
|
||||
*/
|
||||
job_yield(job);
|
||||
}
|
||||
} else {
|
||||
return backup_loop(s);
|
||||
return 0;
|
||||
|
||||
default:
|
||||
g_assert_not_reached();
|
||||
}
|
||||
|
||||
return 0;
|
||||
return backup_loop(s);
|
||||
}
|
||||
|
||||
static void coroutine_fn backup_pause(Job *job)
|
||||
|
||||
+264
-62
@@ -20,6 +20,8 @@
|
||||
#include "block/block_int-io.h"
|
||||
#include "block/dirty-bitmap.h"
|
||||
#include "block/reqlist.h"
|
||||
#include "qemu/hbitmap.h"
|
||||
#include "qemu/host-utils.h"
|
||||
#include "system/block-backend.h"
|
||||
#include "qemu/units.h"
|
||||
#include "qemu/co-shared-resource.h"
|
||||
@@ -90,19 +92,21 @@ typedef struct BlockCopyTask {
|
||||
BlockCopyState *s;
|
||||
BlockCopyCallState *call_state;
|
||||
/*
|
||||
* @method can also be set again in the while loop of
|
||||
* block_copy_dirty_clusters(), but it is never accessed concurrently
|
||||
* because the only other function that reads it is
|
||||
* @method and @zero_fast can also be set again in the while loop of
|
||||
* block_copy_dirty_clusters(), but they are never accessed concurrently
|
||||
* because the only other function that reads them is
|
||||
* block_copy_task_entry() and it is invoked afterwards in the same
|
||||
* iteration.
|
||||
*/
|
||||
BlockCopyMethod method;
|
||||
/* A write-zeroes task asking for BDRV_REQ_NO_FALLBACK. */
|
||||
bool zero_fast;
|
||||
|
||||
/*
|
||||
* Generally, req is protected by lock in BlockCopyState, Still req.offset
|
||||
* is only set on task creation, so may be read concurrently after creation.
|
||||
* req.bytes is changed at most once, and need only protecting the case of
|
||||
* parallel read while updating @bytes value in block_copy_task_shrink().
|
||||
* req.bytes only shrinks, and need only protecting the case of parallel
|
||||
* read while updating @bytes value in block_copy_task_shrink().
|
||||
*/
|
||||
BlockReq req;
|
||||
} BlockCopyTask;
|
||||
@@ -151,12 +155,22 @@ typedef struct BlockCopyState {
|
||||
* This is indicated by skip_unallocated.
|
||||
*
|
||||
* In this case, block_copy() will query the source’s allocation status,
|
||||
* skip unallocated regions, clear them in the copy_bitmap, and invoke
|
||||
* block_copy_reset_unallocated() every time it does.
|
||||
* skip unallocated regions and clear them in the copy_bitmap, as
|
||||
* block_copy_prescan() does.
|
||||
*/
|
||||
bool skip_unallocated; /* atomic */
|
||||
/* State fields that use a thread-safe API */
|
||||
BdrvDirtyBitmap *copy_bitmap;
|
||||
/* Cleared once the target refuses BDRV_REQ_NO_FALLBACK. */
|
||||
bool zero_widen; /* atomic */
|
||||
/* Clusters reading as zero; allocated on demand, frozen once valid. */
|
||||
HBitmap *zero_bitmap;
|
||||
/*
|
||||
* Set when the scan is over: zero_bitmap is complete, and for sync=top
|
||||
* copy_bitmap holds no unallocated clusters, so a task needs no
|
||||
* block-status query of its own.
|
||||
*/
|
||||
bool scan_done; /* atomic, store-release/load-acquire */
|
||||
ProgressMeter *progress;
|
||||
SharedResource *mem;
|
||||
RateLimit rate_limit;
|
||||
@@ -181,6 +195,23 @@ static int64_t block_copy_chunk_size(BlockCopyState *s)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* A write-zeroes task carries no buffer, so it may cover far more than
|
||||
* block_copy_chunk_size(). Return how far it may run; the caller clamps it
|
||||
* to where the zero run ends.
|
||||
*/
|
||||
static int64_t block_copy_widen_zero_area(BlockCopyState *s, int64_t offset,
|
||||
int64_t bytes)
|
||||
{
|
||||
int64_t clean;
|
||||
|
||||
bytes = MIN(bytes, QEMU_ALIGN_DOWN(BDRV_REQUEST_MAX_BYTES,
|
||||
s->cluster_size));
|
||||
clean = bdrv_dirty_bitmap_next_zero(s->copy_bitmap, offset, bytes);
|
||||
|
||||
return clean < 0 ? bytes : clean - offset;
|
||||
}
|
||||
|
||||
/*
|
||||
* Search for the first dirty area in offset/bytes range and create task at
|
||||
* the beginning of it.
|
||||
@@ -190,7 +221,10 @@ block_copy_task_create(BlockCopyState *s, BlockCopyCallState *call_state,
|
||||
int64_t offset, int64_t bytes)
|
||||
{
|
||||
BlockCopyTask *task;
|
||||
BlockCopyMethod method;
|
||||
bool zero_fast = false;
|
||||
int64_t max_chunk;
|
||||
int64_t search_end = offset + bytes;
|
||||
|
||||
QEMU_LOCK_GUARD(&s->lock);
|
||||
max_chunk = MIN_NON_ZERO(block_copy_chunk_size(s), call_state->max_chunk);
|
||||
@@ -201,6 +235,32 @@ block_copy_task_create(BlockCopyState *s, BlockCopyCallState *call_state,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
method = s->method;
|
||||
|
||||
/*
|
||||
* The scan already knows how this range reads: pick the method here and
|
||||
* stop the task where the answer changes.
|
||||
*/
|
||||
if (qatomic_load_acquire(&s->scan_done)) {
|
||||
int64_t boundary;
|
||||
|
||||
if (hbitmap_get(s->zero_bitmap, offset)) {
|
||||
method = COPY_WRITE_ZEROES;
|
||||
zero_fast = qatomic_read(&s->zero_widen);
|
||||
if (zero_fast) {
|
||||
bytes = block_copy_widen_zero_area(s, offset,
|
||||
search_end - offset);
|
||||
}
|
||||
boundary = hbitmap_next_zero(s->zero_bitmap, offset, bytes);
|
||||
} else {
|
||||
boundary = hbitmap_next_dirty(s->zero_bitmap, offset, bytes);
|
||||
}
|
||||
|
||||
if (boundary >= 0) {
|
||||
bytes = boundary - offset;
|
||||
}
|
||||
}
|
||||
|
||||
assert(QEMU_IS_ALIGNED(offset, s->cluster_size));
|
||||
bytes = QEMU_ALIGN_UP(bytes, s->cluster_size);
|
||||
|
||||
@@ -215,7 +275,8 @@ block_copy_task_create(BlockCopyState *s, BlockCopyCallState *call_state,
|
||||
.task.func = block_copy_task_entry,
|
||||
.s = s,
|
||||
.call_state = call_state,
|
||||
.method = s->method,
|
||||
.method = method,
|
||||
.zero_fast = zero_fast,
|
||||
};
|
||||
reqlist_init_req(&s->reqs, &task->req, offset, bytes);
|
||||
|
||||
@@ -271,6 +332,9 @@ void block_copy_state_free(BlockCopyState *s)
|
||||
|
||||
ratelimit_destroy(&s->rate_limit);
|
||||
bdrv_release_dirty_bitmap(s->copy_bitmap);
|
||||
if (s->zero_bitmap) {
|
||||
hbitmap_free(s->zero_bitmap);
|
||||
}
|
||||
shres_destroy(s->mem);
|
||||
g_free(s);
|
||||
}
|
||||
@@ -434,6 +498,7 @@ BlockCopyState *block_copy_state_new(BdrvChild *source, BdrvChild *target,
|
||||
.max_transfer = QEMU_ALIGN_DOWN(
|
||||
block_copy_max_transfer(source, target),
|
||||
cluster_size),
|
||||
.zero_widen = target->bs->supported_zero_flags & BDRV_REQ_NO_FALLBACK,
|
||||
};
|
||||
|
||||
s->discard_source = discard_source;
|
||||
@@ -453,6 +518,15 @@ void block_copy_set_progress_meter(BlockCopyState *s, ProgressMeter *pm)
|
||||
s->progress = pm;
|
||||
}
|
||||
|
||||
/*
|
||||
* Bytes @task moves as data, for the memory pool and the rate limit. Only a
|
||||
* write-zeroes request that may not fall back is sure to need no buffer.
|
||||
*/
|
||||
static uint64_t block_copy_task_data_bytes(BlockCopyTask *task)
|
||||
{
|
||||
return task->zero_fast ? 0 : task->req.bytes;
|
||||
}
|
||||
|
||||
/*
|
||||
* Takes ownership of @task
|
||||
*
|
||||
@@ -474,7 +548,7 @@ static coroutine_fn int block_copy_task_run(AioTaskPool *pool,
|
||||
|
||||
aio_task_pool_wait_slot(pool);
|
||||
if (aio_task_pool_status(pool) < 0) {
|
||||
co_put_to_shres(task->s->mem, task->req.bytes);
|
||||
co_put_to_shres(task->s->mem, block_copy_task_data_bytes(task));
|
||||
block_copy_task_end(task, -ECANCELED);
|
||||
g_free(task);
|
||||
return -ECANCELED;
|
||||
@@ -485,6 +559,34 @@ static coroutine_fn int block_copy_task_run(AioTaskPool *pool,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Widening a write-zeroes request only pays off where the target zeroes by
|
||||
* metadata, so while the target is believed to oblige, a request asks to fail
|
||||
* instead of falling back to writing the zeroes out. A refusal ends the
|
||||
* widening and shrinks @t to one cluster for the caller to write the usual
|
||||
* way; the rest is dirty again and is picked up at the buffer chunk size.
|
||||
*/
|
||||
static int coroutine_fn GRAPH_RDLOCK
|
||||
block_copy_write_zeroes_fast(BlockCopyTask *t, bool *error_is_read)
|
||||
{
|
||||
BlockCopyState *s = t->s;
|
||||
int64_t nbytes = MIN(t->req.offset + t->req.bytes, s->len) - t->req.offset;
|
||||
int ret;
|
||||
|
||||
ret = bdrv_co_pwrite_zeroes(s->target, t->req.offset, nbytes,
|
||||
(s->write_flags & ~BDRV_REQ_WRITE_COMPRESSED) |
|
||||
BDRV_REQ_NO_FALLBACK);
|
||||
if (ret == -ENOTSUP) {
|
||||
qatomic_set(&s->zero_widen, false);
|
||||
block_copy_task_shrink(t, s->cluster_size);
|
||||
} else if (ret < 0) {
|
||||
trace_block_copy_write_zeroes_fail(s, t->req.offset, ret);
|
||||
*error_is_read = false;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* block_copy_do_copy
|
||||
*
|
||||
@@ -587,8 +689,13 @@ static coroutine_fn int block_copy_task_entry(AioTask *task)
|
||||
int ret = -1;
|
||||
|
||||
WITH_GRAPH_RDLOCK_GUARD() {
|
||||
ret = block_copy_do_copy(s, t->req.offset, t->req.bytes, &method,
|
||||
&error_is_read);
|
||||
if (t->zero_fast) {
|
||||
ret = block_copy_write_zeroes_fast(t, &error_is_read);
|
||||
}
|
||||
if (!t->zero_fast || ret == -ENOTSUP) {
|
||||
ret = block_copy_do_copy(s, t->req.offset, t->req.bytes, &method,
|
||||
&error_is_read);
|
||||
}
|
||||
}
|
||||
|
||||
WITH_QEMU_LOCK_GUARD(&s->lock) {
|
||||
@@ -605,7 +712,7 @@ static coroutine_fn int block_copy_task_entry(AioTask *task)
|
||||
progress_work_done(s->progress, t->req.bytes);
|
||||
}
|
||||
}
|
||||
co_put_to_shres(s->mem, t->req.bytes);
|
||||
co_put_to_shres(s->mem, block_copy_task_data_bytes(t));
|
||||
block_copy_task_end(t, ret);
|
||||
|
||||
if (s->discard_source && ret == 0) {
|
||||
@@ -619,20 +726,24 @@ static coroutine_fn int block_copy_task_entry(AioTask *task)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* The scan and the per-task query must resolve BDRV_BLOCK_ZERO alike. */
|
||||
static GRAPH_RDLOCK BlockDriverState *block_copy_status_base(BlockCopyState *s)
|
||||
{
|
||||
if (qatomic_read(&s->skip_unallocated)) {
|
||||
return bdrv_backing_chain_next(s->source->bs);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static coroutine_fn GRAPH_RDLOCK
|
||||
int block_copy_block_status(BlockCopyState *s, int64_t offset, int64_t bytes,
|
||||
int64_t *pnum)
|
||||
{
|
||||
int64_t num;
|
||||
BlockDriverState *base;
|
||||
BlockDriverState *base = block_copy_status_base(s);
|
||||
int ret;
|
||||
|
||||
if (qatomic_read(&s->skip_unallocated)) {
|
||||
base = bdrv_backing_chain_next(s->source->bs);
|
||||
} else {
|
||||
base = NULL;
|
||||
}
|
||||
|
||||
ret = bdrv_co_block_status_above(s->source->bs, base, offset, bytes, &num,
|
||||
NULL, NULL);
|
||||
if (ret < 0 || num < s->cluster_size) {
|
||||
@@ -652,16 +763,41 @@ int block_copy_block_status(BlockCopyState *s, int64_t offset, int64_t bytes,
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Only the scan allocates, and it runs before scan_done. */
|
||||
static HBitmap *block_copy_zero_bitmap(BlockCopyState *s)
|
||||
{
|
||||
if (!s->zero_bitmap) {
|
||||
s->zero_bitmap = hbitmap_alloc(s->len, ctz32(s->cluster_size));
|
||||
}
|
||||
|
||||
return s->zero_bitmap;
|
||||
}
|
||||
|
||||
static void block_copy_mark_zero_prefix(BlockCopyState *s, int64_t offset,
|
||||
int64_t zero_count)
|
||||
{
|
||||
int64_t zero_bytes = QEMU_ALIGN_DOWN(zero_count, s->cluster_size);
|
||||
|
||||
if (zero_bytes > 0) {
|
||||
hbitmap_set(block_copy_zero_bitmap(s), offset, zero_bytes);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if the cluster starting at offset is allocated or not.
|
||||
* return via pnum the number of contiguous clusters sharing this allocation.
|
||||
* One block-status query of the scan at @offset: return 1 if the cluster
|
||||
* there is allocated, 0 if not, -errno on failure, and via @pnum the number
|
||||
* of contiguous clusters sharing that allocation. Their zero prefix goes
|
||||
* into zero_bitmap.
|
||||
*/
|
||||
static int coroutine_fn GRAPH_RDLOCK
|
||||
block_copy_is_cluster_allocated(BlockCopyState *s, int64_t offset,
|
||||
int64_t *pnum)
|
||||
block_copy_scan_status(BlockCopyState *s, int64_t offset, int64_t *pnum)
|
||||
{
|
||||
BlockDriverState *bs = s->source->bs;
|
||||
BlockDriverState *base = block_copy_status_base(s);
|
||||
int64_t orig_offset = offset;
|
||||
int64_t count, total_count = 0;
|
||||
int64_t zero_count = 0;
|
||||
bool zero_broken = false;
|
||||
int64_t bytes = s->len - offset;
|
||||
int ret;
|
||||
|
||||
@@ -669,25 +805,37 @@ block_copy_is_cluster_allocated(BlockCopyState *s, int64_t offset,
|
||||
|
||||
while (true) {
|
||||
/* protected in backup_run() */
|
||||
ret = bdrv_co_is_allocated(bs, offset, bytes, &count);
|
||||
ret = bdrv_co_block_status_above(bs, base, offset, bytes, &count,
|
||||
NULL, NULL);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (!zero_broken) {
|
||||
if (ret & BDRV_BLOCK_ZERO) {
|
||||
zero_count += count;
|
||||
} else {
|
||||
zero_broken = true;
|
||||
}
|
||||
}
|
||||
|
||||
total_count += count;
|
||||
|
||||
if (ret || count == 0) {
|
||||
if ((ret & BDRV_BLOCK_ALLOCATED) || count == 0) {
|
||||
/*
|
||||
* ret: partial segment(s) are considered allocated.
|
||||
* BDRV_BLOCK_ALLOCATED: partial segment(s) are considered
|
||||
* allocated.
|
||||
* otherwise: unallocated tail is treated as an entire segment.
|
||||
*/
|
||||
*pnum = DIV_ROUND_UP(total_count, s->cluster_size);
|
||||
return ret;
|
||||
block_copy_mark_zero_prefix(s, orig_offset, zero_count);
|
||||
return !!(ret & BDRV_BLOCK_ALLOCATED);
|
||||
}
|
||||
|
||||
/* Unallocated segment(s) with uncertain following segment(s) */
|
||||
if (total_count >= s->cluster_size) {
|
||||
*pnum = total_count / s->cluster_size;
|
||||
block_copy_mark_zero_prefix(s, orig_offset, zero_count);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -709,31 +857,92 @@ void block_copy_reset(BlockCopyState *s, int64_t offset, int64_t bytes)
|
||||
}
|
||||
|
||||
/*
|
||||
* Reset bits in copy_bitmap starting at offset if they represent unallocated
|
||||
* data in the image. May reset subsequent contiguous bits.
|
||||
* @return 0 when the cluster at @offset was unallocated,
|
||||
* 1 otherwise, and -ret on error.
|
||||
* One step of the scan run before copying: query the next dirty area, fill
|
||||
* zero_bitmap and, while skip_unallocated is set, drop the clusters which
|
||||
* are not allocated above the backing from copy_bitmap. @cached_end tracks
|
||||
* progress across calls, @count how far @offset should move.
|
||||
*
|
||||
* A failed query only leaves the area unmarked, so it copies as data, but
|
||||
* sync=top cannot tell what to skip and fails instead.
|
||||
*/
|
||||
int64_t coroutine_fn block_copy_reset_unallocated(BlockCopyState *s,
|
||||
int64_t offset,
|
||||
int64_t *count)
|
||||
int coroutine_fn GRAPH_RDLOCK
|
||||
block_copy_prescan(BlockCopyState *s, int64_t offset, int64_t *cached_end,
|
||||
int64_t *count)
|
||||
{
|
||||
int64_t max_bytes = QEMU_ALIGN_DOWN(BDRV_REQUEST_MAX_BYTES,
|
||||
s->cluster_size);
|
||||
int64_t dirty_offset, dirty_bytes, dirty_end;
|
||||
bool found;
|
||||
|
||||
/* CBW mutates copy_bitmap from its own AioContext meanwhile. */
|
||||
WITH_QEMU_LOCK_GUARD(&s->lock) {
|
||||
found = bdrv_dirty_bitmap_next_dirty_area(s->copy_bitmap, offset,
|
||||
s->len, max_bytes,
|
||||
&dirty_offset, &dirty_bytes);
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
*count = s->len - offset;
|
||||
return 0;
|
||||
}
|
||||
dirty_end = dirty_offset + dirty_bytes;
|
||||
|
||||
if (*cached_end < dirty_end) {
|
||||
int64_t clusters;
|
||||
int64_t query_offset = MAX(dirty_offset, *cached_end);
|
||||
int ret = block_copy_scan_status(s, query_offset, &clusters);
|
||||
|
||||
if (ret < 0) {
|
||||
if (qatomic_read(&s->skip_unallocated)) {
|
||||
return ret;
|
||||
}
|
||||
*cached_end = dirty_end;
|
||||
} else {
|
||||
*cached_end = query_offset + clusters * s->cluster_size;
|
||||
if (!ret && qatomic_read(&s->skip_unallocated)) {
|
||||
block_copy_reset(s, query_offset, clusters * s->cluster_size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*count = MIN(*cached_end, dirty_end) - offset;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Decide how @task is copied: COPY_WRITE_ZEROES if it reads as zero. May
|
||||
* shrink @task. Returns false if @task is to be skipped (already ended,
|
||||
* not freed).
|
||||
*/
|
||||
static bool coroutine_fn GRAPH_RDLOCK
|
||||
block_copy_set_task_method(BlockCopyState *s, BlockCopyTask *task)
|
||||
{
|
||||
int ret;
|
||||
int64_t clusters, bytes;
|
||||
int64_t status_bytes;
|
||||
|
||||
ret = block_copy_is_cluster_allocated(s, offset, &clusters);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
/* block_copy_task_create() already decided, from zero_bitmap. */
|
||||
if (qatomic_load_acquire(&s->scan_done)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bytes = clusters * s->cluster_size;
|
||||
|
||||
if (!ret) {
|
||||
block_copy_reset(s, offset, bytes);
|
||||
/* CBW filter could call this early. */
|
||||
ret = block_copy_block_status(s, task->req.offset, task->req.bytes,
|
||||
&status_bytes);
|
||||
assert(ret >= 0); /* never fail */
|
||||
if (status_bytes < task->req.bytes) {
|
||||
block_copy_task_shrink(task, status_bytes);
|
||||
}
|
||||
if (qatomic_read(&s->skip_unallocated) && !(ret & BDRV_BLOCK_ALLOCATED)) {
|
||||
block_copy_task_end(task, 0);
|
||||
trace_block_copy_skip_range(s, task->req.offset, task->req.bytes);
|
||||
return false;
|
||||
}
|
||||
if (ret & BDRV_BLOCK_ZERO) {
|
||||
task->method = COPY_WRITE_ZEROES;
|
||||
task->zero_fast = qatomic_read(&s->zero_widen);
|
||||
}
|
||||
|
||||
*count = bytes;
|
||||
return ret;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -768,7 +977,6 @@ block_copy_dirty_clusters(BlockCopyCallState *call_state)
|
||||
while (bytes && aio_task_pool_status(aio) == 0 &&
|
||||
!qatomic_read(&call_state->cancelled)) {
|
||||
BlockCopyTask *task;
|
||||
int64_t status_bytes;
|
||||
|
||||
task = block_copy_task_create(s, call_state, offset, bytes);
|
||||
if (!task) {
|
||||
@@ -782,24 +990,12 @@ block_copy_dirty_clusters(BlockCopyCallState *call_state)
|
||||
|
||||
found_dirty = true;
|
||||
|
||||
ret = block_copy_block_status(s, task->req.offset, task->req.bytes,
|
||||
&status_bytes);
|
||||
assert(ret >= 0); /* never fail */
|
||||
if (status_bytes < task->req.bytes) {
|
||||
block_copy_task_shrink(task, status_bytes);
|
||||
}
|
||||
if (qatomic_read(&s->skip_unallocated) &&
|
||||
!(ret & BDRV_BLOCK_ALLOCATED)) {
|
||||
block_copy_task_end(task, 0);
|
||||
trace_block_copy_skip_range(s, task->req.offset, task->req.bytes);
|
||||
if (!block_copy_set_task_method(s, task)) {
|
||||
offset = task_end(task);
|
||||
bytes = end - offset;
|
||||
g_free(task);
|
||||
continue;
|
||||
}
|
||||
if (ret & BDRV_BLOCK_ZERO) {
|
||||
task->method = COPY_WRITE_ZEROES;
|
||||
}
|
||||
|
||||
if (!call_state->ignore_ratelimit) {
|
||||
uint64_t ns = ratelimit_calculate_delay(&s->rate_limit, 0);
|
||||
@@ -812,11 +1008,12 @@ block_copy_dirty_clusters(BlockCopyCallState *call_state)
|
||||
}
|
||||
}
|
||||
|
||||
ratelimit_calculate_delay(&s->rate_limit, task->req.bytes);
|
||||
ratelimit_calculate_delay(&s->rate_limit,
|
||||
block_copy_task_data_bytes(task));
|
||||
|
||||
trace_block_copy_process(s, task->req.offset);
|
||||
|
||||
co_get_from_shres(s->mem, task->req.bytes);
|
||||
co_get_from_shres(s->mem, block_copy_task_data_bytes(task));
|
||||
|
||||
offset = task_end(task);
|
||||
bytes = end - offset;
|
||||
@@ -840,8 +1037,6 @@ out:
|
||||
* block_copy_task_run. If it fails, it means some task already failed
|
||||
* for real reason, let's return first failure.
|
||||
* Still, assert that we don't rewrite failure by success.
|
||||
*
|
||||
* Note: ret may be positive here because of block-status result.
|
||||
*/
|
||||
assert(ret >= 0 || aio_task_pool_status(aio) < 0);
|
||||
ret = aio_task_pool_status(aio);
|
||||
@@ -1062,6 +1257,13 @@ void block_copy_set_skip_unallocated(BlockCopyState *s, bool skip)
|
||||
qatomic_set(&s->skip_unallocated, skip);
|
||||
}
|
||||
|
||||
void block_copy_set_scan_done(BlockCopyState *s)
|
||||
{
|
||||
block_copy_zero_bitmap(s);
|
||||
qatomic_set(&s->skip_unallocated, false);
|
||||
qatomic_store_release(&s->scan_done, true);
|
||||
}
|
||||
|
||||
void block_copy_set_speed(BlockCopyState *s, uint64_t speed)
|
||||
{
|
||||
ratelimit_set_speed(&s->rate_limit, speed, BLOCK_COPY_SLICE_TIME);
|
||||
|
||||
+48
-12
@@ -31,8 +31,23 @@ enum {
|
||||
* contiguous regions of the image is efficient.
|
||||
*/
|
||||
COMMIT_BUFFER_SIZE = 512 * 1024, /* in bytes */
|
||||
|
||||
/*
|
||||
* Zeroes need no buffer, so they are bounded by this instead. It stays
|
||||
* well under BDRV_REQUEST_MAX_BYTES and keeps a cancel from waiting on
|
||||
* a multi-gigabyte write.
|
||||
*/
|
||||
COMMIT_ZERO_CHUNK = 256 * 1024 * 1024, /* in bytes */
|
||||
};
|
||||
|
||||
/* Last block-status answer, covering [offset, end). Empty when equal. */
|
||||
typedef struct CommitStatus {
|
||||
int64_t len;
|
||||
int64_t offset;
|
||||
int64_t end;
|
||||
int ret;
|
||||
} CommitStatus;
|
||||
|
||||
typedef struct CommitBlockJob {
|
||||
BlockJob common;
|
||||
BlockDriverState *commit_top_bs;
|
||||
@@ -130,26 +145,45 @@ static void commit_clean(Job *job)
|
||||
|
||||
static int coroutine_fn
|
||||
commit_iteration(CommitBlockJob *s, int64_t offset,
|
||||
int64_t *requested_bytes, void *buf)
|
||||
int64_t *requested_bytes, void *buf, CommitStatus *st)
|
||||
{
|
||||
BlockErrorAction action;
|
||||
int64_t bytes = *requested_bytes;
|
||||
int64_t bytes;
|
||||
int ret = 0;
|
||||
bool error_in_source = true;
|
||||
|
||||
/* Copy if allocated above the base */
|
||||
WITH_GRAPH_RDLOCK_GUARD() {
|
||||
ret = bdrv_co_common_block_status_above(blk_bs(s->top),
|
||||
s->base_overlay, true, true, offset, COMMIT_BUFFER_SIZE,
|
||||
&bytes, NULL, NULL, NULL);
|
||||
assert(offset >= st->offset);
|
||||
|
||||
if (offset >= st->end) {
|
||||
/* Copy if allocated above the base */
|
||||
WITH_GRAPH_RDLOCK_GUARD() {
|
||||
ret = bdrv_co_common_block_status_above(blk_bs(s->top),
|
||||
s->base_overlay, true, BDRV_WANT_PRECISE, offset,
|
||||
st->len - offset, &bytes, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
if (ret < 0) {
|
||||
trace_commit_one_iteration(s, offset, 0, ret);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
st->offset = offset;
|
||||
st->end = offset + bytes;
|
||||
st->ret = ret;
|
||||
}
|
||||
|
||||
ret = st->ret;
|
||||
bytes = st->end - offset;
|
||||
|
||||
/* An unallocated span costs no I/O, so it is crossed in one step. */
|
||||
if (ret & BDRV_BLOCK_ZERO) {
|
||||
bytes = MIN(bytes, COMMIT_ZERO_CHUNK);
|
||||
} else if (ret & BDRV_BLOCK_ALLOCATED) {
|
||||
bytes = MIN(bytes, COMMIT_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
trace_commit_one_iteration(s, offset, bytes, ret);
|
||||
|
||||
if (ret < 0) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (ret & BDRV_BLOCK_ALLOCATED) {
|
||||
if (ret & BDRV_BLOCK_ZERO) {
|
||||
/*
|
||||
@@ -215,6 +249,7 @@ static int coroutine_fn commit_run(Job *job, Error **errp)
|
||||
int64_t n = 0; /* bytes */
|
||||
QEMU_AUTO_VFREE void *buf = NULL;
|
||||
int64_t len, base_len;
|
||||
CommitStatus st = { 0 };
|
||||
|
||||
len = blk_co_getlength(s->top);
|
||||
if (len < 0) {
|
||||
@@ -235,6 +270,7 @@ static int coroutine_fn commit_run(Job *job, Error **errp)
|
||||
}
|
||||
|
||||
buf = blk_blockalign(s->top, COMMIT_BUFFER_SIZE);
|
||||
st.len = len;
|
||||
|
||||
for (offset = 0; offset < len; offset += n) {
|
||||
/* Note that even when no rate limit is applied we need to yield
|
||||
@@ -245,7 +281,7 @@ static int coroutine_fn commit_run(Job *job, Error **errp)
|
||||
break;
|
||||
}
|
||||
|
||||
ret = commit_iteration(s, offset, &n, buf);
|
||||
ret = commit_iteration(s, offset, &n, buf, &st);
|
||||
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
|
||||
+12
-4
@@ -2398,13 +2398,10 @@ static int32_t scsi_disk_dma_command(SCSIRequest *req, uint8_t *buf)
|
||||
}
|
||||
}
|
||||
|
||||
static void scsi_disk_reset(DeviceState *dev)
|
||||
static void scsi_disk_refresh_max_lba(SCSIDiskState *s)
|
||||
{
|
||||
SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev.qdev, dev);
|
||||
uint64_t nb_sectors;
|
||||
|
||||
scsi_device_purge_requests(&s->qdev, SENSE_CODE(RESET));
|
||||
|
||||
blk_get_geometry(s->qdev.conf.blk, &nb_sectors);
|
||||
|
||||
nb_sectors /= s->qdev.blocksize / BDRV_SECTOR_SIZE;
|
||||
@@ -2412,6 +2409,15 @@ static void scsi_disk_reset(DeviceState *dev)
|
||||
nb_sectors--;
|
||||
}
|
||||
s->qdev.max_lba = nb_sectors;
|
||||
}
|
||||
|
||||
static void scsi_disk_reset(DeviceState *dev)
|
||||
{
|
||||
SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev.qdev, dev);
|
||||
|
||||
scsi_device_purge_requests(&s->qdev, SENSE_CODE(RESET));
|
||||
|
||||
scsi_disk_refresh_max_lba(s);
|
||||
/* reset tray statuses */
|
||||
s->tray_locked = 0;
|
||||
s->tray_open = 0;
|
||||
@@ -2437,6 +2443,8 @@ static void scsi_disk_resize_cb(void *opaque)
|
||||
{
|
||||
SCSIDiskState *s = opaque;
|
||||
|
||||
scsi_disk_refresh_max_lba(s);
|
||||
|
||||
/* SPC lists this sense code as available only for
|
||||
* direct-access devices.
|
||||
*/
|
||||
|
||||
@@ -41,8 +41,9 @@ void block_copy_state_free(BlockCopyState *s);
|
||||
|
||||
void block_copy_reset(BlockCopyState *s, int64_t offset, int64_t bytes);
|
||||
|
||||
int64_t coroutine_fn GRAPH_RDLOCK
|
||||
block_copy_reset_unallocated(BlockCopyState *s, int64_t offset, int64_t *count);
|
||||
int coroutine_fn GRAPH_RDLOCK
|
||||
block_copy_prescan(BlockCopyState *s, int64_t offset, int64_t *cached_end,
|
||||
int64_t *count);
|
||||
|
||||
int coroutine_fn block_copy(BlockCopyState *s, int64_t offset, int64_t bytes,
|
||||
bool ignore_ratelimit, uint64_t timeout_ns,
|
||||
@@ -101,5 +102,6 @@ void block_copy_call_cancel(BlockCopyCallState *call_state);
|
||||
BdrvDirtyBitmap *block_copy_dirty_bitmap(BlockCopyState *s);
|
||||
int64_t block_copy_cluster_size(BlockCopyState *s);
|
||||
void block_copy_set_skip_unallocated(BlockCopyState *s, bool skip);
|
||||
void block_copy_set_scan_done(BlockCopyState *s);
|
||||
|
||||
#endif /* BLOCK_COPY_H */
|
||||
@@ -197,4 +197,7 @@ void bdrv_bsc_fill(BlockDriverState *bs, int64_t offset, int64_t bytes);
|
||||
void coroutine_fn GRAPH_RDLOCK
|
||||
bdrv_co_parent_cb_resize(BlockDriverState *bs);
|
||||
|
||||
void co_wrapper_bdrv_rdlock
|
||||
bdrv_parent_cb_resize(BlockDriverState *bs);
|
||||
|
||||
#endif /* BLOCK_INT_IO_H */
|
||||
@@ -1656,7 +1656,9 @@
|
||||
# copying process. Doesn't influence copy-before-write
|
||||
# operations. 0 means unlimited. If max-chunk is non-zero then
|
||||
# it should not be less than job cluster size which is calculated
|
||||
# as maximum of target image cluster size and 64k. Default 0.
|
||||
# as maximum of target image cluster size and 64k. Write-zeroes
|
||||
# requests to a target which zeroes efficiently are not bounded by
|
||||
# it. Default 0.
|
||||
#
|
||||
# @min-cluster-size: Minimum size of blocks used by copy-before-write
|
||||
# and background copy operations. Has to be a power of 2. No
|
||||
|
||||
+101
-1
@@ -25,13 +25,14 @@
|
||||
import time
|
||||
import os
|
||||
import iotests
|
||||
from iotests import qemu_img, qemu_io
|
||||
from iotests import qemu_img, qemu_img_create, qemu_io, compare_images
|
||||
import struct
|
||||
import errno
|
||||
|
||||
backing_img = os.path.join(iotests.test_dir, 'backing.img')
|
||||
mid_img = os.path.join(iotests.test_dir, 'mid.img')
|
||||
test_img = os.path.join(iotests.test_dir, 'test.img')
|
||||
reference_img = os.path.join(iotests.test_dir, 'reference.img')
|
||||
|
||||
class ImageCommitTestCase(iotests.QMPTestCase):
|
||||
'''Abstract base class for image commit test cases'''
|
||||
@@ -951,6 +952,105 @@ class TestCommitWithOverriddenBacking(iotests.QMPTestCase):
|
||||
self.vm.qmp('block-job-complete', device='commit')
|
||||
self.vm.event_wait('BLOCK_JOB_COMPLETED')
|
||||
|
||||
class TestCommitLargeRuns(iotests.QMPTestCase):
|
||||
"""Commit runs long enough to cross commit_iteration()'s cached span."""
|
||||
|
||||
MB = 1024 * 1024
|
||||
CLUSTER = 64 * 1024
|
||||
|
||||
# Runs several COMMIT_BUFFER_SIZE (512K) chunks long, of every kind.
|
||||
SIZE = 32 * MB
|
||||
LAYOUT = [
|
||||
(0, 4 * MB, 'data'),
|
||||
(4 * MB, 6 * MB, 'hole'),
|
||||
(10 * MB, 4 * MB, 'data'),
|
||||
(14 * MB, 6 * MB, 'zero'),
|
||||
(20 * MB, 4 * MB, 'data'),
|
||||
(24 * MB, 8 * MB, 'hole'),
|
||||
]
|
||||
|
||||
# The same, with every transition off the 512K boundary.
|
||||
SIZE_FRAGMENTED = 384 * CLUSTER # 24M
|
||||
LAYOUT_FRAGMENTED = [
|
||||
(0, 45 * CLUSTER, 'data'),
|
||||
(45 * CLUSTER, 55 * CLUSTER, 'hole'),
|
||||
(100 * CLUSTER, CLUSTER, 'data'),
|
||||
(101 * CLUSTER, 49 * CLUSTER, 'zero'),
|
||||
(150 * CLUSTER, 80 * CLUSTER, 'data'),
|
||||
(230 * CLUSTER, CLUSTER, 'hole'),
|
||||
(231 * CLUSTER, 69 * CLUSTER, 'data'),
|
||||
(300 * CLUSTER, 83 * CLUSTER, 'zero'),
|
||||
(383 * CLUSTER, CLUSTER, 'hole'),
|
||||
]
|
||||
|
||||
def setUp(self):
|
||||
self.vm = iotests.VM()
|
||||
self.vm.launch()
|
||||
|
||||
def tearDown(self):
|
||||
self.vm.shutdown()
|
||||
for img in (backing_img, mid_img, test_img, reference_img):
|
||||
if os.path.exists(img):
|
||||
os.remove(img)
|
||||
|
||||
def build_images(self, layout, size):
|
||||
# A pattern of its own in base, so a misplaced cluster shows up.
|
||||
qemu_img_create('-f', iotests.imgfmt, backing_img, str(size))
|
||||
qemu_io('-c', f'write -P 0x11 0 {size}', backing_img)
|
||||
|
||||
qemu_img_create('-f', iotests.imgfmt, '-b', backing_img, '-F',
|
||||
iotests.imgfmt, mid_img, str(size))
|
||||
for offset, length, kind in layout:
|
||||
if kind == 'data':
|
||||
qemu_io('-c', f'write -P 0x22 {offset} {length}', mid_img)
|
||||
elif kind == 'zero':
|
||||
qemu_io('-c', f'write -z {offset} {length}', mid_img)
|
||||
|
||||
# What base must equal once mid is committed into it.
|
||||
qemu_img('convert', '-f', iotests.imgfmt, '-O', iotests.imgfmt,
|
||||
mid_img, reference_img)
|
||||
|
||||
# An empty layer above mid, so top_node=mid is not the active one.
|
||||
qemu_img_create('-f', iotests.imgfmt, '-b', mid_img, '-F',
|
||||
iotests.imgfmt, test_img, str(size))
|
||||
|
||||
self.vm.cmd('blockdev-add', {
|
||||
'node-name': 'base',
|
||||
'driver': iotests.imgfmt,
|
||||
'file': {'driver': 'file', 'filename': backing_img},
|
||||
})
|
||||
self.vm.cmd('blockdev-add', {
|
||||
'node-name': 'mid',
|
||||
'driver': iotests.imgfmt,
|
||||
'file': {'driver': 'file', 'filename': mid_img},
|
||||
'backing': 'base',
|
||||
})
|
||||
self.vm.cmd('blockdev-add', {
|
||||
'node-name': 'active',
|
||||
'driver': iotests.imgfmt,
|
||||
'file': {'driver': 'file', 'filename': test_img},
|
||||
'backing': 'mid',
|
||||
})
|
||||
|
||||
def commit_and_verify(self):
|
||||
self.vm.cmd('block-commit', job_id='commit0', device='active',
|
||||
top_node='mid', base_node='base')
|
||||
self.wait_until_completed(drive='commit0')
|
||||
|
||||
self.vm.cmd('blockdev-del', node_name='active')
|
||||
self.vm.cmd('blockdev-del', node_name='mid')
|
||||
self.vm.cmd('blockdev-del', node_name='base')
|
||||
self.assertTrue(compare_images(reference_img, backing_img))
|
||||
|
||||
def test_commit_large_runs(self):
|
||||
self.build_images(self.LAYOUT, self.SIZE)
|
||||
self.commit_and_verify()
|
||||
|
||||
def test_commit_fragmented_runs(self):
|
||||
self.build_images(self.LAYOUT_FRAGMENTED, self.SIZE_FRAGMENTED)
|
||||
self.commit_and_verify()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
iotests.main(supported_fmts=['qcow2', 'qed'],
|
||||
supported_protocols=['file'])
|
||||
@@ -1,5 +1,5 @@
|
||||
.................................................................
|
||||
...................................................................
|
||||
----------------------------------------------------------------------
|
||||
Ran 65 tests
|
||||
Ran 67 tests
|
||||
|
||||
OK
|
||||
+346
-1
@@ -22,8 +22,11 @@
|
||||
#
|
||||
|
||||
import os
|
||||
from collections import namedtuple
|
||||
|
||||
import iotests
|
||||
from iotests import try_remove
|
||||
from iotests import (compare_images, qemu_img_create, qemu_img_map, qemu_io,
|
||||
try_remove)
|
||||
from qemu.qmp.qmp_client import ExecuteError
|
||||
|
||||
|
||||
@@ -748,6 +751,348 @@ class TestIncrementalBackupBlkdebug(TestIncrementalBackupBase):
|
||||
self.check_backups()
|
||||
|
||||
|
||||
# Backup of sources mixing data, zero clusters and holes.
|
||||
|
||||
Extent = namedtuple('Extent', ['start', 'length', 'kind'])
|
||||
Case = namedtuple('Case', ['size', 'layout', 'expected'], defaults=[None])
|
||||
|
||||
source_img = os.path.join(iotests.test_dir, 'source')
|
||||
base_img = os.path.join(iotests.test_dir, 'base')
|
||||
target_img = os.path.join(iotests.test_dir, 'target')
|
||||
|
||||
SIZE = 64 * 1024 * 1024
|
||||
MB = 1024 * 1024
|
||||
CLUSTER = 64 * 1024
|
||||
|
||||
# Data, write-zero and holes, every combination at a cluster boundary.
|
||||
MIXED = Case(SIZE, [
|
||||
(0, MB, 'data'),
|
||||
(2 * MB, MB, 'zero'),
|
||||
(5 * MB, 2 * MB, 'data'),
|
||||
(8 * MB, MB, 'zero'),
|
||||
(10 * MB, MB // 2, 'data'),
|
||||
(20 * MB, 4 * MB, 'zero'),
|
||||
(30 * MB, MB, 'data'),
|
||||
])
|
||||
|
||||
# Single-cluster runs, and a zero run ending exactly at EOF.
|
||||
BOUNDARY_SIZE = 16 * MB
|
||||
BOUNDARY = Case(BOUNDARY_SIZE, [
|
||||
(0, CLUSTER, 'zero'),
|
||||
(CLUSTER, CLUSTER, 'data'),
|
||||
(2 * CLUSTER, CLUSTER, 'zero'),
|
||||
(3 * CLUSTER, CLUSTER, 'data'),
|
||||
(4 * CLUSTER, 8 * MB, 'zero'),
|
||||
(4 * CLUSTER + 8 * MB, CLUSTER, 'data'),
|
||||
(BOUNDARY_SIZE - CLUSTER, CLUSTER, 'zero'),
|
||||
])
|
||||
|
||||
# A zero run past the old block_copy_chunk_size() 16M cap.
|
||||
LARGE_ZERO = Case(48 * MB, [
|
||||
(0, MB, 'data'),
|
||||
(4 * MB, 32 * MB, 'zero'),
|
||||
(40 * MB, MB, 'data'),
|
||||
])
|
||||
|
||||
# Image size not a multiple of the cluster size: a partial tail cluster.
|
||||
TAIL_SIZE = 4 * MB + 4096
|
||||
TAIL_CLUSTER = (TAIL_SIZE // CLUSTER) * CLUSTER
|
||||
TAIL_DATA = Case(TAIL_SIZE, [
|
||||
(0, MB, 'data'),
|
||||
(2 * MB, MB, 'zero'),
|
||||
(4 * MB, TAIL_SIZE - 4 * MB, 'data'),
|
||||
])
|
||||
# The partial tail cluster falls out of zero_bitmap, so it copies as data.
|
||||
TAIL_ZERO = Case(TAIL_SIZE, [
|
||||
(0, MB, 'data'),
|
||||
(2 * MB, TAIL_SIZE - 2 * MB, 'zero'),
|
||||
], [
|
||||
(0, MB, 'data'),
|
||||
(2 * MB, TAIL_CLUSTER - 2 * MB, 'zero'),
|
||||
(TAIL_CLUSTER, TAIL_SIZE - TAIL_CLUSTER, 'data'),
|
||||
])
|
||||
|
||||
|
||||
def coalesce(extents):
|
||||
out = []
|
||||
for e in extents:
|
||||
prev = out[-1] if out else None
|
||||
adjacent = prev is not None and prev.start + prev.length == e.start
|
||||
if adjacent and prev.kind == e.kind:
|
||||
out[-1] = prev._replace(length=prev.length + e.length)
|
||||
else:
|
||||
out.append(e)
|
||||
return out
|
||||
|
||||
|
||||
def layout_to_extents(layout, size, gap='hole'):
|
||||
extents = []
|
||||
pos = 0
|
||||
for offset, length, kind in layout:
|
||||
if offset > pos:
|
||||
extents.append(Extent(pos, offset - pos, gap))
|
||||
extents.append(Extent(offset, length, kind))
|
||||
pos = offset + length
|
||||
if pos < size:
|
||||
extents.append(Extent(pos, size - pos, gap))
|
||||
return coalesce(extents)
|
||||
|
||||
|
||||
def create_image(path, size, backing=None, opts=None):
|
||||
args = ['-f', iotests.imgfmt]
|
||||
if opts:
|
||||
args += ['-o', opts]
|
||||
if backing:
|
||||
args += ['-b', backing, '-F', iotests.imgfmt]
|
||||
qemu_img_create(*args, path, str(size))
|
||||
|
||||
|
||||
class TestBackupZeroClusters(iotests.QMPTestCase):
|
||||
def setUp(self):
|
||||
self.vm = iotests.VM()
|
||||
self.vm.launch()
|
||||
|
||||
def tearDown(self):
|
||||
self.vm.shutdown()
|
||||
for img in (source_img, base_img, target_img):
|
||||
if os.path.exists(img):
|
||||
os.remove(img)
|
||||
|
||||
def hmp_write(self, drive, cmd):
|
||||
res = self.vm.hmp_qemu_io(drive, cmd)
|
||||
self.assertNotIn('error', res['return'].lower())
|
||||
|
||||
def write_layout(self, layout):
|
||||
for offset, length, kind in layout:
|
||||
opt = '-z' if kind == 'zero' else '-P 0x5a'
|
||||
self.hmp_write('src', f'write {opt} {offset} {length}')
|
||||
|
||||
def assert_map(self, case, backing=False, gap='hole'):
|
||||
# Content is not enough, pin the data/zero/hole split as well.
|
||||
def classify(e):
|
||||
is_hole = e['depth'] > 0 if backing else not e['present']
|
||||
return 'hole' if is_hole else ('zero' if e['zero'] else 'data')
|
||||
|
||||
actual = coalesce([Extent(e['start'], e['length'], classify(e))
|
||||
for e in qemu_img_map(target_img)])
|
||||
layout = case.expected if case.expected else case.layout
|
||||
|
||||
self.assertEqual(actual, layout_to_extents(layout, case.size, gap))
|
||||
|
||||
def add_source(self, case=MIXED, backing=None, opts=None):
|
||||
create_image(source_img, case.size, backing, opts)
|
||||
|
||||
self.vm.cmd('blockdev-add', {
|
||||
'node-name': 'src',
|
||||
'driver': iotests.imgfmt,
|
||||
'file': {'driver': 'file', 'filename': source_img},
|
||||
})
|
||||
|
||||
# Write through the node, so an attached bitmap sees it.
|
||||
self.write_layout(case.layout)
|
||||
|
||||
def dirty_layout(self, case):
|
||||
# A new bitmap tracks nothing yet: dirty all, then re-apply.
|
||||
self.vm.cmd('block-dirty-bitmap-add', node='src', name='bm0')
|
||||
self.hmp_write('src', f'write -z 0 {case.size}')
|
||||
self.write_layout(case.layout)
|
||||
|
||||
def do_backup(self, sync, case, target_backing=None, prefill=None,
|
||||
**kwargs):
|
||||
create_image(target_img, case.size, target_backing)
|
||||
|
||||
if prefill is not None:
|
||||
# Not zero, so a skipped cluster is provably untouched.
|
||||
qemu_io('-c', f'write -P {prefill} 0 {case.size}', target_img)
|
||||
|
||||
self.vm.cmd('blockdev-add', {
|
||||
'node-name': 'target',
|
||||
'driver': iotests.imgfmt,
|
||||
'file': {'driver': 'file', 'filename': target_img},
|
||||
})
|
||||
|
||||
self.vm.cmd('blockdev-backup', device='src', target='target',
|
||||
job_id='bk0', sync=sync, **kwargs)
|
||||
self.wait_until_completed(drive='bk0')
|
||||
|
||||
self.vm.cmd('blockdev-del', node_name='target')
|
||||
self.vm.cmd('blockdev-del', node_name='src')
|
||||
|
||||
def backup_and_check(self, sync, case, gap='zero', backing=False,
|
||||
**kwargs):
|
||||
self.do_backup(sync, case, **kwargs)
|
||||
self.assertTrue(compare_images(source_img, target_img))
|
||||
self.assert_map(case, backing=backing, gap=gap)
|
||||
|
||||
def test_full(self):
|
||||
self.add_source()
|
||||
self.backup_and_check('full', MIXED)
|
||||
|
||||
def test_full_zero_overwrite(self):
|
||||
# full skips holes, so only check that zero overwrites prefill.
|
||||
case = Case(SIZE, [(2 * MB, MB, 'zero')])
|
||||
self.add_source(case)
|
||||
self.do_backup('full', case, prefill=0xcc)
|
||||
qemu_io('-c', f'read -P 0 {2 * MB} {MB}', target_img)
|
||||
|
||||
def test_bitmap(self):
|
||||
self.add_source()
|
||||
self.dirty_layout(MIXED)
|
||||
self.backup_and_check('bitmap', MIXED, bitmap='bm0',
|
||||
bitmap_mode='never')
|
||||
|
||||
def test_top(self):
|
||||
# Non-zero backing data, so a hole and an explicit zero differ.
|
||||
create_image(base_img, SIZE)
|
||||
qemu_io('-c', f'write -P 0x33 0 {SIZE}', base_img)
|
||||
|
||||
self.add_source(backing=base_img)
|
||||
self.backup_and_check('top', MIXED, gap='hole', backing=True,
|
||||
target_backing=base_img)
|
||||
|
||||
def test_boundary_full(self):
|
||||
self.add_source(BOUNDARY)
|
||||
self.backup_and_check('full', BOUNDARY)
|
||||
|
||||
def test_boundary_bitmap(self):
|
||||
self.add_source(BOUNDARY)
|
||||
self.dirty_layout(BOUNDARY)
|
||||
self.backup_and_check('bitmap', BOUNDARY, bitmap='bm0',
|
||||
bitmap_mode='never')
|
||||
|
||||
def test_large_zero_full(self):
|
||||
self.add_source(LARGE_ZERO)
|
||||
self.backup_and_check('full', LARGE_ZERO)
|
||||
|
||||
def test_large_zero_bitmap(self):
|
||||
self.add_source(LARGE_ZERO)
|
||||
self.dirty_layout(LARGE_ZERO)
|
||||
self.backup_and_check('bitmap', LARGE_ZERO, bitmap='bm0',
|
||||
bitmap_mode='never')
|
||||
|
||||
def test_huge_zero(self):
|
||||
# A zero run past the cap on a single write-zeroes request, so it
|
||||
# has to be split. qemu-io caps one write at 2G, hence three.
|
||||
case = Case(2560 * MB, [(0, 1024 * MB, 'zero'),
|
||||
(1024 * MB, 1024 * MB, 'zero'),
|
||||
(2048 * MB, 512 * MB, 'zero')])
|
||||
self.add_source(case)
|
||||
self.backup_and_check('full', case)
|
||||
|
||||
def test_tail_data(self):
|
||||
self.add_source(TAIL_DATA)
|
||||
self.backup_and_check('full', TAIL_DATA)
|
||||
|
||||
def test_tail_zero(self):
|
||||
self.add_source(TAIL_ZERO)
|
||||
self.backup_and_check('full', TAIL_ZERO)
|
||||
|
||||
def test_tail_zero_bitmap(self):
|
||||
# Same tail rounding as test_tail_zero, via the bitmap scan.
|
||||
self.add_source(TAIL_ZERO)
|
||||
self.dirty_layout(TAIL_ZERO)
|
||||
self.backup_and_check('bitmap', TAIL_ZERO, bitmap='bm0',
|
||||
bitmap_mode='never')
|
||||
|
||||
def test_mixed_cluster(self):
|
||||
# 4K source clusters, so content varies inside one 64K cluster.
|
||||
case = Case(2 * CLUSTER, [
|
||||
(0, 8 * 1024, 'zero'),
|
||||
(8 * 1024, 8 * 1024, 'data'),
|
||||
(CLUSTER, CLUSTER, 'zero'),
|
||||
], [
|
||||
# A mixed cluster must be data, or the data at [8k, 16k) is lost.
|
||||
(0, CLUSTER, 'data'),
|
||||
(CLUSTER, CLUSTER, 'zero'),
|
||||
])
|
||||
self.add_source(case, opts='cluster_size=4k')
|
||||
self.backup_and_check('full', case)
|
||||
|
||||
def test_top_zero_broken(self):
|
||||
# An overlay hole before an explicit-zero run: the zero prefix
|
||||
# must stop at the hole, or the backing data under it is lost.
|
||||
size = 2 * CLUSTER
|
||||
create_image(base_img, size, opts='cluster_size=4k')
|
||||
qemu_io('-c', f'write -P 0x33 0 {size}', base_img)
|
||||
|
||||
# [0, 4k) stays a hole, the zero run spills into cluster 1.
|
||||
case = Case(size, [(4096, CLUSTER, 'zero')])
|
||||
self.add_source(case, backing=base_img, opts='cluster_size=4k')
|
||||
|
||||
self.do_backup('top', case, target_backing=base_img)
|
||||
self.assertTrue(compare_images(source_img, target_img))
|
||||
|
||||
def test_bitmap_straddle(self):
|
||||
# One dirty run straddling a zero/data transition, both ways.
|
||||
case = Case(SIZE, [])
|
||||
self.add_source(case)
|
||||
self.vm.cmd('block-dirty-bitmap-add', node='src', name='bm0')
|
||||
|
||||
# One contiguous dirty run each: [7M, 9M) zero to data, and
|
||||
# [15M, 17M) data to zero.
|
||||
layout = [
|
||||
(7 * MB, MB, 'zero'),
|
||||
(8 * MB, MB, 'data'),
|
||||
(15 * MB, MB, 'data'),
|
||||
(16 * MB, MB, 'zero'),
|
||||
]
|
||||
self.write_layout(layout)
|
||||
|
||||
self.do_backup('bitmap', case, bitmap='bm0', bitmap_mode='never')
|
||||
self.assertTrue(compare_images(source_img, target_img))
|
||||
# Nothing outside the two dirty runs may reach the target.
|
||||
self.assert_map(case._replace(layout=layout))
|
||||
|
||||
def test_bitmap_fragmented(self):
|
||||
# Isolated single-cluster dirty spots: nothing outside them
|
||||
# may reach the target.
|
||||
case = Case(SIZE, [])
|
||||
self.add_source(case)
|
||||
|
||||
# Written before the bitmap exists, so untracked.
|
||||
self.hmp_write('src', f'write -P 0x5a 0 {16 * MB}')
|
||||
|
||||
self.vm.cmd('block-dirty-bitmap-add', node='src', name='bm0')
|
||||
|
||||
# The only dirty bit in the data region, with a pattern of its own.
|
||||
data_island = 4 * MB
|
||||
self.hmp_write('src', f'write -P 0x7b {data_island} {CLUSTER}')
|
||||
|
||||
# The only dirty bit in the hole region.
|
||||
zero_island = 24 * MB
|
||||
self.hmp_write('src', f'write -z {zero_island} {CLUSTER}')
|
||||
|
||||
self.do_backup('bitmap', case, bitmap='bm0', bitmap_mode='never',
|
||||
prefill=0xcc)
|
||||
|
||||
# Only the two isolated spots should have reached target ...
|
||||
qemu_io('-c', f'read -P 0x7b {data_island} {CLUSTER}', target_img)
|
||||
qemu_io('-c', f'read -P 0 {zero_island} {CLUSTER}', target_img)
|
||||
|
||||
# ... everything else must still hold the prefill pattern.
|
||||
qemu_io('-c', f'read -P 0xcc 0 {CLUSTER}', target_img)
|
||||
qemu_io('-c', f'read -P 0xcc {8 * MB} {CLUSTER}', target_img)
|
||||
|
||||
def test_bitmap_clean_zero_gap(self):
|
||||
# A clean zero run between two dirty ones must stay prefilled.
|
||||
case = Case(16 * MB, [])
|
||||
self.add_source(case)
|
||||
self.hmp_write('src', f'write -z 0 {16 * MB}')
|
||||
|
||||
self.vm.cmd('block-dirty-bitmap-add', node='src', name='bm0')
|
||||
self.write_layout([(2 * MB, MB, 'zero'), (6 * MB, MB, 'zero')])
|
||||
|
||||
self.do_backup('bitmap', case, bitmap='bm0', bitmap_mode='never',
|
||||
prefill=0xcc)
|
||||
|
||||
qemu_io('-c', f'read -P 0 {2 * MB} {MB}', target_img)
|
||||
qemu_io('-c', f'read -P 0 {6 * MB} {MB}', target_img)
|
||||
|
||||
qemu_io('-c', f'read -P 0xcc 0 {2 * MB}', target_img)
|
||||
qemu_io('-c', f'read -P 0xcc {3 * MB} {3 * MB}', target_img)
|
||||
qemu_io('-c', f'read -P 0xcc {7 * MB} {9 * MB}', target_img)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
iotests.main(supported_fmts=['qcow2'],
|
||||
supported_protocols=['file'],
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
.............
|
||||
..............................
|
||||
----------------------------------------------------------------------
|
||||
Ran 13 tests
|
||||
Ran 30 tests
|
||||
|
||||
OK
|
||||
@@ -24,12 +24,15 @@ import iotests
|
||||
from iotests import imgfmt, log, qemu_img_create, QMPTestCase
|
||||
|
||||
image_size = 1 * 1024 * 1024
|
||||
images = [os.path.join(iotests.test_dir, f'{i}.img') for i in range(0, 4)]
|
||||
images = [os.path.join(iotests.test_dir, f'{i}.img') for i in range(0, 5)]
|
||||
|
||||
# node4 is deliberately larger, to cover a replacement which changes the size
|
||||
image_sizes = [image_size] * 4 + [2 * image_size]
|
||||
|
||||
class TestQOMSetDrive(QMPTestCase):
|
||||
def setUp(self) -> None:
|
||||
for image in images:
|
||||
qemu_img_create('-f', imgfmt, image, str(image_size))
|
||||
for image, size in zip(images, image_sizes):
|
||||
qemu_img_create('-f', imgfmt, image, str(size))
|
||||
|
||||
self.vm = iotests.VM()
|
||||
for i, image in enumerate(images):
|
||||
@@ -68,6 +71,11 @@ class TestQOMSetDrive(QMPTestCase):
|
||||
log(self.vm.qmp('qom-get', path='/machine/peripheral/no-iot',
|
||||
property='drive'))
|
||||
|
||||
log(self.vm.qmp('qom-set', path='/machine/peripheral/no-iot',
|
||||
property='drive', value='node4'))
|
||||
log(self.vm.qmp('qom-get', path='/machine/peripheral/no-iot',
|
||||
property='drive'))
|
||||
|
||||
if __name__ == '__main__':
|
||||
iotests.activate_logging()
|
||||
# LUKS would require special key-secret handling in add_blockdevs()
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
{"return": "node1"}
|
||||
{"return": {}}
|
||||
{"return": "node3"}
|
||||
{"return": {}}
|
||||
{"return": "node4"}
|
||||
.
|
||||
----------------------------------------------------------------------
|
||||
Ran 1 tests
|
||||
|
||||
@@ -236,6 +236,53 @@ static void test_unmap_large_lba(void *obj, void *data,
|
||||
qvirtio_scsi_pci_free(vs);
|
||||
}
|
||||
|
||||
/* Test replacing the backing node with one of a different size */
|
||||
static void test_replaced_node_size(void *obj, void *data,
|
||||
QGuestAllocator *t_alloc)
|
||||
{
|
||||
QVirtioSCSI *scsi = obj;
|
||||
QVirtioSCSIQueues *vs;
|
||||
uint8_t buf[512] = { 0 };
|
||||
/* READ(10), LBA 0, transfer length 1 */
|
||||
const uint8_t read_low_cdb[VIRTIO_SCSI_CDB_SIZE] = {
|
||||
0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00
|
||||
};
|
||||
/* READ(10), LBA 0x1000 (2 MiB), transfer length 1 */
|
||||
const uint8_t read_high_cdb[VIRTIO_SCSI_CDB_SIZE] = {
|
||||
0x28, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x01, 0x00
|
||||
};
|
||||
struct virtio_scsi_cmd_resp resp;
|
||||
|
||||
alloc = t_alloc;
|
||||
vs = qvirtio_scsi_init(scsi->vdev);
|
||||
|
||||
/* LBA 0 is inside the 1 MiB node the device was realized with */
|
||||
virtio_scsi_do_command(vs, read_low_cdb, buf, sizeof(buf), NULL, 0, &resp);
|
||||
g_assert_cmphex(resp.response, ==, 0);
|
||||
g_assert_cmphex(resp.status, ==, GOOD);
|
||||
|
||||
/* Swap in a 128 MiB node; the device is not reset by this */
|
||||
qtest_qmp_assert_success(global_qtest,
|
||||
"{'execute': 'qom-set', 'arguments': {"
|
||||
" 'path': '/machine/peripheral/scsi-hd0',"
|
||||
" 'property': 'drive', 'value': 'big'}}");
|
||||
|
||||
/* The guest has to be told that the capacity it knows is stale */
|
||||
virtio_scsi_do_command(vs, read_high_cdb, buf, sizeof(buf), NULL, 0, &resp);
|
||||
g_assert_cmphex(resp.response, ==, 0);
|
||||
g_assert_cmphex(resp.status, ==, CHECK_CONDITION);
|
||||
g_assert_cmphex(resp.sense[2], ==, UNIT_ATTENTION);
|
||||
g_assert_cmphex(resp.sense[12], ==, 0x2a);
|
||||
g_assert_cmphex(resp.sense[13], ==, 0x09); /* CAPACITY DATA HAS CHANGED */
|
||||
|
||||
/* LBA 0x1000 is past the old node but well inside the new one */
|
||||
virtio_scsi_do_command(vs, read_high_cdb, buf, sizeof(buf), NULL, 0, &resp);
|
||||
g_assert_cmphex(resp.response, ==, 0);
|
||||
g_assert_cmphex(resp.status, ==, GOOD);
|
||||
|
||||
qvirtio_scsi_pci_free(vs);
|
||||
}
|
||||
|
||||
static void test_write_to_cdrom(void *obj, void *data,
|
||||
QGuestAllocator *t_alloc)
|
||||
{
|
||||
@@ -365,6 +412,18 @@ static void *virtio_scsi_setup_4k(GString *cmd_line, void *arg)
|
||||
return arg;
|
||||
}
|
||||
|
||||
static void *virtio_scsi_setup_replace(GString *cmd_line, void *arg)
|
||||
{
|
||||
g_string_append(cmd_line,
|
||||
" -blockdev driver=null-co,read-zeroes=on,"
|
||||
"size=1048576,node-name=small"
|
||||
" -blockdev driver=null-co,read-zeroes=on,"
|
||||
"size=134217728,node-name=big"
|
||||
" -device scsi-hd,id=scsi-hd0,drive=small,"
|
||||
"lun=0,scsi-id=1");
|
||||
return arg;
|
||||
}
|
||||
|
||||
static void *virtio_scsi_setup_cd(GString *cmd_line, void *arg)
|
||||
{
|
||||
g_string_append(cmd_line,
|
||||
@@ -399,6 +458,10 @@ static void register_virtio_scsi_test(void)
|
||||
qos_add_test("large-lba-unmap", "virtio-scsi",
|
||||
test_unmap_large_lba, &opts);
|
||||
|
||||
opts.before = virtio_scsi_setup_replace;
|
||||
qos_add_test("replaced-node-size", "virtio-scsi",
|
||||
test_replaced_node_size, &opts);
|
||||
|
||||
opts.before = virtio_scsi_setup_cd;
|
||||
qos_add_test("write-to-cdrom", "virtio-scsi", test_write_to_cdrom, &opts);
|
||||
|
||||
|
||||
@@ -69,6 +69,10 @@ static bool co_try_get_from_shres_locked(SharedResource *s, uint64_t n)
|
||||
void coroutine_fn co_get_from_shres(SharedResource *s, uint64_t n)
|
||||
{
|
||||
assert(n <= s->total);
|
||||
if (!n) {
|
||||
return;
|
||||
}
|
||||
|
||||
QEMU_LOCK_GUARD(&s->lock);
|
||||
while (!co_try_get_from_shres_locked(s, n)) {
|
||||
qemu_co_queue_wait(&s->queue, &s->lock);
|
||||
@@ -77,6 +81,10 @@ void coroutine_fn co_get_from_shres(SharedResource *s, uint64_t n)
|
||||
|
||||
void coroutine_fn co_put_to_shres(SharedResource *s, uint64_t n)
|
||||
{
|
||||
if (!n) {
|
||||
return;
|
||||
}
|
||||
|
||||
QEMU_LOCK_GUARD(&s->lock);
|
||||
assert(s->total - s->available >= n);
|
||||
s->available += n;
|
||||
|
||||
Reference in new issue
Block a user