From 98ac45c5e49f1e80aaf654bcd231bc1443ac44ee Mon Sep 17 00:00:00 2001 From: Niladri Halder Date: Mon, 19 Feb 2024 15:54:05 +0000 Subject: [PATCH] refactor(csi-driver): replace MountIters with SafeMountIters Ref: https://github.com/openebs/mayastor-dependencies/pull/65 Signed-off-by: Niladri Halder --- Cargo.lock | 6 ++++-- control-plane/csi-driver/src/bin/node/mount.rs | 12 +++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 788bbfdbb..a6fa5c039 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1198,6 +1198,8 @@ name = "devinfo" version = "1.0.0" dependencies = [ "bindgen", + "nix", + "semver", "snafu", "udev 0.8.0", "url", @@ -3432,9 +3434,9 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.18" +version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918" +checksum = "b97ed7a9823b74f99c7742f5336af7be5ecd3eeafcb1507d1fa93347b1d589b0" [[package]] name = "serde" diff --git a/control-plane/csi-driver/src/bin/node/mount.rs b/control-plane/csi-driver/src/bin/node/mount.rs index 8b7de55ed..aa32641b0 100644 --- a/control-plane/csi-driver/src/bin/node/mount.rs +++ b/control-plane/csi-driver/src/bin/node/mount.rs @@ -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 = 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". @@ -31,7 +34,10 @@ impl ReadOnly for &str { pub(crate) fn find_mount(source: Option<&str>, target: Option<&str>) -> Option { let mut found: Option = 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 { @@ -57,7 +63,7 @@ pub(crate) fn find_mount(source: Option<&str>, target: Option<&str>) -> Option) -> Vec { - MountIter::new() + SafeMountIter::get_with_retries(MOUNT_READ_RETRIES) .unwrap() .flatten() .filter(|mount| {