Conversation
1d119bd to
6e52a4e
Compare
6e52a4e to
3cd4685
Compare
e1901bb to
fdf6d8a
Compare
This comment was marked as outdated.
This comment was marked as outdated.
5fdcc54 to
a540d37
Compare
rbradford
left a comment
There was a problem hiding this comment.
The use of the HashSet prohibits duplicates - and your warning logic flags them up. I wonder if there is a legitimate use case for the same FD being passed in twice.
| for fd in fds.into_iter() { | ||
| if self.preserved_fds.contains(&fd) { | ||
| log::warn!( | ||
| "FD {fd} is already preserved. Using the same FD multiple times causes most likely unexpected behavior" |
There was a problem hiding this comment.
The word order in this warning is not quite right - are there legitimate cases where the same FD would be reused?
There was a problem hiding this comment.
It is illegal to use the same FD multiple times, otherwise we open the gate to complexity hell. For example, assume we add two network devices during runtime with the same FD and the first one is unplugged and closes the file descriptor #7371.
I will remove the warning and return an error instead
| /// FDs are all valid. | ||
| pub unsafe fn add_preserved_fds(&mut self, fds: impl IntoIterator<Item = RawFd>) { | ||
| for fd in fds.into_iter() { | ||
| if self.preserved_fds.contains(&fd) { |
There was a problem hiding this comment.
This could be simplified as .insert() returns a bool about where it was added or not - if it wasn't added, because it's a duplicate then we could trigger the warning. Removing the need for the explicit contains check.
119912e to
0bc2877
Compare
- no need for an Option, an empty collection is also as good - We use a HashSet as all FDs are unique anyway The next commit will replace the warn! with an Err, when the same FD is used multiple times. Signed-off-by: Philipp Schuster <[email protected]> On-behalf-of: SAP [email protected]
Allowing the same file descriptor (FD) to be preserved more than once can lead to severe issues. Consider the case where management software adds two virtio-net devices at runtime, both backed by the same externally provided FD. When the first device is removed during runtime, the FD for the second device becomes invalid [0]. To avoid misconfigurations, we now prevent multiple preservation attempts of the same FD. [0] cloud-hypervisor#7371 Signed-off-by: Philipp Schuster <[email protected]> On-behalf-of: SAP [email protected]
0bc2877 to
62468e3
Compare
We don't need the order in that we preserve FDs, but it is beneficial for debugging to see FDs in an ordered way Signed-off-by: Philipp Schuster <[email protected]> On-behalf-of: SAP [email protected]
62468e3 to
0975ba6
Compare
|
I noticed although this is important, it has more caveats than anticipated. I'll do more development in our fork including some testing and upstream this once it is more mature. FYI, the PoC in our fork. |
Please see the commit messages for details.
Steps to Undraft