3 À<×e=ã@sjddlZddlZddlmZddlTddlZddlTddl m Z ddl j Z ej jƒZGdd„dejƒZdS)éNé)Úbase)Ú*)ÚcommandscsfeZdZdZ‡fdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z e j 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 d d| ƒ} |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_checkZ reload_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}t j t jd|ƒq$t jt jd|ƒ|j| ƒ} xv| D]n} | jd ƒ} t| ƒd krÒt jd || 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Ús