File: //lib/python2.7/site-packages/tuned/plugins/plugin_iscsi.py
# Copyright (c) 2019, 2020, Oracle and/or its affiliates.
from . import hotplug
from . import plugin_script
import tuned.logs
log = tuned.logs.get()
class IscsiPlugin(hotplug.Plugin, plugin_script.ScriptPlugin):
"""
Plugin for tuning options of iSCSI-attached block volumes by running custom scripts.
"""
def __init__(self, *args, **kwargs):
super(IscsiPlugin, self).__init__(*args, **kwargs)
def _init_devices(self):
super(IscsiPlugin, self)._init_devices()
self._devices_supported = True
self._free_devices = set()
for device in self._hardware_inventory.get_devices("block"):
if self._device_is_supported(device):
self._free_devices.add(device.sys_name)
self._assigned_devices = set()
log.debug("self._free_devices = %s" % self._free_devices)
def _get_device_objects(self, devices):
return [self._hardware_inventory.get_device("block", x) for x in devices]
@classmethod
def _device_is_supported(cls, device):
return device.device_type == "disk" and \
device.attributes.get("removable", None) == b"0" and \
(device.parent is not None and device.parent.subsystem in ["scsi"])
def _hardware_events_init(self):
self._hardware_inventory.subscribe(self, "block", self._hardware_events_callback)
def _hardware_events_cleanup(self):
self._hardware_inventory.unsubscribe(self)
def _hardware_events_callback(self, event, device):
if self._device_is_supported(device) or event == "remove":
super(IscsiPlugin, self)._hardware_events_callback(event, device)
def _added_device_apply_tuning(self, instance, device_name):
log.debug("_added_device_apply_tuning")
self._call_scripts(instance._scripts, ["start"])
super(IscsiPlugin, self)._added_device_apply_tuning(instance, device_name)
def _removed_device_unapply_tuning(self, instance, device_name):
log.debug("_removed_device_unapply_tuning")
self._call_scripts(instance._scripts, ["start"])
super(IscsiPlugin, self)._removed_device_unapply_tuning(instance, device_name)