Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CA-144169: Removing unneeded XAPI calls for VBD.plug operation. #285

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 1 addition & 2 deletions drivers/FileSR.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ def handles(srtype):

def _check_o_direct(self):
if self.sr_ref and self.session is not None:
other_config = self.session.xenapi.SR.get_other_config(self.sr_ref)
o_direct = other_config.get("o_direct")
o_direct = self.other_conf.get("o_direct")
self.o_direct = o_direct is not None and o_direct == "true"
else:
self.o_direct = True
Expand Down
4 changes: 2 additions & 2 deletions drivers/LVHDSR.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ def load(self, sr_uuid):
raise xs_errors.XenError('InvalidArg', \
opterr='Allocation parameter must be one of %s' % self.PROVISIONING_TYPES)

self.other_conf = self.session.xenapi.SR.get_other_config(self.sr_ref)
if self.other_conf.get(self.TEST_MODE_KEY):
self.testMode = self.other_conf[self.TEST_MODE_KEY]
self._prepareTestMode()
Expand Down Expand Up @@ -2513,7 +2512,8 @@ def _prepareThin(self, attach):
lvhdutil.attachThin(self.sr.journaler, self.sr.uuid, self.uuid)
else:
lvhdutil.detachThin(self.session, self.sr.lvmCache,
self.sr.uuid, self.uuid)
self.sr.uuid, self.uuid,
self.sr.srcmd.params["vdi_ref"])
else:
fn = "attach"
if not attach:
Expand Down
3 changes: 2 additions & 1 deletion drivers/NFSSR.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ def attach(self, sr_uuid):
if not self._checkmount():
self.validate_remotepath(False)
util._testHost(self.dconf['server'], NFSPORT, 'NFSTarget')
io_timeout = util.get_nfs_timeout(self.session, sr_uuid)
io_timeout = util.get_nfs_timeout(self.session,
self.other_conf)
self.mount_remotepath(sr_uuid, io_timeout)
self.attached = True

Expand Down
17 changes: 12 additions & 5 deletions drivers/SR.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ def __init__(self, srcmd, sr_uuid):

self.sr_ref = self.srcmd.params.get('sr_ref')

if not self.session is None:
self.other_conf = self.session.xenapi.SR.get_other_config(self.sr_ref)
else:
self.other_conf = None

if 'device_config' in self.srcmd.params:
if self.dconf.get("SRmaster") == "true":
os.environ['LVM_SYSTEM_DIR'] = MASTER_LVM_CONF
Expand Down Expand Up @@ -141,11 +146,12 @@ def __init__(self, srcmd, sr_uuid):
self.load(sr_uuid)

@staticmethod
def from_uuid(session, sr_uuid):
def from_uuid(session, sr_uuid, sr_ref=None, host_ref=None):
import imp

_SR = session.xenapi.SR
sr_ref = _SR.get_by_uuid(sr_uuid)
if sr_ref is None:
sr_ref = _SR.get_by_uuid(sr_uuid)
sm_type = _SR.get_type(sr_ref)

# NB. load the SM driver module
Expand All @@ -155,7 +161,7 @@ def from_uuid(session, sr_uuid):
sm_ref, sm = sms.popitem()
assert not sms

driver_path = _SM.get_driver_filename(sm_ref)
driver_path = sm['driver_filename']
driver_real = os.path.realpath(driver_path)
module_name = os.path.basename(driver_path)

Expand All @@ -164,15 +170,16 @@ def from_uuid(session, sr_uuid):

# NB. get the host pbd's device_config

host_ref = util.get_localhost_uuid(session)
if host_ref is None:
host_ref = util.get_localhost_uuid(session)

_PBD = session.xenapi.PBD
pbds = _PBD.get_all_records_where('field "SR" = "%s" and' % sr_ref +
'field "host" = "%s"' % host_ref)
pbd_ref, pbd = pbds.popitem()
assert not pbds

device_config = _PBD.get_device_config(pbd_ref)
device_config = pbd['device_config']

# NB. make srcmd, to please our supersized SR constructor.
# FIXME
Expand Down
21 changes: 14 additions & 7 deletions drivers/VDI.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,23 @@ def __init__(self, sr, uuid):
self.load(uuid)

@staticmethod
def from_uuid(session, vdi_uuid):
def from_uuid(session, vdi_uuid, cmd_params=None):

_VDI = session.xenapi.VDI
vdi_ref = _VDI.get_by_uuid(vdi_uuid)
sr_ref = _VDI.get_SR(vdi_ref)
if cmd_params is None:
_VDI = session.xenapi.VDI
vdi_ref = _VDI.get_by_uuid(vdi_uuid)
sr_ref = _VDI.get_SR(vdi_ref)

_SR = session.xenapi.SR
sr_uuid = _SR.get_uuid(sr_ref)
_SR = session.xenapi.SR
sr_uuid = _SR.get_uuid(sr_ref)
host_ref = None
else:
vdi_ref = cmd_params["vdi_ref"]
sr_ref = cmd_params["sr_ref"]
sr_uuid = cmd_params["sr_uuid"]
host_ref = cmd_params["host_ref"]

sr = SR.SR.from_uuid(session, sr_uuid)
sr = SR.SR.from_uuid(session, sr_uuid, sr_ref, host_ref)

sr.srcmd.params['vdi_ref'] = vdi_ref
return sr.vdi(vdi_uuid)
Expand Down
70 changes: 48 additions & 22 deletions drivers/blktap2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1410,18 +1410,21 @@ def call_pluginhandler(cls, session, host_ref, sr_uuid, vdi_uuid, action,

def _add_tag(self, vdi_uuid, writable):
util.SMlog("Adding tag to: %s" % vdi_uuid)
params = self.target.vdi.sr.srcmd.params
attach_mode = "RO"
if writable:
attach_mode = "RW"
vdi_ref = self._session.xenapi.VDI.get_by_uuid(vdi_uuid)
host_ref = self._session.xenapi.host.get_by_uuid(util.get_this_host())
vdi_ref = params["vdi_ref"]
host_ref = params["host_ref"]
sr_ref = params["sr_ref"]
sm_config = self._session.xenapi.VDI.get_sm_config(vdi_ref)
attached_as = util.attached_as(sm_config)
if NO_MULTIPLE_ATTACH and (attached_as == "RW" or \
(attached_as == "RO" and attach_mode == "RW")):
util.SMlog("need to reset VDI %s" % vdi_uuid)
if not resetvdis.reset_vdi(self._session, vdi_uuid, force=False,
term_output=False, writable=writable):
term_output=False, writable=writable, vdi_ref=vdi_ref,
sr_ref=sr_ref, sm_config=sm_config):
raise util.SMException("VDI %s not detached cleanly" % vdi_uuid)
sm_config = self._session.xenapi.VDI.get_sm_config(vdi_ref)
if sm_config.has_key('paused'):
Expand Down Expand Up @@ -1451,8 +1454,9 @@ def _check_tag(self, vdi_uuid):
return True

def _remove_tag(self, vdi_uuid):
vdi_ref = self._session.xenapi.VDI.get_by_uuid(vdi_uuid)
host_ref = self._session.xenapi.host.get_by_uuid(util.get_this_host())
params = self.target.vdi.sr.srcmd.params
vdi_ref = params["vdi_ref"]
host_ref = params["host_ref"]
sm_config = self._session.xenapi.VDI.get_sm_config(vdi_ref)
host_key = "host_%s" % host_ref
if sm_config.has_key(host_key):
Expand All @@ -1468,10 +1472,17 @@ def _get_pool_config(self, pool_name):
# attach_from_config context: HA disks don't need to be in any
# special pool
return pool_info
session = XenAPI.xapi_local()
session.xenapi.login_with_password('root', '', '', 'SM')
sr_ref = self.target.vdi.sr.srcmd.params.get('sr_ref')
sr_config = session.xenapi.SR.get_other_config(sr_ref)
new_session = False
session = self.target.vdi.sr.session
if session is None:
session = XenAPI.xapi_local()
session.xenapi.login_with_password('root', '', '', 'SM')
sr_ref = self.target.vdi.sr.srcmd.params.get('sr_ref')
sr_config = session.xenapi.SR.get_other_config(sr_ref)
new_session = True
else:
sr_config = self.target.vdi.sr.other_conf

vdi_config = session.xenapi.VDI.get_other_config(vdi_ref)
pool_size_str = sr_config.get(POOL_SIZE_KEY)
pool_name_override = vdi_config.get(POOL_NAME_KEY)
Expand All @@ -1495,7 +1506,9 @@ def _get_pool_config(self, pool_name):
if pool_size:
pool_info["mem-pool-size"] = str(pool_size)

session.xenapi.session.logout()
if new_session:
session.xenapi.session.logout()

return pool_info

def attach(self, sr_uuid, vdi_uuid, writable, activate = False, caching_params = {}):
Expand Down Expand Up @@ -1551,7 +1564,8 @@ def activate(self, sr_uuid, vdi_uuid, writable, caching_params):
# Tapdisk needs the allocation_quantum to be in MB
options["allocation_quantum"] = int(aq / (1024*1024))

timeout = util.get_nfs_timeout(self.target.vdi.session, sr_uuid)
timeout = util.get_nfs_timeout(self.target.vdi.session,
self.target.vdi.sr.other_conf)
if timeout:
options["timeout"] = timeout + self.TAPDISK_TIMEOUT_MARGIN
for i in range(self.ATTACH_DETACH_RETRY_SECS):
Expand All @@ -1577,7 +1591,8 @@ def _activate_locked(self, sr_uuid, vdi_uuid, options):
# path if it was leaf-coalesced onto a raw LV), so refresh the
# object completely
params = self.target.vdi.sr.srcmd.params
target = sm.VDI.from_uuid(self.target.vdi.session, vdi_uuid)
target = sm.VDI.from_uuid(self.target.vdi.session, vdi_uuid,
params)
target.sr.srcmd.params = params
driver_info = target.sr.srcmd.driver_info
self.target = self.TargetDriver(target, driver_info)
Expand Down Expand Up @@ -1757,15 +1772,18 @@ def _detach(self, sr_uuid, vdi_uuid):
# Remove phy/
self.PhyLink.from_uuid(sr_uuid, vdi_uuid).unlink()

def _updateCacheRecord(self, session, vdi_uuid, on_boot, caching):
def _updateCacheRecord(self, session, vdi_uuid, on_boot, caching,
vdi_ref):
# Remove existing VDI.sm_config fields
vdi_ref = session.xenapi.VDI.get_by_uuid(vdi_uuid)
sm_config = session.xenapi.VDI.get_sm_config(vdi_ref)
for key in ["on_boot", "caching"]:
session.xenapi.VDI.remove_from_sm_config(vdi_ref,key)
if key in sm_config.keys():
del sm_config[key]
if not on_boot is None:
session.xenapi.VDI.add_to_sm_config(vdi_ref,'on_boot',on_boot)
sm_config["on_boot"] = on_boot
if not caching is None:
session.xenapi.VDI.add_to_sm_config(vdi_ref,'caching',caching)
sm_config["caching"] = caching
session.xenapi.VDI.set_sm_config(vdi_ref,sm_config)

def setup_cache(self, sr_uuid, vdi_uuid, params):
if params.get(self.CONF_KEY_ALLOW_CACHING) != "true":
Expand All @@ -1784,8 +1802,12 @@ def setup_cache(self, sr_uuid, vdi_uuid, params):
util.SMlog("Error: scratch mode not supported by this SR")
return

session = XenAPI.xapi_local()
session.xenapi.login_with_password('root', '', '', 'SM')
session = self.target.vdi.sr.session
new_session = False
if session is None:
session = XenAPI.xapi_local()
session.xenapi.login_with_password('root', '', '', 'SM')
new_session = True

dev_path = None
local_sr_uuid = params.get(self.CONF_KEY_CACHE_SR)
Expand All @@ -1798,9 +1820,12 @@ def setup_cache(self, sr_uuid, vdi_uuid, params):
if dev_path:
self._updateCacheRecord(session, self.target.vdi.uuid,
params.get(self.CONF_KEY_MODE_ON_BOOT),
params.get(self.CONF_KEY_ALLOW_CACHING))
params.get(self.CONF_KEY_ALLOW_CACHING),
self.target.vdi.sr.srcmd.params["vdi_ref"])

if new_session:
session.xenapi.session.logout()

session.xenapi.session.logout()
return dev_path

def alert_no_cache(self, session, vdi_uuid, cache_sr_uuid, err):
Expand Down Expand Up @@ -1966,7 +1991,8 @@ def remove_cache(self, sr_uuid, vdi_uuid, params):
if caching:
self._remove_cache(self._session, local_sr_uuid)

self._updateCacheRecord(self._session, self.target.vdi.uuid, None, None)
self._updateCacheRecord(self._session, self.target.vdi.uuid, None, None,
self.target.vdi.sr.srcmd.params["vdi_ref"])

def _is_tapdisk_in_use(self, minor):
(retVal, links) = util.findRunningProcessOrOpenFile("tapdisk")
Expand Down
3 changes: 1 addition & 2 deletions drivers/lvhdutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,13 @@ def attachThin(journaler, srUuid, vdiUuid):
lvmCache.deactivate(NS_PREFIX_LVM + srUuid, vdiUuid, lvName, False)
lock.release()

def detachThin(session, lvmCache, srUuid, vdiUuid):
def detachThin(session, lvmCache, srUuid, vdiUuid, vdiRef):
"""Shrink the VDI to the minimal size if no one is using it"""
lvName = LV_PREFIX[vhdutil.VDI_TYPE_VHD] + vdiUuid
path = os.path.join(VG_LOCATION, VG_PREFIX + srUuid, lvName)
lock = Lock(vhdutil.LOCK_TYPE_SR, srUuid)
_tryAcquire(lock)

vdiRef = session.xenapi.VDI.get_by_uuid(vdiUuid)
vbds = session.xenapi.VBD.get_all_records_where( \
"field \"VDI\" = \"%s\"" % vdiRef)
numPlugged = 0
Expand Down
18 changes: 13 additions & 5 deletions drivers/resetvdis.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,18 @@ def reset_sr(session, host_uuid, sr_uuid, is_sr_master):
sr_lock.release()
gc_lock.release()

def reset_vdi(session, vdi_uuid, force, term_output=True, writable=True):
vdi_ref = session.xenapi.VDI.get_by_uuid(vdi_uuid)
vdi_rec = session.xenapi.VDI.get_record(vdi_ref)
sm_config = vdi_rec["sm_config"]
def reset_vdi(session, vdi_uuid, force, term_output=True, writable=True,
vdi_ref=None, sr_ref=None, sm_config=None):
if vdi_ref is None:
vdi_ref = session.xenapi.VDI.get_by_uuid(vdi_uuid)

if sm_config is None:
vdi_rec = session.xenapi.VDI.get_record(vdi_ref)
sm_config = vdi_rec["sm_config"]

if sr_ref is None:
sr_ref = vdi_rec["SR"]

host_ref = None
clean = True
for key, val in sm_config.iteritems():
Expand Down Expand Up @@ -96,7 +104,7 @@ def reset_vdi(session, vdi_uuid, force, term_output=True, writable=True):

ret = session.xenapi.host.call_plugin(
host_ref, "on-slave", "is_open",
{"vdiUuid": vdi_uuid, "srRef": vdi_rec["SR"]})
{"vdiUuid": vdi_uuid, "srRef": sr_ref})
if ret != "False":
util.SMlog("VDI %s is still open on host %s, not resetting" % \
(vdi_uuid, host_str))
Expand Down
7 changes: 2 additions & 5 deletions drivers/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,15 +668,12 @@ def get_all_slaves(session):
master_ref = get_this_host_ref(session)
return filter(lambda x: x != master_ref, host_refs)

def get_nfs_timeout(session, sr_uuid):
def get_nfs_timeout(session, sr_other_config):
if not isinstance(session, XenAPI.Session):
SMlog("No XAPI session for getting nfs timeout config")
return 0

try:
sr_ref = session.xenapi.SR.get_by_uuid(sr_uuid)
other_config = session.xenapi.SR.get_other_config(sr_ref)
str_val = other_config.get("nfs-timeout")
str_val = sr_other_config.get("nfs-timeout")
except XenAPI.Failure:
SMlog("Failed to get SR.other-config:nfs-timeout, ignoring")
return 0
Expand Down