Mini Shell

Direktori : /lib/python3.6/site-packages/blivet/devices/__pycache__/
Upload File :
Current File : //lib/python3.6/site-packages/blivet/devices/__pycache__/md.cpython-36.opt-1.pyc

3

{)c�s�@s<ddlZddlZddlZddlZddlmZddlZejdd�ddlm	Z
ddlmZm
Z
ddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlmZddlmZddlZejd�Zddlm Z ddl!m"Z"ddl
m#Z#ddl$m%Z%e%d�Z&Gdd�de"e#�Z'Gdd�de'�Z(Gdd�de'�Z)dS)�N)�reduce�BlockDevz2.0)r�)�mdraid�raid)�errors)�DeviceFormat)�util)�pvs_info)�log_method_call)�udev)�Size)�availabilityZblivet�)�
StorageDevice)�ContainerDevice)�
RaidDevice)�get_majors_by_device_type�mdc
sbeZdZdZdZdgZdZedd��Zedd��Z	e
jgZdi�fdd�	Z
ed
d��Zedd��Zedd��Zejdd��Ze�fdd��Zedd��Zejdd��Zdd�Zedd��Zdd�Zedd ��Zdj�fd!d"�	Zed#d$��Zd%d&�Ze�fd'd(��Zed)d*��Zed+d,��Zd-d.�Zd/d0�Zed1d�d2d�d3d4�Z d5d6�Z!d7d8�Z"ee!e"�Z#�fd9d:�Z$�fd;d<�Z%ed=d>��Z&ed?d@��Z'dAdB�Z(edCdD��Z)edEdF��Z*edGdH��Z+edIdJ��Z,�fdKdL�Z-dkdMdN�Z.dl�fdOdP�	Z/dmdQdR�Z0dndSdT�Z1dUdV�Z2dWdX�Z3dYdZ�Z4d[d\�Z5ed]d^��Z6ed_d`��Z7edadb��Z8edcdd��Z9dedf�Z:�fdgdh�Z;�Z<S)o�MDRaidArrayDevicez  An mdraid (Linux RAID) device. ZmdarrayZmdadmz/dev/mdcCsdS)NZmdmember�)�srr�/usr/lib/python3.6/md.py�<lambda>>szMDRaidArrayDevice.<lambda>cCsdS)N�md_uuidr)rrrrr?sNF�csd|_d|_d|_tt|�j|||
|||
d�y
||_WnBtjk
rz}z$x|j	D]}|j
|�qTW|�WYdd}~XnX||_tj
|�|_tj
|�|_|jr�|j�|_n|p�td�|_|jr�t|t�r�d|_n||_|	|_|j	�r|j	djdk�r|jdk�rtjd��dS)a�
            :param name: the device name (generally a device node's basename)
            :type name: str
            :keyword exists: does this device exist?
            :type exists: bool
            :keyword size: the device's size
            :type size: :class:`~.size.Size`
            :keyword parents: a list of parent devices
            :type parents: list of :class:`StorageDevice`
            :keyword fmt: this device's formatting
            :type fmt: :class:`~.formats.DeviceFormat` or a subclass of it
            :keyword sysfs_path: sysfs device path
            :type sysfs_path: str
            :keyword chunk_size: chunk size for the device
            :type chunk_size: :class:`~.size.Size`
            :keyword uuid: the device UUID
            :type uuid: str

            :keyword level: the device's RAID level
            :type level: any valid RAID level descriptor
            :keyword int member_devices: the number of active member devices
            :keyword int total_devices: the total number of member devices
            :keyword metadata_version: the version of the device's md metadata
            :type metadata_version: str (eg: "0.90")
            :keyword minor: the device minor (obsolete?)
            :type minor: int

            .. note::

                An instance of this class whose :attr:`exists` attribute is
                True and whose parent/member devices are all partitionable is
                also considered to be partitionable.

            .. note::

                An instance of this class whose :attr:`exists` attribute is
                True and whose parent/member devices are all disks is also
                treated like a disk.

        rN)�uuid�exists�size�parents�
sysfs_path�default�mdcontainer�mdbiosraidarrayz9A device with mdcontainer member must be mdbiosraidarray.)�_member_devices�_total_devices�_level�superr�__init__�levelr�DeviceErrorrZremove_childrr	Znumeric_type�member_devicesr�read_chunk_size�_chunk_sizer
�
chunk_size�
isinstance�str�metadata_version�format�type)�self�namer)�major�minorrr+�
total_devicesr�fmtrr1rr r.�eZdev)�	__class__rrr(Bs20
&zMDRaidArrayDevice.__init__cCs<d}|jdk	r8ytjj|j�}Wntjk
r6YnX|S)z� This array's UUID, formatted for external use.

            :returns: the array's UUID in mdadm format, if available
            :rtype: str or NoneType
        N)r�blockdevrZget_md_uuid�MDRaidError)r4Zformatted_uuidrrr�mdadm_format_uuid�s
z#MDRaidArrayDevice.mdadm_format_uuidcCs|jS)z� Return the raid level

            :returns: raid level value
            :rtype:   an object that represents a RAID level
        )r&)r4rrrr)�szMDRaidArrayDevice.levelcCstjS)z, Allowed RAID level for this type of device.)rZraid_levels)r4rrr�_levels�szMDRaidArrayDevice._levelscCsJy|j||j�}Wn,tk
r>}ztj|��WYdd}~XnX||_dS)a Set the RAID level and enforce restrictions based on it.

            :param value: new raid level
            :param type:  object
            :raises :class:`~.errors.DeviceError`: if value does not describe
            a valid RAID level
            :returns:     None
        N)Z
_get_levelr?�
ValueErrorrr*r&)r4�valuer)r:rrrr)�s

cs,|js tdd�dd�|jD��Stt|�jS)NcSs||tj||�S)N)�mathZgcd)�a�brrrr�sz/MDRaidArrayDevice.sector_size.<locals>.<lambda>css|]}t|j�VqdS)N)�int�sector_size)�.0�prrr�	<genexpr>�sz0MDRaidArrayDevice.sector_size.<locals>.<genexpr>)rrrr'rrF)r4)r;rrrF�szMDRaidArrayDevice.sector_sizecCs:|jtd�kr4|jr|j�S|jtjkr.|jStjS|jS)Nr)	r-r
rr,r)r�RAID1rZ
MD_CHUNK_SIZE)r4rrrr.�szMDRaidArrayDevice.chunk_sizecCsft|t�std��|td�td�kr.td��|jr<td��|jtjkr\|td�kr\td��||_dS)Nz#new chunk size must be of type Sizez4 KiBrz(new chunk size must be multiple of 4 KiBz,cannot set chunk size for an existing devicez.specifying chunk size is not allowed for raid1)r/r
r@rr)rrJr-)r4�newsizerrrr.�s
cCs>t||j|j|jd�td�}|jr:ttj|jd�p6d�}|S)N)r�pathr rz
md/chunk_size�0)rrrLr r
�statusr	Zget_sysfs_attr)r4r.rrrr,�s
z!MDRaidArrayDevice.read_chunk_sizecCs@y$|jj�o$|jtd�ko$|jjdkStjk
r:dSXdS)z� Whether or not a bitmap should be created on the array.

            If the array is sufficiently small, a bitmap yields no benefit.

            If the array has no redundancy, a bitmap is just pointless.
        i�ZswapFN)r)�has_redundancyrr
r2r3r�	RaidError)r4rrr�
create_bitmap�s$zMDRaidArrayDevice.create_bitmapcCstjj||jd�S)acEstimate the superblock size for a member of an array,
           given the total available memory for this array and raid level.

           :param raw_array_size: total available for this array and level
           :type raw_array_size: :class:`~.size.Size`
           :returns: estimated superblock size
           :rtype: :class:`~.size.Size`
        )�version)r<r�get_superblock_sizer1)r4Zraw_array_sizerrrrSs	z%MDRaidArrayDevice.get_superblock_sizecCs�|js|jr�y(|jjdd�|jD�|j|j|j�}WnFtj	t
jfk
r~}z"tj
d|j|j|�td�}WYdd}~XnXtjd|j|�n|j}tjd|j|�|S)zfReturns the actual or estimated size depending on whether or
           not the array exists.
        cSsg|]
}|j�qSr)r)rG�drrr�
<listcomp>sz*MDRaidArrayDevice.size.<locals>.<listcomp>z;could not calculate size of device %s for raid level %s: %srNznon-existent RAID %s size == %szexisting RAID %s size == %s)r�
media_presentr)Zget_size�membersr+r.rSr<r=rrP�log�infor5r
�debug�current_size)r4rr:rrrrszMDRaidArrayDevice.sizecs |jdkrtt|�j|d�dS)Nr")rK)r3r'r�update_size)r4rK)r;rrr\(s
zMDRaidArrayDevice.update_sizecCs |jjr|jjn|jj}d|S)NzMDRAID set (%s))r)�nickr5)r4�levelstrrrr�description/szMDRaidArrayDevice.descriptioncCs0tj|�}|d|j|j|j|j|jd�7}|S)Nz�  level = %(level)s  spares = %(spares)s
  members = %(member_devices)s
  total devices = %(total_devices)s  metadata version = %(metadata_version)s)r)�sparesr+r8r1)r�__repr__r)r`r+r8r1)r4rrrrra4s
zMDRaidArrayDevice.__repr__cs4tt|�j}|jt|j�|j|j|j|j	d��|S)N)r)r`r+r8r1)
r'r�dict�updater0r)r`r+r8r1)r4rT)r;rrrb@szMDRaidArrayDevice.dictcCs@|j}|jdks|r&tjd|j��d}||j|j|j|fS)z  This array's mdadm.conf entry. Nzarray %s is not fully definedz)ARRAY %s level=%s num-devices=%d UUID=%s
)r>r+rr*r5rLr))r4rr9rrr�mdadm_conf_entryIs
z"MDRaidArrayDevice.mdadm_conf_entrycCs|js|jSt|j�SdS)z9 Total number of devices in the array, including spares. N)rr%�lenr)r4rrrr8SszMDRaidArrayDevice.total_devicescCs|jS)N)r$)r4rrr�_get_member_devices[sz%MDRaidArrayDevice._get_member_devicescCs8t|tj�std��|jr.||jkr.td��||_dS)Nz!member_devices must be an integerz3member_devices cannot be greater than total_devices)r/�sixZ
integer_typesr@rr8r$)r4Znumberrrr�_set_member_devices^s
z%MDRaidArrayDevice._set_member_devicescCs|j�S)N)rf)rTrrrrfscCs
|j|�S)N)rh)rT�mrrrrgsznumber of member devices)�doccCsNd}|jdk	rJ|jdk	r2|j|jkr2|j|j}n|jdkrJ|j}|j|_|S)Nr)r+r8r%)r4r`rrr�_get_sparesjs


zMDRaidArrayDevice._get_sparescCsL|jjt|j��}||kr2tjd||�tjd��|j|krH|j||_	dS)Nz-failed to set new spares value %d (max is %d)znew spares value is too large)
r)Zget_max_sparesrerrXrZrr*r8r+)r4r`Z
max_sparesrrr�_set_sparesus

zMDRaidArrayDevice._set_sparescsztt|�j|�|jr&|jjr&|j|_|jjsJ|jd7_|j	d7_	|j
oT|j
}x|jD]}||j_q^W||j_dS)Nr)
r'r�_add_parentrNr2rr[�_sizer%r+�is_diskrZ_hidden)r4�parentrorH)r;rrrm�szMDRaidArrayDevice._add_parentcs>|j|j|�}|rtj|��tt|�j|�|jd8_dS)Nr)�_validate_parent_removalr)rr*r'r�_remove_parentr+)r4rp�	error_msg)r;rrrr�s

z MDRaidArrayDevice._remove_parentcCsdS)z= Strings in state file for which status() should return True.�clean�active�active-idle�readonly�	read-auto)rtrurvrwrxr)r4rrr�_true_status_strings�sz&MDRaidArrayDevice._true_status_stringscCs�d}|js|Stjj|j�rn|jrn|j�tj|j�}tj|�}|rn||jkrnt	j
d|j||j�d|_|Sd|j}y"t|�j�j
�}||jkr�d}Wntk
r�d}YnX|S)z� This device's status.

            For now, this should return a boolean:
                True    the device is open and ready for use
                False   the device is not open
        Fz0md array %s is active, but has UUID %s -- not %srz%s/md/array_stateT)r�osrLr �update_sysfs_pathrZ
get_deviceZdevice_get_md_uuidrrXZwarning�open�read�stripry�OSError)r4rNrYrZ
state_file�staterrrrN�s(	



zMDRaidArrayDevice.statuscCs^|jo
|jsdStjj|j�}d|j|f}yt|�j�j�}Wntk
rXd}YnX|S)Nz/sys/%s/md/dev-%s/state)	rNrzrL�basenamer r|r}r~r)r4�member�member_namerLr�rrr�
member_status�s
zMDRaidArrayDevice.member_statuscCs<d}d|j}tj|tj�r8t|�j�j�}|dkr8d}|S)z7 Return True if the array is running in degraded mode. Fz%s/md/degraded�1T)r rz�access�R_OKr|r}r~)r4ZrcZ
degraded_file�valrrr�degraded�s
zMDRaidArrayDevice.degradedcCs
t|j�S)z[ Returns this array's members.

            :rtype: list of :class:`StorageDevice`
        )�listr)r4rrrrW�szMDRaidArrayDevice.memberscCs|jt|j�kp|jS)z� An MDRaidArrayDevice is complete if it has at least as many
            component devices as its count of active devices.
        )r+rerWr)r4rrr�complete�szMDRaidArrayDevice.completecCs*|jtjko(|jdko(tdd�|jD��S)N�0.90�1.0css|]}t|dd�VqdS)�bootableFN)�getattr)rGrHrrrrI�sz-MDRaidArrayDevice.bootable.<locals>.<genexpr>)r�r�)r)rrJr1�allr)r4rrrr��s
zMDRaidArrayDevice.bootablecstt|�j�|j�dS)N)r'r�_post_setupr{)r4)r;rrr��szMDRaidArrayDevice._post_setupcCs^t||j||j|jd�g}x&|jD]}|j|d�|j|j�q$Wtj	j
|j||jd�dS)z Open, or set up, a device. )�origrN�controllable)r�)rWrN)rr5rNr�rW�setup�appendrLr<rZactivater>)r4r��disksr�rrr�_setup�s
zMDRaidArrayDevice._setupcs$tt|�j|d�d|_tj�dS)N)�	recursiver)r'r�_post_teardownr r�settle)r4r�)r;rrr�sz MDRaidArrayDevice._post_teardowncCs^t||j|j|jd�|j|d�|jr,dS|jrNtjj|j�rNt	j
j|j�|j|d�dS)z  Close, or tear down, a device. )rNr�)r�N)
rr5rNr��
_pre_teardownrorrzrLr<rZ
deactivater�)r4r�rrr�teardowns
zMDRaidArrayDevice.teardowncCs(t||j�t|jdd�dkr$d|_dS)z* Determine create parameters for this set Z
mountpointNz	/boot/efiz1.0)rr5r�r2r1)r4Zcurrent_fmtrrr�pre_commit_fixup%sz"MDRaidArrayDevice.pre_commit_fixupcspd�_�j�tj��tjj�j�}|j�_x�j	D]}�j|j
_q6W�fdd�}|�t�jdd�j
�dS)NTcs�tjd�j�tjd�tj�tj�tj	j
�j�}|dkrBdS|jr�tjd�j
�y tjj|jdd|jid�Wn:tjk
r�}ztjd�jt|���WYdd}~XnXtjj�j�dS)	zT Remove any stale LVM metadata that pre-existed in a new array's on-disk footprint. z9waiting 5s for activation of stale lvm on new md array %s�Nz'removing stale LVM metadata found on %sz--selectz
vg_uuid=%s)ZextrazFFailed to remove stale volume group from newly-created md array %s: %s)rXrZrL�timeZsleeprr�r
Z
drop_cache�cache�getZvg_uuidrYr5r<ZlvmZvgremoveZvg_nameZLVMError�errorr0Zpvremove)Zpv_infor:)r4rr�remove_stale_lvm9s 
 z8MDRaidArrayDevice._post_create.<locals>.remove_stale_lvm)�devicer)rr{r�_post_creater<r�detailrLrrWr2rrZdestroy)r4rYr�r�r)r4rr�,s
zMDRaidArrayDevice._post_createc	Csxt||j|jd�dd�|jD�}t|j�|j}d}|jrFt|j�}tj	j
|j||||j|j
t|j�d�tj�dS)z Create the device. )rNcSsg|]
}|j�qSr)rL)rGZdiskrrrrUWsz-MDRaidArrayDevice._create.<locals>.<listcomp>N)rRZbitmapr.)rr5rNrWrer+r)r0r<rZcreaterLr1rQrEr.rr�)r4r�r`r)rrr�_createTs
zMDRaidArrayDevice._createcCs.|j�|j|�dk}tjj|j|j|�dS)NZin_sync)r�r�r<r�removerL)r4r�Zfailrrr�_removebszMDRaidArrayDevice._removec
Csp|j�d}y2|jj�s<|jtjk	r<ttjj|j	�j
�d}Wntjk
rTYnXtjj
|j|j|d�dS)z� Add a member device to an array.

           :param str member: the member's path

           :raises: blockdev.MDRaidError
        Nr)Z	raid_devs)r�r)rOrZLinearrEr<rr�r5�raid_devicesrrP�addrL)r4r�r�rrr�_addhs
zMDRaidArrayDevice._addcCs2g}|jjdkr.|jj|j�}|r.dd|g}|S)NZext2z-Rz	stride=%d)r2r3r)Zget_recommended_strider+)r4�format_argsZrecommended_striderrrr�{szMDRaidArrayDevice.format_argscCs|jS)N)r_)r4rrr�model�szMDRaidArrayDevice.modelcCs |jo|jotdd�|jD��S)Ncss|]}|jVqdS)N)�
partitionable)rGrHrrrrI�sz2MDRaidArrayDevice.partitionable.<locals>.<genexpr>)rrr�rW)r4rrrr��szMDRaidArrayDevice.partitionablecCs |jo|jotdd�|jD��S)Ncss|]}|jVqdS)N)ro)rGrHrrrrI�sz,MDRaidArrayDevice.is_disk.<locals>.<genexpr>)rrr�rW)r4rrrro�szMDRaidArrayDevice.is_diskcCstd|jg�S)Nz
rd.md.uuid=%s)�setr>)r4rrr�dracut_setup_args�sz#MDRaidArrayDevice.dracut_setup_argscsr|jr
dStt|�j|�|jj|_|j|_dd�|jD�|_|j	|_
|j|_|j	sn|jtj
krn|jjd�|_dS)NcSsg|]}d|j�qS)zraid.%d)�id)rGrHrrrrU�sz5MDRaidArrayDevice.populate_ksdata.<locals>.<listcomp>ZKiB)ror'r�populate_ksdatar)r5r`rrWrZpreexistr�rrJr.Z
convert_to)r4�data)r;rrr��s
z!MDRaidArrayDevice.populate_ksdata)
NNNNNNNNFNNrN)N)F)F)N)F)=�__name__�
__module__�__qualname__�__doc__�_typeZ	_packagesZ_dev_dir�property�_format_class_nameZ_format_uuid_attrrZBLOCKDEV_MDRAID_PLUGINZ_external_dependenciesr(r>r)r?�setterrFr.r,rQrSrr\r_rarbrdr8rfrhr+rkrlr`rmrrryrNr�r�rWr�r�r�r�r�r�r�r�r�r�r�r�r�r�ror�r��
__classcell__rr)r;rr8sxT			


$




(	rcs~eZdZdZ�fdd�Zedd��Zedd��Zedd	��Zed
d��Z	dd
d�Z
edd��Zedd��Zedd��Z
�ZS)�MDContainerDevicer"cs"tj|d<tt|�j|f|�dS)Nr))r�	Containerr'r�r()r4r5�kwargs)r;rrr(�s
zMDContainerDevice.__init__cCstjdg�S)N�	container)rZMDRaidLevels)r4rrrr?�szMDContainerDevice._levelscCsdS)NzBIOS RAID containerr)r4rrrr_�szMDContainerDevice.descriptioncCs(|j}|stjd|j��d|j|fS)Nzarray %s is not fully definedzARRAY %s UUID=%s
)r>rr*r5rL)r4rrrrrd�sz"MDContainerDevice.mdadm_conf_entrycCsdS)Nrtru�active-idlerw�	read-auto�inactive)rtrur�rwr�r�r)r4rrrry�sz&MDContainerDevice._true_status_stringsNcCs&t||j|j|jd�|j|d�dS)N)rNr�)r�)rr5rNr�r�)r4r�rrrr��s
zMDContainerDevice.teardowncCsdS)NFr)r4rrrrV�szMDContainerDevice.media_presentcCsdS)NFr)r4rrrro�szMDContainerDevice.is_diskcCsdS)NFr)r4rrrr��szMDContainerDevice.partitionable)N)r�r�r�r�r(r�r?r_rdryr�rVror�r�rr)r;rr��s
r�cs�eZdZdZedd��ZdZdZ�fdd�Ze�fdd��Z	e�fd	d
��Z
edd��Zed
d��Zedd��Z
edd��Zedd��Zdd�Z�fdd�Z�fdd�Zddd�Z�ZS)�MDBiosRaidArrayDevicer#cCsdS)Nr)rrrrr�szMDBiosRaidArrayDevice.<lambda>Tcs tt|�j|f|�|j|_dS)N)r'r�r(r[rn)r4r5r�)r;rrr(�szMDBiosRaidArrayDevice.__init__cstt|�jS)N)r'rro)r4)r;rrro�szMDBiosRaidArrayDevice.is_diskcstt|�jS)N)r'rr�)r4)r;rrr��sz#MDBiosRaidArrayDevice.partitionablecCs|jS)N)rn)r4rrrr�szMDBiosRaidArrayDevice.sizecCs |jjr|jjn|jj}d|S)NzBIOS RAID set (%s))r)r]r5)r4r^rrrr_�sz!MDBiosRaidArrayDevice.descriptioncCs(|j}|stjd|j��d|j|fS)Nzarray %s is not fully definedzARRAY %s UUID=%s
)r>rr*r5rL)r4rrrrrdsz&MDBiosRaidArrayDevice.mdadm_conf_entrycCs|jdjS)Nr)rrW)r4rrrrW	szMDBiosRaidArrayDevice.memberscCs|jdjS)Nr)rr8)r4rrrr8sz#MDBiosRaidArrayDevice.total_devicescCs|jdjS)Nr)rr+)r4rrrrfsz)MDBiosRaidArrayDevice._get_member_devicescs*tt|�j|�|jr&|jjr&|j|_dS)N)r'rrmrNr2rr[rn)r4rp)r;rrrmsz!MDBiosRaidArrayDevice._add_parentcs0|j|j|�}|rtj|��tt|�j|�dS)N)rqr)rr*r'rrr)r4rprs)r;rrrr s
z$MDBiosRaidArrayDevice._remove_parentNcCs&t||j|j|jd�|j|d�dS)N)rNr�)r�)rr5rNr�r�)r4r�rrrr�(s
zMDBiosRaidArrayDevice.teardown)N)r�r�r�r�r�r�Z_is_diskZ_partitionabler(ror�rr_rdrWr8rfrmrrr�r�rr)r;rr��s 	r�)*rBrzrgr�Z	six.movesrZgiZrequire_versionZ
gi.repositoryrr<Z
devicelibsrrrrZformatsrr	Zstatic_datar
Zstorage_logrrrr
ZtasksrZloggingZ	getLoggerrXZstoragerr�rr�librZ	MD_MAJORSrr�r�rrrr�<module>s<
q7