From 1fef85dc04916f6bb5b9cde1a87b2edfd0740ad8 Mon Sep 17 00:00:00 2001 From: Jose Martins Date: Fri, 27 Sep 2024 14:57:35 +0100 Subject: [PATCH] fix(virtio/console): process receiveq only when input buffer not empty Signed-off-by: Jose Martins --- .../src/console/virtio/console_handler.rs | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/src/virtio/src/console/virtio/console_handler.rs b/src/virtio/src/console/virtio/console_handler.rs index 45f80c0..462f514 100644 --- a/src/virtio/src/console/virtio/console_handler.rs +++ b/src/virtio/src/console/virtio/console_handler.rs @@ -32,22 +32,32 @@ where // To see why this is done in a loop, please look at the `Queue::enable_notification` // comments in `virtio_queue`. loop { + if self.console.is_input_buffer_empty() { + break; + } + // Disable the notifications. self.input_queue.disable_notification(&self.mem)?; - // Process the queue. - while let Some(mut chain) = self.input_queue.iter(&self.mem.clone())?.next() { - let sent_bytes = self.console.process_receiveq_chain(&mut chain)?; - //println!("Sent bytes: {}", sent_bytes); - - if sent_bytes > 0 { - println!("process_input_queue bytes: {}", sent_bytes); - self.input_queue - .add_used(chain.memory(), chain.head_index(), sent_bytes)?; - - if self.input_queue.needs_notification(&self.mem)? { - self.driver_notify.signal_used_queue(INPUT_QUEUE_INDEX); + while !self.console.is_input_buffer_empty() { + // Process the queue. + if let Some(mut chain) = self.input_queue.iter(&self.mem.clone())?.next() { + let sent_bytes = self.console.process_receiveq_chain(&mut chain)?; + + if sent_bytes > 0 { + self.input_queue.add_used( + chain.memory(), + chain.head_index(), + sent_bytes, + )?; + if self.input_queue.needs_notification(&self.mem)? { + self.driver_notify.signal_used_queue(INPUT_QUEUE_INDEX); + } + } else { + break; } + } else { + break; } }