public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com, pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH storage v4 3/3] api: FileRestore: allow automatic memory increase for privileged users
Date: Thu, 10 Nov 2022 11:36:34 +0100	[thread overview]
Message-ID: <20221110103634.2177856-7-d.csapak@proxmox.com> (raw)
In-Reply-To: <20221110103634.2177856-1-d.csapak@proxmox.com>

if the user has the appropriate rights (details in the comments of
'check_allow_dynamic_memory') enable the dynamic memory behaviour
of the file-restore binary

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
new in v4:
depends on pve-common 2/2

 PVE/API2/Storage/FileRestore.pm | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/PVE/API2/Storage/FileRestore.pm b/PVE/API2/Storage/FileRestore.pm
index 764ebfb..4b50eed 100644
--- a/PVE/API2/Storage/FileRestore.pm
+++ b/PVE/API2/Storage/FileRestore.pm
@@ -33,6 +33,19 @@ my $parse_volname_or_id = sub {
     return $volid;
 };
 
+# returns one if file-restore vms memory increase should be allowed
+# user needs either
+# 'VM.Allocate' on '/vms'  (can create any number of vms)
+# or 'Sys.Modify' on '/' (can modify the system to a state where it no longer functions)
+my sub check_allow_dynamic_memory {
+    my ($rpcenv, $user) = @_;
+
+    return 1 if $rpcenv->check($user, '/vms', ['VM.Allocate'], 1);
+    return 1 if $rpcenv->check($user, '/', ['Sys.Modify'], 1);
+
+    return 0;
+}
+
 __PACKAGE__->register_method ({
     name => 'list',
     path => 'list',
@@ -119,7 +132,11 @@ __PACKAGE__->register_method ({
 	my (undef, $snap) = PVE::Storage::parse_volname($cfg, $volid);
 
 	my $client = PVE::PBSClient->new($scfg, $storeid);
-	my $ret = $client->file_restore_list($snap, $path, $base64, { timeout => 25 });
+	my $extract_params = {
+	    timeout => 25,
+	    'dynamic-memory' => check_allow_dynamic_memory($rpcenv, $user),
+	};
+	my $ret = $client->file_restore_list($snap, $path, $base64, $extract_params);
 
 	if (ref($ret) eq "HASH") {
 	    my $msg = $ret->{message};
@@ -196,10 +213,14 @@ __PACKAGE__->register_method ({
 	my $client = PVE::PBSClient->new($scfg, $storeid);
 	my $fifo = $client->file_restore_extract_prepare();
 
+	my $extra_params = {
+	    'dynamic-memory' => check_allow_dynamic_memory($rpcenv, $user),
+	};
+
 	$rpcenv->fork_worker('pbs-download', undef, $user, sub {
 	    my $name = decode_base64($path);
 	    print "Starting download of file: $name\n";
-	    $client->file_restore_extract($fifo, $snap, $path, 1);
+	    $client->file_restore_extract($fifo, $snap, $path, 1, $extra_params);
 	});
 
 	my $ret = {
-- 
2.30.2





      parent reply	other threads:[~2022-11-10 10:37 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-10 10:36 [pbs-devel] [PATCH proxmox-backup/common/storage v4] improve file-restore timeout behaviour Dominik Csapak
2022-11-10 10:36 ` [pbs-devel] [PATCH proxmox-backup v4 1/1] file-restore: make dynamic memory behaviour controllable Dominik Csapak
2022-11-15  8:29   ` [pbs-devel] applied: " Thomas Lamprecht
2022-11-10 10:36 ` [pbs-devel] [PATCH common v4 1/2] PBSClient: file_restore_list: add extraParams and use timeout Dominik Csapak
2022-11-15 12:27   ` [pbs-devel] applied: [pve-devel] " Thomas Lamprecht
2022-11-10 10:36 ` [pbs-devel] [PATCH common v4 2/2] PBSClient: add optional 'dynamic-memory' parameter to file-restore commands Dominik Csapak
2022-11-10 10:36 ` [pbs-devel] [PATCH storage v4 1/3] api: FileRestore: decode and return proper error of file-restore listing Dominik Csapak
2022-11-15 12:27   ` [pbs-devel] applied: [pve-devel] " Thomas Lamprecht
2022-11-10 10:36 ` [pbs-devel] [PATCH storage v4 2/3] api: FileRestore: make use of file-restores and guis timeout mechanism Dominik Csapak
2022-11-15 12:28   ` [pbs-devel] applied: [pve-devel] " Thomas Lamprecht
2022-11-10 10:36 ` Dominik Csapak [this message]

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=20221110103634.2177856-7-d.csapak@proxmox.com \
    --to=d.csapak@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal