From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 9511B97EE9 for ; Wed, 6 Mar 2024 15:34:30 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 7E6701A519 for ; Wed, 6 Mar 2024 15:34:30 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Wed, 6 Mar 2024 15:34:29 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 87F3148843 for ; Wed, 6 Mar 2024 15:34:29 +0100 (CET) From: Gabriel Goller To: pbs-devel@lists.proxmox.com Date: Wed, 6 Mar 2024 15:34:13 +0100 Message-ID: <20240306143422.114335-4-g.goller@proxmox.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240306143422.114335-1-g.goller@proxmox.com> References: <20240306143422.114335-1-g.goller@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.095 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - Subject: [pbs-devel] [PATCH proxmox-backup 3/3] pxar: added creation parameters X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 06 Mar 2024 14:34:30 -0000 This adds support for the creation parameters and the `.pxar_creation_params` file into the `pxar` binary. Signed-off-by: Gabriel Goller --- pxar-bin/Cargo.toml | 1 + pxar-bin/src/main.rs | 68 +++++++++++++++++++++++++++----------------- 2 files changed, 43 insertions(+), 26 deletions(-) diff --git a/pxar-bin/Cargo.toml b/pxar-bin/Cargo.toml index d91c03d3..4ed5c29a 100644 --- a/pxar-bin/Cargo.toml +++ b/pxar-bin/Cargo.toml @@ -13,6 +13,7 @@ anyhow.workspace = true futures.workspace = true log.workspace = true nix.workspace = true +serde.workspace = true serde_json.workspace = true tokio = { workspace = true, features = [ "rt", "rt-multi-thread" ] } diff --git a/pxar-bin/src/main.rs b/pxar-bin/src/main.rs index 277d0b46..f0db2440 100644 --- a/pxar-bin/src/main.rs +++ b/pxar-bin/src/main.rs @@ -9,6 +9,7 @@ use std::sync::Arc; use anyhow::{bail, format_err, Error}; use futures::future::FutureExt; use futures::select; +use serde_json::Value; use tokio::signal::unix::{signal, SignalKind}; use pathpatterns::{MatchEntry, MatchType, PatternFlag}; @@ -234,46 +235,71 @@ fn extract_archive( Ok(()) } +#[derive(serde::Deserialize)] +#[serde(rename_all = "kebab-case")] +struct CreateArchiveParams { + archive: String, + source: String, + no_xattrs: Option, + no_fcaps: Option, + no_acls: Option, + all_file_systems: Option, + no_device_nodes: Option, + no_fifos: Option, + no_sockets: Option, + exclude: Option>, + entries_max: Option, +} + #[api( input: { properties: { archive: { + type: String, description: "Archive name.", }, source: { + type: String, description: "Source directory.", }, "no-xattrs": { + type: Boolean, description: "Ignore extended file attributes.", optional: true, default: false, }, "no-fcaps": { + type: Boolean, description: "Ignore file capabilities.", optional: true, default: false, }, "no-acls": { + type: Boolean, description: "Ignore access control list entries.", optional: true, default: false, }, "all-file-systems": { + type: Boolean, description: "Include mounted sudirs.", optional: true, default: false, }, "no-device-nodes": { + type: Boolean, description: "Ignore device nodes.", optional: true, default: false, }, "no-fifos": { + type: Boolean, description: "Ignore fifos.", optional: true, default: false, }, "no-sockets": { + type: Boolean, description: "Ignore sockets.", optional: true, default: false, @@ -288,6 +314,7 @@ fn extract_archive( }, }, "entries-max": { + type: Integer, description: "Max number of entries loaded at once into memory", optional: true, default: ENCODER_MAX_ENTRIES as isize, @@ -298,22 +325,11 @@ fn extract_archive( }, )] /// Create a new .pxar archive. -#[allow(clippy::too_many_arguments)] -async fn create_archive( - archive: String, - source: String, - no_xattrs: bool, - no_fcaps: bool, - no_acls: bool, - all_file_systems: bool, - no_device_nodes: bool, - no_fifos: bool, - no_sockets: bool, - exclude: Option>, - entries_max: isize, -) -> Result<(), Error> { +async fn create_archive(param: Value) -> Result<(), Error> { + let params: CreateArchiveParams = serde_json::from_value(param.clone()).unwrap(); + let patterns = { - let input = exclude.unwrap_or_default(); + let input = params.exclude.unwrap_or_default(); let mut patterns = Vec::with_capacity(input.len()); for entry in input { patterns.push( @@ -324,21 +340,21 @@ async fn create_archive( patterns }; - let device_set = if all_file_systems { + let device_set = if params.all_file_systems.unwrap_or(false) { None } else { Some(HashSet::new()) }; let options = pbs_client::pxar::PxarCreateOptions { - entries_max: entries_max as usize, + entries_max: params.entries_max.unwrap_or(ENCODER_MAX_ENTRIES as isize) as usize, device_set, patterns, skip_lost_and_found: false, skip_e2big_xattr: false, }; - let source = PathBuf::from(source); + let source = PathBuf::from(params.source); let dir = nix::dir::Dir::open( &source, @@ -350,26 +366,26 @@ async fn create_archive( .create_new(true) .write(true) .mode(0o640) - .open(archive)?; + .open(params.archive)?; let writer = std::io::BufWriter::with_capacity(1024 * 1024, file); let mut feature_flags = Flags::DEFAULT; - if no_xattrs { + if params.no_xattrs.unwrap_or(false) { feature_flags.remove(Flags::WITH_XATTRS); } - if no_fcaps { + if params.no_fcaps.unwrap_or(false) { feature_flags.remove(Flags::WITH_FCAPS); } - if no_acls { + if params.no_acls.unwrap_or(false) { feature_flags.remove(Flags::WITH_ACL); } - if no_device_nodes { + if params.no_device_nodes.unwrap_or(false) { feature_flags.remove(Flags::WITH_DEVICE_NODES); } - if no_fifos { + if params.no_fifos.unwrap_or(false) { feature_flags.remove(Flags::WITH_FIFOS); } - if no_sockets { + if params.no_sockets.unwrap_or(false) { feature_flags.remove(Flags::WITH_SOCKETS); } @@ -384,7 +400,7 @@ async fn create_archive( }, None, options, - "".to_string(), + param.to_string(), ) .await?; -- 2.43.0