Skip to content

Commit 05e2ae3

Browse files
committed
Use a macro to get the status values
The bodies of the status methods are identical, so might as well. Signed-off-by: mulhern <amulhern@redhat.com>
1 parent c8d07ff commit 05e2ae3

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

src/cachedev.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -714,8 +714,7 @@ impl CacheDev {
714714

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

src/shared_macros.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,13 @@ macro_rules! table {
4747
&$s.table
4848
};
4949
}
50+
51+
macro_rules! status {
52+
($s:ident, $dm:ident) => {
53+
get_status(
54+
&$dm.table_status(&DevId::Name($s.name()), &DmOptions::new())?
55+
.1,
56+
)?
57+
.parse()
58+
};
59+
}

src/thindev.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,7 @@ impl ThinDev {
381381

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

388387
/// Set the table for the thin device's target

src/thinpooldev.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,8 +548,7 @@ impl ThinPoolDev {
548548
/// Get the current status of the thinpool.
549549
/// Returns an error if there was an error getting the status value.
550550
pub fn status(&self, dm: &DM) -> DmResult<ThinPoolStatus> {
551-
let (_, status) = dm.table_status(&DevId::Name(self.name()), &DmOptions::new())?;
552-
get_status(&status)?.parse()
551+
status!(self, dm)
553552
}
554553

555554
/// Set the table for the existing metadata device.

0 commit comments

Comments
 (0)