fix coresched locating cgroup and reduce verbosity
[nodemanager.git] / coresched_lxc.py
index ff2443e..1134eef 100644 (file)
@@ -4,6 +4,7 @@
 
 import logger
 import os
+import os.path
 import cgroups
 
 glo_coresched_simulate = False
@@ -197,6 +198,8 @@ class CoreSched:
         reservations["_default"] = cpus[:]
         mem_reservations["_default"] = mems[:]
 
+        freezeList = {}
+
         # now check and see if any of our slices had the besteffort flag
         # set
         for name, rec in slivers.iteritems():
@@ -204,6 +207,12 @@ class CoreSched:
             cores = rspec.get(self.slice_attr_name, 0)
             (cores, bestEffort) = self.decodeCoreSpec(cores)
 
+            freezable = rspec.get("cpu_freezable", 0)
+            if (cores==0) and (freezable == 1):
+               freezeList[name] = "FROZEN"
+            else:
+               freezeList[name] = "THAWED"
+
             # if the bestEffort flag isn't set then we have nothing to do
             if not bestEffort:
                 continue
@@ -220,13 +229,39 @@ class CoreSched:
 
         self.reserveUnits(self.cgroup_mem_name, mem_reservations)
 
+        self.freezeUnits("freezer.state", freezeList)
+
+    def freezeUnits (self, var_name, freezeList):
+        for (cgroup, freeze) in freezeList.items():
+            try:
+                logger.verbose("CoreSched: setting freezer for " + cgroup + " to " + freeze)
+                attempts = []
+#                attempts.append("/dev/cgroup/{}/var_name".format(cgroup, var_name))
+                attempts.append("/sys/fs/cgroup/freezer/libvirt/lxc/{}/{}".format(cgroup, var_name))
+                attempts.append("/sys/fs/cgroup/freezer/machine.slice/machine-lxc\\x2d{}.scope/{}".format(cgroup, var_name))
+                if glo_coresched_simulate:
+                    for attempt in attempts: print "F", attempt
+                else:
+                    ok = False
+                    for attempt in attempts:
+                        if os.path.exists(attempt):
+                            file(attempt, "w").write(freeze)
+                            ok = True
+                            break
+                    if not ok:
+                        logger.log("CoreSched: could not freezeUnits with {}".format(cgroup))
+            except Exception as e:
+                # the cgroup probably didn't exit...
+                logger.log("CoreSched: exception while setting freeze for {} ({})".format(cgroup, e))
+
     def reserveUnits (self, var_name, reservations):
-        """ give a set of reservations (dictionary of slicename:cpuid_list),
-            write those reservations to the appropriate cgroup files.
+        """ 
+        give a set of reservations (dictionary of slicename:cpuid_list),
+        write those reservations to the appropriate cgroup files.
 
-            reservations["_default"] is assumed to be the default reservation
-            for slices that do not reserve cores. It's essentially the leftover
-            cpu cores.
+        reservations["_default"] is assumed to be the default reservation
+        for slices that do not reserve cores. It's essentially the leftover
+        cpu cores.
         """
 
         default = reservations["_default"]