Sindbad~EG File Manager

Current Path : /lib/python3.6/site-packages/vdo/vdomgmnt/__pycache__/
Upload File :
Current File : //lib/python3.6/site-packages/vdo/vdomgmnt/__pycache__/VDOService.cpython-36.pyc

3

x?agct�@s�dZddlmZddlmZddlmZddlmZddlmZddlmZdd	lm	Z	dd
lm
Z
ddlmZmZddlm
Z
dd
lmZddlmZmZddlmZmZddlmZmZmZddlmZmZddlZddlZddlZddlZddlZddlZddlm Z ddl!Z!ddl"Z"ddl#Z#ddl$Z$Gdd�de�Z%Gdd�dee%�Z&Gdd�dee%�Z'Gdd�dee%�Z(Gdd�dee%�Z)Gdd�de�Z*dS) z�
  VDOService - manages the VDO service on the local node

  $Id: //eng/vdo-releases/aluminum/src/python/vdo/vdomgmnt/VDOService.py#41 $

�)�absolute_import)�division)�print_function)�unicode_literals�)�
ArgumentError)�	Constants)�Defaults)�
MgmntUtils)�Service�ServiceError)�
SizeString)�VDOKernelModuleService)�DeveloperExitStatus�StateExitStatus)�SystemExitStatus�UserExitStatus)�Command�CommandError�
runCommand)�Transaction�
transactionalN)�
gethostbynamecs(eZdZdZed�f�fdd�	Z�ZS)�VDOServiceErrorz)Base class for VDO service exceptions.
  zVDO volume errorcstt|�j|f|�|�dS)N)�superr�__init__)�self�msg�args�kwargs)�	__class__�� /usr/lib/python3.6/VDOService.pyr>szVDOServiceError.__init__)�__name__�
__module__�__qualname__�__doc__�_r�
__classcell__r!r!)r r"r8srcs(eZdZdZed�f�fdd�	Z�ZS)�VDODeviceAlreadyConfiguredErrorz8The specified device is already configured for a VDO.
  zDevice already configuredcstt|�j|f|�|�dS)N)rr)r)rrrr)r r!r"rHsz(VDODeviceAlreadyConfiguredError.__init__)r#r$r%r&r'rr(r!r!)r r"r)Bsr)cs(eZdZdZed�f�fdd�	Z�ZS)�VDOServiceExistsErrorz VDO service exists exception.
  zVDO volume existscstt|�j|f|�|�dS)N)rr*r)rrrr)r r!r"rRszVDOServiceExistsError.__init__)r#r$r%r&r'rr(r!r!)r r"r*Lsr*cs(eZdZdZed�f�fdd�	Z�ZS)�VDOMissingDeviceErrorz2VDO underlying device does not exist exception.
  z Underlying device does not existcstt|�j|f|�|�dS)N)rr+r)rrrr)r r!r"r\szVDOMissingDeviceError.__init__)r#r$r%r&r'rr(r!r!)r r"r+Vsr+cs(eZdZdZed�f�fdd�	Z�ZS)� VDOServicePreviousOperationErrorz3VDO volume previous operation was not completed.
  z+VDO volume previous operation is incompletecstt|�j|f|�|�dS)N)rr,r)rrrr)r r!r"rgsz)VDOServicePreviousOperationError.__init__)r#r$r%r&r'rr(r!r!)r r"r,asr,cseZdZdZejd�ZdZdZe	d�Z
e	d�Ze	d�Ze	d�Z
e	d	�Ze	d
�Ze	d�Ze	d�Ze	d
�Ze	d�Ze	d�Ze	d�Ze	d�Ze	d�Ze	d�Ze	d�Ze	d�Ze	d�ZdgZddddddddd d!d"d#�ZGd$d%�d%e�Ze d&d'��Z!d(d)�Z"d�d+d,�Z#d-d.�Z$e%d/d0��Z&e%d�d2d3��Z'd4d5�Z(d6d7�Z)d8d9�Z*d:d;�Z+e%d<d=��Z,e%d>d?��Z-e%d@dA��Z.dBdC�Z/d�dEdF�Z0dGdH�Z1d�dIdJ�Z2d�dKdL�Z3d�dMdN�Z4dOdP�Z5dQdR�Z6dSdT�Z7dUdV�Z8dWdX�Z9e:dYdZ��Z;e d[d\��Z<e=�fd]d^��Z>�fd_d`�Z?e=�fdadb��Z@�fdcdd�ZA�fdedf�ZB�fdgdh�ZCe:didj��ZDdkdl�ZEdmdn�ZFdodp�ZGdqdr�ZHdsdt�ZIdudv�ZJdwdx�ZKdydz�ZLd{d|�ZMd}d~�ZNdd��ZOd�d��ZPd�d��ZQd�d�d��ZRd�d��ZSd�d��ZTd�d��ZUd�d��ZVd�d��ZWd�d��ZXd�d��ZYd�d��ZZd�d��Z[d�d��Z\d�d��Z]d�d��Z^d�d��Z_d�d��Z`d�d��Zad�d��Zbd�d��Zcd�d��Zdd�d��Zed�d��Zfd�d��Zgd�d��Zhd�d�d��Zid�d��Zje%d�d���Zkd�d��Zld�d��Zmd�d��Znd�d��Zo�fd�d„Zpd�d�dĄZqd�dƄZrd�dȄZsd�dʄZtd�d̄Zud�d΄Zvd�dЄZwd�d�d҄Zxd�dԄZyd�dքZzd�d؄Z{d�dڄZ|�Z}S)��
VDOServicea�VDOService manages a vdo device mapper target on the local node.

  Attributes:
    ackThreads (int): Number of threads dedicated to performing I/O
      operation acknowledgement calls.
    activated (bool): If True, should be started by the `start` method.
    bioRotationInterval (int): Number of I/O operations to enqueue for
      one bio submission thread in a batch before moving on to enqueue for
      the next.
    bioThreads (int): Number of threads used to submit I/O operations to
      the storage device.
    blockMapCacheSize (sizeString): Memory allocated for block map pages.
    blockMapPeriod (int): Block map period.
    cpuThreads (int): Number of threads used for various CPU-intensive tasks
      such as hashing.
    device (path): The device used for storage for this VDO volume.
    enableCompression (bool): If True, compression should be
      enabled on this volume the next time the `start` method is run.
    enableDeduplication (bool): If True, deduplication should be
      enabled on this volume the next time the `start` method is run.
    hashZoneThreads (int): Number of threads across which to subdivide parts
      of VDO processing based on the hash value computed from the block data
    indexCfreq (int): The Index checkpoint frequency.
    indexMemory (str): The Index memory setting.
    indexSparse (bool): If True, creates a sparse Index.
    indexThreads (int): The Index thread count. If 0, use a thread per core
    logicalSize (SizeString): The logical size of this VDO volume.
    logicalThreads (int): Number of threads across which to subdivide parts
      of the VDO processing based on logical block addresses.
    maxDiscardSize (SizeString): the max discard size for this VDO volume.
    physicalSize (SizeString): The physical size of this VDO volume.
    physicalThreads (int): Number of threads across which to subdivide parts
      of the VDO processing based on physical block addresses.
    slabSize (SizeString): The size increment by which a VDO is grown. Using
      a smaller size constrains the maximum physical size that can be
      accomodated. Must be a power of two between 128M and 32G.
    uuid (str): uuid of vdo volume.
    writePolicy (str): sync, async, async-unsafe or auto.
  zvdo.vdomgmnt.Service.VDOServicez!VDOServiceZVDOszAcknowledgement threadszBio submission threadszBio rotation intervalzBlock map cache sizezBlock map periodz
Block sizeZCompressionzCPU-work threadsZ
DeduplicationzHash zone threadszLogical sizezLogical threadszMax discard sizez
MD RAID5 modez
Physical sizezPhysical threadszVDO statisticszWrite policy�device�blockMapCacheSize�blockMapPeriod�maxDiscardSize�uuid�
ackThreads�bioRotationInterval�
bioThreads�
cpuThreads�hashZoneThreads�logicalThreads�physicalThreads)r/r0r1r2�
vdoAckThreads�vdoBioRotationInterval�
vdoBioThreads�
vdoCpuThreads�vdoHashZoneThreads�vdoLogicalThreads�vdoPhysicalThreadsc@sTeZdZdZdZdZdZdZdZdZ	eded	ed
ededede	diZ
ed
d��ZdS)zVDOService.OperationState�beginCreate�beginGrowLogical�beginGrowPhysical�beginImport�beginRunningSetWritePolicy�finished�unknown�createzgrow logicalz
grow physical�importzwrite policycCs|j|j|j|j|j|jgS)z�Return a list of the possible specific operation states.

      "Specific operation state" means a state that is specifically set
      via normal processing.
      )rArBrCrDrErF)�clsr!r!r"�specificOperationStates�sz1VDOService.OperationState.specificOperationStatesN)
r#r$r%rArBrCrDrErFrG�names�classmethodrKr!r!r!r"�OperationState�srNcCsxx8|jD].}t||d�dk	rtd�j|�}t|td��qWt|dd�dk	rt|jdkrt|jrttd�j|�}t|td��dS)z�Validates that any options specified in the arguments are solely
    those which are modifiable.

    Argument:
      args  - arguments passed from the user
    Nz+Cannot change option {0} after VDO creation)�
exitStatusr2�z8Cannot change uuid to a specific value when --all is set)�fixedOptions�getattrr'�formatrrr2�all)rJr�optionrr!r!r"�validateModifiableOptions�sz$VDOService.validateModifiableOptionscCsd|j�|jr.td�j|j��}|j|�dS|jtd�j|j���d|_|jj|j�|d�dS)zCMarks the VDO device as activated, updating the configuration.
    z{0} already activatedNzActivating VDO {0}T)�_handlePreviousOperationFailure�	activatedr'rS�getName�	_announce�config�addVdo)rrr!r!r"�activate�s
zVDOService.activateTcCs^|j�r(|jtd�j|j�|j���n2|rF|jtd�j|j���n|jsZ|jtd��dS)z.Logs the VDO volume state during create/start.z'VDO instance {0} volume is ready at {1}zVDO volume created at {0}z,VDO volume cannot be started (not activated)N)�runningrZr'rS�getInstanceNumber�getPathrX)rZ
wasCreatedr!r!r"�
announceReadyszVDOService.announceReadycCsR|jtd�j|j���|j�tdd|j�ddg�|jtd�j|j���dS)zConnect to index.z Attempting to get {0} to connect�dmsetup�message�0zindex-enablez{0} connect succeededN)rZr'rSrYrWr)rr!r!r"�connects
zVDOService.connectcCs�|j�|jtd�j|j���tj�}|j�rD|j�|j	|j
�|j|jj
td�j|j���ttjd|jg�j�}|jd�|dkr�|jtj|d��|jj|j��dS)z�Convert the VDO device to be used by LVM. This will stop the VDO
       device, run the conversion tool and then remove the entry from the
       VDO config file.
    zConverting VDO {0}z!Device {0} could not be convertedz/vdoprepareforlvmNrPz      )rWrZr'rSrYr�transactionr^�stop�addUndoStage�start�
setMessage�log�errorrr	ZconversionUtilityDirr.�strip�textwrap�indentr[�	removeVdo)rrf�outputr!r!r"�convert"s

zVDOService.convertFcCs�|jtd�j|j���|jjdj|jj��|j�|j	�|j
�|j|j�|j
�|j|j�|j|jj�tj�}|j|jj�|jtj|jj|j���|j|�|j|j�|j�|j|jj�dS)z Creates and starts a VDO target.zCreating VDO {0}zconfFile is {0}N)rZr'rSrYrk�debugr[�filepathrW�_checkForExistingVDO�_validateParameters�_checkForExistingUUIDr2�_setStableName�_installKernelModule�vdoLogLevel�_setOperationStaterNrArrfrh�persist�	functools�partialrp�_constructVdoFormat�_setUUID�_constructServiceStartrF)r�forcerfr!r!r"rH>s"
zVDOService.createcCsd|j�|js.td�j|j��}|j|�dS|jtd�j|j���d|_|jj|j�|d�dS)zGMarks the VDO device as not activated, updating the configuration.
    z{0} already deactivatedNzDeactivating VDO {0}FT)rWrXr'rSrYrZr[r\)rrr!r!r"�
deactivatehs
zVDOService.deactivatecCs�|j�yDt�j�}|dkr4tdd|j�ddg�ntdd|j�ddg�Wn0tk
r||jjtd	�j	|j����YnXd
S)z*Disables deduplication on this VDO device.��rrbrcrdzindex-closez
index-disablez$Cannot stop deduplication on VDO {0}N)r�r�r)
rWrZ
targetVersionrrY�	Exceptionrkrlr'rS)r�versionr!r!r"�
disconnectws
zVDOService.disconnectcCs&|j�|jr |j�r |j�|jS)z9Returns the instance number of a vdo if running, or zero.)rW�instanceNumberr^�_determineInstanceNumber)rr!r!r"r_�szVDOService.getInstanceNumbercCstjjd|j��S)z)Returns the full path to this VDO device.z/dev/mapper)�os�path�joinrY)rr!r!r"r`�szVDOService.getPathcCst|j�|j�s.td�j|j��}t|td��|j�||jkr^td�j|j�}t|t	d��n&||jkr�td�jt
j�}t|t	d��|j|j
j�|jjtd�j|j���|j�}|jt|�d�}tj�}|j|jjtd�j|j���tdd	|jd
|g�|jd�|jd�|j�|j�}|d
|dt
j}tdj|��|_|jjtd�j|j���|j|j
j�dS)zpGrows the logical size of this VDO volume.

    Arguments:
      newLogicalSize (SizeString): The new size.
    zVDO volume {0} must be running)rOz(Can't shrink a VDO volume (old size {0})z.Can't grow a VDO volume by less than {0} bytesz)Increasing logical size of VDO volume {0})�
numSectorszDevice {0} could not be changedrb�reloadz--tableNF�
logicalBlocks�	blockSizez{0}sz(Increased logical size of VDO volume {0}) rWr^r'rSrYrr�roundToBlock�logicalSizerr�VDO_BLOCK_SIZEr{rNrBrk�info�	toSectors�_generateModifiedDmTable�strrrfrjrlr�_name�_suspend�_resume�_getVDOConfigFromVDO�SECTOR_SIZEr
rF)rZnewLogicalSizerr��vdoConfrf�	vdoConfigr�r!r!r"�growLogical�sB




zVDOService.growLogicalcCs�|j�|j�s.td�j|j��}t|td��|j|j�}|j	�||j
krjtd�j|j
�}t|td��n&||j
kr�td�jtj
�}t|td��|j|jj�|jjtd�j|j���|jt|j��d�}tj�}|j|jjtd�j|j���tdd	|jd
|g�|jd�|jd�|j�|j�}|d
tj}|d|}t dj|��|_
|jjtd�j|j���|j|jj!�dS)z�Grows the physical size of this VDO volume.

    Arguments:
      newPhysicalSize (SizeString): The new size. If None, use all the
                                    remaining free space in the volume
                                    group.
    zVDO volume {0} must be running)rOz(Can't shrink a VDO volume (old size {0})z.Can't grow a VDO volume by less than {0} bytesz*Increasing physical size of VDO volume {0})ZstorageSizezDevice {0} could not be changedrbr�z--tableNFr��physicalBlocksz{0}sz)Increased physical size of VDO volume {0})"rWr^r'rSrYrr�_getDeviceSizer.r��physicalSizerrr�r{rNrCrkr�r�r��toBlocksrrfrjrlrr�r�r�r�r�r
rF)rrZnewPhysicalSizer�rfr��sectorsPerBlockr�r!r!r"�growPhysical�sD	




zVDOService.growPhysicalc	Csn|jtd�j|j���|jjdj|jj��|j�|j	�}|d}|dt
j}|d|}tdj|��|_
|d|}tdj|��|_|d|_|d	}|d
|_|d|_|d|_|j}|d
|_|dk	r�||_|j�|j�|j|j�|j�|j|j�|j|jj�tj�}|j|jj �|jt!j"|jj#|j���|j$|j�|j%�|j|jj&�dS)z Imports and starts a VDO target.zImporting VDO {0}zconfFile is {0}�	VDOConfigr�r�z{0}sr��slabSize�IndexConfig�memory�sparse�checkpointFrequency�UUIDN)'rZr'rSrYrkrsr[rtrW�_getConfigFromVDOrr�r
r�r�r��indexMem�indexSparse�
indexCfreqr2rurvrwrxryrzr{rNrDrrfrhr|r}r~rpr�r�rF)	rr[r�r�r�r��indexConfigr2rfr!r!r"�importDevices@




zVDOService.importDevicecCsX|j�ytdd|j�ddg�Wn0tk
rR|jjtd�j|j����YnXdS)z)Enables deduplication on this VDO device.rbrcrdzindex-enablez%Cannot start deduplication on VDO {0}N)rWrrYr�rkrlr'rS)rr!r!r"�	reconnectFszVDOService.reconnectNcCs�|jtd�j|j���ytj|j�Wn0tk
rX|sTtd�j|j�}t|��YnXg}y|j	||�|sx|j
�WnVtk
r�|dk	r�t|�dkr�|j
td�j|j���|jdd�|D���YnX|jj|j��|j�s�|j�dS)a%Removes a VDO target.

    If removeSteps is not None it as an empty list to which the processing
    commands for removal will be appended.

    If force was not specified and the instance previous operation failure
    is not recoverable VDOServicePreviousOperationError will be raised.
    zRemoving VDO {0}z.Device {0} not found. Remove VDO with --force.NrzSteps to clean up VDO {0}:cSsg|]}dj|��qS)z    {0})rS)�.0�sr!r!r"�
<listcomp>tsz%VDOService.remove.<locals>.<listcomp>)rZr'rSrYr��statr.�OSErrorr+rgrWr,�len�append�extendr[rp�_hasHolders�_clearMetadata)rr��removeStepsrZlocalRemoveStepsr!r!r"�removeRs,	zVDOService.removecCs>y$tdddtj|j�g�}|j�dkStk
r8dSXdS)z-Returns True if the VDO service is available.rb�statusz--targetrPFN)rr	�
vdoTargetNamerYrmr�)r�resultr!r!r"r^�szVDOService.runningc!Cs�|jtd�j|j���|j�|jsD|jjtd�j|j���dS|j�rtt	j
�rt|jjtd�j|j���dS|j|j
�|j�|j��y|r�y|j�Wn0tk
r�|jjtd�j|j����YnXtdd|jd|j�d	|j�g�|j�s"y|j�Wntk
�r YnX|j�|j�rP|jjtd
�j|j�|j��y|j�rb|j�Wn2tk
�r�|jjtd�j|j����YnX|j�Wn2tk
�r�|jjtd�j|j����YnXdS)
z�Starts the VDO target mapper. In noRun mode, we always assume
    the service is not yet running.

    Raises:
      ServiceError
    zStarting VDO {0}zVDO service {0} not activatedNz0VDO service {0} already started; no changes madezDevice {0} not read-onlyrbrHz--uuidz--tablez$started VDO service {0} instance {1}z$Could not enable compression for {0}z&Could not set up device mapper for {0})rZr'rSrYrWrXrkr�r^r�	noRunMode�warning�_validateAvailableMemory�indexMemoryry�_checkConfiguration�
_forceRebuildr�rlrr��_getUUID�_generateDeviceMapperTable�enableDeduplicationr�r�r��enableCompression�_startCompression�_startFullnessMonitoring)rZforceRebuildr!r!r"ri�sVzVDOService.startc
Cs|j�|j�}d|d}|d}|dtj}tdj|d|��}tdj|d|��}tdj|d	tj��}|d
}	|j|	d�}
i}tj||j<tj	|j
�|td�<tj	|j�||j
<tj	|j�||j<t|�||j<t|�||j<t|�|td
�<||td�<|	d|td�<|
|td�<|j|td�<tj	|	d�|td�<|j�|td�<|j��r�|j|�|�r�|j|�n
|j|�tj�dk�rtjdd|j�g�|td�<y&tdd|j�g�}t j!|�||j"<Wn$t#k
�rtd�||j"<YnX|S)zAReturns a dictionary representing the status of this object.
    zVDO-r�r�r�z{0}sr�r�z{0}Br�r�r�ZActivatez	Slab sizer�zIndex checkpoint frequencyzIndex memory settingzIndex parallel factorr�zIndex sparsezIndex statusrrbr�zDevice mapper statusZvdostatsz	--verbosez
not available)$rWr�rr�r
rSr��_getIndexMemory�vdoBlockSizeKey�enableStringrXr'r��vdoCompressionEnabledKeyr��vdoDeduplicationEnabledKeyr��vdoLogicalSizeKey�vdoPhysicalSizeKey�indexThreads�_getDeduplicationStatusr^�_getStatusFromDmsetupTable�_getPendingChanges�_getStatusFromConfigr��getuidr
ZstatusHelperrYrr`�yaml�	safe_load�vdoStatisticsKeyr�)
r�pendingr[r2r�r�r�r�r�r�r�r�r�r!r!r"r��sZ	


zVDOService.statusc
Csd|jtd�j|j���|}|sFy|j�d}Wntk
rDYnX|r�|j�r�tj�r�|j	r�|j
jtd�j|j���dS|j�}|r�|j�r�td�j|j��}t
|td��|r�|j�s�|�r(dd|j�g}|dk	r�|jd	j|��|�r(|�r
t|dd
�ntd�j|j��}t
|td��dd
g}|dk	�rJ|jd	j|��|�rb|�rbt|dd
�|�rt|j||�dd|j�g}|dk	�r�|jd	j|��d}|�r|�rxbtd�D]V}yt|�dStk
�r�}	zdt|	�k�r�d}PWYdd}	~	XnXtjd��q�W|�s|j�|j��r`|�rBtd�j|j��}ntd�j|j��}t
|td��dS)a�Stops the VDO target mapper. In noRun mode, assumes the service
    is already running.

    If removeSteps is not None it is a list to which the processing
    commands will be appended.

    If force was not specified and the instance previous operation failed
    VDOServicePreviousOperationError will be raised.

    Raises:
      ServiceError
      VDOServicePreviousOperationError
    zStopping VDO {0}TzVDO service {0} already stoppedNz"cannot stop VDO volume {0}: in use)rOZumountz-f� )�noThrowz&cannot stop VDO volume with mounts {0}ZudevadmZsettlerbr��
zDevice or resource busyFrz*cannot stop VDO service {0}: device in usezcannot stop VDO service {0})rZr'rSrYrWr,r^rr��previousOperationFailurerkr�r�rr�
_hasMountsr`r�r�r�_stopFullnessMonitoring�ranger�r��time�sleep�)_generatePreviousOperationFailureResponser)
rr�r��executer^r�commandZinUseZunused_i�exr!r!r"rgsr



zVDOService.stopcCs�|r|jdj|j�d��n|jdj|j�d��|j�|rD|jsR|r�|jr�dj|r^dnd�}|jjt|�|j��dS||_|jj	|j�|d�|jr�|j
�n|j�dS)	zoChanges the compression setting on a VDO.  If the VDO is running
    the setting takes effect immediately.
    z"Enabling compression on vdo {name})�namez#Disabling compression on vdo {name}zcompression already {0} on VDO �enabled�disabledNT)rZrSrYrWr�rkr�r'r[r\r��_stopCompression)r�enablercr!r!r"�setCompressionzs"

zVDOService.setCompressioncCs||_d|_dS)a3Sets the configuration reference and other attributes dependent on
    the configuration.

    This method must tolerate the possibility that the configuration is None
    to handle instantiation from YAML representation.  At present, there is
    nothing for which we attempt to use the configuration.
    FN)�_config�_configUpgraded)rr[r!r!r"�	setConfig�s	zVDOService.setConfigcCsz|r|jdj|j�d��n|jdj|j�d��|j�|rD|jsR|r�|jr�dj|r^dnd�}|jjt|�|j��dS||_|jj	|j�|d�|j
��rv|j�rn|j�d}x2tt
j�D]$}|j�}|t
jkr�tjd	�q�Pq�W|t
jkr�nt|t
jk�r ttd
�j|j��td��nL|t
jk�rLtd�j|j��}|jj|�n td
�j||j��}t|td��n|j�dS)zqChanges the deduplication setting on a VDO.  If the VDO is running
    the setting takes effect immediately.
    z$Enabling deduplication on vdo {name})r�z%Disabling deduplication on vdo {name}z!deduplication already {0} on VDO r�r�NTrz$Error enabling deduplication for {0})rOz2Timeout enabling deduplication for {0}, continuingz;Unexpected kernel status {0} enabling deduplication for {0})rZrSrYrWr�rkr�r'r[r\r^r�r�rZDEDUPLICATION_TIMEOUTr�ZdeduplicationStatusOpeningr�r�ZdeduplicationStatusOnlineZdeduplicationStatusErrorrr�warnr�)rr�rcr�Z_ir!r!r"�setDeduplication�sJ






zVDOService.setDeduplicationcCsD|j�|jt|d|j�t|d|j�t|d|j��d}x�|jD]�}t||d�}|dk	r@|dkr�|j�r~|jdj	|j
���q@y|j|�|j|�Wn:t
k
r�}z|jdj	|j
�|��w@WYdd}~XnXt||j||�d	}q@t||j||�d	}q@W|�r@|jj|j
�|d	�|j��r@|jtd
�j	|j
���dS)z�Sets any of the modifiable options that are specified in the arguments.

    Argument:
      args  - arguments passed from the user

    Raises:
      ArgumentError
    r>r?r@FNr2zBCan't modify uuid on VDO {0} while it is running. Skipping change.z3Can't modify uuid on VDO {0}. Skipping change: {1}.Tz7Note: Changes will not apply until VDO {0} is restarted)rW�_validateModifiableThreadCountsrRr7r8r9�modifiableOptionsr^rZrSrYrwr�r�setattrr[r\r')rrZmodifiedrU�valuer�r!r!r"�setModifiableOptions�sB	



zVDOService.setModifiableOptionscCs^|j�||jkrZ||_|j�s6|jj|j�|d�n$|j|jj�|j	�|j|jj
�dS)zaChanges the write policy on a VDO.  If the VDO is running it is
    restarted with the new policyTN)rW�writePolicyr^r[r\rYr{rNrE�_performRunningSetWritePolicyrF)rZpolicyr!r!r"�setWritePolicy	s
zVDOService.setWritePolicycCs6ddddddddd	d
ddd
ddddddddddddgS)z8Returns the list of standard attributes for this object.r3rXr4r5r/r0r6�compression�
deduplicationr.r7r�r�r�r��logicalBlockSizer�r8r1�_operationStater�r9r�r2r�r!r!r!r!r"�getKeys#s2zVDOService.getKeyscCs
|dd�S)NZYAMLInstancer!)rJr!r!r"�_yamlMakeInstanceAszVDOService._yamlMakeInstancecs�tt|�j}tj|j�|d<t|j�|d<tj|j�|d<tj|j	�|d<tj|j
�|d<t|j�|d<t|j�|d<t|j
�|d<t|j�|d	<|j|d
<|S)NrXr/rrr�r�r1r�r�r�)rr-�	_yamlDatarr�rXr�r/r�r�r�r�r1r�r�r�)r�data)r r!r"rFs
zVDOService._yamlDatacs"tt|�j|�|j|dtj|j��tjk|_t|j|dt	|j
���|_
|j|dtj|j��tjk|_|j|dtj|j��tjk|_|j|dtj|j
��tjk|_
t|j|dt	|j���|_t|j|dt	|j���|_t|j|dt	|j���|_t|j|d	t	|j���|_d
|k�r|d
|_dS)NrXr/rrr�r�r1r�r�r�)rr-�_yamlSetAttributes�_defaultIfNonerr�rXr�r
r�r/r�r�r�r�r1r�r�r�)rZ
attributes)r r!r"r	Vs<




zVDOService._yamlSetAttributescs.tt|�j}|jddddddddd	d
g
�|S)NrXr/rrr�r�r1r�r�r�)rr-�_yamlSpeciallyHandledAttributesr�)rZspecials)r r!r"r�sz*VDOService._yamlSpeciallyHandledAttributescs�|dkr|j�S|dkr |j�S|dkr0|j�S|dkr@|j�S|dkrXtt|�j|�S|dkrh|j�S|dkrx|j�St	dj
t|�j|d	���dS)
Nr[�
isConstructed�operationStater�r�Z%unrecoverablePreviousOperationFailurer�z('{obj}' object has no attribute '{attr}')�obj�attr)
�_computedConfig�_computedIsConstructed�_computedOperationState�!_computedPreviousOperationFailurerr-�__getattr__�._computedUnrecoverablePreviousOperationFailure�_computedWritePolicy�AttributeErrorrS�typer#)rr�)r r!r"r�s zVDOService.__getattr__c	s,tt|�j|�|j|�|jj|_d|_|jd�|_	|j
|dtj�|_|j
|dtj
�|_
|j
|dtj�|_|j
|dtj�|_|j
|dtj�|_|j
|dtj�|_tj|_|j
|dtj�}|tjkr�d	|_|j
|d
tj�}|tjk|_|j
|dtj�}|tjk|_|j
|dtj�}|tjk|_|j
|d
tj�|_|jdtd��|_|j
|dtj �|_ |j
|dtj!�|_!tj"|_"td�|_#|j
|dtj$�|_$|j
|dtj%�|_%|j
|dtj&�|_'d|_(d|_)|jd�|_*|jd�|_+|j
|dtj,�|_-|j.|j
|dtj/��|j
|dtj0�}|tjk|_1|j
|dtj2�|_3dS)Nr.r:r;r<r/r0r=�
emulate512irrr]r>ZvdoLogicalSizerdr?r1r@ZvdoSlabSizer�Frrzr2�cfreqr��sparseIndex�udsParallelFactor)4rr-rr�rNrGr�_previousOperationFailure�getr.r
r	r3r4r5r/r0r6rr�rrr�rr�rr�r]rXr7r
r�r8r1�mdRaid5Moder�r9r�r��_writePolicy�_writePolicySetr�rzr2rr��_setMemoryAttrr�rr�rr�)	rr�Zconf�kwrrrr]r�)r r!r"r�sp















zVDOService.__init__cs`|dkr|j|�n2|dkr*||_d|_n|dkr4ntt|�j||�|dkr\t||�j�dS)	Nr�r�TZ
identifierr1r�r�)r1r�r�)r"r r!rr-�__setattr__rRr�)rr�r�)r r!r"r$�szVDOService.__setattr__cCs|j|�}|dkr|S|S)N)r)rr��defaultr�r!r!r"r
s
zVDOService._defaultIfNonecCs|jj|�t|�dS)N)rkr��print)rrcr!r!r"rZszVDOService._announcecCsZ|jj�}|d|jkr6td�j|j��}t|td��t|j	t
j�|_	t|j	t
j
�|_	dS)zQCheck and fix the configuration of this VDO.

    Raises:
      ServiceError
    r�iz$Insufficient block map cache for {0})rONi)r/r�r8r'rSrYrr�maxr0r	ZblockMapPeriodMin�minZblockMapPeriodMax)r�
cachePagesrr!r!r"r�s
zVDOService._checkConfigurationc
Cs�|dks|dkrdSdddtjg}dd�t|dd	�j�D�}td
d�|D��}|tdd�|jj�j�D��O}t|�}g}xF|D]>}y,t	j
td|g��}||d
kr�|j|�Wq�Yq�Xq�Wt|�dkr�dj
|�}td�j||�}	t|	td��dS)z� Checks that the device does not have an already existing UUID.

    Arguments:
      uuid (str) - the uuid to check for

    Raises: VDOServiceError
    NrPrb�tablez--targetcSsg|]}|dkr|�qS)zNo devices foundr!)r��liner!r!r"r�<sz4VDOService._checkForExistingUUID.<locals>.<listcomp>T)r�cSsg|]}|jd�d�qS)r��)�split)r�r*r!r!r"r�>scSsg|]
}|j�qSr!)r.)r��vdor!r!r"r�@s�
vdodumpconfigr�rz, z6UUID {0} already exists in VDO volume(s) stored on {1})rO)r	r�r�
splitlines�setr[Z
getAllVdos�values�listr�r�r�r�r�r'rSrr)
rr2�cmdZ	vdoTablesZvdosZconflictVdosr.r[ZconflictListrr!r!r"rw+s( 


z VDOService._checkForExistingUUIDcCsp|jr td�j|j��}t|��|jj|j�rFtd�j|j�}t|��|j	�rltd�j|j��}t
|td��dS)z�Check to see if there is an existing VDO volume running with the 
       same name as this VDO, or it already exists in this config file

    Raises:
      VDOServiceExistsError VDODeviceAlreadyConfiguredError
    zVDO volume {0} already existsz)Device {0} already configured for VDO usez2Name conflict with extant device mapper target {0})rON)rr'rSrYr*r[ZisDeviceConfiguredr.r)�_mapperDeviceExistsrr)rrr!r!r"ruRs
zVDOService._checkForExistingVDOcCs�y6tj|j�j}tj|�s4|jjdj|jd��dSWn8tk
rn}z|jjdj|j|d��dSd}~XnXdddj|jd�d	d
dg}t	|�dS)z.Clear the VDO metadata from the storage devicez-Not clearing {devicePath}, not a block device)�
devicePathNz,Not clearing {devicePath}, cannot stat: {ex})r6r�Zddzif=/dev/zerozof={devicePath}zoflag=directzbs=4096zcount=1)
r�r�r.�st_mode�S_ISBLKrkrsrSr�r)r�moder�r�r!r!r"r�js"


zVDOService._clearMetadatacCslddlm}|jsfd}y|jj|j��}Wntk
r>Yn"X|j|jj	kr`|j
|jjdd�d|_|jS)z[Update the instance properties as necessary and return the
    configuration instance.
    r)�
ConfigurationNF)r|T)rPr:r�r��getVdorYrrrNrGr{rF)rr:�servicer!r!r"rs	
zVDOService._computedConfigcCs|j|jjkS)zYReturns a boolean indicating if the instance represents a fully
    constructed vdo.
    )r
rNrF)rr!r!r"r�sz!VDOService._computedIsConstructedcCs4|}y|jj|j��}Wntk
r,YnX|jS)z�Return the operation state of the instance.

    If there is an instance in the configuration the state reported is from
    that instance else it's from this instance.
    )r[r;rYrr)rr<r!r!r"r�sz"VDOService._computedOperationStatecCs.|jdkr(|j|jjko$|j|jjk|_|jS)zCReturns a boolean indicating if the instance operation failed.
    N)rr
rNrGrF)rr!r!r"r�s

z,VDOService._computedPreviousOperationFailurecCs|jo|j|jj|jjgkS)zhReturns a boolean indicating if a previous operation failure cannot be
    automatically recovered.
    )r�r
rNrArD)rr!r!r"r�s
z9VDOService._computedUnrecoverablePreviousOperationFailurecCs:|}|js4y|jj|j��}Wntk
r2YnX|jS)z�Return the write policy of the instance.

    If this instance's write policy was not explicitly set and there is an
    instance in the configuration the write policy reported is from that
    instance else it's from this instance.
    )r!r[r;rYrr )rr<r!r!r"r�szVDOService._computedWritePolicycCs|jj�}ttj|d�d�S)zCCompute the --slab-bits parameter value for the slabSize attribute.r�g�������?)r�r��int�mathrk)rZblocksr!r!r"�_computeSlabBits�s
zVDOService._computeSlabBitscCs6|jjdj|j���tj�}|j�|j|j�dS)Nz construction - starting; vdo {0})	rkrsrSrYrrfrirhrg)rrfr!r!r"r��sz!VDOService._constructServiceStartcCs�|jjdj|j���tj�}|j|�|j|j�|j	�}|dt
j}|d|}tdj|��|_
|d|}tdj|��|_dS)Nz1construction - formatting logical volume; vdo {0}r�r�z{0}sr�)rkrsrSrYrrf�
_formatTargetrhr�r�rr�r
r�r�)rr�rfr�r�r�r�r!r!r"r�s

zVDOService._constructVdoFormatcCs~dj|j��}y,t|d��}t|j�j��|_WdQRXWn>tk
rx}z"|jj	t
d�j|j�|��WYdd}~XnXdS)z;Determine the instance number of a running VDO using sysfs.z/sys/kvdo/{0}/instance�rNz8unable to determine VDO service {0} instance number: {1})rSrY�openr=�readrmr�r�rkr�r')rr��f�errr!r!r"r�s z#VDOService._determineInstanceNumbercCstd|jg�dS)zaCalls vdoforcerebuild to exit read-only mode and force a metadata
    rebuild at next start.
    ZvdoforcerebuildN)rr.)rr!r!r"r�szVDOService._forceRebuildcCs>dg}|jdt|j��|j}|dkr.tj}|js<tj|_|jdt|��|jr^|jd�|jj	�dkr�|jd|jj
��|jtjkr�|jdt|j���|r�|jd	�|j|j�y&t
|�j�}|r�|jtj|d
��WnVtk
�r8}z8|j�j�}tjd|�}|dk	�r$t|td
��|�WYdd}~XnXdS)zFormats the VDO target.Z	vdoformatz--uds-checkpoint-frequency=gz--uds-memory-size=z--uds-sparserz--logical-size=z--slab-bits=z--forcez      z.*Cannot format deviceN)rO)r�r�r�r�r	r�r�r�r��toBytesZ	asLvmTextr?r.r�rstriprZrnrorZgetStandardError�re�matchrr)rr�ZcommandLine�memValrq�erlZdetectionMatchr!r!r"r@s6


zVDOService._formatTargetcCs�|jj�}|jj�}|jj�}djdt|j�dt|j�dt|j	�dt|j
�dt|j�dt|j�dt|j
�g�}d	t|�tjd
|jt|j�d�t|j�t|�t|j�|j|j|jdt|�|g}|js�|jd
dg�dj|�}|S)zRGenerate the device mapper table line from the properties of this
    object.
    r��ack�bior4�cpu�hash�logical�physicalrdZV2r��
maxDiscardr�off)r�r�r/r�r1r�r�r3r5r4r6r7r8r9r	r�r.r�rr0rr�r�r�r�)rr�r)ZmaxDiscardBlocksZthreadCountConfigZ	argumentsr�r!r!r"r�=s0







z%VDOService._generateDeviceMapperTablecs�tdd|jg�j�}|jj|�d}|jd�}|jd�}tt||���x t|j	��D]\}}|�|<qTWdj
�fdd�|D�|t��d	��S)z�Changes the specified parameters in the dmsetup table to the specified
    values.

    Raises:
      CommandError if the current table cannot be obtained

    Returns:
      a valid new dmsetup table.
    rbr*z6logicalStart numSectors targetName version storagePathz1 storageSize blockSize cacheBlocks blockMapPeriodz! mdRaid5Mode writePolicy poolNamer�csg|]}�|�qSr!r!)r��key)�dmTabler!r"r�xsz7VDOService._generateModifiedDmTable.<locals>.<listcomp>NzglogicalStart numSectors targetName version storagePath storageSize blockSize cacheBlocks blockMapPeriodz�logicalStart numSectors targetName version storagePath storageSize blockSize cacheBlocks blockMapPeriod mdRaid5Mode writePolicy poolName)rr�rGrkr�r-�dict�zipr3�itemsr�r�)rrr*�
tableOrderZtableOrderItems�
tableItemsrT�valr!)rUr"r�[s


z#VDOService._generateModifiedDmTablecCs,td�j|j�|jj|jd�}t|��dS)ahGenerates the required response to a previous operation failure.

    Logs a message indicating that the previous operation failed and raises the
    VDOServicePreviousOperationError exception with the same message.

    Arguments:
      operation (str) - the operation that failed; default to "create".

    Raises:
      VDOServicePreviousOperationError
    z8VDO volume {0} previous operation ({1}) is incomplete{2}z(; recover by performing 'remove --force'N)r'rSrYrNrLr
r,)rrr!r!r"r�|s
z4VDOService._generatePreviousOperationFailureResponsecCs�|js$|jjtd�j|j���dS|j|jj�krXtd�j|j�|j�}t	|t
d��n�|j|jjkrp|j�n||j|jj
kr�|j�nd|j|jjkr�|j�nL|j|jjkr�|j�n4|j|jjkr�|j�ntd�j|j�}t	|t
d��d|_dS)aBHandles a previous operation failure.

    If the failure can be corrected automatically it is.
    If not, the method logs a message indicating that the previous operation
    failed and raises the VDOServicePreviousOperationError exception with
    the same message.

    Raises:
      VDOServicePreviousOperationError if the previous operation failure
      is a non-recoverable error.

      VDOServiceError if unexpected/unhandled operation state is
      encountered.  Excepting corruption or incorrect setting of state this
      indicates that the developer augmented the code with an operation (new or
      old) which can experience a catastrophic failure requiring some form of
      recovery but failed to update specificOperationStates() and/or failed to
      add a clause to this method to address the new failure.
    z0No failure requiring recovery for VDO volume {0}Nz.VDO volume {0} in unknown operation state: {1})rOz5Missing handler for recover from operation state: {0}F)r�rkrsr'rSrYr
rNrKrrrAr�rB�_recoverGrowLogicalrC�_recoverGrowPhysicalrDrE�_recoverRunningSetWritePolicyr)rrr!r!r"rW�s0




z*VDOService._handlePreviousOperationFailurecCsr|}tj|tj�s&ttd�j|d���tjtj|�j	�rRt
dd|g�}|j�j�}|dkrnttd�j|d���|S)z�Take the server name and convert it to a device name that
    can be opened from the kernel

    Arguments:
      devicePath (path): path to a device.

    Raises:
      ArgumentError
    z{path} does not exist)r��readlinkz-frPz{path} could not be resolved)
r��access�F_OKrr'rSr��S_ISLNK�lstatr7rZrunrm)rr6ZresolvedPathr4r!r!r"�_getBaseDevice�s
zVDOService._getBaseDevicecCstjtd|jg��}|S)zbReturns a dictionary of the configuration values as reported from
    the actual vdo storage.
    r/)r�r�rr.)rr[r!r!r"r��szVDOService._getConfigFromVDOcCstjtd|jg��}|dS)ztReturns a dictionary of the index configuration values as reported
    by the actual uds index used by the vdo.
    r/r�)r�r�rr.)rr[r!r!r"�_getIndexConfigFromVDO�sz!VDOService._getIndexConfigFromVDOcCs tjtd|jg��}d|dS)z>Returns the uuid as reported from the actual vdo storage.
    r/zVDO-r�)r�r�rr.)rr[r!r!r"r��szVDOService._getUUIDcCstjtd|jg��}|dS)zbReturns a dictionary of the configuration values as reported from
    the actual vdo storage.
    r/r�)r�r�rr.)rr[r!r!r"r��szVDOService._getVDOConfigFromVDOcCsNtd�}y,tdd|j�g�}|jd�}|tjj}Wntk
rHYnX|S)Nz
not availablerbr�r�)r'rrYr-rZdmsetupStatusFieldsZdeduplicationStatusr�)rr�rqZfieldsr!r!r"r��s
z"VDOService._getDeduplicationStatuscCs8|j|�}tjj|�}tdd|dg�}tdj|��S)z�Get the size of the device passed in.

    Arguments:
      devicePath (path): path to a device.

    Returns:
      Size of device as a SizeString object
    �catz/sys/class/block/z/sizez{0}s)rdr�r��basenamerr
rS)rr6ZbasePathZbaseNamerqr!r!r"r�	s	
zVDOService._getDeviceSizecCsfytddddd|g�j�}Wn4tk
rP}z|jjdt|��dSd}~XnX|dkr^dS|SdS)	z�Get the UUID of the device passed in,

    Arguments:
      devicePath (path): path to a device.

    Returns:
      UUID as a string, or None if none found
    Zblkidz-sr�z-or�zblkid failed: NrP)rrmrrkr�r�)rr6rqr�r!r!r"�_getDeviceUUIDs	zVDOService._getDeviceUUIDcCs8|dks4d	}||}|d
kr"d}n|dkr0d}nd}|S)z�Takes the input indexMemory value from vdodumpconfig and 
    converts it into a fractional Gigabyte value, if necessary.
    
    Returns:
      The index memory value (in Gigabytes).
    ir�� �g�?ig�?g�?li���i���r!)rrJZmaxInt32r!r!r"r�-s	zVDOService._getIndexMemorycCs�|j�}tdj|dtj��}td�||j<td�||j<td�||j<td�||j	<td�||j
<td�||j<td�||j<td�||j
<|d|td�<tj|ddk�|td�<t|�||j<|d	||j<|d
|td�<d|k�rtdj|dtj��}t|�||j<d
|k�r.|d
||j<d|k�rF|d||j<d|k�r^|d||j	<d|k�rv|d||j
<d|k�r�|d||j<d|k�r�|d||j<d|k�r�|d||j
<dS)zlUpdates the input status dictionary with parameter values from
    the dmsetup table for the running device.z{0}BZcacheBlocksznon-existentZstoragePathzStorage devicer�izEmulate 512 byter0r�zConfigured write policyrRrLrMr4rNrOrPrQN)�_getCurrentDmTabler
rSrr�r'�vdoMaxDiscardSizeKey�vdoAckThreadsKey�vdoBioSubmitThreadsKey�vdoBioRotationIntervalKey�vdoCpuThreadsKey�vdoHashZoneThreadsKey�vdoLogicalThreadsKey�vdoPhysicalThreadsKeyr�r��vdoBlockMapCacheSizeKey�vdoBlockMapPeriodKey)r�
statusDictrUZcacheBlocksInBytesZdiscardBlocksInBytesr!r!r"r�DsJ







z%VDOService._getStatusFromDmsetupTablecCs�|j|td�<tj|jdk�|td�<t|j�||j<|j||j	<|j
|td�<t|j�||j<|j
||j<|j||j<|j||j<|j||j<|j||j<|j||j<|j||j<dS)zcUpdates the input status dictionary with parameter values from
    the config file for this object.zStorage deviceizEmulate 512 bytezConfigured write policyN)r.r'rr�rr�r/rtr0rur�r1rlr3rmr5rnr4ror6rpr7rqr8rrr9rs)rrvr!r!r"r�vszVDOService._getStatusFromConfigcCs�tdd|jg�j�}|jj|�d}|jd�}|jd�}|t|�d�}|dt|��}|j|ddd	��|j|d
dd	��dd�|D�}tt	||��}|S)z�Obtains the dmsetup table for the VDO device.

    Raises:
      CommandError if the current table cannot be obtained.

    Returns:
      The current dmsetup table.
    rbr*z*logicalStart numSectors targetName versionz. storagePath storageSize blockSize cacheBlocksz0 blockMapPeriod mdRaid5Mode writePolicy poolNamer�Nrr�rcSs g|]}|j�rt|�n|�qSr!)�	isdecimalr=)r��ir!r!r"r��sz1VDOService._getCurrentDmTable.<locals>.<listcomp>zXlogicalStart numSectors targetName version storagePath storageSize blockSize cacheBlocksz�logicalStart numSectors targetName version storagePath storageSize blockSize cacheBlocks blockMapPeriod mdRaid5Mode writePolicy poolName)
rr�rGrkr�r-r�r�rVrW)rr*rYrZZtableOptionalItemsrUr!r!r"rk�s	

zVDOService._getCurrentDmTablecCs�|j|j|j|j|j|j|j|j|j|j	d�
}x||j
D]r}||krDq6|||krRq6t||j
|d�}t|||�}|dk	r6t|�|kr6dj
dt|��}|||||<q6WdS)zrUpdates the input status dictionary with pending changes to modifiable
    parameters for the running device.
    )
r/r0r1r:r;r<r=r>r?r@Nz{0}[{1}]z    )rtrurlrmrornrprqrrrsr�rRr�rS)rrvZoptionToStatusKeysrUZconfigValueZstatusValueZpendingValuer!r!r"r��s(
zVDOService._getPendingChangesc
Cs�y*tj|j��}tj|j�}tj|j�}Wntk
r>dSXdj||d�}tjj	|�r�tj
|�}t|�dkr�|jj
dj|j�dj|�d��dSdS)	z�Tests whether other devices are holding the VDO device open. This
    handles the case where there are LVM entities stacked on top of us.

    Returns:
      True iff the VDO device has something holding it open.
    Fz&/sys/dev/block/{major}:{minor}/holders)�major�minorrz&{path} is being held open by {holders}r�)r��holdersT)r�r�r`ry�st_rdevrzr�rSr��isdir�listdirr�rkr�r�)r�stryrzZholdersDirectoryr{r!r!r"r��s


zVDOService._hasHolderscCsRtdgdd�}|rNtjdtj|j��d�}x|j�D]}|j|�r8dSq8WdS)z�Tests whether filesystems are mounted on the VDO device.

    Returns:
      True iff the VDO device has something mounted on it.
    ZmountT)r�z(\A|\s+)z\s+F)rrH�compile�escaper`r0�search)rZ	mountListZmatcherr+r!r!r"r��s
zVDOService._hasMountscCsZt�}y|j�Wn0tk
rB|jjtd�j|j����YnX|dk	rV|j|�dS)z�Install the kernel module providing VDO support.

    Arguments:
      logLevel: the level of logging to use; if None, do not set level
    zKernel module {0} not installedN)	rrir�rkrlr'rSrYZsetLogLevel)rZlogLevelZkmsr!r!r"ry�szVDOService._installKernelModulecCs,ytj|j��dStk
r&dSXdS)zOReturns True if there already exists a dm target with the name of
    this VDO.TFN)r�r�r`r�)rr!r!r"r5	s
zVDOService._mapperDeviceExistscCs�tj�}|j|jjtd�j|j���|j|j	d�}|j|jjtd�j|j���t
dd|jd|g�|jd�|jd�|j
�dS)	zHPeforms the changing of the write policy on a running vdo instance.
    zDevice {0} could not be read)r�zDevice {0} could not be changedrbr�z--tableNF)rrfrjrkrlr'rSrYr�r�rr�r�r�)rrfr�r!r!r"r�s



z(VDOService._performRunningSetWritePolicycCs�|js"|jjtd�j|j���nz|j|jjkrPtd�j|j��}t	|t
d��nL|j�}|d|dtj
}tdj|��|_|j�r�|j�|j|jj�dS)zcRecovers a VDO target from a previous grow logical failure.

    Raises:
      VDOServiceError
    z5No grow logical recovery necessary for VDO volume {0}zCPrevious operation failure for VDO volume {0} not from grow logical)rOr�r�z{0}sN)r�rkrsr'rSrYr
rNrBrrr�rr�r
r�r^r�r{rF)rrr�r�r!r!r"r\'s
zVDOService._recoverGrowLogicalcCs�|js"|jjtd�j|j���nz|j|jjkrPtd�j|j��}t	|t
d��nL|j�}|d|dtj
}tdj|��|_|j�r�|j�|j|jj�dS)zdRecovers a VDO target from a previous grow physical failure.

    Raises:
      VDOServiceError
    z6No grow physical recovery necessary for VDO volume {0}zDPrevious operation failure for VDO volume {0} not from grow physical)rOr�r�z{0}sN)r�rkrsr'rSrYr
rNrCrrr�rr�r
r�r^r�r{rF)rrr�r�r!r!r"r]Gs
zVDOService._recoverGrowPhysicalcCsr|js"|jjtd�j|j���nL|j|jjkrPtd�j|j��}t	|t
d��n|j�r`|j�|j
|jj�dS)z�Recovers a VDO target from a previous setting of write policy against
    a running VDO.

    Raises:
      VDOServiceError
    z9No set write policy recovery necessary for VDO volume {0}zGPrevious operation failure for VDO volume {0} not from set write policy)rON)r�rkrsr'rSrYr
rNrErrr^r�r{rF)rrr!r!r"r^gs
z(VDOService._recoverRunningSetWritePolicycCs�|jjtd�j|j���ytdd|j�g�Wn@tk
rp}z$|jjtd�j|j�|���WYdd}~XnX|j�|jjtd�j|j���dS)zResumes a suspended VDO.zResuming VDO volume {0}rbZresumez"Can't resume VDO volume {0}; {1!s}NzResumed VDO volume {0})	rkr�r'rSrYrr�rlr�)rr�r!r!r"r��szVDOService._resumecs.t|�}|dkrt|�}tt|�jd|�dS)Ng�?r�)�floatr=rr-r$)rr�r�)r r!r"r"�szVDOService._setMemoryAttrcCs.||_|r*|jj|j�|dd�|jj�dS)NT)�replace)rr[r\rYr|)r�stater|r!r!r"r{�szVDOService._setOperationStatecstjj|j��d�g}tjj��r��fdd��fdd�tj��D�D�}�dk	r�|j����dk	r�|jjdj	�d���fdd�|D�}t
|�d	kr�|jjd
j	�|d��dd�|D�}t
|�d	kr�|}|j�|d	|_|jjd
j	|jd��n|jjdj	��d��dS)Nz/dev/disk/by-idcs g|]}tjj|��kr|�qSr!)r�r��realpath)r�Zabsname)r�r!r"r��sz-VDOService._setStableName.<locals>.<listcomp>c3s|]}tjj�|�VqdS)N)r�r�r�)r�r�)�idDirr!r"�	<genexpr>�sz,VDOService._setStableName.<locals>.<genexpr>zpruning {uuid} from aliases)r2csg|]}�|kr|�qSr!r!)r��a)�
deviceUUIDr!r"r��srz'found aliases for {original}: {aliases})�original�aliasescSs g|]}tjd|�dk	r|�qS)z.*/[dm][dm]-uuid-N)rHrI)r�r�r!r!r"r��szusing {new})�newz+no aliases for {original} found in {idDir}!)r�r�)r�r�r�r.r}r~rhrkrsrSr��sort)rr�ZuuidAliasesr!)r�r�r�r"rx�s2








zVDOService._setStableNamecCs�|dkrdSy.|dkr&td|jg�ntdd||jg�WnBtk
r|}z&td�j|j�|�}t|td��WYdd}~XnXdS)z�Sets a new uuid for the vdo volume, either by providing a value
    or having the tool generate a new random one.

    Arguments:
      uuid (str) - the uuid to set

    Raises:
      Exception
    NrPZ
vdosetuuidz--uuidz,Can't set the UUID for VDO volume {0}; {1!s})rO)rr.r�r'rSrYrr)rr2r�rr!r!r"r��s
zVDOService._setUUIDcCs|jd�dS)z9Starts compression on a VDO volume if it is running.
    TN)�_toggleCompression)rr!r!r"r��szVDOService._startCompressioncCsJytdd|j�g�Wn.tk
rD|jjtd�j|j���YnXdS)N�vdodmeventdz-rz$Could not register {0} with dmeventd)rrYr�rkr�r'rS)rr!r!r"r��sz#VDOService._startFullnessMonitoringcCs|jd�dS)z8Stops compression on a VDO volume if it is running.
    FN)r�)rr!r!r"r��szVDOService._stopCompressioncCs:dd|j�g}|dk	r&|jdj|��|r6t|dd�dS)Nr�z-ur�T)r�)rYr�r�r)rr�r�r�r!r!r"r��s
z"VDOService._stopFullnessMonitoringcCs�|jjtd�j|j�|rdnd��|jdd�y tdd|r@dnd	|j�g�Wn@tk
r�}z$|jjtd
�j|j�|���WYdd}~XnX|jjtd�j|j���dS)zSuspends a running VDO.z"Suspending VDO volume {0} with {1}�flushzno flushTNrbZsuspendrPz	--noflushz#Can't suspend VDO volume {0}; {1!s}zSuspended VDO volume {0})	rkr�r'rSrYr�rr�rl)rr�r�r!r!r"r�	szVDOService._suspendcCsR|j�sdS|jtd�j|r dnd|j���tdd|j�dd|rFd	nd
g�dS)z�Turns compression on or off if the VDO is running.

    Arguments:
      enable (boolean): True if compression should be enabled
    Nz{0} compression on VDO {1}ZStartingZStoppingrbrcrdrZonrS)r^rZr'rSrYr)rr�r!r!r"r�	szVDOService._toggleCompressionc
Cs�tdjtjt|����}d}yPtdddg�}x<|j�D]0}tjd|�}|dk	r6|j	d�}tdj|��}q6WWnt
k
r�YnX|dkr�|jjd	�dS|j
�|j
�kr�ttd
j|d����dS)a=Validates whether there is likely enough kernel memory to at least
    create the index. If there is an error getting the info, don't
    fail the create, just let the real check be done in vdoformat.

    Arguments:
      indexMemory - the amount of memory requested or default.

    Raises:
      ArgumentError
    z{0}gNZgrepZMemAvailablez
/proc/meminfozMemAvailable:\s*(\d+)rz{0}kz#Unable to validate available memoryzGNot enough available memory in system for index requirement of {needed})Zneeded)r
rS�localer�r�rr0rHrI�groupr�rkr�rFrr')rr�ZmemoryNeededZmemoryAvailabler�r+r�Z	availabler!r!r"r�	s"
z#VDOService._validateAvailableMemorycCsl|dkr|j}|dkr|j}|dkr*|j}|dksB|dksB|dkrh|dkoX|dkoX|dkrhttd���dS)aYValidates that the hash zone, logical and physical thread counts
    are consistent (all zero or all non-zero).

    Arguments:
      hashZone  - hash zone thread count to use, may be None
      logical   - logical thread count to use, may be None
      physical  - physical thread count to use, may be None

    Raises:
      ArgumentError
    NrzRhash zone, logical and physical threads must either all be zero or all be non-zero)r7r8r9rr')rZhashZonerPrQr!r!r"r�A	sz*VDOService._validateModifiableThreadCountscCs$|j|j�|j|j|j|j�dS)N)r�r�r�r7r8r9)rr!r!r"rvZ	szVDOService._validateParameters)T)F)FN)F)F)FN)F)N)T)T)~r#r$r%r&�loggingZ	getLoggerrkZyaml_tagZvdosKeyr'rmrnrortrur�r�rpr�rqr�rrrlZvdoMdRaid5ModeKeyr�rsr�ZvdoWritePolicyKeyrQr��objectrNrMrVr]rarerrrrHr�r�r_r`r�r�r�r�r�r^rir�rgr�r�r�r�r�staticmethodrr�propertyrr	rrrr$r
rZr�rwrur�rrrrrrr?r�rr�r�r@r�r�r�rWrdr�rer�r�r�r�rhr�r�r�rkr�r�r�ryr5r�r\r]r^r�r"r{rxr�r�r�r�r�r�r�r�r�rvr(r!r!)r r"r-ms�'


)	7;>
8
=
G
_
234J' 
*!3			
2!$

  
	
+	
"r-)+r&Z
__future__rrrrrPrrr	r
rrr
rrrrrZ	vdo.utilsrrrrrr}r�r�r>r�rHZsocketrr�rnr�r�rr)r*r+r,r-r!r!r!r"�<module>s@




Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists