Skip to content

Commit

Permalink
chore: fix some clippy warning (#100)
Browse files Browse the repository at this point in the history
* fix some clippy warning

Signed-off-by: Weizhen Wang <[email protected]>

* fix some clippy warning

Signed-off-by: Weizhen Wang <[email protected]>

---------

Signed-off-by: Weizhen Wang <[email protected]>
  • Loading branch information
hawkingrei authored Sep 4, 2024
1 parent b7cea7e commit 0c26c41
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 55 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 4 additions & 5 deletions src/ceph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down Expand Up @@ -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()));
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
70 changes: 24 additions & 46 deletions src/ceph_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,12 @@ impl CephClient {

/// List all the monitors in the cluster and their current rank
pub fn mon_dump(&self) -> Result<cmd::MonDump, RadosError> {
Ok(cmd::mon_dump(&self.rados_t)?)
cmd::mon_dump(&self.rados_t)
}

/// Get the mon quorum
pub fn mon_quorum(&self) -> Result<String, RadosError> {
Ok(cmd::mon_quorum(&self.rados_t)?)
cmd::mon_quorum(&self.rados_t)
}

/// Show mon daemon version
Expand All @@ -204,58 +204,47 @@ impl CephClient {
}

pub fn osd_pool_quota_get(&self, pool: &str) -> Result<u64, RadosError> {
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<u64>) -> Result<u64, RadosError> {
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<String, RadosError> {
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
Expand All @@ -267,60 +256,51 @@ impl CephClient {

pub fn mgr_dump(&self) -> Result<cmd::MgrDump, RadosError> {
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<Vec<String>, 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<Vec<String>, 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<Vec<cmd::MgrMetadata>, RadosError> {
min_version!(Luminous, self);
Ok(cmd::mgr_metadata(&self.rados_t)?)
cmd::mgr_metadata(&self.rados_t)
}

pub fn osd_metadata(&self) -> Result<Vec<cmd::OsdMetadata>, RadosError> {
Ok(cmd::osd_metadata(&self.rados_t)?)
cmd::osd_metadata(&self.rados_t)
}

pub fn mgr_count_metadata(&self, property: &str) -> Result<HashMap<String, u64>, 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<HashMap<String, u64>, 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<String, RadosError> {
Expand All @@ -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,
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions src/ceph_volume.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ fn check_version(cluster_handle: &Rados) -> RadosResult<()> {
pub fn ceph_volume_list(cluster_handle: &Rados) -> RadosResult<HashMap<String, Vec<Lvm>>> {
check_version(cluster_handle)?;
let output = Command::new("ceph-volume")
.args(&["lvm", "list", "--format=json"])
.args(["lvm", "list", "--format=json"])
.output()?;
let lvms: HashMap<String, Vec<Lvm>> =
serde_json::from_str(&String::from_utf8_lossy(&output.stdout))?;
Expand All @@ -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);
Expand Down

0 comments on commit 0c26c41

Please sign in to comment.