[pve-devel] [PATCH v3 qemu-server 06/19] use new config helpers from guest-common for pending changes
Oguz Bektas
o.bektas at proxmox.com
Mon Oct 14 10:28:38 CEST 2019
most of the pending changes related code has been moved into
AbstractConfig, so we have to call them as class methods from QemuConfig instead.
Signed-off-by: Oguz Bektas <o.bektas at proxmox.com>
---
PVE/API2/Qemu.pm | 14 ++++-----
PVE/QemuServer.pm | 79 +++++------------------------------------------
2 files changed, 15 insertions(+), 78 deletions(-)
diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index ba6de27..b18ed8b 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -931,7 +931,7 @@ __PACKAGE__->register_method({
my $conf = PVE::QemuConfig->load_config($param->{vmid});
- my $pending_delete_hash = PVE::QemuServer::split_flagged_list($conf->{pending}->{delete});
+ my $pending_delete_hash = PVE::QemuConfig->parse_pending_delete($conf->{pending}->{delete});
my $res = [];
@@ -1182,7 +1182,7 @@ my $update_vm_api = sub {
$rpcenv->check_vm_perm($authuser, $vmid, undef, ['VM.Config.Disk']);
PVE::QemuServer::vmconfig_register_unused_drive($storecfg, $vmid, $conf, PVE::QemuServer::parse_drive($opt, $val))
if $is_pending_val;
- PVE::QemuServer::vmconfig_delete_pending_option($conf, $opt, $force);
+ PVE::QemuConfig->add_to_pending_delete($conf, $opt, $force);
PVE::QemuConfig->write_config($vmid, $conf);
} elsif ($opt =~ m/^serial\d+$/) {
if ($val eq 'socket') {
@@ -1190,7 +1190,7 @@ my $update_vm_api = sub {
} elsif ($authuser ne 'root at pam') {
die "only root can delete '$opt' config for real devices\n";
}
- PVE::QemuServer::vmconfig_delete_pending_option($conf, $opt, $force);
+ PVE::QemuConfig->add_to_pending_delete($conf, $opt, $force);
PVE::QemuConfig->write_config($vmid, $conf);
} elsif ($opt =~ m/^usb\d+$/) {
if ($val =~ m/spice/) {
@@ -1198,10 +1198,10 @@ my $update_vm_api = sub {
} elsif ($authuser ne 'root at pam') {
die "only root can delete '$opt' config for real devices\n";
}
- PVE::QemuServer::vmconfig_delete_pending_option($conf, $opt, $force);
+ PVE::QemuConfig->add_to_pending_delete($conf, $opt, $force);
PVE::QemuConfig->write_config($vmid, $conf);
} else {
- PVE::QemuServer::vmconfig_delete_pending_option($conf, $opt, $force);
+ PVE::QemuConfig->add_to_pending_delete($conf, $opt, $force);
PVE::QemuConfig->write_config($vmid, $conf);
}
}
@@ -1242,13 +1242,13 @@ my $update_vm_api = sub {
} else {
$conf->{pending}->{$opt} = $param->{$opt};
}
- PVE::QemuServer::vmconfig_undelete_pending_option($conf, $opt);
+ PVE::QemuConfig->remove_from_pending_delete($conf, $opt);
PVE::QemuConfig->write_config($vmid, $conf);
}
# remove pending changes when nothing changed
$conf = PVE::QemuConfig->load_config($vmid); # update/reload
- my $changes = PVE::QemuServer::vmconfig_cleanup_pending($conf);
+ my $changes = PVE::QemuConfig->cleanup_pending($conf);
PVE::QemuConfig->write_config($vmid, $conf) if $changes;
return if !scalar(keys %{$conf->{pending}});
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index ac9dfde..47edc8c 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -2348,40 +2348,6 @@ sub vm_is_volid_owner {
return undef;
}
-sub split_flagged_list {
- my $text = shift || '';
- $text =~ s/[,;]/ /g;
- $text =~ s/^\s+//;
- return { map { /^(!?)(.*)$/ && ($2, $1) } ($text =~ /\S+/g) };
-}
-
-sub join_flagged_list {
- my ($how, $lst) = @_;
- join $how, map { $lst->{$_} . $_ } keys %$lst;
-}
-
-sub vmconfig_delete_pending_option {
- my ($conf, $key, $force) = @_;
-
- delete $conf->{pending}->{$key};
- my $pending_delete_hash = split_flagged_list($conf->{pending}->{delete});
- $pending_delete_hash->{$key} = $force ? '!' : '';
- $conf->{pending}->{delete} = join_flagged_list(',', $pending_delete_hash);
-}
-
-sub vmconfig_undelete_pending_option {
- my ($conf, $key) = @_;
-
- my $pending_delete_hash = split_flagged_list($conf->{pending}->{delete});
- delete $pending_delete_hash->{$key};
-
- if (%$pending_delete_hash) {
- $conf->{pending}->{delete} = join_flagged_list(',', $pending_delete_hash);
- } else {
- delete $conf->{pending}->{delete};
- }
-}
-
sub vmconfig_register_unused_drive {
my ($storecfg, $vmid, $conf, $drive) = @_;
@@ -2396,37 +2362,6 @@ sub vmconfig_register_unused_drive {
}
}
-sub vmconfig_cleanup_pending {
- my ($conf) = @_;
-
- # remove pending changes when nothing changed
- my $changes;
- foreach my $opt (keys %{$conf->{pending}}) {
- if (defined($conf->{$opt}) && ($conf->{pending}->{$opt} eq $conf->{$opt})) {
- $changes = 1;
- delete $conf->{pending}->{$opt};
- }
- }
-
- my $current_delete_hash = split_flagged_list($conf->{pending}->{delete});
- my $pending_delete_hash = {};
- while (my ($opt, $force) = each %$current_delete_hash) {
- if (defined($conf->{$opt})) {
- $pending_delete_hash->{$opt} = $force;
- } else {
- $changes = 1;
- }
- }
-
- if (%$pending_delete_hash) {
- $conf->{pending}->{delete} = join_flagged_list(',', $pending_delete_hash);
- } else {
- delete $conf->{pending}->{delete};
- }
-
- return $changes;
-}
-
# smbios: [manufacturer=str][,product=str][,version=str][,serial=str][,uuid=uuid][,sku=str][,family=str][,base64=bool]
my $smbios1_fmt = {
uuid => {
@@ -4922,7 +4857,7 @@ sub vmconfig_hotplug_pending {
my $hotplug_features = parse_hotplug_features(defined($conf->{hotplug}) ? $conf->{hotplug} : '1');
- my $pending_delete_hash = split_flagged_list($conf->{pending}->{delete});
+ my $pending_delete_hash = PVE::QemuConfig->parse_pending_delete($conf->{pending}->{delete});
while (my ($opt, $force) = each %$pending_delete_hash) {
next if $selection && !$selection->{$opt};
eval {
@@ -4978,7 +4913,7 @@ sub vmconfig_hotplug_pending {
} else {
# save new config if hotplug was successful
delete $conf->{$opt};
- vmconfig_undelete_pending_option($conf, $opt);
+ PVE::QemuConfig->remove_from_pending_delete($conf, $opt);
PVE::QemuConfig->write_config($vmid, $conf);
$conf = PVE::QemuConfig->load_config($vmid); # update/reload
}
@@ -5113,25 +5048,27 @@ sub vmconfig_delete_or_detach_drive {
}
}
+
+
sub vmconfig_apply_pending {
my ($vmid, $conf, $storecfg) = @_;
# cold plug
- my $pending_delete_hash = split_flagged_list($conf->{pending}->{delete});
+ my $pending_delete_hash = PVE::QemuConfig->parse_pending_delete($conf->{pending}->{delete});
while (my ($opt, $force) = each %$pending_delete_hash) {
die "internal error" if $opt =~ m/^unused/;
$conf = PVE::QemuConfig->load_config($vmid); # update/reload
if (!defined($conf->{$opt})) {
- vmconfig_undelete_pending_option($conf, $opt);
+ PVE::QemuConfig->remove_from_pending_delete($conf, $opt);
PVE::QemuConfig->write_config($vmid, $conf);
} elsif (is_valid_drivename($opt)) {
vmconfig_delete_or_detach_drive($vmid, $storecfg, $conf, $opt, $force);
- vmconfig_undelete_pending_option($conf, $opt);
+ PVE::QemuConfig->remove_from_pending_delete($conf, $opt);
delete $conf->{$opt};
PVE::QemuConfig->write_config($vmid, $conf);
} else {
- vmconfig_undelete_pending_option($conf, $opt);
+ PVE::QemuConfig->remove_from_pending_delete($conf, $opt);
delete $conf->{$opt};
PVE::QemuConfig->write_config($vmid, $conf);
}
--
2.20.1
More information about the pve-devel
mailing list