pub struct RootDirCache<S> { /* private fields */ }Expand description
RootDirCache is a cache of Arc<impl Deref<Target = RootDir>>s indexed by their hash.
The cache internally stores Weaks and drops the corresponding entry when the last Arc is
dropped, so it is a cache of Arcs that are actively in use by its clients. This is useful for
deduplicating the RootDirs used by VFS to serve package directory connections while also
keeping track of which connections are open.
Due to RootDir’s VFS implementation, a package will have alive Arcs if there are
fuchsia.io.Directory connections to the package’s root directory or any sub directory.
This does not keep track of fuchsia.io.File connections made to a RootDirs files (files under
meta/, files not under meta/, and the meta file) but both Blobfs and Fxblob will wait to delete
blobs that have open connections or VMOs until the last one closes, so it is safe to delete
packages that are not in the RootDirCache.
Clients close connections to packages by closing their end of the Zircon channel over which the
fuchsia.io.Directory messages were being sent. Some time after the client end of the channel is
closed, the server (usually in a different process) will be notified by the kernel, and the VFS
task serving the connection will finish, dropping its Arc. When the last Arc is dropped, the
strong count of the corresponding std::sync::Weak in the RootDirCache will decrement to
zero. At this point the RootDirCache will no longer report the package as open.
All this is to say that there will be some delay between a package no longer being in use and
clients of RootDirCache finding out about that.
Implementations§
Source§impl<S: NonMetaStorage + Clone> RootDirCache<S>
impl<S: NonMetaStorage + Clone> RootDirCache<S>
Sourcepub fn new(non_meta_storage: S) -> Self
pub fn new(non_meta_storage: S) -> Self
Creates a RootDirCache that uses non_meta_storage as the backing for the
internally managed crate::RootDirs.
Sourcepub async fn get_or_insert(
&self,
hash: Hash,
root_dir: Option<RootDir<S>>,
) -> Result<Arc<CachedRootDir<S>>, Error>
pub async fn get_or_insert( &self, hash: Hash, root_dir: Option<RootDir<S>>, ) -> Result<Arc<CachedRootDir<S>>, Error>
Returns an Arc<CachedRootDir> corresponding to hash.
If there is not already one in the cache, root_dir will be used if provided, otherwise
a new one will be created using the non_meta_storage provided to Self::new.
If provided, root_dir must be backed by the same NonMetaStorage that Self::new was
called with.
Sourcepub fn get(&self, hash: &Hash) -> Option<Arc<CachedRootDir<S>>>
pub fn get(&self, hash: &Hash) -> Option<Arc<CachedRootDir<S>>>
Returns the Arc<CachedRootDir> with the given hash, if one exists in the cache.
Otherwise returns None.
Holding on to the returned Arc will keep the package open (as reported by
Self::list).
Sourcepub fn list(&self) -> Vec<Arc<CachedRootDir<S>>>
pub fn list(&self) -> Vec<Arc<CachedRootDir<S>>>
Packages with live Arc<CachedRootDir>s.
Holding on to the returned Arcs will keep the packages open.
Trait Implementations§
Source§impl<S: Clone> Clone for RootDirCache<S>
impl<S: Clone> Clone for RootDirCache<S>
Auto Trait Implementations§
impl<S> Freeze for RootDirCache<S>where
S: Freeze,
impl<S> RefUnwindSafe for RootDirCache<S>where
S: RefUnwindSafe,
impl<S> Send for RootDirCache<S>
impl<S> Sync for RootDirCache<S>
impl<S> Unpin for RootDirCache<S>where
S: Unpin,
impl<S> UnsafeUnpin for RootDirCache<S>where
S: UnsafeUnpin,
impl<S> UnwindSafe for RootDirCache<S>where
S: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, D> Encode<Ambiguous1, D> for Twhere
D: ResourceDialect,
impl<T, D> Encode<Ambiguous1, D> for Twhere
D: ResourceDialect,
Source§impl<T, D> Encode<Ambiguous2, D> for Twhere
D: ResourceDialect,
impl<T, D> Encode<Ambiguous2, D> for Twhere
D: ResourceDialect,
§impl<F, N> FidlIntoNative<Box<N>> for Fwhere
F: FidlIntoNative<N>,
impl<F, N> FidlIntoNative<Box<N>> for Fwhere
F: FidlIntoNative<N>,
fn fidl_into_native(self) -> Box<N>
§impl<T> InstanceFromServiceTransport<T> for T
impl<T> InstanceFromServiceTransport<T> for T
§fn from_service_transport(handle: T) -> T
fn from_service_transport(handle: T) -> T
T to [Self]Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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