Skip to content

Commit

Permalink
refactor(csi-driver): replace MountIters with SafeMountIters
Browse files Browse the repository at this point in the history
Ref: openebs/mayastor-dependencies#65

Signed-off-by: Niladri Halder <[email protected]>
  • Loading branch information
niladrih committed Feb 19, 2024
1 parent c6c9ca8 commit 98ac45c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 4 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions control-plane/csi-driver/src/bin/node/mount.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
//! Utility functions for mounting and unmounting filesystems.
use crate::filesystem_ops::FileSystem;
use csi_driver::filesystem::FileSystem as Fs;
use devinfo::mountinfo::{MountInfo, MountIter};
use devinfo::mountinfo::{MountInfo, SafeMountIter};

use std::{collections::HashSet, io::Error};
use sys_mount::{unmount, FilesystemType, Mount, MountFlags, UnmountFlags};
use tracing::{debug, info};
use uuid::Uuid;

/// The number of times we should retry, if SafeMountIter fails to get a consistent result.
const MOUNT_READ_RETRIES: Option<u32> = Some(20);

// Simple trait for checking if the readonly (ro) option
// is present in a "list" of options, while allowing for
// flexibility as to the type of "list".
Expand All @@ -31,7 +34,10 @@ impl ReadOnly for &str {
pub(crate) fn find_mount(source: Option<&str>, target: Option<&str>) -> Option<MountInfo> {
let mut found: Option<MountInfo> = None;

for mount in MountIter::new().unwrap().flatten() {
for mount in SafeMountIter::get_with_retries(MOUNT_READ_RETRIES)
.unwrap()
.flatten()
{
if let Some(value) = source {
if mount.source.to_string_lossy() == value {
if let Some(value) = target {
Expand All @@ -57,7 +63,7 @@ pub(crate) fn find_mount(source: Option<&str>, target: Option<&str>) -> Option<M
/// Return all mounts for a matching source.
/// Optionally ignore the given destination path.
pub(crate) fn find_src_mounts(source: &str, dest_ignore: Option<&str>) -> Vec<MountInfo> {
MountIter::new()
SafeMountIter::get_with_retries(MOUNT_READ_RETRIES)
.unwrap()
.flatten()
.filter(|mount| {
Expand Down

0 comments on commit 98ac45c

Please sign in to comment.