proxmox-backup-proxy: fix leftover references on datastore removal

when we remove a datastore via api/cli, the proxy
has sometimes leftover references to that datastore in its
DATASTORE_MAP which includes an open filehandle on the
'.lock' file

this prevents unmounting/exporting the datastore even after removal,
only a reload/restart of the proxy did help

add a command to our command socket, which removes all non
configured datastores from the map, dropping the open filehandle

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
This commit is contained in:
Dominik Csapak
2021-06-02 13:27:01 +02:00
committed by Dietmar Maurer
parent e5950360ca
commit 062cf75cdf
4 changed files with 34 additions and 1 deletions

View File

@ -69,6 +69,18 @@ impl DataStore {
Ok(datastore)
}
/// removes all datastores that are not configured anymore
pub fn remove_unused_datastores() -> Result<(), Error>{
let (config, _digest) = datastore::config()?;
let mut map = DATASTORE_MAP.lock().unwrap();
// removes all elements that are not in the config
map.retain(|key, _| {
config.sections.contains_key(key)
});
Ok(())
}
fn open_with_path(store_name: &str, path: &Path, config: DataStoreConfig) -> Result<Self, Error> {
let chunk_store = ChunkStore::open(store_name, path)?;