o
    _Z
                     @   sl   d dl Z ddlmZ ddlT d dlZd dlmZ d dlm	Z	 d dl
Z
d dlZej ZG dd dejZdS )    N   )hotplug)*)commandsc                       s   e Zd ZdZ fddZ fddZdd Zedd	 Zd
d Z	dd Z
 fddZ fddZ fddZedd Zdd Zdd Zdd Zeddddd  Zedd$d"d#Z  ZS )%SCSIHostPluginz,
	Plugin for tuning options of SCSI hosts.
	c                    s"   t t| j|i | t | _d S N)superr   __init__r   _cmd)selfargskwargs	__class__ @/usr/lib/python3/dist-packages/tuned/plugins/plugin_scsi_host.pyr	      s   zSCSIHostPlugin.__init__c                    sR   t t|   d| _t | _| jdD ]}| |r"| j	|j
 qt | _d S )NTscsi)r   r   _init_devices_devices_supportedset_free_devices_hardware_inventoryget_devices_device_is_supportedaddsys_name_assigned_devicesr   devicer   r   r   r      s   
zSCSIHostPlugin._init_devicesc                    s    fdd|D S )Nc                    s   g | ]	} j d |qS )r   )r   
get_device).0xr   r   r   
<listcomp>!   s    z6SCSIHostPlugin._get_device_objects.<locals>.<listcomp>r   )r   devicesr   r"   r   _get_device_objects    s   z"SCSIHostPlugin._get_device_objectsc                 C   s
   |j dkS )N	scsi_host)device_type)clsr   r   r   r   r   #   s   
z#SCSIHostPlugin._device_is_supportedc                 C   s   | j | d| j d S )Nr   )r   	subscribe_hardware_events_callbackr"   r   r   r   _hardware_events_init'      z$SCSIHostPlugin._hardware_events_initc                 C   s   | j |  d S r   )r   unsubscriber"   r   r   r   _hardware_events_cleanup*   s   z'SCSIHostPlugin._hardware_events_cleanupc                    s$   |  |rtt| || d S d S r   )r   r   r   r*   )r   eventr   r   r   r   r*   -   s   
z(SCSIHostPlugin._hardware_events_callbackc                       t t| || d S r   )r   r   _added_device_apply_tuningr   instancedevice_namer   r   r   r1   1   r,   z)SCSIHostPlugin._added_device_apply_tuningc                    r0   r   )r   r   _removed_device_unapply_tuningr2   r   r   r   r5   4   r,   z-SCSIHostPlugin._removed_device_unapply_tuningc                 C   s   dd iS )Nalpmr   )r(   r   r   r   _get_config_options7   s   z"SCSIHostPlugin._get_config_optionsc                 C   s   d|_ d|_d S )NTF)_has_static_tuning_has_dynamic_tuningr   r3   r   r   r   _instance_init=   s   
zSCSIHostPlugin._instance_initc                 C   s   d S r   r   r:   r   r   r   _instance_cleanupA   s   z SCSIHostPlugin._instance_cleanupc                 C   s   t jdt|dS )Nz/sys/class/scsi_host/link_power_management_policy)ospathjoinstrr   r   r   r   _get_alpm_policy_fileD   s   z$SCSIHostPlugin._get_alpm_policy_filer6   T)
per_devicec                 C   sV   |d u rd S |  |}|s)tj|r| j|| |S td|t|f  d S |S )NzBALPM control file ('%s') not found, skipping ALPM setting for '%s')	rB   r>   r?   existsr
   write_to_fileloginforA   )r   policyr   simpolicy_filer   r   r   	_set_alpmG   s   
zSCSIHostPlugin._set_alpmFc                 C   s.   |  |}| jj|dd }|dkr|S d S )NT)no_error )rB   r
   	read_filestrip)r   r   ignore_missingrJ   rH   r   r   r   	_get_alpmT   s   
zSCSIHostPlugin._get_alpm)F)__name__
__module____qualname____doc__r	   r   r%   classmethodr   r+   r.   r*   r1   r5   r7   r;   r<   rB   command_setrK   command_getrQ   __classcell__r   r   r   r   r      s*    




r   )errnorM   r   
decorators
tuned.logstunedtuned.constsconststuned.utils.commandsr   r>   relogsgetrF   Pluginr   r   r   r   r   <module>   s    
