Skip to content

Commit

Permalink
Add a fallback for osd id gathering
Browse files Browse the repository at this point in the history
  • Loading branch information
cholcombe973 committed Sep 20, 2017
1 parent 185faed commit 640847d
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/backend/ceph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,16 @@ impl CephBackend {
};
debug!("OSD mounted at: {:?}", mount_point);

let osd_id = get_osd_id(&mount_point, simulate)?;
let osd_id = match get_osd_id(&mount_point, simulate) {
Ok(osd_id) => osd_id,
Err(e) => {
error!(
"Failed to discover osd id: {:?}. Falling back on path name",
e
);
get_osd_id_from_path(&mount_point)?
}
};
debug!("Setting osd {} out", osd_id);
osd_out(self.cluster_handle, osd_id, simulate)?;
debug!("Removing osd {} from crush", osd_id);
Expand Down Expand Up @@ -357,6 +366,21 @@ fn osd_crush_add(
Ok(())
}

// A fallback function to get the osd id from the mount path. This isn't
// 100% accurate but it should be good enough for most cases unless the disk
// is mounted in the wrong location or is missing an osd id in the path name
fn get_osd_id_from_path(path: &Path) -> Result<u64, String> {
match path.file_name() {
Some(name) => {
let name_string = name.to_string_lossy().into_owned();
let parts: Vec<&str> = name_string.split("-").collect();
let id = u64::from_str(parts[1]).map_err(|e| e.to_string())?;
Ok(id)
}
None => Err(format!("Unable to get filename from {}", path.display())),
}
}

// Get an osd ID from the whoami file in the osd mount directory
fn get_osd_id(path: &Path, simulate: bool) -> Result<u64, String> {
let mut whoami_path = PathBuf::from(path);
Expand Down

0 comments on commit 640847d

Please sign in to comment.