From 0c26c41f2fdc02863974326d055bdfbb245f6412 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Wed, 4 Sep 2024 13:19:39 +0800 Subject: [PATCH] chore: fix some clippy warning (#100) * fix some clippy warning Signed-off-by: Weizhen Wang * fix some clippy warning Signed-off-by: Weizhen Wang --------- Signed-off-by: Weizhen Wang --- Makefile | 2 +- src/ceph.rs | 9 +++--- src/ceph_client.rs | 70 ++++++++++++++++------------------------------ src/ceph_volume.rs | 6 ++-- 4 files changed, 32 insertions(+), 55 deletions(-) diff --git a/Makefile b/Makefile index e79237b..d5d6e8e 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ build: fmt: cargo fmt test: - cargo test. + cargo test test-docker: .build-docker docker run --rm -it -v $(CURDIR):/ceph-rust $(DOCKER_CI_IMAGE) diff --git a/src/ceph.rs b/src/ceph.rs index 05c2040..ddc124d 100644 --- a/src/ceph.rs +++ b/src/ceph.rs @@ -862,7 +862,6 @@ impl IoCtx { out_str.as_ptr() as *mut c_char, out_buff_size as c_int, ); - if ret_code == -ERANGE {} if ret_code < 0 { return Err(ret_code.into()); } @@ -2026,7 +2025,7 @@ impl Rados { debug!("return code: {}", ret_code); if ret_code < 0 { if outs_len > 0 && !outs.is_null() { - let slice = ::std::slice::from_raw_parts(outs as *const u8, outs_len as usize); + let slice = ::std::slice::from_raw_parts(outs as *const u8, outs_len); rados_buffer_free(outs); return Err(RadosError::new(String::from_utf8_lossy(slice).into_owned())); } @@ -2096,7 +2095,7 @@ impl Rados { cmds.as_mut_ptr(), 1, data.as_ptr() as *mut c_char, - data.len() as usize, + data.len(), &mut outbuf, &mut outbuf_len, &mut outs, @@ -2186,7 +2185,7 @@ impl Rados { cmds.as_mut_ptr(), 1, data.as_ptr() as *mut c_char, - data.len() as usize, + data.len(), &mut outbuf, &mut outbuf_len, &mut outs, @@ -2277,7 +2276,7 @@ impl Rados { cmds.as_mut_ptr(), 1, data.as_ptr() as *mut c_char, - data.len() as usize, + data.len(), &mut outbuf, &mut outbuf_len, &mut outs, diff --git a/src/ceph_client.rs b/src/ceph_client.rs index 2b20f07..25499d0 100644 --- a/src/ceph_client.rs +++ b/src/ceph_client.rs @@ -190,12 +190,12 @@ impl CephClient { /// List all the monitors in the cluster and their current rank pub fn mon_dump(&self) -> Result { - Ok(cmd::mon_dump(&self.rados_t)?) + cmd::mon_dump(&self.rados_t) } /// Get the mon quorum pub fn mon_quorum(&self) -> Result { - Ok(cmd::mon_quorum(&self.rados_t)?) + cmd::mon_quorum(&self.rados_t) } /// Show mon daemon version @@ -204,58 +204,47 @@ impl CephClient { } pub fn osd_pool_quota_get(&self, pool: &str) -> Result { - Ok(cmd::osd_pool_quota_get(&self.rados_t, pool)?) + cmd::osd_pool_quota_get(&self.rados_t, pool) } pub fn auth_del(&self, osd_id: u64) -> Result<(), RadosError> { - Ok(cmd::auth_del(&self.rados_t, osd_id, self.simulate)?) + cmd::auth_del(&self.rados_t, osd_id, self.simulate) } pub fn osd_rm(&self, osd_id: u64) -> Result<(), RadosError> { - Ok(cmd::osd_rm(&self.rados_t, osd_id, self.simulate)?) + cmd::osd_rm(&self.rados_t, osd_id, self.simulate) } pub fn osd_create(&self, id: Option) -> Result { - Ok(cmd::osd_create(&self.rados_t, id, self.simulate)?) + cmd::osd_create(&self.rados_t, id, self.simulate) } // Add a new mgr to the cluster pub fn mgr_auth_add(&self, mgr_id: &str) -> Result<(), RadosError> { - Ok(cmd::mgr_auth_add(&self.rados_t, mgr_id, self.simulate)?) + cmd::mgr_auth_add(&self.rados_t, mgr_id, self.simulate) } // Add a new osd to the cluster pub fn osd_auth_add(&self, osd_id: u64) -> Result<(), RadosError> { - Ok(cmd::osd_auth_add(&self.rados_t, osd_id, self.simulate)?) + cmd::osd_auth_add(&self.rados_t, osd_id, self.simulate) } /// Get a ceph-x key. The id parameter can be either a number or a string /// depending on the type of client so I went with string. pub fn auth_get_key(&self, client_type: &str, id: &str) -> Result { - Ok(cmd::auth_get_key(&self.rados_t, client_type, id)?) + cmd::auth_get_key(&self.rados_t, client_type, id) } // ceph osd crush add {id-or-name} {weight} [{bucket-type}={bucket-name} ...] /// add or update crushmap position and weight for an osd pub fn osd_crush_add(&self, osd_id: u64, weight: f64, host: &str) -> Result<(), RadosError> { - Ok(cmd::osd_crush_add( - &self.rados_t, - osd_id, - weight, - host, - self.simulate, - )?) + cmd::osd_crush_add(&self.rados_t, osd_id, weight, host, self.simulate) } // ceph osd crush reweight {id} {weight} /// reweight an osd in the CRUSH map pub fn osd_crush_reweight(&self, osd_id: u64, weight: f64) -> Result<(), RadosError> { - Ok(cmd::osd_crush_reweight( - &self.rados_t, - osd_id, - weight, - self.simulate, - )?) + cmd::osd_crush_reweight(&self.rados_t, osd_id, weight, self.simulate) } /// check if a single osd is safe to destroy/remove @@ -267,60 +256,51 @@ impl CephClient { pub fn mgr_dump(&self) -> Result { min_version!(Luminous, self); - Ok(cmd::mgr_dump(&self.rados_t)?) + cmd::mgr_dump(&self.rados_t) } pub fn mgr_fail(&self, mgr_id: &str) -> Result<(), RadosError> { min_version!(Luminous, self); - Ok(cmd::mgr_fail(&self.rados_t, mgr_id, self.simulate)?) + cmd::mgr_fail(&self.rados_t, mgr_id, self.simulate) } pub fn mgr_list_modules(&self) -> Result, RadosError> { min_version!(Luminous, self); - Ok(cmd::mgr_list_modules(&self.rados_t)?) + cmd::mgr_list_modules(&self.rados_t) } pub fn mgr_list_services(&self) -> Result, RadosError> { min_version!(Luminous, self); - Ok(cmd::mgr_list_services(&self.rados_t)?) + cmd::mgr_list_services(&self.rados_t) } pub fn mgr_enable_module(&self, module: &str, force: bool) -> Result<(), RadosError> { min_version!(Luminous, self); - Ok(cmd::mgr_enable_module( - &self.rados_t, - module, - force, - self.simulate, - )?) + cmd::mgr_enable_module(&self.rados_t, module, force, self.simulate) } pub fn mgr_disable_module(&self, module: &str) -> Result<(), RadosError> { min_version!(Luminous, self); - Ok(cmd::mgr_disable_module( - &self.rados_t, - module, - self.simulate, - )?) + cmd::mgr_disable_module(&self.rados_t, module, self.simulate) } pub fn mgr_metadata(&self) -> Result, RadosError> { min_version!(Luminous, self); - Ok(cmd::mgr_metadata(&self.rados_t)?) + cmd::mgr_metadata(&self.rados_t) } pub fn osd_metadata(&self) -> Result, RadosError> { - Ok(cmd::osd_metadata(&self.rados_t)?) + cmd::osd_metadata(&self.rados_t) } pub fn mgr_count_metadata(&self, property: &str) -> Result, RadosError> { min_version!(Luminous, self); - Ok(cmd::mgr_count_metadata(&self.rados_t, property)?) + cmd::mgr_count_metadata(&self.rados_t, property) } pub fn mgr_versions(&self) -> Result, RadosError> { min_version!(Luminous, self); - Ok(cmd::mgr_versions(&self.rados_t)?) + cmd::mgr_versions(&self.rados_t) } pub fn run_command(&self, command: MonCommand) -> Result { @@ -347,7 +327,7 @@ impl CephClient { &mut cmds.as_ptr(), 1, data.as_ptr() as *mut c_char, - data.len() as usize, + data.len(), &mut outbuf, &mut outbuf_len, &mut outs, @@ -357,8 +337,7 @@ impl CephClient { debug!("return code: {}", ret_code); if ret_code < 0 { if outs_len > 0 && !outs.is_null() { - let slice = - unsafe { ::std::slice::from_raw_parts(outs as *const u8, outs_len as usize) }; + let slice = unsafe { ::std::slice::from_raw_parts(outs as *const u8, outs_len) }; str_outs = String::from_utf8_lossy(slice).into_owned(); unsafe { @@ -374,8 +353,7 @@ impl CephClient { // Copy the data from outbuf and then call rados_buffer_free instead libc::free if outbuf_len > 0 && !outbuf.is_null() { - let slice = - unsafe { ::std::slice::from_raw_parts(outbuf as *const u8, outbuf_len as usize) }; + let slice = unsafe { ::std::slice::from_raw_parts(outbuf as *const u8, outbuf_len) }; str_outbuf = String::from_utf8_lossy(slice).into_owned(); unsafe { diff --git a/src/ceph_volume.rs b/src/ceph_volume.rs index 5c2bd13..b593716 100644 --- a/src/ceph_volume.rs +++ b/src/ceph_volume.rs @@ -119,7 +119,7 @@ fn check_version(cluster_handle: &Rados) -> RadosResult<()> { pub fn ceph_volume_list(cluster_handle: &Rados) -> RadosResult>> { check_version(cluster_handle)?; let output = Command::new("ceph-volume") - .args(&["lvm", "list", "--format=json"]) + .args(["lvm", "list", "--format=json"]) .output()?; let lvms: HashMap> = serde_json::from_str(&String::from_utf8_lossy(&output.stdout))?; @@ -138,11 +138,11 @@ pub fn ceph_volume_scan( if let Some(p) = osd_path { let path = format!("{}", p.display()); output = Command::new("ceph-volume") - .args(&["simple", "scan", "--stdout", &path]) + .args(["simple", "scan", "--stdout", &path]) .output()?; } else { output = Command::new("ceph-volume") - .args(&["simple", "scan", "--stdout"]) + .args(["simple", "scan", "--stdout"]) .output()?; } let json = String::from_utf8_lossy(&output.stdout);