From cd4943bdbf7d7a507891e7204f4087143d7a8960 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Lyson=C4=9Bk?= Date: Fri, 10 Mar 2017 10:48:50 +0100 Subject: [PATCH 1/2] Introduce ${i:PROFILE_DIR} function, drop workdir option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Introduced the ${i:PROFILE_DIR} internal function, which can be used in profiles and which expands to the directory in which the profile configuration was found. It replaces the workdir option, which was a bit problematic due to inheritance and the possibility to change its value. The ability to change the value of 'workdir' seems redundant, as the same effect can be achieved by either specifying an absolute path to files in unit configuration or by using a user defined variable. Note that now you need to specify an absolute path or use the ${i:PROFILE_DIR} functin in the initrd_add_dir and initrd_add_img options of the bootloader plugin. Signed-off-by: Ondřej Lysoněk --- tuned/consts.py | 1 - tuned/plugins/base.py | 4 ++-- tuned/plugins/instance/instance.py | 7 +------ tuned/plugins/plugin_bootloader.py | 8 -------- tuned/profiles/loader.py | 12 +++++++++--- tuned/units/manager.py | 2 +- 6 files changed, 13 insertions(+), 21 deletions(-) diff --git a/tuned/consts.py b/tuned/consts.py index f111336..d557608 100644 --- a/tuned/consts.py +++ b/tuned/consts.py @@ -12,7 +12,6 @@ DEFAULT_STORAGE_FILE = "/run/tuned/save.pickle" LOAD_DIRECTORIES = ["/usr/lib/tuned", "/etc/tuned"] PERSISTENT_STORAGE_DIR = "/var/lib/tuned" PLUGIN_MAIN_UNIT_NAME = "main" -PLUGIN_WORKDIR_OPTION_NAME = "workdir" TMP_FILE_SUFFIX = ".tmp" # max. number of consecutive errors to give up diff --git a/tuned/plugins/base.py b/tuned/plugins/base.py index 528e242..73efdae 100644 --- a/tuned/plugins/base.py +++ b/tuned/plugins/base.py @@ -81,13 +81,13 @@ class Plugin(object): # Interface for manipulation with instances of the plugin. # - def create_instance(self, name, devices_expression, devices_udev_regex, workdir, options): + def create_instance(self, name, devices_expression, devices_udev_regex, options): """Create new instance of the plugin and seize the devices.""" if name in self._instances: raise Exception("Plugin instance with name '%s' already exists." % name) effective_options = self._get_effective_options(options) - instance = self._instance_factory.create(self, name, devices_expression, devices_udev_regex, workdir, effective_options) + instance = self._instance_factory.create(self, name, devices_expression, devices_udev_regex, effective_options) self._instances[name] = instance return instance diff --git a/tuned/plugins/instance/instance.py b/tuned/plugins/instance/instance.py index 923221d..8006ab9 100644 --- a/tuned/plugins/instance/instance.py +++ b/tuned/plugins/instance/instance.py @@ -2,12 +2,11 @@ class Instance(object): """ """ - def __init__(self, plugin, name, devices_expression, devices_udev_regex, workdir, options): + def __init__(self, plugin, name, devices_expression, devices_udev_regex, options): self._plugin = plugin self._name = name self._devices_expression = devices_expression self._devices_udev_regex = devices_udev_regex - self._workdir = workdir self._options = options self._active = True @@ -46,10 +45,6 @@ class Instance(object): def devices_udev_regex(self): return self._devices_udev_regex - @property - def workdir(self): - return self._workdir - @property def options(self): return self._options diff --git a/tuned/plugins/plugin_bootloader.py b/tuned/plugins/plugin_bootloader.py index b23deba..9e5dba9 100644 --- a/tuned/plugins/plugin_bootloader.py +++ b/tuned/plugins/plugin_bootloader.py @@ -34,7 +34,6 @@ class BootloaderPlugin(base.Plugin): self._initrd_dst_img_val = None self._cmdline_val = "" self._initrd_val = "" - self._workdir = instance.workdir self._grub2_cfg_file_name = self._get_grub2_cfg_file() def _instance_cleanup(self, instance): @@ -185,11 +184,6 @@ class BootloaderPlugin(base.Plugin): self.update_grub2_cfg = True self._initrd_val = "/" + img_name - def _build_abs_path(self, path): - if path is None or len(path) == 0 or path[0] == "/": - return path - return os.path.normpath(os.path.join(self._workdir, path)) - @command_custom("grub2_cfg_file") def _grub2_cfg_file(self, enabling, value, verify, ignore_missing): # nothing to verify @@ -228,7 +222,6 @@ class BootloaderPlugin(base.Plugin): self._init_initrd_dst_img(src_img) if src_img == "": return False - src_img = self._build_abs_path(src_img) self._install_initrd(src_img) @command_custom("initrd_add_dir", per_device = False, priority = 10) @@ -241,7 +234,6 @@ class BootloaderPlugin(base.Plugin): self._init_initrd_dst_img(src_dir) if src_dir == "": return False - src_dir = self._build_abs_path(src_dir) if not os.path.isdir(src_dir): log.error("error: cannot create initrd image, source directory '%s' doesn't exist" % src_dir) return False diff --git a/tuned/profiles/loader.py b/tuned/profiles/loader.py index 6e3660f..a1b6455 100644 --- a/tuned/profiles/loader.py +++ b/tuned/profiles/loader.py @@ -74,6 +74,9 @@ class Loader(object): profiles.append(profile) + def _expand_profile_dir(self, profile_dir, string): + return re.sub(r'(? Date: Mon, 13 Mar 2017 09:50:26 +0100 Subject: [PATCH 2/2] Use ${i:PROFILE_DIR} in our profiles MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use the new ${i:PROFILE_DIR} internal function with the 'script' option in the profiles we ship. Signed-off-by: Ondřej Lysoněk --- profiles/cpu-partitioning/tuned.conf | 2 +- profiles/laptop-ac-powersave/tuned.conf | 2 +- profiles/powersave/tuned.conf | 2 +- profiles/realtime-virtual-guest/tuned.conf | 2 +- profiles/realtime-virtual-host/tuned.conf | 2 +- profiles/realtime/tuned.conf | 2 +- profiles/sap-hana-vmware/tuned.conf | 2 +- profiles/sap-netweaver/tuned.conf | 2 +- profiles/spindown-disk/tuned.conf | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/profiles/cpu-partitioning/tuned.conf b/profiles/cpu-partitioning/tuned.conf index 5782de9..303b216 100644 --- a/profiles/cpu-partitioning/tuned.conf +++ b/profiles/cpu-partitioning/tuned.conf @@ -37,7 +37,7 @@ cpu_affinity=${not_isolated_cores_expanded} [script] priority=5 -script=script.sh +script=${i:PROFILE_DIR}/script.sh [bootloader] priority=10 diff --git a/profiles/laptop-ac-powersave/tuned.conf b/profiles/laptop-ac-powersave/tuned.conf index 8088760..1e935eb 100644 --- a/profiles/laptop-ac-powersave/tuned.conf +++ b/profiles/laptop-ac-powersave/tuned.conf @@ -7,4 +7,4 @@ summary=Optimize for laptop with power savings include=desktop-powersave [script] -script=script.sh +script=${i:PROFILE_DIR}/script.sh diff --git a/profiles/powersave/tuned.conf b/profiles/powersave/tuned.conf index d74200b..e925ed8 100644 --- a/profiles/powersave/tuned.conf +++ b/profiles/powersave/tuned.conf @@ -36,4 +36,4 @@ vm.dirty_writeback_centisecs=1500 kernel.nmi_watchdog=0 [script] -script=script.sh +script=${i:PROFILE_DIR}/script.sh diff --git a/profiles/realtime-virtual-guest/tuned.conf b/profiles/realtime-virtual-guest/tuned.conf index cab6553..7b36a77 100644 --- a/profiles/realtime-virtual-guest/tuned.conf +++ b/profiles/realtime-virtual-guest/tuned.conf @@ -16,7 +16,7 @@ isolated_cores_present_expanded=${f:cpulist_present:${isolated_cores}} assert=${f:assertion:isolated_cores contains present CPU(s):${isolated_cores_expanded}:${isolated_cores_present_expanded}} [script] -script=script.sh +script=${i:PROFILE_DIR}/script.sh [bootloader] cmdline=isolcpus=${isolated_cores} nohz=on nohz_full=${isolated_cores} rcu_nocbs=${isolated_cores} intel_pstate=disable nosoftlockup diff --git a/profiles/realtime-virtual-host/tuned.conf b/profiles/realtime-virtual-host/tuned.conf index 92a7ee0..1e8563f 100644 --- a/profiles/realtime-virtual-host/tuned.conf +++ b/profiles/realtime-virtual-host/tuned.conf @@ -44,7 +44,7 @@ group.rcuc=0:f:3:*:rcuc.* group.rcub=0:f:3:*:rcub.* [script] -script=script.sh +script=${i:PROFILE_DIR}/script.sh [bootloader] cmdline=isolcpus=${isolated_cores} nohz=on nohz_full=${isolated_cores} rcu_nocbs=${isolated_cores} intel_pstate=disable nosoftlockup diff --git a/profiles/realtime/tuned.conf b/profiles/realtime/tuned.conf index 6d4f7c7..e1b6bcd 100644 --- a/profiles/realtime/tuned.conf +++ b/profiles/realtime/tuned.conf @@ -38,4 +38,4 @@ kernel.timer_migration = 0 cmdline=isolcpus=${isolated_cores} intel_pstate=disable nosoftlockup [script] -script = script.sh +script = ${i:PROFILE_DIR}/script.sh diff --git a/profiles/sap-hana-vmware/tuned.conf b/profiles/sap-hana-vmware/tuned.conf index 9378219..f924f5b 100644 --- a/profiles/sap-hana-vmware/tuned.conf +++ b/profiles/sap-hana-vmware/tuned.conf @@ -18,4 +18,4 @@ kernel.sem = 1250 256000 100 8192 kernel.numa_balancing = 0 [script] -script=script.sh +script=${i:PROFILE_DIR}/script.sh diff --git a/profiles/sap-netweaver/tuned.conf b/profiles/sap-netweaver/tuned.conf index 6190051..c9c58cd 100644 --- a/profiles/sap-netweaver/tuned.conf +++ b/profiles/sap-netweaver/tuned.conf @@ -11,4 +11,4 @@ kernel.sem = 1250 256000 100 8192 vm.max_map_count = 2000000 [script] -script=script.sh +script=${i:PROFILE_DIR}/script.sh diff --git a/profiles/spindown-disk/tuned.conf b/profiles/spindown-disk/tuned.conf index 6b54e53..6f12684 100644 --- a/profiles/spindown-disk/tuned.conf +++ b/profiles/spindown-disk/tuned.conf @@ -34,4 +34,4 @@ vm.laptop_mode=5 vm.swappiness=30 [script] -script=script.sh +script=${i:PROFILE_DIR}/script.sh