a Á]›i7 ã @ sl d dl Z d dlZddlmZ ddlT d dlZd dlT d dl m Z d dlmZ ej ¡ 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 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|i |¤Ž d| _tƒ | _d S )NT)Úsuperr Ú__init__Z_has_dynamic_optionsr Ú_cmd)ÚselfÚargsÚkwargs©Ú __class__© ú@/usr/lib/python3.9/site-packages/tuned/plugins/plugin_modules.pyr 3 s zModulesPlugin.__init__c C s d|_ d|_|j|_d S )NFT)Z_has_dynamic_tuningZ_has_static_tuningÚoptionsÚ_modules©r Úinstancer r r Ú_instance_init8 s zModulesPlugin._instance_initc C s d S ©Nr r r r r Ú_instance_cleanup= s zModulesPlugin._instance_cleanupc C sŒ |D ]‚}| j dd|g¡\}}|dk r6t d¡ d S |dkrTt d|| ¡ f ¡ | j d|g¡\}}|dkrt d|| ¡ f ¡ qd 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ÚwarningÚdebugÚstrip)r ÚmodulesÚmoduleÚretcodeÚoutr r r Ú_reload_modules@ s zModulesPlugin._reload_modulesc C sN | ¡ d}d}d}g }t|j ¡ ƒD ]Ú\}}| j |¡}| j |¡} |sŒ| j d|g¡\}} |dk rvd}t d¡ n|dkrŒt d| ¡ |s˜|dkr&t| ƒdkrÌ| dd … d krÌt dd| ¡} | |¡ t| ƒdkrò|d| d | d 7 }q&t d| ¡ q&| j tj|¡ t|ƒ}|dkrJ| |¡ t|jƒ|krJt tj¡ d S )NÚ r FZmodinfoTz8'modinfo' command not found, not checking kernel modulesz)kernel module '%s' not found, skipping itr é z+rú^\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 |ƒ dd¡S )Nú/r" )ÚstrÚreplace)r Úpathr r r Ú _unquote_pathk s zModulesPlugin._unquote_pathc C s d}d}t d¡}t|j ¡ ƒD ]ð\}}| j |¡}| j |¡} t dd| ¡} d| } tj | ¡s|d}t t jd | ¡ q t t jd | ¡ | | ¡}|D ]p}| d d ¡} t| ƒdkrÎt d||f ¡ qž| | d | d | jj| d | | d ¡ d dd|¡dkržd}qžq |S )NTz\s+r$ r" z/sys/module/%sFzmodule '%s' is not loadedzmodule '%s' is loadedú=r r# z.unrecognized module option for module '%s': %sr z/parameters/)Zerr_retÚno_error)r. Úcompiler( r r) r* r+ r/ Úosr> Úexistsr r, r2 ZSTR_VERIFY_PROFILE_FAILr4 ZSTR_VERIFY_PROFILE_OKÚsplitr- r Z _verify_valuer Ú read_filer? )r r Zignore_missingZdevicesÚretÚrr6 r7 r r8 Zmpathr9 ÚitemÚargr r r Ú_instance_verify_staticn s2 "þþz%ModulesPlugin._instance_verify_staticc C s |t jkr| ¡ d S r )r2 Z ROLLBACK_FULLr' )r r Zrollbackr r r Ú_instance_unapply_static‰ s z&ModulesPlugin._instance_unapply_staticc C sœ | j jtjdd}| d¡}d }}t|ƒ}t d¡}||k rb| || ¡d u rX|}|}|d7 }q6d |d|… ¡}t|ƒdkrˆ|d7 }| j tj|¡ d S )NT)rA r&