[CRIU] [p.haul] [PATCH 1/2] runc: Migration fail implementation, mkdir permission addition

Veronika Kabatova vkabatov at redhat.com
Tue Feb 21 06:53:26 PST 2017


The migration should fail if container with same ID is running on target
host. If same-ID container is created after the migration start, cleanup
of bundle directory is performed.

/var/run/runc/CONTAINER_ID is also created with the same permissions as it is
in runc, not the defaults.

Signed-off-by: Veronika Kabatova <vkabatov at redhat.com>
---
 phaul/p_haul_runc.py | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/phaul/p_haul_runc.py b/phaul/p_haul_runc.py
index 85f40d7..06aa862 100644
--- a/phaul/p_haul_runc.py
+++ b/phaul/p_haul_runc.py
@@ -5,6 +5,7 @@
 import json
 import logging
 import os
+import pwd
 import re
 import shutil
 import subprocess as sp
@@ -99,7 +100,8 @@ class p_haul_type(object):
 		logging.info("Container rootfs: %s", self._ct_rootfs)
 
 	def init_dst(self):
-		pass
+		if os.path.exists(os.path.join(runc_run, self._ctid)):
+			raise Exception("Container with same ID already exists")
 
 	def adjust_criu_req(self, req):
 		if req.type in [pycriu.rpc.DUMP, pycriu.rpc.RESTORE]:
@@ -176,7 +178,9 @@ class p_haul_type(object):
 		sp.call([runc_bin, "delete", self._ctid])
 
 	def migration_fail(self, fs):
-		pass
+		p_haul_user = pwd.getpwuid(os.geteuid()).pw_name
+		sp.call(["ssh", p_haul_user + "@" + fs._p_haul_fs__thost,
+			"rm -r", self._runc_bundle + "/*"])
 
 	def target_cleanup(self, src_data):
 		pass
@@ -232,9 +236,6 @@ class p_haul_type(object):
 		for dsc, i in inherits:
 			self._inherit_fd.update({dsc: i})
 
-		ct_path = os.path.join(runc_run, self._ctid)
-		if not os.path.exists(ct_path):
-			os.makedirs(ct_path)
 		with open(os.path.join(img.image_dir(), "state.json"), "r") as old_state_file:
 			self._restore_state = json.loads(old_state_file.read())
 
@@ -242,6 +243,11 @@ class p_haul_type(object):
 
 	def restored(self, pid):
 		self._restore_state["init_process_pid"] = pid
+		ct_path = os.path.join(runc_run, self._ctid)
+		if not os.path.exists(ct_path):
+			os.makedirs(ct_path, 0711)
+		else:
+			raise Exception("Container with same ID already exists")
 		with open(os.path.join(runc_run, self._ctid, "state.json"),
 				"w+") as new_state_file:
 			new_state_file.write(json.dumps(self._restore_state))
-- 
2.7.4



More information about the CRIU mailing list