diff --git a/drivers/blktap2.py b/drivers/blktap2.py index 7ee2b77e4..ea1eea316 100755 --- a/drivers/blktap2.py +++ b/drivers/blktap2.py @@ -977,8 +977,29 @@ def __init__(self, uuid, target, driver_info): self._vdi_uuid = uuid self._session = target.session self.xenstore_data = scsiutil.update_XS_SCSIdata(uuid,scsiutil.gen_synthetic_page_data(uuid)) + self.__o_direct = None self.lock = Lock("vdi", uuid) + def get_o_direct_capability(self, options = {}): + """Returns True/False based on licensing and caching_params""" + if self.__o_direct is not None: + return self.__o_direct + + if not util.read_caching_is_restricted(self._session): + self.__o_direct = options.get(self.CONF_KEY_O_DIRECT) + if self.__o_direct is not None: + return self.__o_direct + if (self.target.vdi.sr.handles("nfs") or + self.target.vdi.sr.handles("ext")): + from FileSR import FileVDI + if vhdutil.getParent(self.target.vdi.path, FileVDI.extractUuid): + self.__o_direct = False + + if self.__o_direct is None: + self.__o_direct = True + + return self.__o_direct + @classmethod def from_cli(cls, uuid): import VDI as sm @@ -1469,6 +1490,7 @@ def attach(self, sr_uuid, vdi_uuid, writable, activate = False): # Return backend/ link back_path = self.BackendLink.from_uuid(sr_uuid, vdi_uuid).path() struct = { 'params': back_path, + 'o_direct': self.get_o_direct_capability(), 'xenstore_data': self.xenstore_data} util.SMlog('result: %s' % struct) @@ -1562,12 +1584,7 @@ def _activate(self, sr_uuid, vdi_uuid, options): # Maybe launch a tapdisk on the physical link if self.tap_wanted(): vdi_type = self.target.get_vdi_type() - if util.read_caching_is_restricted(self._session): - options["o_direct"] = True - else: - options["o_direct"] = options.get(self.CONF_KEY_O_DIRECT) - if options["o_direct"] is None: - options["o_direct"] = True + options["o_direct"] = self.get_o_direct_capability(options) dev_path = self._tap_activate(phy_path, vdi_type, sr_uuid, options, self._get_pool_config(sr_uuid).get("mem-pool-size"))