VULN_CHECK_I913V6 Gi"ddlmZddlddlZddlZddlZddlZddlZddl m Z ejjZ e ZGddejZy))base)*N)commandsceZdZdZedZedZedZdZ dZ edZ e dd Z e d d Zedd Zed d Ze ddZeddZdZdZdZeddZeddZeddZeddZdZy)VMPlugina Tunes selected sysctl options in `/proc/sys/vm`, currently [option]`dirty_ratio`, [option]`dirty_background_ratio`, [option]`dirty_bytes`, and [option]`dirty_background_bytes`. See https://docs.kernel.org/admin-guide/sysctl/vm.html for detailed documentation of these options. Additionaly enables or disables transparent huge pages depending on the value of the [option]`transparent_hugepages` option. The option can have one of three possible values: `always`, `madvise` and `never`. .Disable transparent hugepages ==== ---- [vm] transparent_hugepages=never ---- ==== The [option]`transparent_hugepage.defrag` option specifies the defragmentation policy. Possible values for this option are `always`, `defer`, `defer+madvise`, `madvise` and `never`. For a detailed explanation of these values refer to link:https://www.kernel.org/doc/Documentation/vm/transhuge.txt[Transparent Hugepage Support]. cddddddddS)N)transparent_hugepagestransparent_hugepagetransparent_hugepage.defrag dirty_bytes dirty_ratiodirty_background_bytesdirty_background_ratio)selfs s8 $(!&(''-O''2JLdercyNrr's r_instance_cleanupzVMPlugin._instance_cleanupDsrcLd}tjj|sd}|S)Nz#/sys/kernel/mm/transparent_hugepagez*/sys/kernel/mm/redhat_transparent_hugepage)rr exists)rr s r _thp_pathzVMPlugin._thp_pathGs! .$   74 +rr c|dvr$|s!tjdt|zytj dd}|j ddkDr|stj dytjj|jd }tjj|r/|s+tj|||rtjgnd |S|stjd y) N)alwaysnevermadvisez-Incorrect 'transparent_hugepages' value '%s'.z /proc/cmdlineTno_errorztransparent_hugepage=rzWtransparent_hugepage is already set in kernel boot cmdline, ignoring value from profileenabledFzDOption 'transparent_hugepages' is not supported on current hardware.)rrstrcmd read_filefindinforr r!r.r- write_to_fileerrnoENOENT)rvaluersimremovecmdlinesys_files r_set_transparent_hugepagesz#VMPlugin._set_transparent_hugepagesOs 00 KK?#e*LM  MM/dM ;' \\)*Q. HH fg  WW\\$..*I 6(WW^^H h"(e5 < KKVW rr c,|j||||yr*)rC)rr>rr?r@s r_set_transparent_hugepagez"VMPlugin._set_transparent_hugepagehs!!%3?rctjj|jd}tjj |r(t j t j|Sy)Nr5rr r!r.r-r7get_active_optionr8rrrBs r_get_transparent_hugepagesz#VMPlugin._get_transparent_hugepageslsJ WW\\$..*I 6(WW^^H   h 7 88 rc$|j|Sr*)rJr's r_get_transparent_hugepagez"VMPlugin._get_transparent_hugepageus ( ( 22rr c*tjj|jd}tjj |r/|s+t j |||rtjgnd|S|stjdy)NdefragFr3zJOption 'transparent_hugepage.defrag' is not supported on current hardware.) rr r!r.r-r7r;r<r=rr)rr>rr?r@rBs r _set_transparent_hugepage_defragz)VMPlugin._set_transparent_hugepage_defragysl WW\\$..*H 5(WW^^H h"(e5 < KK\] rctjj|jd}tjj |r(t j t j|Sy)NrNrGrIs r _get_transparent_hugepage_defragz)VMPlugin._get_transparent_hugepage_defragsJ WW\\$..*H 5(WW^^H   h 7 88 rcdttjdz}||krtj d|d|dyy)NPAGESIZEzThe value of 'z(' must be at least twice the page size (z).FT)intr7getconfrerror)rr" int_value min_bytess r_check_twice_pagesizezVMPlugin._check_twice_pagesizes:#ckk*-..)99vW` ab  rc@|dkrtjd|zyy)Nrz#The value of '%s' must be positive.FTrrWrr"rXs r_check_positivezVMPlugin._check_positives!!^99 2V ;<  rcPd|cxkrdksntjd|zyy)Nrdz,The value of '%s' must be between 0 and 100.FTr\r]s r _check_ratiozVMPlugin._check_ratios' i 3 99 ;f DE  rr c |\|jjdr=|jdd|j||jj d|S|jdd|j |||S)N%rr )stripendswith _dirty_optionrarstriprZrenablingr>verifyignore_missingrs r _dirty_byteszVMPlugin._dirty_bytessw 5;;=11#6   ]M4;L;LhX]XcXcXeXlXlmpXqsy zz  M=$:T:TV^`egm nnrrcltjd|jdd|j|||S)NzlThe 'dirty_ratio' option is deprecated and does not support inheritance, use 'dirty_bytes' with '%' instead.rr rrrfrarhs r _dirty_ratiozVMPlugin._dirty_ratios2++|}  M=$:K:KXW\^d eerrc |\|jjdr=|jdd|j||jj d|S|jdd|j |||S)Nrcrr)rdrerfrargr^rhs r_dirty_background_bytesz VMPlugin._dirty_background_bytess 5;;=11#6   57OQUQbQbdlnsnynyn{oCoCDGoHJP QQ  46NPTPdPdfnpuw} ~~rrcltjd|jdd|j|||S)NzThe 'dirty_background_ratio' option is deprecated and does not support inheritance, use 'dirty_background_bytes' with '%' instead.rrrnrhs r_dirty_background_ratioz VMPlugin._dirty_background_ratios<++ST  46NPTPaPackmrtz {{rc|j|}|j|}|j|} |j|} tjj |st j d|ztj|j} |r| |k(S|r t|} ||| sy| |k(rt jd|d|d|St| dk(r@tj|j} |jj| | n|jj| | t jd|d|d tj!|||S|jj#| }|jj#| }|3t jd|d|d tj!||y|3t jd|d|d tj!||yt jd |zy#t$rt jd|zYywxYw) N) command_namez5Option '%s' is not supported on the current hardware.z%The value of '%s' must be an integer.zNot setting option 'z' to 'z', already set.rzSetting option 'z'.'z:Not restoring '%s', previous value is the same or unknown.)r# _storage_keyrr isfilerrr7r8rdrU ValueErrorrWr:_storagesetr;get)rr" counterpart check_funrir>rj option_pathcounterpart_path option_keycounterpart_key current_valuerXcurrent_counterpart_value old_valueold_counterpart_values rrfzVMPlugin._dirty_options --f5+22;?  f 5*%%;%?/  $;;FOP-- ,224- 5   E I FI & uHH NO L -A # .> ? E E GMMo'@AMMj-088fe <=[%( <mm +)--++O<88VY ?@[),  (88[:O PQ%'<= 88 H6 QR A II5>? s+ H::!IIN)__name__ __module__ __qualname____doc__ classmethodr staticmethodrr#r(r+r. command_setrCrE command_getrJrLrOrQrZr^racommand_customrlrorqrsrfrrrrrs4  jj..f %&'0$%@&@%&'$%3&3+, - +,-  o o f f)*+ )*|+|-rr)r decorators tuned.logstunedrr<structglobtuned.utils.commandsrlogsr|rr7PluginrrrrrsF ) jjnnjVt{{Vr