potentially broken drive-mirror/drive-backup in bdrv_co_discard
v2 cover potentially broken drive-mirror/drive-backup in bdrv_co_discard
Actually I have found this problem running iotest 132 for active async mirror I have sent yesturday. Anyway, the problem is actual for current backup/mirror implementation.
bdrv_co_discard must mark areas dirty after writing zeroes, it must call before_write_notifier chain to push underlying data to backup and it also must properly fill tracked request information.
Changes from v1:
- fixed problem in patch as pointed out by Vova
- ported to current (was made on top of active block mirror)
- minor spelling changes in commit messages
Denis V. Lunev (3):
block: fixed BdrvTrackedRequest filling in bdrv_co_discard
block: fix race in bdrv_co_discard with drive-mirror
block: process before_write_notifiers in bdrv_co_discard
block/io.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
Signature · 1 line
2.1.4
PATCH v2 1/3 block: fixed BdrvTrackedRequest filling in bdrv_co_discard
The request area is specified in bytes, not in sectors.
--- block/io.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
block/io.c +2 -2
@@ -2261,8 +2261,8 @@ int coroutine_fn bdrv_co_discard(BlockDriverState *bs, int64_t sector_num,return 0 ; } -tracked_request_begin (&req, bs, sector_num, nb_sectors, -BDRV_TRACKED_DISCARD ); +tracked_request_begin (&req, bs, sector_num <<BDRV_SECTOR_BITS , + nb_sectors <<BDRV_SECTOR_BITS ,BDRV_TRACKED_DISCARD );bdrv_set_dirty (bs, sector_num, nb_sectors); max_discard =MIN_NON_ZERO (bs->bl.max_discard,BDRV_REQUEST_MAX_SECTORS );
Signature · 1 line
2.1.4
Re: [Qemu-devel] [PATCH 1/3] block: fixed BdrvTrackedRequest filling in bdrv_co_discard
Quoted 8 lines · Denis V. Lunev
The request area is specified in bytes, not in sectors.
Signed-off-by Denis V. Lunev <[email protected]>Reviewed-by Vladimir Sementsov-Ogievskiy<[email protected]>Reviewed-by Fam Zheng <[email protected]>CC Stefan Hajnoczi <[email protected]>CC Kevin Wolf <[email protected]>CC Max Reitz <[email protected]>
Quoted 4 lines
--- block/io.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
[By the way, next on my list of sector-to-byte conversions is discard, so thanks for finding this first]
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH v2 2/3 block: fix race in bdrv_co_discard with drive-mirror
In reply to Denis V. LunevActually we must set dirty bitmap dirty after we have written all our zeroes for correct processing in drive mirror code. In the other case we can face not zeroes in this area in mirror_iteration.
--- block/io.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
block/io.c +2 -1
@@ -2263,7 +2263,6 @@ int coroutine_fn bdrv_co_discard(BlockDriverState *bs, int64_t sector_num,tracked_request_begin (&req, bs, sector_num <<BDRV_SECTOR_BITS , nb_sectors <<BDRV_SECTOR_BITS ,BDRV_TRACKED_DISCARD ); -bdrv_set_dirty (bs, sector_num, nb_sectors); max_discard =MIN_NON_ZERO (bs->bl.max_discard,BDRV_REQUEST_MAX_SECTORS );while (nb_sectors >0 ) {
@@ -2312,6 +2311,8 @@ int coroutine_fn bdrv_co_discard(BlockDriverState *bs, int64_t sector_num, } ret =0 ; out: +bdrv_set_dirty (bs, req.offset >>BDRV_SECTOR_BITS , + req.bytes >>BDRV_SECTOR_BITS );tracked_request_end (&req);return ret; }
Signature · 1 line
2.1.4
PATCH v2 3/3 block: process before_write_notifiers in bdrv_co_discard
In reply to Denis V. LunevThis is mandatory for correct backup creation. In the other case the content under this area would be lost.
Dirty bits are set exactly like in bdrv_aligned_pwritev, i.e. they are set even if notifier has returned a error.
--- block/io.c | 5 +++++ 1 file changed, 5 insertions(+)
block/io.c +5 -0
@@ -2264,6 +2264,11 @@ int coroutine_fn bdrv_co_discard(BlockDriverState *bs, int64_t sector_num,tracked_request_begin (&req, bs, sector_num <<BDRV_SECTOR_BITS , nb_sectors <<BDRV_SECTOR_BITS ,BDRV_TRACKED_DISCARD ); + ret =notifier_with_return_list_notify (&bs->before_write_notifiers, &req); +if (ret <0 ) { + goto out; + } + max_discard =MIN_NON_ZERO (bs->bl.max_discard,BDRV_REQUEST_MAX_SECTORS );while (nb_sectors >0 ) {int ret;
Signature · 1 line
2.1.4
Stefan Hajnoczi
AppliedQuoted 20 lines · Denis V. Lunev
Actually I have found this problem running iotest 132 for active async mirror I have sent yesturday. Anyway, the problem is actual for current backup/mirror implementation.
bdrv_co_discardmust mark areas dirty after writing zeroes, it must callbefore_write_notifierchain to push underlying data to backup and it also must properly fill tracked request information.Changes from v1:
- fixed problem in patch as pointed out by Vova
- ported to current (was made on top of active block mirror)
- minor spelling changes in commit messagesSigned-off-by Denis V. Lunev <[email protected]>Reviewed-by Vladimir Sementsov-Ogievskiy<[email protected]>Reviewed-by Fam Zheng <[email protected]>CC Stefan Hajnoczi <[email protected]>CC Kevin Wolf <[email protected]>CC Max Reitz <[email protected]>
Quoted 7 lines
Denis V. Lunev (3):
block: fixed BdrvTrackedRequest filling inbdrv_co_discard
block: fix race inbdrv_co_discardwith drive-mirror
block: processbefore_write_notifiersinbdrv_co_discardblock/io.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
Makes sense to me so I'm merging it provisionally instead of waiting for more reviews. If there are objections I will revert it so that discussion can continue.
Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block
Stefan
Am 16.06.2016 um 18:09 hat Denis V. Lunev geschrieben:
Quoted 13 lines
Actually I have found this problem running iotest 132 for active async mirror I have sent yesturday. Anyway, the problem is actual for current backup/mirror implementation.
bdrv_co_discardmust mark areas dirty after writing zeroes, it must callbefore_write_notifierchain to push underlying data to backup and it also must properly fill tracked request information.Changes from v1:
- fixed problem in patch as pointed out by Vova
- ported to current (was made on top of active block mirror)
- minor spelling changes in commit messages
Quoted 6 lines
Signed-off-by Denis V. Lunev <[email protected]>Reviewed-by Vladimir Sementsov-Ogievskiy<[email protected]>Reviewed-by Fam Zheng <[email protected]>CC Stefan Hajnoczi <[email protected]>CC Kevin Wolf <[email protected]>CC Max Reitz <[email protected]>