Skip to content

Commit

Permalink
feat(zap): zap list will take a limit
Browse files Browse the repository at this point in the history
Signed-off-by: sundengyu <dengyu.sun@iomesh.com>
  • Loading branch information
sundengyu committed Dec 23, 2024
1 parent fa1fb1c commit f21bd53
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/bindings/async_sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ pub unsafe extern "C" fn libuzfs_dataset_expand_c(arg: *mut c_void) {
pub struct LibuzfsZapListArg {
pub dhp: *mut libuzfs_dataset_handle_t,
pub obj: u64,
pub limit: usize,

pub err: i32,
pub list: Vec<(String, Vec<u8>)>,
}
Expand Down Expand Up @@ -328,6 +330,10 @@ pub unsafe extern "C" fn libuzfs_zap_list_c(arg: *mut c_void) {
let name = String::from_utf8(name).unwrap();
arg.list.push((name, value));

if arg.list.len() >= arg.limit {
break;
}

arg.err = libuzfs_zap_iterator_advance(iter);
if arg.err != 0 {
if arg.err == libc::ENOENT {
Expand Down
4 changes: 3 additions & 1 deletion src/dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,10 +365,12 @@ impl Dataset {
self.claim_inode(ino, gen, InodeType::DIR).await
}

pub async fn zap_list(&self, zap_obj: u64) -> Result<Vec<(String, Vec<u8>)>> {
pub async fn zap_list(&self, zap_obj: u64, limit: usize) -> Result<Vec<(String, Vec<u8>)>> {
let mut arg = LibuzfsZapListArg {
dhp: self.dhp,
obj: zap_obj,
limit,

err: 0,
list: Vec::new(),
};
Expand Down
2 changes: 1 addition & 1 deletion src/tests/dataset_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ async fn uzfs_zap_iterator_test() {
let remover_handle = tokio::task::spawn(async move {
let mut total_ops = num_adders * num_ops_per_adder;
while total_ops > 0 {
for (key, value) in ds_remover.zap_list(zap_obj).await.unwrap() {
for (key, value) in ds_remover.zap_list(zap_obj, usize::MAX).await.unwrap() {
ds_remover.zap_remove(zap_obj, &key).await.unwrap();
assert_eq!(key.as_bytes(), value.as_slice());
total_ops -= 1;
Expand Down
2 changes: 1 addition & 1 deletion zfs

0 comments on commit f21bd53

Please sign in to comment.