qemu-e2k/include/block
Evgeny Yakovlev ce83ee57f6 block: fix deadlock in bdrv_co_flush
The following commit
    commit 3ff2f67a7c
    Author: Evgeny Yakovlev <eyakovlev@virtuozzo.com>
    Date:   Mon Jul 18 22:39:52 2016 +0300
    block: ignore flush requests when storage is clean
has introduced a regression.

There is a problem that it is still possible for 2 requests to execute
in non sequential fashion and sometimes this results in a deadlock
when bdrv_drain_one/all are called for BDS with such stalled requests.

1. Current flushed_gen and flush_started_gen is 1.
2. Request 1 enters bdrv_co_flush to with write_gen 1 (i.e. the same
   as flushed_gen). It gets past flushed_gen != flush_started_gen and
   sets flush_started_gen to 1 (again, the same it was before).
3. Request 1 yields somewhere before exiting bdrv_co_flush
4. Request 2 enters bdrv_co_flush with write_gen 2. It gets past
   flushed_gen != flush_started_gen and sets flush_started_gen to 2.
5. Request 2 runs to completion and sets flushed_gen to 2
6. Request 1 is resumed, runs to completion and sets flushed_gen to 1.
   However flush_started_gen is now 2.

From here on out flushed_gen is always != to flush_started_gen and all
further requests will wait on flush_queue. This change replaces
flush_started_gen with an explicitly tracked active flush request.

Signed-off-by: Evgeny Yakovlev <eyakovlev@virtuozzo.com>
Signed-off-by: Denis V. Lunev <den@openvz.org>
Message-id: 1471457214-3994-2-git-send-email-den@openvz.org
CC: Stefan Hajnoczi <stefanha@redhat.com>
CC: Fam Zheng <famz@redhat.com>
CC: Kevin Wolf <kwolf@redhat.com>
CC: Max Reitz <mreitz@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2016-08-18 14:36:49 +01:00
..
accounting.h Use scripts/clean-includes to drop redundant qemu/typedefs.h 2016-03-22 22:20:16 +01:00
aio.h AioContext: correct comments 2016-07-26 17:46:37 +02:00
block.h block: Convert bdrv_aio_discard() to byte-based 2016-07-20 14:11:55 +01:00
block_int.h block: fix deadlock in bdrv_co_flush 2016-08-18 14:36:49 +01:00
blockjob.h blockjob: Add 'job_id' parameter to block_job_create() 2016-07-13 13:26:02 +02:00
dirty-bitmap.h dirty-bitmap: operate with int64_t amount 2016-07-19 16:54:46 -04:00
nbd.h nbd: Limit nbdflags to 16 bits 2016-08-03 18:44:56 +02:00
qapi.h block/qapi: Use blk_enable_write_cache() 2016-03-30 12:16:02 +02:00
raw-aio.h linux-aio: share one LinuxAioState within an AioContext 2016-07-18 15:09:31 +01:00
scsi.h * SCSI scanner support 2016-07-14 13:44:06 +01:00
snapshot.h include: Clean up includes 2016-02-23 12:43:05 +00:00
thread-pool.h Clean up decorations and whitespace around header guards 2016-07-12 16:20:46 +02:00
throttle-groups.h block: Move I/O throttling configuration functions to BlockBackend 2016-05-19 16:45:30 +02:00
write-threshold.h Use scripts/clean-includes to drop redundant qemu/typedefs.h 2016-03-22 22:20:16 +01:00