[pve-devel] [PATCH qemu-server] Fix #2390: Sort @ifaces array to avoid regeneration of instance-id

Dominik Csapak d.csapak at proxmox.com
Mon Sep 30 08:43:19 CEST 2019


hi, while this patch should work (did not test it),
this can be done better

we could do something like:

---8<---
for (my $id = 0; $id < MAX_NETS; $id++) {
     my $iface = "net$id";
     next if !$conf->{$iface};
--->8---

this way we do not have to grep the whole conf
and sort it afterwards, but have it always sorted by default

(i know the code is not from you, but when we fix
this, we could as well clean it up :) )

where MAX_NETS comes from PVE::QemuServer (somehow)

would you be willing to send a v2 with such a change,
or would you prefer if i send it ?

btw, please see the note about the CLA if you did
not already sent one

https://pve.proxmox.com/wiki/Developer_Documentation#Software_License_and_Copyright

On 9/27/19 9:55 PM, Beat Jörg wrote:
> Signed-off-by: Beat Jörg <beat.joerg at gmail.com>
> ---
>   PVE/QemuServer/Cloudinit.pm | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/PVE/QemuServer/Cloudinit.pm b/PVE/QemuServer/Cloudinit.pm
> index ab001f9..c368dd9 100644
> --- a/PVE/QemuServer/Cloudinit.pm
> +++ b/PVE/QemuServer/Cloudinit.pm
> @@ -173,7 +173,7 @@ sub configdrive2_network {
>       }
>   
>       my @ifaces = grep(/^net(\d+)$/, keys %$conf);
> -    foreach my $iface (@ifaces) {
> +    foreach my $iface (sort @ifaces) {
>   	(my $id = $iface) =~ s/^net//;
>   	next if !$conf->{"ipconfig$id"};
>   	my $net = PVE::QemuServer::parse_ipconfig($conf->{"ipconfig$id"});
> @@ -253,7 +253,7 @@ sub nocloud_network_v2 {
>       my $dns_done;
>   
>       my @ifaces = grep(/^net(\d+)$/, keys %$conf);
> -    foreach my $iface (@ifaces) {
> +    foreach my $iface (sort @ifaces) {
>   	(my $id = $iface) =~ s/^net//;
>   	next if !$conf->{"ipconfig$id"};
>   
> @@ -324,7 +324,7 @@ sub nocloud_network {
>                   . "config:\n";
>   
>       my @ifaces = grep(/^net(\d+)$/, keys %$conf);
> -    foreach my $iface (@ifaces) {
> +    foreach my $iface (sort @ifaces) {
>   	(my $id = $iface) =~ s/^net//;
>   	next if !$conf->{"ipconfig$id"};
>   
> 





More information about the pve-devel mailing list