[CRIU] [PATCH 3/3] p.haul: implement Virtuozzo specific container restore
Nikita Spiridonov
nspiridonov at odin.com
Fri Sep 4 04:15:23 PDT 2015
It is needed to exec vzctl restore instead of usual criu restore
request to successfully restore Virtuozzo containers. Implement
Virtuozzo specific restore.
Signed-off-by: Nikita Spiridonov <nspiridonov at odin.com>
---
phaul/criu_api.py | 5 ++++-
phaul/criu_req.py | 4 ++--
phaul/p_haul_vz.py | 30 +++++++++++++++++++++++++++++-
3 files changed, 35 insertions(+), 4 deletions(-)
diff --git a/phaul/criu_api.py b/phaul/criu_api.py
index 1b7781d..2946e6d 100644
--- a/phaul/criu_api.py
+++ b/phaul/criu_api.py
@@ -54,7 +54,7 @@ class criu_conn:
def send_req(self, req):
req.opts.log_level = self.verb
- req.opts.log_file = "criu_%s.%d.log" % (criu_req.get_name(req), self._iter)
+ req.opts.log_file = self.get_log_name(req.type)
self._cs.send(req.SerializeToString())
self._iter += 1
self._last_req = req.type
@@ -69,6 +69,9 @@ class criu_conn:
return self._recv_resp()
+ def get_log_name(self, req_type):
+ return "criu_%s.%d.log" % (criu_req.get_name(req_type), self._iter)
+
#
# Helper to read CRIU-generated statistics
#
diff --git a/phaul/criu_req.py b/phaul/criu_req.py
index fc03093..42225aa 100644
--- a/phaul/criu_req.py
+++ b/phaul/criu_req.py
@@ -13,9 +13,9 @@ _names = {
pycriu.rpc.CPUINFO_CHECK: "cpuinfo-check",
}
-def get_name(req):
+def get_name(req_type):
"""Return printable request name"""
- return _names[req.type]
+ return _names[req_type]
def _make_req(typ, htype):
"""Prepare generic criu request"""
diff --git a/phaul/p_haul_vz.py b/phaul/p_haul_vz.py
index 76230d7..546a876 100644
--- a/phaul/p_haul_vz.py
+++ b/phaul/p_haul_vz.py
@@ -3,6 +3,7 @@
#
import os
+import subprocess
import shlex
import p_haul_cgroup
import p_haul_module
@@ -15,6 +16,7 @@ name = "vz"
vz_global_conf = "/etc/vz/vz.conf"
vz_conf_dir = "/etc/vz/conf/"
cg_image_name = "ovzcg.img"
+vzctl_bin = "vzctl"
class p_haul_type:
def __init__(self, ctid):
@@ -140,8 +142,34 @@ class p_haul_type:
# Keep this name, we'll need one in prepare_ct()
self.cg_img = os.path.join(path, cg_image_name)
+ def __setup_restore_extra_args(self, path, img, connection):
+ """Create temporary file with extra arguments for criu restore"""
+ extra_args = [
+ "VE_WORK_DIR={0}\n".format(img.work_dir()),
+ "VE_RESTORE_LOG_PATH={0}\n".format(
+ connection.get_log_name(pycriu.rpc.RESTORE))]
+ with open(path, "w") as f:
+ f.writelines(extra_args)
+
+ def __remove_restore_extra_args(self, path):
+ """Remove temporary file with extra arguments for criu restore"""
+ if os.path.isfile(path):
+ os.remove(path)
+
def final_restore(self, img, connection):
- p_haul_module.final_restore(self, img, connection)
+ """Perform Virtuozzo-specific final restore"""
+ try:
+ # Setup restore extra arguments
+ args_path = os.path.join(img.image_dir(), "restore-extra-args")
+ self.__setup_restore_extra_args(args_path, img, connection)
+ # Run vzctl restore
+ proc = subprocess.Popen([vzctl_bin, "restore", self._ctid,
+ "--dumpfile", img.image_dir()])
+ if proc.wait() != 0:
+ raise Exception("Restore failed ({0})".format(proc.returncode))
+ finally:
+ # Remove restore extra arguments
+ self.__remove_restore_extra_args(args_path)
def prepare_ct(self, pid):
"""Create cgroup hierarchy and put root task into it.
--
1.7.1
More information about the CRIU
mailing list