509318396
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
3
À<×e=  ã               @   sj   d dl Z d dlZddlmZ ddlT d dlZd dlT d dl	m
Z
 d dljZejjƒ ZG dd„ dejƒZdS )é    Né   )Úbase)Ú*)Úcommandsc                   sf   e Zd ZdZ‡ fdd„Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
ejfdd„Zdd„ Z‡  ZS )Ú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.
	c                s$   t t| ƒj||Ž d| _tƒ | _d S )NT)Úsuperr   Ú__init__Z_has_dynamic_optionsr   Ú_cmd)ÚselfÚargsÚkwargs)Ú	__class__© ú$/usr/lib/python3.6/plugin_modules.pyr   3   s    zModulesPlugin.__init__c             C   s   d|_ d|_|j|_d S )NFT)Z_has_dynamic_tuningZ_has_static_tuningZoptionsÚ_modules)r
   Úinstancer   r   r   Ú_instance_init8   s    zModulesPlugin._instance_initc             C   s   d S )Nr   )r
   r   r   r   r   Ú_instance_cleanup=   s    zModulesPlugin._instance_cleanupc             C   sŽ   xˆ|D ]€}| j jdd|gƒ\}}|dk r6tjdƒ d S |dkrTtjd||jƒ f ƒ | j jd|gƒ\}}|dkrtjd||jƒ f ƒ qW d S )NZmodprobez-rr   zN'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Úoutr   r   r   Ú_reload_modules@   s    

zModulesPlugin._reload_modulesc             C   sR  | j ƒ  d}d}d}g }xìt|jjƒ ƒD ]Ú\}}| jj|ƒ}| jj|ƒ}	|sŽ| jjd|gƒ\}}
|dk rxd}tj	dƒ n|dkrŽtj
d| ƒ |sš|dkr(t|	ƒdkrÎ|	dd	… d
krÎtjdd|	ƒ}	|j|ƒ t|	ƒdkrô|d| d |	 d 7 }q(tjd| ƒ q(W | jjtj|ƒ t|ƒ}|dk�rN| j|ƒ t|jƒ|k�rNtjtjƒ d S )NÚ r   FZmodinfoTz8'modinfo' command not found, not checking kernel modulesz)kernel module '%s' not found, skipping itr   é   z+rz^\s*\+r\s*,?\s*zoptions ú Ú
zKmodule '%s' doesn't have any option specified, not writing it to modprobe.d)Ú_clear_modprobe_fileÚlistr   ÚitemsÚ
_variablesÚexpandr	   r   r   r   ÚerrorÚlenÚreÚsubÚappendr   Úwrite_to_fileÚconstsÚMODULES_FILEr   ÚinfoZSTR_HINT_REBOOT)r
   r   Úsr   Z
skip_checkZreload_listÚoptionÚvaluer   Úvr   Úlr   r   r   Ú_instance_apply_staticL   s8    


z$ModulesPlugin._instance_apply_staticc             C   s   t |ƒjddƒS )Nú/r   )ÚstrÚreplace)r
   Úpathr   r   r   Ú_unquote_pathk   s    zModulesPlugin._unquote_pathc          
   C   s  d}d}t jdƒ}�xt|jjƒ ƒD ]ò\}}| jj|ƒ}| jj|ƒ}	t jdd|	ƒ}	d| }
tj	j
|
ƒs€d}tjtjd | ƒ q$tjtjd | ƒ |j|	ƒ}xv|D ]n}|jd	ƒ}t|ƒd
krÒtjd||f ƒ q¤| j|d |d | jj|
d | j|d ƒ d dd�|ƒdkr¤d}q¤W q$W |S )NTz\s+z^\s*\+r\s*,?\s*r   z/sys/module/%sFzmodule '%s' is not loadedzmodule '%s' is loadedú=r   z.unrecognized module option for module '%s': %sr   r   z/parameters/)Zerr_retÚno_error)r)   Úcompiler#   r   r$   r%   r&   r*   Úosr9   Úexistsr   r'   r-   ZSTR_VERIFY_PROFILE_FAILr/   ZSTR_VERIFY_PROFILE_OKÚsplitr(   r   Z_verify_valuer	   Ú	read_filer:   )r
   r   Zignore_missingZdevicesÚretÚrr1   r2   r   r3   Zmpathr4   ÚitemÚargr   r   r   Ú_instance_verify_staticn   s,    



"
z%ModulesPlugin._instance_verify_staticc             C   s   |t jkr| jƒ  d S )N)r-   ZROLLBACK_FULLr"   )r
   r   Zrollbackr   r   r   Ú_instance_unapply_static‰   s    
z&ModulesPlugin._instance_unapply_staticc             C   s    | j jtjdd�}|jdƒ}d }}t|ƒ}tjdƒ}x.||k rd|j|| ƒd krZ|}|}|d7 }q8W dj	|d|… ƒ}t|ƒdkrŒ|d7 }| j j
tj|ƒ d S )NT)r<   r!   r   z^\s*#r   )r	   rA   r-   r.   r@   r(   r)   r=   ÚsearchÚjoinr,   )r
   r0   r4   ÚiÚjZllrC   r   r   r   r"   �   s    


z"ModulesPlugin._clear_modprobe_file)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r5   r:   rF   r-   ZROLLBACK_SOFTrG   r"   Ú__classcell__r   r   )r   r   r      s   %r   )r)   Zos.pathr>   r   r   Z
decoratorsZ
tuned.logsZtunedÚ
subprocessZtuned.utils.commandsr   Ztuned.constsr-   ZlogsÚgetr   ZPluginr   r   r   r   r   Ú<module>   s   

