d00d1557b0ef1678d86834701754cda7ee826f02
[mirror/dsa-puppet.git] / modules / ganeti2 / files / qemu-system-aarch64-wrapper
1 #!/bin/bash
2
3 ##
4 ## THIS FILE IS UNDER PUPPET CONTROL. DON'T EDIT IT HERE.
5 ## USE: git clone git+ssh://$USER@puppet.debian.org/srv/puppet.debian.org/git/dsa-puppet.git
6 ##
7
8 ##
9 ## Wrapper to call qemu-system-aarch64 from Ganeti, removing all x86/PCI
10 ## assumptions.
11 ##
12
13 # Default to virt machine, forcing a gic version 3 to support more than 8 vcpus
14 machine="virt,gic-version=3"
15
16 # We want to always enable KVM. Contrary to what the Ganeti's documentation
17 # says, enabling kvm_flag is not enough.
18 args+=("-enable-kvm")
19
20 while [ "$1" ]; do
21     case "$1" in
22         -machine|-M)
23             # Ignore the machine argument (it will be defined below),
24             # except when querying the list of machines
25             if [ "$2" = "?" ] ; then
26                 args+=("-M")
27                 args+=("?")
28             fi
29             shift
30             ;;
31         -cpu)
32             # Check if the CPU is configured to run in 32-bit mode and
33             # force the gvic to version 2 in that case
34             args+=("$1")
35             args+=("$2")
36             if echo "$2" | egrep -q '(^|,)aarch64=off(,|$)' ; then
37                 machine="virt,gic-version=2"
38             fi
39             shift
40             ;;
41         *)
42             # Replace PCI devices by their bus agnostic variant, and drop
43             # all the PCI related options
44             args+=("$(echo $1 | sed -e 's/virtio-\(\w\+\)-pci/virtio-\1-device/' -e 's/,bus=[^,]\+,addr=[^,]\+//')")
45             ;;
46     esac
47     shift
48 done
49
50 # With qemu-system-aarch64 the machine should be defined even for simple
51 # commands like querying the list of devices.
52 args+=("-machine")
53 args+=($machine)
54
55 # Start qemu-system-aarch64 with the mangled arguments
56 exec /usr/bin/qemu-system-aarch64 "${args[@]}"