-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FMO-77: Modify microvm qemu into fmo-qemu (#90)
- Add functionality to read pci passthrough information from a config file during runtime instead of prebuilt nix config - Comments with "FMO" is one that modified compared to upstream microvm - Remove microvm.devices as it is now unused Signed-off-by: Anh Huy Bui <[email protected]>
- Loading branch information
1 parent
7b7ff58
commit 85aa13e
Showing
6 changed files
with
548 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
{ pkgs | ||
, microvmConfig | ||
, toplevel | ||
, ghafOS | ||
}: | ||
|
||
let | ||
inherit (pkgs) lib; | ||
|
||
inherit (import "${ghafOS.inputs.microvm}/lib" { nixpkgs-lib = lib; }) createVolumesScript makeMacvtap; | ||
inherit (makeMacvtap { | ||
inherit microvmConfig hypervisorConfig; | ||
}) openMacvtapFds macvtapFds; | ||
|
||
hypervisorConfig = import (./qemu.nix) { | ||
inherit pkgs microvmConfig macvtapFds; | ||
}; | ||
|
||
inherit (hypervisorConfig) command canShutdown shutdownCommand; | ||
supportsNotifySocket = hypervisorConfig.supportsNotifySocket or false; | ||
preStart = hypervisorConfig.preStart or microvmConfig.preStart; | ||
tapMultiQueue = hypervisorConfig.tapMultiQueue or false; | ||
|
||
execArg = lib.optionalString microvmConfig.prettyProcnames | ||
''-a "microvm@${microvmConfig.hostName}"''; | ||
|
||
# FMO: Use command in an array format | ||
runScriptBin = pkgs.writeShellScriptBin "microvm-run" '' | ||
${preStart} | ||
${createVolumesScript pkgs.buildPackages microvmConfig.volumes} | ||
${lib.optionalString (hypervisorConfig.requiresMacvtapAsFds or false) openMacvtapFds} | ||
CMD=(${command}) | ||
exec ${execArg} "''${CMD[@]}" | ||
''; | ||
|
||
shutdownScriptBin = pkgs.writeShellScriptBin "microvm-shutdown" '' | ||
${shutdownCommand} | ||
''; | ||
|
||
balloonScriptBin = pkgs.writeShellScriptBin "microvm-balloon" '' | ||
set -e | ||
if [ -z "$1" ]; then | ||
echo "Usage: $0 <balloon-size-mb>" | ||
exit 1 | ||
fi | ||
SIZE=$1 | ||
${hypervisorConfig.setBalloonScript} | ||
''; | ||
in | ||
|
||
pkgs.buildPackages.runCommand "microvm-${microvmConfig.hypervisor}-${microvmConfig.hostName}" | ||
{ | ||
# for `nix run` | ||
meta.mainProgram = "microvm-run"; | ||
passthru = { | ||
inherit canShutdown supportsNotifySocket; | ||
inherit (microvmConfig) hypervisor; | ||
}; | ||
} '' | ||
mkdir -p $out/bin | ||
ln -s ${runScriptBin}/bin/microvm-run $out/bin/microvm-run | ||
${if canShutdown | ||
then "ln -s ${shutdownScriptBin}/bin/microvm-shutdown $out/bin/microvm-shutdown" | ||
else ""} | ||
${lib.optionalString ((hypervisorConfig.setBalloonScript or null) != null) '' | ||
ln -s ${balloonScriptBin}/bin/microvm-balloon $out/bin/microvm-balloon | ||
''} | ||
mkdir -p $out/share/microvm | ||
ln -s ${toplevel} $out/share/microvm/system | ||
echo vnet_hdr > $out/share/microvm/tap-flags | ||
${lib.optionalString tapMultiQueue '' | ||
echo multi_queue >> $out/share/microvm/tap-flags | ||
''} | ||
${lib.concatMapStringsSep " " (interface: | ||
lib.optionalString (interface.type == "tap" && interface ? id) '' | ||
echo "${interface.id}" >> $out/share/microvm/tap-interfaces | ||
'') microvmConfig.interfaces} | ||
${lib.concatMapStringsSep " " (interface: | ||
lib.optionalString ( | ||
interface.type == "macvtap" && | ||
interface ? id && | ||
(interface.macvtap.link or null) != null && | ||
(interface.macvtap.mode or null) != null | ||
) '' | ||
echo "${builtins.concatStringsSep " " [ | ||
interface.id | ||
interface.mac | ||
interface.macvtap.link | ||
(builtins.toString interface.macvtap.mode) | ||
]}" >> $out/share/microvm/macvtap-interfaces | ||
'') microvmConfig.interfaces} | ||
${lib.concatMapStrings ({ tag, socket, source, proto, ... }: | ||
lib.optionalString (proto == "virtiofs") '' | ||
mkdir -p $out/share/microvm/virtiofs/${tag} | ||
echo "${socket}" > $out/share/microvm/virtiofs/${tag}/socket | ||
echo "${source}" > $out/share/microvm/virtiofs/${tag}/source | ||
'' | ||
) microvmConfig.shares} | ||
${pkgs.coreutils}/bin/ln -s ${microvmConfig.pciConfigPath} $out/share/microvm/pci-devices | ||
'' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Copyright 2022-2024 TII (SSRC) and the Ghaf contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
{pkgs, microvmConfig}: | ||
# FMO: A helper function to generate pci passthrough options in the qemu command | ||
pkgs.writeShellScriptBin "pci-passthrough-options" '' | ||
pciDevices=$(cat ${microvmConfig.pciConfigPath}) | ||
for device in $pciDevices; do | ||
echo -n "-device vfio-pci,host=$device,multifunction=on " | ||
done | ||
'' |
Oops, something went wrong.