Merge pull request #89221 from eadwu/kvmgt/mdev-multiple-uuids

This commit is contained in:
Jörg Thalheim 2020-05-30 19:45:52 +01:00 committed by GitHub
commit 319418f226
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -9,8 +9,8 @@ let
vgpuOptions = { vgpuOptions = {
uuid = mkOption { uuid = mkOption {
type = types.str; type = with types; listOf str;
description = "UUID of VGPU device. You can generate one with <package>libossp_uuid</package>."; description = "UUID(s) of VGPU device. You can generate one with <package>libossp_uuid</package>.";
}; };
}; };
@ -36,7 +36,7 @@ in {
and find info about device via <command>cat /sys/bus/pci/devices/*/mdev_supported_types/i915-GVTg_V5_4/description</command> and find info about device via <command>cat /sys/bus/pci/devices/*/mdev_supported_types/i915-GVTg_V5_4/description</command>
''; '';
example = { example = {
i915-GVTg_V5_8.uuid = "a297db4a-f4c2-11e6-90f6-d3b88d6c9525"; i915-GVTg_V5_8.uuid = [ "a297db4a-f4c2-11e6-90f6-d3b88d6c9525" ];
}; };
}; };
}; };
@ -51,31 +51,35 @@ in {
boot.kernelModules = [ "kvmgt" ]; boot.kernelModules = [ "kvmgt" ];
boot.kernelParams = [ "i915.enable_gvt=1" ]; boot.kernelParams = [ "i915.enable_gvt=1" ];
systemd.paths = mapAttrs' (name: value:
nameValuePair "kvmgt-${name}" {
description = "KVMGT VGPU ${name} path";
wantedBy = [ "multi-user.target" ];
pathConfig = {
PathExists = "/sys/bus/pci/devices/${cfg.device}/mdev_supported_types/${name}/create";
};
}
) cfg.vgpus;
services.udev.extraRules = '' services.udev.extraRules = ''
SUBSYSTEM=="vfio", OWNER="root", GROUP="kvm" SUBSYSTEM=="vfio", OWNER="root", GROUP="kvm"
''; '';
systemd.services = mapAttrs' (name: value: systemd = let
nameValuePair "kvmgt-${name}" { vgpus = listToAttrs (flatten (mapAttrsToList
description = "KVMGT VGPU ${name}"; (mdev: opt: map (id: nameValuePair "kvmgt-${id}" { inherit mdev; uuid = id; }) opt.uuid)
serviceConfig = { cfg.vgpus));
Type = "oneshot"; in {
RemainAfterExit = true; paths = mapAttrs (_: opt:
ExecStart = "${pkgs.runtimeShell} -c 'echo ${value.uuid} > /sys/bus/pci/devices/${cfg.device}/mdev_supported_types/${name}/create'"; {
ExecStop = "${pkgs.runtimeShell} -c 'echo 1 > /sys/bus/pci/devices/${cfg.device}/${value.uuid}/remove'"; description = "KVMGT VGPU ${opt.uuid} path";
}; wantedBy = [ "multi-user.target" ];
} pathConfig = {
) cfg.vgpus; PathExists = "/sys/bus/pci/devices/${cfg.device}/mdev_supported_types/${opt.mdev}/create";
};
}) vgpus;
services = mapAttrs (_: opt:
{
description = "KVMGT VGPU ${opt.uuid}";
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
ExecStart = "${pkgs.runtimeShell} -c 'echo ${opt.uuid} > /sys/bus/pci/devices/${cfg.device}/mdev_supported_types/${opt.mdev}/create'";
ExecStop = "${pkgs.runtimeShell} -c 'echo 1 > /sys/bus/pci/devices/${cfg.device}/${opt.uuid}/remove'";
};
}) vgpus;
};
}; };
meta.maintainers = with maintainers; [ gnidorah ]; meta.maintainers = with maintainers; [ gnidorah ];