509318396
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
3
À<×eÌ  ã               @   sp   d dl jZddlmZ ddlT d dlmZmZ d dlZ	d dl
mZ d dlZe	jjƒ Zeƒ ZG dd„ dejƒZdS )	é    Né   )Úbase)Ú*)ÚPopenÚPIPE)Úcommandsc               @   st   e Zd ZdZedd„ ƒZdd„ Zedd„ ƒZdd	„ Zd
d„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zeddd�dd„ ƒZdS )ÚMountsPluginaP  
	`mounts`::
	
	Enables or disables barriers for mounts according to the value of the
	[option]`disable_barriers` option. The [option]`disable_barriers`
	option has an optional value `force` which disables barriers even
	on mountpoints with write back caches. Note that only extended file
	systems (ext) are supported by this plug-in.
	c             C   sø   i }d}t dddgttddd�jƒ \}}xÄdd„ |jƒ D ƒD ]®}t|ƒd	k rNq<|dd	… \}}}t|ƒd	krt|d	 nd}	t|ƒd
krŒ|d
 nd}
|dkrž|}q<|dks<|dkr°q<|
dks<|
dkrÂq<|j|
tƒ ||	dœƒ ||
 d j|ƒ q<W || _dS )zÁ
		Gets the information about disks, partitions and mountpoints. Stores information about used filesystem and
		creates a list of all underlying devices (in case of LVM) for each mountpoint.
		NZlsblkz-rnozTYPE,RM,KNAME,FSTYPE,MOUNTPOINTT)ÚstdoutÚstderrZ	close_fdsZuniversal_newlinesc             S   s   g | ]}|j ƒ ‘qS © )Úsplit)Ú.0Úliner   r   ú#/usr/lib/python3.6/plugin_mounts.pyú
<listcomp>$   s    z>MountsPlugin._generate_mountpoint_topology.<locals>.<listcomp>é   é   ZdiskÚ1ÚpartÚlvmz[SWAP])ÚdisksÚdevice_nameÚ
filesystemr   )r   r   )	r   r   ZcommunicateÚ
splitlinesÚlenÚ
setdefaultÚsetÚaddÚ_mountpoint_topology)ÚclsZmountpoint_topologyZcurrent_diskr	   r
   ÚcolumnsZdevice_typeZdevice_removabler   r   Ú
mountpointr   r   r   Ú_generate_mountpoint_topology   s,    z*MountsPlugin._generate_mountpoint_topologyc             C   s*   | j ƒ  d| _t| jjƒ ƒ| _tƒ | _d S )NT)r"   Z_devices_supportedr   r   ÚkeysZ_free_devicesZ_assigned_devices)Úselfr   r   r   Ú_init_devices;   s    zMountsPlugin._init_devicesc             C   s   dd iS )NÚdisable_barriersr   )r$   r   r   r   Ú_get_config_optionsA   s    z MountsPlugin._get_config_optionsc             C   s   d|_ d|_d S )NFT)Z_has_dynamic_tuningZ_has_static_tuning)r$   Úinstancer   r   r   Ú_instance_initG   s    zMountsPlugin._instance_initc             C   s   d S )Nr   )r$   r(   r   r   r   Ú_instance_cleanupK   s    zMountsPlugin._instance_cleanupc             C   s,   t j d| ƒ}x|D ]}tj|ƒjƒ S W dS )zV
		Get device cache type. This will work only for devices on SCSI kernel subsystem.
		z+/sys/block/%s/device/scsi_disk/*/cache_typeN)ÚglobÚcmdZ	read_fileÚstrip)r$   ÚdeviceZsource_filenamesZsource_filenamer   r   r   Ú_get_device_cache_typeN   s    
z#MountsPlugin._get_device_cache_typec             C   s.   x(| j | d D ]}| j|ƒdkrdS qW dS )zr
		Checks if the device has 'write back' cache. If the cache type cannot be determined, asume some other cache.
		r   z
write backTF)r   r/   )r$   r!   r.   r   r   r   Ú_mountpoint_has_writeback_cacheW   s    z,MountsPlugin._mountpoint_has_writeback_cachec             C   s®   t dƒ�H}x@|D ]4}|jƒ }|d d dkr.q|d |kr|d }P qW dS W dQ R X |jdƒ}xH|D ]<}|jdƒ\}}	}
|d	ks’|d
kr–|
dkr–dS |d
krfdS qfW dS dS )zP
		Checks if a given mountpoint is mounted with barriers enabled or disabled.
		z/proc/mountsr   ú/r   r   Nú,ú=Z	nobarrierZbarrierÚ0FT)Úopenr   Ú	partition)r$   r!   Zmounts_filer   r    Zoption_listÚoptionsZoptionÚnameÚsepÚvaluer   r   r   Ú_mountpoint_has_barriers`   s"    



z%MountsPlugin._mountpoint_has_barriersc             C   s   d|dd| g}t j|ƒ dS )z
		Remounts partition.
		z/usr/bin/mountz-oz
remount,%sN)r,   Zexecute)r$   r6   r7   Zremount_commandr   r   r   Ú_remount_partition}   s    zMountsPlugin._remount_partitionr&   T)Z
per_devicec       
      C   sZ  | j d|d�}t|ƒjƒ dk}|p*| j|ƒ}|�r|s:d S d }| j| d jdƒsXd}nl| rn| j|ƒrnd}nV| j|ƒ}	|	d kr†d}n>|	d	kr¬|r¦tj	t
j| ƒ d
S d}n|rÄtjt
j| ƒ d	S |d k	râtj	d||f ƒ d S | jj||	ƒ tj	d| ƒ | j|dƒ nJ|�rd S | jj|ƒ}	|	d k�r0d S tj	d| ƒ | j|dƒ | jj|ƒ d S )Nr&   )Zcommand_namer   Úforcer   Zextzfilesystem not supportedzdevice uses write back cachezunknown current settingFTzbarriers already disabledz#not disabling barriers on '%s' (%s)zdisabling barriers on '%s'z	barrier=0zenabling barriers on '%s'z	barrier=1)Z_storage_keyÚstrÚlowerZ_option_boolr   Ú
startswithr0   r;   ÚlogÚinfoÚconstsZSTR_VERIFY_PROFILE_OKÚerrorZSTR_VERIFY_PROFILE_FAILZ_storager   r<   ÚgetZunset)
r$   Ústartr:   r!   ZverifyZignore_missingZstorage_keyr=   Zreject_reasonÚoriginal_valuer   r   r   Ú_disable_barriers„   sN    

zMountsPlugin._disable_barriersN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úclassmethodr"   r%   r'   r)   r*   r/   r0   r;   r<   Zcommand_customrH   r   r   r   r   r      s   	$		r   )Ztuned.constsrC   Ú r   Z
decoratorsÚ
subprocessr   r   Z
tuned.logsZtunedZtuned.utils.commandsr   r+   ZlogsrE   rA   r,   ZPluginr   r   r   r   r   Ú<module>   s   

