[libvirt] Pushed qemuDomainRestore fix

Chris Lalancette clalance at redhat.com
Fri Apr 2 13:28:15 UTC 2010

FYI, I just pushed this fix (with blessing from DV):

commit d62f4c36c2c28b96952143247a1360e8c18f64c7
Author: Chris Lalancette <clalance at redhat.com>
Date:   Tue Mar 23 09:11:29 2010 -0400

    Don't use virFileReadLimFD in qemuDomainRestore.
    virFileReadLimFD is a poor fit for reading the header
    of the restore file.  The problem is that virFileReadLimFD
    returns an error when there is more data after the amount
    you ask to read, but that is *expected* in this case.
    This patch is essentially a revert of
    1a4d5c9543641c444dccd682f6256ee3faf22a80, but I don't think
    that commit does what it says anyway.  It purports to prevent
    an unwarranted OOM error, but since virFileReadLimFD will
    allocate memory up to the maximum anyway, the upper limit
    on the total amount of memory allocated is the same for either
    the old version or the new version.  Since the old saferead
    actually works and virFileReadLimFD does not, revert to
    using saferead.
    Signed-off-by: Chris Lalancette <clalance at redhat.com>

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 4291bc7..70d2781 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -5547,7 +5547,12 @@ static int qemudDomainRestore(virConnectPtr conn,
         goto cleanup;
-    if (virFileReadLimFD(fd, header.xml_len, &xml) != header.xml_len) {
+    if (VIR_ALLOC_N(xml, header.xml_len) < 0) {
+        virReportOOMError();
+        goto cleanup;
+    }
+    if (saferead(fd, xml, header.xml_len) != header.xml_len) {
                         "%s", _("failed to read XML"));
         goto cleanup;

Chris Lalancette

More information about the libvir-list mailing list