Skip to content

Commit

Permalink
Merge pull request #1456 from martinetd/cleanup_cgroup_mount
Browse files Browse the repository at this point in the history
Fix cleanup of /run/crun state dir when cgroup failed to mount
  • Loading branch information
flouthoc authored Apr 29, 2024
2 parents 1f5fa44 + 4618d50 commit 73cb769
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/libcrun/linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -1353,9 +1353,12 @@ do_mount_cgroup_v2 (libcrun_container_t *container, int targetfd, const char *ta
if (LIKELY (ret == 0))
return 0;

/* Best-effort cleanup of now-unused temporary mount */
umount2 (tmp_mount_dir, MNT_DETACH);
crun_error_release (err);
}
}
rmdir (tmp_mount_dir);
}

ret = do_mount (container, "tmpfs", targetfd, target, "tmpfs", MS_PRIVATE, "nr_blocks=1,nr_inodes=1", LABEL_NONE, err);
Expand Down
14 changes: 14 additions & 0 deletions src/libcrun/status.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <unistd.h>
#include <fcntl.h>
#include <yajl/yajl_tree.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <dirent.h>
Expand Down Expand Up @@ -485,7 +486,20 @@ rmdirfd (const char *namedir, int fd, libcrun_error_t *err)
ret = unlinkat (dirfd (d), de->d_name, 0);
if (ret < 0)
{
retry_unlink:
ret = unlinkat (dirfd (d), de->d_name, AT_REMOVEDIR);
if (ret < 0 && errno == EBUSY)
{
cleanup_close int tfd = openat (dirfd (d), de->d_name, O_CLOEXEC | O_PATH | O_NOFOLLOW);
if (tfd >= 0)
{
proc_fd_path_t procpath;

get_proc_self_fd_path (procpath, tfd);
if (umount2 (procpath, MNT_DETACH) == 0)
goto retry_unlink;
}
}
if (ret < 0 && errno == ENOTEMPTY)
{
cleanup_close int cfd = -1;
Expand Down

0 comments on commit 73cb769

Please sign in to comment.