summaryrefslogtreecommitdiffstats
path: root/core/modules/qemu/data/opt/openslx/scripts/systemd-qemu_env
blob: 15e904b3f39cbb29af73fa8e4f3d5755e2eeb2e3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
# -----------------------------------------------------------------------------
#
# Copyright (c) 2017..2021 bwLehrpool-Projektteam
#
# This program/file is free software distributed under the GPL version 2.
# See https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
#
# If you have any feedback please consult https://bwlehrpool.de and
# send your feedback to support@bwlehrpool.de.
#
# General information about bwLehrpool can be found at https://bwlehrpool.de
#
# -----------------------------------------------------------------------------
# systemd-qemu_env
#    - This is the preparation script for the configuration of QEMU on Linux.
################################################################################

source /opt/openslx/vmchooser/run-virt-includes/vmchooser_runvirt_functions.inc
source /opt/openslx/vmchooser/plugins/qemukvm/includes/kernel-cmdln.inc
source /opt/openslx/vmchooser/plugins/qemukvm/includes/passthrough-pci.inc
source /opt/openslx/vmchooser/plugins/qemukvm/includes/passthrough-mdev.inc

#
# setup PCI devices for passthrough if Intel PCI passthrough is enabled
#
if passthrough_pci_enabled; then
	# check if passthrough is configured properly
	if ! passthrough_pci_check; then
		slxlog --echo "qemu" "PCI device passthrough is enabled but not setup properly!"
		exit 1;
	fi

	# allow access to passthrough IOMMU devices from libvirt-passthrough group
	chown -R root:libvirt-passthrough /dev/vfio/* || slxlog --echo "qemu" "Could not set owner and group for 'vfio' IOMMU devices!"
	chmod -R 660 /dev/vfio/* || slxlog --echo "qemu" "Could not change access mode for 'vfio' IOMMU devices!"
fi

#
# create and setup Intel GVT-g mediated device instance for passthrough if Intel GVT-g is enabled
#
if passthrough_mdev_enabled; then
	# check if passthrough is configured properly
	if ! passthrough_mdev_check; then
		slxlog --echo "qemu" "mediated device passthrough is enabled but not setup properly!"
		exit 2;
	fi

	# load required kernel modules for mediated device passthrough
	modprobe "vfio-mdev" 2> /dev/null \
		|| modprobe "mdev" \
		|| { slxlog --echo "qemu" "Could not load vfio mdev kernel module!"; exit 3; }
	modprobe "kvmgt" || { slxlog --echo "qemu" "Could not load 'kvmgt' kernel module!"; exit 4; }

	# get Intel integrated GPU mediated device for passthrough
	pt_mdev_device="$(passthrough_mdev_device_get_intel_igd)"
	if [ -z "${pt_mdev_device}" ]; then
		slxlog --echo "qemu" "Could not find any Intel integrated GPU with mediated device (Intel GVT-g) support!"
		exit 5;
	fi

	# get Intel GVT-g mediated device instance type
	pt_mdev_device_type="$(passthrough_mdev_type_get "${pt_mdev_device}")"
	if [ -z "${pt_mdev_device_type}" ]; then
		slxlog --echo "qemu" "Could not obtain the mediated device instance type of the Intel integrated GPU (${pt_mdev_device})"
		exit 6;
	fi

	# generate UUID for Intel GVT-g mediated device instance
	pt_mdev_uuid="$(uuidgen)"

	# create Intel GVT-g mediated device instance
	if ! passthrough_mdev_instance_create "${pt_mdev_device}" "${pt_mdev_device_type}" "${pt_mdev_uuid}"; then
		slxlog --echo "qemu" "Failed to create Intel GVT-g mediated device instance!"
	fi
fi