Skip to contentSkip to conversation

backup: Fail early if cannot determine cluster size

PATCH Superseded Fam Zheng 5 participants 8 messages May 18, 2016 – Jun 15, 2016 Block layer

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Fam Zheng

author
#0 lore raw

PATCH 1/1 backup: Fail early if cannot determine cluster size

Otherwise the job is orphaned and block_job_cancel_sync in bdrv_close_all() when quiting will hang.

A simple reproducer is running blockdev-backup from null-co:// to null-co://.

---
 block/backup.c | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)
block/backup.c +18 -16
index 491fd14..3ff48c6 100644
@@ -505,6 +505,7 @@ void backup_start(BlockDriverState *bs, BlockDriverState *target,
     int64_t len;
     BlockDriverInfo bdi;
     int ret;
+    int64_t cluster_size;
 
     assert(bs);
     assert(target);
@@ -568,23 +569,10 @@ void backup_start(BlockDriverState *bs, BlockDriverState *target,
         goto error;
     }
 
-    BackupBlockJob *job = block_job_create(&backup_job_driver, bs, speed,
-                                           cb, opaque, errp);
-    if (!job) {
-        goto error;
-    }
-
-    job->on_source_error = on_source_error;
-    job->on_target_error = on_target_error;
-    job->target = target;
-    job->sync_mode = sync_mode;
-    job->sync_bitmap = sync_mode == MIRROR_SYNC_MODE_INCREMENTAL ?
-                       sync_bitmap : NULL;
-
     /* If there is no backing file on the target, we cannot rely on COW if our
      * backup cluster size is smaller than the target cluster size. Even for
      * targets with a backing file, try to avoid COW if possible. */
-    ret = bdrv_get_info(job->target, &bdi);
+    ret = bdrv_get_info(target, &bdi);
     if (ret < 0 && !target->backing) {
         error_setg_errno(errp, -ret,
             "Couldn't determine the cluster size of the target image, "
@@ -594,11 +582,25 @@ void backup_start(BlockDriverState *bs, BlockDriverState *target,
         goto error;
     } else if (ret < 0 && target->backing) {
         /* Not fatal; just trudge on ahead. */
-        job->cluster_size = BACKUP_CLUSTER_SIZE_DEFAULT;
+        cluster_size = BACKUP_CLUSTER_SIZE_DEFAULT;
     } else {
-        job->cluster_size = MAX(BACKUP_CLUSTER_SIZE_DEFAULT, bdi.cluster_size);
+        cluster_size = MAX(BACKUP_CLUSTER_SIZE_DEFAULT, bdi.cluster_size);
     }
 
+    BackupBlockJob *job = block_job_create(&backup_job_driver, bs, speed,
+                                           cb, opaque, errp);
+    if (!job) {
+        goto error;
+    }
+
+    job->on_source_error = on_source_error;
+    job->on_target_error = on_target_error;
+    job->target = target;
+    job->sync_mode = sync_mode;
+    job->sync_bitmap = sync_mode == MIRROR_SYNC_MODE_INCREMENTAL ?
+                       sync_bitmap : NULL;
+    job->cluster_size = cluster_size;
+
     bdrv_op_block_all(target, job->common.blocker);
     job->common.len = len;
     job->common.co = qemu_coroutine_create(backup_run);
Signature · 1 line
2.8.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Fam Zheng

Otherwise the job is orphaned and block_job_cancel_sync in bdrv_close_all() when quiting will hang.

A simple reproducer is running blockdev-backup from null-co:// to null-co://.

Quoted 72 lines
---
 block/backup.c | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)
block/backup.c +18 -16
index 491fd14..3ff48c6 100644
@@ -505,6 +505,7 @@ void backup_start(BlockDriverState *bs, BlockDriverState *target,
     int64_t len;
     BlockDriverInfo bdi;
     int ret;
+    int64_t cluster_size;
 
     assert(bs);
     assert(target);
@@ -568,23 +569,10 @@ void backup_start(BlockDriverState *bs, BlockDriverState *target,
         goto error;
     }
 
-    BackupBlockJob *job = block_job_create(&backup_job_driver, bs, speed,
-                                           cb, opaque, errp);
-    if (!job) {
-        goto error;
-    }
-
-    job->on_source_error = on_source_error;
-    job->on_target_error = on_target_error;
-    job->target = target;
-    job->sync_mode = sync_mode;
-    job->sync_bitmap = sync_mode == MIRROR_SYNC_MODE_INCREMENTAL ?
-                       sync_bitmap : NULL;
-
     /* If there is no backing file on the target, we cannot rely on COW if our
      * backup cluster size is smaller than the target cluster size. Even for
      * targets with a backing file, try to avoid COW if possible. */
-    ret = bdrv_get_info(job->target, &bdi);
+    ret = bdrv_get_info(target, &bdi);
     if (ret < 0 && !target->backing) {
         error_setg_errno(errp, -ret,
             "Couldn't determine the cluster size of the target image, "
@@ -594,11 +582,25 @@ void backup_start(BlockDriverState *bs, BlockDriverState *target,
         goto error;
     } else if (ret < 0 && target->backing) {
         /* Not fatal; just trudge on ahead. */
-        job->cluster_size = BACKUP_CLUSTER_SIZE_DEFAULT;
+        cluster_size = BACKUP_CLUSTER_SIZE_DEFAULT;
     } else {
-        job->cluster_size = MAX(BACKUP_CLUSTER_SIZE_DEFAULT, bdi.cluster_size);
+        cluster_size = MAX(BACKUP_CLUSTER_SIZE_DEFAULT, bdi.cluster_size);
     }
 
+    BackupBlockJob *job = block_job_create(&backup_job_driver, bs, speed,
+                                           cb, opaque, errp);
+    if (!job) {
+        goto error;
+    }
+
+    job->on_source_error = on_source_error;
+    job->on_target_error = on_target_error;
+    job->target = target;
+    job->sync_mode = sync_mode;
+    job->sync_bitmap = sync_mode == MIRROR_SYNC_MODE_INCREMENTAL ?
+                       sync_bitmap : NULL;
+    job->cluster_size = cluster_size;
+
     bdrv_op_block_all(target, job->common.blocker);
     job->common.len = len;
     job->common.co = qemu_coroutine_create(backup_run);
Signature · 1 line
2.8.2
Reviewed-by on v1 1/1
#2 lore raw
In reply to Fam Zheng
Quoted 3 lines · Fam Zheng

Otherwise the job is orphaned and block_job_cancel_sync in bdrv_close_all() when quiting will hang.

Tch, mea culpa.

Quoted 65 lines

A simple reproducer is running blockdev-backup from null-co:// to null-co://.

---
 block/backup.c | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)
block/backup.c +11 -16
index 491fd14..3ff48c6 100644
@@ -505,6 +505,7 @@ void backup_start(BlockDriverState *bs, BlockDriverState *target,
     int64_t len;
     BlockDriverInfo bdi;
     int ret;
+    int64_t cluster_size;
 
     assert(bs);
     assert(target);
@@ -568,23 +569,10 @@ void backup_start(BlockDriverState *bs, BlockDriverState *target,
         goto error;
     }
 
-    BackupBlockJob *job = block_job_create(&backup_job_driver, bs, speed,
-                                           cb, opaque, errp);
-    if (!job) {
-        goto error;
-    }
-
-    job->on_source_error = on_source_error;
-    job->on_target_error = on_target_error;
-    job->target = target;
-    job->sync_mode = sync_mode;
-    job->sync_bitmap = sync_mode == MIRROR_SYNC_MODE_INCREMENTAL ?
-                       sync_bitmap : NULL;
-
     /* If there is no backing file on the target, we cannot rely on COW if our
      * backup cluster size is smaller than the target cluster size. Even for
      * targets with a backing file, try to avoid COW if possible. */
-    ret = bdrv_get_info(job->target, &bdi);
+    ret = bdrv_get_info(target, &bdi);
     if (ret < 0 && !target->backing) {
         error_setg_errno(errp, -ret,
             "Couldn't determine the cluster size of the target image, "
@@ -594,11 +582,25 @@ void backup_start(BlockDriverState *bs, BlockDriverState *target,
         goto error;
     } else if (ret < 0 && target->backing) {
         /* Not fatal; just trudge on ahead. */
-        job->cluster_size = BACKUP_CLUSTER_SIZE_DEFAULT;
+        cluster_size = BACKUP_CLUSTER_SIZE_DEFAULT;
     } else {
-        job->cluster_size = MAX(BACKUP_CLUSTER_SIZE_DEFAULT, bdi.cluster_size);
+        cluster_size = MAX(BACKUP_CLUSTER_SIZE_DEFAULT, bdi.cluster_size);
     }
 
+    BackupBlockJob *job = block_job_create(&backup_job_driver, bs, speed,
+                                           cb, opaque, errp);
+    if (!job) {
+        goto error;
+    }
+
+    job->on_source_error = on_source_error;

block/backup.c void backup_start(BlockDriverState *bs, BlockDriverState *target, · line 606

Quoted 10 lines
block/backup.c +7 -0
+    job->on_target_error = on_target_error;
+    job->target = target;
+    job->sync_mode = sync_mode;
+    job->sync_bitmap = sync_mode == MIRROR_SYNC_MODE_INCREMENTAL ?
+                       sync_bitmap : NULL;
+    job->cluster_size = cluster_size;
+
     bdrv_op_block_all(target, job->common.blocker);
     job->common.len = len;
     job->common.co = qemu_coroutine_create(backup_run);

Thank you.

#3 lore raw
In reply to Fam Zheng
Quoted 2 lines · Fam Zheng

Otherwise the job is orphaned and block_job_cancel_sync in bdrv_close_all() when quiting will hang.

s/quiting/quitting/

Quoted 3 lines

A simple reproducer is running blockdev-backup from null-co:// to null-co://.

Worth a qemu-iotests addition?

Quoted 7 lines
---
 block/backup.c | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
author
#4 lore raw
Quoted 11 lines · Eric Blake
Quoted 2 lines · Fam Zheng

Otherwise the job is orphaned and block_job_cancel_sync in bdrv_close_all() when quiting will hang.

s/quiting/quitting/

Quoted 3 lines

A simple reproducer is running blockdev-backup from null-co:// to null-co://.

Worth a qemu-iotests addition?

Sure, as you asked, will send one in addition.

Fam

Quoted 13 lines
Quoted 8 lines
---
 block/backup.c | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#5 lore raw
In reply to Fam Zheng
Quoted 11 lines · Fam Zheng

Otherwise the job is orphaned and block_job_cancel_sync in bdrv_close_all() when quiting will hang.

A simple reproducer is running blockdev-backup from null-co:// to null-co://.

---
 block/backup.c | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)

Sorry for having waited so long (I was thinking that maybe Jeff wanted to take this patch), but now the patch no longer applies and I don't feel comfortable with just fixing it up myself; git-backport-diff tells me the required changes are "[0015] [FC]".

Max

author
#6 lore raw
Quoted 13 lines · Max Reitz
Quoted 11 lines · Fam Zheng

Otherwise the job is orphaned and block_job_cancel_sync in bdrv_close_all() when quiting will hang.

A simple reproducer is running blockdev-backup from null-co:// to null-co://.

---
 block/backup.c | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)
Quoted 4 lines

Sorry for having waited so long (I was thinking that maybe Jeff wanted to take this patch), but now the patch no longer applies and I don't feel comfortable with just fixing it up myself; git-backport-diff tells me the required changes are "[0015] [FC]".

No problem! I'll rebase it and submit again.

Fam

author Reviewed-by Max Reitz Reviewed-by Alberto Garcia
#7 lore raw
In reply to Max Reitz
Quoted 13 lines · Max Reitz
Quoted 11 lines · Fam Zheng

Otherwise the job is orphaned and block_job_cancel_sync in bdrv_close_all() when quiting will hang.

A simple reproducer is running blockdev-backup from null-co:// to null-co://.

---
 block/backup.c | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)
Quoted 4 lines

Sorry for having waited so long (I was thinking that maybe Jeff wanted to take this patch), but now the patch no longer applies and I don't feel comfortable with just fixing it up myself; git-backport-diff tells me the required changes are "[0015] [FC]".

Oh it turns out this patch is superseded by

commit 91ab68837933232bcef99da7c968e6d41900419b

Author: Kevin Wolf <[email protected]>
Date:   Thu Apr 14 12:59:55 2016 +0200

backup: Don't leak BackupBlockJob in error path

So let's just drop it.

Fam