From f859377de12e2faa46046b266ce4418c138e61ab Mon Sep 17 00:00:00 2001
From: Wolfgang Bumiller <w.bumiller@proxmox.com>
Date: Wed, 9 Dec 2015 15:22:19 +0100
Subject: [PATCH 17/48] backup: do not return errors in dump callback

---
 blockdev.c | 26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/blockdev.c b/blockdev.c
index af1b9d4..4b073d4 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -3019,6 +3019,11 @@ static int pvebackup_dump_cb(void *opaque, BlockBackend *target,
 {
     PVEBackupDevInfo *di = opaque;
 
+    int size = n_sectors * BDRV_SECTOR_SIZE;
+    if (backup_state.cancel) {
+        return size; // return success
+    }
+
     if (sector_num & 0x7f) {
         if (!backup_state.error) {
             error_setg(&backup_state.error,
@@ -3029,7 +3034,6 @@ static int pvebackup_dump_cb(void *opaque, BlockBackend *target,
     }
 
     int64_t cluster_num = sector_num >> 7;
-    int size = n_sectors * BDRV_SECTOR_SIZE;
 
     int ret = -1;
 
@@ -3037,17 +3041,27 @@ static int pvebackup_dump_cb(void *opaque, BlockBackend *target,
         size_t zero_bytes = 0;
         ret = vma_writer_write(backup_state.vmaw, di->dev_id, cluster_num,
                                buf, &zero_bytes);
-        backup_state.zero_bytes += zero_bytes;
+        if (ret < 0) {
+            if (!backup_state.error) {
+                error_setg(&backup_state.error, "vma_writer_write error %d", ret);
+            }
+            if (di->bs && di->bs->job) {
+                block_job_cancel(di->bs->job);
+            }
+        } else {
+            backup_state.zero_bytes += zero_bytes;
+            backup_state.transferred += size;
+        }
     } else {
-        ret = size;
         if (!buf) {
             backup_state.zero_bytes += size;
         }
+        backup_state.transferred += size;
     }
 
-    backup_state.transferred += size;
+    // Note: always return success, because we want that writes succeed anyways.
 
-    return ret;
+    return size;
 }
 
 static void pvebackup_cleanup(void)
@@ -3119,7 +3133,7 @@ static void pvebackup_cancel(void *opaque)
             BlockJob *job = di->bs->job;
             if (job) {
                 if (!di->completed) {
-                    block_job_cancel_sync(job);
+                     block_job_cancel_sync(job);
                 }
             }
         }
-- 
2.1.4

