Skip to content

Commit

Permalink
Use a macro to get the status values
Browse files Browse the repository at this point in the history
The bodies of the status methods are identical, so might as well.

Signed-off-by: mulhern <[email protected]>
  • Loading branch information
mulkieran committed Mar 1, 2019
1 parent 6fdec98 commit feea886
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/cachedev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -714,8 +714,7 @@ impl CacheDev {

/// Get the current status of the cache device.
pub fn status(&self, dm: &DM) -> DmResult<CacheDevStatus> {
let (_, status) = dm.table_status(&DevId::Name(self.name()), &DmOptions::new())?;
get_status(&status)?.parse()
status!(self, dm)
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/shared_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,13 @@ macro_rules! table {
&$s.table
};
}

macro_rules! status {
($s:ident, $dm:ident) => {
get_status(
&$dm.table_status(&DevId::Name($s.name()), &DmOptions::new())?
.1,
)?
.parse()
};
}
3 changes: 1 addition & 2 deletions src/thindev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,7 @@ impl ThinDev {

/// Get the current status of the thin device.
pub fn status(&self, dm: &DM) -> DmResult<ThinStatus> {
let (_, table) = dm.table_status(&DevId::Name(self.name()), &DmOptions::new())?;
get_status(&table)?.parse()
status!(self, dm)
}

/// Set the table for the thin device's target
Expand Down
3 changes: 1 addition & 2 deletions src/thinpooldev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,7 @@ impl ThinPoolDev {
/// Get the current status of the thinpool.
/// Returns an error if there was an error getting the status value.
pub fn status(&self, dm: &DM) -> DmResult<ThinPoolStatus> {
let (_, status) = dm.table_status(&DevId::Name(self.name()), &DmOptions::new())?;
get_status(&status)?.parse()
status!(self, dm)
}

/// Set the table for the existing metadata device.
Expand Down

0 comments on commit feea886

Please sign in to comment.