Skip to content

Adapt network interfaces sorting #6456

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

changlei-li
Copy link
Contributor

This PR is the adaption of #6381 in networkd and xapi.
XS8: Keep the legacy behaviour, use host-installer, sort-script to sort and rename the network interfaces to ethx.
XS9: 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 to pass interfaces and positions from networkd to xapi.

@changlei-li changlei-li requested a review from minglumlu May 7, 2025 02:52
@@ -420,6 +420,18 @@ module Interface_API (R : RPC) = struct
["Get list of all interface names"]
(debug_info_p @-> unit_p @-> returning iface_list_p err)

let get_interface_positions =
Copy link
Member

Choose a reason for hiding this comment

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

Could this be done within Interface.get_all?

Copy link
Contributor Author

@changlei-li changlei-li May 7, 2025

Choose a reason for hiding this comment

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

I prefer to add a new interface to keep the interface function simple and not modify the old one for potential break.

Copy link
Member

Choose a reason for hiding this comment

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

OK. I thought it's would be simpler to include this in the Interface.get_all from the interface design's point of view. But I'm not sure about this.
Hi @robhoes @psafont @lindig
May I please have your thoughts on this?

BTW, a minor comment on the name: Interface.get_interface_positions seems a bit redundant. If we are going to use this, how about Interface.get_order?

Copy link
Member

Choose a reason for hiding this comment

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

I do prefer the name Interface.get_{positions,order,slots}, But I would keep the function separate, because they have different semantic meaning. was there only a single user of get_all?

Copy link
Contributor Author

@changlei-li changlei-li May 19, 2025

Choose a reason for hiding this comment

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

Yes. There is only one single user of Net.Interface.get_all, which is xapi_pif.make_tables.

@changlei-li changlei-li force-pushed the private/changleli/rework-network branch from c455eb0 to 3b21c30 Compare May 13, 2025 08:39
@changlei-li changlei-li force-pushed the private/changleli/rework-network branch from b694365 to d95662a Compare May 16, 2025 06:30
Comment on lines 132 to 136
let choose_network_name_for_pif device pos_opt =
let pos_str =
match pos_opt with None -> "" | Some pos -> Printf.sprintf "[%d]" pos
in
Printf.sprintf "Pool-wide network associated with %s%s" device pos_str
Copy link
Member

Choose a reason for hiding this comment

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

This will be user visible, might be worth explaining what that number is:

Suggested change
let choose_network_name_for_pif device pos_opt =
let pos_str =
match pos_opt with None -> "" | Some pos -> Printf.sprintf "[%d]" pos
in
Printf.sprintf "Pool-wide network associated with %s%s" device pos_str
let choose_network_name_for_pif device pos_opt =
let pos_str =
match pos_opt with None -> "" | Some pos -> Printf.sprintf "(slot %d)" pos
in
Printf.sprintf "Pool-wide network associated with %s %s" device pos_str

Does this rename the existing PIFs? we probably should start picking words for the user-visible concepts, so "slot" might not be the right one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's just the name label of network, not the PIF. It's all right to add slot to show its meaning explicitly.
@minglumlu I come up with a new question here that if we should change the name of network in xs8? I want to change it with adding slot x. I think no one will/should rely on network name label.

Copy link
Member

Choose a reason for hiding this comment

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

The word used in XenCenter is NIC. They could be consistent now.
Yeah, I think the name is only a default one. A user can change it later anyway.

Copy link
Member

Choose a reason for hiding this comment

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

Or in XS 8, the the networkd could not return the positions (hence dropping the get_index_from_ethx and sort_based_on_ethx) to keep the original naming of network.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The current solution is designed to limit the compatibility in networkd. We don't want to check and write two logics in xapi_pif again like networkd does. So, it's better to keep the main changes of get position method in networkd. If there is really a particular corner demand like the network name label to keep unchanged. I think it is ok to check and write two logics about it then.

Copy link
Member

Choose a reason for hiding this comment

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

That's why the position is of int option.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

option here is mainly for ibft and non-physical devices.

@psafont
Copy link
Member

psafont commented May 19, 2025

The changes look good, but the commits need to be squashed, there are too many of them

@changlei-li
Copy link
Contributor Author

changlei-li commented May 20, 2025

The changes look good, but the commits need to be squashed, there are too many of them

Yes, of course. I have planned to do it before merge.


Done. Compare the diffs:

git diff 2acf27139 ac02a4a5d > diff.0
git diff 2acf27139 dbd1a3ed0 > diff.1
diff diff.0 diff.1

=> They are identical.

`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>
@changlei-li changlei-li force-pushed the private/changleli/rework-network branch from ac02a4a to dbd1a3e Compare May 20, 2025 04:32
@changlei-li changlei-li merged commit ce4de83 into xapi-project:feature/host-network-device-ordering May 21, 2025
17 checks passed
@changlei-li changlei-li deleted the private/changleli/rework-network branch May 21, 2025 01:49
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.

3 participants