mirror of
https://github.com/michael-yuji/xc.git
synced 2025-12-18 16:19:44 +01:00
fix copy_file_range usage. This function should be call in a loop
This commit is contained in:
@@ -489,3 +489,30 @@ impl FreeBSDCommandExt for std::process::Command {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn copy_file_range(source_fd: i32, s_offset: i64, dest_fd: i32, d_offset: i64, max_len: usize) -> nix::Result<usize> {
|
||||||
|
unsafe {
|
||||||
|
let mut source_offset = s_offset;
|
||||||
|
let mut dest_offset = d_offset;
|
||||||
|
let mut remaining_len = max_len;
|
||||||
|
let mut copied_len = 0usize;
|
||||||
|
loop {
|
||||||
|
match nix::libc::copy_file_range(source_fd, &mut source_offset, dest_fd, &mut dest_offset, remaining_len, 0) {
|
||||||
|
0 => {
|
||||||
|
break Ok(copied_len)
|
||||||
|
},
|
||||||
|
-1 => {
|
||||||
|
break Err(nix::Error::last())
|
||||||
|
},
|
||||||
|
m => {
|
||||||
|
assert!(m.is_positive());
|
||||||
|
let n = m as usize;
|
||||||
|
assert!(n <= remaining_len);
|
||||||
|
remaining_len -= n;
|
||||||
|
copied_len += n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -885,15 +885,9 @@ async fn fd_import(
|
|||||||
|
|
||||||
info!("import: content_type is {content_type}");
|
info!("import: content_type is {content_type}");
|
||||||
|
|
||||||
unsafe {
|
if let Err(error) = freebsd::copy_file_range(source_fd, 0, dest_fd, 0, file_len) {
|
||||||
freebsd::nix::libc::copy_file_range(
|
error!(error=error.to_string(), "copy_file_range failed");
|
||||||
source_fd,
|
return ipc_err(EIO, "failed to copyin archive")
|
||||||
std::ptr::null_mut(),
|
|
||||||
dest_fd,
|
|
||||||
std::ptr::null_mut(),
|
|
||||||
file_len,
|
|
||||||
0,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("copy_file_range done");
|
info!("copy_file_range done");
|
||||||
@@ -922,8 +916,8 @@ async fn fd_import(
|
|||||||
let diff_id = OciDigest::new_unchecked(output_lines[0].trim());
|
let diff_id = OciDigest::new_unchecked(output_lines[0].trim());
|
||||||
let archive_digest = OciDigest::new_unchecked(output_lines[1].trim());
|
let archive_digest = OciDigest::new_unchecked(output_lines[1].trim());
|
||||||
|
|
||||||
info!("diff_id: {diff_id}");
|
info!(diff_id=diff_id.as_str(), "diff_id");
|
||||||
info!("archive_digest: {archive_digest}");
|
info!(archive_digest=archive_digest.as_str(), "archive_digest");
|
||||||
|
|
||||||
let path = {
|
let path = {
|
||||||
let mut path = config.layers_dir.to_path_buf();
|
let mut path = config.layers_dir.to_path_buf();
|
||||||
|
|||||||
Reference in New Issue
Block a user