Skip to content

Commit 95c2481

Browse files
authored
linstor: try to delete -rst resource before snapshot backup (#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 8ce34ad commit 95c2481

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
@@ -1117,6 +1117,8 @@ private String restoreResourceFromSnapshot(
11171117
String snapshotName,
11181118
String restoredName) throws ApiException {
11191119
final String rscGrp = getRscGrp(storagePoolVO);
1120+
// try to delete -rst resource, could happen if the copy failed and noone deleted it.
1121+
deleteResourceDefinition(storagePoolVO, restoredName);
11201122
ResourceDefinitionCreate rdc = createResourceDefinitionCreate(restoredName, rscGrp);
11211123
api.resourceDefinitionCreate(rdc);
11221124

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

0 commit comments

Comments
 (0)