Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge tag 'for-upstream' of https://repo.or.cz/qemu/kevin into staging
Block layer patches

- qcow2 spec: Rename "zlib" compression to "deflate"
- Honour graph read lock even in the main thread + prerequisite fixes
- aio-posix: do not nest poll handlers (fixes infinite recursion)
- Refactor QMP blockdev transactions
- iotests/245: Check if 'compress' driver is available

# -----BEGIN PGP SIGNATURE-----
#
# iQJFBAABCAAvFiEE3D3rFZqa+V09dFb+fwmycsiPL9YFAmRlBcwRHGt3b2xmQHJl
# ZGhhdC5jb20ACgkQfwmycsiPL9Z3MRAAuILiH3EV3Dz8L0tgacdMT2cinfdBJYjj
# LMJrrxeaIgHGb3p80nnLRPE3JvT1+DwfCDr5Gi+T9BE7Qz2rnQ+SvnxBWa0Fns2i
# E54amK6aOqFnqfAVLLHbe4Xc+SY91dWIZf3XDsEhhbWnsnAMauehkM9+W52XkFjQ
# apzuoATZD4FeCZRX9PoSFSnTL88ZcA4PGdglr+fjPO4yWY3Hs9RhS9t35iY+zdFD
# JqYwW8Os2kHO7nzpjdXkwz51mxKFcUqafb2Lbt6Fnhv8Q+rdAiSs5pxT/KSuwmCE
# vOw6EKjz6XKpqwktKz0PhW/Hxee+eU1G3UOqYuV9v9gJhoji32pQD+PoadJ0chhk
# xdcve9axWuwG4UYSSv4p/XxMMuuBdbWore/8mLazUoOjFWE1+wbZHmGsG/xQ8Pi7
# A+5rCL0iXPkf1C39CYLGyabc7TtQNooMkrJq7eNCTKuzx1/Y150itqU8Azn9bVe0
# bBGuuu1EvS9vwqMpijFEwnOpFjj38M7hTQayqS1/5PDxrms1ZEBL4TYwm296xwVZ
# cmRvmDXUu6O6ss8oM8Kq+6gHzV7IJT41fvnHui7Re9uUC8qbZ0xxvrI5LBFzt63u
# lfiv+nf8zp5abAfEaaMUakNmRSqlR4kjWB+bknMcdE6myOipZXKD66UbE4qFsHNt
# oH07ljzq/k8=
# =UqzX
# -----END PGP SIGNATURE-----
# gpg: Signature made Wed 17 May 2023 09:50:20 AM PDT
# gpg:                using RSA key DC3DEB159A9AF95D3D7456FE7F09B272C88F2FD6
# gpg:                issuer "kwolf@redhat.com"
# gpg: Good signature from "Kevin Wolf <kwolf@redhat.com>" [full]

* tag 'for-upstream' of https://repo.or.cz/qemu/kevin:
  tested: add test for nested aio_poll() in poll handlers
  aio-posix: do not nest poll handlers
  iotests/245: Check if 'compress' driver is available
  graph-lock: Honour read locks even in the main thread
  blockjob: Adhere to rate limit even when reentered early
  test-bdrv-drain: Call bdrv_co_unref() in coroutine context
  test-bdrv-drain: Take graph lock more selectively
  qemu-img: Take graph lock more selectively
  qcow2: Unlock the graph in qcow2_do_open() where necessary
  block/export: Fix null pointer dereference in error path
  block: Call .bdrv_co_create(_opts) unlocked
  docs/interop/qcow2.txt: fix description about "zlib" clusters
  blockdev: qmp_transaction: drop extra generic layer
  blockdev: use state.bitmap in block-dirty-bitmap-add action
  blockdev: transaction: refactor handling transaction properties
  blockdev: qmp_transaction: refactor loop to classic for
  blockdev: transactions: rename some things
  blockdev: refactor transaction to use Transaction API

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
  • Loading branch information
rth7680 committed May 17, 2023
2 parents d27e7c3 + 75b2591 commit ce7edea
Show file tree
Hide file tree
Showing 30 changed files with 541 additions and 487 deletions.
1 change: 0 additions & 1 deletion block.c
Expand Up @@ -533,7 +533,6 @@ int coroutine_fn bdrv_co_create(BlockDriver *drv, const char *filename,
int ret;
GLOBAL_STATE_CODE();
ERRP_GUARD();
assert_bdrv_graph_readable();

if (!drv->bdrv_co_create_opts) {
error_setg(errp, "Driver '%s' does not support image creation",
Expand Down
7 changes: 2 additions & 5 deletions block/commit.c
Expand Up @@ -116,7 +116,6 @@ static int coroutine_fn commit_run(Job *job, Error **errp)
{
CommitBlockJob *s = container_of(job, CommitBlockJob, common.job);
int64_t offset;
uint64_t delay_ns = 0;
int ret = 0;
int64_t n = 0; /* bytes */
QEMU_AUTO_VFREE void *buf = NULL;
Expand Down Expand Up @@ -149,7 +148,7 @@ static int coroutine_fn commit_run(Job *job, Error **errp)
/* Note that even when no rate limit is applied we need to yield
* with no pending I/O here so that bdrv_drain_all() returns.
*/
job_sleep_ns(&s->common.job, delay_ns);
block_job_ratelimit_sleep(&s->common);
if (job_is_cancelled(&s->common.job)) {
break;
}
Expand Down Expand Up @@ -184,9 +183,7 @@ static int coroutine_fn commit_run(Job *job, Error **errp)
job_progress_update(&s->common.job, n);

if (copy) {
delay_ns = block_job_ratelimit_get_delay(&s->common, n);
} else {
delay_ns = 0;
block_job_ratelimit_processed_bytes(&s->common, n);
}
}

Expand Down
1 change: 0 additions & 1 deletion block/create.c
Expand Up @@ -43,7 +43,6 @@ static int coroutine_fn blockdev_create_run(Job *job, Error **errp)
int ret;

GLOBAL_STATE_CODE();
GRAPH_RDLOCK_GUARD();

job_progress_set_remaining(&s->common, 1);
ret = s->drv->bdrv_co_create(s->opts, errp);
Expand Down
25 changes: 12 additions & 13 deletions block/crypto.c
Expand Up @@ -99,12 +99,10 @@ struct BlockCryptoCreateData {
};


static int block_crypto_create_write_func(QCryptoBlock *block,
size_t offset,
const uint8_t *buf,
size_t buflen,
void *opaque,
Error **errp)
static int coroutine_fn GRAPH_UNLOCKED
block_crypto_create_write_func(QCryptoBlock *block, size_t offset,
const uint8_t *buf, size_t buflen, void *opaque,
Error **errp)
{
struct BlockCryptoCreateData *data = opaque;
ssize_t ret;
Expand All @@ -117,10 +115,9 @@ static int block_crypto_create_write_func(QCryptoBlock *block,
return 0;
}

static int block_crypto_create_init_func(QCryptoBlock *block,
size_t headerlen,
void *opaque,
Error **errp)
static int coroutine_fn GRAPH_UNLOCKED
block_crypto_create_init_func(QCryptoBlock *block, size_t headerlen,
void *opaque, Error **errp)
{
struct BlockCryptoCreateData *data = opaque;
Error *local_error = NULL;
Expand Down Expand Up @@ -314,7 +311,7 @@ static int block_crypto_open_generic(QCryptoBlockFormat format,
}


static int coroutine_fn
static int coroutine_fn GRAPH_UNLOCKED
block_crypto_co_create_generic(BlockDriverState *bs, int64_t size,
QCryptoBlockCreateOptions *opts,
PreallocMode prealloc, Error **errp)
Expand Down Expand Up @@ -627,7 +624,7 @@ static int block_crypto_open_luks(BlockDriverState *bs,
bs, options, flags, errp);
}

static int coroutine_fn
static int coroutine_fn GRAPH_UNLOCKED
block_crypto_co_create_luks(BlockdevCreateOptions *create_options, Error **errp)
{
BlockdevCreateOptionsLUKS *luks_opts;
Expand Down Expand Up @@ -665,7 +662,7 @@ block_crypto_co_create_luks(BlockdevCreateOptions *create_options, Error **errp)
return ret;
}

static int coroutine_fn GRAPH_RDLOCK
static int coroutine_fn GRAPH_UNLOCKED
block_crypto_co_create_opts_luks(BlockDriver *drv, const char *filename,
QemuOpts *opts, Error **errp)
{
Expand Down Expand Up @@ -727,7 +724,9 @@ block_crypto_co_create_opts_luks(BlockDriver *drv, const char *filename,
* beforehand, it has been truncated and corrupted in the process.
*/
if (ret) {
bdrv_graph_co_rdlock();
bdrv_co_delete_file_noerr(bs);
bdrv_graph_co_rdunlock();
}

bdrv_co_unref(bs);
Expand Down
6 changes: 4 additions & 2 deletions block/export/export.c
Expand Up @@ -192,8 +192,10 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp)
return exp;

fail:
blk_set_dev_ops(exp->blk, NULL, NULL);
blk_unref(blk);
if (blk) {
blk_set_dev_ops(blk, NULL, NULL);
blk_unref(blk);
}
aio_context_release(ctx);
if (exp) {
g_free(exp->id);
Expand Down
10 changes: 0 additions & 10 deletions block/graph-lock.c
Expand Up @@ -162,11 +162,6 @@ void coroutine_fn bdrv_graph_co_rdlock(void)
BdrvGraphRWlock *bdrv_graph;
bdrv_graph = qemu_get_current_aio_context()->bdrv_graph;

/* Do not lock if in main thread */
if (qemu_in_main_thread()) {
return;
}

for (;;) {
qatomic_set(&bdrv_graph->reader_count,
bdrv_graph->reader_count + 1);
Expand Down Expand Up @@ -230,11 +225,6 @@ void coroutine_fn bdrv_graph_co_rdunlock(void)
BdrvGraphRWlock *bdrv_graph;
bdrv_graph = qemu_get_current_aio_context()->bdrv_graph;

/* Do not lock if in main thread */
if (qemu_in_main_thread()) {
return;
}

qatomic_store_release(&bdrv_graph->reader_count,
bdrv_graph->reader_count - 1);
/* make sure writer sees reader_count before we check has_writer */
Expand Down
23 changes: 10 additions & 13 deletions block/mirror.c
Expand Up @@ -471,12 +471,11 @@ static unsigned mirror_perform(MirrorBlockJob *s, int64_t offset,
return bytes_handled;
}

static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s)
static void coroutine_fn mirror_iteration(MirrorBlockJob *s)
{
BlockDriverState *source = s->mirror_top_bs->backing->bs;
MirrorOp *pseudo_op;
int64_t offset;
uint64_t delay_ns = 0, ret = 0;
/* At least the first dirty chunk is mirrored in one iteration. */
int nb_chunks = 1;
bool write_zeroes_ok = bdrv_can_write_zeroes_with_unmap(blk_bs(s->target));
Expand Down Expand Up @@ -608,16 +607,13 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s)
assert(io_bytes);
offset += io_bytes;
nb_chunks -= DIV_ROUND_UP(io_bytes, s->granularity);
delay_ns = block_job_ratelimit_get_delay(&s->common, io_bytes_acct);
block_job_ratelimit_processed_bytes(&s->common, io_bytes_acct);
}

ret = delay_ns;
fail:
QTAILQ_REMOVE(&s->ops_in_flight, pseudo_op, next);
qemu_co_queue_restart_all(&pseudo_op->waiting_requests);
g_free(pseudo_op);

return ret;
}

static void mirror_free_init(MirrorBlockJob *s)
Expand Down Expand Up @@ -1011,7 +1007,6 @@ static int coroutine_fn mirror_run(Job *job, Error **errp)
assert(!s->dbi);
s->dbi = bdrv_dirty_iter_new(s->dirty_bitmap);
for (;;) {
uint64_t delay_ns = 0;
int64_t cnt, delta;
bool should_complete;

Expand Down Expand Up @@ -1051,7 +1046,7 @@ static int coroutine_fn mirror_run(Job *job, Error **errp)
mirror_wait_for_free_in_flight_slot(s);
continue;
} else if (cnt != 0) {
delay_ns = mirror_iteration(s);
mirror_iteration(s);
}
}

Expand Down Expand Up @@ -1114,12 +1109,14 @@ static int coroutine_fn mirror_run(Job *job, Error **errp)
}

if (job_is_ready(&s->common.job) && !should_complete) {
delay_ns = (s->in_flight == 0 &&
cnt == 0 ? BLOCK_JOB_SLICE_TIME : 0);
if (s->in_flight == 0 && cnt == 0) {
trace_mirror_before_sleep(s, cnt, job_is_ready(&s->common.job),
BLOCK_JOB_SLICE_TIME);
job_sleep_ns(&s->common.job, BLOCK_JOB_SLICE_TIME);
}
} else {
block_job_ratelimit_sleep(&s->common);
}
trace_mirror_before_sleep(s, cnt, job_is_ready(&s->common.job),
delay_ns);
job_sleep_ns(&s->common.job, delay_ns);
s->last_pause_ns = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
}

Expand Down
6 changes: 3 additions & 3 deletions block/parallels.c
Expand Up @@ -522,8 +522,8 @@ parallels_co_check(BlockDriverState *bs, BdrvCheckResult *res,
}


static int coroutine_fn parallels_co_create(BlockdevCreateOptions* opts,
Error **errp)
static int coroutine_fn GRAPH_UNLOCKED
parallels_co_create(BlockdevCreateOptions* opts, Error **errp)
{
BlockdevCreateOptionsParallels *parallels_opts;
BlockDriverState *bs;
Expand Down Expand Up @@ -622,7 +622,7 @@ static int coroutine_fn parallels_co_create(BlockdevCreateOptions* opts,
goto out;
}

static int coroutine_fn GRAPH_RDLOCK
static int coroutine_fn GRAPH_UNLOCKED
parallels_co_create_opts(BlockDriver *drv, const char *filename,
QemuOpts *opts, Error **errp)
{
Expand Down
6 changes: 3 additions & 3 deletions block/qcow.c
Expand Up @@ -800,8 +800,8 @@ static void qcow_close(BlockDriverState *bs)
error_free(s->migration_blocker);
}

static int coroutine_fn qcow_co_create(BlockdevCreateOptions *opts,
Error **errp)
static int coroutine_fn GRAPH_UNLOCKED
qcow_co_create(BlockdevCreateOptions *opts, Error **errp)
{
BlockdevCreateOptionsQcow *qcow_opts;
int header_size, backing_filename_len, l1_size, shift, i;
Expand Down Expand Up @@ -921,7 +921,7 @@ static int coroutine_fn qcow_co_create(BlockdevCreateOptions *opts,
return ret;
}

static int coroutine_fn GRAPH_RDLOCK
static int coroutine_fn GRAPH_UNLOCKED
qcow_co_create_opts(BlockDriver *drv, const char *filename,
QemuOpts *opts, Error **errp)
{
Expand Down

0 comments on commit ce7edea

Please sign in to comment.