a ”ˆ«h7ã@slddlZddlZddlmZddlTddlZddlTddl m Z ddl m Z ej  ¡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  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|i|¤Žd|_tƒ|_dS)NT)ÚsuperrÚ__init__Z_has_dynamic_optionsrÚ_cmd)ÚselfÚargsÚkwargs©Ú __class__©ú@/usr/lib/python3.9/site-packages/tuned/plugins/plugin_modules.pyr3szModulesPlugin.__init__cCsd|_d|_|j|_dS)NFT)Z_has_dynamic_tuningZ_has_static_tuningÚoptionsÚ_modules©r ÚinstancerrrÚ_instance_init8szModulesPlugin._instance_initcCsdS©NrrrrrÚ_instance_cleanup=szModulesPlugin._instance_cleanupcCsŒ|D]‚}|j dd|g¡\}}|dkr6t d¡dS|dkrTt d|| ¡f¡|j d|g¡\}}|dkrt d|| ¡f¡qdS)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ÚwarningÚdebugÚstrip)r ÚmodulesÚmoduleÚretcodeÚoutrrrÚ_reload_modules@s zModulesPlugin._reload_modulesc CsN| ¡d}d}d}g}t|j ¡ƒD]Ú\}}|j |¡}|j |¡} |sŒ|j d|g¡\}} |dkrvd}t  d¡n|dkrŒt  d|¡|s˜|dkr&t | ƒdkrÌ| dd …d krÌt   d d| ¡} | |¡t | ƒdkrò|d |d | d7}q&t d|¡q&|j tj|¡t |ƒ} | dkrJ| |¡t |jƒ| krJt tj¡dS)NÚrFZmodinfoTz8'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 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|ƒ dd¡S)Nú/r")ÚstrÚreplace)r ÚpathrrrÚ _unquote_pathkszModulesPlugin._unquote_pathc Csd}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| ƒd krÎt  d || f¡qž| | d | d |jj| d| | d ¡ddd|¡dkržd}qžq |S)NTz\s+r$r"z/sys/module/%sFzmodule '%s' is not loadedzmodule '%s' is loadedú=rr#z.unrecognized module option for module '%s': %srz /parameters/)Zerr_retÚno_error)r.Úcompiler(rr)r*r+r/Úosr>Úexistsrr,r2ZSTR_VERIFY_PROFILE_FAILr4ZSTR_VERIFY_PROFILE_OKÚsplitr-rZ _verify_valuer Ú read_filer?)r rZignore_missingZdevicesÚretÚrr6r7rr8Zmpathr9ÚitemÚargrrrÚ_instance_verify_staticns2       "þþz%ModulesPlugin._instance_verify_staticcCs|tjkr| ¡dSr)r2Z ROLLBACK_FULLr')r rZrollbackrrrÚ_instance_unapply_static‰s z&ModulesPlugin._instance_unapply_staticcCsœ|jjtjdd}| d¡}d}}t|ƒ}t d¡}||krb| ||¡durX|}|}|d7}q6d  |d|…¡}t|ƒdkrˆ|d7}|j  tj|¡dS)NT)rAr&rz^\s*#r) r rFr2r3rEr-r.rBÚsearchÚjoinr1)r r5r9ÚiÚjZllrHrrrr's    z"ModulesPlugin._clear_modprobe_file)Ú__name__Ú __module__Ú __qualname__Ú__doc__rrrr!r:r?rKr2Z ROLLBACK_SOFTrLr'Ú __classcell__rrr rr s&  r)r.Zos.pathrCr"rZ decoratorsZ tuned.logsZtunedÚ subprocessZtuned.utils.commandsrZ tuned.constsr2ZlogsÚgetrZPluginrrrrrÚs