<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css"
        integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
</html>
3
<eQ                 @   sj   d dl Z ddlmZ ddlT d dlZd dljZd dlm	Z	 d dl
Z
d dlZej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 )%SCSIHostPlugina  
	`scsi_host`::
	
	Tunes options for SCSI hosts.
	+
	The plug-in sets Aggressive Link Power Management (ALPM) to the value specified
	by the [option]`alpm` option. The option takes one of three values:
	`min_power`, `medium_power` and `max_performance`.
	+
	NOTE: ALPM is only available on SATA controllers that use the Advanced
	Host Controller Interface (AHCI).
	+
	.ALPM setting when extended periods of idle time are expected
	====
	----
	[scsi_host]
	alpm=min_power
	----
	====
	c                s   t t| j|| t | _d S )N)superr   __init__r   _cmd)selfargskwargs)	__class__ &/usr/lib/python3.6/plugin_scsi_host.pyr   "   s    zSCSIHostPlugin.__init__c                sV   t t| j  d| _t | _x,| jjdD ]}| j|r*| jj	|j
 q*W t | _d S )NTscsi)r   r   _init_devicesZ_devices_supportedsetZ_free_devices_hardware_inventoryZget_devices_device_is_supportedaddZsys_nameZ_assigned_devices)r
   device)r   r   r   r   '   s    
zSCSIHostPlugin._init_devicesc                s    fdd|D S )Nc                s   g | ]} j jd |qS )r   )r   Z
get_device).0x)r
   r   r   
<listcomp>2   s    z6SCSIHostPlugin._get_device_objects.<locals>.<listcomp>r   )r
   Zdevicesr   )r
   r   _get_device_objects1   s    z"SCSIHostPlugin._get_device_objectsc             C   s
   |j dkS )NZ	scsi_host)Zdevice_type)clsr   r   r   r   r   4   s    z#SCSIHostPlugin._device_is_supportedc             C   s   | j j| d| j d S )Nr   )r   Z	subscribe_hardware_events_callback)r
   r   r   r   _hardware_events_init8   s    z$SCSIHostPlugin._hardware_events_initc             C   s   | j j|  d S )N)r   Zunsubscribe)r
   r   r   r   _hardware_events_cleanup;   s    z'SCSIHostPlugin._hardware_events_cleanupc                s    | j |rtt| j|| d S )N)r   r   r   r   )r
   Zeventr   )r   r   r   r   >   s    
z(SCSIHostPlugin._hardware_events_callbackc                s   t t| j|| d S )N)r   r   _added_device_apply_tuning)r
   instancedevice_name)r   r   r   r   B   s    z)SCSIHostPlugin._added_device_apply_tuningc                s   t t| j|| d S )N)r   r   _removed_device_unapply_tuning)r
   r    r!   )r   r   r   r"   E   s    z-SCSIHostPlugin._removed_device_unapply_tuningc             C   s   dd iS )Nalpmr   )r   r   r   r   _get_config_optionsH   s    z"SCSIHostPlugin._get_config_optionsc             C   s   d|_ d|_d S )NTF)Z_has_static_tuningZ_has_dynamic_tuning)r
   r    r   r   r   _instance_initN   s    zSCSIHostPlugin._instance_initc             C   s   d S )Nr   )r
   r    r   r   r   _instance_cleanupR   s    z SCSIHostPlugin._instance_cleanupc             C   s   t jjdt|dS )Nz/sys/class/scsi_host/Zlink_power_management_policy)ospathjoinstr)r
   r   r   r   r   _get_alpm_policy_fileU   s    z$SCSIHostPlugin._get_alpm_policy_filer#   T)Z
per_devicec             C   sd   |d krd S | j |}|s`tjj|rF| jj|||r<tjgndd ntj	d|t
|f  d S |S )NF)no_errorzBALPM control file ('%s') not found, skipping ALPM setting for '%s')r+   r'   r(   existsr	   Zwrite_to_fileerrnoENOENTloginfor*   )r
   policyr   Zsimremovepolicy_filer   r   r   	_set_alpmX   s    

zSCSIHostPlugin._set_alpmFc             C   s.   | j |}| jj|ddj }|dkr*|S d S )NT)r,    )r+   r	   Z	read_filestrip)r
   r   Zignore_missingr4   r2   r   r   r   	_get_alpmf   s    
zSCSIHostPlugin._get_alpm)F)__name__
__module____qualname____doc__r   r   r   classmethodr   r   r   r   r   r"   r$   r%   r&   r+   Zcommand_setr5   Zcommand_getr8   __classcell__r   r   )r   r   r      s"   
r   )r.   r6   r   Z
decoratorsZ
tuned.logsZtunedZtuned.constsZconstsZtuned.utils.commandsr   r'   reZlogsgetr0   ZPluginr   r   r   r   r   <module>   s   

