From c1f98a666c5f159c505494ebb1581bee61fbe510 Mon Sep 17 00:00:00 2001
From: Filippos Giannakos <philipgian@grnet.gr>
Date: Fri, 30 Jun 2017 11:20:28 +0300
Subject: [PATCH] Enhance cache settings for userspace URI

---
 ext_scripts/ext_rbd.py | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/ext_scripts/ext_rbd.py b/ext_scripts/ext_rbd.py
index dce1c74..38f576a 100755
--- a/ext_scripts/ext_rbd.py
+++ b/ext_scripts/ext_rbd.py
@@ -301,9 +301,17 @@ def format_qemu_uri(name, pool=None, cephx=None, conf_file=None, cache=None,
         extra_conf += ':id=%s' % cephx['id']
     if conf_file:
         extra_conf += ':conf=%s' % conf_file
-    # TODO: we need to revisit this, to support more caching modes correctly.
-    if cache in ['writeback']:
+    # We need to set these here to override the settings in 'ceph.conf'
+    # They are consistent with how QEMU treats the cache settings for an RBD
+    # drive.
+    if cache in ['writeback', 'writethrough', 'unsafe']:
         extra_conf += ':rbd_cache=true'
+    if cache == 'writethrough':
+        # To ensure that the cache is set in writethrough mode.
+        # QEMU alone, does not set this value when 'cache=writethrough' is set,
+        # although if 'ceph.conf' does not says otherwise, 'rbd_cache' is set
+        # to true.
+        extra_conf += ':rbd_cache_max_dirty=0'
     for k, v in kwargs.iteritems():
         extra_conf += ':%s=%s' % (k, v)
 
-- 
GitLab