3 Yd=@sjddlZddlZddlmZddlTddlZddlTddl m Z ddl j Z ej jZGdddejZdS)N)base)*)commandscsfeZdZdZfddZddZddZdd Zd d Zd d Z ddZ e j fddZ ddZZS) 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)selfargskwargs) __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_cleanupcCsx|D]}|jjdd|g\}}|dkr6tjddS|dkrTtjd||jf|jjd|g\}}|dkrtjd||jfqWdS)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 executelogwarndebugstrip)r modulesmoduleretcodeoutrrr_reload_modules@s  zModulesPlugin._reload_modulesc CsR|jd}d}d}g}xt|jjD]\}}|jj|}|jj|} |s|jjd|g\}} |dkrxd}tj dn|dkrtj d||s|dkr(t | dkr| dd d krt j d d| } |j|t | dkr|d |d | d7}q(tjd|q(W|jjtj|t |} | dkrN|j|t |j| krNtjtjdS)NrFZmodinfoTz8'modinfo' command not found, not checking kernel modulesz)kernel module '%s' not found, skipping itrz+rz^\s*\+r\s*,?\s*zoptions   zKmodule '%s' doesn't have any option specified, not writing it to modprobe.d)_clear_modprobe_filelistritems _variablesexpandr rrrerrorlenresubappendr write_to_fileconsts MODULES_FILErinfoZSTR_HINT_REBOOT) r rsrZ skip_checkZ reload_listoptionvaluervrlrrr_instance_apply_staticLs8        z$ModulesPlugin._instance_apply_staticcCst|jddS)N/r)strreplace)r pathrrr _unquote_pathkszModulesPlugin._unquote_pathc Csd}d}tjd}xt|jjD]\}}|jj|}|jj|} tjdd| } d|} tj j | sd}t j t jd|q$t jt jd||j| } xv| D]n} | jd } t| d krt jd || fq|j| d | d |jj| d|j| d ddd|dkrd}qWq$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_retno_error)r)compiler#rr$r%r&r*osr9existsrr'r-ZSTR_VERIFY_PROFILE_FAILr/ZSTR_VERIFY_PROFILE_OKsplitr(rZ _verify_valuer read_filer:)r rZignore_missingZdevicesretrr1r2rr3Zmpathr4itemargrrr_instance_verify_staticns,        "  z%ModulesPlugin._instance_verify_staticcCs|tjkr|jdS)N)r-Z ROLLBACK_FULLr")r rZrollbackrrr_instance_unapply_statics 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=searchjoinr,)r r0r4ijZllrCrrrr"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-ZlogsgetrZPluginrrrrrs