Commit 028240d5 authored by Jaroslav Škarvada's avatar Jaroslav Škarvada Committed by GitHub

Merge pull request #102 from olysonek/scheduler

Rework and improve the scheduler plugin
parents 72c94b36 de5c4432
......@@ -379,11 +379,14 @@ class Plugin(object):
# Operations with persistent storage for status data.
#
def _storage_key(self, instance_name, command_name, device_name=None):
if device_name is not None:
return "%s/%s/%s" % (command_name, instance_name, device_name)
else:
return "%s/%s" % (command_name, instance_name)
def _storage_key(self, instance_name = None, command_name = None,
device_name = None):
class_name = type(self).__name__
instance_name = "" if instance_name is None else instance_name
command_name = "" if command_name is None else command_name
device_name = "" if device_name is None else device_name
return "%s/%s/%s/%s" % (class_name, instance_name,
command_name, device_name)
def _storage_set(self, instance, command, value, device_name=None):
key = self._storage_key(instance.name, command["name"], device_name)
......
......@@ -319,7 +319,9 @@ class DiskPlugin(hotplug.Plugin):
def _multiply_readahead(self, enabling, multiplier, device, verify, ignore_missing):
if verify:
return None
storage_key = self._storage_key("readahead_multiply", device)
storage_key = self._storage_key(
command_name = "readahead_multiply",
device_name = device)
if enabling:
old_readahead = self._get_readahead(device)
if old_readahead is None:
......
......@@ -125,7 +125,9 @@ class MountsPlugin(base.Plugin):
@command_custom("disable_barriers", per_device=True)
def _disable_barriers(self, start, value, mountpoint, verify, ignore_missing):
storage_key = self._storage_key("disable_barriers", mountpoint)
storage_key = self._storage_key(
command_name = "disable_barriers",
device_name = mountpoint)
force = str(value).lower() == "force"
value = force or self._option_bool(value)
......
......@@ -332,7 +332,9 @@ class NetTuningPlugin(base.Plugin):
return d
def _custom_parameters(self, context, start, value, device, verify):
storage_key = self._storage_key(context, device)
storage_key = self._storage_key(
command_name = context,
device_name = device)
if start:
cd = self._get_device_parameters(context, device)
d = self._set_device_parameters(context, value, device, verify)
......
This diff is collapsed.
......@@ -18,26 +18,25 @@ class SysctlPlugin(base.Plugin):
self._has_dynamic_options = True
self._cmd = commands()
def _sysctl_storage_key(self, instance):
return "%s/options" % instance.name
def _instance_init(self, instance):
instance._has_dynamic_tuning = False
instance._has_static_tuning = True
# FIXME: do we want to do this here?
# recover original values in case of crash
instance._sysctl_original = self._storage.get(self._sysctl_storage_key(instance), {})
storage_key = self._storage_key(instance.name)
instance._sysctl_original = self._storage.get(storage_key, {})
if len(instance._sysctl_original) > 0:
log.info("recovering old sysctl settings from previous run")
self._instance_unapply_static(instance)
instance._sysctl_original = {}
self._storage.unset(self._sysctl_storage_key(instance))
self._storage.unset(storage_key)
instance._sysctl = instance.options
def _instance_cleanup(self, instance):
self._storage.unset(self._sysctl_storage_key(instance))
storage_key = self._storage_key(instance.name)
self._storage.unset(storage_key)
def _instance_apply_static(self, instance):
for option, value in list(instance._sysctl.items()):
......@@ -46,7 +45,8 @@ class SysctlPlugin(base.Plugin):
instance._sysctl_original[option] = original_value
self._write_sysctl(option, self._process_assignment_modifiers(self._variables.expand(self._cmd.unquote(value)), original_value))
self._storage.set("options", instance._sysctl_original)
storage_key = self._storage_key(instance.name)
self._storage.set(storage_key, instance._sysctl_original)
if self._global_cfg.get_bool(consts.CFG_REAPPLY_SYSCTL, consts.CFG_DEF_REAPPLY_SYSCTL):
log.info("reapplying system sysctl")
......
......@@ -259,17 +259,21 @@ class commands:
if mask is None:
return None
mask = str(mask).replace(",", "")
cpu = 0
cpus = []
try:
m = int(mask, 16)
except ValueError:
log.error("invalid hexadecimal mask '%s'" % str(mask))
return []
while m > 0:
if m & 1:
return self.bitmask2cpulist(m)
# Converts an integer bitmask to a list of cpus (e.g. [0,3,4])
def bitmask2cpulist(self, mask):
cpu = 0
cpus = []
while mask > 0:
if mask & 1:
cpus.append(cpu)
m >>= 1
mask >>= 1
cpu += 1
return cpus
......@@ -366,12 +370,10 @@ class commands:
def cpulist2hex(self, l):
if l is None:
return None
m = 0
ul = self.cpulist_unpack(l)
if ul is None:
return None
for v in ul:
m |= pow(2, v)
m = self.cpulist2bitmask(ul)
s = "%x" % m
ls = len(s)
if ls % 8 != 0:
......@@ -379,6 +381,12 @@ class commands:
s = s.zfill(ls)
return ",".join(s[i:i + 8] for i in range(0, len(s), 8))
def cpulist2bitmask(self, l):
m = 0
for v in l:
m |= pow(2, v)
return m
def process_recommend_file(self, fname):
matching_profile = None
try:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment