Skip to content

Commit 3147ffb

Browse files
committed
Fix up the rados_fsid function
The rados_fsid function was failing due to the UUID parsing failing. Ceph actually returns a UUID hyphenated string instead of just a simple UUID string like I had originally thought.
1 parent 5aea983 commit 3147ffb

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

examples/ceph.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fn main() {
4040
// return and allow for pattern matching.
4141

4242
// Example of accessing the `Admin Socket` for mon
43-
match admin_socket_command("help", "/var/run/ceph/ceph-mon.ceph-vm1.asok") {
43+
match admin_socket_command("help", "/var/run/ceph/ceph-mon.ip-172-31-31-247.asok") {
4444
Ok(json) => {
4545
println!("{}", json);
4646
},
@@ -51,16 +51,24 @@ fn main() {
5151

5252
let rados_version = ceph_helpers::rados_libversion();
5353
println!("Librados version: {:?}", rados_version);
54+
55+
println!("Connecting to ceph");
5456
let cluster = ceph_helpers::connect_to_ceph("admin", "/etc/ceph/ceph.conf").unwrap();
57+
println!("Creating pool {}", pool_name);
5558
ceph_helpers::rados_create_pool(cluster, pool_name).unwrap();
5659

60+
println!("Listing pools");
5761
let pools_list = ceph_helpers::rados_pools(cluster).unwrap();
58-
println!("{:?}", pools_list);
62+
for pool in pools_list{
63+
println!("pool: {}", pool);
64+
}
5965

66+
println!("Deleting pool: {}", pool_name);
6067
ceph_helpers::rados_delete_pool(cluster, pool_name).unwrap();
6168

62-
let fsid = ceph_helpers::rados_fsid(cluster).unwrap();
63-
println!("rados_cluster_fsid {}", fsid);
69+
println!("Getting cluster fsid");
70+
let fsid = ceph_helpers::rados_fsid(cluster);
71+
println!("rados_cluster_fsid {:?}", fsid);
6472

6573
let cluster_stat = ceph_helpers::rados_stat_cluster(cluster).unwrap();
6674
println!("Cluster stat: {:?}", cluster_stat);
@@ -74,7 +82,7 @@ fn main() {
7482
// and `git_version`
7583
// will be called soon to replace the string parse.
7684
// Change to the real mon admin socket name
77-
let ceph_ver = ceph_helpers::ceph_version("/var/run/ceph/ceph-mon.ceph-vm1.asok");
85+
let ceph_ver = ceph_helpers::ceph_version("/var/run/ceph/ceph-mon.ip-172-31-31-247.asok");
7886
println!("Ceph Version - {:?}", ceph_ver);
7987
// Mon command to check the health. Same as `ceph -s`
8088
match ceph_helpers::ceph_mon_command(cluster, "prefix", "status", None) {
@@ -102,6 +110,7 @@ fn main() {
102110
// It's very long so it's commented out.
103111
// println!("{}", ceph_helpers::ceph_commands(cluster, None).unwrap().pretty());
104112
unsafe {
113+
println!("Getting rados instance id");
105114
let instance_id = ceph::rados_get_instance_id(cluster);
106115
println!("Instance ID: {}", instance_id);
107116
}

src/ceph.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,14 @@
1414
#![cfg(target_os = "linux")]
1515
#![allow(unused_imports)]
1616

17-
use std::error::Error as StdError;
18-
use std::ffi::{CStr, CString, IntoStringError, NulError};
17+
use std::ffi::{CStr, CString};
1918

20-
use std::io::{BufRead, Cursor, Error};
19+
use std::io::{BufRead, Cursor};
2120
use std::net::IpAddr;
22-
use std::iter::FromIterator;
23-
use std::{ptr, fmt, slice, str};
21+
use std::{ptr, str};
2422
use std::time::{Duration, SystemTime, UNIX_EPOCH};
2523

26-
use uuid::{ParseError, Uuid};
24+
use uuid::{Uuid};
2725
use byteorder::{LittleEndian, WriteBytesExt};
2826
use nom::{IResult, le_u32};
2927
use libc::*;
@@ -1557,22 +1555,18 @@ pub fn rados_fsid(cluster: rados_t) -> Result<Uuid, RadosError> {
15571555
return Err(RadosError::new("Rados not connected. Please initialize cluster".to_string()));
15581556
}
15591557
let mut fsid_buffer: Vec<u8> = Vec::with_capacity(37);
1560-
let fsid: Uuid;
15611558
unsafe {
15621559
let ret_code = rados_cluster_fsid(cluster, fsid_buffer.as_mut_ptr() as *mut c_char, fsid_buffer.capacity());
15631560
if ret_code < 0 {
15641561
return Err(RadosError::new(try!(get_error(ret_code))));
15651562
}
1566-
if ret_code > 0 {
1567-
// Length of buffer required for fsid
1568-
fsid_buffer.reserve(ret_code as usize);
1569-
rados_cluster_fsid(cluster, fsid_buffer.as_mut_ptr() as *mut c_char, fsid_buffer.capacity());
1570-
// Tell the Vec how much Ceph read into the buffer
1571-
fsid_buffer.set_len(ret_code as usize);
1572-
}
1563+
// Tell the Vec how much Ceph read into the buffer
1564+
fsid_buffer.set_len(ret_code as usize);
15731565
}
1574-
fsid = try!(Uuid::from_bytes(&fsid_buffer));
1575-
Ok(fsid)
1566+
//Ceph actually returns the fsid as a uuid string
1567+
let fsid_str = String::from_utf8(fsid_buffer)?;
1568+
// Parse into a UUID and return
1569+
Ok(fsid_str.parse()?)
15761570
}
15771571

15781572
/// Ping a monitor to assess liveness

0 commit comments

Comments
 (0)