vhost-device-can: use the same socket for send/recv#937
vhost-device-can: use the same socket for send/recv#937MatiasVara wants to merge 5 commits intorust-vmm:mainfrom
Conversation
|
When fixing this, some tests started to fail since now the opening of the socket is happening in new(). Before, those tests did not require to open a socket to work. I fixed those tests by adding a few commits together with the fix. I wonder if these tests should be fixed here or in another PR. |
|
To run the tests, we require a virtual can interface in the host named |
Is this something new (i.e. added here) or was there before this PR? |
It was in the code before but it was not being tested. The tests were done to not use a can interface. I am not sure if that was done on purpose. |
|
I think we should wrap the CanFdSocket field into an enum, and add a This way we can add support in the future for classic Can sockets (i.e. not FD) which is something I wanted to do anyway. |
Maybe to avoid updating the container image xD (I have no idea). |
If the linux images contain the |
Thanks! I'll try that. I did not get it completely yet though. |
Use the same socket for send/receive in the backend to prevent the guest from receiving two copies of the message when it sends to the local CAN bus. Fix tests and remove test_can_read_socket_fail() test since read_can_socket() does not open the socket anymore. Fixes rust-vmm#925 Reported-by: Francesco Valla <francesco@valla.it> Signed-off-by: Matias Ezequiel Vara Larsen <mvaralar@redhat.com>
Most of the tests were using `can0` as interface but some used `can`. Use `can0` interface for all tests and `canx` for those that expect an interface down. Signed-off-by: Matias Ezequiel Vara Larsen <mvaralar@redhat.com>
To support 64 bytes packet, set CAN_FRMF_TYPE_FD flag in test_can_controller_operation test. Signed-off-by: Matias Ezequiel Vara Larsen <mvaralar@redhat.com>
|
The PR has now a wider scope :(. I am OK to split if it is required. Bear in mind that I used Claude for the last commit. Claude proposed a single builder for both socket types but I ignored it for the moment. |
Rename this test that previously had to fail since the interface was down. The previous test was testing the NoOutputInterface path which does not exist anymore. Make the test pass when transmission succeeds. Signed-off-by: Matias Ezequiel Vara Larsen <mvaralar@redhat.com>
Add a mock socket for tests so that tests no longer require a CAN interface on the host. Signed-off-by: Matias Ezequiel Vara Larsen <mvaralar@redhat.com>
stefano-garzarella
left a comment
There was a problem hiding this comment.
Maybe we should re-order commit, for example the last 1 and other fixes should come first, but I did just a quick look, I may be wrong.
There was a problem hiding this comment.
About commit 6c94dae can we improve better the commit description?
What I don't get is why having 1 socket fixes the issue we had (I don't know much about can sockets, etc.).
| ctrl.can_socket.read_frame() | ||
| }; | ||
|
|
||
| if let Ok(frame) = frame_result { |
There was a problem hiding this comment.
What happens here if there is no frame returned by read_frame() ?
Are we spinning acquiring now the shared lock?
Maybe this is fine, since we are releasing it in the loop, but I'd like just to understand better if it's expected.
| if self.check_features(VIRTIO_CAN_F_CAN_FD) && res_len > 8 && can_name == "vcan0" { | ||
| if self.check_features(VIRTIO_CAN_F_CAN_FD) && res_len > 8 && can_name == "can0" { | ||
| res_flags |= CAN_FRMF_TYPE_FD; | ||
| warn!("\n\n\nCANFD VCAN0\n\n"); |
There was a problem hiding this comment.
stil VCAN0 here?
BTW are we sure it's fine to can0 instead of vcan0?
Not sure if v prefix was done for a virtual purporse.
| @@ -248,7 +248,7 @@ mod tests { | |||
| #[test] | |||
| fn test_can_valid_configuration_start_backend_server_fail() { | |||
There was a problem hiding this comment.
I think this is pre-existing, but the test name here is a bit confusing, I mean "valid_configuration" while we are opening an invalid interface IIUC.
There was a problem hiding this comment.
Is 09a1ec2 an unrelated fix?
I mean, it's not clear to me if the test was working or not before.
There was a problem hiding this comment.
mmm, so if we run cargo test before commit 3be95bc but after commit 1 is it working or failing?
IMO we should keep tests running to avoid breaking the bisectability, so better to move this commit or squash.
| match self { | ||
| CanSocketKind::Fd(socket) => socket.read_frame(), | ||
| #[cfg(test)] | ||
| CanSocketKind::Mock => Err(std::io::ErrorKind::WouldBlock.into()), |
There was a problem hiding this comment.
Why returning WouldBlock ?
Summary of the PR
Use the same socket for send/receive in the backend to prevent guest to receiving two copies of the message when it sends to the local CAN bus.
Fixes #925
Reported-by: Francesco Valla francesco@valla.it
Requirements
Before submitting your PR, please make sure you addressed the following
requirements:
git commit -s), and the commit message has max 60 characters for thesummary and max 75 characters for each description line.
test.
Release" section of CHANGELOG.md (if no such section exists, please create one).
unsafecode is properly documented.