From 97dc8a88e579d52828b987c371455a0943054ca5 Mon Sep 17 00:00:00 2001 From: aszlig Date: Wed, 7 May 2014 06:48:53 +0200 Subject: [PATCH] vm/windows: Wait for migration to finish. This ensures that the intermediate machine is shut down only after the migration has finished writing the memory dump to disk, to ensure we don't end up with empty state files depending on how fast the migration finished before we actually shut down the VM. Signed-off-by: aszlig --- pkgs/build-support/vm/windows/bootstrap.nix | 4 ++-- .../vm/windows/controller/default.nix | 15 ++++++++++++--- pkgs/build-support/vm/windows/default.nix | 1 + 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/pkgs/build-support/vm/windows/bootstrap.nix b/pkgs/build-support/vm/windows/bootstrap.nix index 47afce5b5a37..e3b44d1b6ab7 100644 --- a/pkgs/build-support/vm/windows/bootstrap.nix +++ b/pkgs/build-support/vm/windows/bootstrap.nix @@ -1,6 +1,6 @@ { stdenv, fetchurl, vmTools, writeScript, writeText, runCommand, makeInitrd , python, perl, coreutils, dosfstools, gzip, mtools, netcat, openssh, qemu -, samba, socat, vde2, cdrkit, pathsFromGraph +, samba, socat, vde2, cdrkit, pathsFromGraph, gnugrep }: { isoFile, productKey, arch ? null }: @@ -10,7 +10,7 @@ with stdenv.lib; let controller = import ./controller { inherit stdenv writeScript vmTools makeInitrd; - inherit samba vde2 openssh socat netcat coreutils gzip; + inherit samba vde2 openssh socat netcat coreutils gzip gnugrep; }; mkCygwinImage = import ./cygwin-iso { diff --git a/pkgs/build-support/vm/windows/controller/default.nix b/pkgs/build-support/vm/windows/controller/default.nix index ee9bf0286943..0beaf401758a 100644 --- a/pkgs/build-support/vm/windows/controller/default.nix +++ b/pkgs/build-support/vm/windows/controller/default.nix @@ -1,5 +1,5 @@ { stdenv, writeScript, vmTools, makeInitrd -, samba, vde2, openssh, socat, netcat, coreutils, gzip +, samba, vde2, openssh, socat, netcat, coreutils, gnugrep, gzip }: { sshKey @@ -217,17 +217,26 @@ let fi ''; + toMonitor = "${socat}/bin/socat - UNIX-CONNECT:$MONITOR_SOCKET"; + postVM = if suspendTo != null then '' while ! test -e "$XCHG_DIR/suspend_now"; do ${checkDropOut} ${coreutils}/bin/sleep 1 done - ${socat}/bin/socat - UNIX-CONNECT:$MONITOR_SOCKET < '${suspendTo}'" - quit CMD + echo -n "Waiting for memory dump to finish..." + while ! echo info migrate | ${toMonitor} | \ + ${gnugrep}/bin/grep -qi '^migration *status: *complete'; do + ${coreutils}/bin/sleep 1 + echo -n . + done + echo " done." + echo quit | ${toMonitor} wait $(< "$WINVM_PIDFILE") eval "$postVM" exit 0 diff --git a/pkgs/build-support/vm/windows/default.nix b/pkgs/build-support/vm/windows/default.nix index f9b44d450d99..f9f1d75c70d6 100644 --- a/pkgs/build-support/vm/windows/default.nix +++ b/pkgs/build-support/vm/windows/default.nix @@ -5,6 +5,7 @@ let inherit (pkgs) stdenv vmTools writeScript writeText runCommand makeInitrd; inherit (pkgs) coreutils dosfstools gzip mtools netcat openssh qemu samba; inherit (pkgs) socat vde2 fetchurl python perl cdrkit pathsFromGraph; + inherit (pkgs) gnugrep; }; builder = ''