Skip to contentSkip to conversation

mirror: restore offset after zeroing out the image

PATCH In review Denis V. Lunev 3 participants 4 messages Jan 30, 2017 – Jan 31, 2017 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mirror: restore offset after zeroing out the image

If explicit zeroing out before mirroring is required for the target image, it moves the block job offset counter to EOF, then offset and len counters count the image size twice.

There is no harm but confusing stats (e.g. for 1G image the completion counter starts from 1G and increases to 2G)

The patch fixed that problem by resetting the offset counter.

---
 block/mirror.c             | 3 +++
 tests/qemu-iotests/094.out | 4 ++--
 2 files changed, 5 insertions(+), 2 deletions(-)
block/mirror.c +3 -0
index 301ba92..94915e8 100644
@@ -587,6 +587,9 @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJob *s)
         }
 
         mirror_wait_for_all_io(s);
+
+        /* offset has moved to EOF, restore it */
+        s->common.offset = 0;
     }
 
     /* First part, loop on the sectors and initialize the dirty bitmap.  */
tests/qemu-iotests/094.out +2 -2
index b66dc07..522a20c 100644
@@ -3,9 +3,9 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
 Formatting 'TEST_DIR/source.IMGFMT', fmt=IMGFMT size=67108864
 {"return": {}}
 {"return": {}}
-{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_READY", "data": {"device": "src", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}}
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_READY", "data": {"device": "src", "len": 0, "offset": 0, "speed": 0, "type": "mirror"}}
 {"return": {}}
-{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}}
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 0, "offset": 0, "speed": 0, "type": "mirror"}}
 {"return": {}}
 {"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "SHUTDOWN"}
 *** done
Signature · 1 line
2.7.4
#1 lore raw
Quoted 8 lines · Denis V. Lunev

If explicit zeroing out before mirroring is required for the target image, it moves the block job offset counter to EOF, then offset and len counters count the image size twice.

There is no harm but confusing stats (e.g. for 1G image the completion counter starts from 1G and increases to 2G)

The patch fixed that problem by resetting the offset counter.

Counters are explicitly documented NOT tied to disk length; they are merely estimates of proportional completion. I'm not sure if this makes the numbers jump backwards from the observer's viewpoint, but if you can ever spot 1g/1g right before rewinding to 0g/1g (where pre-patch could see 1g/2g), then that is a reason to not take this patch. On the other hand, your argument that the pre-patch behavior progressing towards 2g has a very fast progression from 0-1g/2g, and then a much slower 1g-2g/2g, which makes the estimate of percent completion skewed, while a newer progression of 0-1g/1g is more realistic, may have some merit.

I'm not sold on this patch yet, but stronger arguments in the commit message may sway me.

tests/qemu-iotests/094.out Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 · line 7

Quoted 8 lines

+++ b/tests/qemu-iotests/094.out

tests/qemu-iotests/094.out +1 -1
@@ -3,9 +3,9 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
 Formatting 'TEST_DIR/source.IMGFMT', fmt=IMGFMT size=67108864
 {"return": {}}
 {"return": {}}
-{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_READY", "data": {"device": "src", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}}
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_READY", "data": {"device": "src", "len": 0, "offset": 0, "speed": 0, "type": "mirror"}}
 {"return": {}}

This part of the change is scary - a ready event showing 0/0 HAS been known to confuse libvirt in the past. Qemu should NEVER advertise a ready event with 0/0, it should at least be 1/1 (because of the number of clients that have workarounds to deal with older qemu behavior on 0/0 and which might misbehave if we ever issue that again).

tests/qemu-iotests/094.out Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 · line 8

Quoted 2 lines
tests/qemu-iotests/094.out +1 -1
-{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}}
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 0, "offset": 0, "speed": 0, "type": "mirror"}}

So NACK to the patch as currently written, but not necessarily to the idea if you can give better progress numbers and never reach the state of BLOCK_JOB_READY and BLOCK_JOB_COMPLETED with a 0/0 length/offset.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#2 lore raw
Quoted 36 lines · Eric Blake
Quoted 8 lines · Denis V. Lunev

If explicit zeroing out before mirroring is required for the target image, it moves the block job offset counter to EOF, then offset and len counters count the image size twice.

There is no harm but confusing stats (e.g. for 1G image the completion counter starts from 1G and increases to 2G)

The patch fixed that problem by resetting the offset counter.

Counters are explicitly documented NOT tied to disk length; they are merely estimates of proportional completion. I'm not sure if this makes the numbers jump backwards from the observer's viewpoint, but if you can ever spot 1g/1g right before rewinding to 0g/1g (where pre-patch could see 1g/2g), then that is a reason to not take this patch. On the other hand, your argument that the pre-patch behavior progressing towards 2g has a very fast progression from 0-1g/2g, and then a much slower 1g-2g/2g, which makes the estimate of percent completion skewed, while a newer progression of 0-1g/1g is more realistic, may have some merit.

I'm not sold on this patch yet, but stronger arguments in the commit message may sway me.

tests/qemu-iotests/094.out Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 · line 7

Quoted 8 lines

+++ b/tests/qemu-iotests/094.out

tests/qemu-iotests/094.out +1 -1
@@ -3,9 +3,9 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
 Formatting 'TEST_DIR/source.IMGFMT', fmt=IMGFMT size=67108864
 {"return": {}}
 {"return": {}}
-{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_READY", "data": {"device": "src", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}}
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_READY", "data": {"device": "src", "len": 0, "offset": 0, "speed": 0, "type": "mirror"}}
 {"return": {}}

This part of the change is scary - a ready event showing 0/0 HAS been known to confuse libvirt in the past. Qemu should NEVER advertise a ready event with 0/0, it should at least be 1/1 (because of the number of clients that have workarounds to deal with older qemu behavior on 0/0 and which might misbehave if we ever issue that again).

Quoted 6 lines

tests/qemu-iotests/094.out Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 · line 8

Quoted 2 lines
tests/qemu-iotests/094.out +1 -1
-{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}}
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 0, "offset": 0, "speed": 0, "type": "mirror"}}

So NACK to the patch as currently written, but not necessarily to the idea if you can give better progress numbers and never reach the state of BLOCK_JOB_READY and BLOCK_JOB_COMPLETED with a 0/0 length/offset.

ok. fair enough. Thank you for the review.

Will it be better to (somehow) skip progressing below using some condition during mirror_dirty_init() stage?

static void mirror_iteration_done(MirrorOp *op, int ret)

{
    .....

    if (ret >= 0) {
        if (s->cow_bitmap) {
            bitmap_set(s->cow_bitmap, chunk_num, nb_chunks);
        }
        s->common.offset += (uint64_t)op->nb_sectors * BDRV_SECTOR_SIZE;
<---- specifically this progressing
    }

Den

#3 lore raw
Quoted 9 lines · Denis V. Lunev
Quoted 8 lines · Eric Blake
Quoted 7 lines · Denis V. Lunev

If explicit zeroing out before mirroring is required for the target image, it moves the block job offset counter to EOF, then offset and len counters count the image size twice.

There is no harm but confusing stats (e.g. for 1G image the completion counter starts from 1G and increases to 2G)

Quoted 6 lines
Quoted 6 lines
Quoted 1 line

The patch fixed that problem by resetting the offset counter.

Counters are explicitly documented NOT tied to disk length; they are merely estimates of proportional completion. I'm not sure if this makes the numbers jump backwards from the observer's viewpoint, but if you can ever spot 1g/1g right before rewinding to 0g/1g (where pre-patch could see 1g/2g), then that is a reason to not take this patch.

FWIW you'll actually see 1g/0g first (if you happen to catch that tiny phase :)

Quoted 9 lines
Quoted 9 lines

On the other
hand, your argument that the pre-patch behavior progressing towards 2g has a very fast progression from 0-1g/2g, and then a much slower 1g-2g/2g, which makes the estimate of percent completion skewed, while a newer progression of 0-1g/1g is more realistic, may have some merit.

I'm not sold on this patch yet, but stronger arguments in the commit message may sway me.

Quoted 13 lines
Quoted 5 lines
Quoted 5 lines

+++ b/tests/qemu-iotests/094.out

tests/qemu-iotests/094.out +0 -0
@@ -3,9 +3,9 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
 Formatting 'TEST_DIR/source.IMGFMT', fmt=IMGFMT size=67108864
 {"return": {}}
 {"return": {}}
Quoted 8 lines

tests/qemu-iotests/094.out Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 · line 7

Quoted 3 lines
tests/qemu-iotests/094.out +1 -1
-{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_READY", "data": {"device": "src", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}}
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_READY", "data": {"device": "src", "len": 0, "offset": 0, "speed": 0, "type": "mirror"}}
 {"return": {}}

This part of the change is scary - a ready event showing 0/0 HAS been known to confuse libvirt in the past. Qemu should NEVER advertise a ready event with 0/0, it should at least be 1/1 (because of the number of clients that have workarounds to deal with older qemu behavior on 0/0 and which might misbehave if we ever issue that again).

I think this 094.out modification is not needed and actually breaks the test; apologies

Quoted 13 lines
Quoted 7 lines

tests/qemu-iotests/094.out Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 · line 8

Quoted 3 lines
tests/qemu-iotests/094.out +1 -1
-{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}}
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 0, "offset": 0, "speed": 0, "type": "mirror"}}

So NACK to the patch as currently written, but not necessarily to the idea if you can give better progress numbers and never reach the state of BLOCK_JOB_READY and BLOCK_JOB_COMPLETED with a 0/0 length/offset.

ok. fair enough. Thank you for the review.

Will it be better to (somehow) skip progressing below using some condition during mirror_dirty_init() stage?

static void mirror_iteration_done(MirrorOp *op, int ret)

Quoted 11 lines
{
    .....

    if (ret >= 0) {
        if (s->cow_bitmap) {
            bitmap_set(s->cow_bitmap, chunk_num, nb_chunks);
        }
        s->common.offset += (uint64_t)op->nb_sectors * BDRV_SECTOR_SIZE;
<---- specifically this progressing
    }

Isn't this going to look quite too invasive for such cause

Signature · 2 lines
best regards,
Anton