mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-30 12:44:39 +00:00
agent: avoid possible leakage of storage device
When a storage device is used by more than one container, the second and forth instances will cause storage device reference count leakage, thus cause storage device leakage. The reason is: add_storages() will increase reference count of existing storage device, but forget to add the device to the `mount_list` array, thus leak the reference count. Fixes: #7820 Signed-off-by: Jiang Liu <gerry@linux.alibaba.com>
This commit is contained in:
parent
f65ffb23da
commit
9cd706d1c9
@ -71,6 +71,10 @@ impl StorageState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn path(&self) -> &str {
|
||||||
|
self.device.path()
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn ref_count(&self) -> u32 {
|
pub async fn ref_count(&self) -> u32 {
|
||||||
self.count.load(Ordering::Relaxed)
|
self.count.load(Ordering::Relaxed)
|
||||||
}
|
}
|
||||||
|
@ -103,6 +103,10 @@ pub async fn add_storages(
|
|||||||
let path = storage.mount_point.clone();
|
let path = storage.mount_point.clone();
|
||||||
let state = sandbox.lock().await.add_sandbox_storage(&path).await;
|
let state = sandbox.lock().await.add_sandbox_storage(&path).await;
|
||||||
if state.ref_count().await > 1 {
|
if state.ref_count().await > 1 {
|
||||||
|
let path = state.path();
|
||||||
|
if !path.is_empty() {
|
||||||
|
mount_list.push(path.to_string());
|
||||||
|
}
|
||||||
// The device already exists.
|
// The device already exists.
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user