Skip to content

Commit 0c26c41

Browse files
authored
chore: fix some clippy warning (#100)
* fix some clippy warning Signed-off-by: Weizhen Wang <wangweizhen@pingcap.com> * fix some clippy warning Signed-off-by: Weizhen Wang <wangweizhen@pingcap.com> --------- Signed-off-by: Weizhen Wang <wangweizhen@pingcap.com>
1 parent b7cea7e commit 0c26c41

File tree

4 files changed

+32
-55
lines changed

4 files changed

+32
-55
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ build:
55
fmt:
66
cargo fmt
77
test:
8-
cargo test.
8+
cargo test
99

1010
test-docker: .build-docker
1111
docker run --rm -it -v $(CURDIR):/ceph-rust $(DOCKER_CI_IMAGE)

src/ceph.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,6 @@ impl IoCtx {
862862
out_str.as_ptr() as *mut c_char,
863863
out_buff_size as c_int,
864864
);
865-
if ret_code == -ERANGE {}
866865
if ret_code < 0 {
867866
return Err(ret_code.into());
868867
}
@@ -2026,7 +2025,7 @@ impl Rados {
20262025
debug!("return code: {}", ret_code);
20272026
if ret_code < 0 {
20282027
if outs_len > 0 && !outs.is_null() {
2029-
let slice = ::std::slice::from_raw_parts(outs as *const u8, outs_len as usize);
2028+
let slice = ::std::slice::from_raw_parts(outs as *const u8, outs_len);
20302029
rados_buffer_free(outs);
20312030
return Err(RadosError::new(String::from_utf8_lossy(slice).into_owned()));
20322031
}
@@ -2096,7 +2095,7 @@ impl Rados {
20962095
cmds.as_mut_ptr(),
20972096
1,
20982097
data.as_ptr() as *mut c_char,
2099-
data.len() as usize,
2098+
data.len(),
21002099
&mut outbuf,
21012100
&mut outbuf_len,
21022101
&mut outs,
@@ -2186,7 +2185,7 @@ impl Rados {
21862185
cmds.as_mut_ptr(),
21872186
1,
21882187
data.as_ptr() as *mut c_char,
2189-
data.len() as usize,
2188+
data.len(),
21902189
&mut outbuf,
21912190
&mut outbuf_len,
21922191
&mut outs,
@@ -2277,7 +2276,7 @@ impl Rados {
22772276
cmds.as_mut_ptr(),
22782277
1,
22792278
data.as_ptr() as *mut c_char,
2280-
data.len() as usize,
2279+
data.len(),
22812280
&mut outbuf,
22822281
&mut outbuf_len,
22832282
&mut outs,

src/ceph_client.rs

Lines changed: 24 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,12 @@ impl CephClient {
190190

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

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

201201
/// Show mon daemon version
@@ -204,58 +204,47 @@ impl CephClient {
204204
}
205205

206206
pub fn osd_pool_quota_get(&self, pool: &str) -> Result<u64, RadosError> {
207-
Ok(cmd::osd_pool_quota_get(&self.rados_t, pool)?)
207+
cmd::osd_pool_quota_get(&self.rados_t, pool)
208208
}
209209

210210
pub fn auth_del(&self, osd_id: u64) -> Result<(), RadosError> {
211-
Ok(cmd::auth_del(&self.rados_t, osd_id, self.simulate)?)
211+
cmd::auth_del(&self.rados_t, osd_id, self.simulate)
212212
}
213213

214214
pub fn osd_rm(&self, osd_id: u64) -> Result<(), RadosError> {
215-
Ok(cmd::osd_rm(&self.rados_t, osd_id, self.simulate)?)
215+
cmd::osd_rm(&self.rados_t, osd_id, self.simulate)
216216
}
217217

218218
pub fn osd_create(&self, id: Option<u64>) -> Result<u64, RadosError> {
219-
Ok(cmd::osd_create(&self.rados_t, id, self.simulate)?)
219+
cmd::osd_create(&self.rados_t, id, self.simulate)
220220
}
221221

222222
// Add a new mgr to the cluster
223223
pub fn mgr_auth_add(&self, mgr_id: &str) -> Result<(), RadosError> {
224-
Ok(cmd::mgr_auth_add(&self.rados_t, mgr_id, self.simulate)?)
224+
cmd::mgr_auth_add(&self.rados_t, mgr_id, self.simulate)
225225
}
226226

227227
// Add a new osd to the cluster
228228
pub fn osd_auth_add(&self, osd_id: u64) -> Result<(), RadosError> {
229-
Ok(cmd::osd_auth_add(&self.rados_t, osd_id, self.simulate)?)
229+
cmd::osd_auth_add(&self.rados_t, osd_id, self.simulate)
230230
}
231231

232232
/// Get a ceph-x key. The id parameter can be either a number or a string
233233
/// depending on the type of client so I went with string.
234234
pub fn auth_get_key(&self, client_type: &str, id: &str) -> Result<String, RadosError> {
235-
Ok(cmd::auth_get_key(&self.rados_t, client_type, id)?)
235+
cmd::auth_get_key(&self.rados_t, client_type, id)
236236
}
237237

238238
// ceph osd crush add {id-or-name} {weight} [{bucket-type}={bucket-name} ...]
239239
/// add or update crushmap position and weight for an osd
240240
pub fn osd_crush_add(&self, osd_id: u64, weight: f64, host: &str) -> Result<(), RadosError> {
241-
Ok(cmd::osd_crush_add(
242-
&self.rados_t,
243-
osd_id,
244-
weight,
245-
host,
246-
self.simulate,
247-
)?)
241+
cmd::osd_crush_add(&self.rados_t, osd_id, weight, host, self.simulate)
248242
}
249243

250244
// ceph osd crush reweight {id} {weight}
251245
/// reweight an osd in the CRUSH map
252246
pub fn osd_crush_reweight(&self, osd_id: u64, weight: f64) -> Result<(), RadosError> {
253-
Ok(cmd::osd_crush_reweight(
254-
&self.rados_t,
255-
osd_id,
256-
weight,
257-
self.simulate,
258-
)?)
247+
cmd::osd_crush_reweight(&self.rados_t, osd_id, weight, self.simulate)
259248
}
260249

261250
/// check if a single osd is safe to destroy/remove
@@ -267,60 +256,51 @@ impl CephClient {
267256

268257
pub fn mgr_dump(&self) -> Result<cmd::MgrDump, RadosError> {
269258
min_version!(Luminous, self);
270-
Ok(cmd::mgr_dump(&self.rados_t)?)
259+
cmd::mgr_dump(&self.rados_t)
271260
}
272261

273262
pub fn mgr_fail(&self, mgr_id: &str) -> Result<(), RadosError> {
274263
min_version!(Luminous, self);
275-
Ok(cmd::mgr_fail(&self.rados_t, mgr_id, self.simulate)?)
264+
cmd::mgr_fail(&self.rados_t, mgr_id, self.simulate)
276265
}
277266

278267
pub fn mgr_list_modules(&self) -> Result<Vec<String>, RadosError> {
279268
min_version!(Luminous, self);
280-
Ok(cmd::mgr_list_modules(&self.rados_t)?)
269+
cmd::mgr_list_modules(&self.rados_t)
281270
}
282271

283272
pub fn mgr_list_services(&self) -> Result<Vec<String>, RadosError> {
284273
min_version!(Luminous, self);
285-
Ok(cmd::mgr_list_services(&self.rados_t)?)
274+
cmd::mgr_list_services(&self.rados_t)
286275
}
287276

288277
pub fn mgr_enable_module(&self, module: &str, force: bool) -> Result<(), RadosError> {
289278
min_version!(Luminous, self);
290-
Ok(cmd::mgr_enable_module(
291-
&self.rados_t,
292-
module,
293-
force,
294-
self.simulate,
295-
)?)
279+
cmd::mgr_enable_module(&self.rados_t, module, force, self.simulate)
296280
}
297281

298282
pub fn mgr_disable_module(&self, module: &str) -> Result<(), RadosError> {
299283
min_version!(Luminous, self);
300-
Ok(cmd::mgr_disable_module(
301-
&self.rados_t,
302-
module,
303-
self.simulate,
304-
)?)
284+
cmd::mgr_disable_module(&self.rados_t, module, self.simulate)
305285
}
306286

307287
pub fn mgr_metadata(&self) -> Result<Vec<cmd::MgrMetadata>, RadosError> {
308288
min_version!(Luminous, self);
309-
Ok(cmd::mgr_metadata(&self.rados_t)?)
289+
cmd::mgr_metadata(&self.rados_t)
310290
}
311291

312292
pub fn osd_metadata(&self) -> Result<Vec<cmd::OsdMetadata>, RadosError> {
313-
Ok(cmd::osd_metadata(&self.rados_t)?)
293+
cmd::osd_metadata(&self.rados_t)
314294
}
315295

316296
pub fn mgr_count_metadata(&self, property: &str) -> Result<HashMap<String, u64>, RadosError> {
317297
min_version!(Luminous, self);
318-
Ok(cmd::mgr_count_metadata(&self.rados_t, property)?)
298+
cmd::mgr_count_metadata(&self.rados_t, property)
319299
}
320300

321301
pub fn mgr_versions(&self) -> Result<HashMap<String, u64>, RadosError> {
322302
min_version!(Luminous, self);
323-
Ok(cmd::mgr_versions(&self.rados_t)?)
303+
cmd::mgr_versions(&self.rados_t)
324304
}
325305

326306
pub fn run_command(&self, command: MonCommand) -> Result<String, RadosError> {
@@ -347,7 +327,7 @@ impl CephClient {
347327
&mut cmds.as_ptr(),
348328
1,
349329
data.as_ptr() as *mut c_char,
350-
data.len() as usize,
330+
data.len(),
351331
&mut outbuf,
352332
&mut outbuf_len,
353333
&mut outs,
@@ -357,8 +337,7 @@ impl CephClient {
357337
debug!("return code: {}", ret_code);
358338
if ret_code < 0 {
359339
if outs_len > 0 && !outs.is_null() {
360-
let slice =
361-
unsafe { ::std::slice::from_raw_parts(outs as *const u8, outs_len as usize) };
340+
let slice = unsafe { ::std::slice::from_raw_parts(outs as *const u8, outs_len) };
362341
str_outs = String::from_utf8_lossy(slice).into_owned();
363342

364343
unsafe {
@@ -374,8 +353,7 @@ impl CephClient {
374353

375354
// Copy the data from outbuf and then call rados_buffer_free instead libc::free
376355
if outbuf_len > 0 && !outbuf.is_null() {
377-
let slice =
378-
unsafe { ::std::slice::from_raw_parts(outbuf as *const u8, outbuf_len as usize) };
356+
let slice = unsafe { ::std::slice::from_raw_parts(outbuf as *const u8, outbuf_len) };
379357
str_outbuf = String::from_utf8_lossy(slice).into_owned();
380358

381359
unsafe {

src/ceph_volume.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ fn check_version(cluster_handle: &Rados) -> RadosResult<()> {
119119
pub fn ceph_volume_list(cluster_handle: &Rados) -> RadosResult<HashMap<String, Vec<Lvm>>> {
120120
check_version(cluster_handle)?;
121121
let output = Command::new("ceph-volume")
122-
.args(&["lvm", "list", "--format=json"])
122+
.args(["lvm", "list", "--format=json"])
123123
.output()?;
124124
let lvms: HashMap<String, Vec<Lvm>> =
125125
serde_json::from_str(&String::from_utf8_lossy(&output.stdout))?;
@@ -138,11 +138,11 @@ pub fn ceph_volume_scan(
138138
if let Some(p) = osd_path {
139139
let path = format!("{}", p.display());
140140
output = Command::new("ceph-volume")
141-
.args(&["simple", "scan", "--stdout", &path])
141+
.args(["simple", "scan", "--stdout", &path])
142142
.output()?;
143143
} else {
144144
output = Command::new("ceph-volume")
145-
.args(&["simple", "scan", "--stdout"])
145+
.args(["simple", "scan", "--stdout"])
146146
.output()?;
147147
}
148148
let json = String::from_utf8_lossy(&output.stdout);

0 commit comments

Comments
 (0)