Your IP : 52.15.92.58


Current Path : /usr/lib/python3.6/site-packages/tuned/plugins/__pycache__/
Upload File :
Current File : //usr/lib/python3.6/site-packages/tuned/plugins/__pycache__/plugin_sysctl.cpython-36.pyc

3

�<�e��@s�ddlZddlmZddlTddlZddlTddlmZddl	j
Z
ddlZddlZej
j�ZddgZdd	gZGd
d�dej�ZdS)�N�)�base)�*)�commandsZbase_reachable_timeZretrans_timez
/run/sysctl.dz
/etc/sysctl.dcs�eZdZdZ�fdd�Zdd�Zdd�Zdd	�Zd
d�Ze	j
fdd
�Zdd�Zdd�Z
dd�Zdd�Zdd�Zddd�Z�ZS)�SysctlPluginaI
	`sysctl`::
	
	Sets various kernel parameters at runtime.
	+
	This plug-in is used for applying custom `sysctl` settings and should
	only be used to change system settings that are not covered by other
	*TuneD* plug-ins. If the settings are covered by other *TuneD* plug-ins,
	use those plug-ins instead.
	+
	The syntax for this plug-in is
	`_key_=_value_`, where
	`_key_` is the same as the key name provided by the
	`sysctl` utility.
	+
	.Adjusting the kernel runtime kernel.sched_min_granularity_ns value
	====
	----
	[sysctl]
	kernel.sched_min_granularity_ns=3000000
	----
	====
	cs$tt|�j||�d|_t�|_dS)NT)�superr�__init__Z_has_dynamic_optionsr�_cmd)�self�args�kwargs)�	__class__��#/usr/lib/python3.6/plugin_sysctl.pyr*szSysctlPlugin.__init__cCshd|_d|_|j|j�}|jj|i�|_t|j�dkr\tj	d�|j
|�i|_|jj|�|j|_
dS)NFTrz0recovering old sysctl settings from previous run)Z_has_dynamic_tuningZ_has_static_tuning�_storage_key�name�_storage�get�_sysctl_original�len�log�info�_instance_unapply_static�unsetZoptions�_sysctl)r
�instance�storage_keyrrr�_instance_init/s

zSysctlPlugin._instance_initcCs|j|j�}|jj|�dS)N)rrrr)r
rrrrr�_instance_cleanup?szSysctlPlugin._instance_cleanupcCs�xzt|jj��D]h\}}|j|�}|dkr:tjd|�q|jj|jj	|��}|j
||�}|dk	r||j|<|j||�qW|j
|j�}|jj||j�|jjtjtj�r�tjd�|j|j�dS)NzDsysctl option %s will not be set, failed to read the original value.zreapplying system sysctl)�listr�items�_read_sysctlr�error�
_variables�expandr	Zunquote�_process_assignment_modifiersr�
_write_sysctlrrr�setZ_global_cfgZget_bool�constsZCFG_REAPPLY_SYSCTLZCFG_DEF_REAPPLY_SYSCTLr�_apply_system_sysctl)r
r�option�value�original_valueZ	new_valuerrrr�_instance_apply_staticCs"



z#SysctlPlugin._instance_apply_staticcCsvd}d}xht|jj��D]V\}}|j|�}|j|jj|�|�}|dk	r|j||jj	|�|jj	|�|�dkrd}qW|S)NTF)
rrr r!r%r#r$Z
_verify_valuer	Z	remove_ws)r
r�ignore_missingZdevices�retr*r+Zcurr_valrrr�_instance_verify_staticYs
$z$SysctlPlugin._instance_verify_staticcCs,x&t|jj��D]\}}|j||�qWdS)N)rrr r&)r
rZrollbackr*r+rrrresz%SysctlPlugin._instance_unapply_staticc
Cs�i}x\tD]T}ytj|�}Wntk
r2w
YnXx(|D] }|jd�sJq:||kr:|||<q:Wq
Wx4t|j��D]$}||}d||f}|j||�qpW|jd|�dS)Nz.confz%s/%sz/etc/sysctl.conf)�SYSCTL_CONFIG_DIRS�os�listdir�OSError�endswith�sorted�keys�_apply_sysctl_config_file)r
�instance_sysctl�files�d�flistZfname�pathrrrr)is 


z!SysctlPlugin._apply_system_sysctlcCs�tjd|�yPt|d��.}x&t|d�D]\}}|j||||�q(WWdQRXtjd|�WnHttfk
r�}z(|jtjkr�tj	d|t
|�f�WYdd}~XnXdS)Nz%Applying sysctl settings from file %s�rrz.Finished applying sysctl settings from file %sz.Error reading sysctl settings from file %s: %s)r�debug�open�	enumerate�_apply_sysctl_config_liner4�IOError�errno�ENOENTr"�str)r
r=r9�f�lineno�line�errrr8|sz&SysctlPlugin._apply_sysctl_config_filec	Cs�|j�}t|�dks,|ddks,|ddkr0dS|jdd�}t|�dkr^tjd||f�dS|\}}|j�}t|�dkr�tjd||f�dS|j�}||kr�|jj||�}||kr�tjd|||f�|j||d	d
�dS)Nr�#�;�=r�z Syntax error in file %s, line %dz2Overriding sysctl parameter '%s' from '%s' to '%s'T)r.)	�stripr�splitrr"r#r$rr&)	r
r=rHrIr9Ztmpr*r+Zinstance_valuerrrrB�s*$z&SysctlPlugin._apply_sysctl_config_linecCsd|jj|dd�S)Nz/proc/sys/%sz./z/.)r	Ztr)r
r*rrr�_get_sysctl_path�szSysctlPlugin._get_sysctl_pathcCs�|j|�}yht|d��B}d}x.t|�D]"\}}|dkr&tjd|�dSq&W|j�}WdQRXtjd||f�|Sttfk
r�}z6|j	t	j
kr�tjd|�ntjd|t|�f�dSd}~XnXdS)Nr>�rzGFailed to read sysctl parameter '%s', multi-line values are unsupportedz&Value of sysctl parameter '%s' is '%s'zBFailed to read sysctl parameter '%s', the parameter does not existz(Failed to read sysctl parameter '%s': %s)rQr@rArr"rOr?r4rCrDrErF)r
r*r=rGrI�ir+rJrrrr!�s(

zSysctlPlugin._read_sysctlFcCs�|j|�}tjj|�tkr,tjd|�dSy6tjd||f�t|d��}|j	|�WdQRXdSt
tfk
r�}zJ|jtj
kr�|r�tjntj}|d||f�ntjd||t|�f�dSd}~XnXdS)Nz+Refusing to set deprecated sysctl option %sFz%Setting sysctl parameter '%s' to '%s'�wTzIFailed to set sysctl parameter '%s' to '%s', the parameter does not existz/Failed to set sysctl parameter '%s' to '%s': %s)rQr2r=�basename�DEPRECATED_SYSCTL_OPTIONSrr"r?r@�writer4rCrDrErF)r
r*r+r.r=rGrJZlog_funcrrrr&�s&
zSysctlPlugin._write_sysctl)F)�__name__�
__module__�__qualname__�__doc__rrrr-r0r(Z
ROLLBACK_SOFTrr)r8rBrQr!r&�
__classcell__rr)r
rrs
r)�rerRrZ
decoratorsZ
tuned.logsZtuned�
subprocessZtuned.utils.commandsrZtuned.constsr(rDr2ZlogsrrrVr1ZPluginrrrrr�<module>s



?>