Skip to contentSkip to conversation

xl: fix cdrom_insert parsing

PATCH In review Stefano Stabellini 2 participants 2 messages Feb 17, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xl: fix cdrom_insert parsing

Reuse the same code used to parse the disk line from the VM config file in cd_insert.

tools/libxl/xl_cmdimpl.c +13 -30
diff -r d90cbea3df03 tools/libxl/xl_cmdimpl.c
@@ -1847,40 +1847,23 @@ static void cd_insert(const char *dom, c
 static void cd_insert(const char *dom, const char *virtdev, char *phys)
 {
     libxl_device_disk disk; /* we don't free disk's contents */
-    char *p;
-
-    find_domain(dom);
-
+    char *buf = NULL;
+
+    find_domain(dom);
+
+    if (asprintf(&buf, "%s,%s:cdrom,r", phys ? phys : "", virtdev) < 0) {
+        fprintf(stderr, "out of memory\n");
+        return;
+    }
+    if (!parse_disk_config(&disk, buf)) {
+        fprintf(stderr, "format error\n");
+        return;
+    }
     disk.backend_domid = 0;
     disk.domid = domid;
-    if (phys) {
-        p = strchr(phys, ':');
-        if (!p) {
-            fprintf(stderr, "No type specified, ");
-            disk.pdev_path = phys;
-            if (!strncmp(phys, "/dev", 4)) {
-                fprintf(stderr, "assuming phy:\n");
-                disk.backend = DISK_BACKEND_PHY;
-            } else {
-                fprintf(stderr, "assuming file:\n");
-                disk.backend = DISK_BACKEND_TAP; 
-            }
-        } else {
-            *p = '\0';
-            p++;
-            disk.pdev_path = p;
-            libxl_string_to_backend(&ctx, phys, &disk.backend);
-        }
-    } else {
-            disk.pdev_path = strdup("");
-            disk.format = DISK_FORMAT_EMPTY;
-    }
-    disk.vdev = (char*)virtdev;
-    disk.unpluggable = 1;
-    disk.readwrite = 0;
-    disk.is_cdrom = 1;
 
     libxl_cdrom_insert(&ctx, domid, &disk);
+    free(buf);
 }
 
 int main_cd_eject(int argc, char **argv)
#1 lore raw

Stefano Stabellini writes ("[Xen-devel] [PATCH] xl: fix cdrom_insert parsing"):

Quoted 2 lines

Reuse the same code used to parse the disk line from the VM config file in cd_insert.

This looks good to me. I will apply it.

Ian.