Skip to contentSkip to conversation

potentially broken drive-mirror/drive-backup in bdrv_co_discard

PATCH Applied Denis V. Lunev 4 participants 7 messages Jun 16, 2016 – Jun 17, 2016 Block layer

lore
Share & tools
lore
#0 lore raw

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
#1 lore raw

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
index fb99a71..aca175e 100644
@@ -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
Reviewed-by on v2 1/3
#2 lore raw

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.

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
#3 lore raw

PATCH v2 2/3 block: fix race in bdrv_co_discard with drive-mirror

In reply to Denis V. Lunev

Actually 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
index aca175e..11fcfcb 100644
@@ -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
#4 lore raw

PATCH v2 3/3 block: process before_write_notifiers in bdrv_co_discard

In reply to Denis V. Lunev

This 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
index 11fcfcb..2177cc6 100644
@@ -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
#5 lore raw
In reply to Denis V. Lunev
Quoted 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_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

Quoted 7 lines

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(-)

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

Reviewed-by on the v2 series
#6 lore raw
In reply to Denis V. Lunev

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_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

Quoted 6 lines