@@ -86,6 +86,12 @@ class VirtualDisk(VirtualDevice):
8686 driver_types = [DRIVER_TAP_RAW , DRIVER_TAP_QCOW ,
8787 DRIVER_TAP_VMDK , DRIVER_TAP_VDISK ]
8888
89+ CACHE_MODE_NONE = "none"
90+ CACHE_MODE_WRITETHROUGH = "writethrough"
91+ CACHE_MODE_WRITEBACK = "writeback"
92+ cache_types = [CACHE_MODE_NONE , CACHE_MODE_WRITETHROUGH ,
93+ CACHE_MODE_WRITEBACK ]
94+
8995 DEVICE_DISK = "disk"
9096 DEVICE_CDROM = "cdrom"
9197 DEVICE_FLOPPY = "floppy"
@@ -98,7 +104,8 @@ class VirtualDisk(VirtualDevice):
98104 def __init__ (self , path = None , size = None , transient = False , type = None ,
99105 device = DEVICE_DISK , driverName = None , driverType = None ,
100106 readOnly = False , sparse = True , conn = None , volObject = None ,
101- volInstall = None , volName = None , bus = None , shareable = False ):
107+ volInstall = None , volName = None , bus = None , shareable = False ,
108+ driverCache = None ):
102109 """
103110 @param path: filesystem path to the disk image.
104111 @type path: C{str}
@@ -131,6 +138,8 @@ def __init__(self, path=None, size=None, transient=False, type=None,
131138 @type bus: C{str}
132139 @param shareable: If disk can be shared among VMs
133140 @type shareable: C{bool}
141+ @param driverCache: Disk cache mode (none, writethrough, writeback)
142+ @type driverCache: member of cache_types
134143 """
135144
136145 VirtualDevice .__init__ (self , conn = conn )
@@ -145,6 +154,7 @@ def __init__(self, path=None, size=None, transient=False, type=None,
145154 self ._vol_install = None
146155 self ._bus = None
147156 self ._shareable = None
157+ self ._driver_cache = None
148158
149159 # XXX: No property methods for these
150160 self .transient = transient
@@ -162,6 +172,7 @@ def __init__(self, path=None, size=None, transient=False, type=None,
162172 self ._set_vol_install (volInstall , validate = False )
163173 self ._set_bus (bus , validate = False )
164174 self ._set_shareable (shareable , validate = False )
175+ self ._set_driver_cache (driverCache , validate = False )
165176
166177 if volName :
167178 self .__lookup_vol_name (volName )
@@ -272,6 +283,16 @@ def _set_shareable(self, val, validate=True):
272283 self .__validate_wrapper ("_shareable" , val , validate )
273284 shareable = property (_get_shareable , _set_shareable )
274285
286+ def _get_driver_cache (self ):
287+ return self ._driver_cache
288+ def _set_driver_cache (self , val , validate = True ):
289+ if val is not None :
290+ self ._check_str (val , "cache" )
291+ if val not in self .cache_types :
292+ raise ValueError , _ ("Unknown cache mode '%s'" % val )
293+ self .__validate_wrapper ("_driver_cache" , val , validate )
294+ driver_cache = property (_get_driver_cache , _set_driver_cache )
295+
275296 # Validation assistance methods
276297
277298 # Initializes attribute if it hasn't been done, then validates args.
@@ -657,13 +678,21 @@ def get_xml_config(self, disknode=None):
657678
658679 ret = " <disk type='%s' device='%s'>\n " % (self .type , self .device )
659680
681+ dname = self .driver_name
682+ if not dname and self .driver_cache :
683+ self .driver_name = "qemu"
684+
660685 if not self .driver_name is None :
661686 dtypexml = ""
662687 if not self .driver_type is None :
663688 dtypexml = " type='%s'" % self .driver_type
664689
665- ret += " <driver name='%s'%s/>\n " % (self .driver_name ,
666- dtypexml )
690+ dcachexml = ""
691+ if not self .driver_cache is None :
692+ dcachexml = " cache='%s'" % self .driver_cache
693+
694+ ret += " <driver name='%s'%s%s/>\n " % (self .driver_name ,
695+ dtypexml , dcachexml )
667696
668697 if path is not None :
669698 ret += " <source %s='%s'/>\n " % (typeattr , path )
0 commit comments