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

CP-52844: allow for open session to be passed to sr_get_capability #721

Merged
merged 1 commit into from
Dec 6, 2024
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
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