Skip to content

Commit

Permalink
Renames descriptor indirect table methods
Browse files Browse the repository at this point in the history
Renames the following methods to more appropriate names:
Descriptor::is_indirect & DescriptorChain::process_indirect_descriptor
closes: rust-vmm#96

Signed-off-by: German Maglione <[email protected]>
  • Loading branch information
germag authored and jiangliu committed Oct 26, 2021
1 parent bdc263a commit 22b288a
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions crates/virtio-queue/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ impl Descriptor {
self.next
}

/// Check whether this is an indirect descriptor.
pub fn is_indirect(&self) -> bool {
/// Check whether this descriptor refers to a buffer containing an indirect descriptor table.
pub fn refers_to_indirect_table(&self) -> bool {
// TODO: The are a couple of restrictions in terms of which flags combinations are
// actually valid for indirect descriptors. Implement those checks as well somewhere.
self.flags() & VIRTQ_DESC_F_INDIRECT != 0
Expand Down Expand Up @@ -212,7 +212,10 @@ impl<M: GuestAddressSpace> DescriptorChain<M> {

// Alters the internal state of the `DescriptorChain` to switch iterating over an
// indirect descriptor table defined by `desc`.
fn process_indirect_descriptor(&mut self, desc: Descriptor) -> Result<(), Error> {
fn switch_to_indirect_table(&mut self, desc: Descriptor) -> Result<(), Error> {
// Check the VIRTQ_DESC_F_INDIRECT flag (i.e., is_indirect) is not set inside
// an indirect descriptor.
// (see VIRTIO Spec, Section 2.6.5.3.1 Driver Requirements: Indirect Descriptors)
if self.is_indirect {
return Err(Error::InvalidIndirectDescriptor);
}
Expand Down Expand Up @@ -262,8 +265,8 @@ impl<M: GuestAddressSpace> Iterator for DescriptorChain<M> {
// to use read_obj() here.
let desc = self.mem.read_obj::<Descriptor>(desc_addr).ok()?;

if desc.is_indirect() {
self.process_indirect_descriptor(desc).ok()?;
if desc.refers_to_indirect_table() {
self.switch_to_indirect_table(desc).ok()?;
return self.next();
}

Expand Down

0 comments on commit 22b288a

Please sign in to comment.