@@ -26,6 +26,7 @@ use super::{
2626use crate :: devices:: virtio:: balloon:: BalloonError ;
2727use crate :: devices:: virtio:: device:: { IrqTrigger , IrqType } ;
2828use crate :: devices:: virtio:: generated:: virtio_config:: VIRTIO_F_VERSION_1 ;
29+ use crate :: devices:: virtio:: queue:: InvalidAvailIdx ;
2930use crate :: logger:: IncMetric ;
3031use crate :: utils:: u64_to_usize;
3132use crate :: vstate:: memory:: { Address , ByteValued , Bytes , GuestAddress , GuestMemoryMmap } ;
@@ -297,7 +298,7 @@ impl Balloon {
297298 // Internal loop processes descriptors and acummulates the pfns in `pfn_buffer`.
298299 // Breaks out when there is not enough space in `pfn_buffer` to completely process
299300 // the next descriptor.
300- while let Some ( head) = queue. pop ( ) {
301+ while let Some ( head) = queue. pop ( ) ? {
301302 let len = head. len as usize ;
302303 let max_len = MAX_PAGES_IN_DESC * SIZE_OF_U32 ;
303304 valid_descs_found = true ;
@@ -339,7 +340,7 @@ impl Balloon {
339340
340341 // Acknowledge the receipt of the descriptor.
341342 // 0 is number of bytes the device has written to memory.
342- queue. add_used ( head. index , 0 ) . map_err ( BalloonError :: Queue ) ?;
343+ queue. add_used ( head. index , 0 ) ?;
343344 needs_interrupt = true ;
344345 }
345346
@@ -375,8 +376,8 @@ impl Balloon {
375376 let queue = & mut self . queues [ DEFLATE_INDEX ] ;
376377 let mut needs_interrupt = false ;
377378
378- while let Some ( head) = queue. pop ( ) {
379- queue. add_used ( head. index , 0 ) . map_err ( BalloonError :: Queue ) ?;
379+ while let Some ( head) = queue. pop ( ) ? {
380+ queue. add_used ( head. index , 0 ) ?;
380381 needs_interrupt = true ;
381382 }
382383
@@ -392,14 +393,12 @@ impl Balloon {
392393 let mem = self . device_state . mem ( ) . unwrap ( ) ;
393394 METRICS . stats_updates_count . inc ( ) ;
394395
395- while let Some ( head) = self . queues [ STATS_INDEX ] . pop ( ) {
396+ while let Some ( head) = self . queues [ STATS_INDEX ] . pop ( ) ? {
396397 if let Some ( prev_stats_desc) = self . stats_desc_index {
397398 // We shouldn't ever have an extra buffer if the driver follows
398399 // the protocol, but return it if we find one.
399400 error ! ( "balloon: driver is not compliant, more than one stats buffer received" ) ;
400- self . queues [ STATS_INDEX ]
401- . add_used ( prev_stats_desc, 0 )
402- . map_err ( BalloonError :: Queue ) ?;
401+ self . queues [ STATS_INDEX ] . add_used ( prev_stats_desc, 0 ) ?;
403402 }
404403 for index in ( 0 ..head. len ) . step_by ( SIZE_OF_STAT ) {
405404 // Read the address at position `index`. The only case
@@ -433,9 +432,15 @@ impl Balloon {
433432 }
434433
435434 /// Process device virtio queue(s).
436- pub fn process_virtio_queues ( & mut self ) {
437- let _ = self . process_inflate ( ) ;
438- let _ = self . process_deflate_queue ( ) ;
435+ pub fn process_virtio_queues ( & mut self ) -> Result < ( ) , InvalidAvailIdx > {
436+ if let Err ( BalloonError :: InvalidAvailIdx ( err) ) = self . process_inflate ( ) {
437+ return Err ( err) ;
438+ }
439+ if let Err ( BalloonError :: InvalidAvailIdx ( err) ) = self . process_deflate_queue ( ) {
440+ return Err ( err) ;
441+ }
442+
443+ Ok ( ( ) )
439444 }
440445
441446 /// Provides the ID of this balloon device.
@@ -447,9 +452,7 @@ impl Balloon {
447452 // The communication is driven by the device by using the buffer
448453 // and sending a used buffer notification
449454 if let Some ( index) = self . stats_desc_index . take ( ) {
450- self . queues [ STATS_INDEX ]
451- . add_used ( index, 0 )
452- . map_err ( BalloonError :: Queue ) ?;
455+ self . queues [ STATS_INDEX ] . add_used ( index, 0 ) ?;
453456 self . signal_used_queue ( )
454457 } else {
455458 error ! ( "Failed to update balloon stats, missing descriptor." ) ;
@@ -1084,7 +1087,7 @@ pub(crate) mod tests {
10841087 balloon. set_queue ( DEFLATE_INDEX , defq. create_queue ( ) ) ;
10851088
10861089 balloon. activate ( mem) . unwrap ( ) ;
1087- balloon. process_virtio_queues ( )
1090+ balloon. process_virtio_queues ( ) . unwrap ( ) ;
10881091 }
10891092
10901093 #[ test]
0 commit comments