[pbs-devel] [PATCH backup 08/13] snapshot_reader: use Rc for structs that are not Send+Sync

Maximiliano Sandoval m.sandoval at proxmox.com
Mon Feb 12 14:17:33 CET 2024


Fixes the clippy lint:

```
warning: usage of an `Arc` that is not `Send` and `Sync`
   --> pbs-datastore/src/snapshot_reader.rs:156:52
    |
156 |                         self.current_index = Some((Arc::new(index), 0, order));
    |                                                    ^^^^^^^^^^^^^^^
    |
    = note: `Arc<Box<dyn IndexFile + Send>>` is not `Send` and `Sync` as:
    = note: - the trait `Sync` is not implemented for `Box<dyn IndexFile + Send>`
    = help: consider using an `Rc` instead. `Arc` does not provide benefits for non `Send` and `Sync` types
    = note: if you intend to use `Arc` with `Send` and `Sync` traits
    = note: wrap the inner type with a `Mutex` or implement `Send` and `Sync` for `Box<dyn IndexFile + Send>`
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#arc_with_non_send_sync
    = note: `#[warn(clippy::arc_with_non_send_sync)]` on by default
```

Signed-off-by: Maximiliano Sandoval <m.sandoval at proxmox.com>
---
 pbs-datastore/src/snapshot_reader.rs | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/pbs-datastore/src/snapshot_reader.rs b/pbs-datastore/src/snapshot_reader.rs
index ec7a48e5..816df310 100644
--- a/pbs-datastore/src/snapshot_reader.rs
+++ b/pbs-datastore/src/snapshot_reader.rs
@@ -1,6 +1,7 @@
 use std::fs::File;
 use std::os::unix::io::{AsRawFd, FromRawFd};
 use std::path::Path;
+use std::rc::Rc;
 use std::sync::Arc;
 
 use anyhow::{bail, Error};
@@ -126,7 +127,7 @@ pub struct SnapshotChunkIterator<'a, F: Fn(&[u8; 32]) -> bool> {
     todo_list: Vec<String>,
     skip_fn: F,
     #[allow(clippy::type_complexity)]
-    current_index: Option<(Arc<Box<dyn IndexFile + Send>>, usize, Vec<(usize, u64)>)>,
+    current_index: Option<(Rc<Box<dyn IndexFile + Send>>, usize, Vec<(usize, u64)>)>,
 }
 
 impl<'a, F: Fn(&[u8; 32]) -> bool> Iterator for SnapshotChunkIterator<'a, F> {
@@ -153,7 +154,7 @@ impl<'a, F: Fn(&[u8; 32]) -> bool> Iterator for SnapshotChunkIterator<'a, F> {
                         let order =
                             datastore.get_chunks_in_order(&*index, &self.skip_fn, |_| Ok(()))?;
 
-                        self.current_index = Some((Arc::new(index), 0, order));
+                        self.current_index = Some((Rc::new(index), 0, order));
                     } else {
                         return Ok(None);
                     }
-- 
2.39.2





More information about the pbs-devel mailing list