3 Yd @sjddlZddlmZddlTddlZddljZddlm Z ddl Z ddl Z ej j ZGdddejZdS)N)hotplug)*)commandscseZdZdZfddZfddZddZedd Zd d Z d d Z fddZ fddZ fddZ eddZddZddZddZeddddd Zedd$d"d#ZZS)%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 ---- ==== cstt|j||t|_dS)N)superr__init__r_cmd)selfargskwargs) __class__&/usr/lib/python3.6/plugin_scsi_host.pyr"szSCSIHostPlugin.__init__csVtt|jd|_t|_x,|jjdD]}|j|r*|jj |j q*Wt|_ dS)NTscsi) rr _init_devicesZ_devices_supportedsetZ _free_devices_hardware_inventoryZ get_devices_device_is_supportedaddZsys_nameZ_assigned_devices)r device)r rrr's zSCSIHostPlugin._init_devicescsfdd|DS)Ncsg|]}jjd|qS)r)rZ get_device).0x)r rr 2sz6SCSIHostPlugin._get_device_objects..r)r Zdevicesr)r r_get_device_objects1sz"SCSIHostPlugin._get_device_objectscCs |jdkS)NZ scsi_host)Z device_type)clsrrrrr4sz#SCSIHostPlugin._device_is_supportedcCs|jj|d|jdS)Nr)rZ subscribe_hardware_events_callback)r rrr_hardware_events_init8sz$SCSIHostPlugin._hardware_events_initcCs|jj|dS)N)rZ unsubscribe)r rrr_hardware_events_cleanup;sz'SCSIHostPlugin._hardware_events_cleanupcs |j|rtt|j||dS)N)rrrr)r Zeventr)r rrr>s z(SCSIHostPlugin._hardware_events_callbackcstt|j||dS)N)rr_added_device_apply_tuning)r instance device_name)r rrrBsz)SCSIHostPlugin._added_device_apply_tuningcstt|j||dS)N)rr_removed_device_unapply_tuning)r r r!)r rrr"Esz-SCSIHostPlugin._removed_device_unapply_tuningcCsddiS)Nalpmr)rrrr_get_config_optionsHsz"SCSIHostPlugin._get_config_optionscCsd|_d|_dS)NTF)Z_has_static_tuningZ_has_dynamic_tuning)r r rrr_instance_initNszSCSIHostPlugin._instance_initcCsdS)Nr)r r rrr_instance_cleanupRsz SCSIHostPlugin._instance_cleanupcCstjjdt|dS)Nz/sys/class/scsi_host/Zlink_power_management_policy)ospathjoinstr)r rrrr_get_alpm_policy_fileUsz$SCSIHostPlugin._get_alpm_policy_filer#T)Z per_devicecCsT|dkr dS|j|}|sPtjj|r6|jj||ntjd|t|fdS|S)NzBALPM control file ('%s') not found, skipping ALPM setting for '%s') r+r'r(existsr Z write_to_fileloginfor*)r policyrZsim policy_filerrr _set_alpmXs  zSCSIHostPlugin._set_alpmFcCs.|j|}|jj|ddj}|dkr*|SdS)NT)Zno_error)r+r Z read_filestrip)r rZignore_missingr0r/rrr _get_alpmes zSCSIHostPlugin._get_alpm)F)__name__ __module__ __qualname____doc__rrr classmethodrrrrrr"r$r%r&r+Z command_setr1Z command_getr4 __classcell__rr)r rr s"        r)errnor2rZ decoratorsZ tuned.logsZtunedZ tuned.constsZconstsZtuned.utils.commandsrr'reZlogsgetr-ZPluginrrrrrs