Skip to content

Conversation

@changlei-li
Copy link
Contributor

@changlei-li changlei-li commented Oct 24, 2025

No conflict.
Add two commits to

  1. update datamodel_lifecycle
  2. Make CI shellcheck happy, see Merge feature/host-network-device-ordering into master #6724

minglumlu and others added 30 commits March 27, 2025 12:41
Signed-off-by: Ming Lu <ming.lu@cloud.com>
Signed-off-by: Ming Lu <ming.lu@cloud.com>
This part sorts host network devices in xcp-networkd. Previously, the
ordering was handled by the interface-rename functionality. This will
now be replaced by an equivalent function in xcp-networkd, but without
renaming the network devices. The renmaing performed by the
interface-rename was used to record the sorting result as the name of
the NICs like "eth<N>". Now the sorting result will be saved in
xcp-networkd database.

Signed-off-by: Ming Lu <ming.lu@cloud.com>
The "test_network_device_order_inherited.ml" is inherited from the
interface-rename functionality.

Signed-off-by: Ming Lu <ming.lu@cloud.com>
This part sorts host network devices in xcp-networkd. Previously, the
ordering was handled by the interface-rename functionality. This will
now be replaced by an equivalent function in xcp-networkd, but without
renaming the network devices. The renmaing performed by the
interface-rename was used to record the sorting result as the name of
the NICs like "eth<N>". Now the sorting result will be recorded as
internal files.
These IBFT devices are not managed by Toolstack and therefore are
not involved in the ordering process.

Signed-off-by: Ming Lu <ming.lu@cloud.com>
…api-project#6453)

These IBFT devices are not managed by Toolstack and therefore are not
involved in the ordering process.
`Network_utils.is_sorted_by_script` checks interface-rename-data dir.
When true:
Follow the legacy behavior, the new added interface_order field is always None.
When false:
Use `Network_device_order.sort` to sort the interfaces, store the result in
config.interface_order.

Signed-off-by: Changlei Li <changlei.li@cloud.com>
When xapi start, networkd config will be reset, see
Xapi_pif.start_of_day_best_effort_bring_up. In fact,
the interface_order is only maintained by networkd,
it shouldn't be cleared.

Signed-off-by: Changlei Li <changlei.li@cloud.com>
If networkd config.interface_order is None, then sort based
on the renamed interfaces name "ethx" to indicate its position,
else get positions from config.interface_order.

Signed-off-by: Changlei Li <changlei.li@cloud.com>
Xapi get interface position from `get_interface_positions`,
instead of getting position from "ethx" name.

Signed-off-by: Changlei Li <changlei.li@cloud.com>
Some devices like ibft may not be in networkd sort result but need
to build pif, network for it. So the devices need be got by
`get_all`.

Signed-off-by: Changlei Li <changlei.li@cloud.com>
Pif device name maybe change. Look up device_to_position table to
get the new device name in pif refresh. Then update to db.
This function is called by pif.scan and resynchronise_pif_params.

Signed-off-by: Changlei Li <changlei.li@cloud.com>
This PR is the adaption of xapi-project#6381 in networkd and xapi.
Legacy: Keep the legacy behaviour, use host-installer, sort-script to sort
and rename the network interfaces to `ethx`.
New: Use `Network_device_order.sort` to sort the interfaces, store the
result in networkd `config.interface_order`.
Compatibility is offered by check the sort-script
`interface-rename-data` dir.
Add new interface
[Interface.get_interface_positions](xapi-project@b2e7113)
to pass interfaces and positions from networkd to xapi.
Signed-off-by: Changlei Li <changlei.li@cloud.com>
As pool.eject_self calls interface-rename script to rename the
network interfaces, this behavior should be done compatibly.
So, move the interface-rename to networkd with compatibility
check.

Signed-off-by: Changlei Li <changlei.li@cloud.com>
As pool.eject_self calls interface-rename script to rename the network
interfaces, this behaviour should be done compatibly.
So, move the interface-rename to networkd with compatibility check.
When reset networkd state
legacy: use interface-rename script to sort and rename
new: use networkd network_device_order with initial empty order to sort
With interface-rename functionality, the host network devices are
ordered and renamed like "eth<N>". So they can be filtered by
hard-coded "eth" and added into the networkd monitor list and rrdd
collecting list.

While the interface-rename is being replaced by the ordering function
in networkd. Unlike the interface-rename, the networkd will not rename
the host network devices anymore. Instead, the naming of them are left
to the built-in systemd and Kernel.

In both cases, the networkd's Interface.get_interface_positions can
return the managed (ordered) host network devices: when the
interface-rename functionality is still working, it returns the list of
"eth<N>"; when networkd takes the place to perform the ordering, it
returns the names generated by systemd and Kernel.

Signed-off-by: Ming Lu <ming.lu@cloud.com>
…xapi-project#6480)

With interface-rename functionality, the host network devices are
ordered and renamed like "eth<N>". So they can be filtered by hard-coded
"eth" and added into the networkd monitor list and rrdd collecting list.

While the interface-rename is being replaced by the ordering function in
networkd. Unlike the interface-rename, the networkd will not rename the
host network devices anymore. Instead, the naming of them are left to
the built-in systemd and Kernel.

In both cases, the networkd's Interface.get_interface_position can
return the managed (ordered) host network devices: when the
interface-rename functionality is still working, it returns the list of
"eth<N>"; when networkd takes the place to perform the ordering, it
returns the names generated by systemd and Kernel.
When networkd sort the interfaces, host-installer will not
write management interface and managemnt address type. Then
networkd need to write management interface to inventory
according to firstboot management conf.

Signed-off-by: Changlei Li <changlei.li@cloud.com>
This hard code in rename_network_label is used to find NIC position
by ethN. Change to use bridge name to find the position.

Signed-off-by: Changlei Li <changlei.li@cloud.com>
…#6483)

1. network-init script need read inventory and get management address
type. This item should be written to inventory by networkd, the same as
management interface item. Because host-installer will not write it from
the new netdev ordering, see
xenserver/host-installer@33aa793.
2. networl-init renames network name label under common criteria. There
was hard code ethx to determine the interface position. Now change to
get position from the bridge which is right both on legacy and new
ordering method.
The host installer uses this utility to get the management interface
from the management bridge. Now it changes to use MAC address(es) to
find out the management interface(s). This is because the
interface-rename functionality will be deprecated and the names of the
network interfaces are not guaranteed to be the same between dom0 and
host installer's running environment.

Note that this change must be delivered to a host before upgrading to
a new version in which the interface-rename is deprecated because the
host installer is built from the new version and it will not be able to
find the management network interface by name if the networkd_db command
returns only names generated by interface-rename.

Specifically, the "interface_order" field is only available when the
networkd takes place of interface-rename to generate order. Before
that, only the "bridge_mac" can be used because at that time, the
host installer only uses one interface to setup its own networking
during installation and no MAC addresses are recorded in networkd.db
for individual interfaces. The "bridge_mac" is just the MAC address of
one of the interfaces which construct the management bridge.

Signed-off-by: Ming Lu <ming.lu@cloud.com>
The host installer uses this utility to get the management interface
from the management bridge. Now it changes to use MAC address(es) to
find out the management interface(s). This is because the
interface-rename functionality will be deprecated and the names of the
network interfaces are not guaranteed to be the same between dom0 and
host installer's running environment.

Note that this change must be delivered to a host before upgrading to a
new version in which the interface-rename is deprecated because the host
installer is built from the new version and it will not be able to find
the management network interface by name if the networkd_db command
returns only names generated by interface-rename.

Specifically, the "interface_order" field is only available when the
networkd takes place of interface-rename to generate order. Before that,
only the "bridge_mac" can be used because at that time, the host
installer only uses one interface to setup its own networking during
installation and no MAC addresses are recorded in networkd.db for
individual interfaces. The "bridge_mac" is just the MAC address of one
of the interfaces which construct the management bridge.
changlei-li and others added 23 commits June 27, 2025 15:01
…-project#6556)

1. Unify the behaviour when converting interface name to bridge name.
Get a stricter check for eth<N> with sscanf or re rather than start_with
"eth".
2. Construct the default name_label for new created network only with
position.
The bus-info of a USB-based network device follows the format
"usb-<PCI address of USB controller>-<USB port path>". To determine
the device's order when sorting, use the PCI address of the
USB controller.

Signed-off-by: Changlei Li <changlei.li@cloud.com>
…ject#6565)

The bus-info of a USB-based network device follows the format `usb-<PCI
address of USB controller>-<USB port path>`. To determine the device's
order when sorting, use the PCI address of the USB controller.
After RPU from legacy network device name, the name in PIF
object should be updated. The new network device name is
in interface_tables.device_to_position_table. The position
of old device name in PIF object can be get by its associated
bridge and then correspond with the new name.
In this procedure, a exsiting bridge is used to get the position.
However, the bridge is used to update MTU. It is specially
handled when the device is under a bond. The bridge is actually
the parent bond bridge. This leads to no position is found for
old device name and then device name is not updated correctly.
Fix: use the associated bridge to find the position.

Signed-off-by: Changlei Li <changlei.li@cloud.com>
After RPU from legacy network device name, the name in PIF object should
be updated. The new network device name is in
interface_tables.device_to_position_table. The position of old device
name in PIF object can be get by its associated bridge and then
correspond with the new name.
In this procedure, an existing bridge is used to get the position.
However, the bridge is used to update MTU. It is specially handled when
the device is under a bond. The bridge is actually the parent bond
bridge. This leads to no position is found for old device name and then
device name is not updated correctly.
Fix: use the associated bridge to find the position.
For pif which is vlan-master or sriov-logic-pif, its pif.device
comes from its vlan-slave or sriov-physical-pif pif.device.
After RPU, the network interface name may change. Its corresponding
physical pif.device is synced already. The vlan or sriov
non-physical pif.device should be synced accordingly.
For non-physical and unattached pifs (like vlan, sriov pifs that
are not used), the pif.device need to be updated too. So,
refresh_all get all pifs on the host and in refresh_internal the
pif fields physical and currently-attached are carefully distinguished
to keep the original logic not changed.

Signed-off-by: Changlei Li <changlei.li@cloud.com>
Signed-off-by: Changlei Li <changlei.li@cloud.com>
For pif which is vlan-master or sriov-logic-pif, its pif.device comes
from its vlan-slave or sriov-physical-pif pif.device.
For example:
```
uuid ( RO)                     : 00bfb6be-041b-2d16-4118-e98d4f4758a1
                   device ( RO): eth1
                 physical ( RO): false
       currently-attached ( RO): false
                     VLAN ( RO): 12
           vlan-master-of ( RO): 7efb4476-95d7-e27e-6646-983e33ef9a67
            vlan-slave-of ( RO):

uuid ( RO)                     : 32073526-d992-3a2f-9653-f5f5b368680f
                   device ( RO): eth1
                 physical ( RO): true
       currently-attached ( RO): true
                     VLAN ( RO): -1
           vlan-master-of ( RO): <not in database>
            vlan-slave-of ( RO): 7efb4476-95d7-e27e-6646-983e33ef9a67
```
Their names are both eth1. In this feature branch, the interface name
may change after RPU. The physical pif.device is synced in
refresh_internal. But the vlan or sriov non-physical pif.device is not
handled.

This PR syncs the vlan or sriov pif.device by finding its corresponding
physical pif device and get the real device name.
What's more, for all the pif types:
- Physical: maybe change, need to lookup device_to_position_table to get
new device
 - VLAN_untagged: get the underlying physical PIF device
 - Network_sriov_logical: get the underlying physical PIF device
 - Tunnel_access: tunnelN, no need to change
 - Bond_master: bondN, no need to change
 
The function `get_pif_device` is extracted to handle the pif.device by
its type.

At last, the currently-attached:false and nonphysical pif.device need to
be updated too. The refresh_all function is changed to handle all the
pifs on the host.
Conflict between xapi-project#6637 and xapi-project#6466. The PR xapi-project#6637 on master is a
simplified version of PR xapi-project#6466 for upgrade from master to feature
version.
To solve the conflict, keep xapi-project#6466, drop xapi-project#6637.

Signed-off-by: Changlei Li <changlei.li@cloud.com>
)

Conflict between xapi-project#6637 and xapi-project#6466. The PR xapi-project#6637 on master is a simplified
version of PR xapi-project#6466 for upgrade from master to feature version.
To solve the conflict, keep xapi-project#6466, drop xapi-project#6637.
Signed-off-by: Changlei Li <changlei.li@cloud.com>
Signed-off-by: Changlei Li <changlei.li@cloud.com>
Signed-off-by: Changlei Li <changlei.li@cloud.com>
…i-project#6669)

For pool join procedure, the slave host will go through
1 pre_join_check
2 update_non_vm_metadata: in this step, create pif objects for physical
pifs of slave host on master host db.
3 on slave xapi start: copy_bonds_from_master,
copy_network_sriovs_from_master, copy_vlans_from_master,
copy_tunnels_from_master

This issue happens on step 3 when copy bonds from master.
for every bond on master
- get the bond master pif on master
- get the bond slave pifs on master
- confirm the primary bond slaves via comparing the bond master pif mac
- find the corresponding pifs on slave host
- decide if create bond on slave host

In `find the corresponding pifs on slave host`, the previous method is
to compare the pif.device on master and slave hosts. Now we should
compare the position of pif device. Because the network device name is
no longer renamed to ethx, which x is actually the position.

It's similar for copy_network_sriovs_from_master.
For vlans and tunnels, they are based the underneath network, no
pif.device compare. So, this issue doesn't exist.
Signed-off-by: Changlei Li <changlei.li@cloud.com>
Signed-off-by: Changlei Li <changlei.li@cloud.com>
Signed-off-by: Changlei Li <changlei.li@cloud.com>
See xapi-project#6724

Signed-off-by: Changlei Li <changlei.li@cloud.com>
Copy link
Member

@psafont psafont left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new logic is gated behind the lack of presence of the directory /etc/sysconfig/network-scripts/interface-rename-data when networkd tries to first construct the network configuration

@robhoes robhoes added this pull request to the merge queue Oct 27, 2025
Merged via the queue into xapi-project:master with commit 7cc153f Oct 27, 2025
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants