mirror of
https://git.proxmox.com/git/proxmox
synced 2025-04-29 01:41:10 +00:00
rrd: feature-gate support for the v1 format
new users of this crate might not really need support for the v1 format. Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
This commit is contained in:
parent
4d150d35c7
commit
6eed8ed992
@ -25,3 +25,7 @@ serde_json.workspace = true
|
|||||||
proxmox-schema = { workspace = true, features = [ "api-macro" ] }
|
proxmox-schema = { workspace = true, features = [ "api-macro" ] }
|
||||||
proxmox-sys.workspace = true
|
proxmox-sys.workspace = true
|
||||||
proxmox-time.workspace = true
|
proxmox-time.workspace = true
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = [ "rrd_v1" ]
|
||||||
|
rrd_v1 = []
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
//! * Stores data for different time resolution
|
//! * Stores data for different time resolution
|
||||||
//! * Simple cache implementation with journal support
|
//! * Simple cache implementation with journal support
|
||||||
|
|
||||||
|
#[cfg(feature = "rrd_v1")]
|
||||||
mod rrd_v1;
|
mod rrd_v1;
|
||||||
|
|
||||||
pub mod rrd;
|
pub mod rrd;
|
||||||
|
@ -21,8 +21,6 @@ use serde::{Deserialize, Serialize};
|
|||||||
use proxmox_schema::api;
|
use proxmox_schema::api;
|
||||||
use proxmox_sys::fs::{make_tmp_file, CreateOptions};
|
use proxmox_sys::fs::{make_tmp_file, CreateOptions};
|
||||||
|
|
||||||
use crate::rrd_v1;
|
|
||||||
|
|
||||||
/// Proxmox RRD v2 file magic number
|
/// Proxmox RRD v2 file magic number
|
||||||
// openssl::sha::sha256(b"Proxmox Round Robin Database file v2.0")[0..8];
|
// openssl::sha::sha256(b"Proxmox Round Robin Database file v2.0")[0..8];
|
||||||
pub const PROXMOX_RRD_MAGIC_2_0: [u8; 8] = [224, 200, 228, 27, 239, 112, 122, 159];
|
pub const PROXMOX_RRD_MAGIC_2_0: [u8; 8] = [224, 200, 228, 27, 239, 112, 122, 159];
|
||||||
@ -366,15 +364,18 @@ impl RRD {
|
|||||||
bail!("not an rrd file - file is too small ({})", raw.len());
|
bail!("not an rrd file - file is too small ({})", raw.len());
|
||||||
}
|
}
|
||||||
|
|
||||||
let rrd = if raw[0..8] == rrd_v1::PROXMOX_RRD_MAGIC_1_0 {
|
let rrd: RRD = match &raw[0..8] {
|
||||||
let v1 = rrd_v1::RRDv1::from_raw(raw)?;
|
#[cfg(feature = "rrd_v1")]
|
||||||
|
magic if magic == crate::rrd_v1::PROXMOX_RRD_MAGIC_1_0 => {
|
||||||
|
let v1 = crate::rrd_v1::RRDv1::from_raw(raw)?;
|
||||||
v1.to_rrd_v2()
|
v1.to_rrd_v2()
|
||||||
.map_err(|err| format_err!("unable to convert from old V1 format - {}", err))?
|
.map_err(|err| format_err!("unable to convert from old V1 format - {err}"))?
|
||||||
} else if raw[0..8] == PROXMOX_RRD_MAGIC_2_0 {
|
}
|
||||||
|
magic if magic == PROXMOX_RRD_MAGIC_2_0 => {
|
||||||
serde_cbor::from_slice(&raw[8..])
|
serde_cbor::from_slice(&raw[8..])
|
||||||
.map_err(|err| format_err!("unable to decode RRD file - {}", err))?
|
.map_err(|err| format_err!("unable to decode RRD file - {err}"))?
|
||||||
} else {
|
}
|
||||||
bail!("not an rrd file - unknown magic number");
|
_ => bail!("not an rrd file - unknown magic number")
|
||||||
};
|
};
|
||||||
|
|
||||||
if rrd.source.last_update < 0.0 {
|
if rrd.source.last_update < 0.0 {
|
||||||
|
@ -20,12 +20,13 @@ fn compare_file(fn1: &str, fn2: &str) -> Result<(), Error> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
const RRD_V1_FN: &str = "./tests/testdata/cpu.rrd_v1";
|
|
||||||
const RRD_V2_FN: &str = "./tests/testdata/cpu.rrd_v2";
|
const RRD_V2_FN: &str = "./tests/testdata/cpu.rrd_v2";
|
||||||
|
|
||||||
// make sure we can load and convert RRD v1
|
// make sure we can load and convert RRD v1
|
||||||
#[test]
|
#[test]
|
||||||
|
#[cfg(feature = "rrd_v1")]
|
||||||
fn upgrade_from_rrd_v1() -> Result<(), Error> {
|
fn upgrade_from_rrd_v1() -> Result<(), Error> {
|
||||||
|
const RRD_V1_FN: &str = "./tests/testdata/cpu.rrd_v1";
|
||||||
let rrd = RRD::load(Path::new(RRD_V1_FN), true)?;
|
let rrd = RRD::load(Path::new(RRD_V1_FN), true)?;
|
||||||
|
|
||||||
const RRD_V2_NEW_FN: &str = "./tests/testdata/cpu.rrd_v2.upgraded";
|
const RRD_V2_NEW_FN: &str = "./tests/testdata/cpu.rrd_v2.upgraded";
|
||||||
|
Loading…
Reference in New Issue
Block a user