Your IP : 18.119.134.196


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_modules.cpython-36.pyc

3

�<�e=�@sjddlZddlZddlmZddlTddlZddlTddl	m
Z
ddljZej
j�ZGdd�dej�ZdS)�N�)�base)�*)�commandscsfeZdZdZ�fdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
ejfdd�Z
dd�Z�ZS)�
ModulesPlugina!
	`modules`::
	
	Plug-in for applying custom kernel modules options.
	+
	This plug-in can set parameters to kernel modules. It creates
	`/etc/modprobe.d/tuned.conf` file. The syntax is
	`_module_=_option1=value1 option2=value2..._` where `_module_` is
	the module name and `_optionx=valuex_` are module options which may
	or may not be present.
	+
	.Load module `netrom` with module parameter `nr_ndevs=2`
	====
	----
	[modules]
	netrom=nr_ndevs=2
	----
	====
	Modules can also be forced to load/reload by using an additional
	`+r` option prefix.
	+
	.(Re)load module `netrom` with module parameter `nr_ndevs=2`
	====
	----
	[modules]
	netrom=+r nr_ndevs=2
	----
	====
	The `+r` switch will also cause *TuneD* to try and remove `netrom`
	module (if loaded) and try and (re)insert it with the specified
	parameters. The `+r` can be followed by an optional comma (`+r,`)
	for better readability.
	+
	When using `+r` the module will be loaded immediately by the *TuneD*
	daemon itself rather than waiting for the OS to load it with the
	specified parameters.
	cs$tt|�j||�d|_t�|_dS)NT)�superr�__init__Z_has_dynamic_optionsr�_cmd)�self�args�kwargs)�	__class__��$/usr/lib/python3.6/plugin_modules.pyr3szModulesPlugin.__init__cCsd|_d|_|j|_dS)NFT)Z_has_dynamic_tuningZ_has_static_tuningZoptions�_modules)r
�instancerrr�_instance_init8szModulesPlugin._instance_initcCsdS)Nr)r
rrrr�_instance_cleanup=szModulesPlugin._instance_cleanupcCs�x�|D]�}|jjdd|g�\}}|dkr6tjd�dS|dkrTtjd||j�f�|jjd|g�\}}|dkrtjd||j�f�qWdS)NZmodprobez-rrzN'modprobe' command not found, cannot reload kernel modules, reboot is requiredz$cannot remove kernel module '%s': %sz:cannot insert/reinsert module '%s', reboot is required: %s)r	�execute�log�warn�debug�strip)r
�modules�module�retcode�outrrr�_reload_modules@s

zModulesPlugin._reload_modulescCsR|j�d}d}d}g}x�t|jj��D]�\}}|jj|�}|jj|�}	|s�|jjd|g�\}}
|dkrxd}tj	d�n|dkr�tj
d|�|s�|dkr(t|	�dkr�|	dd	�d
kr�tj
dd|	�}	|j|�t|	�dkr�|d|d
|	d7}q(tjd|�q(W|jjtj|�t|�}|dk�rN|j|�t|j�|k�rNtjtj�dS)N�rFZmodinfoTz8'modinfo' command not found, not checking kernel modulesz)kernel module '%s' not found, skipping itr�z+rz^\s*\+r\s*,?\s*zoptions � �
zKmodule '%s' doesn't have any option specified, not writing it to modprobe.d)�_clear_modprobe_file�listr�items�
_variables�expandr	rrr�error�len�re�sub�appendr�
write_to_file�consts�MODULES_FILEr�infoZSTR_HINT_REBOOT)r
r�srZ
skip_checkZreload_list�option�valuer�vr�lrrr�_instance_apply_staticLs8


z$ModulesPlugin._instance_apply_staticcCst|�jdd�S)N�/r)�str�replace)r
�pathrrr�
_unquote_pathkszModulesPlugin._unquote_pathc
Csd}d}tjd�}�xt|jj��D]�\}}|jj|�}|jj|�}	tjdd|	�}	d|}
tj	j
|
�s�d}tjt
jd|�q$tjt
jd|�|j|	�}xv|D]n}|jd	�}
t|
�d
kr�tjd||f�q�|j|
d|
d
|jj|
d|j|
d�ddd�|�dkr�d}q�Wq$W|S)NTz\s+z^\s*\+r\s*,?\s*rz/sys/module/%sFzmodule '%s' is not loadedzmodule '%s' is loaded�=rz.unrecognized module option for module '%s': %srrz/parameters/)Zerr_ret�no_error)r)�compiler#rr$r%r&r*�osr9�existsrr'r-ZSTR_VERIFY_PROFILE_FAILr/ZSTR_VERIFY_PROFILE_OK�splitr(rZ
_verify_valuer	�	read_filer:)r
rZignore_missingZdevices�ret�rr1r2rr3Zmpathr4�item�argrrr�_instance_verify_staticns,



"
z%ModulesPlugin._instance_verify_staticcCs|tjkr|j�dS)N)r-Z
ROLLBACK_FULLr")r
rZrollbackrrr�_instance_unapply_static�s
z&ModulesPlugin._instance_unapply_staticcCs�|jjtjdd�}|jd�}d}}t|�}tjd�}x.||krd|j||�dkrZ|}|}|d7}q8Wdj	|d|��}t|�dkr�|d7}|jj
tj|�dS)NT)r<r!rz^\s*#r)r	rAr-r.r@r(r)r=�search�joinr,)r
r0r4�i�jZllrCrrrr"�s


z"ModulesPlugin._clear_modprobe_file)�__name__�
__module__�__qualname__�__doc__rrrrr5r:rFr-Z
ROLLBACK_SOFTrGr"�
__classcell__rr)r
rrs%r)r)Zos.pathr>rrZ
decoratorsZ
tuned.logsZtuned�
subprocessZtuned.utils.commandsrZtuned.constsr-Zlogs�getrZPluginrrrrr�<module>s



?>