From 6a262bdec754c90ab9cbb3504588648599c4a8b5 Mon Sep 17 00:00:00 2001
From: anatasluo <luolongjuna@gmail.com>
Date: Thu, 25 Mar 2021 11:22:43 +0800
Subject: [PATCH 08/20] kexec: do kexec load before criu dump

Signed-off-by: anatasluo <luolongjuna@gmail.com>
---
 src/server.go | 40 ++++++++++++++++++++--------------------
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/src/server.go b/src/server.go
index 79a94b9..c6eead7 100644
--- a/src/server.go
+++ b/src/server.go
@@ -252,7 +252,26 @@ func UpdateImage(ver string) int {
 		return -1
 	}
 
-	err := findPids(criuPids)
+	kexecLoad := "-l"
+	if enableQK {
+		kexecLoad = "-q"
+	}
+
+	cmdline, err := loadCmdline()
+	if err != nil {
+		log.Error(err)
+		return -1
+	}
+
+	err, _ = runCmd(kexecExe, []string{kexecLoad, "/boot/vmlinuz-" + ver,
+		"--initrd", "/boot/initramfs-" + ver + ".img", "--append=" +
+			cmdline}, os.Stdin, os.Stdout, os.Stderr)
+	if err != nil {
+		log.Errorf("Unable to load kernel image, err is %s \n", err)
+		return -1
+	}
+
+	err = findPids(criuPids)
 	if err != nil {
 		return -1
 	}
@@ -305,25 +324,6 @@ func UpdateImage(ver string) int {
 
 	DumpAllNet(configDir)
 
-	cmdline, err := loadCmdline()
-	if err != nil {
-		log.Error(err)
-		return -1
-	}
-
-	kexecLoad := "-l"
-	if enableQK {
-		kexecLoad = "-q"
-	}
-
-	err, _ = runCmd(kexecExe, []string{kexecLoad, "/boot/vmlinuz-" + ver,
-		"--initrd", "/boot/initramfs-" + ver + ".img", "--append=" +
-			cmdline}, os.Stdin, os.Stdout, os.Stderr)
-	if err != nil {
-		log.Errorf("Unable to load kernel image, err is %s \n", err)
-		return -1
-	}
-
 	err, _ = runCmd(kexecExe, []string{"-e"}, os.Stdin, os.Stdout, os.Stderr)
 	if err != nil {
 		log.Errorf("Unable to run kexec -e with err %s \n", err)
-- 
2.31.1

