Skip to content

Commit

Permalink
Merge pull request #578 from yarda/RHEL-11342
Browse files Browse the repository at this point in the history
hotplug: do not report ENOENT errors on device remove
  • Loading branch information
yarda authored Dec 7, 2023
2 parents 2652d7c + 2f911b7 commit 954bc46
Show file tree
Hide file tree
Showing 14 changed files with 127 additions and 89 deletions.
4 changes: 2 additions & 2 deletions tests/unit/plugins/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def _get_config_options(self):
return {'size':'S','device_setting':'101'}

@decorators.command_set('size')
def _set_size(self, new_size, sim):
def _set_size(self, new_size, sim, remove):
self._size = new_size
return new_size

Expand All @@ -220,7 +220,7 @@ def _get_size(self):
return self._size

@decorators.command_set('device_setting',per_device = True)
def _set_device_setting(self,value,device,sim):
def _set_device_setting(self,value,device,sim,remove):
device.setting = value
return device.setting

Expand Down
18 changes: 9 additions & 9 deletions tuned/plugins/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,15 +506,15 @@ def _execute_device_command(self, instance, command, device, new_value):
else:
new_value = self._check_and_save_value(instance, command, device, new_value)
if new_value is not None:
command["set"](new_value, device, sim = False)
command["set"](new_value, device, sim = False, remove = False)

def _execute_non_device_command(self, instance, command, new_value):
if command["custom"] is not None:
command["custom"](True, new_value, False, False)
else:
new_value = self._check_and_save_value(instance, command, None, new_value)
if new_value is not None:
command["set"](new_value, sim = False)
command["set"](new_value, sim = False, remove = False)

def _norm_value(self, value):
v = self._cmd.unquote(str(value))
Expand Down Expand Up @@ -576,7 +576,7 @@ def _verify_device_command(self, instance, command, device, new_value, ignore_mi
new_value = self._process_assignment_modifiers(new_value, current_value)
if new_value is None:
return None
new_value = command["set"](new_value, device, True)
new_value = command["set"](new_value, device, True, False)
return self._verify_value(command["name"], new_value, current_value, ignore_missing, device)

def _verify_non_device_command(self, instance, command, new_value, ignore_missing):
Expand All @@ -586,27 +586,27 @@ def _verify_non_device_command(self, instance, command, new_value, ignore_missin
new_value = self._process_assignment_modifiers(new_value, current_value)
if new_value is None:
return None
new_value = command["set"](new_value, True)
new_value = command["set"](new_value, True, False)
return self._verify_value(command["name"], new_value, current_value, ignore_missing)

def _cleanup_all_non_device_commands(self, instance):
for command in reversed([command for command in list(self._commands.values()) if not command["per_device"]]):
if (instance.options.get(command["name"], None) is not None) or (command["name"] in self._options_used_by_dynamic):
self._cleanup_non_device_command(instance, command)

def _cleanup_all_device_commands(self, instance, devices):
def _cleanup_all_device_commands(self, instance, devices, remove = False):
for command in reversed([command for command in list(self._commands.values()) if command["per_device"]]):
if (instance.options.get(command["name"], None) is not None) or (command["name"] in self._options_used_by_dynamic):
for device in devices:
self._cleanup_device_command(instance, command, device)
self._cleanup_device_command(instance, command, device, remove)

def _cleanup_device_command(self, instance, command, device):
def _cleanup_device_command(self, instance, command, device, remove = False):
if command["custom"] is not None:
command["custom"](False, None, device, False, False)
else:
old_value = self._storage_get(instance, command, device)
if old_value is not None:
command["set"](old_value, device, sim = False)
command["set"](old_value, device, sim = False, remove = remove)
self._storage_unset(instance, command, device)

def _cleanup_non_device_command(self, instance, command):
Expand All @@ -615,5 +615,5 @@ def _cleanup_non_device_command(self, instance, command):
else:
old_value = self._storage_get(instance, command)
if old_value is not None:
command["set"](old_value, sim = False)
command["set"](old_value, sim = False, remove = False)
self._storage_unset(instance, command)
2 changes: 1 addition & 1 deletion tuned/plugins/hotplug.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,4 @@ def _added_device_apply_tuning(self, instance, device_name):
def _removed_device_unapply_tuning(self, instance, device_name):
if instance.has_dynamic_tuning and self._global_cfg.get(consts.CFG_DYNAMIC_TUNING, consts.CFG_DEF_DYNAMIC_TUNING):
self._instance_unapply_dynamic(instance, device_name)
self._cleanup_all_device_commands(instance, [device_name])
self._cleanup_all_device_commands(instance, [device_name], remove = True)
11 changes: 7 additions & 4 deletions tuned/plugins/plugin_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from tuned.utils.commands import commands

import os
import errno
import struct
import glob

Expand Down Expand Up @@ -73,7 +74,7 @@ def _reset_controller_path(self, device):
return "/sys/module/%s/parameters/power_save_controller" % device

@command_set("timeout", per_device = True)
def _set_timeout(self, value, device, sim):
def _set_timeout(self, value, device, sim, remove):
try:
timeout = int(value)
except ValueError:
Expand All @@ -82,7 +83,8 @@ def _set_timeout(self, value, device, sim):
if timeout >= 0:
sys_file = self._timeout_path(device)
if not sim:
cmd.write_to_file(sys_file, "%d" % timeout)
cmd.write_to_file(sys_file, "%d" % timeout, \
no_error = [errno.ENOENT] if remove else False)
return timeout
else:
return None
Expand All @@ -96,12 +98,13 @@ def _get_timeout(self, device, ignore_missing=False):
return None

@command_set("reset_controller", per_device = True)
def _set_reset_controller(self, value, device, sim):
def _set_reset_controller(self, value, device, sim, remove):
v = cmd.get_bool(value)
sys_file = self._reset_controller_path(device)
if os.path.exists(sys_file):
if not sim:
cmd.write_to_file(sys_file, v)
cmd.write_to_file(sys_file, v, \
no_error = [errno.ENOENT] if remove else False)
return v
return None

Expand Down
30 changes: 17 additions & 13 deletions tuned/plugins/plugin_cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import tuned.consts as consts

import os
import errno
import struct
import errno
import platform
Expand Down Expand Up @@ -500,7 +501,7 @@ def _get_available_governors(self, device):
return self._cmd.read_file("/sys/devices/system/cpu/%s/cpufreq/scaling_available_governors" % device).strip().split()

@command_set("governor", per_device=True)
def _set_governor(self, governors, device, sim):
def _set_governor(self, governors, device, sim, remove):
if not self._check_cpu_can_change_governor(device):
return None
governors = str(governors)
Expand All @@ -517,7 +518,7 @@ def _set_governor(self, governors, device, sim):
log.info("setting governor '%s' on cpu '%s'"
% (governor, device))
self._cmd.write_to_file("/sys/devices/system/cpu/%s/cpufreq/scaling_governor"
% device, governor)
% device, governor, no_error = [errno.ENOENT] if remove else False)
break
elif not sim:
log.debug("Ignoring governor '%s' on cpu '%s', it is not supported"
Expand Down Expand Up @@ -546,7 +547,7 @@ def _sampling_down_factor_path(self, governor = "ondemand"):
return "/sys/devices/system/cpu/cpufreq/%s/sampling_down_factor" % governor

@command_set("sampling_down_factor", per_device = True, priority = 10)
def _set_sampling_down_factor(self, sampling_down_factor, device, sim):
def _set_sampling_down_factor(self, sampling_down_factor, device, sim, remove):
val = None

# hack to clear governors map when the profile starts unloading
Expand All @@ -569,7 +570,7 @@ def _set_sampling_down_factor(self, sampling_down_factor, device, sim):
val = str(sampling_down_factor)
if not sim:
log.info("setting sampling_down_factor to '%s' for governor '%s'" % (val, governor))
self._cmd.write_to_file(path, val)
self._cmd.write_to_file(path, val, no_error = [errno.ENOENT] if remove else False)
return val

@command_get("sampling_down_factor")
Expand Down Expand Up @@ -598,7 +599,7 @@ def _energy_perf_bias_path(self, cpu_id):
return "/sys/devices/system/cpu/cpu%s/power/energy_perf_bias" % cpu_id

@command_set("energy_perf_bias", per_device=True)
def _set_energy_perf_bias(self, energy_perf_bias, device, sim):
def _set_energy_perf_bias(self, energy_perf_bias, device, sim, remove):
if not self._is_cpu_online(device):
log.debug("%s is not online, skipping" % device)
return None
Expand All @@ -613,10 +614,11 @@ def _set_energy_perf_bias(self, energy_perf_bias, device, sim):
if not sim:
for val in vals:
val = val.strip()
if self._cmd.write_to_file(energy_perf_bias_path, val):
log.info("energy_perf_bias successfully set to '%s' on cpu '%s'"
% (val, device))
break
if self._cmd.write_to_file(energy_perf_bias_path, val, \
no_error = [errno.ENOENT] if remove else False):
log.info("energy_perf_bias successfully set to '%s' on cpu '%s'"
% (val, device))
break
else:
log.error("Failed to set energy_perf_bias on cpu '%s'. Is the value in the profile correct?"
% device)
Expand Down Expand Up @@ -711,7 +713,7 @@ def _check_pm_qos_resume_latency_us(self, device):
return self._has_pm_qos_resume_latency_us

@command_set("pm_qos_resume_latency_us", per_device=True)
def _set_pm_qos_resume_latency_us(self, pm_qos_resume_latency_us, device, sim):
def _set_pm_qos_resume_latency_us(self, pm_qos_resume_latency_us, device, sim, remove):
if not self._is_cpu_online(device):
log.debug("%s is not online, skipping" % device)
return None
Expand All @@ -729,7 +731,8 @@ def _set_pm_qos_resume_latency_us(self, pm_qos_resume_latency_us, device, sim):
if not self._check_pm_qos_resume_latency_us(device):
return None
if not sim:
self._cmd.write_to_file(self._pm_qos_resume_latency_us_path(device), latency)
self._cmd.write_to_file(self._pm_qos_resume_latency_us_path(device), latency, \
no_error = [errno.ENOENT] if remove else False)
return latency

@command_get("pm_qos_resume_latency_us")
Expand All @@ -742,7 +745,7 @@ def _get_pm_qos_resume_latency_us(self, device, ignore_missing=False):
return self._cmd.read_file(self._pm_qos_resume_latency_us_path(device), no_error=ignore_missing).strip()

@command_set("energy_performance_preference", per_device=True)
def _set_energy_performance_preference(self, energy_performance_preference, device, sim):
def _set_energy_performance_preference(self, energy_performance_preference, device, sim, remove):
if not self._is_cpu_online(device):
log.debug("%s is not online, skipping" % device)
return None
Expand All @@ -753,7 +756,8 @@ def _set_energy_performance_preference(self, energy_performance_preference, devi
avail_vals = set(self._cmd.read_file(self._pstate_preference_path(cpu_id, True)).split())
for val in vals:
if val in avail_vals:
self._cmd.write_to_file(self._pstate_preference_path(cpu_id), val)
self._cmd.write_to_file(self._pstate_preference_path(cpu_id), val, \
no_error = [errno.ENOENT] if remove else False)
log.info("Setting energy_performance_preference value '%s' for cpu '%s'" % (val, device))
break
else:
Expand Down
19 changes: 11 additions & 8 deletions tuned/plugins/plugin_disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,11 @@ def _elevator_file(self, device):
return self._sysfs_path(device, "queue/scheduler")

@command_set("elevator", per_device=True)
def _set_elevator(self, value, device, sim):
def _set_elevator(self, value, device, sim, remove):
sys_file = self._elevator_file(device)
if not sim:
self._cmd.write_to_file(sys_file, value)
self._cmd.write_to_file(sys_file, value, \
no_error = [errno.ENOENT] if remove else False)
return value

@command_get("elevator")
Expand All @@ -349,7 +350,7 @@ def _get_elevator(self, device, ignore_missing=False):
return self._cmd.get_active_option(self._cmd.read_file(sys_file, no_error=ignore_missing))

@command_set("apm", per_device=True)
def _set_apm(self, value, device, sim):
def _set_apm(self, value, device, sim, remove):
if device not in self._hdparm_apm_devices:
if not sim:
log.info("apm option is not supported for device '%s'" % device)
Expand Down Expand Up @@ -389,7 +390,7 @@ def _get_apm(self, device, ignore_missing=False):
return value

@command_set("spindown", per_device=True)
def _set_spindown(self, value, device, sim):
def _set_spindown(self, value, device, sim, remove):
if device not in self._hdparm_apm_devices:
if not sim:
log.info("spindown option is not supported for device '%s'" % device)
Expand Down Expand Up @@ -428,14 +429,15 @@ def _parse_ra(self, value):
return v

@command_set("readahead", per_device=True)
def _set_readahead(self, value, device, sim):
def _set_readahead(self, value, device, sim, remove):
sys_file = self._readahead_file(device)
val = self._parse_ra(value)
if val is None:
log.error("Invalid readahead value '%s' for device '%s'" % (value, device))
else:
if not sim:
self._cmd.write_to_file(sys_file, "%d" % val)
self._cmd.write_to_file(sys_file, "%d" % val, \
no_error = [errno.ENOENT] if remove else False)
return val

@command_get("readahead")
Expand Down Expand Up @@ -471,10 +473,11 @@ def _scheduler_quantum_file(self, device):
return self._sysfs_path(device, "queue/iosched/quantum")

@command_set("scheduler_quantum", per_device=True)
def _set_scheduler_quantum(self, value, device, sim):
def _set_scheduler_quantum(self, value, device, sim, remove):
sys_file = self._scheduler_quantum_file(device)
if not sim:
self._cmd.write_to_file(sys_file, "%d" % int(value))
self._cmd.write_to_file(sys_file, "%d" % int(value), \
no_error = [errno.ENOENT] if remove else False)
return value

@command_get("scheduler_quantum")
Expand Down
11 changes: 6 additions & 5 deletions tuned/plugins/plugin_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ def _nf_conntrack_hashsize_path(self):
return "/sys/module/nf_conntrack/parameters/hashsize"

@command_set("wake_on_lan", per_device=True)
def _set_wake_on_lan(self, value, device, sim):
def _set_wake_on_lan(self, value, device, sim, remove):
if value is None:
return None

Expand All @@ -406,14 +406,15 @@ def _get_wake_on_lan(self, device, ignore_missing=False):
return value

@command_set("nf_conntrack_hashsize")
def _set_nf_conntrack_hashsize(self, value, sim):
def _set_nf_conntrack_hashsize(self, value, sim, remove):
if value is None:
return None

hashsize = int(value)
if hashsize >= 0:
if not sim:
self._cmd.write_to_file(self._nf_conntrack_hashsize_path(), hashsize)
self._cmd.write_to_file(self._nf_conntrack_hashsize_path(), hashsize, \
no_error = [errno.ENOENT] if remove else False)
return hashsize
else:
return None
Expand Down Expand Up @@ -447,7 +448,7 @@ def _ip_link_show(self, device=None):
return self._call_ip_link(args)

@command_set("txqueuelen", per_device=True)
def _set_txqueuelen(self, value, device, sim):
def _set_txqueuelen(self, value, device, sim, remove):
if value is None:
return None
try:
Expand Down Expand Up @@ -487,7 +488,7 @@ def _get_txqueuelen(self, device, ignore_missing=False):
return res.group(1)

@command_set("mtu", per_device=True)
def _set_mtu(self, value, device, sim):
def _set_mtu(self, value, device, sim, remove):
if value is None:
return None
try:
Expand Down
Loading

0 comments on commit 954bc46

Please sign in to comment.