All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Jan Beulich" <JBeulich@suse.com>
To: xen-devel <xen-devel@lists.xenproject.org>
Cc: Ian Jackson <Ian.Jackson@eu.citrix.com>, Wei Liu <wei.liu2@citrix.com>
Subject: [PATCH] libxc: don't fail domain creation when unpacking initrd fails
Date: Mon, 16 Oct 2017 09:24:44 -0600	[thread overview]
Message-ID: <59E4EB5C0200007800186CF8@prv-mh.provo.novell.com> (raw)

At least Linux kernels have been able to work with gzip-ed initrd for
quite some time; initrd compressed with other methods aren't even being
attempted to unpack. Furthermore the unzip-ing routine used here isn't
capable of dealing with various forms of concatenated files, each of
which was gzip-ed separately (it is this particular case which has been
the source of observed VM creation failures).

Hence, if unpacking fails, simply hand the the compressed blob to the
guest as is.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
---
I'm not intending to request this to go into 4.10, but I certainly
wouldn't mind. I would appreciate though if I could at least get some
initial feedback earlier than when 4.10 branches off, as we will want
to use a backport of this in our trees, which I'd prefer to be in
line with what is eventually going to go into master.

--- a/tools/libxc/include/xc_dom.h
+++ b/tools/libxc/include/xc_dom.h
@@ -291,7 +291,6 @@ int xc_dom_mem_init(struct xc_dom_image
 int xc_dom_kernel_check_size(struct xc_dom_image *dom, size_t sz);
 int xc_dom_kernel_max_size(struct xc_dom_image *dom, size_t sz);
 
-int xc_dom_ramdisk_check_size(struct xc_dom_image *dom, size_t sz);
 int xc_dom_ramdisk_max_size(struct xc_dom_image *dom, size_t sz);
 
 int xc_dom_devicetree_max_size(struct xc_dom_image *dom, size_t sz);
--- a/tools/libxc/xc_dom_core.c
+++ b/tools/libxc/xc_dom_core.c
@@ -314,7 +314,8 @@ int xc_dom_kernel_check_size(struct xc_d
     return 0;
 }
 
-int xc_dom_ramdisk_check_size(struct xc_dom_image *dom, size_t sz)
+static int xc_dom_ramdisk_check_size(struct xc_dom_image *dom, size_t sz,
+                                     size_t raw)
 {
     /* No limit */
     if ( !dom->max_ramdisk_size )
@@ -322,8 +323,9 @@ int xc_dom_ramdisk_check_size(struct xc_
 
     if ( sz > dom->max_ramdisk_size )
     {
-        xc_dom_panic(dom->xch, XC_INVALID_KERNEL,
-                     "ramdisk image too large");
+        if ( raw > dom->max_ramdisk_size )
+            xc_dom_panic(dom->xch, XC_INVALID_KERNEL,
+                         "ramdisk image too large");
         return 1;
     }
 
@@ -999,13 +1001,13 @@ static int xc_dom_build_ramdisk(struct x
     {
         unziplen = xc_dom_check_gzip(dom->xch,
                                      dom->ramdisk_blob, dom->ramdisk_size);
-        if ( xc_dom_ramdisk_check_size(dom, unziplen) != 0 )
+        if ( xc_dom_ramdisk_check_size(dom, unziplen, dom->ramdisk_size) != 0 )
             unziplen = 0;
     }
     else
         unziplen = 0;
 
-    ramdisklen = unziplen ? unziplen : dom->ramdisk_size;
+    ramdisklen = max(unziplen, dom->ramdisk_size);
 
     if ( xc_dom_alloc_segment(dom, &dom->ramdisk_seg, "ramdisk",
                               dom->ramdisk_seg.vstart, ramdisklen) != 0 )
@@ -1017,14 +1019,15 @@ static int xc_dom_build_ramdisk(struct x
                   __FUNCTION__);
         goto err;
     }
-    if ( unziplen )
+    if ( !unziplen ||
+         xc_dom_do_gunzip(dom->xch, dom->ramdisk_blob, dom->ramdisk_size,
+                          ramdiskmap, unziplen) == -1 )
     {
-        if ( xc_dom_do_gunzip(dom->xch, dom->ramdisk_blob, dom->ramdisk_size,
-                              ramdiskmap, ramdisklen) == -1 )
-            goto err;
-    }
-    else
         memcpy(ramdiskmap, dom->ramdisk_blob, dom->ramdisk_size);
+        if ( unziplen > dom->ramdisk_size )
+            memset(ramdiskmap + dom->ramdisk_size, 0,
+                   unziplen - dom->ramdisk_size);
+    }
 
     return 0;
 




_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

             reply	other threads:[~2017-10-16 15:24 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-16 15:24 Jan Beulich [this message]
2017-10-16 15:45 ` [PATCH] libxc: don't fail domain creation when unpacking initrd fails Ian Jackson
2017-10-16 16:19   ` Jan Beulich
2017-10-16 16:43     ` Ian Jackson
2017-10-17  6:28       ` Jan Beulich
2017-10-18 14:31       ` Jan Beulich
2017-10-19 15:06         ` Ian Jackson
2017-10-20 15:47           ` Jan Beulich
2017-10-16 16:48     ` Andrew Cooper
2017-10-16 17:01       ` Ian Jackson
2017-10-25  4:09       ` Doug Goldstein

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=59E4EB5C0200007800186CF8@prv-mh.provo.novell.com \
    --to=jbeulich@suse.com \
    --cc=Ian.Jackson@eu.citrix.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.