diff --git a/pbs-api-types/src/lib.rs b/pbs-api-types/src/lib.rs index 024181ee..14c8cd35 100644 --- a/pbs-api-types/src/lib.rs +++ b/pbs-api-types/src/lib.rs @@ -121,6 +121,8 @@ const_regex! { DNS_NAME!(), "|", IPRE_BRACKET!(), "):)?(?:([0-9]{1,5}):)?(", PROXMOX_SAFE_ID_REGEX_STR!(), r")$" ); + + pub BLOCKDEVICE_NAME_REGEX = r"^(:?(:?h|s|x?v)d[a-z]+)|(:?nvme\d+n\d+)$"; } pub const IP_V4_FORMAT: ApiStringFormat = ApiStringFormat::Pattern(&IP_V4_REGEX); diff --git a/src/api2/node/apt.rs b/src/api2/node/apt.rs index 13b4c80c..c01da81f 100644 --- a/src/api2/node/apt.rs +++ b/src/api2/node/apt.rs @@ -273,7 +273,7 @@ fn apt_get_changelog( command.arg("changelog"); command.arg("-qq"); // don't display download progress command.arg(name); - let output = crate::tools::run_command(command, None)?; + let output = pbs_tools::run_command(command, None)?; Ok(json!(output)) } } diff --git a/src/api2/node/disks/directory.rs b/src/api2/node/disks/directory.rs index cd6cb66b..ff476aa3 100644 --- a/src/api2/node/disks/directory.rs +++ b/src/api2/node/disks/directory.rs @@ -244,7 +244,7 @@ pub fn delete_datastore_disk(name: String) -> Result<(), Error> { // try to unmount, if that fails tell the user to reboot or unmount manually let mut command = std::process::Command::new("umount"); command.arg(&path); - match crate::tools::run_command(command, None) { + match pbs_tools::run_command(command, None) { Err(_) => bail!( "Could not umount '{}' since it is busy. It will stay mounted \ until the next reboot or until unmounted manually!", diff --git a/src/api2/node/disks/zfs.rs b/src/api2/node/disks/zfs.rs index e18f1bd1..1e539ca1 100644 --- a/src/api2/node/disks/zfs.rs +++ b/src/api2/node/disks/zfs.rs @@ -356,7 +356,7 @@ pub fn create_zpool( worker.log(format!("# {:?}", command)); - let output = crate::tools::run_command(command, None)?; + let output = pbs_tools::run_command(command, None)?; worker.log(output); if std::path::Path::new("/lib/systemd/system/zfs-import@.service").exists() { @@ -368,7 +368,7 @@ pub fn create_zpool( let mut command = std::process::Command::new("zfs"); command.args(&["set", &format!("compression={}", compression), &name]); worker.log(format!("# {:?}", command)); - let output = crate::tools::run_command(command, None)?; + let output = pbs_tools::run_command(command, None)?; worker.log(output); } diff --git a/src/api2/types/mod.rs b/src/api2/types/mod.rs index a1892371..bae9ded1 100644 --- a/src/api2/types/mod.rs +++ b/src/api2/types/mod.rs @@ -39,8 +39,6 @@ const_regex!{ pub SUBSCRIPTION_KEY_REGEX = concat!(r"^pbs(?:[cbsp])-[0-9a-f]{10}$"); - pub BLOCKDEVICE_NAME_REGEX = r"^(:?(:?h|s|x?v)d[a-z]+)|(:?nvme\d+n\d+)$"; - pub ZPOOL_NAME_REGEX = r"^[a-zA-Z][a-z0-9A-Z\-_.:]+$"; pub DATASTORE_MAP_REGEX = concat!(r"(:?", PROXMOX_SAFE_ID_REGEX_STR!(), r"=)?", PROXMOX_SAFE_ID_REGEX_STR!()); diff --git a/src/bin/proxmox-restore-daemon.rs b/src/bin/proxmox-restore-daemon.rs index f2d455d3..e9018ecc 100644 --- a/src/bin/proxmox-restore-daemon.rs +++ b/src/bin/proxmox-restore-daemon.rs @@ -1,8 +1,6 @@ ///! Daemon binary to run inside a micro-VM for secure single file restore of disk images -use anyhow::{bail, format_err, Error}; -use lazy_static::lazy_static; -use log::{error, info}; - +use std::fs::File; +use std::io::prelude::*; use std::os::unix::{ io::{FromRawFd, RawFd}, net, @@ -10,16 +8,16 @@ use std::os::unix::{ use std::path::Path; use std::sync::{Arc, Mutex}; +use anyhow::{bail, format_err, Error}; +use lazy_static::lazy_static; +use log::{error, info}; use tokio::sync::mpsc; use tokio_stream::wrappers::ReceiverStream; -use pbs_client::DEFAULT_VSOCK_PORT; - use proxmox::api::RpcEnvironmentType; use proxmox_backup::server::{rest::*, ApiConfig}; -use std::fs::File; -use std::io::prelude::*; +use pbs_client::DEFAULT_VSOCK_PORT; mod proxmox_restore_daemon; use proxmox_restore_daemon::*; diff --git a/src/bin/proxmox_restore_daemon/api.rs b/src/bin/proxmox_restore_daemon/api.rs index b835bb2a..15fe5f00 100644 --- a/src/bin/proxmox_restore_daemon/api.rs +++ b/src/bin/proxmox_restore_daemon/api.rs @@ -9,10 +9,10 @@ use futures::FutureExt; use hyper::http::request::Parts; use hyper::{header, Body, Response, StatusCode}; use log::error; -use pathpatterns::{MatchEntry, MatchPattern, MatchType, Pattern}; use serde_json::Value; use tokio::sync::Semaphore; +use pathpatterns::{MatchEntry, MatchPattern, MatchType, Pattern}; use proxmox::api::{ api, schema::*, ApiHandler, ApiMethod, ApiResponseFuture, Permission, Router, RpcEnvironment, SubdirMap, diff --git a/src/bin/proxmox_restore_daemon/auth.rs b/src/bin/proxmox_restore_daemon/auth.rs index 0973849e..32a8fd98 100644 --- a/src/bin/proxmox_restore_daemon/auth.rs +++ b/src/bin/proxmox_restore_daemon/auth.rs @@ -1,10 +1,11 @@ //! Authentication via a static ticket file -use anyhow::{bail, format_err, Error}; - use std::fs::File; use std::io::prelude::*; -use proxmox_backup::api2::types::Authid; +use anyhow::{bail, format_err, Error}; + +use pbs_api_types::Authid; + use proxmox_backup::config::cached_user_info::CachedUserInfo; use proxmox_backup::server::auth::{ApiAuth, AuthError}; diff --git a/src/bin/proxmox_restore_daemon/disk.rs b/src/bin/proxmox_restore_daemon/disk.rs index 57ca8d7c..dea8fbf9 100644 --- a/src/bin/proxmox_restore_daemon/disk.rs +++ b/src/bin/proxmox_restore_daemon/disk.rs @@ -1,18 +1,19 @@ //! Low-level disk (image) access functions for file restore VMs. -use anyhow::{bail, format_err, Error}; -use lazy_static::lazy_static; -use log::{info, warn}; - use std::collections::HashMap; use std::fs::{create_dir_all, File}; use std::io::{BufRead, BufReader}; use std::path::{Component, Path, PathBuf}; use std::process::Command; +use anyhow::{bail, format_err, Error}; +use lazy_static::lazy_static; +use log::{info, warn}; + use proxmox::const_regex; use proxmox::tools::fs; -use proxmox_backup::api2::types::BLOCKDEVICE_NAME_REGEX; -use proxmox_backup::tools::run_command; + +use pbs_api_types::BLOCKDEVICE_NAME_REGEX; +use pbs_tools::run_command; const_regex! { VIRTIO_PART_REGEX = r"^vd[a-z]+(\d+)$"; diff --git a/src/bin/proxmox_restore_daemon/watchdog.rs b/src/bin/proxmox_restore_daemon/watchdog.rs index 24997809..294c7510 100644 --- a/src/bin/proxmox_restore_daemon/watchdog.rs +++ b/src/bin/proxmox_restore_daemon/watchdog.rs @@ -1,5 +1,6 @@ //! Tokio-based watchdog that shuts down the VM if not pinged for TIMEOUT use std::sync::atomic::{AtomicI64, Ordering}; + use proxmox::tools::time::epoch_i64; const TIMEOUT: i64 = 600; // seconds diff --git a/src/config/network/helper.rs b/src/config/network/helper.rs index 2ec0c1ea..1bf7c08f 100644 --- a/src/config/network/helper.rs +++ b/src/config/network/helper.rs @@ -188,7 +188,7 @@ pub fn compute_file_diff(filename: &str, shadow: &str) -> Result .output() .map_err(|err| format_err!("failed to execute diff - {}", err))?; - let diff = crate::tools::command_output_as_string(output, Some(|c| c == 0 || c == 1)) + let diff = pbs_tools::command_output_as_string(output, Some(|c| c == 0 || c == 1)) .map_err(|err| format_err!("diff failed: {}", err))?; Ok(diff) @@ -209,7 +209,7 @@ pub fn network_reload() -> Result<(), Error> { .output() .map_err(|err| format_err!("failed to execute 'ifreload' - {}", err))?; - crate::tools::command_output(output, None) + pbs_tools::command_output(output, None) .map_err(|err| format_err!("ifreload failed: {}", err))?; diff --git a/src/tape/changer/mtx/mtx_wrapper.rs b/src/tape/changer/mtx/mtx_wrapper.rs index 1cae5164..f6274064 100644 --- a/src/tape/changer/mtx/mtx_wrapper.rs +++ b/src/tape/changer/mtx/mtx_wrapper.rs @@ -1,7 +1,8 @@ use anyhow::Error; +use pbs_tools::run_command; + use crate::{ - tools::run_command, api2::types::ScsiTapeChanger, tape::changer::{ MtxStatus, diff --git a/src/tape/drive/lto/mod.rs b/src/tape/drive/lto/mod.rs index fabb97f7..2fb7c85d 100644 --- a/src/tape/drive/lto/mod.rs +++ b/src/tape/drive/lto/mod.rs @@ -29,10 +29,10 @@ use proxmox::{ use pbs_api_types::Fingerprint; use pbs_datastore::key_derivation::KeyConfig; +use pbs_tools::run_command; use crate::{ config, - tools::run_command, api2::types::{ MamAttribute, LtoDriveAndMediaStatus, diff --git a/src/tools/apt.rs b/src/tools/apt.rs index d725639a..8481e19d 100644 --- a/src/tools/apt.rs +++ b/src/tools/apt.rs @@ -101,7 +101,7 @@ fn get_changelog_url( command.arg("changelog"); command.arg("--print-uris"); command.arg(package); - let output = crate::tools::run_command(command, None)?; // format: 'http://foo/bar' package.changelog + let output = pbs_tools::run_command(command, None)?; // format: 'http://foo/bar' package.changelog let output = match output.splitn(2, ' ').next() { Some(output) => { if output.len() < 2 { diff --git a/src/tools/disks/lvm.rs b/src/tools/disks/lvm.rs index 1a81cea0..fad09c28 100644 --- a/src/tools/disks/lvm.rs +++ b/src/tools/disks/lvm.rs @@ -27,7 +27,7 @@ pub fn get_lvm_devices( let mut command = std::process::Command::new(PVS_BIN_PATH); command.args(&["--reportformat", "json", "--noheadings", "--readonly", "-o", "pv_name"]); - let output = crate::tools::run_command(command, None)?; + let output = pbs_tools::run_command(command, None)?; let mut device_set: HashSet = HashSet::new(); diff --git a/src/tools/disks/mod.rs b/src/tools/disks/mod.rs index af7f7fe1..115653af 100644 --- a/src/tools/disks/mod.rs +++ b/src/tools/disks/mod.rs @@ -19,7 +19,7 @@ use proxmox::sys::linux::procfs::{MountInfo, mountinfo::Device}; use proxmox::{io_bail, io_format_err}; use proxmox::api::api; -use crate::api2::types::{BLOCKDEVICE_NAME_REGEX, StorageStatus}; +use pbs_api_types::{BLOCKDEVICE_NAME_REGEX, StorageStatus}; mod zfs; pub use zfs::*; @@ -574,7 +574,7 @@ pub fn get_lsblk_info() -> Result, Error> { let mut command = std::process::Command::new("lsblk"); command.args(&["--json", "-o", "path,parttype,fstype"]); - let output = crate::tools::run_command(command, None)?; + let output = pbs_tools::run_command(command, None)?; let mut output: serde_json::Value = output.parse()?; @@ -886,7 +886,7 @@ pub fn reread_partition_table(disk: &Disk) -> Result<(), Error> { command.arg("--rereadpt"); command.arg(disk_path); - crate::tools::run_command(command, None)?; + pbs_tools::run_command(command, None)?; Ok(()) } @@ -905,7 +905,7 @@ pub fn inititialize_gpt_disk(disk: &Disk, uuid: Option<&str>) -> Result<(), Erro command.arg(disk_path); command.args(&["-U", uuid]); - crate::tools::run_command(command, None)?; + pbs_tools::run_command(command, None)?; Ok(()) } @@ -922,7 +922,7 @@ pub fn create_single_linux_partition(disk: &Disk) -> Result { command.args(&["-n1", "-t1:8300"]); command.arg(disk_path); - crate::tools::run_command(command, None)?; + pbs_tools::run_command(command, None)?; let mut partitions = disk.partitions()?; @@ -975,7 +975,7 @@ pub fn create_file_system(disk: &Disk, fs_type: FileSystemType) -> Result<(), Er command.args(&["-t", &fs_type]); command.arg(disk_path); - crate::tools::run_command(command, None)?; + pbs_tools::run_command(command, None)?; Ok(()) } @@ -1013,7 +1013,7 @@ pub fn get_fs_uuid(disk: &Disk) -> Result { command.args(&["-o", "export"]); command.arg(disk_path); - let output = crate::tools::run_command(command, None)?; + let output = pbs_tools::run_command(command, None)?; for line in output.lines() { if let Some(uuid) = line.strip_prefix("UUID=") { diff --git a/src/tools/disks/smart.rs b/src/tools/disks/smart.rs index b615603e..fefdbbe3 100644 --- a/src/tools/disks/smart.rs +++ b/src/tools/disks/smart.rs @@ -91,7 +91,7 @@ pub fn get_smart_data( }; command.arg(disk_path); - let output = crate::tools::run_command(command, None)?; + let output = pbs_tools::run_command(command, None)?; let output: serde_json::Value = output.parse()?; diff --git a/src/tools/disks/zpool_list.rs b/src/tools/disks/zpool_list.rs index 515068ca..c42fd62a 100644 --- a/src/tools/disks/zpool_list.rs +++ b/src/tools/disks/zpool_list.rs @@ -147,7 +147,7 @@ pub fn zpool_list(pool: Option, verbose: bool) -> Result Result, Error> { let mut command = std::process::Command::new("zpool"); command.args(&["status", "-p", "-P", pool]); - let output = crate::tools::run_command(command, None)?; + let output = pbs_tools::run_command(command, None)?; parse_zpool_status(&output) } diff --git a/src/tools/mod.rs b/src/tools/mod.rs index e76ab5da..27265db6 100644 --- a/src/tools/mod.rs +++ b/src/tools/mod.rs @@ -17,7 +17,6 @@ use proxmox_http::{ pub use pbs_tools::json; pub use pbs_tools::nom; -pub use pbs_tools::{run_command, command_output, command_output_as_string}; pub use pbs_tools::process_locker::{ ProcessLocker, ProcessLockExclusiveGuard, ProcessLockSharedGuard };