]> git.proxmox.com Git - pxar.git/commitdiff
add: interface to set goodbye table cache
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 29 Apr 2020 11:37:57 +0000 (13:37 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 29 Apr 2020 11:37:57 +0000 (13:37 +0200)
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
src/accessor.rs
src/accessor/sync.rs

index 761a03177afbb8d852e1aac084b4ad8497219cf8..b63223fca61397a6b3021de4628a49f2c1d70193 100644 (file)
@@ -100,6 +100,7 @@ impl<'a> ReadAt for &(dyn ReadAt + 'a) {
     }
 }
 
+#[derive(Clone)]
 struct Caches {
     /// The goodbye table cache maps goodbye table offsets to cache entries.
     gbt_cache: Option<Arc<dyn Cache<u64, [GoodbyeItem]> + Send + Sync>>,
@@ -140,6 +141,17 @@ impl<T: ReadAt> AccessorImpl<T> {
         )
         .await
     }
+
+    pub fn set_goodbye_table_cache(
+        &mut self,
+        cache: Option<Arc<dyn Cache<u64, [GoodbyeItem]> + Send + Sync>>,
+    ) {
+        let new_caches = Arc::new(Caches {
+            gbt_cache: cache,
+            ..*self.caches
+        });
+        self.caches = new_caches;
+    }
 }
 
 impl<T: Clone + ReadAt> AccessorImpl<T> {
index b88cd242327c615ffafecb633c5e79a9c5a14db0..5ecd7e9dd76fa7cb512ed9a9c0a251d7fb502023 100644 (file)
@@ -4,10 +4,12 @@ use std::io;
 use std::os::unix::fs::FileExt;
 use std::path::Path;
 use std::pin::Pin;
+use std::sync::Arc;
 use std::task::{Context, Poll};
 
-use crate::accessor::{self, ReadAt};
+use crate::accessor::{self, cache::Cache, ReadAt};
 use crate::decoder::Decoder;
+use crate::format::GoodbyeItem;
 use crate::util::poll_result_once;
 use crate::Entry;
 
@@ -83,6 +85,14 @@ impl<T: ReadAt> Accessor<T> {
             self.inner.open_root_ref(),
         )?))
     }
+
+    pub fn set_goodbye_table_cache<C>(&mut self, cache: Option<C>)
+    where
+        C: Cache<u64, [GoodbyeItem]> + Send + Sync + 'static,
+    {
+        self.inner
+            .set_goodbye_table_cache(cache.map(|cache| Arc::new(cache) as _))
+    }
 }
 
 impl<T: Clone + ReadAt> Accessor<T> {