Centralize the gathering of mounts and devices and move them to the create phase#835
Centralize the gathering of mounts and devices and move them to the create phase#835cmainas wants to merge 3 commits into
Conversation
Gather all the mounts for the monitor execution environment and the contianer in a single list which is later given as an argument in applyMOunts to perform all the necessary mounts. Signed-off-by: Charalampos Mainas <cmainas@nubificus.co.uk>
✅ Deploy Preview for urunc canceled.
|
|
Amazing regression issues here https://github.com/urunc-dev/urunc/actions/runs/29594391629/job/87931466697?pr=835 A normal file getting mounted and then passed as volume in the container is a loopback device. However, now that we finally properly unmount block devices from the original mount namespace, the llopback device gets removed. Therefore, we setup a device that does not exist. anymore... We need to trace back to the backing file. On top of that, we totally unmount the device and the second test does not even find the device, since it no longer exeists and therefore skips it... |
81b9fc3 to
55a3ef0
Compare
55a3ef0 to
4e3d1d9
Compare
|
Tested this on our dev box: standard qemu/fc boots are fine, and I also exercised the new block volume path with a loop-mounted ext2 file bind-mounted through ctr. The unmount-at-create, autoclear handling and the restore on delete all behave as described -- nice work handling that loop device quirk! A few comments:
Also, quick question on dropping All of the above are optional, maybe apart from the typo fixes in (5) -- will approve on your ack. |
|
Hello @ananos , thank you for the review and further testing.
Yeah, I did not consider a case where a host does not have
Yes, this is a side effect that it is not easy to handle. I think we should also document it in our docs.
Yeap, I can add that too.
This is handled from a follow up PR. #840 which depends on this one.
I will fix that.
Yeap, but I had the same concerns when I was adding the support for non-root execution of the monitor process, because we had to belong to the KVM group and while usually these group ids have some "usual" values, there is no guarantee they will stay the same across different platforms and they can change (for various reasons) leading to unexpected and unwanted behavior. I think a workaround for this would be to let the user specify these group idss in the configuration. There is also the option that we search and find these gids, but this extra overhead for every container execution. |
Similarly with mounts, gather all devices in a single slice and then recreate them inside the monitor's execution environment. The only exception is vAccel related devices. We need to handle the case of vAccel separately for the libcontainer migration. Signed-off-by: Charalampos Mainas <cmainas@nubificus.co.uk>
Move the logic that gathers all needed devices and mounts for monitor execution environment in InitialSetup during "urunc create" and then write the information to a file (monitor.json) which Exec will read and apply the mounts, plus create the devices. THis is necessary for the libcontainer refactor. One important note, we always include the /dev/net/tun device from "urunc create" because ein that phase we have no information about the networking of the container. Therefore, we include the device and then let Exec (which is part of "urunc reexec" and CNI hooks have been executed) to choose if it will create or not the device. The fact that we now unmount the block-based mounts in the create phase also has the side effect that we mess up with the mount of someone else's. These mounts do not belong to urunc and we should restore them back. Furthermore, as shown from the CI testing, block-based mounts which are backed from a disk file (e.g. a custom made ext2 file image) are mounted as loop devices and hence unmounting them might remove the loop device. For that reason, we unset the autoclear flag of the loop device to ensure that the loop device will remain and we will be able to attach it later in the sandbox. We bring back the original flag during cleanup. Signed-off-by: Charalampos Mainas <cmainas@nubificus.co.uk>
4e3d1d9 to
dcb4ce3
Compare
|
I have addressed the above comments by:
|
dcb4ce3 to
b7c2e2b
Compare
Description
This is yet another refactor of the way we handle the rootfs for the monitor process. The core idea is to gather all mounts and devices and apply them from a single function rather than setting them up one by one. This is also necessary in order to move the logic of mounts and devices gathering ti the create phase. Since, we move this logic in "urunc create" we need to pass the findings to the "reexec" process. For that purpose, this PR introduces a new file
monitor.jsonwhich is stored in the bundle directory and simply holds the information for the mounts, devices and block mounts to attach to the sandbox. Such file will be necessary later for libcontainers migration because we need to distinguish the host and the guest environment configuration.The fact that we now unmount the block-based mounts in the create phase also has the side effect that we mess up with the mount of someone else's. These mounts do not belong to urunc and we should restore them back. Furthermore, as shown from the CI testing, block-based mounts which are backed from a disk file (e.g. a custom made ext2 file image) are mounted as loop devices and hence unmounting them might remove the loop device. For that reason, we unset the autoclear flag of the loop device to ensure that the loop device will remain and we will be able to attach it later in the sandbox. We bring back the original flag during cleanup.
Some other important notes:
/dev/net/tundevice is always listed as device from the "urunc create" because it does not have the necessary information to determine if the container has network. This is later determined by the Exec process when it sets up the network. In that phase the CNI hooks have been executed and we can know if there is a virtual ethernet device inside the network namespace (meaning we have network).gid=5) have been removed, since they are unnecessary.Related issues
How was this tested?
with e2e tests
LLM usage
Opus 4.8 for applying the same change to multiple similar functions (e.g. rootfsBuilder interface) and grouping the logic that retrieves the mounts and the devices
Checklist
make lint).make test_ctr,make test_nerdctl,make test_docker,make test_crictl).