Refactor add_unused_volume

Drop add_unused_volume from PVE::QemuServer in favor of
(identical) implementation in PVE::AbstractConfig
This commit is contained in:
Fabian Grünbichler 2016-03-07 12:41:14 +01:00 committed by Dietmar Maurer
parent b2c9558da8
commit 8793d4950e
2 changed files with 4 additions and 24 deletions

View File

@ -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); };

View File

@ -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)
}