]> xenbits.xensource.com Git - libvirt.git/commitdiff
vbox: Errors in vboxAttachDrives are now critical
authorDawid Zamirski <dzamirski@datto.com>
Tue, 24 Oct 2017 19:35:29 +0000 (15:35 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Fri, 3 Nov 2017 17:15:54 +0000 (13:15 -0400)
Previously, if one tried to define a VBOX VM and the API failed to
perform the requested actions for some reason, it would just log the
error and move on to process remaining disk definitions. This is not
desired as it could result in incorrectly defined VM without the caller
even knowing about it. So now all the code paths that call
virReportError are now treated as hard failures as they should have
been.

src/vbox/vbox_common.c

index 2291169c5e5a12ef2358c05f0ae8cfea46f6f12a..fd749eaa8216aead96b3ba63603941de235fc49b 100644 (file)
@@ -955,11 +955,11 @@ vboxSetBootDeviceOrder(virDomainDefPtr def, vboxDriverPtr data,
     }
 }
 
-static void
+static int
 vboxAttachDrives(virDomainDefPtr def, vboxDriverPtr data, IMachine *machine)
 {
     size_t i;
-    int type, format;
+    int type, format, ret = 0;
     const char *src = NULL;
     nsresult rc = 0;
     virDomainDiskDefPtr disk = NULL;
@@ -1049,6 +1049,7 @@ vboxAttachDrives(virDomainDefPtr def, vboxDriverPtr data, IMachine *machine)
                 deviceType = DeviceType_Floppy;
                 accessMode = AccessMode_ReadWrite;
             } else {
+                ret = -1;
                 goto cleanup;
             }
 
@@ -1066,6 +1067,7 @@ vboxAttachDrives(virDomainDefPtr def, vboxDriverPtr data, IMachine *machine)
                 virReportError(VIR_ERR_INTERNAL_ERROR,
                                _("Failed to attach the following disk/dvd/floppy "
                                  "to the machine: %s, rc=%08x"), src, rc);
+                ret = -1;
                 goto cleanup;
             }
 
@@ -1075,6 +1077,7 @@ vboxAttachDrives(virDomainDefPtr def, vboxDriverPtr data, IMachine *machine)
                                _("Can't get the UUID of the file to be attached "
                                  "as harddisk/dvd/floppy: %s, rc=%08x"),
                                src, rc);
+                ret = -1;
                 goto cleanup;
             }
 
@@ -1114,6 +1117,8 @@ vboxAttachDrives(virDomainDefPtr def, vboxDriverPtr data, IMachine *machine)
                 virReportError(VIR_ERR_INTERNAL_ERROR,
                                _("Could not attach the file as "
                                  "harddisk/dvd/floppy: %s, rc=%08x"), src, rc);
+                ret = -1;
+                goto cleanup;
             } else {
                 DEBUGIID("Attached HDD/DVD/Floppy with UUID", &mediumUUID);
             }
@@ -1122,8 +1127,13 @@ vboxAttachDrives(virDomainDefPtr def, vboxDriverPtr data, IMachine *machine)
             vboxIIDUnalloc(&mediumUUID);
             VBOX_UTF16_FREE(mediumFileUtf16);
             VBOX_UTF16_FREE(storageCtlName);
+
+            if (ret < 0)
+                break;
         }
     }
+
+    return ret;
 }
 
 static void
@@ -1852,7 +1862,8 @@ vboxDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags
     gVBoxAPI.UISession.GetMachine(data->vboxSession, &machine);
 
     vboxSetBootDeviceOrder(def, data, machine);
-    vboxAttachDrives(def, data, machine);
+    if (vboxAttachDrives(def, data, machine) < 0)
+        goto cleanup;
     vboxAttachSound(def, machine);
     if (vboxAttachNetwork(def, data, machine) < 0)
         goto cleanup;