Skip to content

Commit

Permalink
Clean up clippy warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Jiang Liu <gerry@linux.alibaba.com>
  • Loading branch information
jiangliu committed May 29, 2022
1 parent 057d452 commit 73234da
Show file tree
Hide file tree
Showing 53 changed files with 759 additions and 797 deletions.
1,074 changes: 532 additions & 542 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion api/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ fn handle_http_request(
let mut response = match uri_parsed {
Ok(uri) => match HTTP_ROUTES.routes.get(uri.path()) {
Some(route) => route
.handle_request(&request, &|r| {
.handle_request(request, &|r| {
kick_api_server(api_notifier.clone(), to_api, from_api, r)
})
.unwrap_or_else(|err| error_response(err, StatusCode::BadRequest)),
Expand Down
13 changes: 2 additions & 11 deletions blobfs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use std::sync::{Arc, Mutex};
use std::thread;

#[cfg(feature = "virtiofs")]
use storage::device::BlobPrefetchRequest;
use nydus_storage::device::BlobPrefetchRequest;
use vm_memory::ByteValued;

mod sync_io;
Expand Down Expand Up @@ -94,23 +94,14 @@ impl FromStr for BlobOndemandConfig {
}

/// Options that configure the behavior of the blobfs fuse file system.
#[derive(Debug, Clone, PartialEq)]
#[derive(Default, Debug, Clone, PartialEq)]
pub struct Config {
/// Blobfs config is embedded with passthrough config
pub ps_config: PassthroughConfig,
/// This provides on demand config of blob management.
pub blob_ondemand_cfg: String,
}

impl Default for Config {
fn default() -> Self {
Config {
ps_config: PassthroughConfig::default(),
blob_ondemand_cfg: Default::default(),
}
}
}

#[allow(dead_code)]
struct RafsHandle {
rafs: Arc<Mutex<Option<Rafs>>>,
Expand Down
6 changes: 3 additions & 3 deletions blobfs/src/sync_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ use fuse_backend_rs::api::CreateIn;
use fuse_backend_rs::transport::FsCacheReqHandler;
use nydus_error::eacces;
#[cfg(feature = "virtiofs")]
use nydus_storage::device::BlobPrefetchRequest;
#[cfg(feature = "virtiofs")]
use std::cmp::min;
use std::ffi::CStr;
use std::io;
#[cfg(feature = "virtiofs")]
use std::path::Path;
use std::time::Duration;
#[cfg(feature = "virtiofs")]
use storage::device::BlobPrefetchRequest;

impl BlobFs {
#[cfg(feature = "virtiofs")]
Expand Down Expand Up @@ -50,7 +50,7 @@ impl BlobFs {

let blob_file = Self::open_file(
libc::AT_FDCWD,
&blob_id_full_path.as_path(),
blob_id_full_path.as_path(),
libc::O_PATH | libc::O_NOFOLLOW | libc::O_CLOEXEC,
0,
)
Expand Down
6 changes: 3 additions & 3 deletions rafs/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ macro_rules! trim_backend_config {
($config:expr, $($i:expr),*) => {
let mut _n :&mut serde_json::Value = &mut $config["device"]["backend"]["config"];
if let serde_json::Value::Object(ref mut m) = _n {
$(if m.contains_key($i) { m[$i].take();} else {()};)*
$(if m.contains_key($i) { m[$i].take();} )*
}
};
}
}

/// Rafs storage backend configuration information.
Expand Down Expand Up @@ -1029,7 +1029,7 @@ pub(crate) mod tests {
#[test]
fn it_should_enable_xattr() {
let rafs = new_rafs_backend();
assert_eq!(rafs.xattr_supported(), true);
assert!(rafs.xattr_supported());
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion rafs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl std::error::Error for RafsError {

impl Display for RafsError {
fn fmt(&self, f: &mut Formatter) -> FmtResult {
write!(f, "{}", format!("{:?}", self))?;
write!(f, "{:?}", self)?;
Ok(())
}
}
Expand Down
4 changes: 2 additions & 2 deletions rafs/src/metadata/cached_v5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ mod cached_tests {
assert_eq!(cached_chunk.uncompress_offset(), 0);
let c_xattr = cached_inode.get_xattrs().unwrap();
for k in c_xattr.iter() {
let k = OsStr::from_bytes(&k);
let k = OsStr::from_bytes(k);
let v = cached_inode.get_xattr(k).unwrap();
assert_eq!(xattr.get(k).cloned().unwrap(), v.unwrap());
}
Expand Down Expand Up @@ -990,7 +990,7 @@ mod cached_tests {

assert_eq!(sb.max_inode, RAFS_ROOT_INODE);
assert_eq!(sb.s_inodes.len(), 0);
assert_eq!(sb.validate_digest, true);
assert!(sb.validate_digest);

let mut inode = CachedInodeV5::new(sb.s_blob.clone(), sb.s_meta.clone());
inode.i_ino = 1;
Expand Down
10 changes: 5 additions & 5 deletions rafs/src/metadata/direct_v5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ struct DirectMappingState {
validate_digest: bool,
}

// Safe to Send/Sync because the underlying data structures are readonly
unsafe impl Send for DirectMappingState {}

unsafe impl Sync for DirectMappingState {}

impl DirectMappingState {
fn new(meta: &RafsSuperMeta, validate_digest: bool) -> Self {
DirectMappingState {
Expand Down Expand Up @@ -180,11 +185,6 @@ pub struct DirectSuperBlockV5 {
state: ArcSwap<DirectMappingState>,
}

// Safe to Send/Sync because the underlying data structures are readonly
unsafe impl Send for DirectSuperBlockV5 {}

unsafe impl Sync for DirectSuperBlockV5 {}

impl DirectSuperBlockV5 {
/// Create a new instance of `DirectSuperBlockV5`.
pub fn new(meta: &RafsSuperMeta, validate_digest: bool) -> Self {
Expand Down
8 changes: 4 additions & 4 deletions rafs/src/metadata/direct_v6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ use storage::device::{
};
use storage::utils::readahead;

// Safe to Send/Sync because the underlying data structures are readonly
unsafe impl Send for DirectSuperBlockV6 {}
unsafe impl Sync for DirectSuperBlockV6 {}

fn err_invalidate_data(rafs_err: RafsError) -> std::io::Error {
std::io::Error::new(std::io::ErrorKind::InvalidData, rafs_err)
}
Expand All @@ -86,6 +82,10 @@ struct DirectMappingState {
validate_digest: bool,
}

// Safe to Send/Sync because the underlying data structures are readonly
unsafe impl Send for DirectMappingState {}
unsafe impl Sync for DirectMappingState {}

impl DirectMappingState {
fn new(meta: &RafsSuperMeta, validate_digest: bool) -> Self {
DirectMappingState {
Expand Down
2 changes: 1 addition & 1 deletion rafs/src/metadata/layout/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ mod tests {
#[test]
fn test_bootstrap_convert() {
let mut value = 0x504030201u64;
let buf: &mut [u8] = &mut value.as_mut_slice();
let buf = value.as_mut_slice();

let v: std::io::Result<&MockU32> = (&buf[1..5]).try_into();
assert!(v.is_err());
Expand Down
27 changes: 14 additions & 13 deletions rafs/src/metadata/layout/v5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -847,13 +847,13 @@ impl RafsV5ExtBlobTable {
pub fn load(&mut self, r: &mut RafsIoReader, count: usize) -> Result<()> {
let mut entries = Vec::<RafsV5ExtBlobEntry>::with_capacity(count);
// Safe because it is already reserved enough space
let (_, mut data, _) = unsafe {
let (_, data, _) = unsafe {
entries.set_len(count);
(&mut entries).align_to_mut::<u8>()
};

r.read_exact(&mut data)?;
self.entries = entries.to_vec().into_iter().map(Arc::new).collect();
r.read_exact(data)?;
self.entries = entries.iter().cloned().map(Arc::new).collect();

Ok(())
}
Expand Down Expand Up @@ -1387,7 +1387,7 @@ pub(crate) fn rafsv5_validate_digest(
return Ok(false);
}
let child_digest = child.get_digest();
let child_digest = child_digest.as_ref().as_ref();
let child_digest = child_digest.as_ref();

hasher.digest_update(child_digest);
}
Expand Down Expand Up @@ -1579,6 +1579,7 @@ pub mod tests {
pub uncompress_offset: u64,
pub file_offset: u64,
pub index: u32,
#[allow(unused)]
pub reserved: u32,
}

Expand Down Expand Up @@ -1815,11 +1816,11 @@ pub mod tests {

assert_eq!(table.size(), 0);
assert_eq!(table.len(), 0);
assert_eq!(table.is_empty(), true);
assert!(table.is_empty());
table.add_entry(0x1);
assert_eq!(table.size(), 8);
assert_eq!(table.len(), 1);
assert_eq!(table.is_empty(), false);
assert!(!table.is_empty());

let tmp_file = TempFile::new().unwrap();
let file = OpenOptions::new()
Expand All @@ -1843,7 +1844,7 @@ pub mod tests {
table.load_prefetch_table_from(&mut reader, 8, 2).unwrap();
assert_eq!(table.size(), 8);
assert_eq!(table.len(), 2);
assert_eq!(table.is_empty(), false);
assert!(!table.is_empty());
assert_eq!(table.inodes[0], 0x1);
assert_eq!(table.inodes[1], 0x0);
}
Expand All @@ -1853,12 +1854,12 @@ pub mod tests {
let mut inode = RafsV5Inode::new();
inode.set_name_size(3);
assert_eq!(inode.size(), 136);
assert_eq!(inode.is_symlink(), false);
assert_eq!(inode.is_hardlink(), false);
assert_eq!(inode.is_dir(), false);
assert_eq!(inode.is_reg(), false);
assert_eq!(inode.has_hole(), false);
assert_eq!(inode.has_xattr(), false);
assert!(!inode.is_symlink());
assert!(!inode.is_hardlink());
assert!(!inode.is_dir());
assert!(!inode.is_reg());
assert!(!inode.has_hole());
assert!(!inode.has_xattr());

let mut inode = RafsV5Inode::new();
inode.set_symlink_size(3);
Expand Down
7 changes: 4 additions & 3 deletions rafs/src/metadata/layout/v6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,7 @@ impl Default for RafsV6Blob {
impl_bootstrap_converter!(RafsV6Blob);

impl RafsV6Blob {
#[allow(clippy::wrong_self_convention)]
fn to_blob_info(&self) -> Result<BlobInfo> {
// debug_assert!(RAFS_DIGEST_LENGTH == 32);
debug_assert!(size_of::<RafsV6Blob>() == 256);
Expand Down Expand Up @@ -2021,7 +2022,7 @@ mod tests {

let mut entry1 = RafsV6XattrEntry::new();
reader.read_exact(entry1.as_mut()).unwrap();
assert_eq!((entry1 == target1 || entry1 == target2), true);
assert!((entry1 == target1 || entry1 == target2));

size += size_of::<RafsV6XattrEntry>()
+ entry1.name_len() as usize
Expand All @@ -2034,9 +2035,9 @@ mod tests {
let mut entry2 = RafsV6XattrEntry::new();
reader.read_exact(entry2.as_mut()).unwrap();
if entry1 == target1 {
assert_eq!(entry2 == target2, true);
assert!(entry2 == target2);
} else {
assert_eq!(entry2 == target1, true);
assert!(entry2 == target1);
}
}
}
2 changes: 1 addition & 1 deletion rafs/src/metadata/md_v5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl RafsSuper {
pub(crate) fn amplify_io(
&self,
max_size: u32,
descs: &mut Vec<BlobIoVec>,
descs: &mut [BlobIoVec],
inode: &Arc<dyn RafsInode>,
window_base: u64,
mut window_size: u64,
Expand Down
4 changes: 2 additions & 2 deletions rafs/src/metadata/md_v6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ mod tests {
..Default::default()
};

assert_eq!(rs.try_load_v6(&mut reader).unwrap(), false);
assert!(!rs.try_load_v6(&mut reader).unwrap());
}

#[test]
Expand All @@ -155,7 +155,7 @@ mod tests {
..Default::default()
};

assert_eq!(rs.try_load_v6(&mut reader).unwrap(), false);
assert!(!rs.try_load_v6(&mut reader).unwrap());
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions rafs/src/metadata/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ impl Default for RafsSuperFlags {

impl Display for RafsSuperFlags {
fn fmt(&self, f: &mut Formatter) -> FmtResult {
write!(f, "{}", format!("{:?}", self))?;
write!(f, "{:?}", self)?;
Ok(())
}
}
Expand Down Expand Up @@ -452,7 +452,7 @@ impl RafsSuper {
/// Create a new `RafsSuper` instance from a `RafsConfig` object.
pub fn new(conf: &RafsConfig) -> Result<Self> {
Ok(Self {
mode: RafsMode::from_str(&conf.mode.as_str())?,
mode: RafsMode::from_str(conf.mode.as_str())?,
validate_digest: conf.digest_validate,
..Default::default()
})
Expand Down
7 changes: 1 addition & 6 deletions rafs/src/metadata/noop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,9 @@ use storage::device::BlobInfo;
use crate::metadata::{Inode, RafsInode, RafsSuperBlock, RafsSuperInodes};
use crate::{RafsIoReader, RafsResult};

#[derive(Default)]
pub struct NoopSuperBlock {}

impl Default for NoopSuperBlock {
fn default() -> Self {
Self {}
}
}

impl NoopSuperBlock {
pub fn new() -> Self {
Self::default()
Expand Down
1 change: 1 addition & 0 deletions rafs/src/mock/mock_inode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use crate::metadata::{
use storage::device::v5::BlobV5ChunkInfo;

#[derive(Default, Clone, Debug)]
#[allow(unused)]
pub struct MockInode {
i_ino: Inode,
i_name: OsString,
Expand Down
9 changes: 1 addition & 8 deletions rafs/src/mock/mock_super.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,13 @@ use storage::device::BlobInfo;
use crate::metadata::{Inode, RafsInode, RafsSuperBlock, RafsSuperInodes};
use crate::{RafsIoReader, RafsResult};

#[derive(Default)]
pub struct MockSuperBlock {
pub inodes: HashMap<Inode, Arc<dyn RafsInode + Send + Sync>>,
}

pub const CHUNK_SIZE: u32 = 200;

impl Default for MockSuperBlock {
fn default() -> Self {
Self {
inodes: HashMap::new(),
}
}
}

impl MockSuperBlock {
pub fn new() -> Self {
Self {
Expand Down
6 changes: 3 additions & 3 deletions src/bin/nydus-image/builder/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ fn same_file(f1: &Node, f2: &Node) -> bool {
return false;
}
let cap_name = OsStr::new("security.capability");
if f1.xattrs.get(&cap_name) != f2.xattrs.get(&cap_name) {
if f1.xattrs.get(cap_name) != f2.xattrs.get(cap_name) {
return false;
}
if !f1.is_dir() {
Expand Down Expand Up @@ -751,7 +751,7 @@ impl DiffBuilder {
}

let blob_mgr = self.blob_map.to_blob_mgr();
BuildOutput::new(&blob_mgr, &bootstrap_mgr)
BuildOutput::new(&blob_mgr, bootstrap_mgr)
}

fn build_with_diff(
Expand Down Expand Up @@ -804,7 +804,7 @@ impl DiffBuilder {
}

let blob_mgr = self.blob_map.to_blob_mgr();
BuildOutput::new(&blob_mgr, &bootstrap_mgr)
BuildOutput::new(&blob_mgr, bootstrap_mgr)
}
}

Expand Down
Loading

0 comments on commit 73234da

Please sign in to comment.