[pve-devel] [PATCH v2 pve-common 4/4] Inotify : write network config : remove allow- ovs with ifupdown2

Wolfgang Bumiller w.bumiller at proxmox.com
Wed Jun 20 10:35:35 CEST 2018


On Wed, Jun 20, 2018 at 07:36:57AM +0200, Alexandre Derumier wrote:
> ---
>  src/PVE/INotify.pm | 17 ++++++++++++-----
>  1 file changed, 12 insertions(+), 5 deletions(-)
> 
> diff --git a/src/PVE/INotify.pm b/src/PVE/INotify.pm
> index 94712d5..48630ae 100644
> --- a/src/PVE/INotify.pm
> +++ b/src/PVE/INotify.pm
> @@ -1053,7 +1053,7 @@ sub __read_etc_network_interfaces {
>  }
>  
>  sub __interface_to_string {
> -    my ($iface, $d, $family, $first_block) = @_;
> +    my ($iface, $d, $family, $first_block, $ifupdown2) = @_;
>  
>      (my $suffix = $family) =~ s/^inet//;
>  
> @@ -1162,7 +1162,13 @@ sub __interface_to_string {
>  	$done->{ovs_type} = 1;
>  
>  	if ($d->{ovs_bridge}) {
> -	    $raw = "allow-$d->{ovs_bridge} $iface\n$raw";
> +
> +	    if ($ifupdown2) {
> +		$raw = "auto $iface\n$raw";
> +	    } else {
> +		$raw = "allow-$d->{ovs_bridge} $iface\n$raw";
> +	    }
> +
>  	    $raw .= "\tovs_bridge $d->{ovs_bridge}\n";
>  	    $done->{ovs_bridge} = 1;
>  	}
> @@ -1195,11 +1201,12 @@ sub __interface_to_string {
>  
>  sub write_etc_network_interfaces {
>      my ($filename, $fh, $config) = @_;
> -    my $raw = __write_etc_network_interfaces($config);
> +    my $ifupdown2 = 1 if -e '/usr/share/ifupdown2';

Note that variable declarations with a postfix condition is undefined
behavior, so no new code should do this.
In this case you can even just use:
    my $ifupdown2 = -e '/usr/share/ifupdown2';

(I'll fix it up locally.)

> +    my $raw = __write_etc_network_interfaces($config, $ifupdown2);
>      PVE::Tools::safe_print($filename, $fh, $raw);
>  }
>  sub __write_etc_network_interfaces {
> -    my ($config) = @_;
> +    my ($config, $ifupdown2) = @_;
>  
>      my $ifaces = $config->{ifaces};
>      my @options = @{$config->{options}};
> @@ -1359,7 +1366,7 @@ NETWORKDOC
>  	$printed->{$iface} = 1;
>  	$raw .= "auto $iface\n" if $d->{autostart};
>  	my $i = 0; # some options should be printed only once
> -	$raw .= __interface_to_string($iface, $d, $_, !$i++) foreach @{$d->{families}};
> +	$raw .= __interface_to_string($iface, $d, $_, !$i++, $ifupdown2) foreach @{$d->{families}};
>      }
>  
>      $raw .= $_->[1] . "\n" foreach @options;
> -- 
> 2.11.0




More information about the pve-devel mailing list