[CRIU] [RFC] [PATCH] p.haul: Generate cgroup external mount map dynamically

Павел Вохмянин pavel.vokhmyanin at gmail.com
Thu Jan 19 07:29:19 PST 2017


libvzctl generates map dynamically by iterating through the known
list and looking up actual mount points, however p.haul just uses
hardcoded map. Due to difference in algorithms they might generate
different maps which leads to migration failure. Libvzctl treats "ve" and
"beancounter" as private, and skips them, thus they are omitted now.

Signed-off-by: Pavel Vokhmyanin <pvokhmyanin at virtuozzo.com>
---
 phaul/p_haul_vz.py | 49 ++++++++++++++++++++++++++++++++++---------------
 1 file changed, 34 insertions(+), 15 deletions(-)

diff --git a/phaul/p_haul_vz.py b/phaul/p_haul_vz.py
index a7dacd8..9f66da7 100644
--- a/phaul/p_haul_vz.py
+++ b/phaul/p_haul_vz.py
@@ -23,18 +23,16 @@ cgexec_bin = "cgexec"


 vz_cgroup_mount_map = {
-       "/sys/fs/cgroup/cpu,cpuacct": "cpu",
-       "/sys/fs/cgroup/cpuset": "cpuset",
-       "/sys/fs/cgroup/net_cls": "net_cls",
-       "/sys/fs/cgroup/memory": "memory",
-       "/sys/fs/cgroup/devices": "devices",
-       "/sys/fs/cgroup/blkio": "blkio",
-       "/sys/fs/cgroup/freezer": "freezer",
-       "/sys/fs/cgroup/beancounter": "beancounter",
-       "/sys/fs/cgroup/ve": "ve",
-       "/sys/fs/cgroup/perf_event": "perf_event",
-       "/sys/fs/cgroup/hugetlb": "hugetlb",
-       "/sys/fs/cgroup/systemd": "systemd",
+       "cpu,cpuacct": "cpu",
+       "cpuset": "cpuset",
+       "net_cls": "net_cls",
+       "memory": "memory",
+       "devices": "devices",
+       "blkio": "blkio",
+       "freezer": "freezer",
+       "perf_event": "perf_event",
+       "hugetlb": "hugetlb",
+       "systemd": "systemd",
 }


@@ -129,7 +127,6 @@ class p_haul_type(object):

        def adjust_criu_req(self, req):
                """Add module-specific options to criu request"""
-
                # Specify dump specific options
                if req.type == pycriu.rpc.DUMP:

@@ -140,8 +137,7 @@ class p_haul_type(object):
                        req.opts.manage_cgroups = True

                        # Setup mapping for external Virtuozzo specific
cgroup mounts
-                       for key, value in vz_cgroup_mount_map.items():
-                               req.opts.ext_mnt.add(key=key, val=value)
+                       self.__fill_vz_cgroup_ext_mount_map(req)

                        # Specify secondary ploop disks as external
                        disks = self.__parse_secondary_disks_
arg(self.__secondary_disks)
@@ -162,6 +158,29 @@ class p_haul_type(object):
                        # Increase timeout up to 180 seconds
                        req.opts.timeout = 180

+       def __fill_vz_cgroup_ext_mount_map(self, req):
+               with open("/proc/self/mountinfo") as x:
+                       mountinfo = x.readlines()
+               # Walk cgroups maps
+               for cgkey in vz_cgroup_mount_map:
+
+                       # If key consists of two cgroups
(e.g."cpu,cpuacct"), walk each
+                       for cgname in cgkey.split(","):
+
+                               # Substite "systemd" with "name=systemd"
option
+                               if cgname == "systemd":
+                                       cgname = "name=systemd"
+
+                               # Iterate through lines in mountinfo until
we find a match
+                               for buf in mountinfo:
+                                       mi_line = buf.split()
+                                       if mi_line[8] != "cgroup":
+                                               continue
+                                       if cgname in mi_line[10].split(","):
+                                               req.opts.ext_mnt.add(key =
mi_line[4],
+                                                               val =
vz_cgroup_mount_map[cgkey])
+                                               break
+
        def root_task_pid(self):
                path = "/var/run/ve/{0}.init.pid".format(self._ctid)
                with open(path) as pidfile:
--
1.8.3.1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openvz.org/pipermail/criu/attachments/20170119/bb6994bb/attachment.html>


More information about the CRIU mailing list