Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/api/filesystem/sync_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ pub trait FileSystem {
cmd: u32,
data: IoctlData,
out_size: u32,
) -> io::Result<IoctlData> {
) -> io::Result<IoctlData<'_>> {
// Rather than ENOSYS, let's return ENOTTY so simulate that the ioctl call is implemented
// but no ioctl number is supported.
Err(io::Error::from_raw_os_error(libc::ENOTTY))
Expand Down Expand Up @@ -1313,7 +1313,7 @@ impl<FS: FileSystem> FileSystem for Arc<FS> {
cmd: u32,
data: IoctlData,
out_size: u32,
) -> io::Result<IoctlData> {
) -> io::Result<IoctlData<'_>> {
self.deref()
.ioctl(ctx, inode, handle, flags, cmd, data, out_size)
}
Expand Down
25 changes: 9 additions & 16 deletions src/api/vfs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use std::collections::HashMap;
use std::ffi::CStr;
use std::fmt;
use std::io;
use std::io::{Error, ErrorKind, Result};
use std::io::{Error, Result};
use std::ops::Deref;
use std::sync::atomic::{AtomicBool, AtomicU8, Ordering};
use std::sync::{Arc, Mutex};
Expand Down Expand Up @@ -434,13 +434,10 @@ impl Vfs {
pub fn restore_mount(&self, fs: BackFileSystem, fs_idx: VfsIndex, path: &str) -> Result<()> {
let (entry, ino) = fs.mount()?;
if ino > VFS_MAX_INO {
return Err(Error::new(
ErrorKind::Other,
format!(
"Unsupported max inode number, requested {} supported {}",
ino, VFS_MAX_INO
),
));
return Err(Error::other(format!(
"Unsupported max inode number, requested {} supported {}",
ino, VFS_MAX_INO
)));
}

let _guard = self.lock.lock().unwrap();
Expand Down Expand Up @@ -535,10 +532,9 @@ impl Vfs {
return Ok(inode);
}
if inode > VFS_MAX_INO {
return Err(Error::new(
ErrorKind::Other,
format!("Inode number {inode} too large, max supported {VFS_MAX_INO}"),
));
return Err(Error::other(format!(
"Inode number {inode} too large, max supported {VFS_MAX_INO}"
)));
}
let ino: u64 = ((fs_idx as u64) << VFS_INDEX_SHIFT) | inode;
trace!(
Expand Down Expand Up @@ -630,10 +626,7 @@ impl Vfs {
}
}

Err(Error::new(
ErrorKind::Other,
"vfs maximum mountpoints reached",
))
Err(Error::other("vfs maximum mountpoints reached"))
}

fn get_fs_by_idx(&self, fs_idx: VfsIndex) -> Result<Arc<BackFileSystem>> {
Expand Down
4 changes: 2 additions & 2 deletions src/common/file_buf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,13 +315,13 @@ impl FileVolatileBuf {
}

/// Generate an `IoSlice` object to read data from the buffer.
pub fn io_slice(&self) -> IoSlice {
pub fn io_slice(&self) -> IoSlice<'_> {
let buf = unsafe { slice::from_raw_parts(self.addr as *const u8, self.size) };
IoSlice::new(buf)
}

/// Generate an `IoSliceMut` object to write data into the buffer.
pub fn io_slice_mut(&self) -> IoSliceMut {
pub fn io_slice_mut(&self) -> IoSliceMut<'_> {
let buf = unsafe {
let ptr = (self.addr as *mut u8).add(self.size);
let sz = self.cap - self.size;
Expand Down
10 changes: 5 additions & 5 deletions src/overlayfs/inode_store.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (C) 2023 Ant Group. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

use std::io::{Error, ErrorKind, Result};
use std::io::{Error, Result};
use std::{
collections::HashMap,
sync::{atomic::Ordering, Arc},
Expand Down Expand Up @@ -45,10 +45,10 @@ impl InodeStore {
ino += 1;
}
error!("reached maximum inode number: {}", VFS_MAX_INO);
Err(Error::new(
ErrorKind::Other,
format!("maximum inode number {} reached", VFS_MAX_INO),
))
Err(Error::other(format!(
"maximum inode number {} reached",
VFS_MAX_INO
)))
}

pub(crate) fn alloc_inode(&mut self, path: &String) -> Result<Inode> {
Expand Down
23 changes: 10 additions & 13 deletions src/overlayfs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ impl OverlayInode {
let pnode = if let Some(n) = self.parent.lock().unwrap().upgrade() {
Arc::clone(&n)
} else {
return Err(Error::new(ErrorKind::Other, "no parent?"));
return Err(Error::other("no parent?"));
};

if !pnode.in_upper_layer() {
Expand Down Expand Up @@ -818,13 +818,10 @@ impl OverlayInode {
f(None)
}
}
None => Err(Error::new(
ErrorKind::Other,
format!(
"BUG: dangling OverlayInode {} without any backend inode",
self.inode
),
)),
None => Err(Error::other(format!(
"BUG: dangling OverlayInode {} without any backend inode",
self.inode
))),
}
}
}
Expand Down Expand Up @@ -1119,7 +1116,7 @@ impl OverlayFs {
let all_inodes = ovi.real_inodes.lock().unwrap();
let real_inode = all_inodes
.first()
.ok_or(Error::new(ErrorKind::Other, "backend inode not found"))?;
.ok_or(Error::other("backend inode not found"))?;
real_inode.layer.statfs(ctx, real_inode.inode)
}
None => Err(Error::from_raw_os_error(libc::ENOENT)),
Expand Down Expand Up @@ -1694,7 +1691,7 @@ impl OverlayFs {
let parent_node = if let Some(ref n) = node.parent.lock().unwrap().upgrade() {
Arc::clone(n)
} else {
return Err(Error::new(ErrorKind::Other, "no parent?"));
return Err(Error::other("no parent?"));
};

let (self_layer, _, self_inode) = node.first_layer_inode();
Expand Down Expand Up @@ -1736,7 +1733,7 @@ impl OverlayFs {
let parent_node = if let Some(ref n) = node.parent.lock().unwrap().upgrade() {
Arc::clone(n)
} else {
return Err(Error::new(ErrorKind::Other, "no parent?"));
return Err(Error::other("no parent?"));
};

let st = node.stat64(ctx)?;
Expand Down Expand Up @@ -2027,8 +2024,8 @@ impl OverlayFs {
.childrens
.lock()
.unwrap()
.iter()
.map(|(_, v)| v.clone())
.values()
.cloned()
.collect::<Vec<_>>();

for child in iter {
Expand Down
4 changes: 2 additions & 2 deletions src/overlayfs/sync_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::api::filesystem::{
};

use libc;
use std::io::{Error, ErrorKind};
use std::io::Error;

impl FileSystem for OverlayFs {
type Inode = Inode;
Expand Down Expand Up @@ -350,7 +350,7 @@ impl FileSystem for OverlayFs {
let rh = if let Some(ref h) = hd.real_handle {
h
} else {
return Err(Error::new(ErrorKind::Other, "no handle"));
return Err(Error::other("no handle"));
};
let real_handle = rh.handle.load(Ordering::Relaxed);
let real_inode = rh.inode;
Expand Down
13 changes: 6 additions & 7 deletions src/passthrough/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ impl InodeMap {
.cloned()
}

fn get_map_mut(&self) -> RwLockWriteGuard<InodeStore> {
fn get_map_mut(&self) -> RwLockWriteGuard<'_, InodeStore> {
// Do not expect poisoned lock here, so safe to unwrap().
self.inodes.write().unwrap()
}
Expand Down Expand Up @@ -275,11 +275,11 @@ impl HandleData {
&self.file
}

fn get_file_mut(&self) -> (MutexGuard<()>, &File) {
fn get_file_mut(&self) -> (MutexGuard<'_, ()>, &File) {
(self.lock.lock().unwrap(), &self.file)
}

fn borrow_fd(&self) -> BorrowedFd {
fn borrow_fd(&self) -> BorrowedFd<'_> {
self.file.as_fd()
}

Expand Down Expand Up @@ -706,10 +706,9 @@ impl<S: BitmapSlice + Send + Sync> PassthroughFs<S> {

if inode > VFS_MAX_INO {
error!("fuse: max inode number reached: {}", VFS_MAX_INO);
return Err(io::Error::new(
io::ErrorKind::Other,
format!("max inode number reached: {VFS_MAX_INO}"),
));
return Err(io::Error::other(format!(
"max inode number reached: {VFS_MAX_INO}"
)));
}

InodeMap::insert_locked(
Expand Down
2 changes: 1 addition & 1 deletion src/passthrough/mount_fd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct MountFd {
}

impl AsFd for MountFd {
fn as_fd(&self) -> BorrowedFd {
fn as_fd(&self) -> BorrowedFd<'_> {
self.file.as_fd()
}
}
Expand Down
11 changes: 5 additions & 6 deletions src/passthrough/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ impl UniqueInodeGenerator {
btree_map::Entry::Occupied(v) => *v.get(),
btree_map::Entry::Vacant(v) => {
if self.next_unique_id.load(Ordering::Relaxed) == u8::MAX {
return Err(io::Error::new(
io::ErrorKind::Other,
return Err(io::Error::other(
"the number of combinations of dev and mntid exceeds 255",
));
}
Expand All @@ -69,10 +68,10 @@ impl UniqueInodeGenerator {
id.ino
} else {
if self.next_virtual_inode.load(Ordering::Relaxed) > MAX_HOST_INO {
return Err(io::Error::new(
io::ErrorKind::Other,
format!("the virtual inode excess {}", MAX_HOST_INO),
));
return Err(io::Error::other(format!(
"the virtual inode excess {}",
MAX_HOST_INO
)));
}
self.next_virtual_inode.fetch_add(1, Ordering::Relaxed) | VIRTUAL_INODE_FLAG
};
Expand Down
2 changes: 1 addition & 1 deletion src/transport/fusedev/fuse_t_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ impl FuseChannel {
/// - Ok(None): signal has pending on the exiting event channel
/// - Ok(Some((reader, writer))): reader to receive request and writer to send reply
/// - Err(e): error message
pub fn get_request(&mut self) -> Result<Option<(Reader, FuseDevWriter)>> {
pub fn get_request(&mut self) -> Result<Option<(Reader<'_>, FuseDevWriter<'_>)>> {
let file_lock = self.file_lock.clone();
let result = file_lock.lock();
let fd = self.file.as_raw_fd();
Expand Down
2 changes: 1 addition & 1 deletion src/transport/fusedev/linux_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ impl FuseChannel {
/// - Ok(None): signal has pending on the exiting event channel
/// - Ok(Some((reader, writer))): reader to receive request and writer to send reply
/// - Err(e): error message
pub fn get_request(&mut self) -> Result<Option<(Reader, FuseDevWriter)>> {
pub fn get_request(&mut self) -> Result<Option<(Reader<'_>, FuseDevWriter<'_>)>> {
let mut events = Events::with_capacity(POLL_EVENTS_CAPACITY);
let mut need_exit = false;
loop {
Expand Down
2 changes: 1 addition & 1 deletion src/transport/fusedev/macos_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ impl FuseChannel {
/// - Ok(None): signal has pending on the exiting event channel
/// - Ok(Some((reader, writer))): reader to receive request and writer to send reply
/// - Err(e): error message
pub fn get_request(&mut self) -> Result<Option<(Reader, FuseDevWriter)>> {
pub fn get_request(&mut self) -> Result<Option<(Reader<'_>, FuseDevWriter<'_>)>> {
let fd = self.file.as_raw_fd();
loop {
match read(fd, &mut self.buf) {
Expand Down
23 changes: 10 additions & 13 deletions src/transport/fusedev/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ impl<'a, S: BitmapSlice> FuseDevWriter<'a, S> {
fn do_write(fd: RawFd, data: &[u8]) -> io::Result<usize> {
write(fd, data).map_err(|e| {
error! {"fail to write to fuse device fd {}: {}, {:?}", fd, e, data};
io::Error::new(io::ErrorKind::Other, format!("{e}"))
io::Error::other(format!("{e}"))
})
}
}
Expand Down Expand Up @@ -322,18 +322,15 @@ impl<S: BitmapSlice> Write for FuseDevWriter<'_, S> {
})
.map_err(|e| {
error! {"fail to write to fuse device on commit: {}", e};
io::Error::new(io::ErrorKind::Other, format!("{e}"))
io::Error::other(format!("{e}"))
})
}
}

/// As this writer can associate multiple writers by splitting, `flush()` can't
/// flush them all. Disable it!
fn flush(&mut self) -> io::Result<()> {
Err(io::Error::new(
io::ErrorKind::Other,
"Writer does not support flush buffer.",
))
Err(io::Error::other("Writer does not support flush buffer."))
}
}

Expand Down Expand Up @@ -362,7 +359,7 @@ mod async_io {
})
.map_err(|e| {
error! {"fail to write to fuse device fd {}: {}", self.fd, e};
io::Error::new(io::ErrorKind::Other, format!("{}", e))
io::Error::other(format!("{}", e))
})
}
}
Expand All @@ -388,7 +385,7 @@ mod async_io {
})
.map_err(|e| {
error! {"fail to write to fuse device fd {}: {}", self.fd, e};
io::Error::new(io::ErrorKind::Other, format!("{}", e))
io::Error::other(format!("{}", e))
})
}
}
Expand Down Expand Up @@ -420,7 +417,7 @@ mod async_io {
})
.map_err(|e| {
error! {"fail to write to fuse device fd {}: {}", self.fd, e};
io::Error::new(io::ErrorKind::Other, format!("{}", e))
io::Error::other(format!("{}", e))
})
}
}
Expand Down Expand Up @@ -466,7 +463,7 @@ mod async_io {
// write to fd, can only happen once per instance
nix::sys::uio::pwrite(self.fd, &self.buf[..cnt], 0).map_err(|e| {
error! {"fail to write to fuse device fd {}: {}", self.fd, e};
io::Error::new(io::ErrorKind::Other, format!("{}", e))
io::Error::other(format!("{}", e))
})
}
}
Expand All @@ -487,17 +484,17 @@ mod async_io {
(0, 0) => Ok(0),
(0, _) => nix::sys::uio::pwrite(self.fd, o, 0).map_err(|e| {
error! {"fail to write to fuse device fd {}: {}", self.fd, e};
io::Error::new(io::ErrorKind::Other, format!("{}", e))
io::Error::other(format!("{}", e))
}),
(_, 0) => nix::sys::uio::pwrite(self.fd, self.buf.as_slice(), 0).map_err(|e| {
error! {"fail to write to fuse device fd {}: {}", self.fd, e};
io::Error::new(io::ErrorKind::Other, format!("{}", e))
io::Error::other(format!("{}", e))
}),
(_, _) => {
let bufs = [IoSlice::new(self.buf.as_slice()), IoSlice::new(o)];
writev(self.fd, &bufs).map_err(|e| {
error! {"fail to write to fuse device fd {}: {}", self.fd, e};
io::Error::new(io::ErrorKind::Other, format!("{}", e))
io::Error::other(format!("{}", e))
})
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/transport/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl<S: BitmapSlice> IoBuffers<'_, S> {
self.bytes_consumed
}

fn allocate_file_volatile_slice(&self, count: usize) -> Vec<FileVolatileSlice> {
fn allocate_file_volatile_slice(&self, count: usize) -> Vec<FileVolatileSlice<'_>> {
let mut rem = count;
let mut bufs: Vec<FileVolatileSlice> = Vec::with_capacity(self.buffers.len());

Expand Down
Loading