Your IP : 13.58.211.135


Current Path : /usr/lib/python3.6/site-packages/tuned/plugins/__pycache__/
Upload File :
Current File : //usr/lib/python3.6/site-packages/tuned/plugins/__pycache__/plugin_mounts.cpython-36.pyc

3

�<�e��@spddljZddlmZddlTddlmZmZddlZ	ddl
mZddlZe	j
j�Ze�ZGdd�dej�ZdS)	�N�)�base)�*)�Popen�PIPE)�commandsc@steZdZdZedd��Zdd�Zedd��Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
eddd�dd��ZdS)�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.
	cCs�i}d}tdddgttddd�j�\}}x�dd�|j�D�D]�}t|�d	krNq<|dd	�\}}}t|�d	krt|d	nd}	t|�d
kr�|d
nd}
|dkr�|}q<|dks<|dkr�q<|
dks<|
dkr�q<|j|
t�||	d��||
dj|�q<W||_dS)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.
		NZlsblkz-rnozTYPE,RM,KNAME,FSTYPE,MOUNTPOINTT)�stdout�stderrZ	close_fdsZuniversal_newlinescSsg|]}|j��qS�)�split)�.0�linerr�#/usr/lib/python3.6/plugin_mounts.py�
<listcomp>$sz>MountsPlugin._generate_mountpoint_topology.<locals>.<listcomp>��Zdisk�1�part�lvmz[SWAP])�disks�device_name�
filesystemr)rr)	rrZcommunicate�
splitlines�len�
setdefault�set�add�_mountpoint_topology)�clsZmountpoint_topologyZcurrent_diskr	r
�columnsZdevice_typeZdevice_removablerr�
mountpointrrr�_generate_mountpoint_topologys,z*MountsPlugin._generate_mountpoint_topologycCs*|j�d|_t|jj��|_t�|_dS)NT)r"Z_devices_supportedrr�keysZ
_free_devicesZ_assigned_devices)�selfrrr�
_init_devices;szMountsPlugin._init_devicescCsddiS)N�disable_barriersr)r$rrr�_get_config_optionsAsz MountsPlugin._get_config_optionscCsd|_d|_dS)NFT)Z_has_dynamic_tuningZ_has_static_tuning)r$�instancerrr�_instance_initGszMountsPlugin._instance_initcCsdS)Nr)r$r(rrr�_instance_cleanupKszMountsPlugin._instance_cleanupcCs,tjd|�}x|D]}tj|�j�SWdS)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$�deviceZsource_filenamesZsource_filenamerrr�_get_device_cache_typeNs
z#MountsPlugin._get_device_cache_typecCs.x(|j|dD]}|j|�dkrdSqWdS)zr
		Checks if the device has 'write back' cache. If the cache type cannot be determined, asume some other cache.
		rz
write backTF)rr/)r$r!r.rrr�_mountpoint_has_writeback_cacheWsz,MountsPlugin._mountpoint_has_writeback_cachecCs�td��H}x@|D]4}|j�}|dddkr.q|d|kr|d}PqWdSWdQRX|jd�}xH|D]<}|jd�\}}	}
|d	ks�|d
kr�|
dkr�dS|d
krfd
SqfWd
SdS)zP
		Checks if a given mountpoint is mounted with barriers enabled or disabled.
		z/proc/mountsr�/rrN�,�=Z	nobarrierZbarrier�0FT)�openr�	partition)r$r!Zmounts_filerr Zoption_list�optionsZoption�name�sep�valuerrr�_mountpoint_has_barriers`s"



z%MountsPlugin._mountpoint_has_barrierscCsd|dd|g}tj|�dS)z
		Remounts partition.
		z/usr/bin/mountz-oz
remount,%sN)r,Zexecute)r$r6r7Zremount_commandrrr�_remount_partition}szMountsPlugin._remount_partitionr&T)Z
per_devicec
CsZ|jd|d�}t|�j�dk}|p*|j|�}|�r|s:dSd}|j|djd�sXd}nl|rn|j|�rnd}nV|j|�}	|	dkr�d}n>|	d	kr�|r�tj	t
j|�d
Sd}n|r�tjt
j
|�d	S|dk	r�tj	d||f�dS|jj||	�tj	d
|�|j|d�nJ|�rdS|jj|�}	|	dk�r0dStj	d|�|j|d�|jj|�dS)Nr&)Zcommand_namer�forcerZextzfilesystem not supportedzdevice uses write back cachezunknown current settingFTzbarriers already disabledz#not disabling barriers on '%s' (%s)zdisabling barriers on '%s'z	barrier=0zenabling barriers on '%s'z	barrier=1)Z_storage_key�str�lowerZ_option_boolr�
startswithr0r;�log�info�constsZSTR_VERIFY_PROFILE_OK�errorZSTR_VERIFY_PROFILE_FAILZ_storagerr<�getZunset)
r$�startr:r!ZverifyZignore_missingZstorage_keyr=Z
reject_reason�original_valuerrr�_disable_barriers�sN

zMountsPlugin._disable_barriersN)�__name__�
__module__�__qualname__�__doc__�classmethodr"r%r'r)r*r/r0r;r<Zcommand_customrHrrrrrs	$		r)Ztuned.constsrC�rZ
decorators�
subprocessrrZ
tuned.logsZtunedZtuned.utils.commandsrr+ZlogsrErAr,ZPluginrrrrr�<module>s



?>