a
Á]›ià ã @ sr d dl mZ ddlmZ ddlT d dlmZmZ d dlZ d dl
mZ d dlZe j
¡ Zeƒ ZG dd„ dejƒZdS ) é Né )Úbase)Ú*)ÚPopenÚPIPE)Úcommandsc @ st e Zd ZdZedd„ ƒZdd„ Zedd„ ƒZdd „ Zd
d„ Z dd
„ Z
dd„ Zdd„ Zdd„ Z
eddddd„ ƒZdS )ÚMountsPlugina=
Enables or disables barriers for mounts according to the value of the
boolean option [option]`disable_barriers`. The option additionally allows
the special value `force`, which disables barriers even on mountpoints with
write back caches.
NOTE: Only extended file systems (ext) are supported by this plug-in.
c C sò i }d}t g d¢ttddd ¡ \}}dd„ | ¡ D ƒD ]®}t|ƒdk rJq8|dd… \}}}t|ƒdkrp|d nd} t|ƒdkrˆ|d nd}
|d krš|}q8|d
ks8|dvr¬q8|
du s8|
dkr¾q8| |
tƒ || d
œ¡ ||
d |¡ q8|| _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.
N)Zlsblkz-rnozTYPE,RM,KNAME,FSTYPE,MOUNTPOINTT)ÚstdoutÚstderrZ close_fdsZuniversal_newlinesc S s g | ]}| ¡ ‘qS © )Úsplit)Ú.0Úliner r ú?/usr/lib/python3.9/site-packages/tuned/plugins/plugin_mounts.pyÚ
# ó z>MountsPlugin._generate_mountpoint_topology..é é ZdiskÚ1)ÚpartZlvmz[SWAP])ÚdisksÚdevice_nameÚ
filesystemr ) r r ZcommunicateÚ
splitlinesÚlenÚ
setdefaultÚsetÚaddÚ_mountpoint_topology)ÚclsZmountpoint_topologyZcurrent_diskr r
ÚcolumnsZdevice_typeZdevice_removabler r Ú
mountpointr r r Ú_generate_mountpoint_topology s, ýz*MountsPlugin._generate_mountpoint_topologyc C s* | ¡ d| _t| j ¡ ƒ| _tƒ | _d S )NT)r" Z_devices_supportedr r ÚkeysZ
_free_devicesZ_assigned_devices©Úselfr r r Ú
_init_devices: s zMountsPlugin._init_devicesc C s dd iS )NÚdisable_barriersr r$ r r r Ú_get_config_options@ 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_initF s zMountsPlugin._instance_initc C s d S )Nr r) r r r Ú_instance_cleanupJ s zMountsPlugin._instance_cleanupc C s, t d| ¡}|D ]}t |¡ ¡ S dS )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_filenamer r r Ú_get_device_cache_typeM s z#MountsPlugin._get_device_cache_typec C s, | j | d D ]}| |¡dkr dS qdS )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 r1 )r% r! r0 r r r Ú_mountpoint_has_writeback_cacheV s z,MountsPlugin._mountpoint_has_writeback_cachec C sÈ t dƒ\}|D ]6}| ¡ }|d d dkr,q|d |kr|d } qVqW d ƒ dS W d ƒ n1 sj0 Y | d¡}|D ]@}| d¡\}} }
|d ks®|d
kr´|
dkr´ dS |d
kr‚ d
S q‚d
S )zP
Checks if a given mountpoint is mounted with barriers enabled or disabled.
z/proc/mountsr ú/r r Nú,ú=Z nobarrierZbarrierÚ0FT)Úopenr Ú partition)r% r! Zmounts_filer r Zoption_listÚoptionsÚoptionÚnameÚsepÚvaluer r r Ú_mountpoint_has_barriers_ s"
.
z%MountsPlugin._mountpoint_has_barriersc C s d|dd| g}t |¡ dS )z
Remounts partition.
z/usr/bin/mountz-oz
remount,%sN)r. Zexecute)r% r8 r9 Zremount_commandr r r Ú_remount_partition| s zMountsPlugin._remount_partitionr' T)Z
per_devicec C sX | j d|d}t|ƒ ¡ dk}|p*| |¡}|r
|s:d S d } | j| d d¡sXd} nj|sl| |¡rld} nV| |¡}
|
d u r„d} n>|
d krª|r¤t t
j| ¡ d
S d} n|rÂt t
j
| ¡ d S | d uràt d|| f ¡ d S | j ||
¡ t d
| ¡ | |d¡ nJ|rd S | j |¡}
|
d u r.d S t d| ¡ | |d¡ | j |¡ d S )Nr' )Zcommand_namer Úforcer Úextzfilesystem 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 Ú
startswithr2 r> ÚlogÚinfoÚconstsZSTR_VERIFY_PROFILE_OKÚerrorZSTR_VERIFY_PROFILE_FAILZ_storager r? ÚgetZunset)r% Ústartr= r! ZverifyZignore_missingr* Zstorage_keyr@ Z
reject_reasonÚoriginal_valuer r r Ú_disable_barriersƒ sP þ
zMountsPlugin._disable_barriersN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úclassmethodr" r&