File libxl-support-block-script.patch of Package libvirt.3100

libxl: set script field of libxl_device_disk

Add a hack to the libvirt libxl driver to set
libxl_device_disk->script when the disk configuration starts
with some well-known Xen external block scripts: dmmd, drbd,
and npiv.

For more details, see bsc#954872

Index: libvirt-1.2.18.4/src/libxl/libxl_conf.c
===================================================================
--- libvirt-1.2.18.4.orig/src/libxl/libxl_conf.c
+++ libvirt-1.2.18.4/src/libxl/libxl_conf.c
@@ -905,6 +905,25 @@ libxlDiskSetCacheMode(libxl_device_disk
     }
 }
 
+static int
+libxlDiskSetScript(libxl_device_disk *x_disk, const char *disk_spec)
+{
+    if (disk_spec == NULL)
+        return 0;
+
+    if (STRPREFIX(disk_spec, "dmmd:")) {
+        if (VIR_STRDUP(x_disk->script, "block-dmmd") < 0)
+            return -1;
+    } else if (STRPREFIX(disk_spec, "drbd:")) {
+        if (VIR_STRDUP(x_disk->script, "block-drbd") < 0)
+            return -1;
+    } else if (STRPREFIX(disk_spec, "npiv:")) {
+        if (VIR_STRDUP(x_disk->script, "block-npiv") < 0)
+            return -1;
+    }
+    return 0;
+}
+
 #define LIBXL_QEMU_DM_STR  "Options specific to the Xen version:"
 
 int
@@ -939,12 +958,13 @@ libxlDomainGetEmulatorType(const virDoma
 int
 libxlMakeDisk(virDomainDiskDefPtr l_disk, libxl_device_disk *x_disk)
 {
+    const char *src = virDomainDiskGetSource(l_disk);
     const char *driver;
     int format;
 
     libxl_device_disk_init(x_disk);
 
-    if (VIR_STRDUP(x_disk->pdev_path, virDomainDiskGetSource(l_disk)) < 0)
+    if (VIR_STRDUP(x_disk->pdev_path, src) < 0)
         return -1;
 
     if (VIR_STRDUP(x_disk->vdev, l_disk->dst) < 0)
@@ -1053,6 +1073,9 @@ libxlMakeDisk(virDomainDiskDefPtr l_disk
     if (libxlDiskSetDiscard(x_disk, l_disk->discard) < 0)
         return -1;
     libxlDiskSetCacheMode(x_disk, l_disk->cachemode);
+    if (libxlDiskSetScript(x_disk, src) < 0)
+        return -1;
+
     /* An empty CDROM must have the empty format, otherwise libxl fails. */
     if (x_disk->is_cdrom && !x_disk->pdev_path)
         x_disk->format = LIBXL_DISK_FORMAT_EMPTY;