[pve-devel] applied: [PATCH v6 qemu-server] vmconfig_apply_pending: remove redundant write/load config calls

Fabian Grünbichler f.gruenbichler at proxmox.com
Thu Jan 16 10:30:09 CET 2020


On January 15, 2020 2:48 pm, Oguz Bektas wrote:
> since we handle errors gracefully now, we don't need to write & save
> config every time we change a setting.
> 
> Signed-off-by: Oguz Bektas <o.bektas at proxmox.com>
> ---
> 
> v5 -> v6:
> * style nit from fabian
> * combine two elsif statements into one, get rid of $new_val and
> $old_val from last version (not needed because of $cleanup_pending
> 
>  PVE/QemuServer.pm | 36 +++++++++---------------------------
>  1 file changed, 9 insertions(+), 27 deletions(-)
> 
> diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
> index f7d99e3..56dc6a0 100644
> --- a/PVE/QemuServer.pm
> +++ b/PVE/QemuServer.pm
> @@ -5108,20 +5108,10 @@ sub vmconfig_apply_pending {
>      foreach my $opt (sort keys %$pending_delete_hash) {
>  	my $force = $pending_delete_hash->{$opt}->{force};
>  	eval {
> -	    die "internal error" if $opt =~ m/^unused/;
> -	    $conf = PVE::QemuConfig->load_config($vmid); # update/reload
> -	    if (!defined($conf->{$opt})) {
> -		PVE::QemuConfig->remove_from_pending_delete($conf, $opt);
> -		PVE::QemuConfig->write_config($vmid, $conf);
> -	    } elsif (is_valid_drivename($opt)) {
> +	    if ($opt =~ m/^unused/) {
> +		die "internal error";
> +	    } elsif (defined($conf->{$opt}) && is_valid_drivename($opt)) {
>  		vmconfig_delete_or_detach_drive($vmid, $storecfg, $conf, $opt, $force);
> -		PVE::QemuConfig->remove_from_pending_delete($conf, $opt);
> -		delete $conf->{$opt};
> -		PVE::QemuConfig->write_config($vmid, $conf);
> -	    } else {
> -		PVE::QemuConfig->remove_from_pending_delete($conf, $opt);
> -		delete $conf->{$opt};
> -		PVE::QemuConfig->write_config($vmid, $conf);
>  	    }
>  	};
>  	if (my $err = $@) {
> @@ -5129,35 +5119,27 @@ sub vmconfig_apply_pending {
>  	} else {
>  	    PVE::QemuConfig->remove_from_pending_delete($conf, $opt);
>  	    delete $conf->{$opt};
> -	    PVE::QemuConfig->write_config($vmid, $conf);
>  	}
>      }
>  
> -    $conf = PVE::QemuConfig->load_config($vmid); # update/reload
> +    PVE::QemuConfig->cleanup_pending($conf);
>  
>      foreach my $opt (keys %{$conf->{pending}}) { # add/change
> -	$conf = PVE::QemuConfig->load_config($vmid); # update/reload
> -
> +	next if $opt eq 'delete'; # just to be sure
>  	eval {
> -	    if (defined($conf->{$opt}) && ($conf->{$opt} eq $conf->{pending}->{$opt})) {
> -		# skip if nothing changed
> -	    } elsif (is_valid_drivename($opt)) {
> +	    if (defined($conf->{$opt}) && is_valid_drivename($opt)) {
>  		vmconfig_register_unused_drive($storecfg, $vmid, $conf, parse_drive($opt, $conf->{$opt}))
> -		    if defined($conf->{$opt});
> -		$conf->{$opt} = $conf->{pending}->{$opt};
> -	    } else {
> -		$conf->{$opt} = $conf->{pending}->{$opt};
>  	    }
>  	};
>  	if (my $err = $@) {
>  	    $add_apply_error->($opt, $err);
>  	} else {
>  	    $conf->{$opt} = delete $conf->{pending}->{$opt};
> -	    PVE::QemuConfig->cleanup_pending($conf);
>  	}
> -
> -	PVE::QemuConfig->write_config($vmid, $conf);
>      }
> +
> +    # write all changes at once to avoid unnecessary i/o
> +    PVE::QemuConfig->write_config($vmid, $conf);
>  }
>  
>  my $safe_num_ne = sub {
> -- 
> 2.20.1
> 
> _______________________________________________
> pve-devel mailing list
> pve-devel at pve.proxmox.com
> https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
> 
> 




More information about the pve-devel mailing list