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] [RFC v10 qemu-server 7/7] api: create disks: factor out common part from if/else
Date: Thu, 13 Jan 2022 11:08:31 +0100	[thread overview]
Message-ID: <20220113100831.34113-9-f.ebner@proxmox.com> (raw)
In-Reply-To: <20220113100831.34113-1-f.ebner@proxmox.com>

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

New in v10.

 PVE/API2/Qemu.pm | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 8c74ecc..fa6aa9c 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -204,7 +204,7 @@ my $create_disks = sub {
 		my $src_size = PVE::Storage::file_size_info($source);
 		die "Could not get file size of $source" if !defined($src_size);
 
-		my (undef, $dst_volid) = PVE::QemuServer::ImportDisk::do_import(
+		(undef, $volid) = PVE::QemuServer::ImportDisk::do_import(
 		    $source,
 		    $vmid,
 		    $storeid,
@@ -215,18 +215,13 @@ my $create_disks = sub {
 		    },
 		);
 
-		push @$vollist, $dst_volid;
-		$disk->{file} = $dst_volid;
 		$disk->{size} = $src_size;
-		delete $disk->{format}; # no longer needed
-		$res->{$ds} = PVE::QemuServer::print_drive($disk);
 	    } else {
 		my $defformat = PVE::Storage::storage_default_format($storecfg, $storeid);
 		my $fmt = $disk->{format} || $defformat;
 
 		$size = PVE::Tools::convert_size($size, 'gb' => 'kb'); # vdisk_alloc uses kb
 
-		my $volid;
 		if ($ds eq 'efidisk0') {
 		    my $smm = PVE::QemuServer::Machine::machine_type_is_q35($conf);
 		    ($volid, $size) = PVE::QemuServer::create_efidisk(
@@ -238,12 +233,13 @@ my $create_disks = sub {
 		} else {
 		    $volid = PVE::Storage::vdisk_alloc($storecfg, $storeid, $vmid, $fmt, undef, $size);
 		}
-		push @$vollist, $volid;
-		$disk->{file} = $volid;
 		$disk->{size} = PVE::Tools::convert_size($size, 'kb' => 'b');
-		delete $disk->{format}; # no longer needed
-		$res->{$ds} = PVE::QemuServer::print_drive($disk);
 	    }
+
+	    push @$vollist, $volid;
+	    $disk->{file} = $volid;
+	    delete $disk->{format}; # no longer needed
+	    $res->{$ds} = PVE::QemuServer::print_drive($disk);
 	} else {
 
 	    PVE::Storage::check_volume_access($rpcenv, $authuser, $storecfg, $vmid, $volid);
-- 
2.30.2





  parent reply	other threads:[~2022-01-13 10:08 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-13 10:08 [pve-devel] [RFC v10 qemu-server/manager] API for disk import and OVF Fabian Ebner
2022-01-13 10:08 ` [pve-devel] [PATCH v10 qemu-server 1/7] schema: add pve-volume-id-or-absolute-path Fabian Ebner
2022-01-13 10:08 ` [pve-devel] [PATCH v10 qemu-server 2/7] parse ovf: untaint path when calling file_size_info Fabian Ebner
     [not found]   ` <<20220113100831.34113-3-f.ebner@proxmox.com>
2022-01-17 15:38     ` Fabian Grünbichler
2022-01-13 10:08 ` [pve-devel] [PATCH v10 qemu-server 3/7] api: add endpoint for parsing .ovf files Fabian Ebner
2022-01-13 10:08 ` [pve-devel] [PATCH v10 manager 1/1] api: nodes: add readovf endpoint Fabian Ebner
     [not found]   ` <<20220113100831.34113-5-f.ebner@proxmox.com>
2022-01-17 15:38     ` Fabian Grünbichler
2022-01-18  8:35       ` Fabian Ebner
2022-01-18  9:56         ` Fabian Grünbichler
2022-01-13 10:08 ` [pve-devel] [PATCH v10 qemu-server 4/7] image convert: allow block device as source Fabian Ebner
2022-01-13 10:08 ` [pve-devel] [RFC v10 qemu-server 5/7] schema: drive: use separate schema when disk allocation is possible Fabian Ebner
2022-01-13 10:08 ` [pve-devel] [RFC v10 qemu-server 6/7] api: support VM disk import Fabian Ebner
     [not found]   ` <<20220113100831.34113-8-f.ebner@proxmox.com>
2022-01-17 15:39     ` Fabian Grünbichler
2022-01-18  8:51       ` Fabian Ebner
2022-01-26 11:40   ` Fabian Ebner
2022-01-26 12:42     ` Fabian Grünbichler
2022-01-27  8:21       ` Fabian Ebner
2022-01-27 10:43         ` Fabian Grünbichler
2022-02-22 12:11   ` Fabian Ebner
2022-02-22 15:33     ` Fabian Grünbichler
2022-01-13 10:08 ` Fabian Ebner [this message]
     [not found] ` <<20220113100831.34113-1-f.ebner@proxmox.com>
2022-01-17 15:43   ` [pve-devel] [RFC v10 qemu-server/manager] API for disk import and OVF Fabian Grünbichler
2022-01-18  9:08     ` Fabian Ebner
2022-01-18 10:19       ` Fabian Grünbichler

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=20220113100831.34113-9-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