Skip to content

Commit 8c6fe49

Browse files
committed
fix(LinstorSR): open non-leaf volumes in RO mode (create_chain_paths)
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]>
1 parent 318460f commit 8c6fe49

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

drivers/LinstorSR.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1793,10 +1793,10 @@ def attach(self, sr_uuid, vdi_uuid):
17931793
'scan SR first to trigger auto-repair'
17941794
)
17951795

1796-
if not attach_from_config or self.sr._is_master:
1797-
writable = 'args' not in self.sr.srcmd.params or \
1798-
self.sr.srcmd.params['args'][0] == 'true'
1796+
writable = 'args' not in self.sr.srcmd.params or \
1797+
self.sr.srcmd.params['args'][0] == 'true'
17991798

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

18321832
# Ensure we have a path...
1833-
self.sr._vhdutil.create_chain_paths(self.uuid)
1833+
self.sr._vhdutil.create_chain_paths(self.uuid, readonly=not writable)
18341834

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

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

23622362
volume_path = self.path
23632363
if not util.pathexists(volume_path):

drivers/linstorvhdutil.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def __init__(self, session, linstor):
152152
self._session = session
153153
self._linstor = linstor
154154

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

@@ -168,7 +168,7 @@ def create_chain_paths(self, vdi_uuid):
168168
def check_volume_usable():
169169
while True:
170170
try:
171-
with open(path, 'r+'):
171+
with open(path, 'r' if readonly else 'r+'):
172172
pass
173173
except IOError as e:
174174
if e.errno == errno.ENODATA:
@@ -186,6 +186,7 @@ def check_volume_usable():
186186
if not vdi_uuid:
187187
break
188188
path = self._linstor.get_device_path(vdi_uuid)
189+
readonly = True # Non-leaf is always readonly.
189190

190191
return leaf_vdi_path
191192

0 commit comments

Comments
 (0)