Skip to content

Commit 0941d01

Browse files
authored
secondary-storage: delete backedup snapshot dir on delete (#7524)
* secondary-storage: delete backedup snapshot dir on delete Fixes #7516 When a backed-up snapshot is deleted and the snapshot file is present in the same name directory (probably only for VMware), the whole directory can be deleted. Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * refactor Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * resolve comment Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> --------- Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
1 parent 7319deb commit 0941d01

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

services/secondary-storage/server/src/main/java/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1997,6 +1997,16 @@ private void savePostUploadPSK(String psk) {
19971997
}
19981998
}
19991999

2000+
protected String getSnapshotFilepathForDelete(String path, String snapshotName) {
2001+
if (!path.endsWith(snapshotName)) {
2002+
return path + "/*" + snapshotName + "*";
2003+
}
2004+
if (s_logger.isDebugEnabled()) {
2005+
s_logger.debug(String.format("Snapshot file %s is present in the same name directory %s. Deleting the directory", snapshotName, path));
2006+
}
2007+
return path;
2008+
}
2009+
20002010
protected Answer deleteSnapshot(final DeleteCommand cmd) {
20012011
DataTO obj = cmd.getData();
20022012
DataStoreTO dstore = obj.getDataStore();
@@ -2033,7 +2043,7 @@ protected Answer deleteSnapshot(final DeleteCommand cmd) {
20332043
return new Answer(cmd, true, details);
20342044
}
20352045
// delete snapshot in the directory if exists
2036-
String lPath = absoluteSnapshotPath + "/*" + snapshotName + "*";
2046+
String lPath = getSnapshotFilepathForDelete(absoluteSnapshotPath, snapshotName);
20372047
String result = deleteLocalFile(lPath);
20382048
if (result != null) {
20392049
details = "failed to delete snapshot " + lPath + " , err=" + result;

services/secondary-storage/server/src/test/java/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResourceTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,21 @@ public void testCleanupStagingNfs() throws Exception{
9191
testLogAppender.assertMessagesLogged();
9292

9393
}
94+
95+
private void performGetSnapshotFilepathForDeleteTest(String expected, String path, String name) {
96+
Assert.assertEquals("Incorrect resultant snapshot delete path", expected, resource.getSnapshotFilepathForDelete(path, name));
97+
}
98+
99+
@Test
100+
public void testGetSnapshotFilepathForDelete() {
101+
performGetSnapshotFilepathForDeleteTest("/snapshots/2/10/somename",
102+
"/snapshots/2/10/somename",
103+
"somename");
104+
performGetSnapshotFilepathForDeleteTest("/snapshots/2/10/diffName/*diffname*",
105+
"/snapshots/2/10/diffName",
106+
"diffname");
107+
performGetSnapshotFilepathForDeleteTest("/snapshots/2/10/*somename*",
108+
"/snapshots/2/10",
109+
"somename");
110+
}
94111
}

0 commit comments

Comments
 (0)