14
14
# You should have received a copy of the GNU General Public License
15
15
# along with this program. If not, see <https://www.gnu.org/licenses/>.
16
16
17
- from sm_typing import Optional , override
17
+ from sm_typing import Any , Optional , override
18
18
19
19
from constants import CBTLOG_TAG
20
20
@@ -381,6 +381,17 @@ def load(self, sr_uuid) -> None:
381
381
self ._linstor = None # Ensure that LINSTOR attribute exists.
382
382
self ._journaler = None
383
383
384
+ # Used to handle reconnect calls on LINSTOR object attached to the SR.
385
+ class LinstorProxy :
386
+ def __init__ (self , sr : LinstorSR ) -> None :
387
+ self .sr = sr
388
+
389
+ def __getattr__ (self , attr : str ) -> Any :
390
+ assert self .sr , "Cannot use `LinstorProxy` without valid `LinstorVolumeManager` instance"
391
+ return getattr (self .sr ._linstor , attr )
392
+
393
+ self ._linstor_proxy = LinstorProxy (self )
394
+
384
395
self ._group_name = self .dconf ['group-name' ]
385
396
386
397
self ._vdi_shared_time = 0
@@ -1151,7 +1162,7 @@ def _load_vdis_ex(self):
1151
1162
if not VdiType .isCowImage (vdi_type ):
1152
1163
managed = not volume_metadata .get (HIDDEN_TAG )
1153
1164
else :
1154
- image_info = self .cowutil .get_info (vdi_uuid )
1165
+ image_info = LinstorCowUtil ( self .session , self . _linstor , getCowUtil ( vdi_type )) .get_info (vdi_uuid )
1155
1166
managed = not image_info .hidden
1156
1167
if image_info .parentUuid :
1157
1168
sm_config ['vhd-parent' ] = image_info .parentUuid
@@ -1207,7 +1218,7 @@ def _load_vdis_ex(self):
1207
1218
# TODO: Replace pylint comment with this feature when possible:
1208
1219
# https://github.com/PyCQA/pylint/pull/2926
1209
1220
vdi .sm_config_override ['key_hash' ] = \
1210
- self . _vhdutil .get_key_hash (vdi_uuid ) # pylint: disable = E1120
1221
+ vdi . linstorcowutil .get_key_hash (vdi_uuid ) # pylint: disable = E1120
1211
1222
1212
1223
# 4.c. Update CBT status of disks either just added
1213
1224
# or already in XAPI.
@@ -1292,12 +1303,13 @@ def _get_vdi_path_and_parent(self, vdi_uuid, volume_name):
1292
1303
return (device_path , None )
1293
1304
1294
1305
# Otherwise it's a COW and a parent can exist.
1295
- if self ._cowutil .check (vdi_uuid ) != cowutil .CheckResult .Success :
1306
+ linstorcowutil = LinstorCowUtil (self .session , self ._linstor , getCowUtil (vdi_type ))
1307
+ if linstorcowutil .check (vdi_uuid ) != cowutil .CheckResult .Success :
1296
1308
return (None , None )
1297
1309
1298
- vhd_info = self . _vhdutil . get_vhd_info (vdi_uuid )
1299
- if vhd_info :
1300
- return (device_path , vhd_info .parentUuid )
1310
+ image_info = linstorcowutil . get_info (vdi_uuid )
1311
+ if image_info :
1312
+ return (device_path , image_info .parentUuid )
1301
1313
except Exception as e :
1302
1314
util .SMlog (
1303
1315
'Failed to get VDI path and parent, ignoring: {}'
@@ -1654,7 +1666,7 @@ def create(self, sr_uuid, vdi_uuid, size) -> str:
1654
1666
assert self .vdi_type
1655
1667
1656
1668
# 2. Compute size and check space available.
1657
- size = self .cowutil .validateAndRoundImageSize (int (size ))
1669
+ size = self .linstorcowutil . cowutil .validateAndRoundImageSize (int (size ))
1658
1670
volume_size = self .linstorcowutil .compute_volume_size (size , self .vdi_type )
1659
1671
util .SMlog (
1660
1672
'LinstorVDI.create: type={}, cow-size={}, volume-size={}'
@@ -1685,18 +1697,16 @@ def create(self, sr_uuid, vdi_uuid, size) -> str:
1685
1697
1686
1698
self ._update_device_name (volume_info .name )
1687
1699
1688
- self .cowutil = None # TODO
1689
-
1690
1700
if not VdiType .isCowImage (self .vdi_type ):
1691
1701
self .size = volume_info .virtual_size
1692
1702
else :
1693
- self .cowutil .create (
1694
- self .path , size , False , self .cowutil .getDefaultPreallocationSizeVirt ()
1703
+ self .linstorcowutil .create (
1704
+ self .path , size , False , self .linstorcowutil . cowutil .getDefaultPreallocationSizeVirt ()
1695
1705
)
1696
- self .size = self .cowutil .get_size_virt (self .uuid )
1706
+ self .size = self .linstorcowutil .get_size_virt (self .uuid )
1697
1707
1698
1708
if self ._key_hash :
1699
- self .cowutil .set_key (self .path , self ._key_hash )
1709
+ self .linstorcowutil .set_key (self .path , self ._key_hash )
1700
1710
1701
1711
# Because cowutil commands modify the volume data,
1702
1712
# we must retrieve a new time the utilization size.
@@ -1902,7 +1912,7 @@ def detach(self, sr_uuid, vdi_uuid) -> None:
1902
1912
while vdi_uuid :
1903
1913
try :
1904
1914
path = self ._linstor .build_device_path (self ._linstor .get_volume_name (vdi_uuid ))
1905
- parent_vdi_uuid = self .sr .cowutil .get_info (vdi_uuid ).parentUuid
1915
+ parent_vdi_uuid = self .sr .linstorcowutil .get_info (vdi_uuid ).parentUuid
1906
1916
except Exception :
1907
1917
break
1908
1918
@@ -1928,7 +1938,7 @@ def resize(self, sr_uuid, vdi_uuid, size) -> str:
1928
1938
raise xs_errors .XenError ('VDIUnavailable' , opterr = 'hidden VDI' )
1929
1939
1930
1940
# Compute the virtual COW and DRBD volume size.
1931
- size = self .cowutil .validateAndRoundImageSize (int (size ))
1941
+ size = self .linstorcowutil . cowutil .validateAndRoundImageSize (int (size ))
1932
1942
volume_size = self .linstorcowutil .compute_volume_size (size , self .vdi_type )
1933
1943
util .SMlog (
1934
1944
'LinstorVDI.resize: type={}, cow-size={}, volume-size={}'
@@ -2003,8 +2013,8 @@ def compose(self, sr_uuid, vdi1, vdi2) -> None:
2003
2013
if not blktap2 .VDI .tap_pause (self .session , self .sr .uuid , self .uuid ):
2004
2014
raise util .SMException ('Failed to pause VDI {}' .format (self .uuid ))
2005
2015
try :
2006
- self .sr .cowutil .set_parent (self .path , parent_path , False )
2007
- self .sr .cowutil .set_hidden (parent_path )
2016
+ self .sr .linstorcowutil .set_parent (self .path , parent_path , False )
2017
+ self .sr .linstorcowutil .set_hidden (parent_path )
2008
2018
self .sr .session .xenapi .VDI .set_managed (
2009
2019
self .sr .srcmd .params ['args' ][0 ], False
2010
2020
)
@@ -2128,7 +2138,7 @@ def _load_this(self):
2128
2138
self .size = volume_info .virtual_size
2129
2139
self .parent = ''
2130
2140
else :
2131
- image_info = self .sr .cowutil .get_info (self .uuid )
2141
+ image_info = self .sr .linstorcowutil .get_info (self .uuid )
2132
2142
self .hidden = image_info .hidden
2133
2143
self .size = image_info .sizeVirt
2134
2144
self .parent = image_info .parentUuid
@@ -2227,6 +2237,10 @@ def _prepare_thin(self, attach):
2227
2237
# Generic helpers.
2228
2238
# --------------------------------------------------------------------------
2229
2239
2240
+ def _set_type (self , vdi_type : str ) -> None :
2241
+ self .vdi_type = vdi_type
2242
+ self .linstorcowutil = LinstorCowUtil (self .session , self .sr ._linstor_proxy , self .vdi_type )
2243
+
2230
2244
def _determine_type_and_path (self ):
2231
2245
"""
2232
2246
Determine whether this is a RAW or a COW VDI.
@@ -2281,12 +2295,12 @@ def _create_snapshot(self, snap_vdi_type, snap_uuid, snap_of_uuid=None):
2281
2295
2282
2296
# 2. Write the snapshot content.
2283
2297
is_raw = (self .vdi_type == VdiType .RAW )
2284
- self .cowutil .snapshot (
2298
+ self .linstorcowutil .snapshot (
2285
2299
snap_path , self .path , is_raw , max (self .size , cowutil .getDefaultPreallocationSizeVirt ())
2286
2300
)
2287
2301
2288
2302
# 3. Get snapshot parent.
2289
- snap_parent = self .cowutil .get_parent (snap_uuid )
2303
+ snap_parent = self .linstorcowutil .get_parent (snap_uuid )
2290
2304
2291
2305
# 4. Update metadata.
2292
2306
util .SMlog ('Set VDI {} metadata of snapshot' .format (snap_uuid ))
@@ -2381,7 +2395,7 @@ def _snapshot(self, snap_type, cbtlog=None, cbt_consistency=None):
2381
2395
'VDIUnavailable' ,
2382
2396
opterr = 'failed to get COW depth'
2383
2397
)
2384
- elif depth >= self ._cowutil .getMaxChainLength ():
2398
+ elif depth >= self .linstorcowutil . cowutil .getMaxChainLength ():
2385
2399
raise xs_errors .XenError ('SnapshotChainTooLong' )
2386
2400
2387
2401
# Ensure we have a valid path if we don't have a local diskful.
0 commit comments