Skip to content

Commit f9e6a8e

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 43f278c commit f9e6a8e

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

Diff for: drivers/LinstorSR.py

+5-5
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):

Diff for: drivers/linstorvhdutil.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def __init__(self, session, linstor):
162162
self._session = session
163163
self._linstor = linstor
164164

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

@@ -178,7 +178,7 @@ def create_chain_paths(self, vdi_uuid):
178178
def check_volume_usable():
179179
while True:
180180
try:
181-
with open(path, 'r+'):
181+
with open(path, 'r' if readonly else 'r+'):
182182
pass
183183
except IOError as e:
184184
if e.errno == errno.ENODATA:
@@ -196,6 +196,7 @@ def check_volume_usable():
196196
if not vdi_uuid:
197197
break
198198
path = self._linstor.get_device_path(vdi_uuid)
199+
readonly = True # Non-leaf is always readonly.
199200

200201
return leaf_vdi_path
201202

0 commit comments

Comments
 (0)