Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Add Windows support for storage monitor #13466

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 47 additions & 10 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion client/storage-monitor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ homepage = "https://substrate.io"
clap = { version = "4.0.9", features = ["derive", "string"] }
futures = "0.3.21"
log = "0.4.17"
nix = { version = "0.26.1", features = ["fs"] }
fs4 = "0.6.3"
sc-client-db = { version = "0.10.0-dev", default-features = false, path = "../db" }
sc-utils = { version = "4.0.0-dev", path = "../utils" }
sp-core = { version = "7.0.0", path = "../../primitives/core" }
Expand Down
11 changes: 3 additions & 8 deletions client/storage-monitor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use clap::Args;
use nix::{errno::Errno, sys::statvfs::statvfs};
use sc_client_db::DatabaseSource;
use sp_core::traits::SpawnEssentialNamed;
use std::{
io,
path::{Path, PathBuf},
time::Duration,
};
Expand All @@ -31,7 +31,7 @@ const LOG_TARGET: &str = "storage-monitor";
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("IO Error")]
IOError(#[from] Errno),
IOError(#[from] io::Error),
#[error("Out of storage space: available {0}MB, required {1}MB")]
StorageOutOfSpace(u64, u64),
}
Expand Down Expand Up @@ -117,12 +117,7 @@ impl StorageMonitorService {

/// Returns free space in MB, or error if statvfs failed.
fn free_space(path: &Path) -> Result<u64, Error> {
statvfs(path)
.map(|stats| {
u64::from(stats.blocks_available()).saturating_mul(u64::from(stats.block_size())) /
1_000_000
})
.map_err(Error::from)
Ok(fs4::available_space(path).map(|s| s / 1_000_000)?)
}

/// Checks if the amount of free space for given `path` is above given `threshold`.
Expand Down