-
Notifications
You must be signed in to change notification settings - Fork 292
CP-54468 Handle USB network devices in network devices sort #6565
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
CP-54468 Handle USB network devices in network devices sort #6565
Conversation
| (* For USB device, the bus-info is like | ||
| "usb-<PCI address of USB controller>-<USB port path>", | ||
| use the PCI address of the USB controller *) | ||
| List.nth (String.split_on_char '-' v) 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is meant to return a result, but List.nth can return an exception, it's quite a bad fit.
It would be better to use only string manipulation here:
| List.nth (String.split_on_char '-' v) 1 | |
| String.sub v 4 (String.length v - 4) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The bus-info format is like usb-0000:44:00.3-1.2. There are three parts when split on '-'. We need the second part. While String.sub v 4 (String.length v - 4) is not correct.
Also needn't to worry about the nth exception. The string is verified starts_with usb-, so it is sure to have nth 1 in the split result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comments do not mantion that the string has 2 hyphens, could you add that to the comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In L249, it is "usb-<PCI address of USB controller>-<USB port path>" with two hyphens already 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest to use sscanf - it can do both checking for usb and extract whatever you need in one go.
let str = "usb-0000:44:00.3-1.2";;
top # Scanf.sscanf str "usb-%[:0-9A-F].%_s" Fun.id;;
- : string = "0000:44:00"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact, the Pciaddr.of_string in L255 uses sscanf to verify pci addr. See https://github.com/xapi-project/xen-api/blob/v25.23.0/ocaml/xapi-idl/lib/xcp_pci.ml#L6-L9. I would insist to preprocess the bus-info by this method here. While the difference is minimal, to be precise: USB network devices are uncommon on servers, so using starts_with to check is sufficient for most scenarios.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@psafont There's no changes needed as the comment is accurate already. Could you change your requested changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the first point is to eliminate any potential exception leaking from the function to make the type of the function clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. I will change the code to make the type of the function clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. The format of PCI addr string will be parsed and checked later in L255 by Pciaddr.of_string.
|
Self test: |
8cacc53 to
efa8cf0
Compare
| ; ( "Bus Info" | ||
| , fun r v -> | ||
| let v = | ||
| if String.starts_with ~prefix:"usb-" v then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
match String.split_on_char '-' str with
| ["usb"; pci; _] -> pci
| _ -> str
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Accept. Done.
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 <[email protected]>
efa8cf0 to
70e8440
Compare
07f39bf
into
xapi-project:feature/host-network-device-ordering
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.