51qubes-suspend-netvm 806 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/bin/sh
  2. . "${PM_FUNCTIONS}"
  3. get_running_netvms() {
  4. # Actually get running VMs with PCI devices attached
  5. RUNNING_VMS=`xl list | tail -n +3 | cut -f 1 -d " "`
  6. RUNNING_NETVMS=""
  7. for VM in $RUNNING_VMS; do
  8. if [ -n "`xl pci-list $VM|tail -n +2`" ]; then
  9. echo "$VM"
  10. fi
  11. done
  12. }
  13. suspend_net()
  14. {
  15. for VM in `get_running_netvms`; do
  16. qvm-run -u root --pass-io $VM 'QUBESRPC qubes.SuspendPre dom0'
  17. done
  18. # Ignore exit status from netvm...
  19. return 0
  20. }
  21. resume_net()
  22. {
  23. for VM in `get_running_netvms`; do
  24. qvm-run -u root --pass-io $VM 'QUBESRPC qubes.SuspendPost dom0'
  25. done
  26. # Ignore exit status from netvm...
  27. return 0
  28. }
  29. case "$1" in
  30. resume) resume_net ;;
  31. suspend) suspend_net ;;
  32. *) exit 0 ;;
  33. esac