KVM: use cache=none for shared disk templates
authorApollon Oikonomopoulos <apollon@noc.grnet.gr>
Mon, 28 Feb 2011 11:51:14 +0000 (13:51 +0200)
committerIustin Pop <iustin@google.com>
Tue, 8 Mar 2011 12:01:40 +0000 (13:01 +0100)
Disable host cache for externally mirrored disks to avoid cache incoherency.
Without this, migrations between the same two nodes may end up in disk
corruption.

This is a runtime override of cluster defaults, mostly a workaround.
Unfortunately, we cannot use cmdlib._CheckHVParams, as we want to check the
hypervisor parameters *in conjunction* with the disk template, which is part of
the instance definition.

Signed-off-by: Apollon Oikonomopoulos <apollon@noc.grnet.gr>
Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>

lib/hypervisor/hv_kvm.py

index 3e9e025..aef5fe1 100644 (file)
@@ -1,7 +1,7 @@
 #
 #
 
-# Copyright (C) 2008, 2009, 2010 Google Inc.
+# Copyright (C) 2008, 2009, 2010, 2011 Google Inc.
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -534,7 +534,14 @@ class KVMHypervisor(hv_base.BaseHypervisor):
       if_val = ',if=%s' % disk_type
     # Cache mode
     disk_cache = hvp[constants.HV_DISK_CACHE]
-    if disk_cache != constants.HT_CACHE_DEFAULT:
+    if instance.disk_template in constants.DTS_EXT_MIRROR:
+      if disk_cache != "none":
+        # TODO: make this a hard error, instead of a silent overwrite
+        logging.warning("KVM: overriding disk_cache setting '%s' with 'none'"
+                        " to prevent shared storage corruption on migration",
+                        disk_cache)
+      cache_val = ",cache=none"
+    elif disk_cache != constants.HT_CACHE_DEFAULT:
       cache_val = ",cache=%s" % disk_cache
     else:
       cache_val = ""