]> git.proxmox.com Git - proxmox-backup.git/commitdiff
file-restore: make dynamic memory behaviour controllable
authorDominik Csapak <d.csapak@proxmox.com>
Thu, 10 Nov 2022 10:36:29 +0000 (11:36 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 11 Nov 2022 09:21:49 +0000 (10:21 +0100)
by adding 'dynamic-memory' parameter that controls if we automatically
increase the memory of the guest vm or not

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
proxmox-file-restore/src/block_driver.rs
proxmox-file-restore/src/block_driver_qemu.rs
proxmox-file-restore/src/main.rs

index 01cc4e18038e1343f0480a8aa99f3300c8ababea..ad2da5fb3c83f8642c167925795be5c8b7a2870a 100644 (file)
@@ -43,6 +43,7 @@ pub trait BlockRestoreDriver {
         details: SnapRestoreDetails,
         img_file: String,
         path: Vec<u8>,
+        dynamic_memory: bool,
     ) -> Async<Result<Vec<ArchiveEntry>, Error>>;
 
     /// pxar=true:
@@ -57,6 +58,7 @@ pub trait BlockRestoreDriver {
         path: Vec<u8>,
         format: Option<FileRestoreFormat>,
         zstd: bool,
+        dynamic_memory: bool,
     ) -> Async<Result<Box<dyn tokio::io::AsyncRead + Unpin + Send>, 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<u8>,
+    dynamic_memory: bool,
 ) -> Result<Vec<ArchiveEntry>, 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<u8>,
     format: Option<FileRestoreFormat>,
     zstd: bool,
+    dynamic_memory: bool,
 ) -> Result<Box<dyn tokio::io::AsyncRead + Send + Unpin>, 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
 }
 
index c2cd8d49e12fb5162642a06ed76a991077c10137..ef0e88a51ac7982a61650d1f7a21f0edd1bdaf9a 100644 (file)
@@ -218,13 +218,14 @@ impl BlockRestoreDriver for QemuBlockDriver {
         details: SnapRestoreDetails,
         img_file: String,
         mut path: Vec<u8>,
+        dynamic_memory: bool,
     ) -> Async<Result<Vec<ArchiveEntry>, 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<u8>,
         format: Option<FileRestoreFormat>,
         zstd: bool,
+        dynamic_memory: bool,
     ) -> Async<Result<Box<dyn tokio::io::AsyncRead + Unpin + Send>, 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}");
                 }
index 2f941e5aa9eab02d675170d0c401c3f98f0f0fd8..201b5afa4c5eb3e99bbd7dabb604b448266e93d0 100644 (file)
@@ -96,6 +96,7 @@ fn keyfile_path(param: &Value) -> Option<String> {
     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<Arc<CryptConfig>>,
     keyfile: Option<String>,
     driver: Option<BlockDriverType>,
+    dynamic_memory: bool,
 ) -> Result<Vec<ArchiveEntry>, 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<u64>,
+    dynamic_memory: bool,
     param: Value,
 ) -> Result<(), Error> {
     let repo = extract_repository_from_value(&param)?;
@@ -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(&param);
@@ -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<String>,
     format: Option<FileRestoreFormat>,
     zstd: bool,
+    dynamic_memory: bool,
     param: Value,
 ) -> Result<(), Error> {
     let repo = extract_repository_from_value(&param)?;
@@ -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?;
             }
         }