3 À<×e= ã @ sj d dl Z d dlZddlmZ ddlT d dlZd dlT d dl m Z d dljZej jƒ ZG dd„ dejƒZdS )é Né )Úbase)Ú*)Úcommandsc sf e Zd ZdZ‡ fdd„Zdd„ Zdd„ Zdd „ Zd d„ Zdd „ Z dd„ Z ejfdd„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. 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 zModulesPlugin.__init__c C s d|_ d|_|j|_d S )NFT)Z_has_dynamic_tuningZ_has_static_tuningZoptionsÚ_modules)r Úinstancer r r Ú_instance_init8 s zModulesPlugin._instance_initc C s d S )Nr )r r r r r Ú_instance_cleanup= s zModulesPlugin._instance_cleanupc C sŽ xˆ|D ]€}| j jdd|gƒ\}}|dk r6tjdƒ d S |dkrTtjd||jƒ f ƒ | j jd|gƒ\}}|dkrtjd||jƒ f ƒ qW d S )NZmodprobez-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 zModulesPlugin._reload_modulesc C sR | j ƒ d}d}d}g }xìt|jjƒ ƒD ]Ú\}}| jj|ƒ}| jj|ƒ} |sŽ| jjd|gƒ\}} |dk rxd}tj dƒ n|dkrŽtj d| ƒ |sš|dkr(t| ƒdkrÎ| dd … d krÎtj dd| ƒ} |j|ƒ t| ƒdkrô|d| d | d 7 }q(tjd| ƒ q(W | jjtj|ƒ t|ƒ}|dk�rN| j|ƒ t|jƒ|k�rNtjtjƒ d S )NÚ r FZmodinfoTz8'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 r r r ÚerrorÚlenÚreÚsubÚappendr Ú write_to_fileÚconstsÚMODULES_FILEr ÚinfoZSTR_HINT_REBOOT)r r Úsr Z skip_checkZreload_listÚoptionÚvaluer Úvr Úlr r r Ú_instance_apply_staticL s8 z$ModulesPlugin._instance_apply_staticc C s t |ƒjddƒS )Nú/r )ÚstrÚreplace)r Úpathr r r Ú _unquote_pathk s zModulesPlugin._unquote_pathc C s d}d}t jdƒ}�xt|jjƒ ƒD ]ò\}}| jj|ƒ}| jj|ƒ} t jdd| ƒ} d| } tj j | ƒs€d}tjt jd | ƒ q$tjt jd | ƒ |j| ƒ}xv|D ]n}|jd ƒ} t| ƒd krÒtjd||f ƒ q¤| j| d | d | jj| d | j| d ƒ d dd�|ƒdkr¤d}q¤W q$W |S )NTz\s+z^\s*\+r\s*,?\s*r z/sys/module/%sFzmodule '%s' is not loadedzmodule '%s' is loadedú=r z.unrecognized module option for module '%s': %sr r z/parameters/)Zerr_retÚno_error)r) Úcompiler# r r$ r% r&