.t_c@sdZddlmZddlmZddlmZddlmZmZddlmZmZddlm Z ddlm Z dd lm Z m Z dd lm Z mZd d lmZmZmZd d lmZmZd dlZd dlZd dlZd dlZd dlZd dlmZd dlZd dlZd dlZdefdYZdeefdYZ deefdYZ!de efdYZ"de efdYZ#defdYZ$dS(s VDOService - manages the VDO service on the local node $Id: //eng/vdo-releases/magnesium/src/python/vdo/vdomgmnt/VDOService.py#35 $ i(t ArgumentError(t Constants(tDefaults(t MgmntLoggert MgmntUtils(tServicet ServiceError(t SizeString(tVDOKernelModuleService(tDeveloperExitStatustStateExitStatus(tSystemExitStatustUserExitStatusi(tCommandt CommandErrort runCommand(t Transactiont transactionalN(t gethostbynametVDOServiceErrorcBs eZdZeddZRS(s)Base class for VDO service exceptions. sVDO volume errorcOs tt|j|||dS(N(tsuperRt__init__(tselftmsgtargstkwargs((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyR8s(t__name__t __module__t__doc__t_R(((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyR2stVDODeviceAlreadyConfiguredErrorcBs eZdZeddZRS(s8The specified device is already configured for a VDO. sDevice already configuredcOs tt|j|||dS(N(RRR(RRRR((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyRBs(RRRRR(((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyR<stVDOServiceExistsErrorcBs eZdZeddZRS(s VDO service exists exception. sVDO volume existscOs tt|j|||dS(N(RRR(RRRR((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyRLs(RRRRR(((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyRFstVDOMissingDeviceErrorcBs eZdZeddZRS(s2VDO underlying device does not exist exception. s Underlying device does not existcOs tt|j|||dS(N(RR R(RRRR((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyRVs(RRRRR(((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyR Pst VDOServicePreviousOperationErrorcBs eZdZeddZRS(s3VDO volume previous operation was not completed. s+VDO volume previous operation is incompletecOs tt|j|||dS(N(RR!R(RRRR((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyRas(RRRRR(((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyR![st VDOServicecBszeZdZejejdZdZdZe dZ e dZ e dZ e dZ e dZe d Ze d Ze d Ze d Ze d Ze dZe dZe dZe dZe dZe dZe dZe dZdgZi dd6dd6dd6dd6dd6dd6dd 6d!d"6d#d$6d%d&6d'd(6Zd)efd*YZe d+Z!d,Z"e#d-Z$d.Z%e&e'd/Z(d0Z)d1Z*d2Z+d3Z,e&d4Z-e&d5Z.d6Z/e'dwd7Z1d8Z2e'd9Z3d:Z4e'dwd;Z5d<Z6d=Z7d>Z8d?Z9d@Z:e;dAZ<e dBZ=e>dCZ?dDZ@e>dEZAdFZBdGZCdHZDe;dIZEdJZFdKZGdLZHdMZIdNZJdOZKdPZLdQZMdRZNdSZOdTZPe'dUZQdVZRdWZSdXZTdYZUdZZVd[ZWd\d]ZXd^ZYd_ZZd`Z[daZ\dbZ]dcZ^ddZ_deZ`dwdfZadgZbe&dhZcdiZddjZedkZfdlZgdmZhe#dnZidoZjdpZkdqZldrZmdsZndtZoduZpdvZqRS(xs 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. enableReadCache (bool): If True, enables the VDO device's read cache. 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. 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. readCacheSize (SizeString): The size of the read cache, in addition to a minimum set by the VDO software. 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. writePolicy (str): sync, async or auto. s.Service.VDOServiceu !VDOServicetVDOss Read cachesRead cache sizesAcknowledgement threadssBio submission threadssBlock map cache sizesBlock map periods Block sizet CompressionsCPU-work threadst DeduplicationsHash zone threadss Logical sizesLogical threadss MD RAID5 modes Physical sizesPhysical threadssVDO statisticss Write policytdevicetblockMapCacheSizetblockMapPeriodt readCachet readCacheSizet ackThreadst vdoAckThreadstbioRotationIntervaltvdoBioRotationIntervalt bioThreadst vdoBioThreadst cpuThreadst vdoCpuThreadsthashZoneThreadstvdoHashZoneThreadstlogicalThreadstvdoLogicalThreadstphysicalThreadstvdoPhysicalThreadstOperationStatecBs;eZdZdZdZdZdZdZedZ RS(t beginCreatetbeginGrowLogicaltbeginGrowPhysicaltbeginRunningSetWritePolicytfinishedtunknowncCs"|j|j|j|j|jgS(sReturn a list of the possible specific operation states. "Specific operation state" means a state that is specifically set via normal processing. (R:R;R<R=R>(tcls((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pytspecificOperationStatess( RRR:R;R<R=R>R?t classmethodRA(((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyR9scCsZxS|jD]H}t||ddk r tdj|}t|dtq q WdS(sValidates that any options specified in the arguments are solely those which are modifiable. Argument: args - arguments passed from the user s+Cannot change option {0} after VDO creationt exitStatusN(t fixedOptionstgetattrtNoneRtformatRR (R@RtoptionR((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pytvalidateModifiableOptionss   cCs|j|jrBtdj|j}|jj|dS|jjtdj|jt|_|jj |j|tdS(sCMarks the VDO device as activated, updating the configuration. s{0} already activatedNsActivating VDO {0}( t_handlePreviousOperationFailuret activatedRRGtgetNametlogtannouncetTruetconfigtaddVdo(RR((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pytactivates  % cCs|jr=|jjtdj|j|jnP|rk|jjtdj|jn"|js|jjtdndS(s.Logs the VDO volume state during create/start.s'VDO instance {0} volume is ready at {1}sVDO volume created at {0}s,VDO volume cannot be started (not activated)N(trunningRMRNRRGtgetInstanceNumbertgetPathRK(Rt wasCreated((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyt announceReadys ( cCsw|jjtdj|j|jtdd|jddg|jjtdj|jdS(sConnect to index.s Attempting to get {0} to connecttdmsetuptmessaget0s index-enables{0} connect succeededN(RMRNRRGRLRJR(R((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pytconnects  c s|jjtdj|j|jjdj|jj|j|j rtdj|j}t |n|jj |j rtdj|j }t |n|jrtdj|j}t|dtn|j|j|j|j|j|j|s8|jntjj|j }dg}tjjr&gfdtjDD]$}tjj||kr|^q}|dk r&|j|}|dk r#|jjd jd |g|D]}||kr|^q}q#q&nt|d kr|jjd jd |d|g|D]$}t j!d|dk ra|^qa}t|d kr|}n|j"|d |_ |jjdjd|j n"|jjdjd |d|j#|j$|j%|j&j't(j)} | j*|jj+| j*t,j-|jj.|j|j/||j0|j%|j&j1dS(s Creates and starts a VDO target.sCreating VDO {0}sconfFile is {0}sVDO volume {0} already existss)Device {0} already configured for VDO uses2Name conflict with extant device mapper target {0}RCs/dev/disk/by-idc3s$|]}tjj|VqdS(N(tostpathtjoin(t.0tname(tidDir(s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pys 9sspruning {uuid} from aliasestuuidis'found aliases for {original}: {aliases}toriginaltaliasess.*/[dm][dm]-uuid-s using {new}tnews+no aliases for {original} found in {idDir}!RaN(2RMRNRRGRLtdebugRPtfilepathRJt isConstructedRtisDeviceConfiguredR&Rt_mapperDeviceExistsRR t_validateAvailableMemoryt indexMemoryt_validateModifiableThreadCountsR3R5R7t_createCheckCleanDeviceR\R]trealpathtisdirtlistdirRFt_getDeviceUUIDtlentretmatchtsortt_installKernelModulet vdoLogLevelt_setOperationStateR9R:Rt transactiont addUndoStagetpersistt functoolstpartialt removeVdot_constructVdoFormatt_constructServiceStartR>( RtforceRRoRdtabsnamet deviceUUIDtat uuidAliasesRz((Ras;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pytcreate sp%          $   .  $   "   cCs|j|jsBtdj|j}|jj|dS|jjtdj|jt|_|jj |j|t dS(sGMarks the VDO device as not activated, updating the configuration. s{0} already deactivatedNsDeactivating VDO {0}( RJRKRRGRLRMRNtFalseRPRQRO(RR((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyt deactivateos  % cCsm|jy#tdd|jddgWn9tk rh|jjtdj|jnXdS(s*Disables deduplication on this VDO device.RXRYRZs index-disables$Cannot stop deduplication on VDO {0}N(RJRRLt ExceptionRMterrorRRG(R((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyt disconnect~s # cCs4|j|j r-|jr-|jn|jS(s9Returns the instance number of a vdo if running, or zero.(RJtinstanceNumberRSt_determineInstanceNumber(R((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyRTs  cCstjjd|jS(s)Returns the full path to this VDO device.s /dev/mapper(R\R]R^RL(R((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyRUscCsx|j|jsFtdj|j}t|dtn|j||jkrtdj|j}t|dt n<||jkrtdjt j }t|dt n|j |j j|jjtdj|jtj}|j|jjtdj|jtdd|jd d t|jg|jd|j|j|j|jjtd j|j|j|jjtd j|j|j}|jd t|}tdd|jd|g|jd|jjtdj|j||_|j|j |j jdS(spGrows the logical size of this VDO volume. Arguments: newLogicalSize (SizeString): The new size. sVDO volume {0} must be runningRCs(Can't shrink a VDO volume (old size {0})s.Can't grow a VDO volume by less than {0} bytess-Preparing to increase logical size of VDO {0}s)Cannot prepare to grow logical on VDO {0}RXRYRZtprepareToGrowLogicals)Increasing logical size of VDO volume {0}sDevice {0} could not be changedt numSectorstreloads--tables(Increased logical size of VDO volume {0}N( RJRSRRGRLRR t roundToBlockt logicalSizeR RtVDO_BLOCK_SIZERyR9R;RMtinfoRRzt setMessageRRtstrttoBlocksRFt_suspendR{t_resumet toSectorst_generateModifiedDmTablet_nameR>(RtnewLogicalSizeRRzRtvdoConf((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyt growLogicalsN                cCs|j|jsFtdj|j}t|dtn|j|jj |j j tdj|jt j }|j|j jtdj|jtdd|jddg|jd|j|j|j|j|j jtd j|jtdd|jdd g|jd|j}|d tj}|d |}td j||_|j|j|jjdS(sGrows 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. sVDO volume {0} must be runningRCs.Preparing to increase physical size of VDO {0}s*Cannot prepare to grow physical on VDO {0}RXRYRZtprepareToGrowPhysicalsCannot grow physical on VDO {0}t growPhysicalt blockSizetphysicalBlockss{0}sN(RJRSRRGRLRR RyR9R<RMRRRzRRRRFRR{Rt_getConfigFromVDORt SECTOR_SIZERt physicalSizeR>(RRRzt vdoConfigtsectorsPerBlockR((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyRs8            cCsm|jy#tdd|jddgWn9tk rh|jjtdj|jnXdS(s)Enables deduplication on this VDO device.RXRYRZs index-enables%Cannot start deduplication on VDO {0}N(RJRRLRRMRRRG(R((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyt reconnects # cCs]|jjtdj|jytj|jWn>tk ry|sztdj|j}t |qznXg}y'|j |||s|j nWnt k r)|dk r#t|dkr#|jtdj|j|jg|D]}dj|^qnnX|jj|j|jsY|jndS(s%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. sRemoving VDO {0}s.Device {0} not found. Remove VDO with --force.isSteps to clean up VDO {0}:s {0}N(RMRNRRGRLR\tstatR&tOSErrorR tstopRJR!RFRstappendtextendRPRt _hasHolderst_clearMetadata(RRt removeStepsRtlocalRemoveStepsts((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pytremoves, %    , cCsQy8tdddtj|jg}|jdkSWntk rLtSXdS(s-Returns True if the VDO service is available.RXtstatuss--targettN(RRt vdoTargetNameRLtstripRR(Rtresult((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyRSIs   c Cs[|jjtdj|j|j|jsa|jjtdj|jdS|jrt j r|jjtdj|jdS|j |j |j |jyT|ry|jWqtk r|jjtdj|jqXntdd|jd|jd |jg|jsyy|jWqytk ruqyXn|j|jr|jjtd j|j|jny|jr|jnWn9tk r|jjtd j|jnX|jWn9tk rV|jjtd j|jnXdS( sStarts the VDO target mapper. In noRun mode, we always assume the service is not yet running. Raises: ServiceError sStarting VDO {0}sVDO service {0} not activatedNsVDO service {0} already startedsDevice {0} not read-onlyRXRs--uuids--tables$started VDO service {0} instance {1}s$Could not enable compression for {0}s&Could not set up device mapper for {0}(RMRNRRGRLRJRKRRSR t noRunModeRkRlRwt_checkConfigurationt _forceRebuildRRRRt_getUUIDt_generateDeviceMapperTabletenableDeduplicationRRRtenableCompressiont_startCompressiont_startFullnessMonitoring(Rt forceRebuild((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pytstartVsT%  %   %        cCs|ji}|j|td(Rtpolicy((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pytsetWritePolicys    cCsOddddddddd d d d d ddddddddddddgS(s8Returns the list of standard attributes for this object.R+RKR-R/R'R(R1RRR&R3RRlRRRRR5t_operationStateRR7R)R*RR((((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pytgetKeyss2cCs |ddS(Nt YAMLInstance(RF(R@((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyt_yamlMakeInstancescCstt|j}tj|j|d     !   ! c CsDtt|j}|jddddddddd d d g |S( NRKR'RRRRRR)R*RR(RR"t_yamlSpeciallyHandledAttributesR(Rtspecials((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyRs  cCs|dkr|jS|dkr,|jS|dkrB|jS|dkrX|jS|dkrztt|j|S|dkr|jS|dkr|jSt dj d t |j d |dS( NRPRhtoperationStateRRlt%unrecoverablePreviousOperationFailureRs('{obj}' object has no attribute '{attr}'tobjtattr( t_computedConfigt_computedIsConstructedt_computedOperationStatet!_computedPreviousOperationFailureRR"t __getattr__t._computedUnrecoverablePreviousOperationFailuret_computedWritePolicytAttributeErrorRGttypeR(RR`((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyR&-s               c KsUtt|j||j||jj|_d|_|j d|_ |j |dt j |_ |j |dt j|_|j |dt j|_|j |dt j|_|j |dt j|_|j |dt j|_tj|_|j |dt j}|tjkr.d |_n|j |d t j}|tjk|_|j |d t j}|tjk|_|j |d t j}|tjk|_|j |d t j|_|j dtd|_ |j |dt j!|_!t j"|_"td|_#|j |dt j$|_$|j |dt j%}|tjk|_&|j |dt j'|_'|j |dt j(|_(|j |dt j)|_*t+|_,d|_-|j d|_.|j |dt j/|_0|j1|j |dt j2|j |dt j3} | tjk|_4|j |dt j5|_6dS(NR&R,R.R0R'R(R2t emulate512iRRRRR4tvdoLogicalSizeRZR6R8R)R*t vdoSlabSizeRiRxtcfreqtindexMemt sparseIndextudsParallelFactor(7RR"RRR9R?RRFt_previousOperationFailuretgetR&RRR+R-R/R'R(R1RRRR+RRRRRRRRKR3RRR5t mdRaid5ModeRR7R)RR*RRt _writePolicyRt_writePolicySetRRxR.Rt_setMemoryAttrR/R0RR1R( RR`tconftkwR+RRRRR)tsparse((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyRDsr                       cCs|dkr!|tjk|_ne|dkr=|j|nI|dkr^||_t|_n(|dkrmntt|j |||dkrt ||j ndS(NR)RlRt identifierRR(s logicalSizes physicalSize( RRRR7R5ROR6RR"t __setattr__RER(RR`R ((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyR<s       cCs#|j|}|dkr|S|S(N(R3RF(RR`tdefaultR ((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyRscCs6dj||}|jjt||jdS(Ns{0} {1} on VDO (RGRMRNRRL(RtactionRHRY((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyRscCs|jj}|d|jkrRtdj|j}t|dtnt|j t j |_ t |j t j |_ dS(sQCheck and fix the configuration of this VDO. Raises: ServiceError iis$Insufficient block map cache for {0}RCNi(R'RR5RRGRLRR tmaxR(RtblockMapPeriodMintmintblockMapPeriodMax(Rt cachePagesR((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyRs cCsyKtj|jj}tj|sJ|jjdjd|jdSWn9tk r}|jjdjd|jd|dSXdddjd|jd d d g}t |dS( s.Clear the VDO metadata from the storage devices-Not clearing {devicePath}, not a block devicet devicePathNs,Not clearing {devicePath}, cannot stat: {ex}Rtdds if=/dev/zerosof={devicePath}s oflag=directsbs=4096scount=1( R\RR&tst_modetS_ISBLKRMRfRGRR(RtmodeRR((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyRs"  cCsddlm}|jsd}y|jj|j}Wntk rNn2X|j|j j kr|j |j j dt nt|_n|jS(s[Update the instance properties as necessary and return the configuration instance. i(t ConfigurationR|N(RRIRRFRtgetVdoRLRRR9R?RyR>RRO(RRItservice((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyR"s     cCs|j|jjkS(sYReturns a boolean indicating if the instance represents a fully constructed vdo. (RR9R>(R((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyR#scCs=|}y|jj|j}Wntk r5nX|jS(sReturn 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. (RPRJRLRR(RRK((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyR$s  cCsF|jdkr?|j|jjko6|j|jjk|_n|jS(sCReturns a boolean indicating if the instance operation failed. N(R2RFRR9R?R>(R((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyR% s cCs|jo|j|jjkS(shReturns a boolean indicating if a previous operation failure cannot be automatically recovered. (RRR9R:(R((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyR's cCsI|}|jsBy|jj|j}WqBtk r>qBXn|jS(sReturn 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. (R6RPRJRLRR5(RRK((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyR(#s  cCs)|jj}ttj|ddS(sCCompute the --slab-bits parameter value for the slabSize attribute.ig?(RRtinttmathRM(Rtblocks((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyt_computeSlabBits4scCsI|jjdj|jtj}|j|j|jdS(Ns construction - starting; vdo {0}( RMRfRGRLRRzRR{R(RRz((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyR;s  cCs|jjdj|jtj}|j||j|j|j }|dt j }|d|}t dj||_ |d|}t dj||_dS(Ns1construction - formatting logical volume; vdo {0}RRs{0}st logicalBlocks(RMRfRGRLRRzt _formatTargetR{RRRRRRR(RRRzRRRR((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyRCs   cCsy#tddddd|jgWntk r*}g|jjD]}|j^qH}t|}|dkr!xt|D]}tj d||dk rx[||dD]K}tj d |}|dk rt d j |j dd tqqWPqqW|j|d n|nXytd d|jgWn)tk rp}|jdkrqdSnXt ddd tdS(sPerforms a verification for create that the storage device doesn't already have something on it. Raises: VDOServiceError tpvcreates--configsdevices/scan_lvs=1s-qqs--testis ^TEST MODEis'WARNING: (.* detected .*)\.\s+Wipe it\?s{0}; use --force to overrideRCitblkids-piNsdevice is a physical volume;s use --force to override(RR&RtgetStandardErrort splitlinesRRsRRtRuRFRRGtgroupR Rt getExitCode(Rtetlinetlinest lineCounttitdetectionMatch((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyRnSs6  +       cCsdj|j}y7t|d"}t|jj|_WdQXWn;tk r}|jj t dj|j|nXdS(s;Determine the instance number of a running VDO using sysfs.s/sys/kvdo/{0}/instancetrNs8unable to determine VDO service {0} instance number: {1}( RGRLtopenRLtreadRRRRMtwarningR(RR]tfterr((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyRs%  cCstd|jgdS(saCalls vdoforcerebuild to exit read-only mode and force a metadata rebuild at next start. tvdoforcerebuildN(RR&(R((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyRscCs$dg}|jdt|j|j}|dkrDtj}n|js\tj|_n|jdt||jr|jdn|jj dkr|jd|jj n|jtjkr|jdt|j n|r|jd n|j|j t |d S( sFormats the VDO target.t vdoformats--uds-checkpoint-frequency=gs--uds-memory-size=s --uds-sparseis--logical-size=s --slab-bits=s--forceN(RRRRlRR/RRRRt asLvmTextROR&R(RRt commandLinetmemVal((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyRQs$       cCs|jj}|jj}djdt|jdt|jdt|jdt|j dt|j dt|j dt|j g}d jd t|t j|jt|jtj|jt|jjt|t|j|j|j|j|g }|S( sRGenerate the device mapper table line from the properties of this object. t,sack=sbio=sbioRotationInterval=scpu=shash=slogical=s physical=RRZ(RRR'RR^RR+R/R-R1R3R5R7RRR&RRRRR*R(R4RR(RRRCtthreadCountConfigR((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyRs(    cKstdd|jgj}|jj|dddd}tt|jd|jd}x$|jD]\}}|||Returns the uuid as reported from the actual vdo storage. RsVDO-tUUID(RRRR&(RRP((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyRLs cCsbtd}y>tdd|jg}|jd}|tjj}Wntk r]nX|S(Ns not availableRXRR(RRRLRoRtdmsetupStatusFieldstdeduplicationStatusR(RRtoutputtfields((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyRTs  cCsqy(tddddd|gj}Wn.tk rX}|jjdt|dSX|dkridS|SdS( sGet the UUID of the device passed in, Arguments: devicePath (path): path to a device. Returns: UUID as a string, or None if none found RSs-sRs-oR sblkid failed: RN(RRRRMRRRF(RRDRR((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyRras  cCsy=tj|j}tj|j}tj|j}Wntk rQtSXdjd|d|}tj j |rtj |}t |dkr|j jdjd|jddj|tSntS( sTests 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. s&/sys/dev/block/{major}:{minor}/holderstmajortminoris&{path} is being held open by {holders}R]tholdersR(R\RRURtst_rdevRRRRGR]RpRqRsRMRR^RO(RtstRRtholdersDirectoryR((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyRvs  cCsrtdgdt}|rntjdtj|jd}x*|jD]}|j|rNtSqNWntS(sTests whether filesystems are mounted on the VDO device. Returns: True iff the VDO device has something mounted on it. tmountRs(\A|\s+)s\s+( RRORttcompiletescapeRURUtsearchR(Rt mountListtmatcherRY((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyRs& cCsst}y|jWn9tk rR|jjtdj|jnX|dk ro|j |ndS(sInstall the kernel module providing VDO support. Arguments: logLevel: the level of logging to use; if None, do not set level sKernel module {0} not installedN( RRRRMRRRGRLRFt setLogLevel(RtlogLeveltkms((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyRws   cCs4ytj|jtSWntk r/tSXdS(sOReturns True if there already exists a dm target with the name of this VDO.N(R\RRURORR(R((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyRjs  cCstj}|j|j|j|j|jjtdj |j |j d|j }|j|jjtdj |j t dd|jd|g|jd|jdS(sHPeforms the changing of the write policy on a running vdo instance. sDevice {0} could not be readRsDevice {0} could not be changedRXRs--tableN(RRzRR{RRRMRRRGRLRRRRRF(RRzR((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyRs     cCs|js1|jjtdj|jn|j|jjkrvtdj|j}t |dt ni|j }|d|dt j }tdj||_|jr|jn|j|jjdS(scRecovers a VDO target from a previous grow logical failure. Raises: VDOServiceError s5No grow logical recovery necessary for VDO volume {0}sCPrevious operation failure for VDO volume {0} not from grow logicalRCRPRs{0}sN(RRMRfRRGRLRR9R;RR RRRRRRSRRyR>(RRRR((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyRvs       cCs|js1|jjtdj|jn|j|jjkrvtdj|j}t |dt ni|j }|d|dt j }tdj||_|jr|jn|j|jjdS(sdRecovers a VDO target from a previous grow physical failure. Raises: VDOServiceError s6No grow physical recovery necessary for VDO volume {0}sDPrevious operation failure for VDO volume {0} not from grow physicalRCRRs{0}sN(RRMRfRRGRLRR9R<RR RRRRRRSRRyR>(RRRR((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyRws       cCs|js1|jjtdj|jnq|j|jjkrvtdj|j}t |dt n,|j r|j n|j |jjdS(sRecovers a VDO target from a previous setting of write policy against a running VDO. Raises: VDOServiceError s9No set write policy recovery necessary for VDO volume {0}sGPrevious operation failure for VDO volume {0} not from set write policyRCN(RRMRfRRGRLRR9R=RR RSRRyR>(RR((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyRxs      cCs|jjtdj|jytdd|jgWn>tk r}|jjtdj|j|nX|j|jjtdj|jdS(sResumes a suspended VDO.sResuming VDO volume {0}RXtresumes"Can't resume VDO volume {0}; {1!s}sResumed VDO volume {0}N( RMRRRGRLRRRR(RR((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyR,s% cCsDt|}|dkr't|}ntt|jd|dS(Ng?Rl(tfloatRLRR"R<(RR tmemory((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyR79s  cCsB||_|r>|jj|j|dt|jjndS(Ntreplace(RRPRQRLROR|(RtstateR|((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyRyBs cCs|jtdS(s9Starts compression on a VDO volume if it is running. N(t_toggleCompressionRO(R((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyRIscCsZytdd|jgWn6tk rU|jjtdj|jnXdS(Nt vdodmeventds-rs$Could not register {0} with dmeventd(RRLRRMRRRG(R((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyROs  cCs|jtdS(s8Stops compression on a VDO volume if it is running. N(RR(R((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyRXscCsWdd|jg}|dk r:|jdj|n|rSt|dtndS(NRs-uRR(RLRFRR^RRO(RRRR((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyR^s  cCs|jjtdj|j|jtdytdd|jgWn>t k r}|jj tdj|j|nX|jjtdj|jdS(sSuspends a running VDO.sSuspending VDO volume {0}RXtsuspends#Can't suspend VDO volume {0}; {1!s}sSuspended VDO volume {0}N( RMRRRGRLRRORFRRR(RR((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyRfs%cCsv|jsdS|jjtdj|r1dnd|jtdd|jdd|rhd nd gdS( sTurns compression on or off if the VDO is running. Arguments: enable (boolean): True if compression should be enabled Ns{0} compression on VDO {1}tStartingtStoppingRXRYRZRtontoff(RSRMRNRRGRLR(RR((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyRss  cCstdjtjt|}d }yutdddg}xY|jD]K}tj d|}|d k rO|j d}tdj|}qOqOWWnt k rnX|d kr|j j dd S|j|jkr ttd jd |nd S( s=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 s{0}gtgrept MemAvailables /proc/meminfosMemAvailable:\s*(\d+)is{0}ks#Unable to validate available memoryNsGNot enough available memory in system for index requirement of {needed}tneeded(RRGtlocaleRRRFRRURtRuRVRRMRRRR(RRlt memoryNeededtmemoryAvailableRRYRt available((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyRks" $    cCs|dkr|j}n|dkr0|j}n|dkrH|j}n|dksl|dksl|dkr|dko|dko|dk rttdndS(sYValidates 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 isRhash zone, logical and physical threads must either all be zero or all be non-zeroN(RFR3R5R7RR(RthashZonetlogicaltphysical((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyRms      $%N(rRRRRt getLoggertmynameRMtyaml_tagtvdosKeyRRRRRRRRRRRRRRtvdoMdRaid5ModeKeyRRRtvdoWritePolicyKeyRDR tobjectR9RBRIRRRORWR[RRRRRRTRURRRRFRRSRRRRRR RRt staticmethodRRtpropertyRRRR&RR<RRRRR"R#R$R%R'R(RORRRnRRRQRRRRJRRRRRrRRRwRjRRvRwRxRR7RyRRRRRRRkRm(((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyR"gs(                      a  :3 8 ; 2_  - $  7  J             1      0              "(%RRRRRRRRRRRR R R R tutilsR RRRRR}RRMR\RttsocketRRRRRRRR R!R"(((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOService.pyts4