From: Ian Campbell Date: Tue, 5 Apr 2011 16:34:48 +0000 (+0100) Subject: libxl: specify disks using supported command line syntax for new qemu X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=d93b35f89b1c6715fb903d057782314759cab20c;p=xen.git libxl: specify disks using supported command line syntax for new qemu The -hdX syntax is only retained for compatibility reasons and the -sdX syntax doesn't even exist. Additionally convert the first four non-SCSI disks to hd[a-d] and ignore any further non-SCSI disks (since qemu only supports 4 IDE devices). SCSI disks are passed through as is. qemu-xen was limited to 7 SCSI devices but upstream qemu supports 256, therefore do not limit the number of disks on the libxl side. qemu-xen did all this itself internally. Fixes "qemu: -xvda: invalid option" and allows PVHVM to work with upstream qemu. Signed-off-by: Ian Campbell Acked-by: Ian Jackson Committed-by: Ian Jackson --- diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c index 157c9fb288..04fc484b6e 100644 --- a/tools/libxl/libxl_dm.c +++ b/tools/libxl/libxl_dm.c @@ -175,6 +175,7 @@ static char ** libxl__build_device_model_args_new(libxl__gc *gc, libxl_device_disk *disks, int num_disks, libxl_device_nic *vifs, int num_vifs) { + libxl_ctx *ctx = libxl__gc_owner(gc); flexarray_t *dm_args; int i; @@ -312,13 +313,48 @@ static char ** libxl__build_device_model_args_new(libxl__gc *gc, if (info->type == XENFV) { for (i; i < num_disks; i++) { + int disk, part; + int dev_number = + libxl__device_disk_dev_number(disks[i].vdev, &disk, &part); + char *drive; + + if (dev_number == -1) { + LIBXL__LOG(ctx, LIBXL__LOG_WARNING, "unable to determine" + " disk number for %s", disks[i].vdev); + continue; + } + if (disks[i].is_cdrom) { - flexarray_append(dm_args, "-cdrom"); - flexarray_append(dm_args, libxl__strdup(gc, disks[i].pdev_path)); + if (disks[i].format == DISK_FORMAT_EMPTY) + drive = libxl__sprintf + (gc, "if=ide,index=%d,media=cdrom", disk); + else + drive = libxl__sprintf + (gc, "file=%s,if=ide,index=%d,media=cdrom", + disks[i].pdev_path, disk); } else { - flexarray_append(dm_args, libxl__sprintf(gc, "-%s", disks[i].vdev)); - flexarray_append(dm_args, libxl__strdup(gc, disks[i].pdev_path)); + if (disks[i].format == DISK_FORMAT_EMPTY) + continue; + + /* + * Explicit sd disks are passed through as is. + * + * For other disks we translate devices 0..3 into + * hd[a-d] and ignore the rest. + */ + if (strncmp(disks[i].vdev, "sd", 2) == 0) + drive = libxl__sprintf(gc, "file=%s,if=scsi,bus=0,unit=%d", + disks[i].pdev_path, disk); + else if (disk < 4) + drive = libxl__sprintf + (gc, "file=%s,if=ide,index=%d,media=disk", + disks[i].pdev_path, disk); + else + continue; /* Do not emulate this disk */ } + + flexarray_append(dm_args, "-drive"); + flexarray_append(dm_args, drive); } } flexarray_append(dm_args, NULL);