Skip to content

Commit 7e4860a

Browse files
Fix stale entry when add local storage failed
1 parent 4e82435 commit 7e4860a

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

server/src/main/java/com/cloud/storage/StorageManagerImpl.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,9 @@ public DataStore createLocalStorage(Host host, StoragePoolInfo pInfo) throws Con
803803
if (!(dc.isLocalStorageEnabled() || useLocalStorageForSystemVM)) {
804804
return null;
805805
}
806-
DataStore store;
806+
DataStore store = null;
807+
DataStoreProvider provider = _dataStoreProviderMgr.getDefaultPrimaryDataStoreProvider();
808+
DataStoreLifeCycle lifeCycle = provider.getDataStoreLifeCycle();
807809
try {
808810
String hostAddress = pInfo.getHost();
809811
if (host.getHypervisorType() == Hypervisor.HypervisorType.VMware) {
@@ -829,8 +831,6 @@ public DataStore createLocalStorage(Host host, StoragePoolInfo pInfo) throws Con
829831
}
830832
}
831833

832-
DataStoreProvider provider = _dataStoreProviderMgr.getDefaultPrimaryDataStoreProvider();
833-
DataStoreLifeCycle lifeCycle = provider.getDataStoreLifeCycle();
834834
if (pool == null) {
835835
Map<String, Object> params = new HashMap<String, Object>();
836836
String name = pInfo.getName() != null ? pInfo.getName() : createLocalStoragePoolName(host, pInfo);
@@ -860,6 +860,14 @@ public DataStore createLocalStorage(Host host, StoragePoolInfo pInfo) throws Con
860860

861861
} catch (Exception e) {
862862
s_logger.warn("Unable to setup the local storage pool for " + host, e);
863+
try {
864+
if (store != null) {
865+
s_logger.debug(String.format("Trying to delete storage pool entry if exists %s", store));
866+
lifeCycle.deleteDataStore(store);
867+
}
868+
} catch (Exception ex) {
869+
s_logger.debug(String.format("Failed to clean up local storage pool: %s", ex.getMessage()));
870+
}
863871
throw new ConnectionException(true, "Unable to setup the local storage pool for " + host, e);
864872
}
865873

0 commit comments

Comments
 (0)