Skip to content

Commit

Permalink
make it work with zfs 0.8
Browse files Browse the repository at this point in the history
The parent of this commit was based on ZoL 0.8-rcX some time in Feb-April 2019.

Since then, some changes happend to the zfs send code that broke the parent commit.

Changes made in this commit:

- Handle FREEOBJECTS(firstobj=X, numobjs=u64max-X)
  Apparently, this wasn't a thing in April 19, cannot remember exactly.

- fixup from_ivset_guid field when squashing
  => f00ab3f22cc2c7f62cfd56be842945667b1d558f (from_ivset_guid was added to stream format)

- 'show' subcommand to dump LSM's internal state

- cargo fmt
  • Loading branch information
problame committed Dec 15, 2019
1 parent 0dae84a commit c9e83bd
Show file tree
Hide file tree
Showing 10 changed files with 216 additions and 81 deletions.
7 changes: 6 additions & 1 deletion bindings/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ fn main() {
let helpers = Path::new(&dir).join("./helpers");

// compile helpers lib
cc::Build::new().file(helpers.join("helpers.c")).flag("-Werror").flag("-Wall").flag("-Wpedantic").compile("helpers");
cc::Build::new()
.file(helpers.join("helpers.c"))
.flag("-Werror")
.flag("-Wall")
.flag("-Wpedantic")
.compile("helpers");

let clang_args = [format!("-I{}", helpers.display())];
let bindings = bindgen::Builder::default()
Expand Down
2 changes: 0 additions & 2 deletions bindings/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


mod generated;
pub use generated::*;

Expand Down
74 changes: 73 additions & 1 deletion zquash/src/dmu_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ impl ReplayRecordExt for dmu_replay_record {
}
}


#[derive(Clone)]
pub struct RecordWithPayload {
pub drr: dmu_replay_record,
Expand All @@ -64,6 +63,79 @@ impl fmt::Debug for RecordWithPayload {
}
}

#[derive(Debug)]
pub enum DrrBeginMutateNvlistError<E: std::fmt::Debug> {
DecodeOuterNvlist,
LookupCryptKeydata,
MutationCallbackError(E),
PackingFailedMutationNotCommitted,
}

impl RecordWithPayload {
pub unsafe fn drr_begin_mutate_crypt_keydata<O, E: std::fmt::Debug, F>(
&mut self,
cb: F,
) -> Result<O, DrrBeginMutateNvlistError<E>>
where
F: FnOnce(*mut nvpair_sys::nvlist_t) -> Result<O, E>,
{
assert_eq!(self.drr.drr_type, dmu_replay_record_DRR_BEGIN);

use const_cstr::const_cstr;
let buf = self.payload.as_mut_ptr();
let mut deser: *mut nvpair_sys::nvlist_t = std::ptr::null_mut();
if nvpair_sys::nvlist_unpack(buf as *mut i8, self.payload.len(), &mut deser, 0) != 0 {
return Err(DrrBeginMutateNvlistError::DecodeOuterNvlist);
}

let mut crypt_keydata: *mut nvpair_sys::nvlist_t = std::ptr::null_mut();
if nvpair_sys::nvlist_lookup_nvlist(
deser,
const_cstr!("crypt_keydata").as_ptr(),
&mut crypt_keydata,
) != 0
{
nvpair_sys::nvlist_free(deser);
return Err(DrrBeginMutateNvlistError::LookupCryptKeydata);
}

let cbres = cb(crypt_keydata);

if cbres.is_ok() {
// commit mutations by replacing self.payload with updated one
let mut packed_allocated_buf: *mut i8 = std::ptr::null_mut();
let mut packed_allocated_buf_size: usize = 0;
if nvpair_sys::nvlist_pack(
deser,
&mut packed_allocated_buf,
&mut packed_allocated_buf_size,
nvpair_sys::NV_ENCODE_NATIVE,
0,
) != 0
{
nvpair_sys::nvlist_free(deser);
return Err(DrrBeginMutateNvlistError::PackingFailedMutationNotCommitted);
}
let buf_as_slice = std::slice::from_raw_parts(
packed_allocated_buf as *const u8,
packed_allocated_buf_size,
);
assert_eq!(self.payload.len(), self.drr.drr_payloadlen as usize);
self.payload = Vec::from(buf_as_slice); // copy
use std::convert::TryInto;
self.drr.drr_payloadlen = packed_allocated_buf_size.try_into().unwrap();
libc::free(packed_allocated_buf as *mut std::ffi::c_void);
}

nvpair_sys::nvlist_free(deser);

match cbres {
Ok(o) => Ok(o),
Err(e) => Err(DrrBeginMutateNvlistError::MutationCallbackError(e)),
}
}
}

pub struct Record<'r> {
pub header: dmu_replay_record,
pub payload_len: u64,
Expand Down
1 change: 0 additions & 1 deletion zquash/src/fletcher4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,4 @@ impl Fletcher4 {
pub fn checksum(&self) -> [u64; 4] {
[self.a, self.b, self.c, self.d]
}

}
2 changes: 1 addition & 1 deletion zquash/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ extern crate derive_more;
pub mod dmu_stream;
pub mod fletcher4;
pub mod lsm;
pub mod split_tree;
pub mod split_tree;
8 changes: 1 addition & 7 deletions zquash/src/lsm/lsm.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


extern crate bincode;
extern crate serde;

Expand Down Expand Up @@ -231,9 +229,7 @@ pub struct SortedLSMWriter<K: Ord, V> {
}

impl<K: Ord + Serialize + DeserializeOwned, V: Serialize + DeserializeOwned> SortedLSMWriter<K, V> {
pub fn new(
path: &std::path::Path
) -> SortedLSMWriter<K, V> {
pub fn new(path: &std::path::Path) -> SortedLSMWriter<K, V> {
SortedLSMWriter {
file: std::io::BufWriter::new(std::fs::File::create(path).unwrap()),
last_entry: None,
Expand Down Expand Up @@ -280,5 +276,3 @@ mod tests {
std::fs::remove_file(&pathout);
}
}


Loading

0 comments on commit c9e83bd

Please sign in to comment.