xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: George Dunlap <george.dunlap@eu.citrix.com>
To: xen-devel@lists.xensource.com
Cc: george.dunlap@eu.citrix.com
Subject: [PATCH v2] libxl: Fix bug in libxl_cdrom_insert, make more robust against bad xenstore data
Date: Fri, 23 Nov 2012 14:40:56 +0000	[thread overview]
Message-ID: <54d1bcd211d14cfbae07.1353681656@elijah> (raw)

# HG changeset patch
# User George Dunlap <george.dunlap@eu.citrix.com>
# Date 1353681608 0
# Node ID 54d1bcd211d14cfbae0782f2bf04f8942c2eb726
# 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.

v2:
 - Remove the checks on read, pending a more robust fix in another patch.

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
@@ -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",

             reply	other threads:[~2012-11-23 14:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-23 14:40 George Dunlap [this message]
2012-11-27 14:14 ` [PATCH v2] libxl: Fix bug in libxl_cdrom_insert, make more robust against bad xenstore data Ian Campbell

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=54d1bcd211d14cfbae07.1353681656@elijah \
    --to=george.dunlap@eu.citrix.com \
    --cc=xen-devel@lists.xensource.com \
    /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 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).