[Libguestfs] [PATCH v2] launch: Error if you try to launch with too many drives.

Richard W.M. Jones rjones at redhat.com
Tue May 2 13:35:53 UTC 2017


In particular the virt-rescue --scratch option makes it very easy to
add huge numbers of drives.  Since the per-backend max_disks limit was
never checked anywhere you could get peculiar failures.  Now you'll
get a clear error message:

$ virt-rescue --scratch=256
libguestfs: error: too many drives have been added, the current backend only supports 255 drives
---
 lib/launch.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/lib/launch.c b/lib/launch.c
index 7f06c69..37ab024 100644
--- a/lib/launch.c
+++ b/lib/launch.c
@@ -55,12 +55,27 @@ static struct backend {
 int
 guestfs_impl_launch (guestfs_h *g)
 {
+  int r;
+
   /* Configured? */
   if (g->state != CONFIG) {
     error (g, _("the libguestfs handle has already been launched"));
     return -1;
   }
 
+  /* Too many drives?
+   *
+   * Some backends such as ‘unix:’ don't allow us to query max_disks.
+   * Don't fail in this case.
+   */
+  guestfs_push_error_handler (g, NULL, NULL);
+  r = guestfs_max_disks (g);
+  guestfs_pop_error_handler (g);
+  if (r >= 0 && g->nr_drives > (size_t) r) {
+    error (g, _("too many drives have been added, the current backend only supports %d drives"), r);
+    return -1;
+  }
+
   /* Start the clock ... */
   gettimeofday (&g->launch_t, NULL);
   TRACE0 (launch_start);
-- 
2.9.3




More information about the Libguestfs mailing list