[pve-devel] [PATCH v2 qemu-server 2/2] Drop skiplock from write_config

Fabian Grünbichler f.gruenbichler at proxmox.com
Fri Feb 12 11:14:41 CET 2016


Since write_config was always called with skiplock=1 except
once, it makes sense to drop this parameter like in
PVE::LXC::write_config . If needed in the future, the
caller can use check_lock before write_config anyway.
---
 PVE/API2/Qemu.pm   | 24 ++++++++++++------------
 PVE/CLI/qm.pm      |  2 +-
 PVE/QemuMigrate.pm |  6 +++---
 PVE/QemuServer.pm  | 36 +++++++++++++++++-------------------
 4 files changed, 33 insertions(+), 35 deletions(-)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index c21287c..226e597 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -908,7 +908,7 @@ my $update_vm_api  = sub {
 		    $rpcenv->check_vm_perm($authuser, $vmid, undef, ['VM.Config.Disk']);
 		    if (PVE::QemuServer::try_deallocate_drive($storecfg, $vmid, $conf, $opt, $drive, $rpcenv, $authuser)) {
 			delete $conf->{$opt};
-			PVE::QemuServer::write_config($vmid, $conf, 1);
+			PVE::QemuServer::write_config($vmid, $conf);
 		    }
 		} elsif (PVE::QemuServer::valid_drivename($opt)) {
 		    &$check_protection($conf, "can't remove drive '$opt'");
@@ -916,10 +916,10 @@ my $update_vm_api  = sub {
 		    PVE::QemuServer::vmconfig_register_unused_drive($storecfg, $vmid, $conf, PVE::QemuServer::parse_drive($opt, $conf->{pending}->{$opt}))
 			if defined($conf->{pending}->{$opt});
 		    PVE::QemuServer::vmconfig_delete_pending_option($conf, $opt, $force);
-		    PVE::QemuServer::write_config($vmid, $conf, 1);
+		    PVE::QemuServer::write_config($vmid, $conf);
 		} else {
 		    PVE::QemuServer::vmconfig_delete_pending_option($conf, $opt, $force);
-		    PVE::QemuServer::write_config($vmid, $conf, 1);
+		    PVE::QemuServer::write_config($vmid, $conf);
 		}
 	    }
 
@@ -943,13 +943,13 @@ my $update_vm_api  = sub {
 		    $conf->{pending}->{$opt} = $param->{$opt};
 		}
 		PVE::QemuServer::vmconfig_undelete_pending_option($conf, $opt);
-		PVE::QemuServer::write_config($vmid, $conf, 1);
+		PVE::QemuServer::write_config($vmid, $conf);
 	    }
 
 	    # remove pending changes when nothing changed
 	    $conf = PVE::QemuServer::load_config($vmid); # update/reload
 	    my $changes = PVE::QemuServer::vmconfig_cleanup_pending($conf);
-	    PVE::QemuServer::write_config($vmid, $conf, 1) if $changes;
+	    PVE::QemuServer::write_config($vmid, $conf) if $changes;
 
 	    return if !scalar(keys %{$conf->{pending}});
 
@@ -2292,11 +2292,11 @@ __PACKAGE__->register_method({
 
 			$newconf->{$opt} = PVE::QemuServer::print_drive($vmid, $newdrive);
 
-			PVE::QemuServer::write_config($newid, $newconf, 1);
+			PVE::QemuServer::write_config($newid, $newconf);
 		    }
 
 		    delete $newconf->{lock};
-		    PVE::QemuServer::write_config($newid, $newconf, 1);
+		    PVE::QemuServer::write_config($newid, $newconf);
 
                     if ($target) {
 			# always deactivate volumes - avoid lvm LVs to be active on several nodes
@@ -2455,7 +2455,7 @@ __PACKAGE__->register_method({
 
 		    PVE::QemuServer::add_unused_volume($conf, $old_volid) if !$param->{delete};
 
-		    PVE::QemuServer::write_config($vmid, $conf, 1);
+		    PVE::QemuServer::write_config($vmid, $conf);
 
 		    eval {
 			# try to deactivate volumes - avoid lvm LVs to be active on several nodes
@@ -2477,7 +2477,7 @@ __PACKAGE__->register_method({
                     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::QemuServer::write_config($vmid, $conf, 1);
+			PVE::QemuServer::write_config($vmid, $conf);
 		    } else {
 			eval { PVE::Storage::vdisk_free($storecfg, $old_volid); };
 			warn $@ if $@;
@@ -2748,7 +2748,7 @@ __PACKAGE__->register_method({
 	    $drive->{size} = $newsize;
 	    $conf->{$disk} = PVE::QemuServer::print_drive($vmid, $drive);
 
-	    PVE::QemuServer::write_config($vmid, $conf, 1);
+	    PVE::QemuServer::write_config($vmid, $conf);
 	};
 
         PVE::QemuServer::lock_config($vmid, $updatefn);
@@ -2953,7 +2953,7 @@ __PACKAGE__->register_method({
 
 	    $snap->{description} = $param->{description} if defined($param->{description});
 
-	     PVE::QemuServer::write_config($vmid, $conf, 1);
+	     PVE::QemuServer::write_config($vmid, $conf);
 	};
 
 	PVE::QemuServer::lock_config($vmid, $updatefn);
@@ -3149,7 +3149,7 @@ __PACKAGE__->register_method({
 	    };
 
 	    $conf->{template} = 1;
-	    PVE::QemuServer::write_config($vmid, $conf, 1);
+	    PVE::QemuServer::write_config($vmid, $conf);
 
 	    return $rpcenv->fork_worker('qmtemplate', $vmid, $authuser, $realcmd);
 	};
diff --git a/PVE/CLI/qm.pm b/PVE/CLI/qm.pm
index 9a8f839..fdac3d5 100755
--- a/PVE/CLI/qm.pm
+++ b/PVE/CLI/qm.pm
@@ -188,7 +188,7 @@ __PACKAGE__->register_method ({
 	    my $conf = PVE::QemuServer::load_config($vmid);
 	    delete $conf->{lock};
 	    delete $conf->{pending}->{lock} if $conf->{pending}; # just to be sure
-	    PVE::QemuServer::write_config($vmid, $conf, 1);
+	    PVE::QemuServer::write_config($vmid, $conf);
 	});
 
 	return undef;
diff --git a/PVE/QemuMigrate.pm b/PVE/QemuMigrate.pm
index 5cacb51..973b6ee 100644
--- a/PVE/QemuMigrate.pm
+++ b/PVE/QemuMigrate.pm
@@ -277,7 +277,7 @@ sub phase1 {
 
     # set migrate lock in config file
     $conf->{lock} = 'migrate';
-    PVE::QemuServer::write_config($vmid, $conf, 1);
+    PVE::QemuServer::write_config($vmid, $conf);
 
     sync_disks($self, $vmid);
 
@@ -290,7 +290,7 @@ sub phase1_cleanup {
 
     my $conf = $self->{vmconf};
     delete $conf->{lock};
-    eval { PVE::QemuServer::write_config($vmid, $conf, 1) };
+    eval { PVE::QemuServer::write_config($vmid, $conf) };
     if (my $err = $@) {
 	$self->log('err', $err);
     }
@@ -546,7 +546,7 @@ sub phase2_cleanup {
 
     my $conf = $self->{vmconf};
     delete $conf->{lock};
-    eval { PVE::QemuServer::write_config($vmid, $conf, 1) };
+    eval { PVE::QemuServer::write_config($vmid, $conf) };
     if (my $err = $@) {
         $self->log('err', $err);
     }
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 9dd4777..1139438 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -2245,9 +2245,7 @@ sub write_vm_config {
 }
 
 sub write_config {
-    my ($vmid, $conf, $skiplock) = @_;
-
-    check_lock($conf) if !$skiplock;
+    my ($vmid, $conf) = @_;
 
     my $cfspath = cfs_config_path($vmid);
 
@@ -3213,7 +3211,7 @@ sub config_to_command {
 	    #if dimm_memory is not aligned to dimm map
 	    if($current_size > $memory) {
 	         $conf->{memory} = $current_size;
-	         write_config($vmid, $conf, 1);
+	         write_config($vmid, $conf);
 	    }
 	});
     }
@@ -3870,7 +3868,7 @@ sub qemu_memory_hotplug {
 		}
 		#update conf after each succesful module hotplug
 		$conf->{memory} = $current_size;
-		write_config($vmid, $conf, 1);
+		write_config($vmid, $conf);
 	});
 
     } else {
@@ -3895,7 +3893,7 @@ sub qemu_memory_hotplug {
 		$conf->{memory} = $current_size;
 
 		eval { qemu_objectdel($vmid, "mem-$name"); };
-		write_config($vmid, $conf, 1);
+		write_config($vmid, $conf);
 	});
     }
 }
@@ -4148,7 +4146,7 @@ sub vmconfig_hotplug_pending {
     }
 
     if ($changes) {
-	write_config($vmid, $conf, 1);
+	write_config($vmid, $conf);
 	$conf = load_config($vmid); # update/reload
     }
 
@@ -4199,7 +4197,7 @@ sub vmconfig_hotplug_pending {
 	    # save new config if hotplug was successful
 	    delete $conf->{$opt};
 	    vmconfig_undelete_pending_option($conf, $opt);
-	    write_config($vmid, $conf, 1);
+	    write_config($vmid, $conf);
 	    $conf = load_config($vmid); # update/reload
 	}
     }
@@ -4257,7 +4255,7 @@ sub vmconfig_hotplug_pending {
 	    # save new config if hotplug was successful
 	    $conf->{$opt} = $value;
 	    delete $conf->{pending}->{$opt};
-	    write_config($vmid, $conf, 1);
+	    write_config($vmid, $conf);
 	    $conf = load_config($vmid); # update/reload
 	}
     }
@@ -4313,16 +4311,16 @@ sub vmconfig_apply_pending {
 	$conf = load_config($vmid); # update/reload
 	if (!defined($conf->{$opt})) {
 	    vmconfig_undelete_pending_option($conf, $opt);
-	    write_config($vmid, $conf, 1);
+	    write_config($vmid, $conf);
 	} elsif (valid_drivename($opt)) {
 	    vmconfig_delete_or_detach_drive($vmid, $storecfg, $conf, $opt, $force);
 	    vmconfig_undelete_pending_option($conf, $opt);
 	    delete $conf->{$opt};
-	    write_config($vmid, $conf, 1);
+	    write_config($vmid, $conf);
 	} else {
 	    vmconfig_undelete_pending_option($conf, $opt);
 	    delete $conf->{$opt};
-	    write_config($vmid, $conf, 1);
+	    write_config($vmid, $conf);
 	}
     }
 
@@ -4342,7 +4340,7 @@ sub vmconfig_apply_pending {
 	}
 
 	delete $conf->{pending}->{$opt};
-	write_config($vmid, $conf, 1);
+	write_config($vmid, $conf);
     }
 }
 
@@ -5422,7 +5420,7 @@ sub rescan {
 
 	my $changes = update_disksize($vmid, $conf, $vm_volids);
 
-	write_config($vmid, $conf, 1) if $changes;
+	write_config($vmid, $conf) if $changes;
     };
 
     if (defined($vmid)) {
@@ -5947,7 +5945,7 @@ my $snapshot_prepare = sub {
 	# always overwrite machine if we save vmstate. This makes sure we
 	# can restore it later using correct machine type
 	$snap->{machine} = get_current_qemu_machine($vmid) if $snap->{vmstate};
-	write_config($vmid, $conf, 1);
+	write_config($vmid, $conf);
     };
 
     lock_config($vmid, $updatefn);
@@ -5983,7 +5981,7 @@ my $snapshot_commit = sub {
 
 	$newconf->{parent} = $snapname;
 
-	write_config($vmid, $newconf, 1);
+	write_config($vmid, $newconf);
     };
 
     lock_config($vmid, $updatefn);
@@ -6062,7 +6060,7 @@ sub snapshot_rollback {
 	    delete $conf->{machine} if $snap->{vmstate} && !$has_machine_config;
 	}
 
-	write_config($vmid, $conf, 1);
+	write_config($vmid, $conf);
 
 	if (!$prepare && $snap->{vmstate}) {
 	    my $statefile = PVE::Storage::path($storecfg, $snap->{vmstate});
@@ -6270,7 +6268,7 @@ sub snapshot_delete {
 	    }
 	}
 
-	write_config($vmid, $conf, 1);
+	write_config($vmid, $conf);
     };
 
     lock_config($vmid, $updatefn);
@@ -6348,7 +6346,7 @@ sub template_create {
 	my $voliddst = PVE::Storage::vdisk_create_base($storecfg, $volid);
 	$drive->{file} = $voliddst;
 	$conf->{$ds} = print_drive($vmid, $drive);
-	write_config($vmid, $conf, 1);
+	write_config($vmid, $conf);
     });
 }
 
-- 
2.1.4





More information about the pve-devel mailing list