ó
æ”\c           @   sœ   d  d l  j Z d d l m Z d d l Td  d l m Z m Z d  d l Z	 d  d l
 m Z d  d l Z e	 j j ƒ  Z e ƒ  Z d e j f d „  ƒ  YZ d S(	   iÿÿÿÿNi   (   t   base(   t   *(   t   Popent   PIPE(   t   commandst   MountsPluginc           B   s†   e  Z d  Z e d „  ƒ Z d „  Z e d „  ƒ Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z e d
 d e ƒd „  ƒ Z RS(   s.   
	Plugin for tuning options of mount-points.
	c      
   C   s‚  i  } d } t d d d g d t d t d t d t ƒj ƒ  \ } } x-g  | j ƒ  D] } | j ƒ  ^ qU D]} t | ƒ d k  r‰ qk n  | d  \ } } }	 t | ƒ d k r¸ | d n d }
 t | ƒ d	 k rÚ | d	 n d } | d
 k rø |	 } qk n  | d k sk | d k rqk n  | d k sk | d k r4qk n  | j | i t	 ƒ  d 6|	 d 6|
 d 6ƒ | | d j
 | ƒ qk W| |  _ d S(   sÁ   
		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.
		t   lsblks   -rnos   TYPE,RM,KNAME,FSTYPE,MOUNTPOINTt   stdoutt   stderrt	   close_fdst   universal_newlinesi   i   t   diskt   1t   partt   lvms   [SWAP]t   diskst   device_namet
   filesystemN(   R   R   (   t   NoneR   R   t   Truet   communicatet
   splitlinest   splitt   lent
   setdefaultt   sett   addt   _mountpoint_topology(   t   clst   mountpoint_topologyt   current_diskR   R   t   linet   columnst   device_typet   device_removableR   R   t
   mountpoint(    (    s?   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_mounts.pyt   _generate_mountpoint_topology   s,    		,""(c         C   s;   |  j  ƒ  t |  _ t |  j j ƒ  ƒ |  _ t ƒ  |  _ d  S(   N(   R$   R   t   _devices_supportedR   R   t   keyst   _free_devicest   _assigned_devices(   t   self(    (    s?   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_mounts.pyt   _init_devices5   s    
	c         C   s   i d  d 6S(   Nt   disable_barriers(   R   (   R)   (    (    s?   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_mounts.pyt   _get_config_options;   s    c         C   s   t  | _ t | _ d  S(   N(   t   Falset   _has_dynamic_tuningR   t   _has_static_tuning(   R)   t   instance(    (    s?   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_mounts.pyt   _instance_initA   s    	c         C   s   d  S(   N(    (   R)   R0   (    (    s?   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_mounts.pyt   _instance_cleanupE   s    c         C   s8   t  j  d | ƒ } x | D] } t j | ƒ j ƒ  SWd S(   sV   
		Get device cache type. This will work only for devices on SCSI kernel subsystem.
		s+   /sys/block/%s/device/scsi_disk/*/cache_typeN(   t   globt   cmdt	   read_filet   stripR   (   R)   t   devicet   source_filenamest   source_filename(    (    s?   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_mounts.pyt   _get_device_cache_typeH   s    c         C   s9   x2 |  j  | d D] } |  j | ƒ d k r t Sq Wt S(   sr   
		Checks if the device has 'write back' cache. If the cache type cannot be determined, asume some other cache.
		R   s
   write back(   R   R:   R   R-   (   R)   R#   R7   (    (    s?   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_mounts.pyt   _mountpoint_has_writeback_cacheQ   s    c         C   sæ   t  d ƒ ` } xV | D]J } | j ƒ  } | d d d k rB q n  | d | k r | d } Pq q Wd SWd QX| j d ƒ } xb | D]V } | j d ƒ \ } }	 }
 | d	 k sÆ | d
 k rÊ |
 d k rÊ t S| d
 k r„ t Sq„ Wt Sd S(   sP   
		Checks if a given mountpoint is mounted with barriers enabled or disabled.
		s   /proc/mountsi    t   /i   i   Nt   ,t   =t	   nobarriert   barriert   0(   t   openR   R   t	   partitionR-   R   (   R)   R#   t   mounts_fileR   R    t   option_listt   optionst   optiont   namet   sept   value(    (    s?   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_mounts.pyt   _mountpoint_has_barriersZ   s"    

$c         C   s'   d | d d | g } t  j | ƒ d S(   s   
		Remounts partition.
		s   /usr/bin/mounts   -os
   remount,%sN(   R4   t   execute(   R)   RC   RF   t   remount_command(    (    s?   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_mounts.pyt   _remount_partitionw   s    R+   t
   per_devicec   
      C   sÑ  |  j  d d d | ƒ } t | ƒ j ƒ  d k } | pB |  j | ƒ } | rp| sU d  Sd  } |  j | d j d ƒ s~ d } n” | r |  j | ƒ r d } nu |  j | ƒ }	 |	 d  k rÁ d	 } nQ |	 t	 k rô | rë t
 j t j | ƒ t Sd
 } n | rt
 j t j | ƒ t	 S| d  k	 r9t
 j d | | f ƒ d  S|  j j | |	 ƒ t
 j d | ƒ |  j | d ƒ n] | rzd  S|  j j | ƒ }	 |	 d  k rœd  St
 j d | ƒ |  j | d ƒ |  j j | ƒ d  S(   Nt   command_nameR+   R   t   forceR   t   exts   filesystem not supporteds   device uses write back caches   unknown current settings   barriers already disableds#   not disabling barriers on '%s' (%s)s   disabling barriers on '%s's	   barrier=0s   enabling barriers on '%s's	   barrier=1(   t   _storage_keyt   strt   lowert   _option_boolR   R   t
   startswithR;   RK   R-   t   logt   infot   constst   STR_VERIFY_PROFILE_OKR   t   errort   STR_VERIFY_PROFILE_FAILt   _storageR   RN   t   gett   unset(
   R)   t   startRJ   R#   t   verifyt   ignore_missingt   storage_keyRQ   t   reject_reasont   original_value(    (    s?   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_mounts.pyt   _disable_barriers~   sN    						(   t   __name__t
   __module__t   __doc__t   classmethodR$   R*   R,   R1   R2   R:   R;   RK   RN   t   command_customR   Rg   (    (    (    s?   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_mounts.pyR      s   $									(   t   tuned.constsRZ   t    R    t
   decoratorst
   subprocessR   R   t
   tuned.logst   tunedt   tuned.utils.commandsR   R3   t   logsR_   RX   R4   t   PluginR   (    (    (    s?   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_mounts.pyt   <module>   s   
	