all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Christian Ebner <c.ebner@proxmox.com>
To: pbs-devel@lists.proxmox.com, pve-devel@lists.proxmox.com
Subject: [PATCH proxmox-backup-qemu v2 5/8] restore: implement `bw-limit` parameter imposing download rate limits
Date: Wed, 16 Sep 2026 16:48:40 +0200	[thread overview]
Message-ID: <20260916144843.567913-6-c.ebner@proxmox.com> (raw)
In-Reply-To: <20260916144843.567913-1-c.ebner@proxmox.com>

Add an optional `bw-limit` parameter to allow setting a download
bandwidth limit for pbs-restore. Since this is a breaking api change,
expose this in the public api as new function and refactor to keep
common code deduplicated.

Subsequently this new API function will be extend further by a
additional parameter.

Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
---
 Cargo.toml     |  1 +
 current-api.h  | 13 +++++++++++++
 src/lib.rs     | 49 +++++++++++++++++++++++++++++++++++++++++++++++--
 src/restore.rs |  9 +++++++--
 4 files changed, 68 insertions(+), 4 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml
index d73324f..8b01ee0 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -32,6 +32,7 @@ once_cell = "1.5"
 openssl = "0.10"
 
 proxmox-async = "0.5"
+proxmox-human-byte = "1"
 proxmox-lang = "1"
 proxmox-schema = { version = "5", features = [ "api-macro" ] }
 proxmox-sortable-macro = "1"
diff --git a/current-api.h b/current-api.h
index 60d7558..b9a3a44 100644
--- a/current-api.h
+++ b/current-api.h
@@ -319,6 +319,19 @@ struct ProxmoxRestoreHandle *proxmox_restore_new_ns(const char *repo,
                                                     const char *fingerprint,
                                                     char **error);
 
+/**
+ * Connect to the backup server for restore (sync)
+ */
+struct ProxmoxRestoreHandle *proxmox_restore_new_ns_rate_limited(const char *repo,
+                                                                 const char *snapshot,
+                                                                 const char *namespace_,
+                                                                 const char *password,
+                                                                 const char *keyfile,
+                                                                 const char *key_password,
+                                                                 const char *fingerprint,
+                                                                 const char *bw_limit,
+                                                                 char **error);
+
 /**
  * Open connection to the backup server (sync)
  *
diff --git a/src/lib.rs b/src/lib.rs
index 1d4ea21..4d4c28b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -3,12 +3,16 @@
 use anyhow::{format_err, Error};
 use std::ffi::CString;
 use std::os::raw::{c_char, c_int, c_long, c_uchar, c_void};
-use std::ptr;
+use std::ptr::{self, null};
 use std::sync::{Arc, Condvar, Mutex};
 
+use proxmox_human_byte::HumanByte;
 use proxmox_lang::try_block;
 
-use pbs_api_types::{Authid, BackupArchiveName, BackupDir, BackupNamespace, BackupType, CryptMode};
+use pbs_api_types::{
+    Authid, BackupArchiveName, BackupDir, BackupNamespace, BackupType, ClientRateLimitConfig,
+    CryptMode,
+};
 use pbs_client::BackupRepository;
 
 pub mod capi_types;
@@ -140,6 +144,7 @@ pub(crate) struct BackupSetup {
     pub key_password: Option<String>,
     pub master_keyfile: Option<std::path::PathBuf>,
     pub fingerprint: Option<String>,
+    pub inbound_rate_limit: Option<ClientRateLimitConfig>,
 }
 
 // helper class to implement synchronous interface
@@ -304,6 +309,7 @@ pub extern "C" fn proxmox_backup_new_ns(
             key_password,
             master_keyfile,
             fingerprint,
+            inbound_rate_limit: None,
         };
 
         BackupTask::new(setup, compress, crypt_mode)
@@ -816,6 +822,7 @@ pub extern "C" fn proxmox_restore_new(
             key_password,
             master_keyfile: None,
             fingerprint,
+            inbound_rate_limit: None,
         };
 
         RestoreTask::new(setup)
@@ -842,6 +849,33 @@ pub extern "C" fn proxmox_restore_new_ns(
     key_password: *const c_char,
     fingerprint: *const c_char,
     error: *mut *mut c_char,
+) -> *mut ProxmoxRestoreHandle {
+    proxmox_restore_new_ns_rate_limited(
+        repo,
+        snapshot,
+        namespace,
+        password,
+        keyfile,
+        key_password,
+        fingerprint,
+        null(),
+        error,
+    )
+}
+
+/// Connect to the backup server for restore (sync)
+#[no_mangle]
+#[allow(clippy::not_unsafe_ptr_arg_deref)]
+pub extern "C" fn proxmox_restore_new_ns_rate_limited(
+    repo: *const c_char,
+    snapshot: *const c_char,
+    namespace: *const c_char,
+    password: *const c_char,
+    keyfile: *const c_char,
+    key_password: *const c_char,
+    fingerprint: *const c_char,
+    bw_limit: *const c_char,
+    error: *mut *mut c_char,
 ) -> *mut ProxmoxRestoreHandle {
     let result: Result<_, Error> = try_block!({
         let repo: BackupRepository = tools::utf8_c_string(repo)?
@@ -862,6 +896,16 @@ pub extern "C" fn proxmox_restore_new_ns(
         let keyfile = tools::utf8_c_string(keyfile)?.map(std::path::PathBuf::from);
         let key_password = tools::utf8_c_string(key_password)?;
         let fingerprint = tools::utf8_c_string(fingerprint)?;
+        let inbound_rate_limit = match tools::utf8_c_string(bw_limit)? {
+            Some(rate_limit) => {
+                let rate_limit: HumanByte = rate_limit.parse()?;
+                Some(ClientRateLimitConfig {
+                    rate: Some(rate_limit),
+                    burst: None,
+                })
+            }
+            None => None,
+        };
 
         let setup = BackupSetup {
             host: repo.host().to_owned(),
@@ -876,6 +920,7 @@ pub extern "C" fn proxmox_restore_new_ns(
             key_password,
             master_keyfile: None,
             fingerprint,
+            inbound_rate_limit,
         };
 
         RestoreTask::new(setup)
diff --git a/src/restore.rs b/src/restore.rs
index 8f518bc..c6c1c9c 100644
--- a/src/restore.rs
+++ b/src/restore.rs
@@ -8,7 +8,7 @@ use tokio::runtime::Runtime;
 
 use proxmox_async::runtime::get_runtime_with_builder;
 
-use pbs_api_types::BackupArchiveName;
+use pbs_api_types::{BackupArchiveName, RateLimitConfig};
 use pbs_client::{BackupReader, HttpClient, HttpClientOptions, RemoteChunkReader};
 use pbs_datastore::cached_chunk_reader::CachedChunkReader;
 use pbs_datastore::data_blob::DataChunkBuilder;
@@ -91,11 +91,16 @@ impl RestoreTask {
     }
 
     pub async fn connect(&self) -> Result<libc::c_int, Error> {
-        let options = HttpClientOptions::new_non_interactive(
+        let mut options = HttpClientOptions::new_non_interactive(
             self.setup.password.clone(),
             self.setup.fingerprint.clone(),
         );
 
+        if let Some(limit) = self.setup.inbound_rate_limit.clone() {
+            let limit = RateLimitConfig::from_client_config(limit);
+            options = options.rate_limit(limit);
+        }
+
         let http = HttpClient::new(
             &self.setup.host,
             self.setup.port,
-- 
2.47.3





  parent reply	other threads:[~2026-09-16 14:50 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-16 14:48 [PATCH many v2 0/8] fix #7530: Implement download bandwidth and restore limits for pbs-restore Christian Ebner
2026-09-16 14:48 ` [PATCH proxmox v2 1/8] pbs-api-types: expose ClientRateLimitConfig fields as pub Christian Ebner
2026-09-16 14:48 ` [PATCH proxmox-backup-qemu v2 2/8] commands/restore: fix useless borrow clippy warnings for archive names Christian Ebner
2026-09-16 14:48 ` [PATCH proxmox-backup-qemu v2 3/8] commands: fix clippy error for reimplementing Result::ok() Christian Ebner
2026-09-16 14:48 ` [PATCH proxmox-backup-qemu v2 4/8] commands: extend stricter type checks for guest config archive names Christian Ebner
2026-09-16 14:48 ` Christian Ebner [this message]
2026-09-16 14:48 ` [PATCH proxmox-backup-qemu v2 6/8] restore: implement `rate-limit` imposing chunk data stream limits Christian Ebner
2026-09-16 14:48 ` [PATCH pve-qemu v2 7/8] fix #7530: pbs-restore: expose optional rate limit parameters Christian Ebner
2026-09-16 14:48 ` [PATCH qemu-server v2 8/8] pbs-restore: set restore bandwidth limit for volumes Christian Ebner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260916144843.567913-6-c.ebner@proxmox.com \
    --to=c.ebner@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal