proxmox-rrd: use syncfs after writing rrd files

Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
This commit is contained in:
Dietmar Maurer 2021-10-18 13:45:30 +02:00
parent 77c2e4668b
commit 336e8f3e7f
4 changed files with 18 additions and 1 deletions

View File

@ -12,6 +12,7 @@ proxmox-router = "1.1"
anyhow = "1.0"
bitflags = "1.2.1"
crossbeam-channel = "0.5"
libc = "0.2"
log = "0.4"
nix = "0.19.1"
serde = { version = "1.0", features = ["derive"] }

View File

@ -147,6 +147,10 @@ impl RRDCache {
Ok(JournalEntry { time, value, dst, rel_path })
}
pub fn sync_journal(&self) -> Result<(), Error> {
self.state.read().unwrap().sync_journal()
}
/// Apply and commit the journal. Should be used at server startup.
pub fn apply_journal(&self) -> Result<bool, Error> {
let state = Arc::clone(&self.state);
@ -387,6 +391,8 @@ fn commit_journal_impl(
}
}
state.read().unwrap().syncfs()?;
if errors != 0 {
bail!("errors during rrd flush - unable to commit rrd journal");
}

View File

@ -3,6 +3,7 @@ use std::path::PathBuf;
use std::sync::Arc;
use std::io::{Write, BufReader};
use std::ffi::OsStr;
use std::os::unix::io::AsRawFd;
use anyhow::Error;
use nix::fcntl::OFlag;
@ -50,6 +51,16 @@ impl JournalState {
})
}
pub fn sync_journal(&self) -> Result<(), Error> {
nix::unistd::fdatasync(self.journal.as_raw_fd())?;
Ok(())
}
pub fn syncfs(&self) -> Result<(), nix::Error> {
let res = unsafe { libc::syncfs(self.journal.as_raw_fd()) };
nix::errno::Errno::result(res).map(drop)
}
pub fn append_journal_entry(
&mut self,
time: f64,

View File

@ -14,7 +14,6 @@
use std::path::Path;
use anyhow::{bail, format_err, Error};
use serde::{Serialize, Deserialize};
use proxmox::tools::fs::{replace_file, CreateOptions};