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

Submitted by Павел Вохмянин on Jan. 19, 2017, 3:29 p.m.

Details

Message ID CAAOyFzeMO3w=AjhN+ySqLgWPtM8iE6Aai5A7y5Ez73GLrN0bxw@mail.gmail.com
State Superseded
Series "p.haul: Generate cgroup external mount map dynamically"
Headers show

Commit Message

Павел Вохмянин Jan. 19, 2017, 3:29 p.m.
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@virtuozzo.com>
---
 phaul/p_haul_vz.py | 49 ++++++++++++++++++++++++++++++++++---------------
 1 file changed, 34 insertions(+), 15 deletions(-)

                        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

Patch hide | download patch | download mbox

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

Comments

Cyrill Gorcunov Jan. 19, 2017, 3:46 p.m.
On Thu, Jan 19, 2017 at 06:29:19PM +0300, Павел Вохмянин wrote:
>    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.

Drop this.