stratisd/dbus_api/filesystem/filesystem_3_6/
props.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
5use dbus::arg::{Iter, IterAppend};
6use dbus_tree::{MTSync, MethodErr, PropInfo};
7
8use devicemapper::Bytes;
9
10use crate::{
11    dbus_api::{
12        consts,
13        filesystem::shared::{self, get_filesystem_property},
14        types::TData,
15        util::tuple_to_option,
16    },
17    engine::PropChangeAction,
18};
19
20pub fn get_fs_size_limit(
21    i: &mut IterAppend<'_>,
22    p: &PropInfo<'_, MTSync<TData>, TData>,
23) -> Result<(), MethodErr> {
24    get_filesystem_property(i, p, |(_, _, f)| Ok(shared::fs_size_limit_prop(f)))
25}
26
27pub fn set_fs_size_limit(
28    i: &mut Iter<'_>,
29    p: &PropInfo<'_, MTSync<TData>, TData>,
30) -> Result<(), MethodErr> {
31    let size_limit_opt: (bool, &str) = i.get().ok_or_else(|| {
32        MethodErr::failed("New filesystem limit required as argument to increase it")
33    })?;
34    let size_limit_str = tuple_to_option(size_limit_opt);
35    let size_limit = match size_limit_str {
36        Some(lim) => Some(Bytes(lim.parse::<u128>().map_err(|e| {
37            MethodErr::failed(&format!("Failed to parse {lim} as unsigned integer: {e}"))
38        })?)),
39        None => None,
40    };
41
42    let res = shared::set_fs_property_to_display(
43        p,
44        consts::FILESYSTEM_SIZE_LIMIT_PROP,
45        |(_, uuid, p)| shared::set_fs_size_limit_prop(uuid, p, size_limit),
46    );
47    match res {
48        Ok(PropChangeAction::NewValue(v)) => {
49            p.tree
50                .get_data()
51                .push_fs_size_limit_change(p.path.get_name(), v);
52            Ok(())
53        }
54        Ok(PropChangeAction::Identity) => Ok(()),
55        Err(e) => Err(e),
56    }
57}