Skip to content

Commit 9989135

Browse files
NambrokbenjamreisWescoeur
committed
Linstor: Fix on destroy
linstor-manager: - fix on get_drbd_volumes Failed because the key backing-disk is not always present. LinstorSR: - Refactored some hosts variable to reference the OpaqueRef status linstorvolumemanager: - Add destroying DRBD remnants on each hosts before destroying resource groups - Correctly remove DB files (#57) `glob` method only returns the dir when not wildcard is used in the path. Therefore the remove call right after will fail everytime. Signed-off-by: Damien Thenot <[email protected]> Co-authored-by: Benjamin Reis <[email protected]> Co-authored-by: Ronan Abhamon <[email protected]>
1 parent 20c54e8 commit 9989135

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

drivers/LinstorSR.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -650,17 +650,17 @@ def delete(self, uuid):
650650
opterr='Cannot get controller node name'
651651
)
652652

653-
host = None
653+
host_ref = None
654654
if node_name == 'localhost':
655-
host = util.get_this_host_ref(self.session)
655+
host_ref = util.get_this_host_ref(self.session)
656656
else:
657657
for slave in util.get_all_slaves(self.session):
658658
r_name = self.session.xenapi.host.get_record(slave)['hostname']
659659
if r_name == node_name:
660-
host = slave
660+
host_ref = slave
661661
break
662662

663-
if not host:
663+
if not host_ref:
664664
raise xs_errors.XenError(
665665
'LinstorSRDelete',
666666
opterr='Failed to find host with hostname: {}'.format(
@@ -677,7 +677,7 @@ def delete(self, uuid):
677677
'groupName': self._group_name,
678678
}
679679
self._exec_manager_command(
680-
host, 'destroy', args, 'LinstorSRDelete'
680+
host_ref, 'destroy', args, 'LinstorSRDelete'
681681
)
682682
except Exception as e:
683683
try:

drivers/linstor-manager

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,10 @@ def get_drbd_volumes(volume_group=None):
241241
config = json.loads(stdout)
242242
for resource in config:
243243
for volume in resource['_this_host']['volumes']:
244-
backing_disk = volume['backing-disk']
244+
backing_disk = volume.get('backing-disk')
245+
if not backing_disk:
246+
continue
247+
245248
match = BACKING_DISK_RE.match(backing_disk)
246249
if not match:
247250
continue

drivers/linstorvolumemanager.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import distutils.util
2020
import errno
21-
import glob
2221
import json
2322
import linstor
2423
import os.path
@@ -1362,13 +1361,27 @@ def destroy(self):
13621361

13631362
# 4.4. Refresh linstor connection.
13641363
# Without we get this error:
1365-
# "Cannot delete resource group 'xcp-sr-linstor_group_thin_device' because it has existing resource definitions.."
1364+
# "Cannot delete resource group 'xcp-sr-linstor_group_thin_device' because it has existing resource definitions.."
13661365
# Because the deletion of the databse was not seen by Linstor for some reason.
13671366
# It seems a simple refresh of the Linstor connection make it aware of the deletion.
13681367
self._linstor.disconnect()
13691368
self._linstor.connect()
13701369

1371-
# 4.5. Destroy group and storage pools.
1370+
# 4.5. Destroy remaining drbd nodes on hosts.
1371+
# We check if there is a DRBD node on hosts that could mean blocking when destroying resource groups.
1372+
# It needs to be done locally by each host so we go through the linstor-manager plugin.
1373+
# If we don't do this sometimes, the destroy will fail when trying to destroy the resource groups with:
1374+
# "linstor-manager:destroy error: Failed to destroy SP `xcp-sr-linstor_group_thin_device` on node `r620-s2`: The specified storage pool 'xcp-sr-linstor_group_thin_device' on node 'r620-s2' can not be deleted as volumes / snapshot-volumes are still using it."
1375+
session = util.timeout_call(5, util.get_localAPI_session)
1376+
for host_ref in session.xenapi.host.get_all():
1377+
try:
1378+
response = session.xenapi.host.call_plugin(
1379+
host_ref, 'linstor-manager', 'destroyDrbdVolumes', {'volume_group': self._group_name}
1380+
)
1381+
except Exception as e:
1382+
util.SMlog('Calling destroyDrbdVolumes on host {} failed with error {}'.format(host_ref, e))
1383+
1384+
# 4.6. Destroy group and storage pools.
13721385
self._destroy_resource_group(self._linstor, self._group_name)
13731386
self._destroy_resource_group(self._linstor, self._ha_group_name)
13741387
for pool in self._get_storage_pools(force=True):
@@ -1381,8 +1394,9 @@ def destroy(self):
13811394

13821395
try:
13831396
self._start_controller(start=False)
1384-
for file in glob.glob(DATABASE_PATH + '/'):
1385-
os.remove(file)
1397+
for file in os.listdir(DATABASE_PATH):
1398+
if file != 'lost+found':
1399+
os.remove(DATABASE_PATH + '/' + file)
13861400
except Exception as e:
13871401
util.SMlog(
13881402
'Ignoring failure after LINSTOR SR destruction: {}'

0 commit comments

Comments
 (0)