From eba599073104a8f6533d320b6454570a39264551 Mon Sep 17 00:00:00 2001 From: Vitali Lovich Date: Wed, 1 May 2024 07:13:33 -0700 Subject: [PATCH] WeakDmaFile was accidentally missing from exports Also missing were default and new constructor methods. --- glommio/src/io/dma_file.rs | 24 ++++++++++++++++++++++++ glommio/src/io/glommio_file.rs | 10 +++++++++- glommio/src/io/mod.rs | 2 +- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/glommio/src/io/dma_file.rs b/glommio/src/io/dma_file.rs index 334f5bf2a..47fbf1984 100644 --- a/glommio/src/io/dma_file.rs +++ b/glommio/src/io/dma_file.rs @@ -880,7 +880,31 @@ pub struct WeakDmaFile { pollable: PollableStatus, } +impl Default for WeakDmaFile { + fn default() -> Self { + Self::new() + } +} + impl WeakDmaFile { + /// Creates an empty reference that will never upgrade. + pub fn new() -> WeakDmaFile { + Self { + file: WeakGlommioFile::new(), + o_direct_alignment: 0, + max_sectors_size: 0, + max_segment_size: 0, + pollable: PollableStatus::Pollable, + } + } + + /// The number of strong references that still remain on the file. + /// If created via [Self::new], this will return 0. + pub fn strong_count(&self) -> usize { + self.file.strong_count() + } + + /// Returns an `Option` containing ownership over the file if the file hasn't been closed yet, otherwise None. pub fn upgrade(&self) -> Option { self.file.upgrade().map(|file| OwnedDmaFile { file, diff --git a/glommio/src/io/glommio_file.rs b/glommio/src/io/glommio_file.rs index b93c00087..6942e834a 100644 --- a/glommio/src/io/glommio_file.rs +++ b/glommio/src/io/glommio_file.rs @@ -437,7 +437,7 @@ impl From for OwnedGlommioFile { } } -#[derive(Debug, Clone)] +#[derive(Default, Debug, Clone)] pub(crate) struct WeakGlommioFile { pub(crate) fd: AWeak, pub(crate) path: Option, @@ -447,6 +447,14 @@ pub(crate) struct WeakGlommioFile { } impl WeakGlommioFile { + pub(crate) fn new() -> Self { + Self::default() + } + + pub(crate) fn strong_count(&self) -> usize { + self.fd.strong_count() + } + pub(crate) fn upgrade(&self) -> Option { self.fd.upgrade().map(|fd| OwnedGlommioFile { fd: Some(fd), diff --git a/glommio/src/io/mod.rs b/glommio/src/io/mod.rs index 1e9a2af22..0f49277b5 100644 --- a/glommio/src/io/mod.rs +++ b/glommio/src/io/mod.rs @@ -162,7 +162,7 @@ pub use self::{ }, bulk_io::{IoVec, MergedBufferLimit, ReadAmplificationLimit, ReadManyResult}, directory::Directory, - dma_file::{CloseResult, DmaFile, OwnedDmaFile}, + dma_file::{CloseResult, DmaFile, OwnedDmaFile, WeakDmaFile}, dma_file_stream::{ DmaStreamReader, DmaStreamReaderBuilder, DmaStreamWriter, DmaStreamWriterBuilder, },