Skip to content

Commit

Permalink
CP-10986: Return read caching status on VDI.attach
Browse files Browse the repository at this point in the history
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
  • Loading branch information
siddharthv committed Mar 4, 2015
1 parent 38c9a0e commit 86a988b
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions drivers/blktap2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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"))
Expand Down

0 comments on commit 86a988b

Please sign in to comment.