Skip to content

Commit

Permalink
CP-52844: allow for open session to be passed to sr_get_capability
Browse files Browse the repository at this point in the history
sr_get_capability can create, and subsequently log out a local Xapi
session, however the users of the method will most likely already have
an open session so allow that to be passed to avoid session churn in
xapi.

Signed-off-by: Mark Syms <[email protected]>
  • Loading branch information
MarkSymsCtx committed Dec 5, 2024
1 parent e054691 commit a127f36
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
3 changes: 2 additions & 1 deletion drivers/SRCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ def _run(self, sr, target):

elif self.cmd == 'vdi_delete':
if 'VDI_CONFIG_CBT' in util.sr_get_capability(
self.params['sr_uuid']):
self.params['sr_uuid'],
session=sr.session):
return target.delete(self.params['sr_uuid'],
self.vdi_uuid, data_only=False)
else:
Expand Down
3 changes: 2 additions & 1 deletion drivers/VDI.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,8 @@ def _get_blocktracking_status(self, uuid=None):
uuid = self.uuid
if self.vdi_type == vhdutil.VDI_TYPE_RAW:
return False
elif 'VDI_CONFIG_CBT' not in util.sr_get_capability(self.sr.uuid):
elif 'VDI_CONFIG_CBT' not in util.sr_get_capability(
self.sr.uuid, session=self.sr.session):
return False
logpath = self._get_cbt_logpath(uuid)
return self._cbt_log_exists(logpath)
Expand Down
2 changes: 1 addition & 1 deletion drivers/trim_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def do_trim(session, args):
sr_uuid = args["sr_uuid"]
os.environ['LVM_SYSTEM_DIR'] = MASTER_LVM_CONF

if TRIM_CAP not in util.sr_get_capability(sr_uuid):
if TRIM_CAP not in util.sr_get_capability(sr_uuid, session=session):
util.SMlog("Trim command ignored on unsupported SR %s" % sr_uuid)
err_msg = {ERROR_CODE_KEY: 'UnsupportedSRForTrim',
ERROR_MSG_KEY: 'Trim on [%s] not supported' % sr_uuid}
Expand Down
11 changes: 8 additions & 3 deletions drivers/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,13 @@ def ioretry_stat(path, maxretry=IORETRY_MAX):
raise CommandException(errno.EIO, "os.statvfs")


def sr_get_capability(sr_uuid):
def sr_get_capability(sr_uuid, session=None):
result = []
session = get_localAPI_session()
local_session = None
if session is None:
local_session = get_localAPI_session()
session = local_session

try:
sr_ref = session.xenapi.SR.get_by_uuid(sr_uuid)
sm_type = session.xenapi.SR.get_record(sr_ref)['type']
Expand All @@ -390,7 +394,8 @@ def sr_get_capability(sr_uuid):

return result
finally:
session.xenapi.session.logout()
if local_session:
local_session.xenapi.session.logout()

def sr_get_driver_info(driver_info):
results = {}
Expand Down

0 comments on commit a127f36

Please sign in to comment.