HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/btrfs.cpython-310.pyc
o

�N�gń�@svdZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
dd�Zdd�Zdd	�Z
d
d�Zdd
�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�ZdEd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�ZdFd-d.�Zd/d0�Z dFd1d2�Z!dGd3d4�Z"d5d6�Z#d7d8�Z$d9d:�Z%	"	"	"	"	"	"	"	"	"	"	"			dHd;d<�Z&d=d>�Z'd?d@�Z(dIdAdB�Z)dFdCdD�Z*dS)Jz)
Module for managing BTRFS file systems.
�N)�CommandExecutionErrorcCstjj��o
t�d�dkS)z)
    Only work on POSIX-like systems
    Zkernel�Linux)�salt�utils�platformZ
is_windowsZ
__grains__�get�rr�F/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/btrfs.py�__virtual__sr
cCs:tdd�}|�d�rt|d��d|d�dd�diS)	zk
    Return BTRFS version.

    CLI Example:

    .. code-block:: bash

        salt '*' btrfs.version
    �cmd.run_allzbtrfs --version�stderr�version�stdout� ����)�__salt__rr�split��outrrr	r
%s

r
cCs�i}dd�|�d�D�dd�D]H}|�d�r9t�dd|�}d	d
�|�d�D�\}}|dkr0|p1d|d
<||d<q|�d�rXt�d|���}|d}|d|d|dd�||<q|S)z'
    Parse BTRFS device info data.
    cSsg|]}|r|�qSrr��.0�linerrr	�
<listcomp>:�z%_parse_btrfs_info.<locals>.<listcomp>�
NrzLabel:z	Label:\s+�css�|]}|��VqdS�N��strip)rZtknrrr	�	<genexpr>=��z$_parse_btrfs_info.<locals>.<genexpr>zuuid:Znone�label�uuidz	devid�\s+r��)Z	device_id�size�used)r�
startswith�re�subr)�data�retrr"Zuuid_Zdev_dataZdev_idrrr	�_parse_btrfs_info5s" 


��r.cCs,tdd|���}tjj�|�t|d�S)z~
    Get BTRFS filesystem information.

    CLI Example:

    .. code-block:: bash

        salt '*' btrfs.info /dev/sda1
    rzbtrfs filesystem show r)rrr�fsutils�_verify_runr.)�devicerrrr	�infoNs
r2cCs0tdd�}tjj�|�tjjj|ddd�S)z�
    Get known BTRFS formatted devices on the system.

    CLI Example:

    .. code-block:: bash

        salt '*' btrfs.devices
    r�blkid -o exportr�btrfs)Zfs_type)rrrr/r0�
_blkid_outputrrrr	�devices^s
r6cCs.tdd|���}||d|dpddd�S)z/
    Defragment only one BTRFS mountpoint.
    rzbtrfs filesystem defragment -f rF)�mount_point�passed�log�range�r)�
mountpointrrrr	�_defragment_mountpointns
�r=c	Cs�tjj�|�}tjj�d�}|r|�|�std|�d���g}|r3||D]}|�t|d��q%|Sd}|�	�D]}|D]}||dkrId}nq=q9t|�}|s_|ds_d|d	vr_d
|d	<|sqd|d<t
j�|�rm|pnd|d<|�|�|S)a�
    Defragment mounted BTRFS filesystem.
    In order to defragment a filesystem, device should be properly mounted and writable.

    If passed a device name, then defragmented whole filesystem, mounted on in.
    If passed a moun tpoint of the filesystem, then only this mount point is defragmented.

    CLI Example:

    .. code-block:: bash

        salt '*' btrfs.defragment /dev/sda1
        salt '*' btrfs.defragment /path/on/filesystem
    r4�Device "z" is not mountedr7FTr8zrange ioctl not supportedr9z<Range ioctl defragmentation is not supported in this kernel.r:)
rrr/�
_is_device�_get_mountsrr�appendr=�values�os�path�exists)	rDZ	is_device�mounts�resultr7Z
is_mountpointZmountpointsZmpntZd_resrrr	�
defragment{s<������
rHcCsXtdd�}tjj�|�i}dd�|d�d�D�D]}|�dd�\}}|||<q|S)	z�
    List currently available BTRFS features.

    CLI Example:

    .. code-block:: bash

        salt '*' btrfs.mkfs_features
    rzmkfs.btrfs -O list-allcSs"g|]
}d|vrt�dd|��qS)� - r$r)r*r+rrrr	r�szfeatures.<locals>.<listcomp>rrrIr)rrrr/r0r)rr-r�option�descriptionrrr	�features�s

�
rLcCs�i}|�d�dd�D]Y}dd�t�dd|��dd�D�}t|�d	krdt�d
d|d��dd
���}|dvr^|d�d�}|d��||<|d�dd��d�}|d||�d
|d��<q|d||<q|S)z
    Parse usage/overall.
    rrNcSsg|]
}|��r|���qSrr�r�itemrrr	r�s��z"_usage_overall.<locals>.<listcomp>r$r�:�z[()]rr�_)Zfree_estimatedZglobal_reserve�(�)z: )rr*r+�len�replace�lowerr)�rawr,r�keyset�keyZsubkrrr	�_usage_overall�s��rZc
Cs�dd�}|�d�}|d�d�\}}}|�dd��dd	���}i}i||<||fD]}||�||�dd	���q)|d
d�D]}||�|t�dd|�����q?|S)
z
    Parse usage/specific.
    cSstt|�d��g�S)NrO)�dict�tupler)�valrrr	�get_key�sz _usage_specific.<locals>.get_keyrrr�,rQrOrrNr$)rrUrV�updater*r+r)rWr^�sectionr'r(r,r]r6rrr	�_usage_specific�s
"rbcCsTi}|�d�dd�D]}t�dd|����d�}t|�dkr'|d||d<q|S)z"
    Parse usage/unallocated.
    rrNr$rrPr)rr*r+rrT)rWr-rrXrrr	�_usage_unallocated�s�rccCsztdd|���}tjj�|�i}|d�d�D]!}|�d�r't|�|d<q|�d�r3t|�|d<q|�	t
|��q|S)	z�
    Show in which disk the chunks are allocated.

    CLI Example:

    .. code-block:: bash

        salt '*' btrfs.usage /your/mountpoint
    rzbtrfs filesystem usage rz

z	Overall:
Zoverallz
Unallocated:
Zunallocated)rrrr/r0rr)rZrcr`rb)rDrr-rarrr	�usages


rdcOs�|std��tjj�d�}|D]}|�|�rtd|�d���qdg}|�d�}|�d�}t|�dkrA|r9|�d	�|r@|�d
�n|rK|�d|���|rU|�d|���d
D]'\}}|dkrl||vrld�|d�|d<|�|�r~|�|�d|�|����qW|�d�r�|�d�|�d�dur�t	�
�p�|�d���|�d�r�|�d�|�d�s�|�d�|�|�tdd�
|��}	tjj�|	�d|	di}
|
�td|d��|
S)a2
    Create a file system on the specified device. By default wipes out with force.

    General options:

    * **allocsize**: Specify the BTRFS offset from the start of the device.
    * **bytecount**: Specify the size of the resultant filesystem.
    * **nodesize**: Node size.
    * **leafsize**: Specify the nodesize, the tree block size in which btrfs stores data.
    * **noforce**: Prevent force overwrite when an existing filesystem is detected on the device.
    * **sectorsize**: Specify the sectorsize, the minimum data block allocation unit.
    * **nodiscard**: Do not perform whole device TRIM operation by default.
    * **uuid**: Pass UUID or pass True to generate one.


    Options:

    * **dto**: (raid0|raid1|raid5|raid6|raid10|single|dup)
               Specify how the data must be spanned across the devices specified.
    * **mto**: (raid0|raid1|raid5|raid6|raid10|single|dup)
               Specify how metadata must be spanned across the devices specified.
    * **fts**: Features (call ``salt <host> btrfs.features`` for full list of available features)

    See the ``mkfs.btrfs(8)`` manpage for a more complete description of corresponding options description.

    CLI Example:

    .. code-block:: bash

        salt '*' btrfs.mkfs /dev/sda1
        salt '*' btrfs.mkfs /dev/sda1 noforce=True
    zNo devices specifiedr4r>z" should not be mountedz
mkfs.btrfs�dto�mtorz	-d singlez	-m singlez-d z-m ))z-lZleafsize)z-Lr")z-OZfts)z-AZ	allocsize)z-bZ	bytecount)z-nZnodesize)�-sZ
sectorsizer"z'{}'rr#z-U {}T�	nodiscard�-KZnoforce�-frr9r�
btrfs.infor)rrrr/r@rrTrA�formatr#Zuuid1�extendr�joinr0r`)r6�kwargsrFr1�cmdrerfrYrJrr-rrr	�mkfssT!
�



�	
�
��




rqcCs�|dkr&tjj�|�std|�d���tjj�d��|�s%td|�d���n(t|�dksG|dd	vsG|d
dvsGt�	dd
|dd�dd
��rNtd�
|���tdd|�d|���}tjj�|�d|di}|�
td|��|S)aY
    Resize filesystem.

    General options:

    * **mountpoint**: Specify the BTRFS mountpoint to resize.
    * **size**: ([+/-]<newsize>[kKmMgGtTpPeE]|max) Specify the new size of the target.

    CLI Example:

    .. code-block:: bash

        salt '*' btrfs.resize /mountpoint size=+1g
        salt '*' btrfs.resize /dev/sda1 size=max
    �maxzMountpoint "z" should be a valid devicer4r>z" should be mountedr%rz-+rZkKmMgGtTpPeEz\drrNz>Unknown size: "{}". Expected: [+/-]<newsize>[kKmMgGtTpPeE]|maxrzbtrfs filesystem resize rr9rrk)rrr/r?rr@rrTr*r+rlrr0r`)r<r'rr-rrr	�resizews.
�����rsc	Cs4ddddddddd	�}|�td
d|���dd
�S)z�
    Check an ext2/ext3/ext4 file system.

    This is forced check to determine a filesystem is clean or not.
    NOTE: Maybe this function needs to be moved as a standard method in extfs module in a future.
    z	No errorszFilesystem errors correctedzSystem should be rebootedz"Filesystem errors left uncorrectedzOperational errorzUsage or syntax errorzFsck canceled by user requestzShared-library error)rrrP���� �rzfsck -f -n �retcodez
Unknown error)rr)r1Zmsgsrrr	�	_fsck_ext�s��rzFcCs�tdd�}tjj�|�tjj�|d�}|�|�s#td|�d���||ddvr7td�|||d���tjj�	||d��|d	d
ig�d�d	�}|dkrVtd
��tjj�tdd|����dt
|�|||dd�i}tjj�tdd|����tjj�tdd|�d|����tdd�}tjj�|�tjj�|d�}d|||dd�|d<|�d�}|dd}tj�
|�s�td|�d���|s�||d|�d�<tjd|�d�gdtjd�}	|	j��|d|�d�<n8d|d|�d�<d|d|�d�<tjj�tdd |����tdd!|���}tjj�|�|d|dd"<|�d#�}
tj�
|
��rG|�sGtjj�tdd$|
����|S)%a�
    Convert ext2/3/4 to BTRFS. Device should be mounted.

    Filesystem can be converted temporarily so the further processing and rollback is possible,
    or permanently, where previous extended filesystem image gets deleted. Please note, permanent
    conversion takes a while as BTRFS filesystem needs to be properly rebalanced afterwards.

    General options:

    * **permanent**: Specify if the migration should be permanent (false by default)
    * **keeplf**: Keep ``lost+found`` of the partition (removed by default,
                  but still in the image, if not permanent migration)

    CLI Example:

    .. code-block:: bash

        salt '*' btrfs.convert /dev/sda1
        salt '*' btrfs.convert /dev/sda1 permanent=True
    rr3rzThe device "z" was is not found.�type)Zext2Zext3Zext4z&The device "{}" is a "{}" file system.r7Nr�/abOne does not simply converts a root filesystem!

Converting an extended root filesystem to BTRFS is a careful
and lengthy process, among other steps including the following
requirements:

  1. Proper verified backup.
  2. System outage.
  3. Offline system access.

For further details, please refer to your OS vendor
documentation regarding this topic.
zumount �before)Zfsck_statusr7r{zbtrfs-convert zmount r�N/A�afterz/ext2_savedz'BTRFS migration went wrong: the image "z" not found!Z_image�filez/imageT)�checkrZ_image_infoZremovedzbtrfs subvolume delete �btrfs filesystem balance Zbalance_logz/lost+foundzrm -rf )rrrr/r0r5rrrlr@rzrCrDrE�
subprocess�run�PIPErr)r1Z	permanentZkeeplfrr6r<r-Z
image_pathZorig_fstypeZimage_info_procZ
lost_foundrrr	�convert�s|
�����
���

�

���
r�cOs�g}tjj�|�rtd|�d���d}tjj�d���D]\}}|D]}|d|kr.d}nq"q|s:td|�d���|s@td	��td
�}	|D]}||	��vrWtd|�d���qGd
|��g}
|D]}|
�	|�q`|dkr�|�
d�rv|
�	d�|�
d�r�|
�	d�|
�	|�tdd�|
��}tjj�|�|dr�|�	|d�|dkr�d}|�
d�}|�
d�}
|r�|
r�tdd�
||
|��}n	tdd|���}tjj�|�|dr�|�	|d�i}|r�|�dd�|�i�|�td|��|S)zW
    Restripe BTRFS: add or remove devices from the particular mounted filesystem.
    z#Mountpount expected, while device "�" specifiedFr4r7TzNo BTRFS device mounted on "z" mountpointzNo devices specified.z
btrfs.devicesr>z" is not recognizedz
btrfs device �addrhri�forcerjrrrNZdcZmcz0btrfs balance start -dconvert={} -mconvert={} {}r�r9rrk)rrr/r?rr@�itemsr�keysrArrnr0rlr`)r<�	directionr6roZfs_logZmountedr1Z	mntpointsZmntdataZavailable_devicesrprZdata_conversionZmeta_conversionr-rrr	�	_restripe0sp
���
�
�






��r�cO�t|dg|�Ri|��S)a$
    Add a devices to a BTRFS filesystem.

    General options:

    * **nodiscard**: Do not perform whole device TRIM
    * **force**: Force overwrite existing filesystem on the disk

    CLI Example:

    .. code-block:: bash

        salt '*' btrfs.add /mountpoint /dev/sda1 /dev/sda2
    r��r��r<r6rorrr	r�ysr�cOr�)z�
    Remove devices from a BTRFS filesystem.

    CLI Example:

    .. code-block:: bash

        salt '*' btrfs.delete /mountpoint /dev/sda1 /dev/sda2
    �deleter�r�rrr	r��s
r�cCsBi}|�d�D]}t�d|d�}t|�dkr|d||d<q|S)z 
    Parse properties list.
    rr$rrPr)rr*rT)r,rrrrr	�_parse_proplist�s�r�c
CsH|r|dvrtd|�d���dg}|�d�|�|rdpd�|r)|�d|���|�|�|r\zd	d
�|�d�D�D]\}}|�|�|�|�q;Wnty[}zt|��d}~wwtd
d�|��}tjj�	|�|s�i}t
|d���D]'\}	}
d|
i||	<td
d|�d|	���d}|r�|�d�dp�d||	d<qx|SdS)aM
    List properties for given btrfs object. The object can be path of BTRFS device,
    mount point, or any directories/files inside the BTRFS filesystem.

    General options:

    * **type**: Possible types are s[ubvol], f[ilesystem], i[node] and d[evice].
    * **force**: Force overwrite existing filesystem on the disk
    * **set**: <key=value,key1=value1...> Options for a filesystem properties.

    CLI Example:

    .. code-block:: bash

        salt '*' btrfs.properties /mountpoint
        salt '*' btrfs.properties /dev/sda1 type=subvol set='ro=false,label="My Storage"'
    )�sZsubvol�fZ
filesystem�i�inode�dr1zUnknown property type: "r�r4�property�set�listz-tcSs g|]}dd�|�d�D��qS)cSsg|]}|���qSrrrMrrr	r�rz)properties.<locals>.<listcomp>.<listcomp>�=)r)rrXrrr	r�s��zproperties.<locals>.<listcomp>r_NrrrrKzbtrfs property get r�rr~�value)rrAr�	Exceptionrrnrrr/r0r�r�)�objr{r�rprYr��exrr-ZpropZdescrrrr	�
properties�s@


�
���� �r�cCs ddd|g}td|dd�dkS)z�
    Check if a subvolume is present in the filesystem.

    path
        Mount point for the subvolume (full path)

    CLI Example:

    .. code-block:: bash

        salt '*' btrfs.subvolume_exists /mnt/var

    r4�	subvolume�showzcmd.retcodeT)Zignore_retcoderr;)rDrprrr	�subvolume_exists�sr�cCs�|rt|�turtd��|rtj�||�}t|�rdSgd�}t|�tur/|�d�|�|�|�|�t	d|�}t
jj�
|�dS)aj
    Create subvolume `name` in `dest`.

    Return True if the subvolume is created, False is the subvolume is
    already there.

    name
         Name of the new subvolume

    dest
         If not given, the subvolume will be created in the current
         directory, if given will be in /dest/name

    qgroupids
         Add the newly created subcolume to a qgroup. This parameter
         is a list

    CLI Example:

    .. code-block:: bash

        salt '*' btrfs.subvolume_create var
        salt '*' btrfs.subvolume_create var dest=/mnt
        salt '*' btrfs.subvolume_create var qgroupids='[200]'

    z"Qgroupids parameter must be a listF)r4r��createz-irT)r{r�rrCrDrnr�rArmrrrr/r0)�name�destZ	qgroupidsrp�resrrr	�subvolume_create�s


r�cCs�|s|r
t|�tustd��|r|dvrtd��dd�t�|g|p"g�D�}|s*dSgd�}|dkr8|�d	�n	|d
krA|�d�|�|�td|�}tj	j
�|�d
S)aS
    Delete the subvolume(s) from the filesystem

    The user can remove one single subvolume (name) or multiple of
    then at the same time (names). One of the two parameters needs to
    specified.

    Please, refer to the documentation to understand the implication
    on the transactions, and when the subvolume is really deleted.

    Return True if the subvolume is deleted, False is the subvolume
    was already missing.

    name
        Name of the subvolume to remove

    names
        List of names of subvolumes to remove

    commit
        * 'after': Wait for transaction commit at the end
        * 'each': Wait for transaction commit after each delete

    CLI Example:

    .. code-block:: bash

        salt '*' btrfs.subvolume_delete /var/volumes/tmp
        salt '*' btrfs.subvolume_delete /var/volumes/tmp commit=after

    z&Provide a value for the name parameter)r�eachzValue for commit not recognizedcSsg|]
}|rt|�r|�qSr)r�)r�nrrr	rMs���z$subvolume_delete.<locals>.<listcomp>F)r4r�r�rz--commit-afterr�z
--commit-eachrT)r{r�r�	itertools�chainrArmrrrr/r0)r��namesZcommitrpr�rrr	�subvolume_delete&s$ �

r�cCs\ddd||g}td|�}tjj�|�|d��}dd�|D�}|d��d}||d	�S)
a
    List the recently modified files in a subvolume

    name
        Name of the subvolume

    last_gen
        Last transid marker from where to compare

    CLI Example:

    .. code-block:: bash

        salt '*' btrfs.subvolume_find_new /var/volumes/tmp 1024

    r4r�zfind-newrrcSs"g|]
}|�d�r|��d�qS)r�r)r)r)r�lrrr	rys"z&subvolume_find_new.<locals>.<listcomp>r)�files�transid)rrrr/r0�
splitlinesr)r�Zlast_genrpr��linesr�r�rrr	�subvolume_find_newas�r�cCsTddd|g}td|�}tjj�|�|d��}|��d}|��d}||d�S)	z�
    Get the default subvolume of the filesystem path

    path
        Mount point for the subvolume

    CLI Example:

    .. code-block:: bash

        salt '*' btrfs.subvolume_get_default /var/volumes/tmp

    r4r�zget-defaultrrrr)�idr�)rrrr/r0rr)rDrpr�rZid_r�rrr	�subvolume_get_default�s
�r�cCsLd}|�|�r |t|�d���}|r|}d}n|�dd�\}}||��fS)a/
    Helper for the line parser.

    If key is a prefix of line, will remove ir from the line and will
    extract the value (space separation), and the rest of the line.

    If use_rest is True, the value will be the rest of the line.

    Return a tuple with the value and the rest of the line.
    Nrrr)r)rTrr)rrYZuse_restr�rrr	�_pop�s
r�csr|rt|�turtd��dd�t�dd�D��|r(t�fdd�|D��s(td��gd	�}|d
f|df|df|d
f|df|df|df|df|	df|
df|dff}|�dd�|D��|rb|�d|g�|
rk|�d|
g�|rx|�d�d�	|���|�|�t
d|�}tjj
�|�d}g}|d��D]"}i}|D]}t|||dk�\}}|r�|||��<q�|s�|�|�q�|S)aM
    List the subvolumes present in the filesystem.

    path
        Mount point for the subvolume

    parent_id
        Print parent ID

    absolute
        Print all the subvolumes in the filesystem and distinguish
        between absolute and relative path with respect to the given
        <path>

    ogeneration
        Print the ogeneration of the subvolume

    generation
        Print the generation of the subvolume

    subvolumes
        Print only subvolumes below specified <path>

    uuid
        Print the UUID of the subvolume

    parent_uuid
        Print the parent uuid of subvolumes (and snapshots)

    sent_subvolume_uuid
        Print the UUID of the sent subvolume, where the subvolume is
        the result of a receive operation

    snapshots
        Only snapshot subvolumes in the filesystem will be listed

    readonly
        Only readonly subvolumes in the filesystem will be listed

    deleted
        Only deleted subvolumens that are ye not cleaned

    generation_cmp
        List subvolumes in the filesystem that its generation is >=,
        <= or = value. '+' means >= value, '-' means <= value, If
        there is neither '+' nor '-', it means = value

    ogeneration_cmp
        List subvolumes in the filesystem that its ogeneration is >=,
        <= or = value

    sort
        List subvolumes in order by specified items. Possible values:
        * rootid
        * gen
        * ogen
        * path
        You can add '+' or '-' in front of each items, '+' means
        ascending, '-' means descending. The default is ascending. You
        can combite it in a list.

    CLI Example:

    .. code-block:: bash

        salt '*' btrfs.subvolume_list /var/volumes/tmp
        salt '*' btrfs.subvolume_list /var/volumes/tmp path=True
        salt '*' btrfs.subvolume_list /var/volumes/tmp sort='[-rootid]'

    zSort parameter must be a listcSsg|]\}}d�||f��qS)r)rn)r�orderZattribrrr	rs��z"subvolume_list.<locals>.<listcomp>)�-r�+)Zrootid�genZogenrDc3s�|]}|�vVqdSrr)rr��Zvalid_sortsrr	r r!z!subvolume_list.<locals>.<genexpr>zValue for sort not recognized)r4r�r�z-pz-az-cz-gz-oz-uz-qz-Rrg�-rz-dcss �|]}|dr|dVqdS)rrNr)r�prrr	r /s�z-Gz-Cz	--sort={}r_r)
�IDr�Zcgen�parentz	top levelZotime�parent_uuidZ
received_uuidr#rDrrD)r{r�rr��product�allrmrArlrnrrrr/r0r�r�rV)rDZ	parent_id�absoluteZogenerationZ
generationZ
subvolumesr#r�Zsent_subvolume_uuidZ	snapshots�readonlyZdeletedZgeneration_cmpZogeneration_cmp�sortrp�paramsr��columnsrGr�tablerYr�rr�r	�subvolume_list�sZW���


�
�r�cCs,ddd||g}td|�}tjj�|�dS)z�
    Set the subvolume as default

    subvolid
        ID of the new default subvolume

    path
        Mount point for the filesystem

    CLI Example:

    .. code-block:: bash

        salt '*' btrfs.subvolume_set_default 257 /var/volumes/tmp

    r4r�zset-defaultrT)rrrr/r0)ZsubvolidrDrpr�rrr	�subvolume_set_defaultbsr�c	Cs�ddd|g}td|�}tjj�|�i}i}|d��}|�d�}|||��<|D]}|�dd�\}}|��||�	���<q*|S)	z�
    Show information of a given subvolume

    path
        Mount point for the filesystem

    CLI Example:

    .. code-block:: bash

        salt '*' btrfs.subvolume_show /var/volumes/tmp

    r4r�r�rrrrOr)
rrrr/r0r��poprrrV)	rDrpr�rGr�rrYrr�rrr	�subvolume_showzs
r�cCs�|s|std��gd�}|r|�d�|�|�|r!|s!|�|�|r,|r,tj�||�}|r3|�|�td|�}tjj�	|�dS)a�
    Create a snapshot of a source subvolume

    source
        Source subvolume from where to create the snapshot

    dest
        If only dest is given, the subvolume will be named as the
        basename of the source

    name
       Name of the snapshot

    read_only
        Create a read only snapshot

    CLI Example:

    .. code-block:: bash

        salt '*' btrfs.subvolume_snapshot /var/volumes/tmp dest=/.snapshots
        salt '*' btrfs.subvolume_snapshot /var/volumes/tmp name=backup

    z%Provide parameter dest, name, or both)r4r�Zsnapshotr�rT)
rrArCrDrnrrrr/r0)�sourcer�r�Z	read_onlyrpr�rrr	�subvolume_snapshot�s



r�cCsh|rt|�turtd��gd�}|r|�d|g�|�|�|r%|�|�td|�}tjj�	|�dS)a�
    Wait until given subvolume are completely removed from the
    filesystem after deletion.

    path
        Mount point for the filesystem

    subvolids
        List of IDs of subvolumes to wait for

    sleep
        Sleep N seconds betwenn checks (default: 1)

    CLI Example:

    .. code-block:: bash

        salt '*' btrfs.subvolume_sync /var/volumes/tmp
        salt '*' btrfs.subvolume_sync /var/volumes/tmp subvolids='[257]'

    z"Subvolids parameter must be a list)r4r��syncrgrT)
r{r�rrmrArrrr/r0)rDZ	subvolids�sleeprpr�rrr	�subvolume_sync�s

r�)FF)NN)NNN)FFFFFFFFFFFNNN)NNF)+�__doc__r�rCr*r�r#Zsalt.utils.fsutilsrZsalt.utils.platformZsalt.exceptionsrr
r
r.r2r6r=rHrLrZrbrcrdrqrsrzr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrr	�<module>sp
2
]-
tI

?

0;!%
�&
!.