mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 05:21:08 +00:00
Add Windows support for storage monitor (#13466)
* Add Windows support for storage monitor * Apply suggested changes
This commit is contained in:
committed by
GitHub
parent
6aa4127a74
commit
a1c546e9aa
Generated
+47
-10
@@ -2557,6 +2557,17 @@ dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fs4"
|
||||
version = "0.6.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ea55201cc351fdb478217c0fb641b59813da9b4efe4c414a9d8f989a657d149"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"rustix 0.35.13",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fs_extra"
|
||||
version = "1.3.0"
|
||||
@@ -3282,6 +3293,12 @@ dependencies = [
|
||||
"webrtc-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "io-lifetimes"
|
||||
version = "0.7.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "59ce5ef949d49ee85593fc4d3f3f95ad61657076395cbbce23e2121fc5542074"
|
||||
|
||||
[[package]]
|
||||
name = "io-lifetimes"
|
||||
version = "1.0.5"
|
||||
@@ -3323,8 +3340,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "22e18b0a45d56fe973d6db23972bf5bc46f988a4a2385deac9cc29572f09daef"
|
||||
dependencies = [
|
||||
"hermit-abi 0.3.0",
|
||||
"io-lifetimes",
|
||||
"rustix",
|
||||
"io-lifetimes 1.0.5",
|
||||
"rustix 0.36.8",
|
||||
"windows-sys 0.45.0",
|
||||
]
|
||||
|
||||
@@ -4222,6 +4239,12 @@ dependencies = [
|
||||
"nalgebra",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "linux-raw-sys"
|
||||
version = "0.0.46"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d4d2456c373231a208ad294c33dc5bff30051eafd954cd4caae83a712b12854d"
|
||||
|
||||
[[package]]
|
||||
name = "linux-raw-sys"
|
||||
version = "0.1.4"
|
||||
@@ -4372,7 +4395,7 @@ version = "0.6.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b20a59d985586e4a5aef64564ac77299f8586d8be6cf9106a5a40207e8908efb"
|
||||
dependencies = [
|
||||
"rustix",
|
||||
"rustix 0.36.8",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -7830,6 +7853,20 @@ dependencies = [
|
||||
"nom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustix"
|
||||
version = "0.35.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "727a1a6d65f786ec22df8a81ca3121107f235970dc1705ed681d3e6e8b9cd5f9"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"errno",
|
||||
"io-lifetimes 0.7.5",
|
||||
"libc",
|
||||
"linux-raw-sys 0.0.46",
|
||||
"windows-sys 0.42.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustix"
|
||||
version = "0.36.8"
|
||||
@@ -7838,9 +7875,9 @@ checksum = "f43abb88211988493c1abb44a70efa56ff0ce98f233b7b276146f1f3f7ba9644"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"errno",
|
||||
"io-lifetimes",
|
||||
"io-lifetimes 1.0.5",
|
||||
"libc",
|
||||
"linux-raw-sys",
|
||||
"linux-raw-sys 0.1.4",
|
||||
"windows-sys 0.45.0",
|
||||
]
|
||||
|
||||
@@ -8538,7 +8575,7 @@ dependencies = [
|
||||
"once_cell",
|
||||
"parity-scale-codec",
|
||||
"paste",
|
||||
"rustix",
|
||||
"rustix 0.36.8",
|
||||
"sc-allocator",
|
||||
"sc-executor-common",
|
||||
"sc-runtime-test",
|
||||
@@ -9098,9 +9135,9 @@ name = "sc-storage-monitor"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"clap 4.1.4",
|
||||
"fs4",
|
||||
"futures",
|
||||
"log",
|
||||
"nix 0.26.2",
|
||||
"sc-client-db",
|
||||
"sc-utils",
|
||||
"sp-core",
|
||||
@@ -12055,7 +12092,7 @@ dependencies = [
|
||||
"directories-next",
|
||||
"file-per-thread-logger",
|
||||
"log",
|
||||
"rustix",
|
||||
"rustix 0.36.8",
|
||||
"serde",
|
||||
"sha2 0.10.6",
|
||||
"toml",
|
||||
@@ -12135,7 +12172,7 @@ checksum = "f76ef2e410329aaf8555ac6571d6fe07711be0646dcdf7ff3ab750a42ed2e583"
|
||||
dependencies = [
|
||||
"object 0.29.0",
|
||||
"once_cell",
|
||||
"rustix",
|
||||
"rustix 0.36.8",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -12166,7 +12203,7 @@ dependencies = [
|
||||
"memoffset 0.6.5",
|
||||
"paste",
|
||||
"rand 0.8.5",
|
||||
"rustix",
|
||||
"rustix 0.36.8",
|
||||
"wasmtime-asm-macros",
|
||||
"wasmtime-environ",
|
||||
"wasmtime-jit-debug",
|
||||
|
||||
@@ -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" }
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
@@ -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),
|
||||
}
|
||||
@@ -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`.
|
||||
|
||||
Reference in New Issue
Block a user