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 F2C218DE6C; Thu, 10 Nov 2022 11:37:10 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id CB78D250B1; Thu, 10 Nov 2022 11:36:40 +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; Thu, 10 Nov 2022 11:36:38 +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 9F234437AC; Thu, 10 Nov 2022 11:36:35 +0100 (CET) From: Dominik Csapak To: pve-devel@lists.proxmox.com, pbs-devel@lists.proxmox.com Date: Thu, 10 Nov 2022 11:36:29 +0100 Message-Id: <20221110103634.2177856-2-d.csapak@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221110103634.2177856-1-d.csapak@proxmox.com> References: <20221110103634.2177856-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.065 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% 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 Subject: [pbs-devel] [PATCH proxmox-backup v4 1/1] file-restore: make dynamic memory behaviour controllable 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: Thu, 10 Nov 2022 10:37:11 -0000 by adding 'dynamic-memory' parameter that controls if we automatically increase the memory of the guest vm or not Signed-off-by: Dominik Csapak --- new in v4 not really happy with the 'clippy allow', but imho there is no obvious way to bundle those parameters without restructuring the code much proxmox-file-restore/src/block_driver.rs | 10 +++- proxmox-file-restore/src/block_driver_qemu.rs | 6 ++- proxmox-file-restore/src/main.rs | 54 +++++++++++++++++-- 3 files changed, 61 insertions(+), 9 deletions(-) diff --git a/proxmox-file-restore/src/block_driver.rs b/proxmox-file-restore/src/block_driver.rs index 01cc4e18..ad2da5fb 100644 --- a/proxmox-file-restore/src/block_driver.rs +++ b/proxmox-file-restore/src/block_driver.rs @@ -43,6 +43,7 @@ pub trait BlockRestoreDriver { details: SnapRestoreDetails, img_file: String, path: Vec, + dynamic_memory: bool, ) -> Async, Error>>; /// pxar=true: @@ -57,6 +58,7 @@ pub trait BlockRestoreDriver { path: Vec, format: Option, zstd: bool, + dynamic_memory: bool, ) -> Async, Error>>; /// Return status of all running/mapped images, result value is (id, extra data), where id must @@ -92,9 +94,12 @@ pub async fn data_list( details: SnapRestoreDetails, img_file: String, path: Vec, + dynamic_memory: bool, ) -> Result, Error> { let driver = driver.unwrap_or(DEFAULT_DRIVER).resolve(); - driver.data_list(details, img_file, path).await + driver + .data_list(details, img_file, path, dynamic_memory) + .await } pub async fn data_extract( @@ -104,10 +109,11 @@ pub async fn data_extract( path: Vec, format: Option, zstd: bool, + dynamic_memory: bool, ) -> Result, Error> { let driver = driver.unwrap_or(DEFAULT_DRIVER).resolve(); driver - .data_extract(details, img_file, path, format, zstd) + .data_extract(details, img_file, path, format, zstd, dynamic_memory) .await } diff --git a/proxmox-file-restore/src/block_driver_qemu.rs b/proxmox-file-restore/src/block_driver_qemu.rs index c2cd8d49..ef0e88a5 100644 --- a/proxmox-file-restore/src/block_driver_qemu.rs +++ b/proxmox-file-restore/src/block_driver_qemu.rs @@ -218,13 +218,14 @@ impl BlockRestoreDriver for QemuBlockDriver { details: SnapRestoreDetails, img_file: String, mut path: Vec, + dynamic_memory: bool, ) -> Async, Error>> { async move { let (cid, client) = ensure_running(&details).await?; if !path.is_empty() && path[0] != b'/' { path.insert(0, b'/'); } - if path_is_zfs(&path) { + if path_is_zfs(&path) && dynamic_memory { if let Err(err) = set_dynamic_memory(cid, None).await { log::error!("could not increase memory: {err}"); } @@ -245,13 +246,14 @@ impl BlockRestoreDriver for QemuBlockDriver { mut path: Vec, format: Option, zstd: bool, + dynamic_memory: bool, ) -> Async, Error>> { async move { let (cid, client) = ensure_running(&details).await?; if !path.is_empty() && path[0] != b'/' { path.insert(0, b'/'); } - if path_is_zfs(&path) { + if path_is_zfs(&path) && dynamic_memory { if let Err(err) = set_dynamic_memory(cid, None).await { log::error!("could not increase memory: {err}"); } diff --git a/proxmox-file-restore/src/main.rs b/proxmox-file-restore/src/main.rs index 105dc079..4af49f52 100644 --- a/proxmox-file-restore/src/main.rs +++ b/proxmox-file-restore/src/main.rs @@ -96,6 +96,7 @@ fn keyfile_path(param: &Value) -> Option { None } +#[allow(clippy::too_many_arguments)] async fn list_files( repo: BackupRepository, namespace: BackupNamespace, @@ -104,6 +105,7 @@ async fn list_files( crypt_config: Option>, keyfile: Option, driver: Option, + dynamic_memory: bool, ) -> Result, Error> { let client = connect(&repo)?; let client = BackupReader::start( @@ -170,7 +172,7 @@ async fn list_files( snapshot, keyfile, }; - data_list(driver, details, file, path).await + data_list(driver, details, file, path, dynamic_memory).await } } } @@ -226,6 +228,12 @@ async fn list_files( minimum: 1, optional: true, }, + "dynamic-memory": { + type: Boolean, + description: "If enabled, automatically increases memory for started vms in case of accessing a zpool inside.", + default: false, + optional: true, + }, } }, returns: { @@ -243,6 +251,7 @@ async fn list( path: String, base64: bool, timeout: Option, + dynamic_memory: bool, param: Value, ) -> Result<(), Error> { let repo = extract_repository_from_value(¶m)?; @@ -272,7 +281,16 @@ async fn list( let result = if let Some(timeout) = timeout { match tokio::time::timeout( std::time::Duration::from_secs(timeout), - list_files(repo, ns, snapshot, path, crypt_config, keyfile, driver), + list_files( + repo, + ns, + snapshot, + path, + crypt_config, + keyfile, + driver, + dynamic_memory, + ), ) .await { @@ -280,7 +298,17 @@ async fn list( Err(_) => Err(http_err!(SERVICE_UNAVAILABLE, "list not finished in time")), } } else { - list_files(repo, ns, snapshot, path, crypt_config, keyfile, driver).await + list_files( + repo, + ns, + snapshot, + path, + crypt_config, + keyfile, + driver, + dynamic_memory, + ) + .await }; let output_format = get_output_format(¶m); @@ -387,6 +415,12 @@ async fn list( type: BlockDriverType, optional: true, }, + "dynamic-memory": { + type: Boolean, + description: "If enabled, automatically increases memory for started vms in case of accessing a zpool inside.", + default: false, + optional: true, + }, } } )] @@ -400,6 +434,7 @@ async fn extract( target: Option, format: Option, zstd: bool, + dynamic_memory: bool, param: Value, ) -> Result<(), Error> { let repo = extract_repository_from_value(¶m)?; @@ -481,6 +516,7 @@ async fn extract( path.clone(), Some(FileRestoreFormat::Pxar), false, + dynamic_memory, ) .await?; let decoder = Decoder::from_tokio(reader).await?; @@ -493,8 +529,16 @@ async fn extract( format_err!("unable to remove temporary .pxarexclude-cli file - {}", e) })?; } else { - let mut reader = - data_extract(driver, details, file, path.clone(), format, zstd).await?; + let mut reader = data_extract( + driver, + details, + file, + path.clone(), + format, + zstd, + dynamic_memory, + ) + .await?; tokio::io::copy(&mut reader, &mut tokio::io::stdout()).await?; } } -- 2.30.2