Skip to content

Commit eedf6d3

Browse files
committed
linstor: try to delete -rst resource before snapshot backup (apache#10443)
If a -rst resource wasn't deleted because of a failed copy, a reoccurring snapshot attempt couldn't be done, because there was still the "old" -rst resource. To prevent this always try to remove the -rst resource before, if it doesn't exist it is a noop.
1 parent 6828116 commit eedf6d3

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

plugins/storage/volume/linstor/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to Linstor CloudStack plugin will be documented in this file
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [2025-02-21]
9+
10+
### Fixed
11+
12+
- Always try to delete cs-...-rst resource before doing a snapshot backup
13+
814
## [2025-01-27]
915

1016
### Fixed

plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/datastore/driver/LinstorPrimaryDataStoreDriverImpl.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,6 +1116,8 @@ private String restoreResourceFromSnapshot(
11161116
String snapshotName,
11171117
String restoredName) throws ApiException {
11181118
final String rscGrp = getRscGrp(storagePoolVO);
1119+
// try to delete -rst resource, could happen if the copy failed and noone deleted it.
1120+
deleteResourceDefinition(storagePoolVO, restoredName);
11191121
ResourceDefinitionCreate rdc = createResourceDefinitionCreate(restoredName, rscGrp);
11201122
api.resourceDefinitionCreate(rdc);
11211123

@@ -1258,19 +1260,22 @@ private Answer copyFromTemporaryResource(
12581260
throws ApiException {
12591261
Answer answer;
12601262
String restoreName = rscName + "-rst";
1261-
String devName = restoreResourceFromSnapshot(api, pool, rscName, snapshotName, restoreName);
1262-
1263-
Optional<RemoteHostEndPoint> optEPAny = getLinstorEP(api, restoreName);
1264-
if (optEPAny.isPresent()) {
1265-
// patch the src device path to the temporary linstor resource
1266-
snapshotObject.setPath(devName);
1267-
origCmd.setSrcTO(snapshotObject.getTO());
1268-
answer = optEPAny.get().sendMessage(origCmd);
1269-
} else{
1270-
answer = new Answer(origCmd, false, "Unable to get matching Linstor endpoint.");
1263+
try {
1264+
String devName = restoreResourceFromSnapshot(api, pool, rscName, snapshotName, restoreName);
1265+
1266+
Optional<RemoteHostEndPoint> optEPAny = getLinstorEP(api, restoreName);
1267+
if (optEPAny.isPresent()) {
1268+
// patch the src device path to the temporary linstor resource
1269+
snapshotObject.setPath(devName);
1270+
origCmd.setSrcTO(snapshotObject.getTO());
1271+
answer = optEPAny.get().sendMessage(origCmd);
1272+
} else{
1273+
answer = new Answer(origCmd, false, "Unable to get matching Linstor endpoint.");
1274+
}
1275+
} finally {
1276+
// delete the temporary resource, noop if already gone
1277+
api.resourceDefinitionDelete(restoreName);
12711278
}
1272-
// delete the temporary resource, noop if already gone
1273-
api.resourceDefinitionDelete(restoreName);
12741279
return answer;
12751280
}
12761281

0 commit comments

Comments
 (0)