3 À<×e ã @ sd d dl Z d dlZddlmZ ddlT d dlZd dlmZ d dl m Z ejjƒ Z G dd„ dejƒZdS ) é Né )Úbase)Ú*)Ú exceptions)Úcommandsc sh e Zd ZdZedd„ ƒZ‡ fdd„Zedd„ ƒZdd „ Zd d„ Z e dƒd d„ ƒZedƒdd„ ƒZ ‡ ZS )Ú SelinuxPlugina° `selinux`:: Plug-in for tuning SELinux options. + SELinux decisions, such as allowing or denying access, are cached. This cache is known as the Access Vector Cache (AVC). When using these cached decisions, SELinux policy rules need to be checked less, which increases performance. The [option]`avc_cache_threshold` option allows adjusting the maximum number of AVC entries. + NOTE: Prior to changing the default value, evaluate the system performance with care. Increasing the value could potentially decrease the performance by making AVC slow. + .Increase the AVC cache threshold for hosts with containers. ==== ---- [selinux] avc_cache_threshold=8192 ---- ==== c C s( d}t jj|ƒs$d}t jj|ƒs$d }|S )Nz/sys/fs/selinuxz/selinux)ÚosÚpathÚexists)Úselfr © r ú$/usr/lib/python3.6/plugin_selinux.pyÚ_get_selinux_path$ s zSelinuxPlugin._get_selinux_pathc sP t ƒ | _| jƒ | _| jd kr&tjdƒ‚tjj| jddƒ| _ t t| ƒj||Ž d S )NzFSELinux is not enabled on your system or incompatible version is used.ZavcZcache_threshold) r Ú_cmdr Z _selinux_pathr ZNotSupportedPluginExceptionr r ÚjoinÚ_cache_threshold_pathÚsuperr Ú__init__)r ÚargsÚkwargs)Ú __class__r r r - s zSelinuxPlugin.__init__c C s dd iS )NÚavc_cache_thresholdr )r r r r Ú_get_config_options5 s z!SelinuxPlugin._get_config_optionsc C s d|_ d|_d S )NTF)Z_has_static_tuningZ_has_dynamic_tuning)r Úinstancer r r Ú_instance_init; s zSelinuxPlugin._instance_initc C s d S )Nr )r r r r r Ú_instance_cleanup? s zSelinuxPlugin._instance_cleanupr c C sL |d krd S t |ƒ}|dkrD|s@| jj| j||r8tjgndd |S d S d S )Nr F)Zno_error)Úintr Z write_to_filer ÚerrnoÚENOENT)r ÚvalueZsimÚremoveZ thresholdr r r Ú_set_avc_cache_thresholdB s z&SelinuxPlugin._set_avc_cache_thresholdc C s&