← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~cjwatson/launchpad-buildd/loop-udev-race into lp:launchpad-buildd

 

Colin Watson has proposed merging lp:~cjwatson/launchpad-buildd/loop-udev-race into lp:launchpad-buildd.

Commit message:
Defend against racing with udev to create loop devices in trusty containers (LP: #1723216).

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #1723216 in launchpad-buildd: "buildd fails to build trusty based images with `mknod: ‘/dev/loopX’: File exists` errors"
  https://bugs.launchpad.net/launchpad-buildd/+bug/1723216

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad-buildd/loop-udev-race/+merge/332371
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad-buildd/loop-udev-race into lp:launchpad-buildd.
=== modified file 'debian/changelog'
--- debian/changelog	2017-09-13 13:57:34 +0000
+++ debian/changelog	2017-10-17 16:24:03 +0000
@@ -1,3 +1,10 @@
+launchpad-buildd (153) UNRELEASED; urgency=medium
+
+  * Defend against racing with udev to create loop devices in trusty
+    containers (LP: #1723216).
+
+ -- Colin Watson <cjwatson@xxxxxxxxxx>  Tue, 17 Oct 2017 17:19:44 +0100
+
 launchpad-buildd (152) xenial; urgency=medium
 
   [ Colin Watson ]

=== modified file 'lpbuildd/target/lxd.py'
--- lpbuildd/target/lxd.py	2017-09-11 14:54:23 +0000
+++ lpbuildd/target/lxd.py	2017-10-17 16:24:03 +0000
@@ -331,6 +331,26 @@
             policy_rc_d_file.flush()
             os.fchmod(policy_rc_d_file.fileno(), 0o755)
             self.copy_in(policy_rc_d_file.name, "/usr/local/sbin/policy-rc.d")
+        # Ensure that loop devices are not created, even if the target
+        # system's udev rules would ordinarily do so.  We can't do it the
+        # other way round (ensure that udev always creates them) because not
+        # all buildd chroots have udev.
+        # Poking this into /lib is wrong, but /etc/udev/rules.d/ doesn't
+        # exist in all buildd chroots, and xenial's LXD doesn't support
+        # creating directories when pushing files.  The containers won't be
+        # upgraded in ways that make this be a problem anyway.
+        with tempfile.NamedTemporaryFile(mode="w+") as udev_rules_file:
+            # Copied from systemd 234.
+            print(
+                'SUBSYSTEM=="block", KERNEL=="loop[0-9]*", '
+                'ENV{DEVTYPE}=="disk", TEST!="loop/backing_file", '
+                'ENV{SYSTEMD_READY}="0"',
+                file=udev_rules_file)
+            udev_rules_file.flush()
+            os.fchmod(udev_rules_file.fileno(), 0o644)
+            self.copy_in(
+                udev_rules_file.name,
+                "/lib/udev/rules.d/99-zz-buildd-loop.rules")
 
         # Start the container and wait for it to start.
         container.start(wait=True)