From 242f04afc9e5b0c6a5315e213c0120db4cc16783 Mon Sep 17 00:00:00 2001 From: Tiago Castro Date: Thu, 21 Nov 2024 14:57:16 +0000 Subject: [PATCH] style: use rust stable for linting Nightly clippy is no longer required, so we can remove its requirement and thus simplify the devel rather than require using both stable and nightly compiler. Nightly fmt is still required, but since the options we need are still not stable, I think it's better to drop them for a more mainstream approach. This should also reduce the target/debug size as there'll be only builds from one compiler. Signed-off-by: Tiago Castro --- .rustfmt.toml | 15 -------- build.rs | 20 +++-------- build_helpers/library_config.rs | 53 +++++++++------------------ build_helpers/tool.rs | 5 +-- examples/hello_world.rs | 10 ++---- nix/shell/rust.nix | 2 +- scripts/rust-linter-env.sh | 8 ++--- src/bdev.rs | 63 +++++++-------------------------- src/bdev_async.rs | 19 +++------- src/bdev_builder.rs | 31 ++++------------ src/bdev_desc.rs | 31 ++++------------ src/bdev_io.rs | 12 ++----- src/bdev_iter.rs | 4 +-- src/bdev_module.rs | 32 ++++------------- src/bdev_ops.rs | 6 +--- src/bdevs/bdev_nvme.rs | 9 +---- src/cpu_cores.rs | 14 ++------ src/dma.rs | 15 +++----- src/error.rs | 4 +-- src/ffihelper.rs | 16 +++------ src/io_channel.rs | 34 ++++++------------ src/io_device_traverse.rs | 28 ++++----------- src/io_devices.rs | 11 ++---- src/io_type.rs | 3 +- src/io_vec.rs | 23 +++--------- src/json_write_context.rs | 24 ++++--------- src/lib.rs | 17 +++------ src/nvme.rs | 50 +++++++------------------- src/nvmf.rs | 25 +++++-------- src/poller.rs | 24 ++++--------- src/thread.rs | 42 +++++----------------- src/untyped_bdev.rs | 6 +--- src/uuid.rs | 12 ++----- 33 files changed, 159 insertions(+), 509 deletions(-) delete mode 100644 .rustfmt.toml diff --git a/.rustfmt.toml b/.rustfmt.toml deleted file mode 100644 index 66f195f..0000000 --- a/.rustfmt.toml +++ /dev/null @@ -1,15 +0,0 @@ -# changed from 100 to 80 -max_width = 80 -# default is false -wrap_comments = true -comment_width = 80 -# was true -struct_lit_single_line = false -#changed from Mixed -imports_layout = "HorizontalVertical" -# changed from Preserve (merge_imports = false) -imports_granularity="Crate" -#default false -spaces_around_ranges = true -# was 2015 -edition = "2018" diff --git a/build.rs b/build.rs index f952596..77e1f2b 100644 --- a/build.rs +++ b/build.rs @@ -76,10 +76,7 @@ fn rust_fmt_nightly() -> Option { fn get_spdk_path() -> Result { let spdk_path = match env::var_os("SPDK_ROOT_DIR") { Some(s) => { - println!( - "SPDK_ROOT_DIR variable is set to {}", - s.to_str().unwrap() - ); + println!("SPDK_ROOT_DIR variable is set to {}", s.to_str().unwrap()); PathBuf::from(s) } None => { @@ -122,10 +119,7 @@ fn configure_spdk() -> Result { spdk_path.join("include/spdk/module"), spdk_path.join("module"), )?; - spdk_lib.add_inc_alt( - spdk_path.join("include/spdk/lib"), - spdk_path.join("lib"), - )?; + spdk_lib.add_inc_alt(spdk_path.join("include/spdk/lib"), spdk_path.join("lib"))?; spdk_lib.add_inc_alt( spdk_path.join("include/spdk/lib/ftl"), spdk_path.join("lib/ftl"), @@ -240,11 +234,7 @@ where src_files.push(p); } } - Err(e) => { - return Err(Error::Generic(format!( - "Bad SPDK helper source {s}: {e}" - ))) - } + Err(e) => return Err(Error::Generic(format!("Bad SPDK helper source {s}: {e}"))), } } @@ -357,9 +347,7 @@ fn main() { .prepend_enum_name(false) .size_t_is_usize(false) .generate_inline_functions(true) - .parse_callbacks(Box::new(MacroCallback { - macros, - })); + .parse_callbacks(Box::new(MacroCallback { macros })); // Use nightly rustfmt if it is possible. let bindings = if let Some(rust_fmt) = rust_fmt_nightly() { diff --git a/build_helpers/library_config.rs b/build_helpers/library_config.rs index e00881c..9bb10dd 100644 --- a/build_helpers/library_config.rs +++ b/build_helpers/library_config.rs @@ -120,24 +120,19 @@ impl Display for Library { impl Library { /// Creates a new `Library` instance. - fn new, V: AsRef>( - name: U, - parent_name: V, - cfg: &LibraryConfig, - ) -> Self { + fn new, V: AsRef>(name: U, parent_name: V, cfg: &LibraryConfig) -> Self { let pkg_name = name.as_ref().to_str().unwrap(); - let (lib_name, is_ar) = - if pkg_name.starts_with(":lib") && pkg_name.ends_with(".a") { - let s = pkg_name - .strip_prefix(":lib") - .unwrap() - .strip_suffix(".a") - .unwrap(); - (OsString::from(&s), true) - } else { - (OsString::from(&pkg_name), false) - }; + let (lib_name, is_ar) = if pkg_name.starts_with(":lib") && pkg_name.ends_with(".a") { + let s = pkg_name + .strip_prefix(":lib") + .unwrap() + .strip_suffix(".a") + .unwrap(); + (OsString::from(&s), true) + } else { + (OsString::from(&pkg_name), false) + }; let is_system = cfg.marked_system.contains(&lib_name); @@ -153,10 +148,7 @@ impl Library { /// Prints Cargo link instructions. fn cargo(&self) { if self.is_system { - println!( - "cargo:rustc-link-lib={}", - self.lib_name.to_str().unwrap() - ); + println!("cargo:rustc-link-lib={}", self.lib_name.to_str().unwrap()); } else { // Use 'whole-archive' flag on non-system libs. println!( @@ -224,16 +216,10 @@ impl LibraryConfig { /// Adds a new pkg_config search path. The path must exist on the file /// system. #[allow(dead_code)] - pub fn add_pkg_cfg_path>( - &self, - new_path: T, - ) -> Result<(), Error> { + pub fn add_pkg_cfg_path>(&self, new_path: T) -> Result<(), Error> { match fs::canonicalize(&new_path) { Ok(cp) => { - println!( - "Added PKG_CONFIG_PATH_FOR_TARGET: {}", - cp.to_str().unwrap() - ); + println!("Added PKG_CONFIG_PATH_FOR_TARGET: {}", cp.to_str().unwrap()); append_path_var(OsStr::new("PKG_CONFIG_PATH_FOR_TARGET"), &cp); Ok(()) } @@ -314,10 +300,7 @@ impl LibraryConfig { } /// Finds a library via pkg_config. - pub fn find_lib>( - &mut self, - lib_name: T, - ) -> Result<(), Error> { + pub fn find_lib>(&mut self, lib_name: T) -> Result<(), Error> { let lib_name = OsString::from(&lib_name); let library = self.cfg.probe(lib_name.to_str().unwrap())?; @@ -425,11 +408,7 @@ impl LibraryConfig { /// Builds a shared (.so) library from all the libraries found previously. #[allow(dead_code)] - pub fn build_shared_lib( - &self, - out_dir: &Path, - lib_name: &OsStr, - ) -> Result { + pub fn build_shared_lib(&self, out_dir: &Path, lib_name: &OsStr) -> Result { let mut tool = Tool::new()?; tool.add_flag("shared"); diff --git a/build_helpers/tool.rs b/build_helpers/tool.rs index 4ea01d9..3164bd9 100644 --- a/build_helpers/tool.rs +++ b/build_helpers/tool.rs @@ -41,10 +41,7 @@ impl Tool { } /// Creates a shared library path from the given directory and library name. - pub fn make_shared_lib_path( - out_dir: &Path, - lib_name: &OsStr, - ) -> Result { + pub fn make_shared_lib_path(out_dir: &Path, lib_name: &OsStr) -> Result { let lib_path = &format!("lib{}.so", lib_name.to_str().unwrap()); let res = out_dir.to_path_buf().join(lib_path); Ok(res) diff --git a/examples/hello_world.rs b/examples/hello_world.rs index 6fd5e52..ab354a4 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -5,14 +5,8 @@ use std::{ }; use spdk_rs::libspdk::{ - size_t, - spdk_app_fini, - spdk_app_opts, - spdk_app_opts_init, - spdk_app_parse_args, - spdk_app_start, - spdk_app_stop, - SPDK_APP_PARSE_ARGS_SUCCESS, + size_t, spdk_app_fini, spdk_app_opts, spdk_app_opts_init, spdk_app_parse_args, spdk_app_start, + spdk_app_stop, SPDK_APP_PARSE_ARGS_SUCCESS, }; extern "C" fn hello_world_parse_arg(_ch: c_int, _arg: *mut c_char) -> c_int { diff --git a/nix/shell/rust.nix b/nix/shell/rust.nix index 6852b0f..0cb55b4 100644 --- a/nix/shell/rust.nix +++ b/nix/shell/rust.nix @@ -19,7 +19,7 @@ let shellEnv = { # Path to nightly Rust, needed for linter and style. - RUST_NIGHTLY_PATH = rustChannels.nightly; + # RUST_NIGHTLY_PATH = rustChannels.nightly; # Path to debug output dir. RUST_TARGET_DEBUG = "target/debug"; diff --git a/scripts/rust-linter-env.sh b/scripts/rust-linter-env.sh index a3c9624..85969bd 100644 --- a/scripts/rust-linter-env.sh +++ b/scripts/rust-linter-env.sh @@ -46,10 +46,10 @@ fi # rustfmt and clippy "2021-11-29". # When upgrading Rust toolchain version, check 'cargo --version', # 'cargo fmt --version', 'cargo clippy --version' and put them here. -RUST_TOOLCHAIN_VER="2024-10-30" -WANTED_CARGO_VER="cargo 1.84.0-nightly (* 2024-10-25)" -WANTED_RUSTFMT_VER="rustfmt 1.8.0-nightly (* 2024-10-29)" -WANTED_CLIPPY_VER="clippy 0.1.84 (* 2024-10-29)" +RUST_TOOLCHAIN_VER=${RUST_TOOLCHAIN_VER:-"1.82.0"} +WANTED_CARGO_VER=${WANTED_CARGO_VER:-"cargo 1.82.0 (* 2024-08-21)"} +WANTED_RUSTFMT_VER=${WANTED_RUSTFMT_VER:-"rustfmt 1.7.1-stable (* 2024-10-15)"} +WANTED_CLIPPY_VER=${WANTED_CLIPPY_VER:-"clippy 0.1.82 (* 2024-10-15)"} CARGO="cargo" CARGO_MODE="system" diff --git a/src/bdev.rs b/src/bdev.rs index 8374920..f58ee88 100644 --- a/src/bdev.rs +++ b/src/bdev.rs @@ -11,38 +11,15 @@ use std::{ use nix::errno::Errno; use crate::{ - ffihelper::{ - errno_result_from_i32, - AsStr, - ErrnoResult, - FfiResult, - IntoCString, - }, + ffihelper::{errno_result_from_i32, AsStr, ErrnoResult, FfiResult, IntoCString}, libspdk::{ - spdk_bdev, - spdk_bdev_alias_add, - spdk_bdev_alias_del, - spdk_bdev_fn_table, - spdk_bdev_get_aliases, - spdk_bdev_get_buf_align, - spdk_bdev_get_by_name, - spdk_bdev_has_write_cache, - spdk_bdev_io_type_supported, - spdk_bdev_module, - spdk_bdev_module_release_bdev, - spdk_bdev_register, - spdk_bdev_unregister, - SPDK_BDEV_CLAIM_EXCL_WRITE, - SPDK_BDEV_CLAIM_NONE, + spdk_bdev, spdk_bdev_alias_add, spdk_bdev_alias_del, spdk_bdev_fn_table, + spdk_bdev_get_aliases, spdk_bdev_get_buf_align, spdk_bdev_get_by_name, + spdk_bdev_has_write_cache, spdk_bdev_io_type_supported, spdk_bdev_module, + spdk_bdev_module_release_bdev, spdk_bdev_register, spdk_bdev_unregister, + SPDK_BDEV_CLAIM_EXCL_WRITE, SPDK_BDEV_CLAIM_NONE, }, - BdevIo, - BdevModule, - BdevOps, - IoChannel, - IoDevice, - IoType, - Thread, - Uuid, + BdevIo, BdevModule, BdevOps, IoChannel, IoDevice, IoType, Thread, Uuid, }; /// Wrapper for SPDK `spdk_bdev` structure and the related API. @@ -80,11 +57,7 @@ where /// TODO pub fn unregister_bdev(&mut self) { unsafe { - spdk_bdev_unregister( - self.as_inner_ptr(), - None, - null_mut::(), - ); + spdk_bdev_unregister(self.as_inner_ptr(), None, null_mut::()); } } @@ -193,21 +166,15 @@ where /// If the alias is already present we return true pub fn add_alias(&mut self, alias: &str) -> bool { let alias = alias.into_cstring(); - let ret = - unsafe { spdk_bdev_alias_add(self.as_inner_ptr(), alias.as_ptr()) } - .to_result(Errno::from_raw); + let ret = unsafe { spdk_bdev_alias_add(self.as_inner_ptr(), alias.as_ptr()) } + .to_result(Errno::from_raw); matches!(ret, Err(Errno::EEXIST) | Ok(_)) } /// Removes the given alias from the Bdev. pub fn remove_alias(&mut self, alias: &str) { - unsafe { - spdk_bdev_alias_del( - self.as_inner_ptr(), - alias.into_cstring().as_ptr(), - ) - }; + unsafe { spdk_bdev_alias_del(self.as_inner_ptr(), alias.into_cstring().as_ptr()) }; } /// Returns a list of Bdev aliases. @@ -261,9 +228,7 @@ where /// Returns true if this Bdev is claimed by some other component. pub fn is_claimed(&self) -> bool { - unsafe { - self.as_inner_ref().internal.claim_type != SPDK_BDEV_CLAIM_NONE - } + unsafe { self.as_inner_ref().internal.claim_type != SPDK_BDEV_CLAIM_NONE } } /// Returns true if this Bdev is claimed by the given component. @@ -296,9 +261,7 @@ where /// Determines whenever the Bdev supports the requested I/O type. pub fn io_type_supported(&self, io_type: IoType) -> bool { - unsafe { - spdk_bdev_io_type_supported(self.as_inner_ptr(), io_type.into()) - } + unsafe { spdk_bdev_io_type_supported(self.as_inner_ptr(), io_type.into()) } } /// Returns a reference to a data object associated with this Bdev. diff --git a/src/bdev_async.rs b/src/bdev_async.rs index c329f76..68f0db6 100644 --- a/src/bdev_async.rs +++ b/src/bdev_async.rs @@ -5,23 +5,12 @@ use futures::channel::{oneshot, oneshot::Canceled}; use crate::{ error::{SpdkError::BdevUnregisterFailed, SpdkResult}, - ffihelper::{ - cb_arg, - done_errno_cb, - errno_error, - errno_result_from_i32, - ErrnoResult, - }, + ffihelper::{cb_arg, done_errno_cb, errno_error, errno_result_from_i32, ErrnoResult}, libspdk::{ - bdev_reset_device_stat, - spdk_bdev, - spdk_bdev_get_device_stat, - spdk_bdev_io_stat, - spdk_bdev_unregister, - SPDK_BDEV_RESET_STAT_ALL, + bdev_reset_device_stat, spdk_bdev, spdk_bdev_get_device_stat, spdk_bdev_io_stat, + spdk_bdev_unregister, SPDK_BDEV_RESET_STAT_ALL, }, - Bdev, - BdevOps, + Bdev, BdevOps, }; /// TODO diff --git a/src/bdev_builder.rs b/src/bdev_builder.rs index 95d91f2..0e49eea 100644 --- a/src/bdev_builder.rs +++ b/src/bdev_builder.rs @@ -4,24 +4,10 @@ use crate::{ bdev::Container, ffihelper::IntoCString, libspdk::{ - spdk_bdev, - spdk_bdev_fn_table, - spdk_bdev_io, - spdk_bdev_io_type, - spdk_get_io_channel, - spdk_io_channel, - spdk_json_write_ctx, - SPDK_BDEV_RESET_IO_DRAIN_RECOMMENDED_VALUE, + spdk_bdev, spdk_bdev_fn_table, spdk_bdev_io, spdk_bdev_io_type, spdk_get_io_channel, + spdk_io_channel, spdk_json_write_ctx, SPDK_BDEV_RESET_IO_DRAIN_RECOMMENDED_VALUE, }, - Bdev, - BdevIo, - BdevModule, - BdevOps, - IoChannel, - IoDevice, - IoType, - JsonWriteContext, - Uuid, + Bdev, BdevIo, BdevModule, BdevOps, IoChannel, IoDevice, IoType, JsonWriteContext, Uuid, }; /// Builder for `Bdev` structure. @@ -211,8 +197,7 @@ where optimal_open_zones: Default::default(), media_events: Default::default(), ctratt: unsafe { zeroed() }, - reset_io_drain_timeout: - SPDK_BDEV_RESET_IO_DRAIN_RECOMMENDED_VALUE as u16, + reset_io_drain_timeout: SPDK_BDEV_RESET_IO_DRAIN_RECOMMENDED_VALUE as u16, module: self.module.as_ptr(), fn_table: null_mut::(), internal: unsafe { zeroed() }, @@ -302,9 +287,7 @@ unsafe extern "C" fn inner_bdev_submit_request( /// # Safety /// /// TODO -unsafe extern "C" fn inner_bdev_get_io_channel( - ctx: *mut c_void, -) -> *mut spdk_io_channel +unsafe extern "C" fn inner_bdev_get_io_channel(ctx: *mut c_void) -> *mut spdk_io_channel where BdevData: BdevOps, { @@ -327,9 +310,7 @@ where /// # Safety /// /// TODO -unsafe extern "C" fn inner_bdev_get_module_ctx( - _ctx: *mut c_void, -) -> *mut c_void +unsafe extern "C" fn inner_bdev_get_module_ctx(_ctx: *mut c_void) -> *mut c_void where BdevData: BdevOps, { diff --git a/src/bdev_desc.rs b/src/bdev_desc.rs index 96b36ff..c634c03 100644 --- a/src/bdev_desc.rs +++ b/src/bdev_desc.rs @@ -6,22 +6,12 @@ use crate::{ ffihelper::{errno_error, ErrnoResult, IntoCString}, io_channel::IoChannelGuard, libspdk::{ - bdev_lock_lba_range, - bdev_unlock_lba_range, - lba_range, - spdk_bdev, - spdk_bdev_close, - spdk_bdev_desc, - spdk_bdev_desc_get_bdev, - spdk_bdev_event_type, - spdk_bdev_get_io_channel, - spdk_bdev_open_ext, - SPDK_BDEV_EVENT_MEDIA_MANAGEMENT, - SPDK_BDEV_EVENT_REMOVE, + bdev_lock_lba_range, bdev_unlock_lba_range, lba_range, spdk_bdev, spdk_bdev_close, + spdk_bdev_desc, spdk_bdev_desc_get_bdev, spdk_bdev_event_type, spdk_bdev_get_io_channel, + spdk_bdev_open_ext, SPDK_BDEV_EVENT_MEDIA_MANAGEMENT, SPDK_BDEV_EVENT_REMOVE, SPDK_BDEV_EVENT_RESIZE, }, - Bdev, - BdevOps, + Bdev, BdevOps, }; /// Bdev descriptor errors. @@ -130,9 +120,7 @@ where } /// Returns a channel to the underlying Bdev. - pub fn io_channel( - &self, - ) -> Result, BdevDescError> { + pub fn io_channel(&self) -> Result, BdevDescError> { let ch = unsafe { spdk_bdev_get_io_channel(self.as_ptr()) }; if ch.is_null() { error!( @@ -187,9 +175,7 @@ where }); } - Ok(LbaRangeLock { - ctx, - }) + Ok(LbaRangeLock { ctx }) } /// Releases exclusive access over a block range. @@ -339,10 +325,7 @@ pub struct LbaRange { impl LbaRange { /// Creates a new LbaRange. pub fn new(offset: u64, len: u64) -> LbaRange { - LbaRange { - offset, - len, - } + LbaRange { offset, len } } } diff --git a/src/bdev_io.rs b/src/bdev_io.rs index 9999de8..f669ba5 100644 --- a/src/bdev_io.rs +++ b/src/bdev_io.rs @@ -11,18 +11,10 @@ use std::{ use crate::{ libspdk::{ - spdk_bdev_io, - spdk_bdev_io_complete, - spdk_bdev_io_get_buf, - spdk_io_channel, - spdk_nvme_cmd, + spdk_bdev_io, spdk_bdev_io_complete, spdk_bdev_io_get_buf, spdk_io_channel, spdk_nvme_cmd, }, nvme::NvmeStatus, - Bdev, - BdevOps, - IoStatus, - IoType, - IoVec, + Bdev, BdevOps, IoStatus, IoType, IoVec, }; /// Trait to cast an array-like container to an array of `IoVec`. diff --git a/src/bdev_iter.rs b/src/bdev_iter.rs index 44a2531..0a12565 100644 --- a/src/bdev_iter.rs +++ b/src/bdev_iter.rs @@ -3,9 +3,7 @@ use std::marker::PhantomData; use crate::{ libspdk::{spdk_bdev, spdk_bdev_first, spdk_bdev_module, spdk_bdev_next}, - Bdev, - BdevModule, - BdevOps, + Bdev, BdevModule, BdevOps, }; impl Bdev diff --git a/src/bdev_module.rs b/src/bdev_module.rs index f781434..36a33b9 100644 --- a/src/bdev_module.rs +++ b/src/bdev_module.rs @@ -3,20 +3,10 @@ use std::{ffi::CString, marker::PhantomData, mem::zeroed, ptr::NonNull}; use crate::{ ffihelper::{AsStr, IntoCString}, libspdk::{ - spdk_bdev_module, - spdk_bdev_module_claim_bdev, - spdk_bdev_module_list_add, - spdk_bdev_module_list_find, - spdk_json_write_ctx, + spdk_bdev_module, spdk_bdev_module_claim_bdev, spdk_bdev_module_list_add, + spdk_bdev_module_list_find, spdk_json_write_ctx, }, - Bdev, - BdevBuilder, - BdevDesc, - BdevModuleIter, - BdevOps, - JsonWriteContext, - SpdkError, - SpdkResult, + Bdev, BdevBuilder, BdevDesc, BdevModuleIter, BdevOps, JsonWriteContext, SpdkError, SpdkResult, }; /// Wrapper for SPDK Bdev module structure. @@ -42,9 +32,7 @@ impl BdevModule { let s = mod_name.into_cstring(); let p = unsafe { spdk_bdev_module_list_find(s.as_ptr()) }; match NonNull::new(p) { - Some(inner) => Ok(BdevModule { - inner, - }), + Some(inner) => Ok(BdevModule { inner }), None => Err(SpdkError::BdevModuleNotFound { name: String::from(mod_name), }), @@ -73,20 +61,12 @@ impl BdevModule { /// /// * `bdev`: Block device to be claimed. /// * `desc`: Descriptor for the block device. - pub fn claim_bdev( - &self, - bdev: &Bdev, - desc: &BdevDesc, - ) -> SpdkResult<()> + pub fn claim_bdev(&self, bdev: &Bdev, desc: &BdevDesc) -> SpdkResult<()> where T: BdevOps, { let err = unsafe { - spdk_bdev_module_claim_bdev( - bdev.as_inner_ptr(), - desc.as_ptr(), - self.as_ptr(), - ) + spdk_bdev_module_claim_bdev(bdev.as_inner_ptr(), desc.as_ptr(), self.as_ptr()) }; if err == 0 { diff --git a/src/bdev_ops.rs b/src/bdev_ops.rs index 51175fe..e842853 100644 --- a/src/bdev_ops.rs +++ b/src/bdev_ops.rs @@ -22,11 +22,7 @@ pub trait BdevOps { /// /// * `chan`: TODO /// * `bio`: TODO - fn submit_request( - &self, - chan: IoChannel, - bio: BdevIo, - ); + fn submit_request(&self, chan: IoChannel, bio: BdevIo); /// TODO /// diff --git a/src/bdevs/bdev_nvme.rs b/src/bdevs/bdev_nvme.rs index 43ea504..a751b88 100644 --- a/src/bdevs/bdev_nvme.rs +++ b/src/bdevs/bdev_nvme.rs @@ -3,14 +3,7 @@ use nix::errno::Errno; use std::mem::zeroed; use crate::{ - ffihelper::{ - cb_arg, - copy_str_with_null, - done_errno_cb, - drop_cb_arg, - ErrnoResult, - IntoCString, - }, + ffihelper::{cb_arg, copy_str_with_null, done_errno_cb, drop_cb_arg, ErrnoResult, IntoCString}, libspdk::{bdev_nvme_delete, nvme_path_id, SPDK_NVME_TRANSPORT_PCIE}, }; diff --git a/src/cpu_cores.rs b/src/cpu_cores.rs index 1e05a84..7ca489e 100644 --- a/src/cpu_cores.rs +++ b/src/cpu_cores.rs @@ -4,13 +4,8 @@ use std::{ }; use crate::libspdk::{ - spdk_cpuset, - spdk_cpuset_set_cpu, - spdk_cpuset_zero, - spdk_env_get_core_count, - spdk_env_get_current_core, - spdk_env_get_first_core, - spdk_env_get_last_core, + spdk_cpuset, spdk_cpuset_set_cpu, spdk_cpuset_zero, spdk_env_get_core_count, + spdk_env_get_current_core, spdk_env_get_first_core, spdk_env_get_last_core, spdk_env_get_next_core, }; @@ -167,10 +162,7 @@ impl CoreSelectorBase { pub fn new() -> Self { let cores = Cores::list_cores(); assert!(cores.len() > 0, "No CPU cores found"); - Self { - cores, - next: 0, - } + Self { cores, next: 0 } } } diff --git a/src/dma.rs b/src/dma.rs index 4f21e2f..490822e 100644 --- a/src/dma.rs +++ b/src/dma.rs @@ -11,14 +11,8 @@ use std::{ use snafu::Snafu; use crate::{ - libspdk::{ - spdk_dma_free, - spdk_zmalloc, - SPDK_ENV_LCORE_ID_ANY, - SPDK_MALLOC_DMA, - }, - AsIoVecs, - IoVec, + libspdk::{spdk_dma_free, spdk_zmalloc, SPDK_ENV_LCORE_ID_ANY, SPDK_MALLOC_DMA}, + AsIoVecs, IoVec, }; #[derive(Debug, Snafu, Clone)] @@ -96,9 +90,8 @@ impl DmaBuf { pub fn dump(&self) -> String { let mut out = String::default(); let ptr = self.as_ptr(); - for i in 0 .. self.0.len() { - let cur_byte = - unsafe { *((ptr as *const u8).wrapping_add(i as usize)) }; + for i in 0..self.0.len() { + let cur_byte = unsafe { *((ptr as *const u8).wrapping_add(i as usize)) }; // print 16 bytes per line. if i > 0 && i % 16 == 0 { out.push_str("\n"); diff --git a/src/error.rs b/src/error.rs index e65a2cb..e655efb 100644 --- a/src/error.rs +++ b/src/error.rs @@ -12,9 +12,7 @@ pub enum SpdkError { #[snafu(display("Bdev '{name}' is already claimed by another module"))] BdevAlreadyClaimed { name: String }, - #[snafu(display( - "Bdev '{name}' is not claimed by this module '{mod_name}'", - ))] + #[snafu(display("Bdev '{name}' is not claimed by this module '{mod_name}'",))] BdevNotClaimed { name: String, mod_name: String }, #[snafu(display("Failed to unregister Bdev '{name}': {source}"))] diff --git a/src/ffihelper.rs b/src/ffihelper.rs index bc99fa3..a14cc42 100644 --- a/src/ffihelper.rs +++ b/src/ffihelper.rs @@ -97,11 +97,7 @@ pub fn copy_cstr_with_null(src: &CStr, dst: &mut [c_char]) { /// the null byte. If the string to be copied (including the terminating null /// byte) is longer than the destination, it is truncated to fit the /// destination. -pub fn copy_cstr_to_buf_with_null( - src: &CStr, - dst: *mut c_char, - dst_size: usize, -) { +pub fn copy_cstr_to_buf_with_null(src: &CStr, dst: *mut c_char, dst_size: usize) { let bytes = src.to_bytes(); let count = std::cmp::min(bytes.len(), dst_size - 1); unsafe { @@ -126,8 +122,7 @@ pub fn cb_arg(sender: oneshot::Sender) -> *mut c_void { /// Drops a callback argument contructed by `cb_arg`. /// This is needed when the callback is known to be not called. pub fn drop_cb_arg(sender_ptr: *mut c_void) { - let sender = - unsafe { Box::from_raw(sender_ptr as *mut oneshot::Sender) }; + let sender = unsafe { Box::from_raw(sender_ptr as *mut oneshot::Sender) }; drop(sender); } @@ -143,8 +138,7 @@ pub extern "C" fn done_cb(sender_ptr: *mut c_void, val: T) where T: std::fmt::Debug, { - let sender = - unsafe { Box::from_raw(sender_ptr as *mut oneshot::Sender) }; + let sender = unsafe { Box::from_raw(sender_ptr as *mut oneshot::Sender) }; // the receiver side might be gone, if this happens it either means that the // function has gone out of scope or that the future was cancelled. We can @@ -167,9 +161,7 @@ where /// * `sender_ptr`: TODO /// * `errno`: TODO pub extern "C" fn done_errno_cb(sender_ptr: *mut c_void, errno: i32) { - let sender = unsafe { - Box::from_raw(sender_ptr as *mut oneshot::Sender>) - }; + let sender = unsafe { Box::from_raw(sender_ptr as *mut oneshot::Sender>) }; sender .send(errno_result_from_i32((), errno)) diff --git a/src/io_channel.rs b/src/io_channel.rs index d4ac2e6..3b1e24b 100644 --- a/src/io_channel.rs +++ b/src/io_channel.rs @@ -3,12 +3,8 @@ use std::ops::Deref; use std::{fmt, marker::PhantomData, ptr::NonNull}; use crate::libspdk::{ - spdk_io_channel, - spdk_io_channel_get_io_device_name, - spdk_io_channel_iter, - spdk_io_channel_iter_get_channel, - spdk_put_io_channel, - spdk_rs_io_channel_get_ctx, + spdk_io_channel, spdk_io_channel_get_io_device_name, spdk_io_channel_iter, + spdk_io_channel_iter_get_channel, spdk_put_io_channel, spdk_rs_io_channel_get_ctx, spdk_thread_get_name, }; @@ -30,19 +26,13 @@ impl IoChannel { /// Returns a reference to the channel data instance that this I/O channel /// owns. pub fn channel_data(&self) -> &ChannelData { - unsafe { - &*(spdk_rs_io_channel_get_ctx(self.inner.as_ptr()) - as *mut ChannelData) - } + unsafe { &*(spdk_rs_io_channel_get_ctx(self.inner.as_ptr()) as *mut ChannelData) } } /// Returns a mutable reference to the channel data instance that this I/O /// channel owns. pub fn channel_data_mut(&mut self) -> &mut ChannelData { - unsafe { - &mut *(spdk_rs_io_channel_get_ctx(self.inner.as_ptr()) - as *mut ChannelData) - } + unsafe { &mut *(spdk_rs_io_channel_get_ctx(self.inner.as_ptr()) as *mut ChannelData) } } /// Returns the name of the I/O channel which is used to register the @@ -50,22 +40,18 @@ impl IoChannel { /// or an actual name. fn name(&self) -> &str { unsafe { - std::ffi::CStr::from_ptr(spdk_io_channel_get_io_device_name( - self.as_ptr(), - )) - .to_str() - .unwrap() + std::ffi::CStr::from_ptr(spdk_io_channel_get_io_device_name(self.as_ptr())) + .to_str() + .unwrap() } } /// TODO fn thread_name(&self) -> &str { unsafe { - std::ffi::CStr::from_ptr(spdk_thread_get_name( - self.inner.as_ref().thread, - )) - .to_str() - .unwrap() + std::ffi::CStr::from_ptr(spdk_thread_get_name(self.inner.as_ref().thread)) + .to_str() + .unwrap() } } diff --git a/src/io_device_traverse.rs b/src/io_device_traverse.rs index 7d892c9..2c71323 100644 --- a/src/io_device_traverse.rs +++ b/src/io_device_traverse.rs @@ -4,13 +4,10 @@ use std::{marker::PhantomData, os::raw::c_void}; use crate::{ libspdk::{ - spdk_for_each_channel, - spdk_for_each_channel_continue, - spdk_io_channel_iter, + spdk_for_each_channel, spdk_for_each_channel_continue, spdk_io_channel_iter, spdk_io_channel_iter_get_ctx, }, - IoChannel, - IoDevice, + IoChannel, IoDevice, }; /// TODO @@ -51,9 +48,7 @@ impl From for i32 { /// * `'Ctx`: TODO struct TraverseCtx<'a, 'b, 'c, ChannelData, Ctx> { /// TODO - channel_cb: Box< - dyn FnMut(&mut ChannelData, &mut Ctx) -> ChannelTraverseStatus + 'a, - >, + channel_cb: Box ChannelTraverseStatus + 'a>, /// TODO done_cb: Box, /// TODO @@ -73,8 +68,7 @@ impl<'a, 'b, 'c, ChannelData, Ctx> TraverseCtx<'a, 'b, 'c, ChannelData, Ctx> { /// * `done_cb`: TODO /// * `caller_ctx`: TODO fn new( - channel_cb: impl FnMut(&mut ChannelData, &mut Ctx) -> ChannelTraverseStatus - + 'a, + channel_cb: impl FnMut(&mut ChannelData, &mut Ctx) -> ChannelTraverseStatus + 'a, done_cb: impl FnMut(ChannelTraverseStatus, Ctx) + 'b, caller_ctx: Ctx, ) -> Self { @@ -111,10 +105,7 @@ pub trait IoDeviceChannelTraverse: IoDevice { fn traverse_io_channels<'a, 'b, Ctx>( &self, context: Ctx, - channel_cb: impl FnMut( - &mut ::ChannelData, - &mut Ctx, - ) -> ChannelTraverseStatus + channel_cb: impl FnMut(&mut ::ChannelData, &mut Ctx) -> ChannelTraverseStatus + 'a, done_cb: impl FnMut(ChannelTraverseStatus, Ctx) + 'b, ) { @@ -164,9 +155,7 @@ pub trait IoDeviceChannelTraverse: IoDevice { /// # Arguments /// /// * `i`: TODO -extern "C" fn inner_traverse_channel( - i: *mut spdk_io_channel_iter, -) { +extern "C" fn inner_traverse_channel(i: *mut spdk_io_channel_iter) { let ctx = TraverseCtx::::from_iter(i); let mut chan = IoChannel::::from_iter(i); @@ -209,10 +198,7 @@ where T: Send, F: FnMut(&mut D::ChannelData, &T) -> (), { - fn channel_cb( - channel: &mut D::ChannelData, - ctx: &mut Self, - ) -> ChannelTraverseStatus { + fn channel_cb(channel: &mut D::ChannelData, ctx: &mut Self) -> ChannelTraverseStatus { (ctx.func)(channel, &ctx.data); ChannelTraverseStatus::Ok } diff --git a/src/io_devices.rs b/src/io_devices.rs index 93b8a04..1eb6ea4 100644 --- a/src/io_devices.rs +++ b/src/io_devices.rs @@ -103,10 +103,7 @@ where /// /// * `ctx`: TODO /// * `buf`: TODO -unsafe extern "C" fn inner_io_channel_create( - ctx: *mut c_void, - buf: *mut c_void, -) -> i32 +unsafe extern "C" fn inner_io_channel_create(ctx: *mut c_void, buf: *mut c_void) -> i32 where Dev: IoDevice, { @@ -126,10 +123,8 @@ where /// /// * `ctx`: TODO /// * `buf`: TODO -unsafe extern "C" fn inner_io_channel_destroy( - ctx: *mut c_void, - buf: *mut c_void, -) where +unsafe extern "C" fn inner_io_channel_destroy(ctx: *mut c_void, buf: *mut c_void) +where Dev: IoDevice, { let io_dev = from_io_device_id::(ctx); diff --git a/src/io_type.rs b/src/io_type.rs index 310ec8d..c5d13d6 100644 --- a/src/io_type.rs +++ b/src/io_type.rs @@ -64,8 +64,7 @@ impl From for IoType { impl From for IoStatus { fn from(s: i32) -> Self { assert!( - s >= libspdk::SPDK_MIN_BDEV_IO_STATUS - && s <= libspdk::SPDK_BDEV_IO_STATUS_SUCCESS, + s >= libspdk::SPDK_MIN_BDEV_IO_STATUS && s <= libspdk::SPDK_BDEV_IO_STATUS_SUCCESS, "Invalid or unknown status code" ); unsafe { *std::mem::transmute::<*const i32, *const IoStatus>(&s) } diff --git a/src/io_vec.rs b/src/io_vec.rs index 7c637f2..0b68ebe 100644 --- a/src/io_vec.rs +++ b/src/io_vec.rs @@ -32,10 +32,7 @@ impl IoVec { /// Creates a new `IoVec` instance. #[inline(always)] pub fn new(iov_base: *mut c_void, iov_len: u64) -> Self { - Self(libspdk::iovec { - iov_base, - iov_len, - }) + Self(libspdk::iovec { iov_base, iov_len }) } /// Returns length of the `IoVec` buffer. @@ -68,18 +65,14 @@ impl IoVec { #[inline(always)] pub fn as_slice(&self) -> &[u8] { assert!(self.is_initialized()); - unsafe { - from_raw_parts(self.as_ptr() as *const _, self.len() as usize) - } + unsafe { from_raw_parts(self.as_ptr() as *const _, self.len() as usize) } } /// Returns mutable `u8` slice representation of `IoVec`. #[inline(always)] pub fn as_mut_slice(&mut self) -> &mut [u8] { assert!(self.is_initialized()); - unsafe { - from_raw_parts_mut(self.as_mut_ptr() as *mut _, self.len() as usize) - } + unsafe { from_raw_parts_mut(self.as_mut_ptr() as *mut _, self.len() as usize) } } /// TODO @@ -96,13 +89,7 @@ impl IoVec { /// Fills the buffer with the given value. pub fn fill(&mut self, val: u8) { - unsafe { - std::ptr::write_bytes( - self.0.iov_base as *mut u8, - val, - self.0.iov_len as usize, - ) - } + unsafe { std::ptr::write_bytes(self.0.iov_base as *mut u8, val, self.0.iov_len as usize) } } /// Compares two buffer and returns the index of the first mismatching @@ -119,7 +106,7 @@ impl IoVec { return Some(len_b); } - for i in 0 .. len_a { + for i in 0..len_a { if a[i] != b[i] { return Some(i); } diff --git a/src/json_write_context.rs b/src/json_write_context.rs index ae38389..9b2711a 100644 --- a/src/json_write_context.rs +++ b/src/json_write_context.rs @@ -8,13 +8,10 @@ use serde::Serialize; use crate::{ libspdk::{ - spdk_json_write_array_end, - spdk_json_write_ctx, - spdk_json_write_named_array_begin, + spdk_json_write_array_end, spdk_json_write_ctx, spdk_json_write_named_array_begin, spdk_json_write_val_raw, }, - SpdkError, - SpdkResult, + SpdkError, SpdkResult, }; /// Wrapper for SPDK JSON write context (`spdk_json_write_ctx`). @@ -39,9 +36,7 @@ impl JsonWriteContext { { match serde_json::to_string(val) { Ok(s) => self.write_string(&s), - Err(err) => Err(SpdkError::SerdeFailed { - source: err, - }), + Err(err) => Err(SpdkError::SerdeFailed { source: err }), } } @@ -61,19 +56,12 @@ impl JsonWriteContext { /// /// * `data`: TODO /// * `len`: TODO - pub(crate) fn write_raw( - &self, - data: *const c_void, - len: usize, - ) -> SpdkResult<()> { - let err = - unsafe { spdk_json_write_val_raw(self.as_ptr(), data, len as u64) }; + pub(crate) fn write_raw(&self, data: *const c_void, len: usize) -> SpdkResult<()> { + let err = unsafe { spdk_json_write_val_raw(self.as_ptr(), data, len as u64) }; if err == 0 { Ok(()) } else { - Err(SpdkError::JsonWriteFailed { - code: err, - }) + Err(SpdkError::JsonWriteFailed { code: err }) } } diff --git a/src/lib.rs b/src/lib.rs index 3f1bdaa..80e06de 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -57,13 +57,8 @@ pub use crate::{ bdev_io::BdevIo, bdev_iter::{BdevGlobalIter, BdevModuleIter}, bdev_module::{ - BdevModule, - BdevModuleBuild, - BdevModuleBuilder, - WithModuleConfigJson, - WithModuleFini, - WithModuleGetCtxSize, - WithModuleInit, + BdevModule, BdevModuleBuild, BdevModuleBuilder, WithModuleConfigJson, WithModuleFini, + WithModuleGetCtxSize, WithModuleInit, }, bdev_ops::BdevOps, cpu_cores::{Core, CoreIterator, Cores, RoundRobinCoreSelector}, @@ -76,12 +71,8 @@ pub use crate::{ io_vec::{AsIoVecPtr, AsIoVecs, IoVec}, json_write_context::JsonWriteContext, nvme::{ - nvme_admin_opc, - nvme_nvm_opcode, - nvme_reservation_acquire_action, - nvme_reservation_register_action, - nvme_reservation_register_cptpl, - nvme_reservation_type, + nvme_admin_opc, nvme_nvm_opcode, nvme_reservation_acquire_action, + nvme_reservation_register_action, nvme_reservation_register_cptpl, nvme_reservation_type, NvmeStatus, }, nvmf::{NvmfController, NvmfSubsystemEvent}, diff --git a/src/nvme.rs b/src/nvme.rs index cbe49dd..8976ef1 100644 --- a/src/nvme.rs +++ b/src/nvme.rs @@ -5,24 +5,12 @@ use std::{ }; use crate::libspdk::{ - spdk_bdev_io, - spdk_bdev_io_get_nvme_status, - spdk_nvme_command_specific_status_code, - spdk_nvme_cpl, - spdk_nvme_generic_command_status_code, - spdk_nvme_media_error_status_code, - spdk_nvme_path_status_code, - spdk_nvme_status, - spdk_nvme_status_code_type, - spdk_nvmf_request, - SPDK_NVME_SCT_COMMAND_SPECIFIC, - SPDK_NVME_SCT_GENERIC, - SPDK_NVME_SCT_MEDIA_ERROR, - SPDK_NVME_SCT_PATH, - SPDK_NVME_SCT_VENDOR_SPECIFIC, - SPDK_NVME_SC_DATA_TRANSFER_ERROR, - SPDK_NVME_SC_DEALLOCATED_OR_UNWRITTEN_BLOCK, - SPDK_NVME_SC_SUCCESS, + spdk_bdev_io, spdk_bdev_io_get_nvme_status, spdk_nvme_command_specific_status_code, + spdk_nvme_cpl, spdk_nvme_generic_command_status_code, spdk_nvme_media_error_status_code, + spdk_nvme_path_status_code, spdk_nvme_status, spdk_nvme_status_code_type, spdk_nvmf_request, + SPDK_NVME_SCT_COMMAND_SPECIFIC, SPDK_NVME_SCT_GENERIC, SPDK_NVME_SCT_MEDIA_ERROR, + SPDK_NVME_SCT_PATH, SPDK_NVME_SCT_VENDOR_SPECIFIC, SPDK_NVME_SC_DATA_TRANSFER_ERROR, + SPDK_NVME_SC_DEALLOCATED_OR_UNWRITTEN_BLOCK, SPDK_NVME_SC_SUCCESS, }; /// Accessors for `spdk_nvme_cpl` (completion queue entry) struct. @@ -94,33 +82,23 @@ impl NvmeStatus { pub const SUCCESS: Self = NvmeStatus::Generic(SPDK_NVME_SC_SUCCESS); /// Shorthand for SPDK_NVME_SC_DEALLOCATED_OR_UNWRITTEN_BLOCK. - pub const UNWRITTEN_BLOCK: Self = - Self::Media(SPDK_NVME_SC_DEALLOCATED_OR_UNWRITTEN_BLOCK); + pub const UNWRITTEN_BLOCK: Self = Self::Media(SPDK_NVME_SC_DEALLOCATED_OR_UNWRITTEN_BLOCK); /// Shorthand for a vendor-specific ENOSPC error. pub const NO_SPACE: Self = Self::VendorSpecific(Errno::ENOSPC as i32); /// A shorthand for a generic data transfer error. - pub const DATA_TRANSFER_ERROR: Self = - NvmeStatus::Generic(SPDK_NVME_SC_DATA_TRANSFER_ERROR); + pub const DATA_TRANSFER_ERROR: Self = NvmeStatus::Generic(SPDK_NVME_SC_DATA_TRANSFER_ERROR); /// TODO pub fn as_sct_sc_codes(&self) -> (i32, i32) { unsafe { match *self { - Self::Generic(c) => { - (transmute(SPDK_NVME_SCT_GENERIC), transmute(c)) - } - Self::CmdSpecific(c) => { - (transmute(SPDK_NVME_SCT_COMMAND_SPECIFIC), transmute(c)) - } - Self::Media(c) => { - (transmute(SPDK_NVME_SCT_MEDIA_ERROR), transmute(c)) - } + Self::Generic(c) => (transmute(SPDK_NVME_SCT_GENERIC), transmute(c)), + Self::CmdSpecific(c) => (transmute(SPDK_NVME_SCT_COMMAND_SPECIFIC), transmute(c)), + Self::Media(c) => (transmute(SPDK_NVME_SCT_MEDIA_ERROR), transmute(c)), Self::Path(c) => (transmute(SPDK_NVME_SCT_PATH), transmute(c)), - Self::VendorSpecific(c) => { - (transmute(SPDK_NVME_SCT_VENDOR_SPECIFIC), transmute(c)) - } + Self::VendorSpecific(c) => (transmute(SPDK_NVME_SCT_VENDOR_SPECIFIC), transmute(c)), Self::Unknown(sct, sc) => (transmute(sct), transmute(sc)), } } @@ -180,9 +158,7 @@ impl From<(i32, i32)> for NvmeStatus { match transmute(sct) { SPDK_NVME_SCT_GENERIC => Self::Generic(transmute(sc)), - SPDK_NVME_SCT_COMMAND_SPECIFIC => { - Self::CmdSpecific(transmute(sc)) - } + SPDK_NVME_SCT_COMMAND_SPECIFIC => Self::CmdSpecific(transmute(sc)), SPDK_NVME_SCT_MEDIA_ERROR => Self::Media(transmute(sc)), SPDK_NVME_SCT_PATH => Self::Path(transmute(sc)), SPDK_NVME_SCT_VENDOR_SPECIFIC => Self::VendorSpecific(sc), diff --git a/src/nvmf.rs b/src/nvmf.rs index 52a3114..db1ea51 100644 --- a/src/nvmf.rs +++ b/src/nvmf.rs @@ -8,9 +8,7 @@ use std::{ use crate::{ ffihelper::AsStr, libspdk::{ - spdk_nvmf_ctrlr, - spdk_nvmf_subsystem_event, - SPDK_NVMF_SUBSYSTEM_EVENT_HOST_CONNECT, + spdk_nvmf_ctrlr, spdk_nvmf_subsystem_event, SPDK_NVMF_SUBSYSTEM_EVENT_HOST_CONNECT, SPDK_NVMF_SUBSYSTEM_EVENT_HOST_DISCONNECT, SPDK_NVMF_SUBSYSTEM_EVENT_HOST_KEEP_ALIVE_TIMEOUT, }, @@ -65,21 +63,16 @@ pub enum NvmfSubsystemEvent { } impl NvmfSubsystemEvent { - pub fn from_cb_args( - event: spdk_nvmf_subsystem_event, - ctx: *mut c_void, - ) -> Self { + pub fn from_cb_args(event: spdk_nvmf_subsystem_event, ctx: *mut c_void) -> Self { match event { - SPDK_NVMF_SUBSYSTEM_EVENT_HOST_CONNECT => Self::HostConnect( - NvmfController::from(ctx as *mut spdk_nvmf_ctrlr), - ), - SPDK_NVMF_SUBSYSTEM_EVENT_HOST_DISCONNECT => Self::HostDisconnect( - NvmfController::from(ctx as *mut spdk_nvmf_ctrlr), - ), + SPDK_NVMF_SUBSYSTEM_EVENT_HOST_CONNECT => { + Self::HostConnect(NvmfController::from(ctx as *mut spdk_nvmf_ctrlr)) + } + SPDK_NVMF_SUBSYSTEM_EVENT_HOST_DISCONNECT => { + Self::HostDisconnect(NvmfController::from(ctx as *mut spdk_nvmf_ctrlr)) + } SPDK_NVMF_SUBSYSTEM_EVENT_HOST_KEEP_ALIVE_TIMEOUT => { - Self::HostKeepAliveTimeout(NvmfController::from( - ctx as *mut spdk_nvmf_ctrlr, - )) + Self::HostKeepAliveTimeout(NvmfController::from(ctx as *mut spdk_nvmf_ctrlr)) } _ => { warn!("Unknown NVMF subsystem event: {event:?}"); diff --git a/src/poller.rs b/src/poller.rs index d0431d9..1c563e4 100644 --- a/src/poller.rs +++ b/src/poller.rs @@ -12,13 +12,8 @@ use crate::{ cpu_cores::Cores, ffihelper::{AsStr, IntoCString}, libspdk::{ - spdk_poller, - spdk_poller_fn, - spdk_poller_pause, - spdk_poller_register, - spdk_poller_register_named, - spdk_poller_resume, - spdk_poller_unregister, + spdk_poller, spdk_poller_fn, spdk_poller_pause, spdk_poller_register, + spdk_poller_register_named, spdk_poller_resume, spdk_poller_unregister, }, Thread, }; @@ -64,10 +59,9 @@ where .field("interval_us", &self.interval) .field( "thread", - &self.thread.map_or_else( - || "".to_string(), - |t| t.name().to_string(), - ), + &self + .thread + .map_or_else(|| "".to_string(), |t| t.name().to_string()), ) .finish() } @@ -139,9 +133,7 @@ where ) } } - None => unsafe { - spdk_poller_register(poll_fn, self.as_ctx().0, self.interval) - }, + None => unsafe { spdk_poller_register(poll_fn, self.as_ctx().0, self.interval) }, }; self.state = PollerState::Waiting; } @@ -411,8 +403,6 @@ where trace!("New poller context '{}' ({:p})", ctx.dbg_name(), ctx); - Poller { - inner: Some(ctx), - } + Poller { inner: Some(ctx) } } } diff --git a/src/thread.rs b/src/thread.rs index 89a0b12..398f04f 100644 --- a/src/thread.rs +++ b/src/thread.rs @@ -10,18 +10,9 @@ use std::{ use crate::{ cpu_cores::{Cores, CpuMask}, libspdk::{ - spdk_get_thread, - spdk_set_thread, - spdk_thread, - spdk_thread_create, - spdk_thread_destroy, - spdk_thread_exit, - spdk_thread_get_by_id, - spdk_thread_get_id, - spdk_thread_get_name, - spdk_thread_is_exited, - spdk_thread_poll, - spdk_thread_send_msg, + spdk_get_thread, spdk_set_thread, spdk_thread, spdk_thread_create, spdk_thread_destroy, + spdk_thread_exit, spdk_thread_get_by_id, spdk_thread_get_id, spdk_thread_get_name, + spdk_thread_is_exited, spdk_thread_poll, spdk_thread_send_msg, }, }; @@ -67,9 +58,7 @@ impl Thread { mask.set_cpu(core, true); spdk_thread_create(name.as_ptr(), mask.as_ptr()) }) - .map(|inner| Self { - inner, - }) + .map(|inner| Self { inner }) } /// Marks thread as exiting. @@ -140,9 +129,7 @@ impl Thread { /// Returns the primary ("init") SPDK thread or None. /// Useful when shutting down before init thread is allocated. pub fn primary_safe() -> Option { - NonNull::new(unsafe { spdk_thread_get_by_id(1) }).map(|inner| Self { - inner, - }) + NonNull::new(unsafe { spdk_thread_get_by_id(1) }).map(|inner| Self { inner }) } /// Returns thread identifier. @@ -197,11 +184,7 @@ impl Thread { } /// TODO - pub unsafe fn send_msg_unsafe( - &self, - f: extern "C" fn(ctx: *mut c_void), - arg: *mut c_void, - ) { + pub unsafe fn send_msg_unsafe(&self, f: extern "C" fn(ctx: *mut c_void), arg: *mut c_void) { let rc = spdk_thread_send_msg(self.as_ptr(), Some(f), arg); assert_eq!(rc, 0); } @@ -228,10 +211,7 @@ impl Thread { (ctx.closure)(ctx.args); } - let ctx = Box::new(Ctx { - closure: f, - args, - }); + let ctx = Box::new(Ctx { closure: f, args }); let rc = unsafe { spdk_thread_send_msg( @@ -260,7 +240,7 @@ impl Thread { pub fn unaffinitize() { unsafe { let mut set: libc::cpu_set_t = std::mem::zeroed(); - for i in 0 .. libc::sysconf(libc::_SC_NPROCESSORS_ONLN) { + for i in 0..libc::sysconf(libc::_SC_NPROCESSORS_ONLN) { libc::CPU_SET(i as usize, &mut set) } @@ -268,11 +248,7 @@ impl Thread { .into_iter() .for_each(|i| libc::CPU_CLR(i as usize, &mut set)); - libc::sched_setaffinity( - 0, - std::mem::size_of::(), - &set, - ); + libc::sched_setaffinity(0, std::mem::size_of::(), &set); trace!("pthread started on core {}", libc::sched_getcpu()); } diff --git a/src/untyped_bdev.rs b/src/untyped_bdev.rs index 048923a..cd90014 100644 --- a/src/untyped_bdev.rs +++ b/src/untyped_bdev.rs @@ -14,11 +14,7 @@ impl BdevOps for () { fn destruct(self: Pin<&mut Self>) {} - fn submit_request( - &self, - _chan: IoChannel, - _bio: BdevIo, - ) { + fn submit_request(&self, _chan: IoChannel, _bio: BdevIo) { unreachable!() } diff --git a/src/uuid.rs b/src/uuid.rs index 99730b3..4a17009 100644 --- a/src/uuid.rs +++ b/src/uuid.rs @@ -26,9 +26,7 @@ impl Uuid { /// /// * `u`: TODO pub(crate) fn new(u: &spdk_uuid) -> Self { - Self { - inner: *u, - } + Self { inner: *u } } /// Consumes the `Uuid` and returns its SPDK internal representation. @@ -73,9 +71,7 @@ impl From for Uuid { ) }; - Self { - inner, - } + Self { inner } } } @@ -87,9 +83,7 @@ impl From for uuid::Uuid { impl Clone for Uuid { fn clone(&self) -> Self { - Self { - inner: self.inner, - } + Self { inner: self.inner } } }