Skip to content

Commit 3b6873f

Browse files
committed
Get the pool object path using a shared Manager object
Signed-off-by: mulhern <[email protected]>
1 parent 925d235 commit 3b6873f

File tree

12 files changed

+244
-88
lines changed

12 files changed

+244
-88
lines changed

src/dbus/blockdev/blockdev_3_0/mod.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@
44

55
use std::sync::Arc;
66

7-
use zbus::{fdo::Error, interface, zvariant::ObjectPath, Connection};
7+
use tokio::sync::RwLock;
8+
use zbus::{
9+
fdo::Error,
10+
interface,
11+
zvariant::{ObjectPath, OwnedObjectPath},
12+
Connection,
13+
};
814

915
use crate::{
10-
dbus::blockdev::shared::blockdev_prop,
11-
engine::{DevUuid, Engine, PoolUuid},
16+
dbus::{blockdev::shared::blockdev_prop, manager::Manager},
17+
engine::{DevUuid, Engine, Lockable, PoolUuid},
1218
stratis::StratisResult,
1319
};
1420

@@ -23,14 +29,21 @@ pub use props::{
2329

2430
pub struct BlockdevR0 {
2531
engine: Arc<dyn Engine>,
32+
manager: Lockable<Arc<RwLock<Manager>>>,
2633
parent_uuid: PoolUuid,
2734
uuid: DevUuid,
2835
}
2936

3037
impl BlockdevR0 {
31-
fn new(engine: Arc<dyn Engine>, parent_uuid: PoolUuid, uuid: DevUuid) -> Self {
38+
fn new(
39+
engine: Arc<dyn Engine>,
40+
manager: Lockable<Arc<RwLock<Manager>>>,
41+
parent_uuid: PoolUuid,
42+
uuid: DevUuid,
43+
) -> Self {
3244
BlockdevR0 {
3345
engine,
46+
manager,
3447
parent_uuid,
3548
uuid,
3649
}
@@ -39,11 +52,12 @@ impl BlockdevR0 {
3952
pub async fn register(
4053
engine: Arc<dyn Engine>,
4154
connection: &Arc<Connection>,
55+
manager: &Lockable<Arc<RwLock<Manager>>>,
4256
path: ObjectPath<'_>,
4357
parent_uuid: PoolUuid,
4458
uuid: DevUuid,
4559
) -> StratisResult<()> {
46-
let blockdev = Self::new(engine, parent_uuid, uuid);
60+
let blockdev = Self::new(engine, manager.clone(), parent_uuid, uuid);
4761

4862
connection.object_server().at(path, blockdev).await?;
4963
Ok(())
@@ -90,8 +104,8 @@ impl BlockdevR0 {
90104

91105
#[zbus(property(emits_changed_signal = "const"))]
92106
#[allow(non_snake_case)]
93-
async fn Pool(&self) -> Result<ObjectPath<'_>, Error> {
94-
blockdev_prop(&self.engine, self.parent_uuid, self.uuid, pool_prop).await
107+
async fn Pool(&self) -> Result<OwnedObjectPath, Error> {
108+
pool_prop(self.manager.read().await, self.parent_uuid)
95109
}
96110

97111
#[zbus(property(emits_changed_signal = "const"))]

src/dbus/blockdev/blockdev_3_0/props.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
// License, v. 2.0. If a copy of the MPL was not distributed with this
33
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
44

5-
use zbus::zvariant::ObjectPath;
5+
use tokio::sync::OwnedRwLockReadGuard;
6+
use zbus::{fdo::Error, zvariant::OwnedObjectPath};
67

78
use crate::{
8-
dbus::util::option_to_tuple,
9-
engine::{BlockDev, BlockDevTier, DevUuid},
9+
dbus::{util::option_to_tuple, Manager},
10+
engine::{BlockDev, BlockDevTier, DevUuid, PoolUuid, SharedGuard},
1011
};
1112

1213
pub fn devnode_prop(_: BlockDevTier, _: DevUuid, dev: &dyn BlockDev) -> String {
@@ -25,9 +26,18 @@ pub fn physical_path_prop(_: BlockDevTier, _: DevUuid, dev: &dyn BlockDev) -> St
2526
dev.devnode().display().to_string()
2627
}
2728

28-
pub fn pool_prop<'a>(_: BlockDevTier, _: DevUuid, _dev: &dyn BlockDev) -> ObjectPath<'a> {
29-
// FIXME: I do not know how to get pool object path from pool UUID.
30-
ObjectPath::default()
29+
pub fn pool_prop(
30+
guard: SharedGuard<OwnedRwLockReadGuard<Manager>>,
31+
pool_uuid: PoolUuid,
32+
) -> Result<OwnedObjectPath, Error> {
33+
guard
34+
.pool_get_path(&pool_uuid)
35+
.ok_or_else(|| {
36+
Error::Failed(format!(
37+
"No object path associated with pool UUID {pool_uuid}"
38+
))
39+
})
40+
.cloned()
3141
}
3242

3343
pub fn total_physical_size_prop(_: BlockDevTier, _: DevUuid, dev: &dyn BlockDev) -> String {

src/dbus/blockdev/blockdev_3_1/mod.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@
44

55
use std::sync::Arc;
66

7-
use zbus::{fdo::Error, interface, zvariant::ObjectPath, Connection};
7+
use tokio::sync::RwLock;
8+
use zbus::{
9+
fdo::Error,
10+
interface,
11+
zvariant::{ObjectPath, OwnedObjectPath},
12+
Connection,
13+
};
814

915
use crate::{
10-
dbus::blockdev::shared::blockdev_prop,
11-
engine::{DevUuid, Engine, PoolUuid},
16+
dbus::{blockdev::shared::blockdev_prop, manager::Manager},
17+
engine::{DevUuid, Engine, Lockable, PoolUuid},
1218
stratis::StratisResult,
1319
};
1420

@@ -19,14 +25,21 @@ use crate::dbus::blockdev::blockdev_3_0::{
1925

2026
pub struct BlockdevR1 {
2127
engine: Arc<dyn Engine>,
28+
manager: Lockable<Arc<RwLock<Manager>>>,
2229
parent_uuid: PoolUuid,
2330
uuid: DevUuid,
2431
}
2532

2633
impl BlockdevR1 {
27-
fn new(engine: Arc<dyn Engine>, parent_uuid: PoolUuid, uuid: DevUuid) -> Self {
34+
fn new(
35+
engine: Arc<dyn Engine>,
36+
manager: Lockable<Arc<RwLock<Manager>>>,
37+
parent_uuid: PoolUuid,
38+
uuid: DevUuid,
39+
) -> Self {
2840
BlockdevR1 {
2941
engine,
42+
manager,
3043
parent_uuid,
3144
uuid,
3245
}
@@ -35,11 +48,12 @@ impl BlockdevR1 {
3548
pub async fn register(
3649
engine: Arc<dyn Engine>,
3750
connection: &Arc<Connection>,
51+
manager: &Lockable<Arc<RwLock<Manager>>>,
3852
path: ObjectPath<'_>,
3953
parent_uuid: PoolUuid,
4054
uuid: DevUuid,
4155
) -> StratisResult<()> {
42-
let blockdev = Self::new(engine, parent_uuid, uuid);
56+
let blockdev = Self::new(engine, manager.clone(), parent_uuid, uuid);
4357

4458
connection.object_server().at(path, blockdev).await?;
4559
Ok(())
@@ -86,8 +100,8 @@ impl BlockdevR1 {
86100

87101
#[zbus(property(emits_changed_signal = "const"))]
88102
#[allow(non_snake_case)]
89-
async fn Pool(&self) -> Result<ObjectPath<'_>, Error> {
90-
blockdev_prop(&self.engine, self.parent_uuid, self.uuid, pool_prop).await
103+
async fn Pool(&self) -> Result<OwnedObjectPath, Error> {
104+
pool_prop(self.manager.read().await, self.parent_uuid)
91105
}
92106

93107
#[zbus(property(emits_changed_signal = "const"))]

src/dbus/blockdev/blockdev_3_2/mod.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@
44

55
use std::sync::Arc;
66

7-
use zbus::{fdo::Error, interface, zvariant::ObjectPath, Connection};
7+
use tokio::sync::RwLock;
8+
use zbus::{
9+
fdo::Error,
10+
interface,
11+
zvariant::{ObjectPath, OwnedObjectPath},
12+
Connection,
13+
};
814

915
use crate::{
10-
dbus::blockdev::shared::blockdev_prop,
11-
engine::{DevUuid, Engine, PoolUuid},
16+
dbus::{blockdev::shared::blockdev_prop, manager::Manager},
17+
engine::{DevUuid, Engine, Lockable, PoolUuid},
1218
stratis::StratisResult,
1319
};
1420

@@ -19,14 +25,21 @@ use crate::dbus::blockdev::blockdev_3_0::{
1925

2026
pub struct BlockdevR2 {
2127
engine: Arc<dyn Engine>,
28+
manager: Lockable<Arc<RwLock<Manager>>>,
2229
parent_uuid: PoolUuid,
2330
uuid: DevUuid,
2431
}
2532

2633
impl BlockdevR2 {
27-
fn new(engine: Arc<dyn Engine>, parent_uuid: PoolUuid, uuid: DevUuid) -> Self {
34+
fn new(
35+
engine: Arc<dyn Engine>,
36+
manager: Lockable<Arc<RwLock<Manager>>>,
37+
parent_uuid: PoolUuid,
38+
uuid: DevUuid,
39+
) -> Self {
2840
BlockdevR2 {
2941
engine,
42+
manager,
3043
parent_uuid,
3144
uuid,
3245
}
@@ -35,11 +48,12 @@ impl BlockdevR2 {
3548
pub async fn register(
3649
engine: Arc<dyn Engine>,
3750
connection: &Arc<Connection>,
51+
manager: &Lockable<Arc<RwLock<Manager>>>,
3852
path: ObjectPath<'_>,
3953
parent_uuid: PoolUuid,
4054
uuid: DevUuid,
4155
) -> StratisResult<()> {
42-
let blockdev = Self::new(engine, parent_uuid, uuid);
56+
let blockdev = Self::new(engine, manager.clone(), parent_uuid, uuid);
4357

4458
connection.object_server().at(path, blockdev).await?;
4559
Ok(())
@@ -86,8 +100,8 @@ impl BlockdevR2 {
86100

87101
#[zbus(property(emits_changed_signal = "const"))]
88102
#[allow(non_snake_case)]
89-
async fn Pool(&self) -> Result<ObjectPath<'_>, Error> {
90-
blockdev_prop(&self.engine, self.parent_uuid, self.uuid, pool_prop).await
103+
async fn Pool(&self) -> Result<OwnedObjectPath, Error> {
104+
pool_prop(self.manager.read().await, self.parent_uuid)
91105
}
92106

93107
#[zbus(property(emits_changed_signal = "const"))]

src/dbus/blockdev/blockdev_3_3/mod.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@
44

55
use std::sync::Arc;
66

7-
use zbus::{fdo::Error, interface, zvariant::ObjectPath, Connection};
7+
use tokio::sync::RwLock;
8+
use zbus::{
9+
fdo::Error,
10+
interface,
11+
zvariant::{ObjectPath, OwnedObjectPath},
12+
Connection,
13+
};
814

915
use crate::{
10-
dbus::blockdev::shared::blockdev_prop,
11-
engine::{DevUuid, Engine, PoolUuid},
16+
dbus::{blockdev::shared::blockdev_prop, manager::Manager},
17+
engine::{DevUuid, Engine, Lockable, PoolUuid},
1218
stratis::StratisResult,
1319
};
1420

@@ -23,14 +29,21 @@ pub use props::new_physical_size_prop;
2329

2430
pub struct BlockdevR3 {
2531
engine: Arc<dyn Engine>,
32+
manager: Lockable<Arc<RwLock<Manager>>>,
2633
parent_uuid: PoolUuid,
2734
uuid: DevUuid,
2835
}
2936

3037
impl BlockdevR3 {
31-
fn new(engine: Arc<dyn Engine>, parent_uuid: PoolUuid, uuid: DevUuid) -> Self {
38+
fn new(
39+
engine: Arc<dyn Engine>,
40+
manager: Lockable<Arc<RwLock<Manager>>>,
41+
parent_uuid: PoolUuid,
42+
uuid: DevUuid,
43+
) -> Self {
3244
BlockdevR3 {
3345
engine,
46+
manager,
3447
parent_uuid,
3548
uuid,
3649
}
@@ -39,11 +52,12 @@ impl BlockdevR3 {
3952
pub async fn register(
4053
engine: Arc<dyn Engine>,
4154
connection: &Arc<Connection>,
55+
manager: &Lockable<Arc<RwLock<Manager>>>,
4256
path: ObjectPath<'_>,
4357
parent_uuid: PoolUuid,
4458
uuid: DevUuid,
4559
) -> StratisResult<()> {
46-
let blockdev = Self::new(engine, parent_uuid, uuid);
60+
let blockdev = Self::new(engine, manager.clone(), parent_uuid, uuid);
4761

4862
connection.object_server().at(path, blockdev).await?;
4963
Ok(())
@@ -100,8 +114,8 @@ impl BlockdevR3 {
100114

101115
#[zbus(property(emits_changed_signal = "const"))]
102116
#[allow(non_snake_case)]
103-
async fn Pool(&self) -> Result<ObjectPath<'_>, Error> {
104-
blockdev_prop(&self.engine, self.parent_uuid, self.uuid, pool_prop).await
117+
async fn Pool(&self) -> Result<OwnedObjectPath, Error> {
118+
pool_prop(self.manager.read().await, self.parent_uuid)
105119
}
106120

107121
#[zbus(property(emits_changed_signal = "const"))]

src/dbus/blockdev/blockdev_3_4/mod.rs

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,43 @@
44

55
use std::sync::Arc;
66

7-
use zbus::{fdo::Error, interface, zvariant::ObjectPath, Connection};
8-
9-
use crate::{
10-
dbus::blockdev::shared::blockdev_prop,
11-
engine::{DevUuid, Engine, PoolUuid},
12-
stratis::StratisResult,
7+
use tokio::sync::RwLock;
8+
use zbus::{
9+
fdo::Error,
10+
interface,
11+
zvariant::{ObjectPath, OwnedObjectPath},
12+
Connection,
1313
};
1414

1515
use crate::dbus::blockdev::blockdev_3_0::{
1616
devnode_prop, hardware_info_prop, init_time_prop, physical_path_prop, pool_prop, tier_prop,
1717
total_physical_size_prop, user_info_prop,
1818
};
19+
use crate::{
20+
dbus::{blockdev::shared::blockdev_prop, manager::Manager},
21+
engine::{DevUuid, Engine, Lockable, PoolUuid},
22+
stratis::StratisResult,
23+
};
1924

2025
use crate::dbus::blockdev::blockdev_3_3::new_physical_size_prop;
2126

2227
pub struct BlockdevR4 {
2328
engine: Arc<dyn Engine>,
29+
manager: Lockable<Arc<RwLock<Manager>>>,
2430
parent_uuid: PoolUuid,
2531
uuid: DevUuid,
2632
}
2733

2834
impl BlockdevR4 {
29-
fn new(engine: Arc<dyn Engine>, parent_uuid: PoolUuid, uuid: DevUuid) -> Self {
35+
fn new(
36+
engine: Arc<dyn Engine>,
37+
manager: Lockable<Arc<RwLock<Manager>>>,
38+
parent_uuid: PoolUuid,
39+
uuid: DevUuid,
40+
) -> Self {
3041
BlockdevR4 {
3142
engine,
43+
manager,
3244
parent_uuid,
3345
uuid,
3446
}
@@ -37,11 +49,12 @@ impl BlockdevR4 {
3749
pub async fn register(
3850
engine: Arc<dyn Engine>,
3951
connection: &Arc<Connection>,
52+
manager: &Lockable<Arc<RwLock<Manager>>>,
4053
path: ObjectPath<'_>,
4154
parent_uuid: PoolUuid,
4255
uuid: DevUuid,
4356
) -> StratisResult<()> {
44-
let blockdev = Self::new(engine, parent_uuid, uuid);
57+
let blockdev = Self::new(engine, manager.clone(), parent_uuid, uuid);
4558

4659
connection.object_server().at(path, blockdev).await?;
4760
Ok(())
@@ -98,8 +111,8 @@ impl BlockdevR4 {
98111

99112
#[zbus(property(emits_changed_signal = "const"))]
100113
#[allow(non_snake_case)]
101-
async fn Pool(&self) -> Result<ObjectPath<'_>, Error> {
102-
blockdev_prop(&self.engine, self.parent_uuid, self.uuid, pool_prop).await
114+
async fn Pool(&self) -> Result<OwnedObjectPath, Error> {
115+
pool_prop(self.manager.read().await, self.parent_uuid)
103116
}
104117

105118
#[zbus(property(emits_changed_signal = "const"))]

0 commit comments

Comments
 (0)