관리-도구
편집 파일: plugin_modules.cpython-39.pyc
a ,�g7 � @ 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|�}|dk�rJ| �|� t|j�|k�rJt�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"