-
Notifications
You must be signed in to change notification settings - Fork 36
Description of inoder-handler.rs #31
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
Open
bhartisaurav
wants to merge
2
commits into
codenet:main
Choose a base branch
from
bhartisaurav:patch-1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# Description of inoder-handler | ||
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. Testing |
||
|
||
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. Testing |
||
### Brief about Virtio: | ||
virtIO is a virtualization standard for network and disk device drivers. It was chosen to be the main platform for IO virtualization in KVM. | ||
|
||
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. testing |
||
### About virtio block: | ||
- The virtio-blk device presents a block device to the virtual machine. | ||
- Each virtio-blk device appears as a disk inside the guest. | ||
- Virtio-blk is an abstraction layer over devices in a paravirtualized hypervisor. | ||
- It mainly provides two abstractions: | ||
- Request: Contains block request parsing abstraction. | ||
- Executor: Contains a block request execution abstraction that is based on std::io::Read and std::io::Write. | ||
|
||
### Inorder-handler: | ||
|
||
- This object is used to process the queue of a block device without making any assumptions about the notification mechanism. | ||
- For the time being, it uses a special backend called "StdIoBackend", but in the future it will implement the more generic and flexible one. | ||
- This queuehandler takes the request and processes it. Return the requests in the same order in which they were received. | ||
```rs | ||
pub struct InOrderQueueHandler<M: GuestAddressSpace, S: SignalUsedQueue> { | ||
pub driver_notify: S, | ||
pub queue: Queue<M>, | ||
pub disk: StdIoBackend<File>, | ||
} | ||
``` | ||
|
||
- In this process_queue implementation, we follow various steps: | ||
- First, we disable the notification event from guest drivers. | ||
- Then, we process the available chain of requests through the process_chain method. | ||
- If notification is enabled, then we process the next set of requests in the chain. | ||
|
||
``` | ||
pub fn process_queue(&mut self) -> result::Result<(), Error> { | ||
|
||
//basically telling the way of cosuming descriptor from the queue. | ||
loop { | ||
self.queue.disable_notification()?; | ||
|
||
while let Some(chain) = self.queue.iter()?.next() { | ||
self.process_chain(chain)?; | ||
} | ||
|
||
if !self.queue.enable_notification()? { | ||
break; | ||
} | ||
} | ||
|
||
Ok(()) | ||
} | ||
``` | ||
|
||
|
||
- In this process_chain implementation, we take each request from the chain of requests, assuming there is no request parse error. | ||
- Then, process each request and write it into the memory buffer. | ||
``` | ||
fn process_chain(&mut self, mut chain: DescriptorChain<M::T>) -> result::Result<(), Error> { | ||
let used_len = match Request::parse(&mut chain) { | ||
Ok(request) => self.disk.process_request(chain.memory(), &request)?, | ||
Err(e) => { | ||
warn!("block request parse error: {:?}", e); | ||
0 | ||
} | ||
}; | ||
``` | ||
|
||
- After processing each request, it is used to update the used ring through the chain descriptor and the total length of the descriptor chain that was used (written to). It is also sent the notification if needed, based on request. | ||
self.queue.add_used(chain.head_index(), used_len)?; | ||
|
||
if self.queue.needs_notification()? { | ||
self.driver_notify.signal_used_queue(0); | ||
} | ||
``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Testing