Skip to content

Commit

Permalink
refactor(fmt): use fmt style from rust stable
Browse files Browse the repository at this point in the history
Signed-off-by: Tiago Castro <[email protected]>
  • Loading branch information
tiagolobocastro committed Dec 3, 2024
1 parent 2f29c15 commit 20f2e44
Show file tree
Hide file tree
Showing 264 changed files with 3,847 additions and 9,447 deletions.
19 changes: 0 additions & 19 deletions .rustfmt.toml

This file was deleted.

3 changes: 1 addition & 2 deletions io-engine-bench/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
fn main() {
let profile = std::env::var("PROFILE").unwrap();
let spdk_rpath =
format!("{}/target/{}", std::env::var("SRCDIR").unwrap(), profile);
let spdk_rpath = format!("{}/target/{}", std::env::var("SRCDIR").unwrap(), profile);
println!("cargo:rustc-link-search=native={spdk_rpath}");
println!("cargo:rustc-link-arg=-Wl,-rpath={spdk_rpath}");
}
26 changes: 7 additions & 19 deletions io-engine-bench/src/nexus.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use criterion::{criterion_group, criterion_main, Criterion};
use io_engine::{
bdev::nexus::nexus_create,
constants::NVME_NQN_PREFIX,
core::MayastorCliArgs,
bdev::nexus::nexus_create, constants::NVME_NQN_PREFIX, core::MayastorCliArgs,
grpc::v1::nexus::nexus_destroy,
};
use std::sync::Arc;
Expand All @@ -15,10 +13,7 @@ use common::compose::{
mayastor::{BdevShareRequest, BdevUri, CreateNexusRequest, Null},
GrpcConnect,
},
Binary,
Builder,
ComposeTest,
MayastorTest,
Binary, Builder, ComposeTest, MayastorTest,
};

/// Infer the build type from the `OUT_DIR` and `SRCDIR`.
Expand Down Expand Up @@ -60,8 +55,7 @@ fn new_environment<'a>() -> Arc<MayastorTest<'a>> {

/// Get remote nvmf targets to use as nexus children.
async fn get_children(compose: Arc<ComposeTest>) -> &'static Vec<String> {
static STATIC_TARGETS: tokio::sync::OnceCell<Vec<String>> =
tokio::sync::OnceCell::const_new();
static STATIC_TARGETS: tokio::sync::OnceCell<Vec<String>> = tokio::sync::OnceCell::const_new();

STATIC_TARGETS
.get_or_init(|| async move {
Expand Down Expand Up @@ -171,9 +165,7 @@ impl Drop for GrpcNexus {
let nexus_hdl = &mut hdls.last_mut().unwrap();
nexus_hdl
.mayastor
.destroy_nexus(mayastor::DestroyNexusRequest {
uuid,
})
.destroy_nexus(mayastor::DestroyNexusRequest { uuid })
.await
.unwrap();
});
Expand All @@ -183,10 +175,7 @@ impl Drop for GrpcNexus {
}
}
/// Create a new nexus via grpc and return it as droppable to be destroyed.
async fn nexus_create_grpc(
compose: &Arc<ComposeTest>,
nr_children: usize,
) -> GrpcNexus {
async fn nexus_create_grpc(compose: &Arc<ComposeTest>, nr_children: usize) -> GrpcNexus {
let children = get_children(compose.clone())
.await
.iter()
Expand Down Expand Up @@ -219,9 +208,8 @@ fn criterion_benchmark(c: &mut Criterion) {
group
// Benchmark nexus create in-binary
.bench_function("direct", |b| {
b.to_async(&runtime).iter_with_large_drop(|| {
nexus_create_direct(&ms_environment, &compose, 3)
})
b.to_async(&runtime)
.iter_with_large_drop(|| nexus_create_direct(&ms_environment, &compose, 3))
})
// Benchmark nexus create via gRPC
.bench_function("grpc", |b| {
Expand Down
17 changes: 4 additions & 13 deletions io-engine-tests/src/bdev.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
use super::compose::rpc::v1::{
bdev::{Bdev, CreateBdevRequest, ListBdevOptions},
SharedRpcHandle,
Status,
SharedRpcHandle, Status,
};

/// Creates a bdev.
pub async fn create_bdev(
rpc: SharedRpcHandle,
uri: &str,
) -> Result<Bdev, Status> {
pub async fn create_bdev(rpc: SharedRpcHandle, uri: &str) -> Result<Bdev, Status> {
rpc.lock()
.await
.bdev
Expand All @@ -24,18 +20,13 @@ pub async fn list_bdevs(rpc: SharedRpcHandle) -> Result<Vec<Bdev>, Status> {
rpc.lock()
.await
.bdev
.list(ListBdevOptions {
name: None,
})
.list(ListBdevOptions { name: None })
.await
.map(|r| r.into_inner().bdevs)
}

/// Finds a bdev by its name.
pub async fn find_bdev_by_name(
rpc: SharedRpcHandle,
name: &str,
) -> Option<Bdev> {
pub async fn find_bdev_by_name(rpc: SharedRpcHandle, name: &str) -> Option<Bdev> {
match list_bdevs(rpc).await {
Err(_) => None,
Ok(nn) => nn.into_iter().find(|p| p.name == name),
Expand Down
12 changes: 2 additions & 10 deletions io-engine-tests/src/bdev_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,14 @@ pub async fn read_some(
Ok(())
}

pub async fn write_zeroes_some(
nexus_name: &str,
offset: u64,
len: u64,
) -> Result<(), CoreError> {
pub async fn write_zeroes_some(nexus_name: &str, offset: u64, len: u64) -> Result<(), CoreError> {
let h = UntypedBdevHandle::open(nexus_name, true, false)?;

h.write_zeroes_at(offset, len).await?;
Ok(())
}

pub async fn read_some_safe(
nexus_name: &str,
offset: u64,
fill: u8,
) -> Result<bool, CoreError> {
pub async fn read_some_safe(nexus_name: &str, offset: u64, fill: u8) -> Result<bool, CoreError> {
let h = UntypedBdevHandle::open(nexus_name, true, false)?;

let buflen = u64::from(h.get_bdev().block_len() * 2);
Expand Down
17 changes: 3 additions & 14 deletions io-engine-tests/src/compose/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,8 @@ use tokio::sync::oneshot::channel;
use crate::mayastor_test_init_ex;
use io_engine::{
core::{
device_monitor_loop,
mayastor_env_stop,
runtime,
MayastorCliArgs,
MayastorEnvironment,
ProtectedSubsystems,
Reactor,
Reactors,
ResourceLockManager,
ResourceLockManagerConfig,
device_monitor_loop, mayastor_env_stop, runtime, MayastorCliArgs, MayastorEnvironment,
ProtectedSubsystems, Reactor, Reactors, ResourceLockManager, ResourceLockManagerConfig,
GLOBAL_RC,
},
grpc,
Expand Down Expand Up @@ -81,10 +73,7 @@ impl<'a> MayastorTest<'a> {
Self::new_ex(args, None)
}

pub fn new_ex(
args: MayastorCliArgs,
log_level: Option<&str>,
) -> MayastorTest<'static> {
pub fn new_ex(args: MayastorCliArgs, log_level: Option<&str>) -> MayastorTest<'static> {
let (tx, rx) = bounded(1);
mayastor_test_init_ex(args.log_format.unwrap_or_default(), log_level);
let thdl = std::thread::Builder::new()
Expand Down
17 changes: 4 additions & 13 deletions io-engine-tests/src/compose/rpc/v0.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use composer::ComposeTest;

use mayastor::{
bdev_rpc_client::BdevRpcClient,
json_rpc_client::JsonRpcClient,
mayastor_client::MayastorClient,
bdev_rpc_client::BdevRpcClient, json_rpc_client::JsonRpcClient, mayastor_client::MayastorClient,
};

use std::{
Expand All @@ -28,15 +26,10 @@ pub struct RpcHandle {

impl RpcHandle {
/// connect to the containers and construct a handle
pub(super) async fn connect(
name: String,
endpoint: SocketAddr,
) -> Result<Self, String> {
pub(super) async fn connect(name: String, endpoint: SocketAddr) -> Result<Self, String> {
let mut attempts = 40;
loop {
if TcpStream::connect_timeout(&endpoint, Duration::from_millis(100))
.is_ok()
{
if TcpStream::connect_timeout(&endpoint, Duration::from_millis(100)).is_ok() {
break;
} else {
thread::sleep(Duration::from_millis(101));
Expand Down Expand Up @@ -74,9 +67,7 @@ pub struct GrpcConnect<'a> {
impl<'a> GrpcConnect<'a> {
/// create new gRPC connect object
pub fn new(comp: &'a ComposeTest) -> Self {
Self {
ct: comp,
}
Self { ct: comp }
}

/// return grpc handles to the containers
Expand Down
46 changes: 16 additions & 30 deletions io-engine-tests/src/compose/rpc/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,10 @@ pub struct RpcHandle {

impl RpcHandle {
/// connect to the containers and construct a handle
pub(super) async fn connect(
name: String,
endpoint: SocketAddr,
) -> Result<Self, String> {
pub(super) async fn connect(name: String, endpoint: SocketAddr) -> Result<Self, String> {
let mut attempts = 40;
loop {
if TcpStream::connect_timeout(&endpoint, Duration::from_millis(100))
.is_ok()
{
if TcpStream::connect_timeout(&endpoint, Duration::from_millis(100)).is_ok() {
break;
} else {
thread::sleep(Duration::from_millis(101));
Expand All @@ -88,29 +83,25 @@ impl RpcHandle {
.await
.unwrap();

let replica =
replica::ReplicaRpcClient::connect(format!("http://{endpoint}"))
.await
.unwrap();
let replica = replica::ReplicaRpcClient::connect(format!("http://{endpoint}"))
.await
.unwrap();

let host = host::HostRpcClient::connect(format!("http://{endpoint}"))
.await
.unwrap();

let nexus =
nexus::NexusRpcClient::connect(format!("http://{endpoint}"))
.await
.unwrap();
let nexus = nexus::NexusRpcClient::connect(format!("http://{endpoint}"))
.await
.unwrap();

let snapshot =
snapshot::SnapshotRpcClient::connect(format!("http://{endpoint}"))
.await
.unwrap();
let snapshot = snapshot::SnapshotRpcClient::connect(format!("http://{endpoint}"))
.await
.unwrap();

let stats =
stats::StatsRpcClient::connect(format!("http://{endpoint}"))
.await
.unwrap();
let stats = stats::StatsRpcClient::connect(format!("http://{endpoint}"))
.await
.unwrap();

let test = test::TestRpcClient::connect(format!("http://{endpoint}"))
.await
Expand Down Expand Up @@ -139,9 +130,7 @@ pub struct GrpcConnect<'a> {
impl<'a> GrpcConnect<'a> {
/// create new gRPC connect object
pub fn new(comp: &'a ComposeTest) -> Self {
Self {
ct: comp,
}
Self { ct: comp }
}

/// return grpc handles to the containers
Expand Down Expand Up @@ -176,10 +165,7 @@ impl<'a> GrpcConnect<'a> {
}
}

pub async fn grpc_handle_shared(
&self,
name: &str,
) -> Result<SharedRpcHandle, String> {
pub async fn grpc_handle_shared(&self, name: &str) -> Result<SharedRpcHandle, String> {
self.grpc_handle(name).await.map(|rpc| {
let name = rpc.name.clone();
let endpoint = rpc.endpoint;
Expand Down
26 changes: 7 additions & 19 deletions io-engine-tests/src/error_bdev.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use spdk_rs::libspdk::{
create_aio_bdev,
vbdev_error_create,
vbdev_error_inject_error,
vbdev_error_inject_opts,
create_aio_bdev, vbdev_error_create, vbdev_error_inject_error, vbdev_error_inject_opts,
};
pub use spdk_rs::libspdk::{SPDK_BDEV_IO_TYPE_READ, SPDK_BDEV_IO_TYPE_WRITE};

Expand All @@ -16,32 +13,23 @@ pub fn create_error_bdev(error_device: &str, backing_device: &str) {

unsafe {
// this allows us to create a bdev without its name being a uri
retval = create_aio_bdev(
cname.as_ptr(),
filename.as_ptr(),
512,
false,
false,
)
retval = create_aio_bdev(cname.as_ptr(), filename.as_ptr(), 512, false, false)
};
assert_eq!(retval, 0);

let err_bdev_name_str = std::ffi::CString::new(error_device.to_string())
.expect("Failed to create name string");
let err_bdev_name_str =
std::ffi::CString::new(error_device.to_string()).expect("Failed to create name string");
unsafe {
// create the error bdev around it
retval = vbdev_error_create(
err_bdev_name_str.as_ptr(),
std::ptr::null_mut(),
);
retval = vbdev_error_create(err_bdev_name_str.as_ptr(), std::ptr::null_mut());
}
assert_eq!(retval, 0);
}

pub fn inject_error(error_device: &str, op: u32, mode: u32, count: u32) {
let retval: i32;
let err_bdev_name_str = std::ffi::CString::new(error_device)
.expect("Failed to create name string");
let err_bdev_name_str =
std::ffi::CString::new(error_device).expect("Failed to create name string");
let raw = err_bdev_name_str.into_raw();

let opts = vbdev_error_inject_opts {
Expand Down
Loading

0 comments on commit 20f2e44

Please sign in to comment.