Skip to content

Commit

Permalink
Merge pull request #3674 from mulkieran/destroy-filesystems-set
Browse files Browse the repository at this point in the history
Enforce set invariant in destroy_filesystems
  • Loading branch information
mulkieran authored Aug 15, 2024
2 parents eafccd0 + d4c4e7b commit a5cdc20
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/dbus_api/pool/pool_3_0/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// 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 std::collections::{HashMap, HashSet};

use dbus::{arg::Array, Message};
use dbus_tree::{MTSync, MethodInfo, MethodResult};
Expand Down Expand Up @@ -168,7 +168,7 @@ pub fn destroy_filesystems(m: &MethodInfo<'_, MTSync<TData>, TData>) -> MethodRe
let result = handle_action!(
pool.destroy_filesystems(
&pool_name,
&filesystem_map.keys().cloned().collect::<Vec<_>>(),
&filesystem_map.keys().cloned().collect::<HashSet<_>>(),
),
dbus_context,
pool_path.get_name()
Expand Down
4 changes: 2 additions & 2 deletions src/dbus_api/pool/pool_3_7/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// 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 std::collections::{HashMap, HashSet};

use dbus::{arg::Array, Message};
use dbus_tree::{MTSync, MethodInfo, MethodResult};
Expand Down Expand Up @@ -56,7 +56,7 @@ pub fn destroy_filesystems(m: &MethodInfo<'_, MTSync<TData>, TData>) -> MethodRe
let result = handle_action!(
pool.destroy_filesystems(
&pool_name,
&filesystem_map.keys().cloned().collect::<Vec<_>>(),
&filesystem_map.keys().cloned().collect::<HashSet<_>>(),
),
dbus_context,
pool_path.get_name()
Expand Down
2 changes: 1 addition & 1 deletion src/engine/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ pub trait Pool: Debug + Send + Sync {
fn destroy_filesystems(
&mut self,
pool_name: &str,
fs_uuids: &[FilesystemUuid],
fs_uuids: &HashSet<FilesystemUuid>,
) -> StratisResult<SetDeleteAction<FilesystemUuid, FilesystemUuid>>;

/// Rename filesystem
Expand Down
16 changes: 9 additions & 7 deletions src/engine/sim_engine/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ impl Pool for SimPool {
fn destroy_filesystems(
&mut self,
_pool_name: &str,
fs_uuids: &[FilesystemUuid],
fs_uuids: &HashSet<FilesystemUuid>,
) -> StratisResult<SetDeleteAction<FilesystemUuid, FilesystemUuid>> {
let mut removed = Vec::new();
for &uuid in fs_uuids {
Expand Down Expand Up @@ -909,7 +909,7 @@ mod tests {
.changed()
.unwrap();
let mut pool = test_async!(engine.get_mut_pool(PoolIdentifier::Uuid(uuid))).unwrap();
assert!(match pool.destroy_filesystems(pool_name, &[]) {
assert!(match pool.destroy_filesystems(pool_name, &HashSet::new()) {
Ok(uuids) => !uuids.is_changed(),
_ => false,
});
Expand All @@ -930,7 +930,7 @@ mod tests {
.unwrap();
let mut pool = test_async!(engine.get_mut_pool(PoolIdentifier::Uuid(uuid))).unwrap();
assert_matches!(
pool.destroy_filesystems(pool_name, &[FilesystemUuid::new_v4()]),
pool.destroy_filesystems(pool_name, &[FilesystemUuid::new_v4()].into()),
Ok(_)
);
}
Expand All @@ -955,10 +955,12 @@ mod tests {
.changed()
.unwrap();
let fs_uuid = fs_results[0].1;
assert!(match pool.destroy_filesystems(pool_name, &[fs_uuid]) {
Ok(filesystems) => filesystems == SetDeleteAction::new(vec![fs_uuid], vec![]),
_ => false,
});
assert!(
match pool.destroy_filesystems(pool_name, &[fs_uuid].into()) {
Ok(filesystems) => filesystems == SetDeleteAction::new(vec![fs_uuid], vec![]),
_ => false,
}
);
}

#[test]
Expand Down
10 changes: 4 additions & 6 deletions src/engine/strat_engine/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -953,20 +953,18 @@ mod test {
let mut pool = test_async!(engine.get_mut_pool(PoolIdentifier::Uuid(uuid1))).unwrap();
pool.destroy_filesystems(
name2,
fs_uuid1
&fs_uuid1
.into_iter()
.map(|(_, u, _)| u)
.collect::<Vec<_>>()
.as_slice(),
.collect::<HashSet<_>>(),
)
.unwrap();
pool.destroy_filesystems(
name2,
fs_uuid2
&fs_uuid2
.into_iter()
.map(|(_, u, _)| u)
.collect::<Vec<_>>()
.as_slice(),
.collect::<HashSet<_>>(),
)
.unwrap();
}
Expand Down
4 changes: 2 additions & 2 deletions src/engine/strat_engine/pool/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// 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::path::Path;
use std::{collections::HashSet, path::Path};

use serde_json::Value;

Expand Down Expand Up @@ -122,7 +122,7 @@ impl Pool for AnyPool {
fn destroy_filesystems(
&mut self,
pool_name: &str,
fs_uuids: &[FilesystemUuid],
fs_uuids: &HashSet<FilesystemUuid>,
) -> StratisResult<SetDeleteAction<FilesystemUuid, FilesystemUuid>> {
match self {
AnyPool::V1(p) => p.destroy_filesystems(pool_name, fs_uuids),
Expand Down
12 changes: 9 additions & 3 deletions src/engine/strat_engine/pool/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
// 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::{cmp::max, collections::HashMap, path::Path, vec::Vec};
use std::{
cmp::max,
collections::{HashMap, HashSet},
path::Path,
vec::Vec,
};

use chrono::{DateTime, Utc};
use serde_json::{Map, Value};
Expand Down Expand Up @@ -1016,7 +1021,7 @@ impl Pool for StratPool {
fn destroy_filesystems(
&mut self,
pool_name: &str,
fs_uuids: &[FilesystemUuid],
fs_uuids: &HashSet<FilesystemUuid>,
) -> StratisResult<SetDeleteAction<FilesystemUuid, FilesystemUuid>> {
let mut removed = Vec::new();
for &uuid in fs_uuids {
Expand Down Expand Up @@ -1696,7 +1701,8 @@ mod tests {
assert!(pool
.set_overprov_mode(&Name::new(pool_name.to_string()), false)
.is_err());
pool.destroy_filesystems(pool_name, &[fs_uuid]).unwrap();
pool.destroy_filesystems(pool_name, &[fs_uuid].into())
.unwrap();

pool.set_overprov_mode(&Name::new(pool_name.to_string()), false)
.unwrap();
Expand Down
11 changes: 8 additions & 3 deletions src/engine/strat_engine/pool/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
// 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, path::Path, vec::Vec};
use std::{
collections::{HashMap, HashSet},
path::Path,
vec::Vec,
};

use chrono::{DateTime, Utc};
use serde_json::{Map, Value};
Expand Down Expand Up @@ -922,7 +926,7 @@ impl Pool for StratPool {
fn destroy_filesystems(
&mut self,
pool_name: &str,
fs_uuids: &[FilesystemUuid],
fs_uuids: &HashSet<FilesystemUuid>,
) -> StratisResult<SetDeleteAction<FilesystemUuid, FilesystemUuid>> {
let mut removed = Vec::new();
for &uuid in fs_uuids {
Expand Down Expand Up @@ -1603,7 +1607,8 @@ mod tests {
assert!(pool
.set_overprov_mode(&Name::new(pool_name.to_string()), false)
.is_err());
pool.destroy_filesystems(pool_name, &[fs_uuid]).unwrap();
pool.destroy_filesystems(pool_name, &[fs_uuid].into())
.unwrap();

pool.set_overprov_mode(&Name::new(pool_name.to_string()), false)
.unwrap();
Expand Down
6 changes: 5 additions & 1 deletion src/jsonrpc/server/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ pub async fn filesystem_destroy<'a>(
let (uuid, _) = pool
.get_filesystem_by_name(&Name::new(fs_name.to_string()))
.ok_or_else(|| StratisError::Msg(format!("No filesystem named {fs_name} found")))?;
block_in_place(|| Ok(pool.destroy_filesystems(pool_name, &[uuid])?.is_changed()))
block_in_place(|| {
Ok(pool
.destroy_filesystems(pool_name, &[uuid].into())?
.is_changed())
})
}

// stratis-min filesystem rename
Expand Down

0 comments on commit a5cdc20

Please sign in to comment.