xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH] libxl: Fix bug in libxl_cdrom_insert, make more robust against bad xenstore data
@ 2012-11-22 14:16 Fabio Fantoni
  0 siblings, 0 replies; 5+ messages in thread
From: Fabio Fantoni @ 2012-11-22 14:16 UTC (permalink / raw)
  To: xen-devel


[-- Attachment #1.1: Type: text/plain, Size: 626 bytes --]

I tested it with xen-unstable: no more segfault error and in genera good 
debug.
Below the result of my test:

xl cd-insert W7 hdb raw:/mnt/vm/iso/QUANTAL.iso
libxl: error: libxl_device.c:243:libxl__device_disk_set_backend: Disk 
vdev=hdb failed to stat: raw:/mnt/vm/iso/QUANTAL.iso: No such file or 
directory

I launched the command based on this syntax:
Usage: xl [-vfN] cd-insert <Domain> <VirtualDevice> <type:path>

I also tried removing "raw:" but  it gave:
xl cd-insert W7 hdb /mnt/vm/iso/QUANTAL.iso
libxl: error: libxl_device.c:269:libxl__device_disk_set_backend: no 
suitable backend for disk hdb


[-- Attachment #1.2: Firma crittografica S/MIME --]
[-- Type: application/pkcs7-signature, Size: 4510 bytes --]

[-- Attachment #2: Type: text/plain, Size: 126 bytes --]

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

^ permalink raw reply	[flat|nested] 5+ messages in thread
* [PATCH] libxl: Fix bug in libxl_cdrom_insert, make more robust against bad xenstore data
@ 2012-11-21 17:29 George Dunlap
  2012-11-23 10:05 ` Ian Campbell
  0 siblings, 1 reply; 5+ messages in thread
From: George Dunlap @ 2012-11-21 17:29 UTC (permalink / raw)
  To: xen-devel; +Cc: george.dunlap

# HG changeset patch
# User George Dunlap <george.dunlap@eu.citrix.com>
# Date 1353518844 0
# Node ID a4f707f6049a4a8152d2886f1b1d49f9e70ef5eb
# Parent  ae6fb202b233af815466055d9f1a635802a50855
libxl: Fix bug in libxl_cdrom_insert, make more robust against bad xenstore data

libxl_cdrom_insert was failing to initialize the backend type,
resulting in the wrong default backend.  The result was not only that
the CD was not inserted properly, but also that some improper xenstore
entries were created, causing further block commands to fail.

This patch fixes the bug by setting the disk backend type based on the
type of the existing device.

It also makes the system more robust by:
* Checking to see that it has got a valid path before proceeding to
write a partial xenstore entry
* Handling non-existent nodes in the backend xenstore entries more
gracefully

Signed-off-by: George Dunlap <george.dunlap@eu.citrix.com>

diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -2201,14 +2201,14 @@ static void libxl__device_disk_from_xs_b
         disk->removable = 0;
 
     tmp = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "%s/mode", be_path));
-    if (!strcmp(tmp, "w"))
+    if (tmp && !strcmp(tmp, "w"))
         disk->readwrite = 1;
     else
         disk->readwrite = 0;
 
     tmp = libxl__xs_read(gc, XBT_NULL,
                          libxl__sprintf(gc, "%s/device-type", be_path));
-    disk->is_cdrom = !strcmp(tmp, "cdrom");
+    disk->is_cdrom = tmp && !strcmp(tmp, "cdrom");
 
     disk->format = LIBXL_DISK_FORMAT_UNKNOWN;
 }
@@ -2353,6 +2353,7 @@ int libxl_cdrom_insert(libxl_ctx *ctx, u
 
     libxl__device device;
     const char * path;
+    char * tmp;
 
     flexarray_t *insert = NULL;
 
@@ -2383,8 +2384,11 @@ int libxl_cdrom_insert(libxl_ctx *ctx, u
     disks = libxl_device_disk_list(ctx, domid, &num);
     for (i = 0; i < num; i++) {
         if (disks[i].is_cdrom && !strcmp(disk->vdev, disks[i].vdev))
-            /* found */
+        {
+            /* Found.  Set backend type appropriately. */
+            disk->backend=disks[i].backend;
             break;
+        }
     }
     if (i == num) {
         LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Virtual device not found");
@@ -2410,6 +2414,17 @@ int libxl_cdrom_insert(libxl_ctx *ctx, u
 
     path = libxl__device_backend_path(gc, &device);
 
+    /* Sanity check: make sure the backend exists before writing here */
+    tmp = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "%s/frontend", path));
+    if (!tmp)
+    {
+        LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Internal error: %s does not exist",
+            libxl__sprintf(gc, "%s/frontend", path));
+        rc = ERROR_FAIL;
+        goto out;
+    }
+
+
     insert = flexarray_make(gc, 4, 1);
 
     flexarray_append_pair(insert, "type",

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-11-23 11:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-22 14:16 [PATCH] libxl: Fix bug in libxl_cdrom_insert, make more robust against bad xenstore data Fabio Fantoni
  -- strict thread matches above, loose matches on Subject: below --
2012-11-21 17:29 George Dunlap
2012-11-23 10:05 ` Ian Campbell
2012-11-23 11:37   ` George Dunlap
2012-11-23 11:48     ` Ian Campbell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).