public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH v11 qemu-server 11/14] api: factor out check/cleanup for drive params
Date: Mon,  7 Mar 2022 13:17:39 +0100	[thread overview]
Message-ID: <20220307121743.60206-12-f.ebner@proxmox.com> (raw)
In-Reply-To: <20220307121743.60206-1-f.ebner@proxmox.com>

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---

New in v11.

 PVE/API2/Qemu.pm | 38 +++++++++++++++++++++-----------------
 1 file changed, 21 insertions(+), 17 deletions(-)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 01321c8..791a23f 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -63,6 +63,23 @@ my $resolve_cdrom_alias = sub {
     }
 };
 
+my $check_drive_param = sub {
+    my ($param, $storecfg, $extra_checks) = @_;
+
+    for my $opt (sort keys $param->%*) {
+	next if !PVE::QemuServer::is_valid_drivename($opt);
+
+	my $drive = PVE::QemuServer::parse_drive($opt, $param->{$opt});
+	raise_param_exc({ $opt => "unable to parse drive options" }) if !$drive;
+
+	PVE::QemuServer::cleanup_drive_path($opt, $storecfg, $drive);
+
+	$extra_checks->($drive) if $extra_checks;
+
+	$param->{$opt} = PVE::QemuServer::print_drive($drive);
+    }
+};
+
 my $NEW_DISK_RE = qr!^(([^/:\s]+):)?(\d+(\.\d+)?)$!;
 my $check_storage_access = sub {
    my ($rpcenv, $authuser, $storecfg, $vmid, $settings, $default_storage) = @_;
@@ -617,15 +634,7 @@ __PACKAGE__->register_method({
 
 	    &$check_cpu_model_access($rpcenv, $authuser, $param);
 
-	    foreach my $opt (keys %$param) {
-		if (PVE::QemuServer::is_valid_drivename($opt)) {
-		    my $drive = PVE::QemuServer::parse_drive($opt, $param->{$opt});
-		    raise_param_exc({ $opt => "unable to parse drive options" }) if !$drive;
-
-		    PVE::QemuServer::cleanup_drive_path($opt, $storecfg, $drive);
-		    $param->{$opt} = PVE::QemuServer::print_drive($drive);
-		}
-	    }
+	    $check_drive_param->($param, $storecfg);
 
 	    PVE::QemuServer::add_random_macs($param);
 	} else {
@@ -1195,15 +1204,10 @@ my $update_vm_api  = sub {
 	die "cannot add non-replicatable volume to a replicated VM\n";
     };
 
+    $check_drive_param->($param, $storecfg, $check_replication);
+
     foreach my $opt (keys %$param) {
-	if (PVE::QemuServer::is_valid_drivename($opt)) {
-	    # cleanup drive path
-	    my $drive = PVE::QemuServer::parse_drive($opt, $param->{$opt});
-	    raise_param_exc({ $opt => "unable to parse drive options" }) if !$drive;
-	    PVE::QemuServer::cleanup_drive_path($opt, $storecfg, $drive);
-	    $check_replication->($drive);
-	    $param->{$opt} = PVE::QemuServer::print_drive($drive);
-	} elsif ($opt =~ m/^net(\d+)$/) {
+	if ($opt =~ m/^net(\d+)$/) {
 	    # add macaddr
 	    my $net = PVE::QemuServer::parse_net($param->{$opt});
 	    $param->{$opt} = PVE::QemuServer::print_net($net);
-- 
2.30.2





  parent reply	other threads:[~2022-03-07 12:17 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-07 12:17 [pve-devel] [PATCH-SERIES v11 qemu-server/manager] API for disk import and OVF Fabian Ebner
2022-03-07 12:17 ` [pve-devel] [PATCH v11 qemu-server 01/14] device unplug: verify that unplugging scsi disk completed Fabian Ebner
2022-03-07 12:17 ` [pve-devel] [PATCH v11 qemu-server 02/14] api: create disks: always activate/update size when attaching existing volume Fabian Ebner
2022-03-07 12:17 ` [pve-devel] [PATCH v11 qemu-server 03/14] api: update: pass correct config when creating disks Fabian Ebner
2022-03-07 12:17 ` [pve-devel] [PATCH v11 qemu-server 04/14] clone disk: remove check for min QEMU version 2.7 Fabian Ebner
2022-03-07 12:17 ` [pve-devel] [PATCH v11 qemu-server 05/14] clone disk: group source and target parameters Fabian Ebner
2022-03-07 12:17 ` [pve-devel] [PATCH v11 qemu-server 06/14] clone disk: allow cloning from an unused or unreferenced disk Fabian Ebner
2022-03-07 12:17 ` [pve-devel] [PATCH v11 qemu-server 07/14] schema: add pve-volume-id-or-absolute-path Fabian Ebner
2022-03-07 12:17 ` [pve-devel] [PATCH v11 qemu-server 08/14] parse ovf: untaint path when calling file_size_info Fabian Ebner
2022-03-07 12:17 ` [pve-devel] [PATCH v11 qemu-server 09/14] api: add endpoint for parsing .ovf files Fabian Ebner
2022-03-07 12:17 ` [pve-devel] [PATCH v11 qemu-server 10/14] image convert: allow block device as source Fabian Ebner
2022-03-07 12:17 ` Fabian Ebner [this message]
2022-03-07 12:17 ` [pve-devel] [PATCH v11 qemu-server 12/14] schema: drive: use separate schema when disk allocation is possible Fabian Ebner
2022-03-07 12:17 ` [pve-devel] [PATCH v11 qemu-server 13/14] api: support VM disk import Fabian Ebner
2022-03-07 12:17 ` [pve-devel] [PATCH v11 qemu-server 14/14] api: update vm: print drive string for newly allocated/imported drives Fabian Ebner
2022-03-07 12:17 ` [pve-devel] [PATCH v11 manager 1/1] api: nodes: add readovf endpoint Fabian 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=20220307121743.60206-12-f.ebner@proxmox.com \
    --to=f.ebner@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