From fd40ca7c6768e64a8b6842415b3b3b73796141d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20=C5=A0karvada?= Date: Tue, 12 Jul 2016 11:57:11 +0200 Subject: [PATCH] plugin_disk: try to workaround embedded '/' in device names MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It seems that some drivers return udev names with embedded slashes '/', e.g.: sfdsk/gdssys34 When kernel creates sysfs nodes for them it replaces '/' by '!' not to cause ambiguity in path, i.e. the device from previous example will become: sfdsk!gdssys34 This commit add support for such cases. It checks whether there is embedded '/' in the device name, if yes, it tries to construct sysfs path with '!'. It checks whether the resulting sysfs path exists, if not, it tries the version with embedded '/'. This is safety fallback not to cause regression in some weird cases and it may be dropped in the future. Related: rhbz#1353142 Signed-off-by: Jaroslav Škarvada --- tuned/plugins/plugin_disk.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tuned/plugins/plugin_disk.py b/tuned/plugins/plugin_disk.py index b6f5fa2..04ef076 100644 --- a/tuned/plugins/plugin_disk.py +++ b/tuned/plugins/plugin_disk.py @@ -198,8 +198,15 @@ class DiskPlugin(hotplug.Plugin): def _instance_unapply_dynamic(self, instance, device): pass + def _sysfs_path(self, device, suffix, prefix = "/sys/block/"): + if "/" in device: + dev = os.path.join(prefix, device.replace("/", "!"), suffix) + if os.path.exists(dev): + return dev + return os.path.join(prefix, device, suffix) + def _elevator_file(self, device): - return os.path.join("/sys/block/", device, "queue/scheduler") + return self._sysfs_path(device, "queue/scheduler") @command_set("elevator", per_device=True) def _set_elevator(self, value, device, sim): @@ -261,7 +268,7 @@ class DiskPlugin(hotplug.Plugin): return 253 def _readahead_file(self, device): - return os.path.join("/sys/block/", device, "queue/read_ahead_kb") + return self._sysfs_path(device, "queue/read_ahead_kb") def _parse_ra(self, value): val = str(value).split(None, 1) @@ -307,7 +314,7 @@ class DiskPlugin(hotplug.Plugin): self._storage.unset(storage_key) def _scheduler_quantum_file(self, device): - return os.path.join("/sys/block/", device, "queue/iosched/quantum") + return self._sysfs_path(device, "queue/iosched/quantum") @command_set("scheduler_quantum", per_device=True) def _set_scheduler_quantum(self, value, device, sim):