Block layer patches
The following changes since commit 53ef8a92eb04ee19640f5aad3bff36cd4a36c250:
Merge remote-tracking branch 'remotes/pmaydell/tags/pull-target-arm-20200406' into staging (2020-04-06 12:36:45 +0100)
are available in the Git repository at:
git://repo.or.cz/qemu/kevin.git tags/for-upstream
for you to fetch changes up to 3f6de653b946fe849330208becf79d6af7e876cb:
vpc: Don't round up already aligned BAT sizes (2020-04-07 15:42:08 +0200)
----------------------------------------------------------------
Block layer patches:
- Fix crashes and hangs related to iothreads, bdrv_drain and block jobs:
- Fix some AIO context locking in jobs
- Fix blk->in_flight during blk_wait_while_drained()
- vpc: Don't round up already aligned BAT sizes
----------------------------------------------------------------
Kevin Wolf (4):
block-backend: Reorder flush/pdiscard function definitions
block: Increase BB.in_flight for coroutine and sync interfaces
block: Fix blk->in_flight during blk_wait_while_drained()
vpc: Don't round up already aligned BAT sizes
Stefan Reiter (3):
job: take each job's lock individually in job_txn_apply
replication: assert we own context before job_cancel_sync
backup: don't acquire aio_context in backup_clean
include/sysemu/block-backend.h | 1 - block/backup.c | 4 - block/block-backend.c | 206 +++++++++++++++++++++++++---------------- block/replication.c | 5 +- block/vpc.c | 2 +- blockdev.c | 9 ++ job-qmp.c | 9 ++ job.c | 50 ++++++++-- tests/test-blockjob.c | 2 + 9 files changed, 193 insertions(+), 95 deletions(-)
[PULL 3/7] backup: don't acquire aio_context in backup_clean
From: Stefan Reiter <[email protected]>
All code-paths leading to backup_clean (via job_clean) have the job's context already acquired. The job's context is guaranteed to be the same as the one used by backup_top via backup_job_create.
Since the previous logic effectively acquired the lock twice, this broke cleanup of backups for disks using IO threads, since the BDRV_POLL_WHILE in bdrv_backup_top_drop -> bdrv_do_drained_begin would only release the lock once, thus deadlocking with the IO thread.
This is a partial revert of 0abf2581717a19.
Message-Id: <[email protected]>
--- block/backup.c | 4 ---- 1 file changed, 4 deletions(-)
block/backup.c +0 -4
@@ -126,11 +126,7 @@ static void backup_abort(Job *job)static void backup_clean (Job *job) {BackupBlockJob *s =container_of (job, BackupBlockJob, common.job); -AioContext *aio_context =bdrv_get_aio_context (s->backup_top); - -aio_context_acquire (aio_context);bdrv_backup_top_drop (s->backup_top); -aio_context_release (aio_context); }void backup_do_checkpoint (BlockJob *job,Error **errp)
Signature · 1 line
2.20.1
[PULL 6/7] block: Fix blk->in_flight during blk_wait_while_drained()
In reply to Kevin WolfWaiting in blk_wait_while_drained() while blk->in_flight is increased for the current request is wrong because it will cause the drain operation to deadlock.
This patch makes sure that blk_wait_while_drained() is called with blk->in_flight increased exactly once for the current request, and that it temporarily decreases the counter while it waits.
Message-Id: <[email protected]>
--- block/block-backend.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-)
block/block-backend.c +5 -12
@@ -1140,10 +1140,15 @@ static int blk_check_byte_request(BlockBackend *blk, int64_t offset,return 0 ; } +/* To be called between exactly one pair of blk_inc/dec_in_flight() */ static void coroutine_fn blk_wait_while_drained(BlockBackend *blk) { +assert (blk->in_flight >0 ); +if (blk->quiesce_counter && !blk->disable_request_queuing) { +blk_dec_in_flight (blk);qemu_co_queue_wait (&blk->queued_requests,NULL ); +blk_inc_in_flight (blk); } }
@@ -1418,12 +1423,6 @@ static void blk_aio_read_entry(void *opaque)BlkRwCo *rwco = &acb->rwco;QEMUIOVector *qiov = rwco->iobuf; -if (rwco->blk->quiesce_counter) { -blk_dec_in_flight (rwco->blk); -blk_wait_while_drained (rwco->blk); -blk_inc_in_flight (rwco->blk); - } -assert (qiov->size == acb->bytes); rwco->ret =blk_do_preadv (rwco->blk, rwco->offset, acb->bytes, qiov, rwco->flags);
@@ -1436,12 +1435,6 @@ static void blk_aio_write_entry(void *opaque)BlkRwCo *rwco = &acb->rwco;QEMUIOVector *qiov = rwco->iobuf; -if (rwco->blk->quiesce_counter) { -blk_dec_in_flight (rwco->blk); -blk_wait_while_drained (rwco->blk); -blk_inc_in_flight (rwco->blk); - } -assert (!qiov || qiov->size == acb->bytes); rwco->ret =blk_do_pwritev_part (rwco->blk, rwco->offset, acb->bytes, qiov,0 , rwco->flags);
Signature · 1 line
2.20.1
[PULL 2/7] replication: assert we own context before job_cancel_sync
In reply to Kevin WolfFrom: Stefan Reiter <[email protected]>
job_cancel_sync requires the job's lock to be held, all other callers already do this (replication_stop, drive_backup_abort, blockdev_backup_abort, job_cancel_sync_all, cancel_common).
In this case we're in a BlockDriver handler, so we already have a lock, just assert that it is the same as the one used for the commit_job.
Message-Id: <[email protected]>
--- block/replication.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
block/replication.c +4 -1
@@ -144,12 +144,15 @@ fail:static void replication_close (BlockDriverState *bs) {BDRVReplicationState *s = bs->opaque; +Job *commit_job;if (s->stage ==BLOCK_REPLICATION_RUNNING ) {replication_stop (s->rs, false,NULL ); }if (s->stage ==BLOCK_REPLICATION_FAILOVER ) { -job_cancel_sync (&s->commit_job->job); + commit_job = &s->commit_job->job; +assert (commit_job->aio_context ==qemu_get_current_aio_context ()); +job_cancel_sync (commit_job); }if (s->mode ==REPLICATION_MODE_SECONDARY ) {
Signature · 1 line
2.20.1
[PULL 5/7] block: Increase BB.in_flight for coroutine and sync interfaces
In reply to Kevin WolfExternal callers of blk_co_*() and of the synchronous blk_*() functions don't currently increase the BlockBackend.in_flight counter, but calls from blk_aio_*() do, so there is an inconsistency whether the counter has been increased or not.
This patch moves the actual operations to static functions that can later know they will always be called with in_flight increased exactly once, even for external callers using the blk_co_*() coroutine interfaces.
If the public blk_co_*() interface is unused, remove it.
Message-Id: <[email protected]>
--- include/sysemu/block-backend.h | 1 - block/block-backend.c | 103 +++++++++++++++++++++++++-------- 2 files changed, 80 insertions(+), 24 deletions(-)
include/sysemu/block-backend.h +0 -1
@@ -171,7 +171,6 @@ BlockAIOCB *blk_aio_pdiscard(BlockBackend *blk, int64_t offset, int bytes, BlockCompletionFunc *cb, void *opaque);void blk_aio_cancel (BlockAIOCB *acb);void blk_aio_cancel_async (BlockAIOCB *acb); -int blk_co_ioctl (BlockBackend *blk,unsigned long int req,void *buf);int blk_ioctl (BlockBackend *blk,unsigned long int req,void *buf);BlockAIOCB *blk_aio_ioctl (BlockBackend *blk,unsigned long int req,void *buf,BlockCompletionFunc *cb,void *opaque);
block/block-backend.c +80 -23
219 lines not on this page · raw message
Signature · 1 line
2.20.1
[PULL 7/7] vpc: Don't round up already aligned BAT sizes
In reply to Kevin WolfAs reported on Launchpad, Azure apparently doesn't accept images for upload that are not both aligned to 1 MB blocks and have a BAT size that matches the image size exactly.
As far as I can tell, there is no real reason why we create a BAT that is one entry longer than necessary for aligned image sizes, so change that.
(Even though the condition is only mentioned as "should" in the spec and previous products accepted larger BATs - but we'll try to maintain compatibility with as many of Microsoft's ever-changing interpretations of the VHD spec as possible.)
Message-Id: <[email protected]>
--- block/vpc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/vpc.c +1 -1
@@ -835,7 +835,7 @@ static int create_dynamic_disk(BlockBackend *blk, uint8_t *buf,/* Write the footer (twice: at the beginning and at the end) */ block_size =0x200000 ; - num_bat_entries = (total_sectors + block_size /512 ) / (block_size /512 ); + num_bat_entries =DIV_ROUND_UP (total_sectors, block_size /512 ); ret =blk_pwrite (blk, offset, buf,HEADER_SIZE ,0 );if (ret <0 ) {
Signature · 1 line
2.20.1
[PULL 1/7] job: take each job's lock individually in job_txn_apply
In reply to Kevin WolfFrom: Stefan Reiter <[email protected]>
All callers of job_txn_apply hold a single job's lock, but different jobs within a transaction can have different contexts, thus we need to lock each one individually before applying the callback function.
Similar to job_completed_txn_abort this also requires releasing the caller's context before and reacquiring it after to avoid recursive locks which might break AIO_WAIT_WHILE in the callback. This is safe, since existing code would already have to take this into account, lest job_completed_txn_abort might have broken.
This also brings to light a different issue: When a callback function in job_txn_apply moves it's job to a different AIO context, callers will try to release the wrong lock (now that we re-acquire the lock correctly, previously it would just continue with the old lock, leaving the job unlocked for the rest of the return path). Fix this by not caching the job's context.
This is only necessary for qmp_block_job_finalize, qmp_job_finalize and job_exit, since everyone else calls through job_exit.
One test needed adapting, since it calls job_finalize directly, so it manually needs to acquire the correct context.
Message-Id: <[email protected]>
--- blockdev.c | 9 ++++++++ job-qmp.c | 9 ++++++++ job.c | 50 ++++++++++++++++++++++++++++++++++--------- tests/test-blockjob.c | 2 ++ 4 files changed, 60 insertions(+), 10 deletions(-)
blockdev.c +9 -0
@@ -3612,7 +3612,16 @@ void qmp_block_job_finalize(const char *id, Error **errp) }trace_qmp_block_job_finalize (job); +job_ref (&job->job);job_finalize (&job->job, errp); + +/* +* Job's context might have changed via job_finalize (and job_txn_apply +* automatically acquires the new one), so make sure we release the correct +* one. +*/ + aio_context =blk_get_aio_context (job->blk); +job_unref (&job->job);aio_context_release (aio_context); }
job-qmp.c +9 -0
@@ -114,7 +114,16 @@ void qmp_job_finalize(const char *id, Error **errp) }trace_qmp_job_finalize (job); +job_ref (job);job_finalize (job, errp); + +/* +* Job's context might have changed via job_finalize (and job_txn_apply +* automatically acquires the new one), so make sure we release the correct +* one. +*/ + aio_context = job->aio_context; +job_unref (job);aio_context_release (aio_context); }
job.c +40 -10
93 lines not on this page · raw message
tests/test-blockjob.c +2 -0
@@ -367,7 +367,9 @@ static void test_cancel_concluded(void)aio_poll (qemu_get_aio_context (), true);assert (job->status ==JOB_STATUS_PENDING ); +aio_context_acquire (job->aio_context);job_finalize (job, &error_abort); +aio_context_release (job->aio_context);assert (job->status ==JOB_STATUS_CONCLUDED );cancel_common (s);
Signature · 1 line
2.20.1
[PULL 4/7] block-backend: Reorder flush/pdiscard function definitions
In reply to Kevin WolfMove all variants of the flush/pdiscard functions to a single place and put the blk_co_*() version first because it is called by all other variants (and will become static in the next patch).
Message-Id: <[email protected]>
--- block/block-backend.c | 92 +++++++++++++++++++++---------------------- 1 file changed, 46 insertions(+), 46 deletions(-)
block/block-backend.c +46 -46
@@ -1488,38 +1488,6 @@ BlockAIOCB *blk_aio_pwritev(BlockBackend *blk, int64_t offset, blk_aio_write_entry, flags, cb, opaque); } -static void blk_aio_flush_entry (void *opaque) -{ -BlkAioEmAIOCB *acb = opaque; -BlkRwCo *rwco = &acb->rwco; - - rwco->ret =blk_co_flush (rwco->blk); -blk_aio_complete (acb); -} - -BlockAIOCB *blk_aio_flush (BlockBackend *blk, -BlockCompletionFunc *cb,void *opaque) -{ -return blk_aio_prwv (blk,0 ,0 ,NULL , blk_aio_flush_entry,0 , cb, opaque); -} - -static void blk_aio_pdiscard_entry (void *opaque) -{ -BlkAioEmAIOCB *acb = opaque; -BlkRwCo *rwco = &acb->rwco; - - rwco->ret =blk_co_pdiscard (rwco->blk, rwco->offset, acb->bytes); -blk_aio_complete (acb); -} - -BlockAIOCB *blk_aio_pdiscard (BlockBackend *blk, -int64_t offset,int bytes, -BlockCompletionFunc *cb,void *opaque) -{ -return blk_aio_prwv (blk, offset, bytes,NULL , blk_aio_pdiscard_entry,0 , - cb, opaque); -} -void blk_aio_cancel (BlockAIOCB *acb) {bdrv_aio_cancel (acb);
@@ -1586,6 +1554,37 @@ int blk_co_pdiscard(BlockBackend *blk, int64_t offset, int bytes)return bdrv_co_pdiscard (blk->root, offset, bytes); } +static void blk_aio_pdiscard_entry (void *opaque) +{ +BlkAioEmAIOCB *acb = opaque; +BlkRwCo *rwco = &acb->rwco; + + rwco->ret =blk_co_pdiscard (rwco->blk, rwco->offset, acb->bytes); +blk_aio_complete (acb); +} + +BlockAIOCB *blk_aio_pdiscard (BlockBackend *blk, +int64_t offset,int bytes, +BlockCompletionFunc *cb,void *opaque) +{ +return blk_aio_prwv (blk, offset, bytes,NULL , blk_aio_pdiscard_entry,0 , + cb, opaque); +} + +static void blk_pdiscard_entry (void *opaque) +{ +BlkRwCo *rwco = opaque; +QEMUIOVector *qiov = rwco->iobuf; + + rwco->ret =blk_co_pdiscard (rwco->blk, rwco->offset, qiov->size); +aio_wait_kick (); +} + +int blk_pdiscard (BlockBackend *blk,int64_t offset,int bytes) +{ +return blk_prw (blk, offset,NULL , bytes, blk_pdiscard_entry,0 ); +} +int blk_co_flush (BlockBackend *blk) {blk_wait_while_drained (blk);
@@ -1597,6 +1596,21 @@ int blk_co_flush(BlockBackend *blk)return bdrv_co_flush (blk_bs (blk)); } +static void blk_aio_flush_entry (void *opaque) +{ +BlkAioEmAIOCB *acb = opaque; +BlkRwCo *rwco = &acb->rwco; + + rwco->ret =blk_co_flush (rwco->blk); +blk_aio_complete (acb); +} + +BlockAIOCB *blk_aio_flush (BlockBackend *blk, +BlockCompletionFunc *cb,void *opaque) +{ +return blk_aio_prwv (blk,0 ,0 ,NULL , blk_aio_flush_entry,0 , cb, opaque); +} +static void blk_flush_entry (void *opaque) {BlkRwCo *rwco = opaque;
@@ -2083,20 +2097,6 @@ int blk_truncate(BlockBackend *blk, int64_t offset, bool exact,return bdrv_truncate (blk->root, offset, exact, prealloc, errp); } -static void blk_pdiscard_entry (void *opaque) -{ -BlkRwCo *rwco = opaque; -QEMUIOVector *qiov = rwco->iobuf; - - rwco->ret =blk_co_pdiscard (rwco->blk, rwco->offset, qiov->size); -aio_wait_kick (); -} - -int blk_pdiscard (BlockBackend *blk,int64_t offset,int bytes) -{ -return blk_prw (blk, offset,NULL , bytes, blk_pdiscard_entry,0 ); -} -int blk_save_vmstate (BlockBackend *blk,const uint8_t *buf,int64_t pos,int size) {
Signature · 1 line
2.20.1
Peter Maydell
AppliedQuoted 16 lines · Kevin Wolf
The following changes since commit
53ef8a92eb04ee19640f5aad3bff36cd4a36c250:Merge remote-tracking branch 'remotes/pmaydell/tags/pull-target-arm-20200406' into staging (2020-04-06 12:36:45 +0100)
are available in the Git repository at:
git://repo.or.cz/qemu/kevin.gittags/for-upstreamfor you to fetch changes up to
3f6de653b946fe849330208becf79d6af7e876cb:vpc: Don't round up already aligned BAT sizes (2020-04-07 15:42:08 +0200)
----------------------------------------------------------------
Block layer patches:
Quoted 6 lines
- Fix crashes and hangs related to iothreads,
bdrv_drainand block jobs:
- Fix some AIO context locking in jobs
- Fixblk->in_flightduringblk_wait_while_drained()
- vpc: Don't round up already aligned BAT sizes----------------------------------------------------------------
Applied, thanks.
Please update the changelog at https://wiki.qemu.org/ChangeLog/5.0
for any user-visible changes.
-- PMM