File libxl-set-cach-mode.patch of Package libvirt.11695

https://bugzilla.novell.com/show_bug.cgi?id=879425
---
 src/libxl/libxl_conf.c |   26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

Index: libvirt-1.2.5/src/libxl/libxl_conf.c
===================================================================
--- libvirt-1.2.5.orig/src/libxl/libxl_conf.c
+++ libvirt-1.2.5/src/libxl/libxl_conf.c
@@ -842,6 +842,31 @@ libxlDiskSetDiscard(libxl_device_disk *x
 #endif
 }
 
+static void
+libxlDiskSetCacheMode(libxl_device_disk *x_disk, int cachemode)
+{
+    switch (cachemode) {
+#if defined(LIBXL_HAVE_LIBXL_DEVICE_DISK_DISABLE_FLUSH_MAGIC)
+    case VIR_DOMAIN_DISK_CACHE_UNSAFE:
+        if (x_disk->readwrite)
+            x_disk->readwrite = (x_disk->readwrite & LIBXL_HAVE_LIBXL_DEVICE_DISK_DISABLE_FLUSH_MASK) | LIBXL_HAVE_LIBXL_DEVICE_DISK_DISABLE_FLUSH_MAGIC;
+        break;
+#endif
+#if defined(LIBXL_HAVE_LIBXL_DEVICE_DISK_DIRECT_IO_SAFE_MAGIC)
+    case VIR_DOMAIN_DISK_CACHE_DIRECTSYNC:
+        if (x_disk->readwrite)
+            x_disk->readwrite = (x_disk->readwrite & LIBXL_HAVE_LIBXL_DEVICE_DISK_DIRECT_IO_SAFE_MASK) | LIBXL_HAVE_LIBXL_DEVICE_DISK_DIRECT_IO_SAFE_MAGIC;
+        break;
+#endif
+    case VIR_DOMAIN_DISK_CACHE_DEFAULT:
+    case VIR_DOMAIN_DISK_CACHE_DISABLE:
+    case VIR_DOMAIN_DISK_CACHE_WRITETHRU:
+    case VIR_DOMAIN_DISK_CACHE_WRITEBACK:
+    default:
+        break;
+    }
+}
+
 #define LIBXL_QEMU_DM_STR  "Options specific to the Xen version:"
 
 int
@@ -987,6 +1012,7 @@ libxlMakeDisk(virDomainDiskDefPtr l_disk
     x_disk->removable = 1;
     x_disk->readwrite = !l_disk->readonly;
     libxlDiskSetDiscard(x_disk, l_disk->discard);
+    libxlDiskSetCacheMode(x_disk, l_disk->cachemode);
     x_disk->is_cdrom = l_disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM ? 1 : 0;
     /* An empty CDROM must have the empty format, otherwise libxl fails. */
     if (x_disk->is_cdrom && !x_disk->pdev_path)