3 À<×eÌã@spddljZddlmZddlTddlmZmZddlZ ddl m Z ddl Z e j 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 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. c Csøi}d}tdddgttddd�jƒ\}}xÄdd„|jƒDƒD]®}t|ƒd krNq<|dd …\}}}t|ƒd krt|d nd} t|ƒd krŒ|d nd} |d krž|}q<|d ks<|dkr°q<| dks<| dkrÂq<|j| tƒ|| dœƒ|| dj|ƒq$sz>MountsPlugin._generate_mountpoint_topology..ééZdiskÚ1ÚpartÚlvmz[SWAP])ÚdisksÚ device_nameÚ filesystemr)rr) 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*|jƒd|_t|jjƒƒ|_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_optionsAsz MountsPlugin._get_config_optionscCsd|_d|_dS)NFT)Z_has_dynamic_tuningZ_has_static_tuning)r$Úinstancer r rÚ_instance_initGszMountsPlugin._instance_initcCsdS)Nr )r$r(r r rÚ_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_filenamer r rÚ_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.r r rÚ_mountpoint_has_writeback_cacheWsz,MountsPlugin._mountpoint_has_writeback_cachec Cs®tdƒ�H}x@|D]4}|jƒ}|dddkr.q|d|kr|d}PqWdSWdQRX|jdƒ}xH|D]<}|jdƒ\}} } |d ks’|d kr–| d kr–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!Z mounts_filerr Z option_listÚoptionsZoptionÚnameÚsepÚvaluer r rÚ_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_commandr r rÚ_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_missingZ storage_keyr=Z reject_reasonÚoriginal_valuer r rÚ_disable_barriers„sN     zMountsPlugin._disable_barriersN)Ú__name__Ú __module__Ú __qualname__Ú__doc__Ú classmethodr"r%r'r)r*r/r0r;r<Zcommand_customrHr r r rr s  $   r)Z tuned.constsrCÚrZ decoratorsÚ subprocessrrZ tuned.logsZtunedZtuned.utils.commandsrr+ZlogsrErAr,ZPluginrr r r rÚs