Skip to content

Commit

Permalink
fix zcachedb logs entry printing (openzfs#826)
Browse files Browse the repository at this point in the history
When attempting to print chunks/entries (e.g. with `zcachedb logs --index`),
if the `cffi::Slice` can be a direct memory (`Bytes`) reference, then
the binary value of the entries is printed, rather than pretty-printing
them.

This commit provides a better `Debug` implementation for `cffi::Slice`,
which fixes `zcachedb logs`.
  • Loading branch information
ahrens authored Apr 27, 2023
1 parent fc6cebe commit fe1248b
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion cmd/zfs_object_agent/util/src/cffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
//! was written out, see block_encode.rs.
use std::any::type_name;
use std::fmt;
use std::fmt::Debug;
use std::fmt::Formatter;
use std::mem::align_of;
use std::mem::size_of;
use std::ops::Deref;
Expand Down Expand Up @@ -116,12 +119,23 @@ pub fn bytes_to_slice<T: Cffi>(bytes: Bytes) -> Result<Slice<T>> {
}
}

#[derive(Debug)]
pub enum Slice<T: Cffi> {
Referenced(Bytes),
Owned(Vec<T>),
}

impl<T: Cffi + Debug> Debug for Slice<T> {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
match self {
Slice::Referenced(_) => f
.debug_tuple("Slice::Referenced")
.field(&self.deref())
.finish(),
Slice::Owned(_) => f.debug_tuple("Slice::Owned").field(&self.deref()).finish(),
}
}
}

impl<T: Cffi> Slice<T> {
pub fn new_owned(vec: Vec<T>) -> Self {
Slice::Owned(vec)
Expand Down

0 comments on commit fe1248b

Please sign in to comment.