-
Notifications
You must be signed in to change notification settings - Fork 0
refine: Refine API #93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,4 +4,4 @@ pub mod device; | |
| pub mod result; | ||
| pub mod transport; | ||
| pub mod types; | ||
| pub mod virt_queue; | ||
| pub mod virtqueue; | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,8 +1,6 @@ | ||||||||||||||||||||||||||||||
| use std::marker::PhantomData; | ||||||||||||||||||||||||||||||
| use std::sync::Arc; | ||||||||||||||||||||||||||||||
| use std::sync::LockResult; | ||||||||||||||||||||||||||||||
| use std::sync::Mutex; | ||||||||||||||||||||||||||||||
| use std::sync::MutexGuard; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| use bitflags::Flags; | ||||||||||||||||||||||||||||||
| use tokio::sync::Notify; | ||||||||||||||||||||||||||||||
|
|
@@ -14,32 +12,34 @@ use crate::result::Result; | |||||||||||||||||||||||||||||
| use crate::transport::control_register::ControlRegister; | ||||||||||||||||||||||||||||||
| use crate::types::interrupt_status::InterruptStatus; | ||||||||||||||||||||||||||||||
| use crate::types::status::Status; | ||||||||||||||||||||||||||||||
| use crate::virt_queue::VirtQueue; | ||||||||||||||||||||||||||||||
| use crate::virtqueue::Virtqueue; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| pub mod control_register; | ||||||||||||||||||||||||||||||
| pub mod mmio; | ||||||||||||||||||||||||||||||
| pub mod pci; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| pub struct VirtioDev<C, D>(Arc<Mutex<VirtioDevInternal<C, D>>>); | ||||||||||||||||||||||||||||||
| pub struct VirtioDev<C, D> { | ||||||||||||||||||||||||||||||
| device: D, | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| impl<C, D> Clone for VirtioDev<C, D> { | ||||||||||||||||||||||||||||||
| fn clone(&self) -> Self { | ||||||||||||||||||||||||||||||
| Self(self.0.clone()) | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| device_feature_sel: Option<u32>, | ||||||||||||||||||||||||||||||
| driver_features: u64, | ||||||||||||||||||||||||||||||
| driver_feature_sel: Option<u32>, | ||||||||||||||||||||||||||||||
| queue_sel: Option<u32>, | ||||||||||||||||||||||||||||||
| virtqueues: Vec<Option<Virtqueue>>, | ||||||||||||||||||||||||||||||
| virtqueue_notifiers: Vec<Option<Arc<Notify>>>, | ||||||||||||||||||||||||||||||
| interrupt_status: InterruptStatus, | ||||||||||||||||||||||||||||||
| status: Status, | ||||||||||||||||||||||||||||||
| config_generation: u32, | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| impl<C, D> VirtioDev<C, D> { | ||||||||||||||||||||||||||||||
| pub fn lock(&self) -> LockResult<MutexGuard<'_, VirtioDevInternal<C, D>>> { | ||||||||||||||||||||||||||||||
| self.0.lock() | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| _mark: PhantomData<C>, | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| impl<C, D> From<D> for VirtioDev<C, D> | ||||||||||||||||||||||||||||||
| impl<C, D> VirtioDev<C, D> | ||||||||||||||||||||||||||||||
| where | ||||||||||||||||||||||||||||||
| C: MemoryContainer, | ||||||||||||||||||||||||||||||
| D: VirtioDevice<C>, | ||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| fn from(device: D) -> Self { | ||||||||||||||||||||||||||||||
| pub fn new(device: D) -> Arc<Mutex<Self>> { | ||||||||||||||||||||||||||||||
| let virtqueues_size_max = device.virtqueues_size_max(); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| let virtqueue_notifiers = virtqueues_size_max | ||||||||||||||||||||||||||||||
|
|
@@ -49,10 +49,10 @@ where | |||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| let virtqueues = virtqueues_size_max | ||||||||||||||||||||||||||||||
| .iter() | ||||||||||||||||||||||||||||||
| .map(|size_max| size_max.map(VirtQueue::new)) | ||||||||||||||||||||||||||||||
| .map(|size_max| size_max.map(Virtqueue::new)) | ||||||||||||||||||||||||||||||
| .collect(); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| let internal = Arc::new(Mutex::new(VirtioDevInternal { | ||||||||||||||||||||||||||||||
| let virtio_dev = Arc::new(Mutex::new(VirtioDev { | ||||||||||||||||||||||||||||||
| device, | ||||||||||||||||||||||||||||||
| device_feature_sel: Default::default(), | ||||||||||||||||||||||||||||||
| driver_features: Default::default(), | ||||||||||||||||||||||||||||||
|
|
@@ -66,8 +66,6 @@ where | |||||||||||||||||||||||||||||
| _mark: PhantomData, | ||||||||||||||||||||||||||||||
| })); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| let virtio_dev = VirtioDev(internal); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| let dev = virtio_dev.lock().unwrap(); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
@@ -94,23 +92,7 @@ where | |||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| pub struct VirtioDevInternal<C, D> { | ||||||||||||||||||||||||||||||
| device: D, | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| device_feature_sel: Option<u32>, | ||||||||||||||||||||||||||||||
| driver_features: u64, | ||||||||||||||||||||||||||||||
| driver_feature_sel: Option<u32>, | ||||||||||||||||||||||||||||||
| queue_sel: Option<u32>, | ||||||||||||||||||||||||||||||
| virtqueues: Vec<Option<VirtQueue>>, | ||||||||||||||||||||||||||||||
| virtqueue_notifiers: Vec<Option<Arc<Notify>>>, | ||||||||||||||||||||||||||||||
| interrupt_status: InterruptStatus, | ||||||||||||||||||||||||||||||
| status: Status, | ||||||||||||||||||||||||||||||
| config_generation: u32, | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| _mark: PhantomData<C>, | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| impl<C, D> VirtioDevInternal<C, D> | ||||||||||||||||||||||||||||||
| impl<C, D> VirtioDev<C, D> | ||||||||||||||||||||||||||||||
| where | ||||||||||||||||||||||||||||||
| D: VirtioDevice<C>, | ||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
|
|
@@ -322,11 +304,11 @@ where | |||||||||||||||||||||||||||||
| self.device.write_config(offset, len, buf) | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| pub fn get_virtqueue(&self, queue_sel: usize) -> Option<&VirtQueue> { | ||||||||||||||||||||||||||||||
| pub fn get_virtqueue(&self, queue_sel: usize) -> Option<&Virtqueue> { | ||||||||||||||||||||||||||||||
| self.virtqueues.get(queue_sel).unwrap().as_ref() | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| pub fn get_virtqueue_mut(&mut self, queue_sel: usize) -> Option<&mut VirtQueue> { | ||||||||||||||||||||||||||||||
| pub fn get_virtqueue_mut(&mut self, queue_sel: usize) -> Option<&mut Virtqueue> { | ||||||||||||||||||||||||||||||
| self.virtqueues.get_mut(queue_sel).unwrap().as_mut() | ||||||||||||||||||||||||||||||
|
Comment on lines
+307
to
312
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid panicking in Both methods currently Suggested patch pub fn get_virtqueue(&self, queue_sel: usize) -> Option<&Virtqueue> {
- self.virtqueues.get(queue_sel).unwrap().as_ref()
+ self.virtqueues.get(queue_sel).and_then(|q| q.as_ref())
}
pub fn get_virtqueue_mut(&mut self, queue_sel: usize) -> Option<&mut Virtqueue> {
- self.virtqueues.get_mut(queue_sel).unwrap().as_mut()
+ self.virtqueues.get_mut(queue_sel).and_then(|q| q.as_mut())
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: junyu0312/rust-vm
Length of output: 770
🏁 Script executed:
Repository: junyu0312/rust-vm
Length of output: 214
🏁 Script executed:
Repository: junyu0312/rust-vm
Length of output: 3824
Build failure: module
virtqueuenot found.The module declaration on line 7 exists but the corresponding source file (
virtqueue.rsorvirtqueue/mod.rs) is missing. This breaks the build sincetransport.rsanddevice.rsboth import fromcrate::virtqueue. Include the virtqueue module implementation in this PR.🧰 Tools
🪛 GitHub Actions: CI
[error] 7-7: file not found for module
virtqueue.🤖 Prompt for AI Agents