Skip to content

Commit

Permalink
fix(LinstorSR): open non-leaf volumes in RO mode (create_chain_paths)
Browse files Browse the repository at this point in the history
We must never open non-leaf volumes with the write option.
Only read only mode should be used to allow any host to access DRBD data.
Otherwise an attach call on dom-0 can be interrupted because a host already has a read lock.

Signed-off-by: Ronan Abhamon <[email protected]>
  • Loading branch information
Wescoeur committed Jun 28, 2024
1 parent 318460f commit 8c6fe49
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
10 changes: 5 additions & 5 deletions drivers/LinstorSR.py
Original file line number Diff line number Diff line change
Expand Up @@ -1793,10 +1793,10 @@ def attach(self, sr_uuid, vdi_uuid):
'scan SR first to trigger auto-repair'
)

if not attach_from_config or self.sr._is_master:
writable = 'args' not in self.sr.srcmd.params or \
self.sr.srcmd.params['args'][0] == 'true'
writable = 'args' not in self.sr.srcmd.params or \
self.sr.srcmd.params['args'][0] == 'true'

if not attach_from_config or self.sr._is_master:
# We need to inflate the volume if we don't have enough place
# to mount the VHD image. I.e. the volume capacity must be greater
# than the VHD size + bitmap size.
Expand Down Expand Up @@ -1830,7 +1830,7 @@ def attach(self, sr_uuid, vdi_uuid):
return self._attach_using_http_nbd()

# Ensure we have a path...
self.sr._vhdutil.create_chain_paths(self.uuid)
self.sr._vhdutil.create_chain_paths(self.uuid, readonly=not writable)

self.attached = True
return VDI.VDI.attach(self, self.sr.uuid, self.uuid)
Expand Down Expand Up @@ -2357,7 +2357,7 @@ def _snapshot(self, snap_type, cbtlog=None, cbt_consistency=None):
raise xs_errors.XenError('SnapshotChainTooLong')

# Ensure we have a valid path if we don't have a local diskful.
self.sr._vhdutil.create_chain_paths(self.uuid)
self.sr._vhdutil.create_chain_paths(self.uuid, readonly=True)

volume_path = self.path
if not util.pathexists(volume_path):
Expand Down
5 changes: 3 additions & 2 deletions drivers/linstorvhdutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def __init__(self, session, linstor):
self._session = session
self._linstor = linstor

def create_chain_paths(self, vdi_uuid):
def create_chain_paths(self, vdi_uuid, readonly=False):
# OPTIMIZE: Add a limit_to_first_allocated_block param to limit vhdutil calls.
# Useful for the snapshot code algorithm.

Expand All @@ -168,7 +168,7 @@ def create_chain_paths(self, vdi_uuid):
def check_volume_usable():
while True:
try:
with open(path, 'r+'):
with open(path, 'r' if readonly else 'r+'):
pass
except IOError as e:
if e.errno == errno.ENODATA:
Expand All @@ -186,6 +186,7 @@ def check_volume_usable():
if not vdi_uuid:
break
path = self._linstor.get_device_path(vdi_uuid)
readonly = True # Non-leaf is always readonly.

return leaf_vdi_path

Expand Down

0 comments on commit 8c6fe49

Please sign in to comment.