Skip to content

Commit

Permalink
qemu: backport 9p-darwin to v6.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
willcohen committed Mar 9, 2022
1 parent 54da1bc commit acd6320
Show file tree
Hide file tree
Showing 5 changed files with 417 additions and 41 deletions.
83 changes: 44 additions & 39 deletions pkgs/applications/virtualization/qemu/9p-ignore-noatime.patch
Original file line number Diff line number Diff line change
@@ -1,44 +1,49 @@
commit cdc3e7eeafa9f683214d2c15d52ef384c3de6611
Author: aszlig <[email protected]>
Date: Mon Mar 18 13:21:01 2019 +0100

9pfs: Ignore O_NOATIME open flag

Since Linux 4.19, overlayfs uses the O_NOATIME flag on its lowerdir,
which in turn causes errors when the Nix store is mounted in the guest
because the file owner of the store paths typically don't match the
owner of the QEMU process.

After submitting a patch to the overlayfs mailing list[1], it turns out
that my patch was incomplete[2] and needs a bit more rework.

So instead of using an incomplete kernel patch in nixpkgs, which affects
*all* users of overlayfs, not just NixOS VM tests, I decided that for
now it's better to patch QEMU instead.

The change here really only ignores the O_NOATIME flag so that the
behaviour is similar to what NFS does. From open(2):

This flag may not be effective on all filesystems. One example is NFS,
where the server maintains the access time.

This change is therefore only temporary until the final fix lands in the
stable kernel releases.

[1]: https://www.spinics.net/lists/linux-unionfs/msg06755.html
[2]: https://www.spinics.net/lists/linux-unionfs/msg06756.html

Signed-off-by: aszlig <[email protected]>
From 9e4932ae99946b1a08ab5b5345fd2bc3486e54a5 Mon Sep 17 00:00:00 2001
From: aszlig <[email protected]>
Date: Mon, 18 Mar 2019 13:21:01 +0100
Subject: [PATCH] 9pfs: Ignore O_NOATIME open flag

Since Linux 4.19, overlayfs uses the O_NOATIME flag on its lowerdir,
which in turn causes errors when the Nix store is mounted in the guest
because the file owner of the store paths typically don't match the
owner of the QEMU process.

After submitting a patch to the overlayfs mailing list[1], it turns out
that my patch was incomplete[2] and needs a bit more rework.

So instead of using an incomplete kernel patch in nixpkgs, which affects
*all* users of overlayfs, not just NixOS VM tests, I decided that for
now it's better to patch QEMU instead.

The change here really only ignores the O_NOATIME flag so that the
behaviour is similar to what NFS does. From open(2):

This flag may not be effective on all filesystems. One example is NFS,
where the server maintains the access time.

This change is therefore only temporary until the final fix lands in the
stable kernel releases.

[1]: https://www.spinics.net/lists/linux-unionfs/msg06755.html
[2]: https://www.spinics.net/lists/linux-unionfs/msg06756.html

Signed-off-by: aszlig <[email protected]>
---
hw/9pfs/9p.c | 1 -
1 file changed, 1 deletion(-)

diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
index 55821343e5..0b8425fe18 100644
index a6d6b3f835..4eb26e2294 100644
--- a/hw/9pfs/9p.c
+++ b/hw/9pfs/9p.c
@@ -127,7 +127,6 @@ static int dotl_to_open_flags(int flags)
{ P9_DOTL_LARGEFILE, O_LARGEFILE },
{ P9_DOTL_DIRECTORY, O_DIRECTORY },
{ P9_DOTL_NOFOLLOW, O_NOFOLLOW },
@@ -139,7 +139,6 @@ static int dotl_to_open_flags(int flags)
{ P9_DOTL_DSYNC, O_DSYNC },
{ P9_DOTL_FASYNC, FASYNC },
#ifndef CONFIG_DARWIN
- { P9_DOTL_NOATIME, O_NOATIME },
{ P9_DOTL_SYNC, O_SYNC },
};

/*
* On Darwin, we could map to F_NOCACHE, which is
* similar, but doesn't quite have the same
--
2.35.1

77 changes: 77 additions & 0 deletions pkgs/applications/virtualization/qemu/allow-virtfs-on-darwin.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
From 4ca09b7cd1d42eb6b1587fed74cd4d684e31bfbe Mon Sep 17 00:00:00 2001
From: Keno Fischer <[email protected]>
Date: Sun, 27 Feb 2022 17:35:22 -0500
Subject: [PATCH] 9p: darwin: meson: Allow VirtFS on Darwin

To allow VirtFS on darwin, we need to check that pthread_fchdir_np is
available, which has only been available since macOS 10.12.

Additionally, virtfs_proxy_helper is disabled on Darwin. This patch
series does not currently provide an implementation of the proxy-helper,
but this functionality could be implemented later on.

Signed-off-by: Keno Fischer <[email protected]>
[Michael Roitzsch: - Rebase for NixOS]
Signed-off-by: Michael Roitzsch <[email protected]>
[Will Cohen: - Rebase to master]
Signed-off-by: Will Cohen <[email protected]>
Reviewed-by: Paolo Bonzini <[email protected]>
[Will Cohen: - Add check for pthread_fchdir_np to virtfs
- Add comments to patch commit
- Note that virtfs_proxy_helper does not work
on macOS
- Fully adjust meson virtfs error note to specify
macOS
- Rebase to master]
Signed-off-by: Will Cohen <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Christian Schoenebeck <[email protected]>
Acked-by: Christian Schoenebeck <[email protected]>
---
fsdev/meson.build | 1 +
meson.build | 17 +++++++++++------
2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/fsdev/meson.build b/fsdev/meson.build
index adf57cc43e..b632b66348 100644
--- a/fsdev/meson.build
+++ b/fsdev/meson.build
@@ -7,6 +7,7 @@ fsdev_ss.add(when: ['CONFIG_FSDEV_9P'], if_true: files(
'qemu-fsdev.c',
), if_false: files('qemu-fsdev-dummy.c'))
softmmu_ss.add_all(when: 'CONFIG_LINUX', if_true: fsdev_ss)
+softmmu_ss.add_all(when: 'CONFIG_DARWIN', if_true: fsdev_ss)

if have_virtfs_proxy_helper
executable('virtfs-proxy-helper',
diff --git a/meson.build b/meson.build
index 2265fa409a..6d73c02903 100644
--- a/meson.build
+++ b/meson.build
@@ -1383,12 +1383,17 @@ endif
have_host_block_device = (targetos != 'darwin' or
cc.has_header('IOKit/storage/IOMedia.h'))

-have_virtfs = (targetos == 'linux' and
- have_system and
- libattr.found() and
- libcap_ng.found())
-
-have_virtfs_proxy_helper = have_virtfs and have_tools
+have_virtfs = get_option('virtfs') \
+ .require(targetos == 'linux' or targetos == 'darwin',
+ error_message: 'virtio-9p (virtfs) requires Linux or macOS') \
+ .require(targetos == 'linux' or cc.has_function('pthread_fchdir_np'),
+ error_message: 'virtio-9p (virtfs) on macOS requires the presence of pthread_fchdir_np') \
+ .require(targetos == 'darwin' or (libattr.found() and libcap_ng.found()),
+ error_message: 'virtio-9p (virtfs) on Linux requires libcap-ng-devel and libattr-devel') \
+ .disable_auto_if(not have_tools and not have_system) \
+ .allowed()
+
+have_virtfs_proxy_helper = targetos != 'darwin' and have_virtfs and have_tools

if get_option('virtfs').enabled()
if not have_virtfs
--
2.35.1

54 changes: 52 additions & 2 deletions pkgs/applications/virtualization/qemu/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,64 @@ stdenv.mkDerivation rec {

patches = [
./fix-qemu-ga.patch
./9p-ignore-noatime.patch
# Cocoa clipboard support only works on macOS 10.14+
(fetchpatch {
url = "https://gitlab.com/qemu-project/qemu/-/commit/7e3e20d89129614f4a7b2451fe321cc6ccca3b76.diff";
sha256 = "09xz06g57wxbacic617pq9c0qb7nly42gif0raplldn5lw964xl2";
revert = true;
})
] ++ lib.optional nixosTestRunner ./force-uid0-on-9p.patch;
# 9p-darwin for 7.0 backported to 6.2.0
#
# Can generally be removed when updating derivation to 7.0. Nine of the
# patches can be drawn directly from QEMU upstream, but the second commit
# and the eleventh commit had to be modified when rebasing back to 6.2.0.
(fetchpatch {
url = "https://gitlab.com/qemu-project/qemu/-/commit/e0bd743bb2dd4985791d4de880446bdbb4e04fed.patch";
sha256 = "sha256-c6QYL3zig47fJwm6rqkqGp3E1PakVTaihvXDRebbBlQ=";
})
./rename-9p-util.patch
(fetchpatch {
url = "https://gitlab.com/qemu-project/qemu/-/commit/f41db099c71151291c269bf48ad006de9cbd9ca6.patch";
sha256 = "sha256-70/rrhZw+02JJbJ3CoW8B1GbdM4Lwb2WkUdwstYAoIQ=";
})
(fetchpatch {
url = "https://gitlab.com/qemu-project/qemu/-/commit/6b3b279bd670c6a2fa23c9049820c814f0e2c846.patch";
sha256 = "sha256-7WqklSvLirEuxTXTIMQDQhWpXnwMseJ1RumT+faq/Y8=";
})
(fetchpatch {
url = "https://gitlab.com/qemu-project/qemu/-/commit/67a71e3b71a2834d028031a92e76eb9444e423c6.patch";
sha256 = "sha256-COFm/SwfJSoSl9YDpL6ceAE8CcE4mGhsGxw1HMuL++o=";
})
(fetchpatch {
url = "https://gitlab.com/qemu-project/qemu/-/commit/38d7fd68b0c8775b5253ab84367419621aa032e6.patch";
sha256 = "sha256-iwGIzq9FWW6zpbDg/IKrp5OZpK9cgQqTRWWq8WBIHRQ=";
})
(fetchpatch {
url = "https://gitlab.com/qemu-project/qemu/-/commit/57b3910bc3513ab515296692daafd1c546f3c115.patch";
sha256 = "sha256-ybl9+umZAcQKHYL7NkGJQC0W7bccTagA9KQiFaR2LYA=";
})
(fetchpatch {
url = "https://gitlab.com/qemu-project/qemu/-/commit/b5989326f558faedd2511f29459112cced2ca8f5.patch";
sha256 = "sha256-s+O9eCgj2Ev+INjL9LY9MJBdISIdZLslI3lue2DICGM=";
})
(fetchpatch {
url = "https://gitlab.com/qemu-project/qemu/-/commit/029ed1bd9defa33a80bb40cdcd003699299af8db.patch";
sha256 = "sha256-mGqcRWcEibDJdhTRrN7ZWrMuCfUWW8vWiFj7sb2/RYo=";
})
(fetchpatch {
url = "https://gitlab.com/qemu-project/qemu/-/commit/d3671fd972cd185a6923433aa4802f54d8b62112.patch";
sha256 = "sha256-GUh5o7mbFTm/dm6CqcGdoMlC+YrV8RlcEwu/mxrfTzo=";
})
./allow-virtfs-on-darwin.patch
# QEMU upstream does not demand compatibility to pre-10.13, so 9p-darwin
# support on nix requires utimensat fallback. The patch adding this fallback
# set was removed during the process of upstreaming this functionality, and
# will still be needed in nix until the macOS SDK reaches 10.13+.
./provide-fallback-for-utimensat.patch
# Still needed indefinitely
./9p-ignore-noatime.patch
]
++ lib.optional nixosTestRunner ./force-uid0-on-9p.patch;

postPatch = ''
# Otherwise tries to ensure /var/run exists.
Expand Down
Loading

0 comments on commit acd6320

Please sign in to comment.