Skip to content

Commit

Permalink
fallocate: deallocate pages but still seg fault on remove and cannot …
Browse files Browse the repository at this point in the history
…read
  • Loading branch information
DevonSchwartz authored and hayley-leblanc committed Aug 26, 2024
1 parent c861cf4 commit 39dc359
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions linux/fs/squirrelfs/h_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,7 @@ impl file::Operations for FileOps {

// zero out the first page that is partial
if start_page_offset < offset {
pr_info!("Start");
pr_info!("{:?}", start_page_offset);
let partial_start_length = if page_size - (offset % page_size) > len {len} else {page_size - (offset % page_size)};
pr_info!("{:?}", partial_start_length);
let pages = DataPageListWrapper::get_data_page_list(pi.get_inode_info()?, partial_start_length.try_into()?, offset.try_into()?)?;
let (_bytes_written, pages) = match pages {
Ok(pages) => {
Expand All @@ -188,27 +185,35 @@ impl file::Operations for FileOps {
pages.fence();
}

pr_info!("{:?}, {:?}", end_page_offset, end_offset);
// zero out end page that is partial
if end_page_offset > end_offset {
pr_info!("End");
let partial_end_length = end_offset % page_size;
let partial_end_offset = if end_page_offset - page_size > offset {end_page_offset - page_size} else {offset};
pr_info!("{:?}, {:?}", partial_end_length, partial_end_offset);
let pages = DataPageListWrapper::get_data_page_list(pi.get_inode_info()?, partial_end_length.try_into()?,
partial_end_offset.try_into()?)?;
let (_bytes_written, pages) = match pages {
Ok(pages) => {
pr_info!("here");
let (bytes_written, pages) = pages.zero_pages(sbi, partial_end_length.try_into()?, partial_end_offset.try_into()?)?;
end_page -= 1;
pr_info!("");
(bytes_written, pages)
},
Err(e) => return Err(EINVAL),
};
pages.fence();
}

if start_page <= end_page {
let full_pages_offset = start_page * page_size;
let full_pages_length = (end_page - start_page + 1) * page_size;
let (new_size, pi) = pi.dec_size(initial_size.try_into()?);
let pages = DataPageListWrapper::get_data_pages_to_truncate(&pi, full_pages_length.try_into()?,
full_pages_offset.try_into()?)?;
let pages = pages.unmap(sbi)?.fence();
let pages = pages.dealloc(sbi)?.fence().mark_free();
sbi.page_allocator.dealloc_data_page_list(&pages)?;
let pi_info = pi.get_inode_info()?;
pi_info.remove_pages(&pages)?;
}
}
Ok(1)
}
Expand Down

0 comments on commit 39dc359

Please sign in to comment.