From 17b2fc7ed399325558b891e13e104214568fd154 Mon Sep 17 00:00:00 2001
From: Wolfgang Bumiller <w.bumiller@proxmox.com>
Date: Wed, 9 Dec 2015 15:39:36 +0100
Subject: [PATCH 18/48] backup: vma: correctly propagate error

---
 blockdev.c   | 2 +-
 vma-writer.c | 7 +++++++
 vma.h        | 1 +
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/blockdev.c b/blockdev.c
index 4b073d4..6253ef1 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -3043,7 +3043,7 @@ static int pvebackup_dump_cb(void *opaque, BlockBackend *target,
                                buf, &zero_bytes);
         if (ret < 0) {
             if (!backup_state.error) {
-                error_setg(&backup_state.error, "vma_writer_write error %d", ret);
+                vma_writer_error_propagate(backup_state.vmaw, &backup_state.error);
             }
             if (di->bs && di->bs->job) {
                 block_job_cancel(di->bs->job);
diff --git a/vma-writer.c b/vma-writer.c
index b0cf529..689e988 100644
--- a/vma-writer.c
+++ b/vma-writer.c
@@ -792,6 +792,13 @@ vma_writer_write(VmaWriter *vmaw, uint8_t dev_id, int64_t cluster_num,
     return transferred;
 }
 
+void vma_writer_error_propagate(VmaWriter *vmaw, Error **errp)
+{
+    if (vmaw->status < 0 && *errp == NULL) {
+        error_setg(errp, "%s", vmaw->errmsg);
+    }
+}
+
 int vma_writer_close(VmaWriter *vmaw, Error **errp)
 {
     g_assert(vmaw != NULL);
diff --git a/vma.h b/vma.h
index 9bb6ea4..98377e4 100644
--- a/vma.h
+++ b/vma.h
@@ -116,6 +116,7 @@ typedef struct VmaDeviceInfo {
 
 VmaWriter *vma_writer_create(const char *filename, uuid_t uuid, Error **errp);
 int vma_writer_close(VmaWriter *vmaw, Error **errp);
+void vma_writer_error_propagate(VmaWriter *vmaw, Error **errp);
 void vma_writer_destroy(VmaWriter *vmaw);
 int vma_writer_add_config(VmaWriter *vmaw, const char *name, gpointer data,
                           size_t len);
-- 
2.1.4

