Skip to content

Commit c2b6a44

Browse files
mtjhrcslp
authored andcommitted
virtio-net: Gracefully handle passt process quitting
When the process quits, prints an error msg and effectively disables virtio-net. Signed-off-by: Matej Hrica <[email protected]>
1 parent 941f1d9 commit c2b6a44

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

src/devices/src/virtio/net/device.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ impl Net {
176176
Err(e @ passt::WriteError::Internal(_)) => {
177177
log::error!("Failed to finish write: {e:?}");
178178
}
179+
Err(e @ passt::WriteError::ProcessNotRunning) => {
180+
log::debug!("Failed to finish write: {e:?}");
181+
}
179182
}
180183
}
181184

@@ -318,7 +321,10 @@ impl Net {
318321
dropped_frames += drop_rest_of_frames(tx_queue);
319322
break;
320323
}
321-
Err(e @ passt::WriteError::Internal(_)) => return Err(TxError::Passt(e)),
324+
325+
Err(
326+
e @ passt::WriteError::Internal(_) | e @ passt::WriteError::ProcessNotRunning,
327+
) => return Err(TxError::Passt(e)),
322328
}
323329
}
324330

src/devices/src/virtio/net/event_handler.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,19 @@ impl Subscriber for Net {
6565
self.process_tx_queue_event();
6666
}
6767
_ if source == passt_socket => {
68-
if event_set.contains(EventSet::IN) {
69-
self.process_passt_socket_readable()
70-
}
68+
if event_set.contains(EventSet::HANG_UP)
69+
|| event_set.contains(EventSet::READ_HANG_UP)
70+
{
71+
log::error!("Got {event_set:?} on passt fd, virtio-net will stop working");
72+
eprintln!("LIBKRUN VIRTIO-NET FATAL: Passt process seems to have quit or crashed! Networking is now disabled!");
73+
} else {
74+
if event_set.contains(EventSet::IN) {
75+
self.process_passt_socket_readable()
76+
}
7177

72-
if event_set.contains(EventSet::OUT) {
73-
self.process_passt_socket_writeable()
78+
if event_set.contains(EventSet::OUT) {
79+
self.process_passt_socket_writeable()
80+
}
7481
}
7582
}
7683
_ => {
@@ -95,7 +102,10 @@ impl Subscriber for Net {
95102
EpollEvent::new(EventSet::IN, self.queue_evts[RX_INDEX].as_raw_fd() as u64),
96103
EpollEvent::new(EventSet::IN, self.queue_evts[TX_INDEX].as_raw_fd() as u64),
97104
EpollEvent::new(
98-
EventSet::IN | EventSet::OUT | EventSet::EDGE_TRIGGERED,
105+
EventSet::IN
106+
| EventSet::OUT
107+
| EventSet::EDGE_TRIGGERED
108+
| EventSet::READ_HANG_UP,
99109
self.raw_passt_socket_fd() as u64,
100110
),
101111
]

src/devices/src/virtio/net/passt.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ pub enum WriteError {
2121
NothingWritten,
2222
/// Part of the buffer was written, the write has to be finished using try_finish_write
2323
PartialWrite,
24+
/// Passt doesnt seem to be running (received EPIPE)
25+
ProcessNotRunning,
2426
/// Another internal error occurred
2527
Internal(nix::Error),
2628
}
@@ -183,6 +185,7 @@ impl Passt {
183185
return Err(WriteError::PartialWrite);
184186
}
185187
}
188+
Err(nix::Error::EPIPE) => return Err(WriteError::ProcessNotRunning),
186189
Err(e) => return Err(WriteError::Internal(e)),
187190
}
188191
}

0 commit comments

Comments
 (0)