Skip to content

Commit 8ad8dde

Browse files
committed
refactor(linstor): add GC volume deletion helper
This adds the `mark_volume_for_deletion` function on the LINSTOR volume manager to have a common implementation for marking a volume for later deletion by the GC. This also adds a constant that holds the volume UUID prefix that gets added to such volumes to avoid duplicating this prefix in multiple places. Signed-off-by: Alexandre Sollier <alexandre.sollier@vates.tech>
1 parent f3d5fa7 commit 8ad8dde

3 files changed

Lines changed: 24 additions & 10 deletions

File tree

drivers/LinstorSR.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from linstorvolumemanager import LinstorVolumeManagerError
2828
from linstorvolumemanager import DATABASE_VOLUME_NAME
2929
from linstorvolumemanager import PERSISTENT_PREFIX
30+
from linstorvolumemanager import DELETED_PREFIX
3031

3132
LINSTOR_AVAILABLE = True
3233
except ImportError:
@@ -1114,7 +1115,7 @@ def _load_vdis_ex(self):
11141115
if not introduce:
11151116
continue
11161117

1117-
if vdi_uuid.startswith('DELETED_'):
1118+
if vdi_uuid.startswith(DELETED_PREFIX):
11181119
continue
11191120

11201121
volume_metadata = volumes_metadata.get(vdi_uuid)
@@ -1479,9 +1480,7 @@ def _undo_clone(self, volume_names, vdi_uuid, base_uuid, snap_uuid):
14791480
# volume info remains... The problem is we can't rename
14801481
# properly the base VDI below this line, so we must change the
14811482
# UUID of this bad VDI before.
1482-
self._linstor.update_volume_uuid(
1483-
vdi_uuid, 'DELETED_' + vdi_uuid, force=True
1484-
)
1483+
self._linstor.mark_volume_for_deletion(vdi_uuid, force=True)
14851484

14861485
# Rename!
14871486
self._linstor.update_volume_uuid(base_uuid, vdi_uuid)

drivers/cleanup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
from linstorvolumemanager import get_controller_uri
6262
from linstorvolumemanager import LinstorVolumeManager, LinstorVolumeManagerError, LinstorVolumeOpeners
6363
from linstorvolumemanager import PERSISTENT_PREFIX as LINSTOR_PERSISTENT_PREFIX
64+
from linstorvolumemanager import DELETED_PREFIX as LINSTOR_DELETED_PREFIX
6465

6566
LINSTOR_AVAILABLE = True
6667
except ImportError:
@@ -2916,7 +2917,7 @@ def _doCoalesceLeaf(self, vdi: VDI, coalesce_on_remote: bool):
29162917
vdi._coalesceCowImageOnHost(host_ref, vdi) # vdi is the leaf for the online coalesce
29172918
util.fistpoint.activate("LVHDRT_coaleaf_after_coalesce", self.uuid)
29182919
vdi.pause(failfast=True)
2919-
# We make a pause here after the online coalesce but before the rename so we can refresh the chain for tapdisk.
2920+
# We make a pause here after the online coalesce but before the rename so we can refresh the chain for tapdisk.
29202921
# It's also needed to be paused for the rename on slaves with LVMSR.
29212922
# We let the caller `_liveLeafCoalesce` do the unpause with the call to `vdi.ensureUnpaused()`
29222923
else:
@@ -3744,7 +3745,7 @@ def handle_fail(vdi_uuid, e):
37443745
if not volume_info.name and not list(volume_metadata.items()):
37453746
continue # Ignore it, probably deleted.
37463747

3747-
if vdi_uuid.startswith('DELETED_'):
3748+
if vdi_uuid.startswith(LINSTOR_DELETED_PREFIX):
37483749
# Assume it's really a RAW volume of a failed snap without COW header/footer.
37493750
# We must remove this VDI now without adding it in the VDI list.
37503751
# Otherwise `Relinking` calls and other actions can be launched on it.

drivers/linstorvolumemanager.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
# Persistent prefix to add to RAW persistent volumes.
3838
PERSISTENT_PREFIX = 'xcp-persistent-'
3939

40+
# Prefix added to the UUID of a LINSTOR volume that will be deleted by the GC.
41+
DELETED_PREFIX = 'DELETED_'
42+
4043
# Contains the data of the "/var/lib/linstor" directory.
4144
DATABASE_VOLUME_NAME = PERSISTENT_PREFIX + 'database'
4245
DATABASE_SIZE = 1 << 30 # 1GB.
@@ -1143,6 +1146,20 @@ def update_volume_uuid(self, volume_uuid, new_volume_uuid, force=False):
11431146
)
11441147
)
11451148

1149+
def mark_volume_for_deletion(self, volume_uuid, force=False):
1150+
"""
1151+
Add a prefix to the volume UUID to mark it for deletion by the GC.
1152+
:param str volume_uuid: The volume to mark.
1153+
:param bool force: Whether to force-update the volume UUID. See the
1154+
documentation of `update_volume_uuid` for more details.
1155+
"""
1156+
if volume_uuid.startswith(DELETED_PREFIX):
1157+
return
1158+
1159+
self.update_volume_uuid(
1160+
volume_uuid, DELETED_PREFIX + volume_uuid, force=force
1161+
)
1162+
11461163
def update_volume_name(self, volume_uuid, volume_name):
11471164
"""
11481165
Change the volume name of a volume.
@@ -2599,10 +2616,7 @@ def _build_volumes(self, repair):
25992616
# This prefix is mandatory if it exists a snap transaction to
26002617
# rollback because the original VDI UUID can try to be renamed
26012618
# with the UUID we are trying to delete...
2602-
if not volume_uuid.startswith('DELETED_'):
2603-
self.update_volume_uuid(
2604-
volume_uuid, 'DELETED_' + volume_uuid, force=True
2605-
)
2619+
self.mark_volume_for_deletion(volume_uuid, force=True)
26062620

26072621
for dest_uuid, src_uuid in updating_uuid_volumes.items():
26082622
dest_namespace = self._build_volume_namespace(dest_uuid)

0 commit comments

Comments
 (0)