a h@slddlZddlmZddlTddlZddlmZddlm Z ddl Z ddl Z ej ZGdddejZdS)N)hotplug)*)commandscseZdZdZfddZfddZddZedd Zd d Z d d Z fddZ fddZ fddZ eddZddZddZddZddZddZed d!d"d#d$Zed d(d&d'ZZS))SCSIHostPlugina 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 four values: `min_power`, `med_power_with_dipm`, `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=med_power_with_dipm ---- ==== cs"tt|j|i|t|_dSN)superr__init__r_cmd)selfargskwargs __class__B/usr/lib/python3.9/site-packages/tuned/plugins/plugin_scsi_host.pyr szSCSIHostPlugin.__init__csRtt|d|_t|_|jdD]}||r(|j |j q(t|_ dS)NTscsi) rr _init_devicesZ_devices_supportedsetZ _free_devices_hardware_inventoryZ get_devices_device_is_supportedaddZsys_nameZ_assigned_devicesr devicerrrr%s zSCSIHostPlugin._init_devicescsfdd|DS)Ncsg|]}jd|qS)r)rZ get_device).0xr rr 0z6SCSIHostPlugin._get_device_objects..r)r Zdevicesrrr_get_device_objects/sz"SCSIHostPlugin._get_device_objectscCs |jdkS)NZ scsi_host)Z device_type)clsrrrrr2sz#SCSIHostPlugin._device_is_supportedcCs|j|d|jdS)Nr)rZ subscribe_hardware_events_callbackrrrr_hardware_events_init6sz$SCSIHostPlugin._hardware_events_initcCs|j|dSr)rZ unsubscriberrrr_hardware_events_cleanup9sz'SCSIHostPlugin._hardware_events_cleanupcs ||rtt|||dSr)rrrr!)r Zeventrrrrr!<s z(SCSIHostPlugin._hardware_events_callbackcstt|||dSr)rr_added_device_apply_tuningr instanceZ device_namerrrr$@sz)SCSIHostPlugin._added_device_apply_tuningcstt|||dSr)rr_removed_device_unapply_tuningr%rrrr'Csz-SCSIHostPlugin._removed_device_unapply_tuningcCsddiS)Nalpmr)r rrr_get_config_optionsFsz"SCSIHostPlugin._get_config_optionscCsd|_d|_dS)NTF)Z_has_static_tuningZ_has_dynamic_tuningr r&rrr_instance_initLszSCSIHostPlugin._instance_initcCsdSrrr*rrr_instance_cleanupPsz SCSIHostPlugin._instance_cleanupcCstjdt|dS)N/sys/class/scsi_host/Zlink_power_management_policyospathjoinstrrrrr_get_alpm_policy_fileSsz$SCSIHostPlugin._get_alpm_policy_filecCstjdt|dS)Nr-Z ahci_port_cmdr.rrrr_get_ahci_port_cmd_fileVsz&SCSIHostPlugin._get_ahci_port_cmd_filecCs8||}tj|sdSt|j|d}|d@dkS)NFi$r)r4r/r0isfileintr read_file)r rZ port_cmd_fileZport_cmdrrr_is_external_sata_portYs   z%SCSIHostPlugin._is_external_sata_portr(T)Z per_devicecCs|dur dS||r,tdt|dS||}|stj|rf|jj |||r\t j gnddntd|t|fdS|S)NzUDevice '%s' is an external SATA controller, skipping ALPM setting to support hot plugFZno_errorzBALPM control file ('%s') not found, skipping ALPM setting for '%s') r9loginfor2r3r/r0existsr Z write_to_fileerrnoENOENT)r policyrr&Zsimremove policy_filerrr _set_alpmbs    zSCSIHostPlugin._set_alpmFcCs.||}|jj|dd}|dkr*|SdS)NTr:)r3r r8strip)r rr&Zignore_missingrBr@rrr _get_alpmus zSCSIHostPlugin._get_alpm)F)__name__ __module__ __qualname____doc__r rr classmethodrr"r#r!r$r'r)r+r,r3r4r9Z command_setrCZ command_getrF __classcell__rrrrr s,         r)r>rDrZ decoratorsZ tuned.logsZtunedZ tuned.constsZconstsZtuned.utils.commandsrr/reZlogsgetr;ZPluginrrrrrs