관리-도구
편집 파일: plugin_bootloader.cpython-36.opt-1.pyc
3 �<�e:e � @ s� d dl mZ d dlT ddlZd dl mZ ddlmZ ddlj Z ddl Z ddlZddlZddl mZ ejj� ZG dd � d ej�ZdS ) � )�base)�*� N)� exceptions)�commands)�sleepc s� e Zd ZdZ� fdd�Zdd� Zdd� Zedd � �Ze d[dd��Z e d d� �Zdd� Zdd� Z i i fdd�Zdd� Zdd� Zdd� Zdd� Zdd� Zdd � Zd!d"� Zejfd#d$�Zd%d&� Zd'd(� Zd)d*� Zd+d,� Zd-d.� Zd/d0� Zd1d2� Zd3d4� Z d5d6� Z!d7d8� Z"d9d:� Z#d;d<� Z$d=d>� Z%d?d@� Z&e'dA�dBdC� �Z(e'dD�dEdF� �Z)e'dG�dHdI� �Z*e'dJdKdLdM�dNdO� �Z+e'dPdKdLdM�dQdR� �Z,e'dSdKdLdM�dTdU� �Z-e'dVdKdLdM�dWdX� �Z.dYdZ� Z/� Z0S )\�BootloaderPlugina� `bootloader`:: Adds options to the kernel command line. This plug-in supports the GRUB 2 boot loader and the Boot Loader Specification (BLS). + NOTE: *TuneD* will not remove or replace kernel command line parameters added via other methods like *grubby*. *TuneD* will manage the kernel command line parameters added via *TuneD*. Please refer to your platform bootloader documentation about how to identify and manage kernel command line parameters set outside of *TuneD*. + Customized non-standard location of the GRUB 2 configuration file can be specified by the [option]`grub2_cfg_file` option. + The kernel options are added to the current GRUB configuration and its templates. Reboot the system for the kernel option to take effect. + Switching to another profile or manually stopping the `tuned` service removes the additional options. If you shut down or reboot the system, the kernel options persist in the [filename]`grub.cfg` file and grub environment files. + The kernel options can be specified by the following syntax: + [subs="+quotes,+macros"] ---- cmdline__suffix__=__arg1__ __arg2__ ... __argN__ ---- + Or with an alternative, but equivalent syntax: + [subs="+quotes,+macros"] ---- cmdline__suffix__=+__arg1__ __arg2__ ... __argN__ ---- + Where __suffix__ can be arbitrary (even empty) alphanumeric string which should be unique across all loaded profiles. It is recommended to use the profile name as the __suffix__ (for example, [option]`cmdline_my_profile`). If there are multiple [option]`cmdline` options with the same suffix, during the profile load/merge the value which was assigned previously will be used. This is the same behavior as any other plug-in options. The final kernel command line is constructed by concatenating all the resulting [option]`cmdline` options. + It is also possible to remove kernel options by the following syntax: + [subs="+quotes,+macros"] ---- cmdline__suffix__=-__arg1__ __arg2__ ... __argN__ ---- + Such kernel options will not be concatenated and thus removed during the final kernel command line construction. + .Modifying the kernel command line ==== For example, to add the [option]`quiet` kernel option to a *TuneD* profile, include the following lines in the [filename]`tuned.conf` file: ---- [bootloader] cmdline_my_profile=+quiet ---- An example of a custom profile `my_profile` that adds the [option]`isolcpus=2` option to the kernel command line: ---- [bootloader] cmdline_my_profile=isolcpus=2 ---- An example of a custom profile `my_profile` that removes the [option]`rhgb quiet` options from the kernel command line (if previously added by *TuneD*): ---- [bootloader] cmdline_my_profile=-rhgb quiet ---- ==== + .Modifying the kernel command line, example with inheritance ==== For example, to add the [option]`rhgb quiet` kernel options to a *TuneD* profile `profile_1`: ---- [bootloader] cmdline_profile_1=+rhgb quiet ---- In the child profile `profile_2` drop the [option]`quiet` option from the kernel command line: ---- [main] include=profile_1 [bootloader] cmdline_profile_2=-quiet ---- The final kernel command line will be [option]`rhgb`. In case the same [option]`cmdline` suffix as in the `profile_1` is used: ---- [main] include=profile_1 [bootloader] cmdline_profile_1=-quiet ---- It will result in the empty kernel command line because the merge executes and the [option]`cmdline_profile_1` gets redefined to just [option]`-quiet`. Thus there is nothing to remove in the final kernel command line processing. ==== + The [option]`initrd_add_img=IMAGE` adds an initrd overlay file `IMAGE`. If the `IMAGE` file name begins with '/', the absolute path is used. Otherwise, the current profile directory is used as the base directory for the `IMAGE`. + The [option]`initrd_add_dir=DIR` creates an initrd image from the directory `DIR` and adds the resulting image as an overlay. If the `DIR` directory name begins with '/', the absolute path is used. Otherwise, the current profile directory is used as the base directory for the `DIR`. + The [option]`initrd_dst_img=PATHNAME` sets the name and location of the resulting initrd image. Typically, it is not necessary to use this option. By default, the location of initrd images is `/boot` and the name of the image is taken as the basename of `IMAGE` or `DIR`. This can be overridden by setting [option]`initrd_dst_img`. + The [option]`initrd_remove_dir=VALUE` removes the source directory from which the initrd image was built if `VALUE` is true. Only 'y', 'yes', 't', 'true' and '1' (case insensitive) are accepted as true values for this option. Other values are interpreted as false. + .Adding an overlay initrd image ==== ---- [bootloader] initrd_remove_dir=True initrd_add_dir=/tmp/tuned-initrd.img ---- This creates an initrd image from the `/tmp/tuned-initrd.img` directory and and then removes the `tuned-initrd.img` directory from `/tmp`. ==== + The [option]`skip_grub_config=VALUE` does not change grub configuration if `VALUE` is true. However, [option]`cmdline` options are still processed, and the result is used to verify the current cmdline. Only 'y', 'yes', 't', 'true' and '1' (case insensitive) are accepted as true values for this option. Other values are interpreted as false. + .Do not change grub configuration ==== ---- [bootloader] skip_grub_config=True cmdline=+systemd.cpu_affinity=1 ---- ==== c s6 t jjtj�stjd��tt| �j ||� t � | _d S )Nz4Required GRUB2 template not found, disabling plugin.)�os�path�isfile�constsZGRUB2_TUNED_TEMPLATE_PATHr ZNotSupportedPluginException�superr �__init__r �_cmd)�self�args�kwargs)� __class__� �'/usr/lib/python3.6/plugin_bootloader.pyr � s zBootloaderPlugin.__init__c C sV d|_ d|_d| _d| _d| _d | _d| _d| _| j� | _ | j � | _| j� d k | _ d S )NFT� )Z_has_dynamic_tuningZ_has_static_tuning�update_grub2_cfg�_skip_grub_config_val�_initrd_remove_dir�_initrd_dst_img_val�_cmdline_val�_initrd_val�_get_grub2_cfg_files�_grub2_cfg_file_names�_bls_enabled�_bls�_rpm_ostree_status�_rpm_ostree)r �instancer r r �_instance_init� s zBootloaderPlugin._instance_initc C s d S )Nr )r r# r r r �_instance_cleanup� s z"BootloaderPlugin._instance_cleanupc C s d d d d d d d d�S )N)�grub2_cfg_file�initrd_dst_img�initrd_add_img�initrd_add_dir�initrd_remove_dir�cmdline�skip_grub_configr )�clsr r r �_get_config_options� s z$BootloaderPlugin._get_config_optionsr c C s` i }|j � }xN| j � D ]B}||kr|j dd�}|j|d g �jt|�dkrR|d nd� qW |S )z� Returns dict created from options e.g.: _options_to_dict("A=A A=B A B=A C=A", "A=B B=A B=B") returns {'A': ['A', None], 'C': ['A']} �=r r N)�split� setdefault�append�len)�optionsZomit�d�oZarrr r r �_options_to_dict� s .z!BootloaderPlugin._options_to_dictc C s dj dd� | j� D ��S )N� c S s2 g | ]*\}}|D ]}|d k r(|d | n|�qqS )Nr/ r )�.0�k�vZv1r r r � <listcomp>� s z5BootloaderPlugin._dict_to_options.<locals>.<listcomp>)�join�items)r5 r r r �_dict_to_options� s z!BootloaderPlugin._dict_to_optionsc C sr | j jddgdd�\}}}tjd||f � |dkr8dS |j� }t|�dk sX|d d krjtjd | � dS |d S )zW Returns status of rpm-ostree transactions or None if not run on rpm-ostree system z rpm-ostreeZstatusT)� return_errz.rpm-ostree status output stdout: %s stderr: %sr N� zState:z2Exceptional format of rpm-ostree status result: %sr )r �execute�log�debugr0 r3 �warn)r �rc�out�errZsplitedr r r r! � s z#BootloaderPlugin._rpm_ostree_statusc C sF d}d}x(t |�D ]}| j� dkr&dS t|� qW | j� dkrBdS dS )N� g �?ZidleTF)�ranger! r )r Zsleep_cyclesZ sleep_secs�ir r r �_wait_till_idle s z BootloaderPlugin._wait_till_idlec s� | j jddgdd�\}}}tjd||f � |dkr8dS | j|�}| j� sXtjd� dS i }| j|�j� }x8|j � D ],\� } x| D ]} |� j | � q�W | |� <