Yet more stuff. Direct IO is not working at all.
This commit is contained in:
5
Cargo.lock
generated
5
Cargo.lock
generated
@@ -125,15 +125,16 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"clap",
|
||||
"libc",
|
||||
"ron",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.177"
|
||||
version = "0.2.178"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976"
|
||||
checksum = "37c93d8daa9d8a012fd8ab92f088405fb202ea0b6ab73ee2482ae66af4f42091"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
[package]
|
||||
name = "kramer"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
libc = "0.2.178"
|
||||
# NOTE:
|
||||
# = X.X.X is the version used in testing.
|
||||
# Use this version for greatest compatibility.
|
||||
|
||||
19
src/io.rs
19
src/io.rs
@@ -1,5 +1,6 @@
|
||||
use std::fs::{File, OpenOptions};
|
||||
use std::io::{self, Seek, SeekFrom};
|
||||
use std::os::unix::fs::{FileExt, OpenOptionsExt};
|
||||
|
||||
use crate::cli::CONFIG;
|
||||
|
||||
@@ -22,8 +23,18 @@ pub fn get_stream_length<S: Seek>(stream: &mut S) -> io::Result<u64> {
|
||||
pub fn load_input() -> anyhow::Result<File> {
|
||||
OpenOptions::new()
|
||||
.read(true)
|
||||
//.custom_flags(libc::O_DIRECT)
|
||||
.open(&CONFIG.input)
|
||||
.with_context(|| format!("Failed to open input file: {}", &CONFIG.input.display()))
|
||||
|
||||
/*
|
||||
use std::ffi::CString;
|
||||
use std::os::fd::FromRawFd;
|
||||
|
||||
let path = CString::new(CONFIG.input.to_str().unwrap().to_owned()).unwrap();
|
||||
let flags = libc::O_DIRECT | libc::O_RDONLY;
|
||||
let f = unsafe { File::from_raw_fd(libc::open(path.as_ptr(), flags)) };
|
||||
*/
|
||||
}
|
||||
|
||||
pub fn load_output() -> anyhow::Result<File> {
|
||||
@@ -40,16 +51,10 @@ pub fn load_output() -> anyhow::Result<File> {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn load_map_read() -> anyhow::Result<File> {
|
||||
pub fn load_map_read() -> std::io::Result<File> {
|
||||
OpenOptions::new()
|
||||
.read(true)
|
||||
.open(crate::path::MAP_PATH.clone())
|
||||
.with_context(|| {
|
||||
format!(
|
||||
"Failed to open/create mapping file at: {}",
|
||||
crate::path::MAP_PATH.display()
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn load_map_write() -> anyhow::Result<File> {
|
||||
|
||||
@@ -2,7 +2,7 @@ use std::fs::File;
|
||||
use std::io::{BufWriter, Read, Seek, SeekFrom, Write};
|
||||
use std::usize;
|
||||
|
||||
use anyhow::Context;
|
||||
use anyhow::{Context, anyhow};
|
||||
|
||||
use crate::cli::CONFIG;
|
||||
use crate::mapping::prelude::*;
|
||||
@@ -18,13 +18,16 @@ pub struct Recover {
|
||||
impl Recover {
|
||||
pub fn new() -> anyhow::Result<Self> {
|
||||
let input: File = crate::io::load_input()?;
|
||||
|
||||
let output: File = crate::io::load_output()?;
|
||||
|
||||
let map: MapFile = {
|
||||
crate::io::load_map_read()?
|
||||
.try_into()
|
||||
.unwrap_or(MapFile::new(CONFIG.sector_size))
|
||||
if let Ok(f) = crate::io::load_map_read()
|
||||
&& let Ok(map_file) = MapFile::try_from(f)
|
||||
{
|
||||
map_file
|
||||
} else {
|
||||
MapFile::new(CONFIG.sector_size)
|
||||
}
|
||||
};
|
||||
|
||||
let mut r = Recover {
|
||||
@@ -120,12 +123,15 @@ impl Recover {
|
||||
println!("Hit error: {:?}", err);
|
||||
if CONFIG.reopen_on_error {
|
||||
self.reload_input()
|
||||
.context("Failed to reload input file after previous error.")?;
|
||||
.context("Failed to reload input file after previous error")?;
|
||||
}
|
||||
|
||||
self.input
|
||||
.seek_relative((read_position + buf_capacity) as i64)
|
||||
.seek_relative(buf_capacity as i64)
|
||||
.context("Failed to seek input by buf_capacity to skip previous error")?;
|
||||
self.output
|
||||
.seek_relative(buf_capacity as i64)
|
||||
.context("Failed to seek output by buf_capacity to skip previous error")?;
|
||||
|
||||
// I don't remember what level was for.
|
||||
cluster.stage = Stage::ForIsolation { level: 1 };
|
||||
@@ -138,6 +144,7 @@ impl Recover {
|
||||
}
|
||||
|
||||
self.map.update(cluster);
|
||||
self.map.write_to(&mut crate::io::load_map_write()?)?;
|
||||
read_position += buf_capacity;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user