Skip to content

Commit

Permalink
update to use 64KB msize, don't use tokio for files
Browse files Browse the repository at this point in the history
tokio issue:
- tokio-rs/tokio#1976

This means when we pass a buffer > 16KB to the OS, tokio truncates it to
16KB blowing up 9pfs msize expectations.
  • Loading branch information
rcgoodfellow committed Aug 25, 2022
1 parent 4ed9465 commit 66d46cf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 26 deletions.
36 changes: 13 additions & 23 deletions p9kp/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ use std::error::Error;
use std::io;
use std::marker::Sync;
use std::path::PathBuf;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::{
fs::{File, OpenOptions},
net::UnixStream,
};
use tokio::net::UnixStream;

use std::fs::{File, OpenOptions};
use std::io::{Read, Write};
use std::os::unix::fs::OpenOptionsExt;

#[async_trait]
pub trait Client {
Expand Down Expand Up @@ -172,8 +172,7 @@ impl Client for ChardevClient {
.read(true)
.write(true)
.custom_flags(libc::O_EXCL)
.open(&self.dev)
.await?,
.open(&self.dev)?,
);
Ok(())
}
Expand All @@ -194,28 +193,19 @@ impl Client for ChardevClient {
};

let out = to_bytes_le(t)?;
file.write_all(out.as_slice()).await?;
file.write_all(out.as_slice())?;

trace!(self.log, "message sent");

let mut msg = Vec::new();

loop {
// maximum message size of 8 kB
let mut buf = [0u8; 8192];
debug!(self.log, "waiting for data");
let n = file.read(&mut buf).await?;
debug!(self.log, "read {} bytes", n);
msg.extend_from_slice(&buf[0..n]);
if n < 0xF000 {
break;
}
}
let mut buf = [0u8; crate::CHUNK_SIZE as usize];
debug!(self.log, "reading data ({})", buf.len());
let n = file.read(&mut buf)?;
debug!(self.log, "read {} bytes", n);

let r: R = match read_msg(msg.as_slice()) {
let r: R = match read_msg(buf.as_slice()) {
Ok(r) => r,
Err(e) => {
trace!(self.log, "{:?}", msg.as_slice());
trace!(self.log, "{:?}", buf);
return Err(e);
}
};
Expand Down
6 changes: 3 additions & 3 deletions p9kp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use std::process::Command;

pub mod client;

const CHUNK_SIZE: u32 = 8192;
const CHUNK_SIZE: u32 = 65536;
const MAX_MSG_SIZE: u32 = CHUNK_SIZE - 11;

#[derive(Parser)]
Expand Down Expand Up @@ -269,7 +269,7 @@ async fn copydir<C: Client + Send>(

let mut offset = 0;
loop {
let chunk_size = 8192 - 11;
let chunk_size = MAX_MSG_SIZE;
let readdir = Treaddir::new(newfid, offset, chunk_size);
let d = client.send::<Treaddir, Rreaddir>(&readdir).await?;
if d.data.is_empty() {
Expand Down Expand Up @@ -342,7 +342,7 @@ async fn copyfile<C: Client>(

let mut offset = 0;
loop {
let r = Tread::new(newfid, offset, 8192 - 11 /*mini chunks*/);
let r = Tread::new(newfid, offset, MAX_MSG_SIZE);
let f = client.send::<Tread, Rread>(&r).await?;
if f.data.is_empty() {
break;
Expand Down

0 comments on commit 66d46cf

Please sign in to comment.