[PATCH v2 08/10] qemu: Don't lookup invalid domains unless specified otherwise

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Change qemuDomObjFromDomain() to qemuDomObjFromDomainInternal() with
additional parameter that controls how to deal with invalid domains.
New qemuDomObjFromDomain() then follows the safe path wo we don't have
to change its callers from all APIs and qemuDomObjFromDomainInvalid() is
added as a new function that can be called from APIs that are prepared
to handle invalid definitions as well.

Signed-off-by: Martin Kletzander <mkletzan@xxxxxxxxxx>
---
 src/qemu/qemu_driver.c | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index e8711f0f3173..e89dfcd09d4a 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -210,15 +210,22 @@ struct qemuAutostartData {
 /**
  * qemuDomObjFromDomain:
  * @domain: Domain pointer that has to be looked up
+ * @invalid: Whether to also return invalid definitions
  *
  * This function looks up @domain and returns the appropriate virDomainObjPtr
  * that has to be released by calling virDomainObjEndAPI().
  *
+ * If @invalid is true, this function can return domain definition with only
+ * name and uuid set, so beware as that can lead to NULL pointer dereference.
+ * This function should be called with @invalid == true only from APIs that are
+ * needed to fix the domain definition (e.g. those needed for looking it up or
+ * providing a new definition.
+ *
  * Returns the domain object with incremented reference counter which is locked
  * on success, NULL otherwise.
  */
 static virDomainObjPtr
-qemuDomObjFromDomain(virDomainPtr domain)
+qemuDomObjFromDomainInternal(virDomainPtr domain, bool invalid)
 {
     virDomainObjPtr vm;
     virQEMUDriverPtr driver = domain->conn->privateData;
@@ -232,10 +239,29 @@ qemuDomObjFromDomain(virDomainPtr domain)
                        uuidstr, domain->name);
         return NULL;
     }
+    if (!invalid && vm->def->parseError) {
+        virReportError(VIR_ERR_XML_ERROR,
+                       _("domain '%s' was not loaded due to an XML error "
+                         "(%s), please redefine it"),
+                       vm->def->name, vm->def->parseError);
+        virDomainObjEndAPI(&vm);
+    }

     return vm;
 }

+static inline virDomainObjPtr
+qemuDomObjFromDomain(virDomainPtr domain)
+{
+    return qemuDomObjFromDomainInternal(domain, false);
+}
+
+static inline virDomainObjPtr
+qemuDomObjFromDomainInvalid(virDomainPtr domain)
+{
+    return qemuDomObjFromDomainInternal(domain, true);
+}
+
 /* Looks up the domain object from snapshot and unlocks the
  * driver. The returned domain object is locked and ref'd and the
  * caller must call virDomainObjEndAPI() on it. */
-- 
2.6.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]