thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

Blame SOURCES/kvm-block-vdi-Error-out-immediately-in-vdi_create.patch

958e1b
From 5a762ccf05fea97bc3e98b8dd317374c51c14c26 Mon Sep 17 00:00:00 2001
958e1b
From: Jeffrey Cody <jcody@redhat.com>
958e1b
Date: Tue, 16 Sep 2014 20:11:47 +0200
958e1b
Subject: [PATCH 09/20] block/vdi: Error out immediately in vdi_create()
958e1b
958e1b
Message-id: <2947dd91a4c9967cbd5a241145c355263e04207a.1410897407.git.jcody@redhat.com>
958e1b
Patchwork-id: 61213
958e1b
O-Subject: [PATCH qemu-kvm-rhel RHEL7.1 08/15] block/vdi: Error out immediately in vdi_create()
958e1b
Bugzilla: 1098086
958e1b
RH-Acked-by: Fam Zheng <famz@redhat.com>
958e1b
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
958e1b
RH-Acked-by: Max Reitz <mreitz@redhat.com>
958e1b
958e1b
From: Max Reitz <mreitz@redhat.com>
958e1b
958e1b
Currently, if an error occurs during the part of vdi_create() which
958e1b
actually writes the image, the function stores -errno, but continues
958e1b
anyway.
958e1b
958e1b
Instead of trying to write data which (if it can be written at all) does
958e1b
not make any sense without the operations before succeeding (e.g.,
958e1b
writing the image header), just error out immediately.
958e1b
958e1b
Signed-off-by: Max Reitz <mreitz@redhat.com>
958e1b
Reviewed-by: Stefan Weil <sw@weilnetz.de>
958e1b
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
958e1b
(cherry picked from commit 0549ea8b6d3ed4eba9a3bd0abfaed3af5de69873)
958e1b
Signed-off-by: Jeff Cody <jcody@redhat.com>
958e1b
958e1b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
958e1b
---
958e1b
 block/vdi.c |    7 ++++++-
958e1b
 1 files changed, 6 insertions(+), 1 deletions(-)
958e1b
958e1b
diff --git a/block/vdi.c b/block/vdi.c
958e1b
index 0211023..fb25424 100644
958e1b
--- a/block/vdi.c
958e1b
+++ b/block/vdi.c
958e1b
@@ -753,6 +753,7 @@ static int vdi_create(const char *filename, QEMUOptionParameter *options,
958e1b
     vdi_header_to_le(&header);
958e1b
     if (write(fd, &header, sizeof(header)) < 0) {
958e1b
         result = -errno;
958e1b
+        goto close_and_exit;
958e1b
     }
958e1b
 
958e1b
     if (bmap_size > 0) {
958e1b
@@ -766,6 +767,8 @@ static int vdi_create(const char *filename, QEMUOptionParameter *options,
958e1b
         }
958e1b
         if (write(fd, bmap, bmap_size) < 0) {
958e1b
             result = -errno;
958e1b
+            g_free(bmap);
958e1b
+            goto close_and_exit;
958e1b
         }
958e1b
         g_free(bmap);
958e1b
     }
958e1b
@@ -773,10 +776,12 @@ static int vdi_create(const char *filename, QEMUOptionParameter *options,
958e1b
     if (image_type == VDI_TYPE_STATIC) {
958e1b
         if (ftruncate(fd, sizeof(header) + bmap_size + blocks * block_size)) {
958e1b
             result = -errno;
958e1b
+            goto close_and_exit;
958e1b
         }
958e1b
     }
958e1b
 
958e1b
-    if (close(fd) < 0) {
958e1b
+close_and_exit:
958e1b
+    if ((close(fd) < 0) && !result) {
958e1b
         result = -errno;
958e1b
     }
958e1b
 
958e1b
-- 
958e1b
1.7.1
958e1b