Skip to content

Commit 86a988b

Browse files
committed
CP-10986: Return read caching status on VDI.attach
Returning the status of read caching during VDI Attach is a bit tricky. This is because the SM only works out whether or not O_DIRECT should be used during VDI Activate (which happens after attach). This is determined by a number of elements: licensing, override parameters or VDI Type, etc. This patch isolates this check in a separate (private) method and caches it. Both VDI attach and activate use this method to work out whether tapdisk will be enabling read caching or not. We also add this information to the return struct in VDI.attach as requested by the ticket. Signed-off-by: Siddharth Vinothkumar <siddharth.vinothkumar@citrix.com> Acked-by: Felipe Franciosi <felipe@paradoxo.org> Github: closes #242 on xapi-project/sm
1 parent 38c9a0e commit 86a988b

1 file changed

Lines changed: 23 additions & 6 deletions

File tree

drivers/blktap2.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -977,8 +977,29 @@ def __init__(self, uuid, target, driver_info):
977977
self._vdi_uuid = uuid
978978
self._session = target.session
979979
self.xenstore_data = scsiutil.update_XS_SCSIdata(uuid,scsiutil.gen_synthetic_page_data(uuid))
980+
self.__o_direct = None
980981
self.lock = Lock("vdi", uuid)
981982

983+
def get_o_direct_capability(self, options = {}):
984+
"""Returns True/False based on licensing and caching_params"""
985+
if self.__o_direct is not None:
986+
return self.__o_direct
987+
988+
if not util.read_caching_is_restricted(self._session):
989+
self.__o_direct = options.get(self.CONF_KEY_O_DIRECT)
990+
if self.__o_direct is not None:
991+
return self.__o_direct
992+
if (self.target.vdi.sr.handles("nfs") or
993+
self.target.vdi.sr.handles("ext")):
994+
from FileSR import FileVDI
995+
if vhdutil.getParent(self.target.vdi.path, FileVDI.extractUuid):
996+
self.__o_direct = False
997+
998+
if self.__o_direct is None:
999+
self.__o_direct = True
1000+
1001+
return self.__o_direct
1002+
9821003
@classmethod
9831004
def from_cli(cls, uuid):
9841005
import VDI as sm
@@ -1469,6 +1490,7 @@ def attach(self, sr_uuid, vdi_uuid, writable, activate = False):
14691490
# Return backend/ link
14701491
back_path = self.BackendLink.from_uuid(sr_uuid, vdi_uuid).path()
14711492
struct = { 'params': back_path,
1493+
'o_direct': self.get_o_direct_capability(),
14721494
'xenstore_data': self.xenstore_data}
14731495
util.SMlog('result: %s' % struct)
14741496

@@ -1562,12 +1584,7 @@ def _activate(self, sr_uuid, vdi_uuid, options):
15621584
# Maybe launch a tapdisk on the physical link
15631585
if self.tap_wanted():
15641586
vdi_type = self.target.get_vdi_type()
1565-
if util.read_caching_is_restricted(self._session):
1566-
options["o_direct"] = True
1567-
else:
1568-
options["o_direct"] = options.get(self.CONF_KEY_O_DIRECT)
1569-
if options["o_direct"] is None:
1570-
options["o_direct"] = True
1587+
options["o_direct"] = self.get_o_direct_capability(options)
15711588
dev_path = self._tap_activate(phy_path, vdi_type, sr_uuid,
15721589
options,
15731590
self._get_pool_config(sr_uuid).get("mem-pool-size"))

0 commit comments

Comments
 (0)