agent: reduce reference count for failed mount
The kata agent adds a reference for each storage object before mount
and skip mount again if the storage object is known. We need to
remove the object reference if mount fails.
Fixes:
@@ -779,16 +779,20 @@ pub async fn add_storages(
}
};
- // Todo need to rollback the mounted storage if err met.
-
- if res.is_err() {
+ let mount_point = match res {
+ Err(e) => {
error!(
logger,
- "add_storages failed, storage: {:?}, error: {:?} ", storage, res
+ "add_storages failed, storage: {:?}, error: {:?} ", storage, e
);
+ let mut sb = sandbox.lock().await;
+ sb.unset_sandbox_storage(&storage.mount_point)
+ .map_err(|e| warn!(logger, "fail to unset sandbox storage {:?}", e))
+ .ok();
+ return Err(e);
}
-
- let mount_point = res?;
+ Ok(m) => m,
+ };
if !mount_point.is_empty() {
mount_list.push(mount_point);
