Skip to content

Commit 5417386

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 571b059 commit 5417386

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
@@ -719,8 +719,7 @@ impl CacheDev {
719719

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

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
@@ -387,8 +387,7 @@ impl ThinDev {
387387

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

394393
/// 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
@@ -553,8 +553,7 @@ impl ThinPoolDev {
553553
/// Get the current status of the thinpool.
554554
/// Returns an error if there was an error getting the status value.
555555
pub fn status(&self, dm: &DM) -> DmResult<ThinPoolStatus> {
556-
let (_, status) = dm.table_status(&DevId::Name(self.name()), &DmOptions::new())?;
557-
get_status(&status)?.parse()
556+
status!(self, dm)
558557
}
559558

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

0 commit comments

Comments
 (0)