Skip to contentSkip to conversation

blockdev: fix missed target unref for drive-backup

PATCH Superseded John Snow 2 participants 3 messages May 10, 2019 – May 13, 2019

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

John Snow

author
#0 lore raw

PATCH 1/1 blockdev: fix missed target unref for drive-backup

If the bitmap can't be used for whatever reason, we skip putting down the reference. Fix that.

In practice, this means that if you attempt to gracefully exit QEMU after a backup command being rejected, bdrv_close_all will fail and tell you some unpleasant things via assert().

---
 blockdev.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
blockdev.c +5 -7
index 79fbac8450..278ecdd122 100644
@@ -3525,8 +3525,7 @@ static BlockJob *do_drive_backup(DriveBackup *backup, JobTxn *txn,
     if (set_backing_hd) {
         bdrv_set_backing_hd(target_bs, source, &local_err);
         if (local_err) {
-            bdrv_unref(target_bs);
-            goto out;
+            goto unref;
         }
     }
 
@@ -3534,11 +3533,10 @@ static BlockJob *do_drive_backup(DriveBackup *backup, JobTxn *txn,
         bmap = bdrv_find_dirty_bitmap(bs, backup->bitmap);
         if (!bmap) {
             error_setg(errp, "Bitmap '%s' could not be found", backup->bitmap);
-            bdrv_unref(target_bs);
-            goto out;
+            goto unref;
         }
         if (bdrv_dirty_bitmap_check(bmap, BDRV_BITMAP_DEFAULT, errp)) {
-            goto out;
+            goto unref;
         }
     }
     if (!backup->auto_finalize) {
@@ -3552,12 +3550,12 @@ static BlockJob *do_drive_backup(DriveBackup *backup, JobTxn *txn,
                             backup->sync, bmap, backup->compress,
                             backup->on_source_error, backup->on_target_error,
                             job_flags, NULL, NULL, txn, &local_err);
-    bdrv_unref(target_bs);
     if (local_err != NULL) {
         error_propagate(errp, local_err);
-        goto out;
     }
 
+unref:
+    bdrv_unref(target_bs);
 out:
     aio_context_release(aio_context);
     return job;
Signature · 1 line
2.20.1
Reviewed-by on v1 1/1
#1 lore raw

Am 10.05.2019 um 23:52 hat John Snow geschrieben:

Quoted 43 lines

If the bitmap can't be used for whatever reason, we skip putting down the reference. Fix that.

In practice, this means that if you attempt to gracefully exit QEMU after a backup command being rejected, bdrv_close_all will fail and tell you some unpleasant things via assert().

---
 blockdev.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
blockdev.c +3 -5
index 79fbac8450..278ecdd122 100644
@@ -3525,8 +3525,7 @@ static BlockJob *do_drive_backup(DriveBackup *backup, JobTxn *txn,
     if (set_backing_hd) {
         bdrv_set_backing_hd(target_bs, source, &local_err);
         if (local_err) {
-            bdrv_unref(target_bs);
-            goto out;
+            goto unref;
         }
     }
 
@@ -3534,11 +3533,10 @@ static BlockJob *do_drive_backup(DriveBackup *backup, JobTxn *txn,
         bmap = bdrv_find_dirty_bitmap(bs, backup->bitmap);
         if (!bmap) {
             error_setg(errp, "Bitmap '%s' could not be found", backup->bitmap);
-            bdrv_unref(target_bs);
-            goto out;
+            goto unref;
         }
         if (bdrv_dirty_bitmap_check(bmap, BDRV_BITMAP_DEFAULT, errp)) {
-            goto out;
+            goto unref;
         }
     }
     if (!backup->auto_finalize) {

blockdev.c static BlockJob *do_drive_backup(DriveBackup *backup, JobTxn *txn, · line 3558

Quoted 7 lines
blockdev.c +0 -2
@@ -3552,12 +3550,12 @@ static BlockJob *do_drive_backup(DriveBackup *backup, JobTxn *txn,
                             backup->sync, bmap, backup->compress,
                             backup->on_source_error, backup->on_target_error,
                             job_flags, NULL, NULL, txn, &local_err);
-    bdrv_unref(target_bs);
     if (local_err != NULL) {
         error_propagate(errp, local_err);
-        goto out;

Please leave a 'goto unref' here so we can later add more code without modifying unrelated error paths (or, more likely, forgetting to modify them).

blockdev.c static BlockJob *do_drive_backup(DriveBackup *backup, JobTxn *txn, · line 3561

Quoted 7 lines
blockdev.c +2 -0
     }
 
+unref:
+    bdrv_unref(target_bs);
 out:
     aio_context_release(aio_context);
     return job;

With this fixed:

author
#2 lore raw
Quoted 47 lines · Kevin Wolf

Am 10.05.2019 um 23:52 hat John Snow geschrieben:

Quoted 46 lines

If the bitmap can't be used for whatever reason, we skip putting down the reference. Fix that.

In practice, this means that if you attempt to gracefully exit QEMU after a backup command being rejected, bdrv_close_all will fail and tell you some unpleasant things via assert().

---
 blockdev.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
blockdev.c +3 -5
index 79fbac8450..278ecdd122 100644
@@ -3525,8 +3525,7 @@ static BlockJob *do_drive_backup(DriveBackup *backup, JobTxn *txn,
     if (set_backing_hd) {
         bdrv_set_backing_hd(target_bs, source, &local_err);
         if (local_err) {
-            bdrv_unref(target_bs);
-            goto out;
+            goto unref;
         }
     }
 
@@ -3534,11 +3533,10 @@ static BlockJob *do_drive_backup(DriveBackup *backup, JobTxn *txn,
         bmap = bdrv_find_dirty_bitmap(bs, backup->bitmap);
         if (!bmap) {
             error_setg(errp, "Bitmap '%s' could not be found", backup->bitmap);
-            bdrv_unref(target_bs);
-            goto out;
+            goto unref;
         }
         if (bdrv_dirty_bitmap_check(bmap, BDRV_BITMAP_DEFAULT, errp)) {
-            goto out;
+            goto unref;
         }
     }
     if (!backup->auto_finalize) {
@@ -3552,12 +3550,12 @@ static BlockJob *do_drive_backup(DriveBackup *backup, JobTxn *txn,
                             backup->sync, bmap, backup->compress,
                             backup->on_source_error, backup->on_target_error,
                             job_flags, NULL, NULL, txn, &local_err);
Quoted 9 lines

blockdev.c static BlockJob *do_drive_backup(DriveBackup *backup, JobTxn *txn, · line 3558

Quoted 4 lines
blockdev.c +0 -2
-    bdrv_unref(target_bs);
     if (local_err != NULL) {
         error_propagate(errp, local_err);
-        goto out;

Please leave a 'goto unref' here so we can later add more code without modifying unrelated error paths (or, more likely, forgetting to modify them).

Oh, that makes sense.

Quoted 11 lines

blockdev.c static BlockJob *do_drive_backup(DriveBackup *backup, JobTxn *txn, · line 3561

Quoted 7 lines
blockdev.c +2 -0
     }
 
+unref:
+    bdrv_unref(target_bs);
 out:
     aio_context_release(aio_context);
     return job;

With this fixed:

Thanks!