-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3516 from mulkieran/issue_stratisd_3515
Add origin field to StratFilesystem
- Loading branch information
Showing
28 changed files
with
441 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
use dbus_tree::{Access, EmitsChangedSignal, Factory, MTSync, Property}; | ||
|
||
use crate::dbus_api::{consts, filesystem::filesystem_3_7::props::get_fs_origin, types::TData}; | ||
|
||
pub fn origin_property(f: &Factory<MTSync<TData>, TData>) -> Property<MTSync<TData>, TData> { | ||
f.property::<(bool, String), _>(consts::FILESYSTEM_ORIGIN_PROP, ()) | ||
.access(Access::Read) | ||
.emits_changed(EmitsChangedSignal::True) | ||
.on_get(get_fs_origin) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
mod api; | ||
mod props; | ||
|
||
pub use api::origin_property; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
use dbus::arg::IterAppend; | ||
use dbus_tree::{MTSync, MethodErr, PropInfo}; | ||
|
||
use crate::dbus_api::{ | ||
filesystem::shared::{self, get_filesystem_property}, | ||
types::TData, | ||
}; | ||
|
||
pub fn get_fs_origin( | ||
i: &mut IterAppend<'_>, | ||
p: &PropInfo<'_, MTSync<TData>, TData>, | ||
) -> Result<(), MethodErr> { | ||
get_filesystem_property(i, p, |(_, _, f)| Ok(shared::fs_origin_prop(f))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
use dbus_tree::{Factory, MTSync, Method}; | ||
|
||
use crate::dbus_api::{pool::pool_3_7::methods::destroy_filesystems, types::TData}; | ||
|
||
pub fn destroy_filesystems_method( | ||
f: &Factory<MTSync<TData>, TData>, | ||
) -> Method<MTSync<TData>, TData> { | ||
f.method("DestroyFilesystems", (), destroy_filesystems) | ||
.in_arg(("filesystems", "ao")) | ||
// b: true if filesystems were destroyed | ||
// as: Array of UUIDs of destroyed filesystems | ||
// | ||
// Rust representation: (bool, Vec<String>) | ||
.out_arg(("results", "(bas)")) | ||
.out_arg(("return_code", "q")) | ||
.out_arg(("return_string", "s")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
use std::collections::HashMap; | ||
|
||
use dbus::{arg::Array, Message}; | ||
use dbus_tree::{MTSync, MethodInfo, MethodResult}; | ||
|
||
use crate::{ | ||
dbus_api::{ | ||
consts::filesystem_interface_list, | ||
types::{DbusErrorEnum, TData, OK_STRING}, | ||
util::{engine_to_dbus_err_tuple, get_next_arg}, | ||
}, | ||
engine::{EngineAction, FilesystemUuid, StratisUuid}, | ||
}; | ||
|
||
pub fn destroy_filesystems(m: &MethodInfo<'_, MTSync<TData>, TData>) -> MethodResult { | ||
let message: &Message = m.msg; | ||
let mut iter = message.iter_init(); | ||
|
||
let filesystems: Array<'_, dbus::Path<'static>, _> = get_next_arg(&mut iter, 0)?; | ||
|
||
let dbus_context = m.tree.get_data(); | ||
let object_path = m.path.get_name(); | ||
let return_message = message.method_return(); | ||
let default_return: (bool, Vec<String>) = (false, Vec::new()); | ||
|
||
let pool_path = m | ||
.tree | ||
.get(object_path) | ||
.expect("implicit argument must be in tree"); | ||
let pool_uuid = typed_uuid!( | ||
get_data!(pool_path; default_return; return_message).uuid; | ||
Pool; | ||
default_return; | ||
return_message | ||
); | ||
|
||
let mut guard = get_mut_pool!(dbus_context.engine; pool_uuid; default_return; return_message); | ||
let (pool_name, _, pool) = guard.as_mut_tuple(); | ||
|
||
let mut filesystem_map: HashMap<FilesystemUuid, dbus::Path<'static>> = HashMap::new(); | ||
for path in filesystems { | ||
if let Some((u, path)) = m.tree.get(&path).and_then(|op| { | ||
op.get_data() | ||
.as_ref() | ||
.map(|d| (&d.uuid, op.get_name().clone())) | ||
}) { | ||
let uuid = *typed_uuid!(u; Fs; default_return; return_message); | ||
filesystem_map.insert(uuid, path); | ||
} | ||
} | ||
|
||
let result = handle_action!( | ||
pool.destroy_filesystems( | ||
&pool_name, | ||
&filesystem_map.keys().cloned().collect::<Vec<_>>(), | ||
), | ||
dbus_context, | ||
pool_path.get_name() | ||
); | ||
let msg = match result { | ||
Ok(uuids) => { | ||
// Only get changed values here as non-existent filesystems will have been filtered out | ||
// before calling destroy_filesystems | ||
let uuid_vec: Vec<String> = | ||
if let Some((ref changed_uuids, ref updated_uuids)) = uuids.changed() { | ||
for uuid in changed_uuids { | ||
let op = filesystem_map | ||
.get(uuid) | ||
.expect("'uuids' is a subset of filesystem_map.keys()"); | ||
dbus_context.push_remove(op, filesystem_interface_list()); | ||
} | ||
|
||
for sn_op in m.tree.iter().filter(|op| { | ||
op.get_data() | ||
.as_ref() | ||
.map(|data| match data.uuid { | ||
StratisUuid::Fs(uuid) => updated_uuids.contains(&uuid), | ||
_ => false, | ||
}) | ||
.unwrap_or(false) | ||
}) { | ||
dbus_context.push_filesystem_origin_change(sn_op.get_name()); | ||
} | ||
|
||
changed_uuids | ||
.iter() | ||
.map(|uuid| uuid_to_string!(uuid)) | ||
.collect() | ||
} else { | ||
Vec::new() | ||
}; | ||
return_message.append3( | ||
(true, uuid_vec), | ||
DbusErrorEnum::OK as u16, | ||
OK_STRING.to_string(), | ||
) | ||
} | ||
Err(err) => { | ||
let (rc, rs) = engine_to_dbus_err_tuple(&err); | ||
return_message.append3(default_return, rc, rs) | ||
} | ||
}; | ||
Ok(vec![msg]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
mod api; | ||
mod methods; | ||
|
||
pub use api::destroy_filesystems_method; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.