Current File : //usr/share/netplan/netplan_cli/cli/commands/__pycache__/sriov_rebind.cpython-312.pyc
�

Z9
g�����dZddlZddlZddlZddlmZddlmZddlm	Z	m
Z
mZddlZdZ
dZd	ZGd
�de�ZGd�d
e�ZGd�de�ZGd�dej(�Zy)z"netplan SR-IOV rebind command line�N)�sleep�)�utils)�	PCIDevice�bind_vfs�_get_pci_slot_name�g�������?�c��eZdZy)�MLX5VFLAGStateNotFoundN��__name__�
__module__�__qualname__���;/usr/share/netplan/netplan_cli/cli/commands/sriov_rebind.pyrr#���rrc��eZdZy)�MLX5VFLAGStateCannotBeReadNr
rrrrr'rrrc��eZdZy)�MLX5VFLAGStateDisabledNr
rrrrr+rrrc�f��eZdZ�fd�Zd�Zd�Zdedefd�Zdefd�Z	ded	e
fd
�Zded	efd�Z�xZ
S)
�NetplanSriovRebindc�*��t�|�ddd��y)N�rebindzKRebind SR-IOV virtual functions of given physical functions to their driverT)�
command_id�description�leaf)�super�__init__)�self�	__class__s �rr!zNetplanSriovRebind.__init__1s���
���H�%r�"�	�	$rc��|jjddd��|jjdtdgd��|j|_tjd	�|_d
|j_tjtj��}|j�|jrm|jjt
j�|jt
j�|j!tj"d��nl|jjt
j$�|jt
j$�|j!tj"d
��|jj'|�|j)�y)Nz
--root-dir�/zBSearch for configuration files in this root directory instead of /)�default�help�netdevs�*z*Space separated list of PF interface names)�type�nargsr&r'�sriov_rebindF)�streamz%(levelname)s:%(message)sz%(message)s)�parser�add_argument�str�command_rebind�func�logging�	getLogger�logger�	propagate�
StreamHandler�sys�stdout�
parse_args�debug�setLevel�DEBUG�setFormatter�	Formatter�INFO�
addHandler�run_command)r"�log_handlers  r�runzNetplanSriovRebind.run6s7����� � ��s�&j�	!�	l���� � ���C��&R�	!�	T��'�'��	��'�'��7��� %������+�+�3�:�:�>�������:�:��K�K� � ����/�� � ����/��$�$�W�%6�%6�7R�%S�T��K�K� � ����.�� � ����.��$�$�W�%6�%6�}�%E�F������{�+����rc	��|jD]�}t|�}t|�}|js+|jjdj
|���P|j||�t|j|j�}|jjdj
|t|�����y)zeBind virtual functions of SR-IOV devices to their corresponding driver after eswitch mode was changedz1{} does not seem to be a SR-IOV physical functionz{}: bound {} VFsN)r(rr�is_pfr5r;�format�!_perform_hardware_specific_quirksr�vfs�driver�len)r"�iface�pci_addr�pcidev�	bound_vfss     rr1z!NetplanSriovRebind.command_rebindQs����\�\�
	Q�E�)�%�0�H��x�(�F��<�<����!�!�"U�"\�"\�]b�"c�d��

�2�2�5�&�A� ����V�]�]�;�I��K�K���0�7�7���I��O�P�
	QrrL�pfc��|jdv�rJtj�}|j|j�tj
�}|j
|�|jj�D]�}|jr|j|k(s|j|k(s�.|jjd�x}s�L|j}|j|�s"|j j#|�d|�d����|j j#|�d��	|j%|�|j j#|�d����y
y
#t&$r"|j j#|�d��Y��t($r"|j j#|�d��Y��0t*$r"|j j#|�d	��Y��YwxYw)z�
        Perform any hardware-specific quirks for the given SR-IOV device to make
        sure it's ready before the bind.
        )�	mlx5_core�bondz - LAG mode z is not supported by VF LAGz+ - waiting for the LAG state to be 'active'z - VF LAG state is 'active'z - VF LAG state cannot be readz& - VF LAG state debugfs file not foundz1 - VF LAG state is still 'disabled' after waitingN)rJ�netplan�Parser�load_yaml_hierarchy�root_dir�State�import_parser_results�	ethernets�values�
_has_match�set_name�id�links�get�
_bond_mode�_is_bond_mode_supportedr5r;�"_wait_for_mlx5_pf_lag_state_activerrr)r"rLrPr.�np_state�netdef�	bond_link�	bond_modes        rrHz4NetplanSriovRebind._perform_hardware_specific_quirksbs����9�9�
�%��^�^�%�F��&�&�t�}�}�5��}�}��H��*�*�6�2�"�,�,�3�3�5�
W���%�%�&�/�/�U�*B�v�y�y�TY�GY�$*�L�L�$4�$4�V�$<�<�y�<�%.�$8�$8�	�#�;�;�I�F� �K�K�-�-���|�I�;�Ni�.j�k�$����)�)�U�G�3`�*a�b�	W� �C�C�B�G�!�K�K�-�-���7T�.U�V�7
W�&��8 :�X� �K�K�-�-���7U�.V�W�5�`� �K�K�-�-���7]�.^�_�5�m� �K�K�-�-���7j�.k�l�m�s�(E�'G�&G�.&G�Gc��tttz�}|j}d|�d�}tj
j
|�stt�t�|dkDrP	|j|�dk7r.|jj|�d��tt�ny	|dz
}|dkDr�Pt�#t$rt�wxYw)z�
        The mlx5 driver added support for debugfs in https://github.com/torvalds/linux/commit/7f46a0b7327a
        It's available since kernel 5.19 https://cdn.kernel.org/pub/linux/kernel/v5.x/ChangeLog-5.19
        �/sys/kernel/debug/mlx5/�
/lag/stater�activez, VF LAG state is not active yet, retrying...N�)�int�MAX_WAITING_TIME_SEC�INTERVAL_SECrM�os�path�existsr�FALLBACK_WAIT_TIME_SECr�_get_mlx5_vf_lag_stater5r;�	Exceptionrr)r"rP�retriesrMrqs     rrcz5NetplanSriovRebind._wait_for_mlx5_pf_lag_state_active�s���
�*�\�9�:���;�;��(��
�*�=���w�w�~�~�d�#�
�(�)�(�(���k�

1��.�.�x�8�H�D��K�K�%�%��
�2^�&_�`��,�'��(���k�G���k�%�$���
1�0�0�
1�s
�#AB8�8C�mode�returnc�
�|dvS)zx
        Return True or False if the bond mode is one of the supported modes
        for the VG LAG activation.
        )z
active-backupzbalanced-xorz802.3adr)r"rws  rrbz*NetplanSriovRebind._is_bond_mode_supported�s��
�C�C�CrrMc��d|�d�}t|d�5}|j�j�cddd�S#1swYyxYw)Nrirj�r)�open�read�strip)r"rMrq�fs    rrtz)NetplanSriovRebind._get_mlx5_vf_lag_state�s@��(��
�*�=��
�$��_�	$���6�6�8�>�>�#�	$�	$�	$�s	�;�A)rrrr!rDr1r0rrHrc�boolrbrt�
__classcell__)r#s@rrr/s`���$�
�6Q�")W�s�)W�	�)W�V"%�Y�"%�HD�C�D�D�D�$�s�$�s�$rr)�__doc__r3rpr8�timer�r�sriovrrrrTrsrornrurrr�NetplanCommandrrrr�<module>r�sm��$)��	�
���;�;��������	�Y�	�	��	�	�Y�	�M$��-�-�M$r