관리-도구
편집 파일: plugin_modules.cpython-36.opt-1.pyc
3 �<�e= � @ sj d dl Z d dlZddlmZ ddlT d dlZd dlT d dl m Z d dljZej j� 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! `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 zModulesPlugin.__init__c C s d|_ d|_|j|_d S )NFT)Z_has_dynamic_tuningZ_has_static_tuningZoptions�_modules)r �instancer r r �_instance_init8 s zModulesPlugin._instance_initc C s d S )Nr )r r r r r �_instance_cleanup= s zModulesPlugin._instance_cleanupc C s� x�|D ]�}| j jdd|g�\}}|dk r6tjd� d S |dkrTtjd||j� f � | j jd|g�\}}|dkrtjd||j� f � qW d 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�warn�debug�strip)r �modules�module�retcode�outr r r �_reload_modules@ s zModulesPlugin._reload_modulesc C sR | j � d}d}d}g }x�t|jj� �D ]�\}}| jj|�}| jj|�} |s�| jjd|g�\}} |dk rxd}tj d� n|dkr�tj d| � |s�|dkr(t| �dkr�| dd � d kr�tj dd| �} |j|� t| �dkr�|d| d | d 7 }q(tjd| � q(W | jjtj|� t|�}|dk�rN| j|� t|j�|k�rNtjtj� d S )N� r FZmodinfoTz8'modinfo' command not found, not checking kernel modulesz)kernel module '%s' not found, skipping itr � z+rz^\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 |�jdd�S )N�/r )�str�replace)r �pathr r r � _unquote_pathk s zModulesPlugin._unquote_pathc C s d}d}t jd�}�xt|jj� �D ]�\}}| jj|�}| jj|�} t jdd| �} d| } tj j | �s�d}tjt jd | � q$tjt jd | � |j| �}xv|D ]n}|jd �} t| �d kr�tjd||f � q�| j| d | d | jj| d | j| d � d dd�|�dkr�d}q�W q$W |S )NTz\s+z^\s*\+r\s*,?\s*r z/sys/module/%sFzmodule '%s' is not loadedzmodule '%s' is loaded�=r z.unrecognized module option for module '%s': %sr r z/parameters/)Zerr_ret�no_error)r) �compiler# r r$ r% r&