Skip to content

Commit

Permalink
Merge pull request #1204 from cagatay-y/too-virtq-too-refactor
Browse files Browse the repository at this point in the history
fuse: provide header and payloads separately
  • Loading branch information
mkroening authored May 22, 2024
2 parents 7614614 + 21c7a2b commit 1646570
Show file tree
Hide file tree
Showing 6 changed files with 420 additions and 1,020 deletions.
23 changes: 11 additions & 12 deletions src/drivers/fs/virtio_fs.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use alloc::boxed::Box;
use alloc::rc::Rc;
use alloc::string::{String, ToString};
use alloc::vec::Vec;
Expand All @@ -15,7 +16,7 @@ use crate::drivers::virtio::transport::mmio::{ComCfg, IsrStatus, NotifCfg};
use crate::drivers::virtio::transport::pci::{ComCfg, IsrStatus, NotifCfg};
use crate::drivers::virtio::virtqueue::error::VirtqError;
use crate::drivers::virtio::virtqueue::split::SplitVq;
use crate::drivers::virtio::virtqueue::{AsSliceU8, BuffSpec, Bytes, Virtq, VqIndex, VqSize};
use crate::drivers::virtio::virtqueue::{AsSliceU8, BufferType, Virtq, VqIndex, VqSize};
use crate::fs::fuse::{self, FuseInterface};

/// A wrapper struct for the raw configuration structure.
Expand Down Expand Up @@ -143,21 +144,19 @@ impl VirtioFsDriver {
impl FuseInterface for VirtioFsDriver {
fn send_command<O: fuse::ops::Op>(
&mut self,
cmd: &fuse::Cmd<O>,
cmd: (Box<fuse::CmdHeader<O>>, Option<Box<[u8]>>),
rsp: &mut fuse::Rsp<O>,
) -> Result<(), VirtqError> {
let send = (
cmd.as_slice_u8(),
BuffSpec::Single(Bytes::new(cmd.len()).ok_or(VirtqError::BufferToLarge)?),
);
let rsp_len = rsp.len();
let recv = (
rsp.as_slice_u8_mut(),
BuffSpec::Single(Bytes::new(rsp_len).ok_or(VirtqError::BufferToLarge)?),
);
let (cmd_header, cmd_payload_opt) = cmd;
let send: &[&[u8]] = if let Some(cmd_payload) = cmd_payload_opt.as_deref() {
&[cmd_header.as_slice_u8(), cmd_payload]
} else {
&[cmd_header.as_slice_u8()]
};
let recv = &[rsp.as_slice_u8_mut()];
let transfer_tkn = self.vqueues[1]
.clone()
.prep_transfer_from_raw(Some(send), Some(recv))
.prep_transfer_from_raw(send, recv, BufferType::Direct)
.unwrap();
transfer_tkn.dispatch_blocking()?;
Ok(())
Expand Down
Loading

0 comments on commit 1646570

Please sign in to comment.