a ”ˆ«hÃã@srddlmZddlmZddlTddlmZmZddlZ ddl m Z ddl Z e j  ¡Ze ƒZGdd„dejƒZdS) éNé)Úbase)Ú*)ÚPopenÚPIPE)Úcommandsc@steZdZdZedd„ƒZdd„Zedd„ƒZdd „Zd d „Z d d „Z dd„Z dd„Z dd„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 Csòi}d}tgd¢ttddd ¡\}}dd„| ¡DƒD]®}t|ƒdkrJq8|dd…\}}}t|ƒdkrp|dnd} t|ƒdkrˆ|dnd} |d krš|}q8|d ks8|d vr¬q8| dus8| d kr¾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_newlinescSsg|] }| ¡‘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) rrZ communicateÚ splitlinesÚlenÚ setdefaultÚsetÚaddÚ_mountpoint_topology) ÚclsZmountpoint_topologyZ current_diskr r ÚcolumnsZ device_typeZdevice_removablerrÚ mountpointr r rÚ_generate_mountpoint_topologys,ý z*MountsPlugin._generate_mountpoint_topologycCs*| ¡d|_t|j ¡ƒ|_tƒ|_dS)NT)r"Z_devices_supportedrrÚkeysZ _free_devicesZ_assigned_devices©Úselfr r rÚ _init_devices:szMountsPlugin._init_devicescCsddiS)NÚdisable_barriersr r$r r rÚ_get_config_options@sÿz MountsPlugin._get_config_optionscCsd|_d|_dS)NFT)Z_has_dynamic_tuningZ_has_static_tuning©r%Úinstancer r rÚ_instance_initFszMountsPlugin._instance_initcCsdS)Nr r)r r rÚ_instance_cleanupJszMountsPlugin._instance_cleanupcCs,t d|¡}|D]}t |¡ ¡SdS)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_typeMsz#MountsPlugin._get_device_cache_typecCs,|j|dD]}| |¡dkrdSqdS)zr Checks if the device has 'write back' cache. If the cache type cannot be determined, asume some other cache. rz write backTF)rr1)r%r!r0r r rÚ_mountpoint_has_writeback_cacheVsz,MountsPlugin._mountpoint_has_writeback_cachec CsÈtdƒ\}|D]6}| ¡}|dddkr,q|d|kr|d}qVqWdƒdSWdƒn1sj0Y| d¡}|D]@}| d¡\}} } |d ks®|d kr´| d kr´d S|d kr‚d Sq‚d S)zP Checks if a given mountpoint is mounted with barriers enabled or disabled. z /proc/mountsrú/rrNú,ú=Z nobarrierZbarrierÚ0FT)Úopenr Ú partition) r%r!Z mounts_filerr Z option_listÚoptionsÚoptionÚnameÚsepÚvaluer r rÚ_mountpoint_has_barriers_s"  . z%MountsPlugin._mountpoint_has_barrierscCsd|dd|g}t |¡dS)z Remounts partition. z/usr/bin/mountz-oz remount,%sN)r.Zexecute)r%r8r9Zremount_commandr r rÚ_remount_partition|szMountsPlugin._remount_partitionr'T)Z per_devicec CsX|jd|d}t|ƒ ¡dk}|p*| |¡}|r |s:dSd} |j|d d¡sXd} nj|sl| |¡rld} nV| |¡} | dur„d} n>| d krª|r¤t  t j |¡d Sd } n|rÂt  t j |¡d S| duràt  d || f¡dS|j || ¡t  d |¡| |d¡nJ|rdS|j |¡} | dur.dSt  d|¡| |d¡|j |¡dS)Nr')Z command_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Ú startswithr2r>ÚlogÚinfoÚconstsZSTR_VERIFY_PROFILE_OKÚerrorZSTR_VERIFY_PROFILE_FAILZ_storagerr?ÚgetZunset) r%Ústartr=r!ZverifyZignore_missingr*Z storage_keyr@Z reject_reasonÚoriginal_valuer r rÚ_disable_barriersƒsPþ     zMountsPlugin._disable_barriersN)Ú__name__Ú __module__Ú __qualname__Ú__doc__Ú classmethodr"r&r(r+r,r1r2r>r?Zcommand_customrLr r r rr s  #    r)Z tuned.constsrGÚrZ decoratorsÚ subprocessrrZ tuned.logsZtunedZtuned.utils.commandsrr-ZlogsrIrEr.ZPluginrr r r rÚs