[pve-devel] [PATCH qemu-server 3/3] Refactor add_unused_volume
Fabian Grünbichler
f.gruenbichler at proxmox.com
Mon Mar 7 12:41:14 CET 2016
Drop add_unused_volume from PVE::QemuServer in favor of
(identical) implementation in PVE::AbstractConfig
---
PVE/API2/Qemu.pm | 4 ++--
PVE/QemuServer.pm | 24 ++----------------------
2 files changed, 4 insertions(+), 24 deletions(-)
diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 40ea353..0d33f6c 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -2453,7 +2453,7 @@ __PACKAGE__->register_method({
$conf->{$disk} = PVE::QemuServer::print_drive($vmid, $newdrive);
- PVE::QemuServer::add_unused_volume($conf, $old_volid) if !$param->{delete};
+ PVE::QemuConfig->add_unused_volume($conf, $old_volid) if !$param->{delete};
PVE::QemuConfig->write_config($vmid, $conf);
@@ -2476,7 +2476,7 @@ __PACKAGE__->register_method({
if ($param->{delete}) {
if (PVE::QemuServer::is_volume_in_use($storecfg, $conf, undef, $old_volid)) {
warn "volume $old_volid still has snapshots, can't delete it\n";
- PVE::QemuServer::add_unused_volume($conf, $old_volid);
+ PVE::QemuConfig->add_unused_volume($conf, $old_volid);
PVE::QemuConfig->write_config($vmid, $conf);
} else {
eval { PVE::Storage::vdisk_free($storecfg, $old_volid); };
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 04ffc05..67ba355 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -1557,26 +1557,6 @@ sub add_random_macs {
}
}
-sub add_unused_volume {
- my ($config, $volid) = @_;
-
- my $key;
- for (my $ind = $MAX_UNUSED_DISKS - 1; $ind >= 0; $ind--) {
- my $test = "unused$ind";
- if (my $vid = $config->{$test}) {
- return if $vid eq $volid; # do not add duplicates
- } else {
- $key = $test;
- }
- }
-
- die "To many unused volume - please delete them first.\n" if !$key;
-
- $config->{$key} = $volid;
-
- return $key;
-}
-
sub vm_is_volid_owner {
my ($storecfg, $vmid, $volid) = @_;
@@ -1631,7 +1611,7 @@ sub vmconfig_register_unused_drive {
if (!drive_is_cdrom($drive)) {
my $volid = $drive->{file};
if (vm_is_volid_owner($storecfg, $vmid, $volid)) {
- add_unused_volume($conf, $volid, $vmid);
+ PVE::QemuConfig->add_unused_volume($conf, $volid, $vmid);
}
}
}
@@ -5305,7 +5285,7 @@ sub update_disksize {
next if !$path; # just to be sure
next if $usedpath->{$path};
$changes = 1;
- add_unused_volume($conf, $volid);
+ PVE::QemuConfig->add_unused_volume($conf, $volid);
$usedpath->{$path} = 1; # avoid to add more than once (aliases)
}
--
2.1.4
More information about the pve-devel
mailing list