libxl: allow 'phy' backend to use empty files
authorRoger Pau Monne <roger.pau@citrix.com>
Fri, 19 Feb 2016 18:01:55 +0000 (19:01 +0100)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Fri, 1 Apr 2016 14:09:05 +0000 (15:09 +0100)
This was introduced by 97ee1f (~5 years ago), but was probably never
surfaced because most people used regular files as CDROM images, so the PHY
backend was actually never selected. A year ago this was changed, and now
regular RAW files are also handled by the PHY backend, which has made this
bug suface.

Fix it by allowing empty disks to use the PHY backend, skipping the stat
tests.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reported-by: Alex Braunegg <alex.braunegg@gmail.com>
tools/libxl/libxl_device.c

index 6a411c6d12189e103d37d388292a44a13d3de795..4166988a0249e5a4af3abd78386bfbcdc9cefa1b 100644 (file)
@@ -199,6 +199,12 @@ static int disk_try_backend(disk_try_backend_args *a,
         if (libxl_defbool_val(a->disk->colo_enable))
             goto bad_colo;
 
+        if (a->disk->format == LIBXL_DISK_FORMAT_EMPTY) {
+            LOG(DEBUG, "Disk vdev=%s is empty, skipping physical device check",
+                a->disk->vdev);
+            return backend;
+        }
+
         if (a->disk->backend_domid != LIBXL_TOOLSTACK_DOMID) {
             LOG(DEBUG, "Disk vdev=%s, is using a storage driver domain, "
                        "skipping physical device check", a->disk->vdev);
@@ -284,6 +290,12 @@ int libxl__device_disk_set_backend(libxl__gc *gc, libxl_device_disk *disk) {
             LOG(ERROR, "Disk vdev=%s is empty but not cdrom", disk->vdev);
             return ERROR_INVAL;
         }
+        if (disk->pdev_path != NULL && strcmp(disk->pdev_path, "")) {
+            LOG(ERROR,
+                "Disk vdev=%s is empty but an image has been provided: %s",
+                disk->vdev, disk->pdev_path);
+            return ERROR_INVAL;
+        }
         memset(&a.stab, 0, sizeof(a.stab));
     } else if ((disk->backend == LIBXL_DISK_BACKEND_UNKNOWN ||
                 disk->backend == LIBXL_DISK_BACKEND_PHY) &&