mirror: Only mirror granularity-aligned chunks
PATCH v2 1/1 mirror: Only mirror granularity-aligned chunks
In write-blocking mode, all writes to the top node directly go to the target. We must only mirror chunks of data that are aligned to the job's granularity, because that is how the dirty bitmap works. Therefore, the request alignment for writes must be the job's granularity (in write-blocking mode).
Unfortunately, this forces all reads and writes to have the same granularity (we only need this alignment for writes to the target, not the source), but that is something to be fixed another time.
---
v2: Fix the placement of our bdrv_refresh_limits() call [Vladimir]
--- block/mirror.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
block/mirror.c +25 -0
@@ -1481,6 +1481,15 @@ static void bdrv_mirror_top_child_perm(BlockDriverState *bs, BdrvChild *c, *nshared =BLK_PERM_ALL ; } +static void bdrv_mirror_top_refresh_limits (BlockDriverState *bs,Error **errp) +{ +MirrorBDSOpaque *s = bs->opaque; + +if (s && s->job && s->job->copy_mode ==MIRROR_COPY_MODE_WRITE_BLOCKING ) { + bs->bl.request_alignment = s->job->granularity; + } +} +/* Dummy node that provides consistent read to its users without requiring it * from its backing file and that allows writes on the backing file chain. */ static BlockDriver bdrv_mirror_top = {
@@ -1493,6 +1502,7 @@ static BlockDriver bdrv_mirror_top = { .bdrv_co_block_status = bdrv_co_block_status_from_backing, .bdrv_refresh_filename = bdrv_mirror_top_refresh_filename, .bdrv_child_perm = bdrv_mirror_top_child_perm, + .bdrv_refresh_limits = bdrv_mirror_top_refresh_limits, }; static BlockJob *mirror_start_job(
@@ -1637,6 +1647,21 @@ static BlockJob *mirror_start_job( s->should_complete = true; } +/* +* Must be called before we start tracking writes, but after +* +* ((MirrorBlockJob *) +* ((MirrorBDSOpaque *) +* mirror_top_bs->opaque +* )->job +* )->copy_mode +* +* has the correct value. +* (We start tracking writes as of the following +* bdrv_create_dirty_bitmap() call.) +*/ +bdrv_refresh_limits (mirror_top_bs, &error_abort); + s->dirty_bitmap =bdrv_create_dirty_bitmap (bs, granularity,NULL , errp);if (!s->dirty_bitmap) { goto fail;
Signature · 1 line
2.21.0
Quoted 54 lines · Max Reitz
In write-blocking mode, all writes to the top node directly go to the target. We must only mirror chunks of data that are aligned to the job's granularity, because that is how the dirty bitmap works. Therefore, the request alignment for writes must be the job's granularity (in write-blocking mode).
Unfortunately, this forces all reads and writes to have the same granularity (we only need this alignment for writes to the target, not the source), but that is something to be fixed another time.
Signed-off-by Max Reitz <[email protected]>---
v2: Fix the placement of ourbdrv_refresh_limits()call [Vladimir]--- block/mirror.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)block/mirror.c +14
-0@@ -1481,6 +1481,15 @@ static void bdrv_mirror_top_child_perm(BlockDriverState *bs, BdrvChild *c, *nshared =BLK_PERM_ALL ; } +static void bdrv_mirror_top_refresh_limits (BlockDriverState *bs,Error **errp) +{ +MirrorBDSOpaque *s = bs->opaque; + +if (s && s->job && s->job->copy_mode ==MIRROR_COPY_MODE_WRITE_BLOCKING ) { + bs->bl.request_alignment = s->job->granularity; + } +} +/* Dummy node that provides consistent read to its users without requiring it * from its backing file and that allows writes on the backing file chain. */ static BlockDriver bdrv_mirror_top = {@@ -1493,6 +1502,7 @@ static BlockDriver bdrv_mirror_top = { .bdrv_co_block_status = bdrv_co_block_status_from_backing, .bdrv_refresh_filename = bdrv_mirror_top_refresh_filename, .bdrv_child_perm = bdrv_mirror_top_child_perm, + .bdrv_refresh_limits = bdrv_mirror_top_refresh_limits, }; static BlockJob *mirror_start_job(@@ -1637,6 +1647,21 @@ static BlockJob *mirror_start_job( s->should_complete = true; } +/* +* Must be called before we start tracking writes, but after +* +* ((MirrorBlockJob *)
block/mirror.c static BlockJob *mirror_start_job( · line 1663
Quoted 10 lines
block/mirror.c +10
-0+* ((MirrorBDSOpaque *) +* mirror_top_bs->opaque +* )->job +* )->copy_mode +* +* has the correct value. +* (We start tracking writes as of the following +* bdrv_create_dirty_bitmap() call.) +*/ +bdrv_refresh_limits (mirror_top_bs, &error_abort);
Also, I'm not sure about error_abort() here. why not use local_err and return NULL if failed?
Quoted 5 lines
block/mirror.c +1
-0+ s->dirty_bitmap =bdrv_create_dirty_bitmap (bs, granularity,NULL , errp);if (!s->dirty_bitmap) { goto fail;
Signature · 2 lines
Best regards, Vladimir
Quoted 60 lines · Vladimir Sementsov-Ogievskiy
Quoted 59 lines · Max Reitz
In write-blocking mode, all writes to the top node directly go to the target. We must only mirror chunks of data that are aligned to the job's granularity, because that is how the dirty bitmap works. Therefore, the request alignment for writes must be the job's granularity (in write-blocking mode).
Unfortunately, this forces all reads and writes to have the same granularity (we only need this alignment for writes to the target, not the source), but that is something to be fixed another time.
Signed-off-by Max Reitz <[email protected]>---
v2: Fix the placement of ourbdrv_refresh_limits()call [Vladimir]--- block/mirror.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)block/mirror.c +19
-0@@ -1481,6 +1481,15 @@ static void bdrv_mirror_top_child_perm(BlockDriverState *bs, BdrvChild *c, *nshared =BLK_PERM_ALL ; } +static void bdrv_mirror_top_refresh_limits (BlockDriverState *bs,Error **errp) +{ +MirrorBDSOpaque *s = bs->opaque; + +if (s && s->job && s->job->copy_mode ==MIRROR_COPY_MODE_WRITE_BLOCKING ) { + bs->bl.request_alignment = s->job->granularity; + } +} +/* Dummy node that provides consistent read to its users without requiring it * from its backing file and that allows writes on the backing file chain. */ static BlockDriver bdrv_mirror_top = {@@ -1493,6 +1502,7 @@ static BlockDriver bdrv_mirror_top = { .bdrv_co_block_status = bdrv_co_block_status_from_backing, .bdrv_refresh_filename = bdrv_mirror_top_refresh_filename, .bdrv_child_perm = bdrv_mirror_top_child_perm, + .bdrv_refresh_limits = bdrv_mirror_top_refresh_limits, }; static BlockJob *mirror_start_job(@@ -1637,6 +1647,21 @@ static BlockJob *mirror_start_job( s->should_complete = true; } +/* +* Must be called before we start tracking writes, but after +* +* ((MirrorBlockJob *) +* ((MirrorBDSOpaque *) +* mirror_top_bs->opaque +* )->job +* )->copy_mode +*
Quoted 8 lines
block/mirror.c static BlockJob *mirror_start_job( · line 1663
Quoted 5 lines
block/mirror.c +5
-0+* has the correct value. +* (We start tracking writes as of the following +* bdrv_create_dirty_bitmap() call.) +*/ +bdrv_refresh_limits (mirror_top_bs, &error_abort);Also, I'm not sure about
error_abort()here. why not uselocal_errand return NULL if failed?
Why would it fail?
Max
Quoted 7 lines
Quoted 5 lines
block/mirror.c +1
-0+ s->dirty_bitmap =bdrv_create_dirty_bitmap (bs, granularity,NULL , errp);if (!s->dirty_bitmap) { goto fail;
Quoted 70 lines · Max Reitz
Quoted 60 lines · Vladimir Sementsov-Ogievskiy
Quoted 59 lines · Max Reitz
In write-blocking mode, all writes to the top node directly go to the target. We must only mirror chunks of data that are aligned to the job's granularity, because that is how the dirty bitmap works. Therefore, the request alignment for writes must be the job's granularity (in write-blocking mode).
Unfortunately, this forces all reads and writes to have the same granularity (we only need this alignment for writes to the target, not the source), but that is something to be fixed another time.
Signed-off-by Max Reitz <[email protected]>---
v2: Fix the placement of ourbdrv_refresh_limits()call [Vladimir]--- block/mirror.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)block/mirror.c +19
-0@@ -1481,6 +1481,15 @@ static void bdrv_mirror_top_child_perm(BlockDriverState *bs, BdrvChild *c, *nshared =BLK_PERM_ALL ; } +static void bdrv_mirror_top_refresh_limits (BlockDriverState *bs,Error **errp) +{ +MirrorBDSOpaque *s = bs->opaque; + +if (s && s->job && s->job->copy_mode ==MIRROR_COPY_MODE_WRITE_BLOCKING ) { + bs->bl.request_alignment = s->job->granularity; + } +} +/* Dummy node that provides consistent read to its users without requiring it * from its backing file and that allows writes on the backing file chain. */ static BlockDriver bdrv_mirror_top = {@@ -1493,6 +1502,7 @@ static BlockDriver bdrv_mirror_top = { .bdrv_co_block_status = bdrv_co_block_status_from_backing, .bdrv_refresh_filename = bdrv_mirror_top_refresh_filename, .bdrv_child_perm = bdrv_mirror_top_child_perm, + .bdrv_refresh_limits = bdrv_mirror_top_refresh_limits, }; static BlockJob *mirror_start_job(@@ -1637,6 +1647,21 @@ static BlockJob *mirror_start_job( s->should_complete = true; } +/* +* Must be called before we start tracking writes, but after +* +* ((MirrorBlockJob *) +* ((MirrorBDSOpaque *) +* mirror_top_bs->opaque +* )->job +* )->copy_mode +* Quoted 8 lines
block/mirror.c static BlockJob *mirror_start_job( · line 1663
Quoted 5 lines
block/mirror.c +5
-0+* has the correct value. +* (We start tracking writes as of the following +* bdrv_create_dirty_bitmap() call.) +*/ +bdrv_refresh_limits (mirror_top_bs, &error_abort);Also, I'm not sure about
error_abort()here. why not uselocal_errand return NULL if failed?
Quoted 1 line
Why would it fail?
Ah. That’s why. Because the children can fail.
That is so stupid. Like, really.
Max