summaryrefslogtreecommitdiff
path: root/qmenu/qmenu_vm/fqvm_pci
diff options
context:
space:
mode:
authorCasper <me@skylarcloud.xyz>2024-12-23 17:13:45 -0700
committerCasper <me@skylarcloud.xyz>2024-12-23 17:13:45 -0700
commit01a33ab0913d439150065ac23644c4f140ff8917 (patch)
tree9ad71bd7e6f5a5aad2c2cdbff4bb75de12565998 /qmenu/qmenu_vm/fqvm_pci
parent7b5a0e9e88f015cb68a46bb657661f4663e287af (diff)
added qmenu!
Diffstat (limited to 'qmenu/qmenu_vm/fqvm_pci')
-rw-r--r--qmenu/qmenu_vm/fqvm_pci70
1 files changed, 70 insertions, 0 deletions
diff --git a/qmenu/qmenu_vm/fqvm_pci b/qmenu/qmenu_vm/fqvm_pci
new file mode 100644
index 0000000..c71d055
--- /dev/null
+++ b/qmenu/qmenu_vm/fqvm_pci
@@ -0,0 +1,70 @@
+if qvm-check -q --running "$qube"; then
+
+ echo Go back... | dmenu-unlinked -p "$qube needs to be powered off, in order to attach or detach PCI devices." > /dev/null 2>&1
+else
+ list_pci=$(qvm-pci)
+
+ qvm-prefs "$qube" maxmem | grep -q ^0 ||
+
+ answer=$(printf 'Continue anyways\nDisable dynamic memory balancing' | dmenu-unlinked -l 2 -i -p "Dynamic memory balancing is enabled in $qube, some devices might not work!" | cut -f1 -d\ )
+
+ [ "$answer" = Disable ] && qvm-prefs "$qube" maxmem 0
+
+ qvm-prefs "$qube" virt_mode | grep -q pvh &&
+
+ answer=$(printf 'Continue anyways\nChange to another virtualisation mode' | dmenu-unlinked -l 2 -i -p "$qube is using PVH for its virtualisation mode, which does not support PCI passthrough!" | cut -f1 -d\ )
+
+ if [ "$answer" = Change ]; then
+
+ virtmode=$(printf 'HVM\nPV' | dmenu-unlinked -l 2 -i -p "Select virtualisation mode for $qube:") &&
+
+ qvm-prefs "$qube" virt_mode "$virtmode"
+ fi
+
+ device=1
+
+ while [ -n "$device" ]; do
+
+ device=$(echo "$list_pci" | dmenu-unlinked -l 30 -p "$qube:")
+
+ if [ -n "$device" ] && [ "$(echo "$device" | wc -l)" -eq 1 ]; then
+
+ device_src=$(echo "$device" | cut -f1 -d\ | sed 's/:.*//')
+ device_bdf=$(echo "$device" | cut -f1 -d\ | sed 's/.*://')
+
+ if echo "$device" | grep -q " $qube$\\| $qube (no-strict-reset=True)$\\| $qube (permissive=True)$"; then
+
+ if nyprompt "Detach \"$device_bdf\" from $qube?"; then
+
+ qvm-pci detach "$qube" "$device_src":"$device_bdf" ||
+
+ echo Go back... | dmenu-unlinked -p "Error: Failed to detach \"$device_bdf\" from $qube!" > /dev/null 2>&1
+
+ list_pci=$(qvm-pci)
+ fi
+ else
+ if nyprompt "Attach \"$device_bdf\" to $qube?"; then
+
+ # Check if there is more than one function
+ # that belongs to the same device.
+ bdf_count=$(echo "$list_pci" | cut -f1 -d\ | grep -c $(echo "$device_bdf" | sed 's/\..*//'))
+
+ if [ "$bdf_count" -gt 1 ]; then
+
+ [ -n "$pci_option" ] && unset pci_option
+
+ answer=$(printf 'No, attach without this option\nYes' | dmenu-unlinked -i -p "\"$device_bdf\" is most likely to be attached with the option 'no-strict-reset' enabled. Do not enable this option if you are unaware of the security implications! Do you want to attach \"$device_bdf\" with the option 'no-strict-reset' set to true?")
+
+ [ "$answer" = Yes ] && pci_option='-o no-strict-reset=True'
+ fi
+
+ qvm-pci attach --persistent $pci_option "$qube" "$device_src:$device_bdf" ||
+
+ echo Go back... | dmenu-unlinked -p "Error: Failed to attach '$device_bdf' to $qube!" > /dev/null 2>&1
+
+ list_pci=$(qvm-pci)
+ fi
+ fi
+ fi
+ done
+fi