[pbs-devel] [PATCH v9 proxmox-backup 43/58] pxar: add optional payload input to mount archive

Christian Ebner c.ebner at proxmox.com
Wed Jun 5 12:54:01 CEST 2024


Allow to pass an optional input path to mount a split pxar archive
with dedicated payload data file.

Signed-off-by: Christian Ebner <c.ebner at proxmox.com>
---
changes since version 8:
- not present in previous version

 pbs-pxar-fuse/src/lib.rs | 14 +++++++++++++-
 pxar-bin/src/main.rs     | 27 ++++++++++++++++++++++-----
 2 files changed, 35 insertions(+), 6 deletions(-)

diff --git a/pbs-pxar-fuse/src/lib.rs b/pbs-pxar-fuse/src/lib.rs
index 377635b2a..780a4ddbe 100644
--- a/pbs-pxar-fuse/src/lib.rs
+++ b/pbs-pxar-fuse/src/lib.rs
@@ -61,12 +61,24 @@ impl Session {
         options: &OsStr,
         verbose: bool,
         mountpoint: &Path,
+        payload_input_path: Option<&Path>,
     ) -> Result<Self, Error> {
         // TODO: Add a buffered/caching ReadAt layer?
         let file = std::fs::File::open(archive_path)?;
         let file_size = file.metadata()?.len();
         let reader: Reader = Arc::new(accessor::sync::FileReader::new(file));
-        let accessor = Accessor::new(pxar::PxarVariant::Unified(reader), file_size).await?;
+        let accessor = if let Some(payload_input) = payload_input_path {
+            let payload_file = std::fs::File::open(payload_input)?;
+            let payload_size = payload_file.metadata()?.len();
+            let payload_reader: Reader = Arc::new(accessor::sync::FileReader::new(payload_file));
+            Accessor::new(
+                pxar::PxarVariant::Split(reader, (payload_reader, payload_size)),
+                file_size,
+            )
+            .await?
+        } else {
+            Accessor::new(pxar::PxarVariant::Unified(reader), file_size).await?
+        };
         Self::mount(accessor, options, verbose, mountpoint)
     }
 
diff --git a/pxar-bin/src/main.rs b/pxar-bin/src/main.rs
index 638ac00b6..85887a8ed 100644
--- a/pxar-bin/src/main.rs
+++ b/pxar-bin/src/main.rs
@@ -458,18 +458,34 @@ async fn create_archive(
                 optional: true,
                 default: false,
             },
+            "payload-input": {
+                description: "'ppxar' payload input data file to restore split archive.",
+                optional: true,
+            },
         },
     },
 )]
 /// Mount the archive to the provided mountpoint via FUSE.
-async fn mount_archive(archive: String, mountpoint: String, verbose: bool) -> Result<(), Error> {
+async fn mount_archive(
+    archive: String,
+    mountpoint: String,
+    verbose: bool,
+    payload_input: Option<String>,
+) -> Result<(), Error> {
     let archive = Path::new(&archive);
     let mountpoint = Path::new(&mountpoint);
     let options = OsStr::new("ro,default_permissions");
+    let payload_input = payload_input.map(|payload_input| PathBuf::from(payload_input));
 
-    let session = pbs_pxar_fuse::Session::mount_path(archive, options, verbose, mountpoint)
-        .await
-        .map_err(|err| format_err!("pxar mount failed: {}", err))?;
+    let session = pbs_pxar_fuse::Session::mount_path(
+        archive,
+        options,
+        verbose,
+        mountpoint,
+        payload_input.as_deref(),
+    )
+    .await
+    .map_err(|err| format_err!("pxar mount failed: {}", err))?;
 
     let mut interrupt = signal(SignalKind::interrupt())?;
 
@@ -576,7 +592,8 @@ fn main() {
             CliCommand::new(&API_METHOD_MOUNT_ARCHIVE)
                 .arg_param(&["archive", "mountpoint"])
                 .completion_cb("archive", complete_file_name)
-                .completion_cb("mountpoint", complete_file_name),
+                .completion_cb("mountpoint", complete_file_name)
+                .completion_cb("payload-input", complete_file_name),
         )
         .insert(
             "list",
-- 
2.39.2





More information about the pbs-devel mailing list