[CRIU] [PATCH 1/2] p.haul: refine criu requests-related code
Nikita Spiridonov
nspiridonov at odin.com
Thu Jun 25 02:00:01 PDT 2015
Move all criu requests-related code to separate methods in
phaul_iter_worker and phaul_service classes to simplify migration
logic.
Signed-off-by: Nikita Spiridonov <nspiridonov at odin.com>
---
phaul/p_haul_iters.py | 94 +++++++++++++++++++++++++++--------------------
phaul/p_haul_service.py | 91 +++++++++++++++++++++++++++------------------
2 files changed, 108 insertions(+), 77 deletions(-)
diff --git a/phaul/p_haul_iters.py b/phaul/p_haul_iters.py
index 7a898da..5932bef 100644
--- a/phaul/p_haul_iters.py
+++ b/phaul/p_haul_iters.py
@@ -47,28 +47,6 @@ class phaul_iter_worker:
print "Setting up remote"
self.th.setup(p_type)
-
- def make_dump_req(self, typ):
- #
- # Prepare generic request for (pre)dump
- #
-
- req = cr_rpc.criu_req()
- req.type = typ
- req.opts.pid = self.pid
- req.opts.ps.fd = self.criu.mem_sk_fileno()
- req.opts.track_mem = True
-
- req.opts.images_dir_fd = self.img.image_dir_fd()
- req.opts.work_dir_fd = self.img.work_dir_fd()
- p_img = self.img.prev_image_dir()
- if p_img:
- req.opts.parent_img = p_img
- if not self.fs.persistent_inodes():
- req.opts.force_irmap = True
-
- return req
-
def set_options(self, opts):
self.th.set_options(opts)
self.criu.verbose(opts["verbose"])
@@ -80,10 +58,7 @@ class phaul_iter_worker:
print "Checking CPU compatibility"
print " `- Dumping CPU info"
- req = cr_rpc.criu_req()
- req.type = cr_rpc.CPUINFO_DUMP
- req.opts.images_dir_fd = self.img.work_dir_fd()
- req.keep_open = True
+ req = self.__make_cpuinfo_dump_req()
resp = self.criu.send_req(req)
if not resp.success:
raise Exception("Can't dump cpuinfo")
@@ -106,7 +81,6 @@ class phaul_iter_worker:
self.fs.start_migration()
print "Starting iterations"
- cc = self.criu
while True:
print "* Iteration %d" % self.iteration
@@ -116,8 +90,8 @@ class phaul_iter_worker:
print "\tIssuing pre-dump command to service"
- req = self.make_dump_req(cr_rpc.PRE_DUMP)
- resp = cc.send_req(req)
+ req = self.__make_predump_req()
+ resp = self.criu.send_req(req)
if not resp.success:
raise Exception("Pre-dump failed")
@@ -168,15 +142,9 @@ class phaul_iter_worker:
self.img.new_image_dir()
print "\tIssuing dump command to service"
- req = self.make_dump_req(cr_rpc.DUMP)
- req.opts.notify_scripts = True
- req.opts.file_locks = True
- req.opts.evasive_devices = True
- req.opts.link_remap = True
- if self.htype.can_migrate_tcp():
- req.opts.tcp_established = True
- resp = cc.send_req(req)
+ req = self.__make_dump_req()
+ resp = self.criu.send_req(req)
while True:
if resp.type != cr_rpc.NOTIFY:
raise Exception("Dump failed")
@@ -195,7 +163,7 @@ class phaul_iter_worker:
self.htype.net_unlock()
print "\t\tNotify (%s)" % resp.notify.script
- resp = cc.ack_notify()
+ resp = self.criu.ack_notify()
print "Dump complete"
self.th.end_iter()
@@ -219,7 +187,7 @@ class phaul_iter_worker:
# DUMP/success message
#
- resp = cc.ack_notify()
+ resp = self.criu.ack_notify()
if not resp.success:
raise Exception("Dump screwed up")
@@ -229,4 +197,50 @@ class phaul_iter_worker:
self._mstat.iteration(stats)
self._mstat.stop(self)
self.img.close()
- cc.close()
+ self.criu.close()
+
+ def __make_req(self, typ):
+ """Prepare generic criu request"""
+ req = cr_rpc.criu_req()
+ req.type = typ
+ return req
+
+ def __make_common_dump_req(self, typ):
+ """Prepare common criu request for pre-dump or dump"""
+
+ req = self.__make_req(typ)
+ req.opts.pid = self.pid
+ req.opts.ps.fd = self.criu.mem_sk_fileno()
+ req.opts.track_mem = True
+
+ req.opts.images_dir_fd = self.img.image_dir_fd()
+ req.opts.work_dir_fd = self.img.work_dir_fd()
+ p_img = self.img.prev_image_dir()
+ if p_img:
+ req.opts.parent_img = p_img
+ if not self.fs.persistent_inodes():
+ req.opts.force_irmap = True
+
+ return req
+
+ def __make_cpuinfo_dump_req(self):
+ """Prepare cpuinfo dump criu request"""
+ req = self.__make_req(cr_rpc.CPUINFO_DUMP)
+ req.opts.images_dir_fd = self.img.work_dir_fd()
+ req.keep_open = True
+ return req
+
+ def __make_predump_req(self):
+ """Prepare pre-dump criu request"""
+ return self.__make_common_dump_req(cr_rpc.PRE_DUMP)
+
+ def __make_dump_req(self):
+ """Prepare dump criu request"""
+ req = self.__make_common_dump_req(cr_rpc.DUMP)
+ req.opts.notify_scripts = True
+ req.opts.file_locks = True
+ req.opts.evasive_devices = True
+ req.opts.link_remap = True
+ if self.htype.can_migrate_tcp():
+ req.opts.tcp_established = True
+ return req
diff --git a/phaul/p_haul_service.py b/phaul/p_haul_service.py
index d3e19ff..e37e7fc 100644
--- a/phaul/p_haul_service.py
+++ b/phaul/p_haul_service.py
@@ -53,18 +53,8 @@ class phaul_service:
def start_page_server(self):
print "Starting page server for iter %d" % self.dump_iter
- req = cr_rpc.criu_req()
- req.type = cr_rpc.PAGE_SERVER
- req.keep_open = True
- req.opts.ps.fd = self.criu.mem_sk_fileno()
-
- req.opts.images_dir_fd = self.img.image_dir_fd()
- req.opts.work_dir_fd = self.img.work_dir_fd()
- p_img = self.img.prev_image_dir()
- if p_img:
- req.opts.parent_img = p_img
-
print "\tSending criu rpc req"
+ req = self.__make_page_server_req()
resp = self.criu.send_req(req)
if not resp.success:
raise Exception("Failed to start page server")
@@ -87,10 +77,7 @@ class phaul_service:
def rpc_check_cpuinfo(self):
print "Checking cpuinfo"
- req = cr_rpc.criu_req()
- req.type = cr_rpc.CPUINFO_CHECK
- req.opts.images_dir_fd = self.img.work_dir_fd()
- req.keep_open = True
+ req = self.__make_cpuinfo_check_req()
resp = self.criu.send_req(req)
print " `-", resp.success
return resp.success
@@ -99,27 +86,8 @@ class phaul_service:
print "Restoring from images"
self.htype.put_meta_images(self.img.image_dir())
- req = cr_rpc.criu_req()
- req.type = cr_rpc.RESTORE
- req.opts.images_dir_fd = self.img.image_dir_fd()
- req.opts.work_dir_fd = self.img.work_dir_fd()
- req.opts.notify_scripts = True
-
- if self.htype.can_migrate_tcp():
- req.opts.tcp_established = True
-
- for veth in self.htype.veths():
- v = req.opts.veths.add()
- v.if_in = veth.name
- v.if_out = veth.pair
-
- nroot = self.htype.mount()
- if nroot:
- req.opts.root = nroot
- print "Restore root set to %s" % req.opts.root
-
- cc = self.criu
- resp = cc.send_req(req)
+ req = self.__make_restore_req()
+ resp = self.criu.send_req(req)
while True:
if resp.type == cr_rpc.NOTIFY:
print "\t\tNotify (%s.%d)" % (resp.notify.script, resp.notify.pid)
@@ -137,7 +105,7 @@ class phaul_service:
elif resp.notify.script == "network-lock":
raise Exception("Locking network on restore?")
- resp = cc.ack_notify()
+ resp = self.criu.ack_notify()
continue
if not resp.success:
@@ -152,3 +120,52 @@ class phaul_service:
def rpc_restore_time(self):
stats = criu_api.criu_get_rstats(self.img)
return stats.restore_time
+
+ def __make_req(self, typ):
+ """Prepare generic criu request"""
+ req = cr_rpc.criu_req()
+ req.type = typ
+ return req
+
+ def __make_page_server_req(self):
+ """Prepare page server criu request"""
+
+ req = self.__make_req(cr_rpc.PAGE_SERVER)
+ req.keep_open = True
+ req.opts.ps.fd = self.criu.mem_sk_fileno()
+ req.opts.images_dir_fd = self.img.image_dir_fd()
+ req.opts.work_dir_fd = self.img.work_dir_fd()
+
+ p_img = self.img.prev_image_dir()
+ if p_img:
+ req.opts.parent_img = p_img
+
+ return req
+
+ def __make_cpuinfo_check_req(self):
+ """Prepare cpuinfo check criu request"""
+ req = self.__make_req(cr_rpc.CPUINFO_CHECK)
+ req.keep_open = True
+ req.opts.images_dir_fd = self.img.work_dir_fd()
+ return req
+
+ def __make_restore_req(self):
+ """Prepare restore criu request"""
+
+ req = self.__make_req(cr_rpc.RESTORE)
+ req.opts.images_dir_fd = self.img.image_dir_fd()
+ req.opts.work_dir_fd = self.img.work_dir_fd()
+ req.opts.notify_scripts = True
+
+ if self.htype.can_migrate_tcp():
+ req.opts.tcp_established = True
+
+ for veth in self.htype.veths():
+ req.opts.veths.add(if_in = veth.name, if_out = veth.pair)
+
+ nroot = self.htype.mount()
+ if nroot:
+ req.opts.root = nroot
+ print "Restore root set to %s" % req.opts.root
+
+ return req
--
1.7.1
More information about the CRIU
mailing list