Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 31 additions & 40 deletions libs/sm/blktap2.py
Original file line number Diff line number Diff line change
Expand Up @@ -994,8 +994,6 @@ def get_o_direct_capability(self, options):

@classmethod
def from_cli(cls, uuid):
import VDI as sm

session = XenAPI.xapi_local()
session.xenapi.login_with_password('root', '', '', 'SM')

Expand Down Expand Up @@ -1608,7 +1606,7 @@ def _deactivate(self, sr_uuid, vdi_uuid, caching_params):

minor = nbd_link.read_minor_from_path()
self._tap_deactivate(minor)
self.remove_cache(sr_uuid, vdi_uuid, caching_params)
self.remove_cache(caching_params)

# Remove the backend link
nbd_link.unlink()
Expand Down Expand Up @@ -1717,20 +1715,14 @@ def _setup_cache(self, session, sr_uuid, vdi_uuid, local_sr_uuid,
scratch_mode, options):
from sm import SR
from sm.drivers import EXTSR
from sm.drivers import NFSSR
from sm.core.lock import Lock
from sm.drivers.FileSR import FileVDI

parent_uuid = vhdutil.getParent(self.target.vdi.path,
FileVDI.extractUuid)
if not parent_uuid:
util.SMlog("ERROR: VDI %s has no parent, not enabling" % \
self.target.vdi.uuid)

if self._no_parent(self.target.vdi):
util.SMlog("ERROR: VDI %s has no parent, not enabling" %
self.target.vdi.uuid)
return

util.SMlog("Setting up cache")
parent_uuid = parent_uuid.strip()
shared_target = NFSSR.NFSFileVDI(self.target.vdi.sr, parent_uuid)
shared_target = self.target.vdi.sr.vdi(self.target.vdi.parent)

if shared_target.parent:
util.SMlog("ERROR: Parent VDI %s has parent, not enabling" %
Expand All @@ -1740,14 +1732,14 @@ def _setup_cache(self, session, sr_uuid, vdi_uuid, local_sr_uuid,
SR.registerSR(EXTSR.EXTSR)
local_sr = SR.SR.from_uuid(session, local_sr_uuid)

lock = Lock(self.LOCK_CACHE_SETUP, parent_uuid)
lock = Lock(self.LOCK_CACHE_SETUP, shared_target.uuid)
lock.acquire()

# read cache
read_cache_path = "%s/%s.vhdcache" % (local_sr.path, shared_target.uuid)
if util.pathexists(read_cache_path):
util.SMlog("Read cache node (%s) already exists, not creating" % \
read_cache_path)
util.SMlog("Read cache node (%s) already exists, not creating" %
read_cache_path)
else:
try:
vhdutil.snapshot(read_cache_path, shared_target.path, False)
Expand All @@ -1761,8 +1753,8 @@ def _setup_cache(self, session, sr_uuid, vdi_uuid, local_sr_uuid,
local_leaf_path = "%s/%s.vhdcache" % \
(local_sr.path, self.target.vdi.uuid)
if util.pathexists(local_leaf_path):
util.SMlog("Local leaf node (%s) already exists, deleting" % \
local_leaf_path)
util.SMlog("Local leaf node (%s) already exists, deleting" %
local_leaf_path)
os.unlink(local_leaf_path)
try:
vhdutil.snapshot(local_leaf_path, read_cache_path, False,
Expand All @@ -1775,11 +1767,9 @@ def _setup_cache(self, session, sr_uuid, vdi_uuid, local_sr_uuid,
local_leaf_size = vhdutil.getSizeVirt(local_leaf_path)
if leaf_size > local_leaf_size:
util.SMlog("Leaf size %d > local leaf cache size %d, resizing" %
(leaf_size, local_leaf_size))
(leaf_size, local_leaf_size))
vhdutil.setSizeVirtFast(local_leaf_path, leaf_size)

vdi_type = self.target.get_vdi_type()

prt_tapdisk = Tapdisk.find_by_path(read_cache_path)
if not prt_tapdisk:
parent_options = copy.deepcopy(options)
Expand All @@ -1796,7 +1786,7 @@ def _setup_cache(self, session, sr_uuid, vdi_uuid, local_sr_uuid,
raise

secondary = "%s:%s" % (self.target.get_vdi_type(),
self.PhyLink.from_uuid(sr_uuid, vdi_uuid).readlink())
(self.PhyLink.from_uuid(sr_uuid, vdi_uuid).readlink()))

util.SMlog("Parent tapdisk: %s" % prt_tapdisk)
leaf_tapdisk = Tapdisk.find_by_path(local_leaf_path)
Expand All @@ -1808,6 +1798,8 @@ def _setup_cache(self, session, sr_uuid, vdi_uuid, local_sr_uuid,
child_options["existing_prt"] = prt_tapdisk.minor
child_options["secondary"] = secondary
child_options["standby"] = scratch_mode
# Disable memory read caching
child_options.pop("o_direct", None)
try:
leaf_tapdisk = \
Tapdisk.launch_on_tap(blktap, local_leaf_path,
Expand All @@ -1818,13 +1810,13 @@ def _setup_cache(self, session, sr_uuid, vdi_uuid, local_sr_uuid,

lock.release()

util.SMlog("Local read cache: %s, local leaf: %s" % \
(read_cache_path, local_leaf_path))
util.SMlog("Local read cache: %s, local leaf: %s" %
(read_cache_path, local_leaf_path))

self.tap = leaf_tapdisk
return leaf_tapdisk.get_devpath()

def remove_cache(self, sr_uuid, vdi_uuid, params):
def remove_cache(self, params):
if not self.target.has_cap("SR_CACHING"):
return

Expand Down Expand Up @@ -1861,26 +1853,20 @@ def _is_tapdisk_in_use(self, minor):
def _remove_cache(self, session, local_sr_uuid):
from sm import SR
from sm.drivers import EXTSR
from sm.drivers import NFSSR
from sm.core.lock import Lock
from sm.drivers.FileSR import FileVDI

parent_uuid = vhdutil.getParent(self.target.vdi.path,
FileVDI.extractUuid)
if not parent_uuid:
util.SMlog("ERROR: No parent for VDI %s, ignore" % \
self.target.vdi.uuid)

if self._no_parent(self.target.vdi):
util.SMlog("ERROR: No parent for VDI %s, ignore" %
self.target.vdi.uuid)
return

util.SMlog("Tearing down the cache")

parent_uuid = parent_uuid.strip()
shared_target = NFSSR.NFSFileVDI(self.target.vdi.sr, parent_uuid)
shared_target = self.target.vdi.sr.vdi(self.target.vdi.parent)

SR.registerSR(EXTSR.EXTSR)
local_sr = SR.SR.from_uuid(session, local_sr_uuid)

lock = Lock(self.LOCK_CACHE_SETUP, parent_uuid)
lock = Lock(self.LOCK_CACHE_SETUP, shared_target.uuid)
lock.acquire()

# local write node
Expand All @@ -1895,8 +1881,8 @@ def _remove_cache(self, session, local_sr_uuid):
if not prt_tapdisk:
util.SMlog("Parent tapdisk not found")
elif not self._is_tapdisk_in_use(prt_tapdisk.minor):
util.SMlog("Parent tapdisk not in use: shutting down %s" % \
read_cache_path)
util.SMlog("Parent tapdisk not in use: shutting down %s" %
read_cache_path)
try:
prt_tapdisk.shutdown()
except:
Expand All @@ -1908,6 +1894,11 @@ def _remove_cache(self, session, local_sr_uuid):

lock.release()

@staticmethod
def _no_parent(vdi):
return vdi.parent is None or vdi.parent == ''


PythonKeyError = KeyError


Expand Down
6 changes: 5 additions & 1 deletion libs/sm/drivers/LVHDSR.py
Original file line number Diff line number Diff line change
Expand Up @@ -2006,12 +2006,16 @@ def _initFromLVInfo(self, lvInfo):
self.sm_config_override["vdi_type"] = self.vdi_type
else:
self.sm_config_override = {'vdi_type': self.vdi_type}
if 'vhd-parent' in self.sm_config_override:
self.parent = self.sm_config_override['vhd-parent']
if self.vdi_type == vhdutil.VDI_TYPE_RAW:
self.loaded = True

def _initFromVHDInfo(self, vhdInfo):
self.size = vhdInfo.sizeVirt
self.parent = vhdInfo.parentUuid
if (self.parent == '' or (vhdInfo.parentUuid != ''
and vhdInfo.parentUuid != self.parent)):
self.parent = vhdInfo.parentUuid
self.hidden = vhdInfo.hidden
self.loaded = True

Expand Down
2 changes: 1 addition & 1 deletion libs/sm/drivers/LVHDoHBASR.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from sm.core import scsiutil
from sm.core import mpath_cli

CAPABILITIES = ["SR_PROBE", "SR_UPDATE", "SR_METADATA", "SR_TRIM",
CAPABILITIES = ["SR_PROBE", "SR_UPDATE", "SR_METADATA", "SR_TRIM", "SR_CACHING",
"VDI_CREATE", "VDI_DELETE", "VDI_ATTACH", "VDI_DETACH",
"VDI_GENERATE_CONFIG", "VDI_SNAPSHOT", "VDI_CLONE", "VDI_MIRROR",
"VDI_RESIZE", "ATOMIC_PAUSE", "VDI_RESET_ON_BOOT/2",
Expand Down
2 changes: 1 addition & 1 deletion libs/sm/drivers/LVHDoISCSISR.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import copy
import xml.dom.minidom

CAPABILITIES = ["SR_PROBE", "SR_UPDATE", "SR_METADATA", "SR_TRIM",
CAPABILITIES = ["SR_PROBE", "SR_UPDATE", "SR_METADATA", "SR_TRIM", "SR_CACHING",
"VDI_CREATE", "VDI_DELETE", "VDI_ATTACH", "VDI_DETACH",
"VDI_GENERATE_CONFIG", "VDI_CLONE", "VDI_SNAPSHOT",
"VDI_RESIZE", "ATOMIC_PAUSE", "VDI_RESET_ON_BOOT/2",
Expand Down
Loading
Loading