Skip to content

Commit 86cfdde

Browse files
committed
Add blockdev object paths when devices added to pool
Signed-off-by: mulhern <amulhern@redhat.com>
1 parent b09a385 commit 86cfdde

File tree

2 files changed

+121
-94
lines changed

2 files changed

+121
-94
lines changed

src/dbus/pool/pool_3_0/methods.rs

Lines changed: 86 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use devicemapper::Bytes;
1515

1616
use crate::{
1717
dbus::{
18+
blockdev::register_blockdev,
1819
consts::OK_STRING,
1920
filesystem::{register_filesystem, unregister_filesystem},
2021
manager::Manager,
@@ -297,7 +298,7 @@ pub async fn add_data_devs_method<'a>(
297298
engine: &Arc<dyn Engine>,
298299
connection: &Arc<Connection>,
299300
manager: &Lockable<Arc<RwLock<Manager>>>,
300-
_counter: &Arc<AtomicU64>,
301+
counter: &Arc<AtomicU64>,
301302
pool_uuid: PoolUuid,
302303
devices: Vec<PathBuf>,
303304
) -> ((bool, Vec<ObjectPath<'a>>), u16, String) {
@@ -329,30 +330,36 @@ pub async fn add_data_devs_method<'a>(
329330
})
330331
.await
331332
{
332-
Ok(Ok((action, diff))) => {
333-
match action.changed() {
334-
Some(_) => {
335-
if let Some(d) = diff {
336-
send_pool_foreground_signals(connection, manager, pool_uuid, d).await;
337-
}
338-
// TODO: Register blockdevs here.
339-
(
340-
// TODO: Change to blockdev object paths.
341-
default_return,
342-
DbusErrorEnum::OK as u16,
343-
OK_STRING.to_string(),
344-
)
333+
Ok(Ok((action, diff))) => match action.changed() {
334+
Some(bd_uuids) => {
335+
if let Some(d) = diff {
336+
send_pool_foreground_signals(connection, manager, pool_uuid, d).await;
345337
}
346-
None => {
347-
(
348-
// TODO: Change to blockdev object paths.
349-
default_return,
350-
DbusErrorEnum::OK as u16,
351-
OK_STRING.to_string(),
338+
let mut bd_paths = Vec::new();
339+
for dev_uuid in bd_uuids {
340+
match register_blockdev(
341+
engine, connection, manager, counter, pool_uuid, dev_uuid,
352342
)
343+
.await
344+
{
345+
Ok(op) => bd_paths.push(op),
346+
Err(_) => {
347+
warn!("Unable to register object path for blockdev with UUID {dev_uuid} belonging to pool {pool_uuid} on the D-Bus");
348+
}
349+
}
353350
}
351+
(
352+
(true, bd_paths),
353+
DbusErrorEnum::OK as u16,
354+
OK_STRING.to_string(),
355+
)
354356
}
355-
}
357+
None => (
358+
default_return,
359+
DbusErrorEnum::OK as u16,
360+
OK_STRING.to_string(),
361+
),
362+
},
356363
Ok(Err(e)) => {
357364
let (rc, rs) = engine_to_dbus_err_tuple(&e);
358365
(default_return, rc, rs)
@@ -368,7 +375,7 @@ pub async fn init_cache_method<'a>(
368375
engine: &Arc<dyn Engine>,
369376
connection: &Arc<Connection>,
370377
manager: &Lockable<Arc<RwLock<Manager>>>,
371-
_counter: &Arc<AtomicU64>,
378+
counter: &Arc<AtomicU64>,
372379
pool_uuid: PoolUuid,
373380
devices: Vec<PathBuf>,
374381
) -> ((bool, Vec<ObjectPath<'a>>), u16, String) {
@@ -398,35 +405,41 @@ pub async fn init_cache_method<'a>(
398405
})
399406
.await
400407
{
401-
Ok(Ok(action)) => {
402-
match action.changed() {
403-
Some(_) => {
404-
match manager.read().await.pool_get_path(&pool_uuid) {
405-
Some(p) => {
406-
send_has_cache_signal(connection, p).await;
407-
}
408-
None => {
409-
warn!("No object path associated with pool UUID {pool_uuid}; failed to send pool has cache change signals");
410-
}
411-
};
412-
// TODO: Register blockdevs here.
413-
(
414-
// TODO: Change to blockdev object paths.
415-
default_return,
416-
DbusErrorEnum::OK as u16,
417-
OK_STRING.to_string(),
418-
)
419-
}
420-
None => {
421-
(
422-
// TODO: Change to blockdev object paths.
423-
default_return,
424-
DbusErrorEnum::OK as u16,
425-
OK_STRING.to_string(),
408+
Ok(Ok(action)) => match action.changed() {
409+
Some(bd_uuids) => {
410+
match manager.read().await.pool_get_path(&pool_uuid) {
411+
Some(p) => {
412+
send_has_cache_signal(connection, p).await;
413+
}
414+
None => {
415+
warn!("No object path associated with pool UUID {pool_uuid}; failed to send pool has cache change signals");
416+
}
417+
};
418+
let mut bd_paths = Vec::new();
419+
for dev_uuid in bd_uuids {
420+
match register_blockdev(
421+
engine, connection, manager, counter, pool_uuid, dev_uuid,
426422
)
423+
.await
424+
{
425+
Ok(op) => bd_paths.push(op),
426+
Err(_) => {
427+
warn!("Unable to register object path for blockdev with UUID {dev_uuid} belonging to pool {pool_uuid} on the D-Bus");
428+
}
429+
}
427430
}
431+
(
432+
(true, bd_paths),
433+
DbusErrorEnum::OK as u16,
434+
OK_STRING.to_string(),
435+
)
428436
}
429-
}
437+
None => (
438+
default_return,
439+
DbusErrorEnum::OK as u16,
440+
OK_STRING.to_string(),
441+
),
442+
},
430443
Ok(Err(e)) => {
431444
let (rc, rs) = engine_to_dbus_err_tuple(&e);
432445
(default_return, rc, rs)
@@ -442,7 +455,7 @@ pub async fn add_cache_devs_method<'a>(
442455
engine: &Arc<dyn Engine>,
443456
connection: &Arc<Connection>,
444457
manager: &Lockable<Arc<RwLock<Manager>>>,
445-
_counter: &Arc<AtomicU64>,
458+
counter: &Arc<AtomicU64>,
446459
pool_uuid: PoolUuid,
447460
devices: Vec<PathBuf>,
448461
) -> ((bool, Vec<ObjectPath<'a>>), u16, String) {
@@ -473,27 +486,33 @@ pub async fn add_cache_devs_method<'a>(
473486
})
474487
.await
475488
{
476-
Ok(Ok(action)) => {
477-
match action.changed() {
478-
Some(_) => {
479-
// TODO: Register blockdevs here.
480-
(
481-
// TODO: Change to blockdev object paths.
482-
default_return,
483-
DbusErrorEnum::OK as u16,
484-
OK_STRING.to_string(),
485-
)
486-
}
487-
None => {
488-
(
489-
// TODO: Change to blockdev object paths.
490-
default_return,
491-
DbusErrorEnum::OK as u16,
492-
OK_STRING.to_string(),
489+
Ok(Ok(action)) => match action.changed() {
490+
Some(bd_uuids) => {
491+
let mut bd_paths = Vec::new();
492+
for dev_uuid in bd_uuids {
493+
match register_blockdev(
494+
engine, connection, manager, counter, pool_uuid, dev_uuid,
493495
)
496+
.await
497+
{
498+
Ok(op) => bd_paths.push(op),
499+
Err(_) => {
500+
warn!("Unable to register object path for blockdev with UUID {dev_uuid} belonging to pool {pool_uuid} on the D-Bus");
501+
}
502+
}
494503
}
504+
(
505+
(true, bd_paths),
506+
DbusErrorEnum::OK as u16,
507+
OK_STRING.to_string(),
508+
)
495509
}
496-
}
510+
None => (
511+
default_return,
512+
DbusErrorEnum::OK as u16,
513+
OK_STRING.to_string(),
514+
),
515+
},
497516
Ok(Err(e)) => {
498517
let (rc, rs) = engine_to_dbus_err_tuple(&e);
499518
(default_return, rc, rs)

src/dbus/pool/pool_3_5/methods.rs

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use zbus::{zvariant::ObjectPath, Connection};
1212

1313
use crate::{
1414
dbus::{
15+
blockdev::register_blockdev,
1516
consts::OK_STRING,
1617
manager::Manager,
1718
types::DbusErrorEnum,
@@ -25,7 +26,7 @@ pub async fn init_cache_method<'a>(
2526
engine: &Arc<dyn Engine>,
2627
connection: &Arc<Connection>,
2728
manager: &Lockable<Arc<RwLock<Manager>>>,
28-
_counter: &Arc<AtomicU64>,
29+
counter: &Arc<AtomicU64>,
2930
pool_uuid: PoolUuid,
3031
devices: Vec<PathBuf>,
3132
) -> ((bool, Vec<ObjectPath<'a>>), u16, String) {
@@ -55,35 +56,42 @@ pub async fn init_cache_method<'a>(
5556
})
5657
.await
5758
{
58-
Ok(Ok(action)) => {
59-
match action.changed() {
60-
Some(_) => {
61-
match manager.read().await.pool_get_path(&pool_uuid) {
62-
Some(p) => {
63-
send_has_cache_signal(connection, p).await;
64-
}
65-
None => {
66-
warn!("No object path associated with pool UUID {pool_uuid}; failed to send pool has cache change signals");
67-
}
68-
};
69-
// TODO: Register blockdevs here.
70-
(
71-
// TODO: Change to blockdev object paths.
72-
default_return,
73-
DbusErrorEnum::OK as u16,
74-
OK_STRING.to_string(),
75-
)
76-
}
77-
None => {
78-
(
79-
// TODO: Change to blockdev object paths.
80-
default_return,
81-
DbusErrorEnum::OK as u16,
82-
OK_STRING.to_string(),
59+
Ok(Ok(action)) => match action.changed() {
60+
Some(bd_uuids) => {
61+
match manager.read().await.pool_get_path(&pool_uuid) {
62+
Some(p) => {
63+
send_has_cache_signal(connection, p).await;
64+
}
65+
None => {
66+
warn!("No object path associated with pool UUID {pool_uuid}; failed to send pool has cache change signals");
67+
}
68+
};
69+
70+
let mut bd_paths = Vec::new();
71+
for dev_uuid in bd_uuids {
72+
match register_blockdev(
73+
engine, connection, manager, counter, pool_uuid, dev_uuid,
8374
)
75+
.await
76+
{
77+
Ok(op) => bd_paths.push(op),
78+
Err(_) => {
79+
warn!("Unable to register object path for blockdev with UUID {dev_uuid} belonging to pool {pool_uuid} on the D-Bus");
80+
}
81+
}
8482
}
83+
(
84+
(true, bd_paths),
85+
DbusErrorEnum::OK as u16,
86+
OK_STRING.to_string(),
87+
)
8588
}
86-
}
89+
None => (
90+
default_return,
91+
DbusErrorEnum::OK as u16,
92+
OK_STRING.to_string(),
93+
),
94+
},
8795
Ok(Err(e)) => {
8896
let (rc, rs) = engine_to_dbus_err_tuple(&e);
8997
(default_return, rc, rs)

0 commit comments

Comments
 (0)