← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~vorlon/launchpad-buildd:devtmpfs into launchpad-buildd:master

 

Steve Langasek has proposed merging ~vorlon/launchpad-buildd:devtmpfs into launchpad-buildd:master.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~vorlon/launchpad-buildd/+git/launchpad-buildd/+merge/442776

To address race conditions when using kpartx to expose partitions on loop devices, we would like to move livecd-rootfs to use `losetup -P`, which synchronously creates all of the necessary devices in the kernel without races.

The problem is that the kernel creates these device nodes on devtmpfs - which is not mounted in the container.

Since the lxd target in launchpad-buildd is already a privileged container, I propose simply mounting devtmpfs in the container as well so that the kernel-created device nodes are exposed.

This also lets us remove some other code for manually creating devices as these will be populated by default by the kernel.

I am not confident that the changes here around nvidia device creation are correct.  I am assuming these devices will be created automatically on module load but I am not in a position to verify this at the moment.

The dm-* devices are *not* something that would be precreated by the kernel so I think we still need the code to mknod these.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~vorlon/launchpad-buildd:devtmpfs into launchpad-buildd:master.
diff --git a/lpbuildd/target/lxd.py b/lpbuildd/target/lxd.py
index fb0aad1..2512043 100644
--- a/lpbuildd/target/lxd.py
+++ b/lpbuildd/target/lxd.py
@@ -430,6 +430,8 @@ class LXD(Backend):
             ("lxc.cgroup.devices.allow", ""),
             ("lxc.mount.auto", ""),
             ("lxc.mount.auto", "proc:rw sys:rw"),
+            ("lxc.mount.entry","udev /dev devtmpfs rw,nosuid,relatime,mode=755,inode64"),
+            ("lxc.autodev", "0"),
         ]
 
         lxc_version = self._client.host_info["environment"]["driver_version"]
@@ -586,26 +588,6 @@ class LXD(Backend):
                 "Container failed to start within %d seconds" % timeout
             )
 
-        # Create loop devices.  We do this by hand rather than via the LXD
-        # profile, as the latter approach creates lots of independent mounts
-        # under /dev/, and that can cause confusion when building live
-        # filesystems.
-        self.run(
-            ["mknod", "-m", "0660", "/dev/loop-control", "c", "10", "237"]
-        )
-        for minor in range(256):
-            self.run(
-                [
-                    "mknod",
-                    "-m",
-                    "0660",
-                    "/dev/loop%d" % minor,
-                    "b",
-                    "7",
-                    str(minor),
-                ]
-            )
-
         # Create dm-# devices.  On focal kpartx looks for dm devices and hangs
         # in their absence.
         major = get_device_mapper_major()
@@ -623,26 +605,6 @@ class LXD(Backend):
             )
 
         if "gpu-nvidia" in self.constraints:
-            # Create nvidia* devices.  We have to do this here rather than
-            # bind-mounting them into the container, because bind-mounts
-            # aren't propagated into snaps (such as lxd) installed inside
-            # the container.
-            for path in self._nvidia_container_paths:
-                if path.startswith("/dev/"):
-                    st = os.stat(path)
-                    if stat.S_ISCHR(st.st_mode):
-                        self.run(
-                            [
-                                "mknod",
-                                "-m",
-                                "0%o" % stat.S_IMODE(st.st_mode),
-                                path,
-                                "c",
-                                str(os.major(st.st_rdev)),
-                                str(os.minor(st.st_rdev)),
-                            ]
-                        )
-
             # We bind-mounted several libraries into the container, so run
             # ldconfig to update the dynamic linker's cache.
             self.run(["/sbin/ldconfig"])
diff --git a/lpbuildd/target/tests/test_lxd.py b/lpbuildd/target/tests/test_lxd.py
index 04078fa..9eefd66 100644
--- a/lpbuildd/target/tests/test_lxd.py
+++ b/lpbuildd/target/tests/test_lxd.py
@@ -309,6 +309,8 @@ class TestLXD(TestCase):
             ("lxc.cgroup.devices.allow", ""),
             ("lxc.mount.auto", ""),
             ("lxc.mount.auto", "proc:rw sys:rw"),
+            ("lxc.mount.entry","udev /dev devtmpfs rw,nosuid,relatime,mode=755,inode64"),
+            ("lxc.autodev", "0"),
         ]
 
         major, minor = (int(v) for v in driver_version.split(".")[0:2])
@@ -589,35 +591,8 @@ class TestLXD(TestCase):
                 ),
                 Equals(["hostname"]),
                 Equals(["hostname", "--fqdn"]),
-                Equals(
-                    lxc
-                    + [
-                        "mknod",
-                        "-m",
-                        "0660",
-                        "/dev/loop-control",
-                        "c",
-                        "10",
-                        "237",
-                    ]
-                ),
             ]
         )
-        for minor in range(256):
-            expected_args.append(
-                Equals(
-                    lxc
-                    + [
-                        "mknod",
-                        "-m",
-                        "0660",
-                        "/dev/loop%d" % minor,
-                        "b",
-                        "7",
-                        str(minor),
-                    ]
-                )
-            )
         for minor in range(8):
             expected_args.append(
                 Equals(
@@ -636,30 +611,6 @@ class TestLXD(TestCase):
         if gpu_nvidia:
             expected_args.extend(
                 [
-                    Equals(
-                        lxc
-                        + [
-                            "mknod",
-                            "-m",
-                            "0666",
-                            "/dev/nvidia0",
-                            "c",
-                            "195",
-                            "0",
-                        ]
-                    ),
-                    Equals(
-                        lxc
-                        + [
-                            "mknod",
-                            "-m",
-                            "0666",
-                            "/dev/nvidiactl",
-                            "c",
-                            "195",
-                            "255",
-                        ]
-                    ),
                     Equals(lxc + ["/sbin/ldconfig"]),
                 ]
             )

Follow ups