Skip to main content

SmartCopier

Struct SmartCopier 

Source
pub struct SmartCopier {
Show 19 fields pub ring: IoUring, pub buffer_pool: BufferPool, pub atomic_buffer_pool: Option<BufferPool>, pub async_fd: Arc<AsyncFd<RawFd>>, pub vdo_opt: bool, pub direct_io_ok: bool, pub source_caps: Arc<Capabilities>, pub target_caps: Arc<Capabilities>, pub vdo_stall_threshold: u32, pub barrier_callback: Option<Box<dyn Fn(u64) + Send + Sync>>, pub source_uncached: bool, pub target_uncached: bool, pub governor: Option<Arc<Governor>>, pub fsync_tracker: FsyncLatencyTracker, pub skip_fsync: bool, pub segment_stall_timeout_secs: u64, pub segment_overall_timeout_secs: u64, pub postcopy_ring: IoUring, pub postcopy_async_fd: Arc<AsyncFd<RawFd>>,
}
Expand description

Async copy engine backed by io_uring with auto-adaptive tier selection

Probes source/target capabilities and selects the fastest copy path: reflink (FICLONE), copy_file_range, sendfile, or pipelined io_uring.

Fields§

§ring: IoUring

io_uring instance for async I/O submission

§buffer_pool: BufferPool

Registered buffer pool for io_uring fixed-buffer reads/writes

§atomic_buffer_pool: Option<BufferPool>

Separate aligned buffer pool for hardware atomic writes (RWF_ATOMIC)

§async_fd: Arc<AsyncFd<RawFd>>

Async wrapper around the io_uring eventfd for tokio integration

§vdo_opt: bool

Enable VDO zero-block optimization (punch holes for all-zero blocks)

§direct_io_ok: bool

Whether O_DIRECT is safe on the target filesystem

§source_caps: Arc<Capabilities>

Detected capabilities of the source filesystem

§target_caps: Arc<Capabilities>

Detected capabilities of the target filesystem

§vdo_stall_threshold: u32

Number of consecutive zero blocks before triggering VDO stall warning

§barrier_callback: Option<Box<dyn Fn(u64) + Send + Sync>>

Optional callback invoked after each file copy with the target inode

§source_uncached: bool

Use RWF_UNCACHED for source reads

§target_uncached: bool

Use RWF_UNCACHED for target writes

§governor: Option<Arc<Governor>>

PSI-based system stress governor

§fsync_tracker: FsyncLatencyTracker

Adaptive fsync timeout tracker

§skip_fsync: bool

Skip fsync after writes (for batch operations that fsync at the end)

§segment_stall_timeout_secs: u64

Seconds without progress before declaring a segment stall

§segment_overall_timeout_secs: u64

Maximum seconds for an entire segment copy before timeout

§postcopy_ring: IoUring

Separate io_uring ring for postcopy operations (rename, fsync, unlink, link, symlink, truncate, statx). Uses IORING_SETUP_ATTACH_WQ to share the kernel async worker pool with ring.

§postcopy_async_fd: Arc<AsyncFd<RawFd>>

Async eventfd wrapper for the postcopy ring.

Implementations§

Source§

impl SmartCopier

Stat a path via io_uring Statx requesting only STATX_NLINK, returning the hard-link count. Falls back to spawn_blocking(std::fs::metadata) when the kernel returns EOPNOTSUPP or EINVAL (e.g. older kernels, NFS).

Source§

impl SmartCopier

Source

pub async fn copy( src: &Path, dst: &Path, ring: &mut IoUring, buffer_pool: &mut BufferPool, atomic_pool: Option<&mut BufferPool>, async_fd: Arc<AsyncFd<RawFd>>, vdo_opt: bool, offset: u64, length: u64, direct_io_ok: bool, src_file_size: u64, source_caps: &Arc<Capabilities>, target_caps: &Arc<Capabilities>, vdo_stall_threshold: u32, source_uncached: bool, target_uncached: bool, barrier_callback: &Option<Box<dyn Fn(u64) + Send + Sync>>, governor: Option<Arc<Governor>>, target_label: String, fsync_tracker: &mut FsyncLatencyTracker, skip_fsync: bool, segment_stall_timeout_secs: u64, segment_overall_timeout_secs: u64, is_sparse: bool, postcopy_ring: &mut IoUring, postcopy_async_fd: &Arc<AsyncFd<RawFd>>, ) -> Result<CopyStats>

Copy a file (or range) from src to dst using the full io_uring pipeline

Source

pub async fn copy_with_limit( src: &Path, dst: &Path, ring: &mut IoUring, buffer_pool: &mut BufferPool, atomic_pool: Option<&mut BufferPool>, async_fd: Arc<AsyncFd<RawFd>>, vdo_opt: bool, offset: u64, length: u64, direct_io_ok: bool, src_file_size: u64, source_caps: &Arc<Capabilities>, target_caps: &Arc<Capabilities>, vdo_stall_threshold: u32, source_uncached: bool, target_uncached: bool, barrier_callback: &Option<Box<dyn Fn(u64) + Send + Sync>>, governor: Option<Arc<Governor>>, target_label: String, fsync_tracker: &mut FsyncLatencyTracker, buffer_limit: Option<usize>, skip_fsync: bool, segment_stall_timeout_secs: u64, segment_overall_timeout_secs: u64, is_sparse: bool, postcopy_ring: &mut IoUring, postcopy_async_fd: &Arc<AsyncFd<RawFd>>, ) -> Result<CopyStats>

Copy with an optional buffer count limit for backpressure control

Source§

impl SmartCopier

Source

pub async fn copy_delta( &mut self, src: &Path, dst: &Path, dirty_ranges: &[DirtyRange], file_size: u64, label: &str, ) -> Result<CopyStats>

Copy only the specified dirty ranges from src to dst. Each DirtyRange triggers an optimized_copy_range() call.

Trait Implementations§

Source§

impl OptimizedFs for SmartCopier

Source§

fn optimized_copy( &mut self, src: PathBuf, dst: PathBuf, src_file_size: u64, target_label: String, buffer_limit: Option<usize>, skip_fsync: bool, is_sparse: bool, ) -> impl Future<Output = Result<CopyStats>> + Send

Copy an entire file, choosing reflink/sendfile/io_uring as appropriate
Source§

fn optimized_rename( &mut self, src: PathBuf, dst: PathBuf, flags: u32, ) -> impl Future<Output = Result<CopyStats>> + Send

Rename a file with optional flags (e.g. RENAME_EXCHANGE)
Source§

fn optimized_copy_range( &mut self, src: PathBuf, dst: PathBuf, offset: u64, length: u64, src_file_size: u64, target_label: String, buffer_limit: Option<usize>, skip_fsync: bool, ) -> impl Future<Output = Result<CopyStats>> + Send

Copy a byte range within a file (used for Merkle delta resync)
Source§

fn optimized_truncate( &mut self, dst: PathBuf, size: u64, ) -> impl Future<Output = Result<CopyStats>> + Send

Truncate a file to the given size
Source§

fn optimized_fallocate( &mut self, dst: PathBuf, mode: i32, offset: u64, length: u64, ) -> impl Future<Output = Result<CopyStats>> + Send

Allocate or punch holes in a file
Unlink a file or remove a directory via io_uring UnlinkAt (AT_REMOVEDIR for dirs). Falls back to spawn_blocking on EOPNOTSUPP.
Create a hard link via io_uring LinkAt. Falls back to spawn_blocking on EOPNOTSUPP.
Create a symbolic link via io_uring SymlinkAt. Falls back to spawn_blocking on EOPNOTSUPP.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more