start a cleanup pass on warnings

This commit is contained in:
bunnie 2022-01-07 22:10:54 +08:00
parent 11c22b6d19
commit b4bfaefa64
5 changed files with 68 additions and 9 deletions

View file

@ -1,3 +1,4 @@
{
"rust-analyzer.checkOnSave.allTargets": false
"rust-analyzer.checkOnSave.allTargets": false,
"rust-analyzer.cargo.target":"riscv32imac-unknown-xous-elf"
}

View file

@ -160,6 +160,9 @@ pub(crate) enum PddbRetcode {
Ok = 1,
BasisLost = 2,
AccessDenied = 3,
UnexpectedEof = 4,
InternalError = 5,
DiskFull = 6,
}
/// PddbBuf is a C-representation of a page of memory that's used
/// to shuttle data for streaming channels. It must be exactly one

View file

@ -1319,7 +1319,7 @@ impl BasisCacheEntry {
if let Some(dict) = self.dicts.get_mut(&String::from(name)) {
let dict_offset = VirtAddr::new(dict.index.get() as u64 * DICT_VSIZE).unwrap();
if !dict.clean {
let mut dict_name = DictName::try_from_str(name).or(Err(Error::new(ErrorKind::InvalidInput, "dictionary name invalid: invalid utf-8 or length")))?;
let dict_name = DictName::try_from_str(name).or(Err(Error::new(ErrorKind::InvalidInput, "dictionary name invalid: invalid utf-8 or length")))?;
let dict_disk = Dictionary {
flags: dict.flags,
age: dict.age,
@ -1385,7 +1385,7 @@ impl BasisCacheEntry {
log::debug!("merging in key {}", key_name);
// key is within the current page, add it to the target list
let mut dk_entry = DictKeyEntry::default();
let mut kn = KeyName::try_from_str(key_name).or(Err(Error::new(ErrorKind::InvalidInput, "key name invalid: invalid utf-8 or length")))?;
let kn = KeyName::try_from_str(key_name).or(Err(Error::new(ErrorKind::InvalidInput, "key name invalid: invalid utf-8 or length")))?;
let key_desc = KeyDescriptor {
start: key.start,
len: key.len,

View file

@ -134,6 +134,7 @@ impl<'a> Write for PddbKey<'a> {
match FromPrimitive::from_u8(rcode as u8) {
Some(PddbRetcode::Ok) => Ok(()),
Some(PddbRetcode::BasisLost) => Err(Error::new(ErrorKind::BrokenPipe, "Basis lost")),
Some(PddbRetcode::DiskFull) => Err(Error::new(ErrorKind::OutOfMemory, "Out of disk space, some data lost on sync")),
_ => Err(Error::new(ErrorKind::Interrupted, "Flush failed for unspecified reasons")),
}
} else {

View file

@ -399,6 +399,7 @@ struct TokenRecord {
pub dict: String,
pub key: String,
pub basis: Option<String>,
pub alloc_hint: Option<usize>,
pub conn: xous::CID, // callback connection
}
@ -724,6 +725,7 @@ fn xmain() -> ! {
key: String::from(key),
basis: if let Some(name) = bname {Some(String::from(name))} else {None},
conn: cid,
alloc_hint: if let Some(hint) = req.alloc_hint {Some(hint as usize)} else {None},
};
token_dict.insert(token, token_record);
req.token = Some(token);
@ -948,7 +950,7 @@ fn xmain() -> ! {
Some(Opcode::GetDictNameAtIndex) => {
let mut buffer = unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) };
let mut req = buffer.to_original::<PddbDictRequest, _>().unwrap();
if let Some(token) = key_token {
if let Some(token) = dict_token {
if req.token != token {
req.code = PddbRequestCode::AccessDenied;
} else {
@ -970,14 +972,66 @@ fn xmain() -> ! {
buffer.replace(req).unwrap();
}
Some(Opcode::ReadKey) => {
// placeholder
let mut buffer = unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) };
let pbuf = PddbBuf::from_slice_mut(buffer.as_mut()); // direct translation, no serialization necessary for performance
let token = pbuf.token;
if let Some(rec) = token_dict.get(&token) {
match basis_cache.key_read(&mut pddb_os,
&rec.dict, &rec.key,
&mut pbuf.data[..pbuf.len as usize], Some(pbuf.position as usize),
if let Some (name) = &rec.basis {Some(&name)} else {None}) {
Ok(readlen) => {
pbuf.len = readlen as u16;
pbuf.retcode = PddbRetcode::Ok;
}
Err(e) => match e.kind() {
std::io::ErrorKind::NotFound => pbuf.retcode = PddbRetcode::BasisLost,
std::io::ErrorKind::UnexpectedEof => pbuf.retcode = PddbRetcode::UnexpectedEof,
std::io::ErrorKind::OutOfMemory => pbuf.retcode = PddbRetcode::DiskFull,
_ => pbuf.retcode = PddbRetcode::InternalError,
}
}
} else {
pbuf.retcode = PddbRetcode::BasisLost;
}
// we don't nede a "replace" operation because all ops happen in-place
}
Some(Opcode::WriteKey) => {
// placeholder
}
Some(Opcode::WriteKeyFlush) => {
// placeholder
let mut buffer = unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) };
let pbuf = PddbBuf::from_slice_mut(buffer.as_mut()); // direct translation, no serialization necessary for performance
let token = pbuf.token;
if let Some(rec) = token_dict.get(&token) {
match basis_cache.key_update(&mut pddb_os,
&rec.dict, &rec.key,
&pbuf.data[..pbuf.len as usize], Some(pbuf.position as usize),
rec.alloc_hint, if let Some (name) = &rec.basis {Some(&name)} else {None},
false
) {
Ok(_) => {
pbuf.retcode = PddbRetcode::Ok;
}
Err(e) => match e.kind() {
std::io::ErrorKind::NotFound => pbuf.retcode = PddbRetcode::BasisLost,
std::io::ErrorKind::UnexpectedEof => pbuf.retcode = PddbRetcode::UnexpectedEof,
std::io::ErrorKind::OutOfMemory => pbuf.retcode = PddbRetcode::DiskFull,
_ => pbuf.retcode = PddbRetcode::InternalError,
}
}
} else {
pbuf.retcode = PddbRetcode::BasisLost;
}
// we don't nede a "replace" operation because all ops happen in-place
}
Some(Opcode::WriteKeyFlush) => msg_blocking_scalar_unpack!(msg, _, _, _, _, {
match basis_cache.sync(&mut pddb_os, None) {
Ok(_) => xous::return_scalar(msg.sender, PddbRetcode::Ok.to_usize().unwrap()).unwrap(),
Err(e) => match e.kind() {
std::io::ErrorKind::OutOfMemory => xous::return_scalar(msg.sender, PddbRetcode::DiskFull.to_usize().unwrap()).unwrap(),
std::io::ErrorKind::NotFound => xous::return_scalar(msg.sender, PddbRetcode::BasisLost.to_usize().unwrap()).unwrap(),
_ => xous::return_scalar(msg.sender, PddbRetcode::InternalError.to_usize().unwrap()).unwrap(),
}
};
}),
Some(Opcode::Quit) => {
log::warn!("quitting the PDDB server");
send_message(