<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css"
        integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
</html>
3
<e=                 @   sj   d dl Z d dlZddlmZ ddlT d dlZd dlT d dl	m
Z
 d dljZejj ZG dd dejZdS )    N   )base)*)commandsc                   sf   e Zd ZdZ fddZdd Zdd Zdd	 Zd
d Zdd Z	dd Z
ejfddZdd Z  ZS )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    zModulesPlugin.__init__c             C   s   d|_ d|_|j|_d S )NFT)Z_has_dynamic_tuningZ_has_static_tuningZoptions_modules)r
   instancer   r   r   _instance_init8   s    zModulesPlugin._instance_initc             C   s   d S )Nr   )r
   r   r   r   r   _instance_cleanup=   s    zModulesPlugin._instance_cleanupc             C   s   x|D ]}| j jdd|g\}}|dk r6tjd d S |dkrTtjd||j f  | j jd|g\}}|dkrtjd||j f  qW d S )NZmodprobez-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    

zModulesPlugin._reload_modulesc             C   sR  | j   d}d}d}g }xt|jj D ]\}}| jj|}| jj|}	|s| jjd|g\}}
|dk rxd}tj	d n|dkrtj
d|  |s|dkr(t|	dkr|	dd	 d
krtjdd|	}	|j| t|	dkr|d| d |	 d 7 }q(tjd|  q(W | jjtj| t|}|dkrN| j| t|j|krNtjtj d S )N r   FZmodinfoTz8'modinfo' command not found, not checking kernel modulesz)kernel module '%s' not found, skipping itr      z+rz^\s*\+r\s*,?\s*zoptions  
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   infoZSTR_HINT_REBOOT)r
   r   sr   Z
skip_checkZreload_listoptionvaluer   vr   lr   r   r   _instance_apply_staticL   s8    


z$ModulesPlugin._instance_apply_staticc             C   s   t |jddS )N/r   )strreplace)r
   pathr   r   r   _unquote_pathk   s    zModulesPlugin._unquote_pathc          
   C   s  d}d}t jd}xt|jj D ]\}}| jj|}| jj|}	t jdd|	}	d| }
tj	j
|
sd}tjtjd |  q$tjtjd |  |j|	}xv|D ]n}|jd	}t|d
krtjd||f  q| j|d |d | jj|
d | j|d  d dd|dkrd}qW q$W |S )NTz\s+z^\s*\+r\s*,?\s*r   z/sys/module/%sFzmodule '%s' is not loadedzmodule '%s' is loaded=r   z.unrecognized module option for module '%s': %sr   r   z/parameters/)Zerr_retno_error)r)   compiler#   r   r$   r%   r&   r*   osr9   existsr   r'   r-   ZSTR_VERIFY_PROFILE_FAILr/   ZSTR_VERIFY_PROFILE_OKsplitr(   r   Z_verify_valuer	   	read_filer:   )r
   r   Zignore_missingZdevicesretrr1   r2   r   r3   Zmpathr4   itemargr   r   r   _instance_verify_staticn   s,    



"
z%ModulesPlugin._instance_verify_staticc             C   s   |t jkr| j  d S )N)r-   ZROLLBACK_FULLr"   )r
   r   Zrollbackr   r   r   _instance_unapply_static   s    
z&ModulesPlugin._instance_unapply_staticc             C   s   | j jtjdd}|jd}d }}t|}tjd}x.||k rd|j|| d krZ|}|}|d7 }q8W dj	|d| }t|dkr|d7 }| j j
tj| d S )NT)r<   r!   r   z^\s*#r   )r	   rA   r-   r.   r@   r(   r)   r=   searchjoinr,   )r
   r0   r4   ijZllrC   r   r   r   r"      s    


z"ModulesPlugin._clear_modprobe_file)__name__
__module____qualname____doc__r   r   r   r   r5   r:   rF   r-   ZROLLBACK_SOFTrG   r"   __classcell__r   r   )r   r   r      s   %r   )r)   Zos.pathr>   r   r   Z
decoratorsZ
tuned.logsZtuned
subprocessZtuned.utils.commandsr   Ztuned.constsr-   Zlogsgetr   ZPluginr   r   r   r   r   <module>   s   

