2011-03-29 12:20:50 +02:00
#!/bin/sh
. "${PM_FUNCTIONS}"
2011-03-30 22:29:57 +02:00
get_running_netvms() {
# Actually get running VMs with PCI devices attached
2011-06-01 23:44:06 +02:00
RUNNING_VMS=`xl list | tail -n +3 | cut -f 1 -d " "`
2011-03-30 22:29:57 +02:00
RUNNING_NETVMS=""
for VM in $RUNNING_VMS; do
2011-06-01 23:44:06 +02:00
if [ -n "`xl pci-list $VM|tail -n +2`" ]; then
2011-03-30 22:29:57 +02:00
echo "$VM"
fi
done
}
2011-03-29 12:20:50 +02:00
suspend_net()
{
2011-03-30 22:29:57 +02:00
for VM in `get_running_netvms`; do
2012-02-01 16:04:52 +01:00
qvm-run -u root --pass-io $VM 'service NetworkManager stop; for if in `ls /sys/class/net|grep -v "lo\|vif"`; do ip l s $if down; done; modprobe -r uhci_hcd ehci_hcd'
2011-03-30 22:29:57 +02:00
done
2011-03-29 12:22:31 +02:00
# Ignore exit status from netvm...
return 0
2011-03-29 12:20:50 +02:00
}
resume_net()
{
2011-03-30 22:29:57 +02:00
for VM in `get_running_netvms`; do
2012-02-01 16:04:52 +01:00
qvm-run -u root --pass-io $VM "modprobe ehci_hcd; modprobe uhci_hcd; [ -x /bin/systemctl ] && systemctl start NetworkManager.service || service qubes_core_netvm start"
2011-03-30 22:29:57 +02:00
done
2011-03-29 12:22:31 +02:00
# Ignore exit status from netvm...
return 0
2011-03-29 12:20:50 +02:00
}
case "$1" in
resume) resume_net ;;
suspend) suspend_net ;;
*) exit 0 ;;
esac