瀏覽代碼

Rename Error::BufferTooSmall to QueueFull and improve documentation. (#43)

* Rename Error::BufferTooSmall to QueueFull and improve documentation.

This is a more accurate description of the issue.

* Remove obsolete TODO.
Andrew Walbran 2 年之前
父節點
當前提交
633548725c
共有 4 個文件被更改,包括 7 次插入8 次删除
  1. 1 1
      src/blk.rs
  2. 2 2
      src/lib.rs
  3. 4 4
      src/queue.rs
  4. 0 1
      src/transport/pci.rs

+ 1 - 1
src/blk.rs

@@ -130,7 +130,7 @@ impl<H: Hal, T: Transport> VirtIOBlk<H, T> {
     ///
     /// It will submit request to the VirtIO block device and return a token identifying
     /// the position of the first Descriptor in the chain. If there are not enough
-    /// Descriptors to allocate, then it returns [Error::BufferTooSmall].
+    /// Descriptors to allocate, then it returns [`Error::QueueFull`].
     ///
     /// The caller can then call `pop_used` to check whether the device has finished handling the
     /// request. Once it has, the caller can then read the response and dispose of the buffers.

+ 2 - 2
src/lib.rs

@@ -41,8 +41,8 @@ pub type Result<T = ()> = core::result::Result<T, Error>;
 /// The error type of VirtIO drivers.
 #[derive(Copy, Clone, Debug, Eq, PartialEq)]
 pub enum Error {
-    /// The buffer is too small.
-    BufferTooSmall,
+    /// There are not enough descriptors available in the virtqueue, try again later.
+    QueueFull,
     /// The device is not ready.
     NotReady,
     /// The queue is already in use.

+ 4 - 4
src/queue.rs

@@ -30,7 +30,7 @@ pub struct VirtQueue<H: Hal> {
     /// This is both the number of descriptors, and the number of slots in the available and used
     /// rings.
     queue_size: u16,
-    /// The number of used queues.
+    /// The number of descriptors currently in use.
     num_used: u16,
     /// The head desc index of the free list.
     free_head: u16,
@@ -102,7 +102,7 @@ impl<H: Hal> VirtQueue<H> {
             return Err(Error::InvalidParam);
         }
         if inputs.len() + outputs.len() + self.num_used as usize > self.queue_size as usize {
-            return Err(Error::BufferTooSmall);
+            return Err(Error::QueueFull);
         }
 
         // allocate descriptors from free list
@@ -449,14 +449,14 @@ mod tests {
     }
 
     #[test]
-    fn add_too_big() {
+    fn add_too_many() {
         let mut header = VirtIOHeader::make_fake_header(MODERN_VERSION, 1, 0, 0, 4);
         let mut transport = unsafe { MmioTransport::new(NonNull::from(&mut header)) }.unwrap();
         let mut queue = VirtQueue::<FakeHal>::new(&mut transport, 0, 4).unwrap();
         assert_eq!(queue.available_desc(), 4);
         assert_eq!(
             unsafe { queue.add(&[&[], &[], &[]], &[&mut [], &mut []]) }.unwrap_err(),
-            Error::BufferTooSmall
+            Error::QueueFull
         );
     }
 

+ 0 - 1
src/transport/pci.rs

@@ -85,7 +85,6 @@ pub struct PciTransport {
     device_function: DeviceFunction,
     /// The common configuration structure within some BAR.
     common_cfg: NonNull<CommonCfg>,
-    // TODO: Use a raw slice, once they are supported by our MSRV.
     /// The start of the queue notification region within some BAR.
     notify_region: NonNull<[WriteOnly<u16>]>,
     notify_off_multiplier: u32,