Skip to content

Commit 939715f

Browse files
authored
Merge pull request #121 from Burning1020/fix-multi-delete
sandbox: Ignore not found error in sandbox deletion
2 parents 546f6f6 + 7f3c891 commit 939715f

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

vmm/sandbox/src/cgroup.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17+
use std::error::Error;
18+
1719
use anyhow::{anyhow, Ok, Result};
1820
use cgroups_rs::{
1921
cgroup_builder::*, cpu::CpuController, cpuset::CpuSetController, hugetlb::HugeTlbController,
@@ -186,10 +188,23 @@ fn remove_sandbox_cgroup(cgroup: &Cgroup) -> Result<()> {
186188
// get the tids in the current cgroup and then move the tids to parent cgroup
187189
let tids = cgroup.tasks();
188190
for tid in tids {
189-
cgroup.move_task_to_parent(tid)?;
191+
cgroup.move_task_to_parent(tid).unwrap_or_default();
190192
}
191193

192-
cgroup.delete()?;
194+
// Should ignore the NotFound error of cgroup path as it may be already deleted.
195+
if let Err(e) = cgroup.delete() {
196+
if e.kind() == &cgroups_rs::error::ErrorKind::RemoveFailed {
197+
if let Some(cause) = e.source() {
198+
if let Some(ioe) = cause.downcast_ref::<std::io::Error>() {
199+
if ioe.kind() == std::io::ErrorKind::NotFound {
200+
return Ok(());
201+
}
202+
}
203+
}
204+
}
205+
206+
return Err(e.into());
207+
}
193208
Ok(())
194209
}
195210

vmm/sandbox/src/sandbox.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,12 @@ where
323323
}
324324

325325
cleanup_mounts(&sb.base_dir).await?;
326-
remove_dir_all(&sb.base_dir).await?;
326+
// Should Ignore the NotFound error of base dir as it may be already deleted.
327+
if let Err(e) = remove_dir_all(&sb.base_dir).await {
328+
if e.kind() != ErrorKind::NotFound {
329+
return Err(e.into());
330+
}
331+
}
327332
}
328333
self.sandboxes.write().await.remove(id);
329334
Ok(())

0 commit comments

Comments
 (0)