Skip to content

Commit 87add55

Browse files
WescoeurNambrok
authored andcommitted
fix(tapdisk-pause): ensure LINSTOR VHD chain is available
Signed-off-by: Ronan Abhamon <[email protected]>
1 parent e093164 commit 87add55

File tree

3 files changed

+44
-35
lines changed

3 files changed

+44
-35
lines changed

Diff for: drivers/LinstorSR.py

+2-33
Original file line numberDiff line numberDiff line change
@@ -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._create_chain_paths(self.uuid)
1833+
self.sr._vhdutil.create_chain_paths(self.uuid)
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._create_chain_paths(self.uuid)
2360+
self.sr._vhdutil.create_chain_paths(self.uuid)
23612361

23622362
volume_path = self.path
23632363
if not util.pathexists(volume_path):
@@ -2820,37 +2820,6 @@ def _detach_using_http_nbd(self):
28202820
self._kill_persistent_nbd_server(volume_name)
28212821
self._kill_persistent_http_server(volume_name)
28222822

2823-
def _create_chain_paths(self, vdi_uuid):
2824-
# OPTIMIZE: Add a limit_to_first_allocated_block param to limit vhdutil calls.
2825-
# Useful for the snapshot code algorithm.
2826-
2827-
while vdi_uuid:
2828-
path = self._linstor.get_device_path(vdi_uuid)
2829-
if not util.pathexists(path):
2830-
raise xs_errors.XenError(
2831-
'VDIUnavailable', opterr='Could not find: {}'.format(path)
2832-
)
2833-
2834-
# Diskless path can be created on the fly, ensure we can open it.
2835-
def check_volume_usable():
2836-
while True:
2837-
try:
2838-
with open(path, 'r+'):
2839-
pass
2840-
except IOError as e:
2841-
if e.errno == errno.ENODATA:
2842-
time.sleep(2)
2843-
continue
2844-
if e.errno == errno.EROFS:
2845-
util.SMlog('Volume not attachable because RO. Openers: {}'.format(
2846-
self.sr._linstor.get_volume_openers(vdi_uuid)
2847-
))
2848-
raise
2849-
break
2850-
util.retry(check_volume_usable, 15, 2)
2851-
2852-
vdi_uuid = self.sr._vhdutil.get_vhd_info(vdi_uuid).parentUuid
2853-
28542823
# ------------------------------------------------------------------------------
28552824

28562825

Diff for: drivers/linstorvhdutil.py

+38
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import errno
2222
import json
2323
import socket
24+
import time
2425
import util
2526
import vhdutil
2627
import xs_errors
@@ -141,6 +142,43 @@ def __init__(self, session, linstor):
141142
self._session = session
142143
self._linstor = linstor
143144

145+
def create_chain_paths(self, vdi_uuid):
146+
# OPTIMIZE: Add a limit_to_first_allocated_block param to limit vhdutil calls.
147+
# Useful for the snapshot code algorithm.
148+
149+
leaf_vdi_path = self._linstor.get_device_path(vdi_uuid)
150+
path = leaf_vdi_path
151+
while True:
152+
if not util.pathexists(path):
153+
raise xs_errors.XenError(
154+
'VDIUnavailable', opterr='Could not find: {}'.format(path)
155+
)
156+
157+
# Diskless path can be created on the fly, ensure we can open it.
158+
def check_volume_usable():
159+
while True:
160+
try:
161+
with open(path, 'r+'):
162+
pass
163+
except IOError as e:
164+
if e.errno == errno.ENODATA:
165+
time.sleep(2)
166+
continue
167+
if e.errno == errno.EROFS:
168+
util.SMlog('Volume not attachable because RO. Openers: {}'.format(
169+
self._linstor.get_volume_openers(vdi_uuid)
170+
))
171+
raise
172+
break
173+
util.retry(check_volume_usable, 15, 2)
174+
175+
vdi_uuid = self.get_vhd_info(vdi_uuid).parentUuid
176+
if not vdi_uuid:
177+
break
178+
path = self._linstor.get_device_path(vdi_uuid)
179+
180+
return leaf_vdi_path
181+
144182
# --------------------------------------------------------------------------
145183
# Getters: read locally and try on another host in case of failure.
146184
# --------------------------------------------------------------------------

Diff for: drivers/tapdisk-pause

+4-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import vhdutil
3030
import lvmcache
3131

3232
try:
33+
from linstorvhdutil import LinstorVhdUtil
3334
from linstorvolumemanager import get_controller_uri, LinstorVolumeManager
3435
LINSTOR_AVAILABLE = True
3536
except ImportError:
@@ -162,11 +163,12 @@ class Tapdisk:
162163
dconf = session.xenapi.PBD.get_device_config(pbd)
163164
group_name = dconf['group-name']
164165

165-
device_path = LinstorVolumeManager(
166+
linstor = LinstorVolumeManager(
166167
get_controller_uri(),
167168
group_name,
168169
logger=util.SMlog
169-
).get_device_path(self.vdi_uuid)
170+
)
171+
device_path = LinstorVhdUtil(session, linstor).create_chain_paths(self.vdi_uuid)
170172

171173
if realpath != device_path:
172174
util.SMlog(

0 commit comments

Comments
 (0)