git.iko.soy/typeable/nixpkgs
on master help sign in
Merge overlayfs fix, LTS kernel bump and test

In Linux 4.19 there has been a major rework of the overlayfs implementation and it now opens files in lowerdir with O_NOATIME, which in turn caused issues in our VM tests because the process owner of QEMU doesn't match the file owner of the lowerdir. The crux here is that 9p propagates the O_NOATIME flag to the host and the guest kernel has no way of verifying whether that flag will lead to any problems beforehand. There is ongoing work to possibly fix this in the kernel, but it will take a while until there is a working patch and consensus. So in order to bring our default kernel back to 4.19 and of course make it possible to run newer kernels in VM tests, I'm merging a small QEMU patch as an interim solution, which we can drop once we have a working fix in the next round of stable kernels. Now we already had Linux 4.19 set as the default kernel, but that was subsequently reverted in 048c36ccaa0add5e5de387e9de0d3775d3fdd10d because the patch we have used was the revert of the commit I bisected a while ago. This patch broke overlayfs in other ways, so I'm also merging in a VM test by @bachp, which only tests whether overlayfs is working, just to be on the safe side that something like this won't happen in the future. Even though this change could be considered a moderate mass-rebuild at least for GNU/Linux, I'm merging this to master, mainly to give us some time to get it into the current 19.03 release branch (and subsequent testing window) once we got no new breaking builds from Hydra. Cc: @samueldr, @lheckemann Fixes: https://github.com/NixOS/nixpkgs/issues/54509 Fixes: https://github.com/NixOS/nixpkgs/issues/48828 Merges: https://github.com/NixOS/nixpkgs/pull/57641 Merges: https://github.com/NixOS/nixpkgs/pull/54508

commit12efcc2dee4f2fe7ff3bd8143fc3750d8d4fdb39 authoraszlig <aszlig@nix.build> dateTue 19 Mar 2019, 00:15 (8 years ago) parent8fce8a99a395a4a8307b9
5 files changed+104−1
nixos/tests/all-tests.nix+1 nixos/tests/overlayfs.nix+57 pkgs/applications/virtualization/qemu/9p-ignore-noatime.patch+44 pkgs/applications/virtualization/qemu/default.nix+1 pkgs/top-level/all-packages.nix+1−1
nixos/tests/all-tests.nix+1
@@ -174,6 +174,7 @@ in
174174 osquery = handleTest ./osquery.nix {};
175175 osrm-backend = handleTest ./osrm-backend.nix {};
176176 ostree = handleTest ./ostree.nix {};
177+ overlayfs = handleTest ./overlayfs.nix {};
177178 pam-oath-login = handleTest ./pam-oath-login.nix {};
178179 pam-u2f = handleTest ./pam-u2f.nix {};
179180 pantheon = handleTest ./pantheon.nix {};
nixos/tests/overlayfs.nixnew file+57
@@ -0,0 +1,57 @@
1+import ./make-test.nix ({ pkgs, ... }: {
2+ name = "overlayfs";
3+ meta.maintainers = with pkgs.stdenv.lib.maintainers; [ bachp ];
4+
5+ machine = { pkgs, ... }: {
6+ virtualisation.emptyDiskImages = [ 512 ];
7+ networking.hostId = "deadbeef";
8+ environment.systemPackages = with pkgs; [ parted ];
9+ };
10+
11+ testScript = ''
12+ $machine->succeed("ls /dev");
13+
14+ $machine->succeed("mkdir -p /tmp/mnt");
15+
16+ # Test ext4 + overlayfs
17+ $machine->succeed(
18+
19+ "mkfs.ext4 -F -L overlay-ext4 /dev/vdb",
20+ "mount -t ext4 /dev/vdb /tmp/mnt",
21+
22+ "mkdir -p /tmp/mnt/upper /tmp/mnt/lower /tmp/mnt/work /tmp/mnt/merged",
23+
24+ # Setup some existing files
25+ "echo 'Replace' > /tmp/mnt/lower/replace.txt",
26+ "echo 'Append' > /tmp/mnt/lower/append.txt",
27+ "echo 'Overwrite' > /tmp/mnt/lower/overwrite.txt",
28+
29+ "mount -t overlay overlay -o lowerdir=/tmp/mnt/lower,upperdir=/tmp/mnt/upper,workdir=/tmp/mnt/work /tmp/mnt/merged",
30+
31+ # Test new
32+ "echo 'New' > /tmp/mnt/merged/new.txt",
33+ "[[ \"\$(cat /tmp/mnt/merged/new.txt)\" == \"New\" ]]",
34+
35+ # Test replace
36+ "[[ \"\$(cat /tmp/mnt/merged/replace.txt)\" == \"Replace\" ]]",
37+ "echo 'Replaced' > /tmp/mnt/merged/replace-tmp.txt",
38+ "mv /tmp/mnt/merged/replace-tmp.txt /tmp/mnt/merged/replace.txt",
39+ "[[ \"\$(cat /tmp/mnt/merged/replace.txt)\" == \"Replaced\" ]]",
40+
41+ # Overwrite
42+ "[[ \"\$(cat /tmp/mnt/merged/overwrite.txt)\" == \"Overwrite\" ]]",
43+ "echo 'Overwritten' > /tmp/mnt/merged/overwrite.txt",
44+ "[[ \"\$(cat /tmp/mnt/merged/overwrite.txt)\" == \"Overwritten\" ]]",
45+
46+ # Test append
47+ "[[ \"\$(cat /tmp/mnt/merged/append.txt)\" == \"Append\" ]]",
48+ "echo 'ed' >> /tmp/mnt/merged/append.txt",
49+ #"cat /tmp/mnt/merged/append.txt && exit 1",
50+ "[[ \"\$(cat /tmp/mnt/merged/append.txt)\" == \"Append\ned\" ]]",
51+
52+ "umount /tmp/mnt/merged",
53+ "umount /tmp/mnt",
54+ "udevadm settle"
55+ );
56+ '';
57+})
pkgs/applications/virtualization/qemu/9p-ignore-noatime.patchnew file+44
@@ -0,0 +1,44 @@
1+commit cdc3e7eeafa9f683214d2c15d52ef384c3de6611
2+Author: aszlig <aszlig@nix.build>
3+Date: Mon Mar 18 13:21:01 2019 +0100
4+
5+ 9pfs: Ignore O_NOATIME open flag
6+
7+ Since Linux 4.19, overlayfs uses the O_NOATIME flag on its lowerdir,
8+ which in turn causes errors when the Nix store is mounted in the guest
9+ because the file owner of the store paths typically don't match the
10+ owner of the QEMU process.
11+
12+ After submitting a patch to the overlayfs mailing list[1], it turns out
13+ that my patch was incomplete[2] and needs a bit more rework.
14+
15+ So instead of using an incomplete kernel patch in nixpkgs, which affects
16+ *all* users of overlayfs, not just NixOS VM tests, I decided that for
17+ now it's better to patch QEMU instead.
18+
19+ The change here really only ignores the O_NOATIME flag so that the
20+ behaviour is similar to what NFS does. From open(2):
21+
22+ This flag may not be effective on all filesystems. One example is NFS,
23+ where the server maintains the access time.
24+
25+ This change is therefore only temporary until the final fix lands in the
26+ stable kernel releases.
27+
28+ [1]: https://www.spinics.net/lists/linux-unionfs/msg06755.html
29+ [2]: https://www.spinics.net/lists/linux-unionfs/msg06756.html
30+
31+ Signed-off-by: aszlig <aszlig@nix.build>
32+
33+diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
34+index 55821343e5..0b8425fe18 100644
35+--- a/hw/9pfs/9p.c
36++++ b/hw/9pfs/9p.c
37+@@ -127,7 +127,6 @@ static int dotl_to_open_flags(int flags)
38+ { P9_DOTL_LARGEFILE, O_LARGEFILE },
39+ { P9_DOTL_DIRECTORY, O_DIRECTORY },
40+ { P9_DOTL_NOFOLLOW, O_NOFOLLOW },
41+- { P9_DOTL_NOATIME, O_NOATIME },
42+ { P9_DOTL_SYNC, O_SYNC },
43+ };
44+
pkgs/applications/virtualization/qemu/default.nix+1
@@ -76,6 +76,7 @@ stdenv.mkDerivation rec {
7676 patches = [
7777 ./no-etc-install.patch
7878 ./fix-qemu-ga.patch
79+ ./9p-ignore-noatime.patch
7980 ] ++ optional nixosTestRunner ./force-uid0-on-9p.patch
8081 ++ optional pulseSupport ./fix-hda-recording.patch
8182 ++ optionals stdenv.hostPlatform.isMusl [
pkgs/top-level/all-packages.nix+1−1
@@ -14903,7 +14903,7 @@ in
1490314903 });
1490414904
1490514905 # The current default kernel / kernel modules.
14906− linuxPackages = linuxPackages_4_14;
14906+ linuxPackages = linuxPackages_4_19;
1490714907 linux = linuxPackages.kernel;
1490814908
1490914909 # Update this when adding the newest kernel major version!