<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css"
        integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
</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 \}}xd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rq<|
dks<|
dkrq<|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rd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rd}n>|	d	kr|rtj	t
j|  d
S d}n|rtjt
j|  d	S |d k	rt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   

