Skip to content

Commit 2bf58c1

Browse files
jiangliuSamuel Ortiz
authored andcommitted
Implement Clone trait for DescriptorChain
The Clone trait is needed to support readable()/writable() filter iterator. Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
1 parent 7721050 commit 2bf58c1

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/queue.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ impl<'a, M: GuestMemory> DescriptorChain<'a, M> {
182182
}
183183

184184
/// Create a new DescriptorChain instance.
185-
fn checked_new(
185+
pub fn checked_new(
186186
mem: &'a M,
187187
dtable_addr: GuestAddress,
188188
queue_size: u16,
@@ -355,6 +355,22 @@ impl<'a, M: GuestMemory> Iterator for DescriptorChain<'a, M> {
355355
}
356356
}
357357

358+
impl<'a, M: GuestMemory> Clone for DescriptorChain<'a, M> {
359+
fn clone(&self) -> Self {
360+
DescriptorChain {
361+
mem: self.mem,
362+
desc_table: self.desc_table,
363+
queue_size: self.queue_size,
364+
ttl: self.ttl,
365+
index: self.index,
366+
desc: self.desc,
367+
curr_indirect: self.curr_indirect.clone(),
368+
is_master: self.is_master,
369+
has_next: self.has_next,
370+
}
371+
}
372+
}
373+
358374
/// An iterator for readable or writable descriptors.
359375
pub struct DescriptorChainRwIter<'a, M: GuestMemory> {
360376
chain: DescriptorChain<'a, M>,
@@ -1196,6 +1212,7 @@ pub(crate) mod tests {
11961212
assert_eq!(desc.flags(), VIRTQ_DESC_F_NEXT);
11971213
assert_eq!(desc.next, j + 1);
11981214
assert!(c.has_next());
1215+
assert_eq!(c.index(), 0);
11991216
}
12001217
}
12011218

0 commit comments

Comments
 (0)