]> git.proxmox.com Git - pve-common.git/blobdiff - src/PVE/INotify.pm
cgroup: cpu quota: fix resetting period length for v1
[pve-common.git] / src / PVE / INotify.pm
index 562a243fd7ec098f5ae7e22c59cc1f7c6f08a088..0d82a522b63f105ad271eaaae7490d40ab6529e4 100644 (file)
@@ -904,14 +904,15 @@ sub __read_etc_network_interfaces {
     SECTION: while (defined ($line = <$fh>)) {
        chomp ($line);
        next if $line =~ m/^\s*#/;
-       next if $line =~ m/^\s*(allow-hotplug)\s+(.*)$/;
 
-       if ($line =~ m/^\s*(auto|allow-ovs)\s+(.*)$/) {
-           my @aa = split (/\s+/, $2);
+       if ($line =~ m/^\s*(allow-auto|auto|allow-ovs)\s+(.*)$/) {
 
-           foreach my $a (@aa) {
-               $ifaces->{$a}->{autostart} = 1;
-           }
+           $ifaces->{$_}->{autostart} = 1 for split (/\s+/, $2);
+
+       } elsif ($line =~ m/^\s*(allow-hotplug)\s+(.*)$/) {
+
+           # FIXME: handle those differently? auto makes it required on-boot, vs. best-effort
+           $ifaces->{$_}->{autostart} = 1 for split (/\s+/, $2);
 
        } elsif ($line =~ m/^\s*iface\s+(\S+)\s+(inet6?)\s+(\S+)\s*$/) {
            my $i = $1;
@@ -930,13 +931,7 @@ sub __read_etc_network_interfaces {
                    $f->{comments} = '' if !$f->{comments};
                    my $comment = decode('UTF-8', $1);
                    $f->{comments} .= "$comment\n";
-               } elsif ($line =~ m/^\s*(?:iface\s
-                                          |mapping\s
-                                          |auto\s
-                                          |allow-
-                                          |source\s
-                                          |source-directory\s
-                                        )/x) {
+               } elsif ($line =~ m/^\s*(?:(?:iface|mapping|auto|source|source-directory)\s|allow-)/) {
                    last;
                } elsif ($line =~ m/^\s*((\S+)\s+(.+))$/) {
                    my $option = $1;
@@ -969,9 +964,10 @@ sub __read_etc_network_interfaces {
                        'vxlan-id' => 1,
                        'vxlan-svcnodeip' => 1,
                        'vxlan-physdev' => 1,
-                       'vxlan-local-tunnelip' => 1 };
+                       'vxlan-local-tunnelip' => 1,
+                   };
 
-                   if (($id eq 'address') || ($id eq 'netmask') || ($id eq 'broadcast') || ($id eq 'gateway')) {
+                   if ($id eq 'address' || $id eq 'netmask' || $id eq 'broadcast' || $id eq 'gateway') {
                        $f->{$id} = $value;
                    } elsif ($simple_options->{$id}) {
                        $d->{$id} = $value;
@@ -998,8 +994,7 @@ sub __read_etc_network_interfaces {
                    } elsif ($id eq 'bond_mode') {
                        # always use names
                        foreach my $bm (keys %$bond_modes) {
-                           my $id = $bond_modes->{$bm};
-                           if ($id eq $value) {
+                           if ($bond_modes->{$bm} eq $value) {
                                $value = $bm;
                                last;
                            }
@@ -1014,7 +1009,7 @@ sub __read_etc_network_interfaces {
                    last;
                }
            }
-           $d->{"$_$suffix"} = $f->{$_} foreach (keys %$f);
+           $d->{"$_$suffix"} = $f->{$_} for keys $f->%*;
            last SECTION if !defined($line);
            redo SECTION;
        } elsif ($line =~ /\w/) {
@@ -1029,10 +1024,12 @@ sub __read_etc_network_interfaces {
     }
 
     if (!$ifaces->{lo}) {
-       $ifaces->{lo}->{priority} = 1;
-       $ifaces->{lo}->{method} = 'loopback';
-       $ifaces->{lo}->{type} = 'loopback';
-       $ifaces->{lo}->{autostart} = 1;
+       $ifaces->{lo} = {
+           priority => 1,
+           method => 'loopback',
+           type => 'loopback',
+           autostart => 1,
+       };
     }
 
     foreach my $iface (keys %$ifaces) {
@@ -1061,13 +1058,12 @@ sub __read_etc_network_interfaces {
        } elsif ($iface =~ m/^vmbr\d+$/) {
            if (!$d->{ovs_type}) {
                $d->{type} = 'bridge';
-
-               if (!defined ($d->{bridge_fd})) {
-                   $d->{bridge_fd} = 0;
-               }
                if (!defined ($d->{bridge_stp})) {
                    $d->{bridge_stp} = 'off';
                }
+               if (!defined($d->{bridge_fd}) && $d->{bridge_stp} eq 'off') {
+                   $d->{bridge_fd} = 0;
+               }
            } elsif ($d->{ovs_type} eq 'OVSBridge') {
                $d->{type} = $d->{ovs_type};
            }
@@ -1156,6 +1152,10 @@ sub __read_etc_network_interfaces {
        $d->{method} = 'manual' if !$d->{method};
        $d->{method6} = 'manual' if !$d->{method6};
 
+       if (my $comments6 = delete $d->{comments6}) {
+           $d->{comments} = ($d->{comments} // '') . $comments6;
+       }
+
        $d->{families} ||= ['inet'];
     }
 
@@ -1220,12 +1220,9 @@ sub __interface_to_string {
 
     return '' if !($d && $d->{"method$suffix"});
 
-    my $raw = '';
-
-    $raw .= "iface $iface $family " . $d->{"method$suffix"} . "\n";
+    my $raw = "iface $iface $family " . $d->{"method$suffix"} . "\n";
 
     if (my $addr = $d->{"address$suffix"}) {
-
        if ($addr !~ /\/\d+$/ && $d->{"netmask$suffix"}) {
            if ($d->{"netmask$suffix"} =~ m/^\d+$/) {
                $addr .= "/" . $d->{"netmask$suffix"};
@@ -1233,17 +1230,17 @@ sub __interface_to_string {
                $addr .= "/" . $mask;
            }
        }
-
-       $raw .= "\taddress " . $addr . "\n";
+       $raw .= "\taddress ${addr}\n";
     }
 
     $raw .= "\tgateway " . $d->{"gateway$suffix"} . "\n" if $d->{"gateway$suffix"};
 
-    my $done = { type => 1, priority => 1, method => 1, active => 1, exists => 1,
-                comments => 1, autostart => 1, options => 1,
-                address => 1, netmask => 1, gateway => 1, broadcast => 1,
-                method6 => 1, families => 1, options6 => 1,
-                address6 => 1, netmask6 => 1, gateway6 => 1, broadcast6 => 1, 'uplink-id' => 1 };
+    my $done = {
+       type => 1, priority => 1, method => 1, active => 1, exists => 1, comments => 1,
+       autostart => 1, options => 1, address => 1, netmask => 1, gateway => 1, broadcast => 1,
+       method6 => 1, families => 1, options6 => 1, comments6 => 1, address6 => 1,
+       netmask6 => 1, gateway6 => 1, broadcast6 => 1, 'uplink-id' => 1,
+     };
 
     if (!$first_block) {
        # not printing out options
@@ -1254,18 +1251,29 @@ sub __interface_to_string {
        $raw .= "\tbridge-ports $ports\n";
        $done->{bridge_ports} = 1;
 
-       my $v = defined($d->{bridge_stp}) ? $d->{bridge_stp} : 'off';
-       $raw .= "\tbridge-stp $v\n";
+       my $br_stp = defined($d->{bridge_stp}) ? $d->{bridge_stp} : 'off';
+       my $no_stp = $br_stp eq 'off';
+
+       $raw .= "\tbridge-stp $br_stp\n";
        $done->{bridge_stp} = 1;
 
-       $v = defined($d->{bridge_fd}) ? $d->{bridge_fd} : 0;
-       $raw .= "\tbridge-fd $v\n";
+       # NOTE: forwarding delay must be 2 <= FD <= 30 if STP is enabled
+       if (defined(my $br_fd = $d->{bridge_fd})) {
+           if ($no_stp || ($br_fd >= 2 && $br_fd <= 30)) {
+               $raw .= "\tbridge-fd $br_fd\n";
+           } else {
+               # only complain if the user actually set a value, but not for default fallback below
+               warn "'$iface': ignoring 'bridge_fd' value '$br_fd', outside of allowed range 2-30\n";
+           }
+       } elsif ($no_stp) {
+           $raw .= "\tbridge-fd 0\n";
+       }
        $done->{bridge_fd} = 1;
 
        if( defined($d->{bridge_vlan_aware})) {
            $raw .= "\tbridge-vlan-aware yes\n";
-           $v = defined($d->{bridge_vids}) ? $d->{bridge_vids} : "2-4094";
-           $raw .= "\tbridge-vids $v\n";
+           my $vlans = defined($d->{bridge_vids}) ? $d->{bridge_vids} : "2-4094";
+           $raw .= "\tbridge-vids $vlans\n";
        }
        $done->{bridge_vlan_aware} = 1;
        $done->{bridge_vids} = 1;
@@ -1334,8 +1342,7 @@ sub __interface_to_string {
        $raw .= "\tovs_mtu $d->{mtu}\n" if $d->{mtu};
        $done->{mtu} = 1;
 
-    } elsif ($d->{type} eq 'OVSPort' || $d->{type} eq 'OVSIntPort' ||
-            $d->{type} eq 'OVSBond') {
+    } elsif ($d->{type} eq 'OVSPort' || $d->{type} eq 'OVSIntPort' || $d->{type} eq 'OVSBond') {
 
        $d->{autostart} = 0; # started by the bridge
 
@@ -1446,8 +1453,7 @@ sub __write_etc_network_interfaces {
     # delete unused OVS ports
     foreach my $iface (keys %$ifaces) {
        my $d = $ifaces->{$iface};
-       if ($d->{type} eq 'OVSPort' || $d->{type} eq 'OVSIntPort' ||
-           $d->{type} eq 'OVSBond') {
+       if ($d->{type} eq 'OVSPort' || $d->{type} eq 'OVSIntPort' || $d->{type} eq 'OVSBond') {
            my $brname = $used_ports->{$iface};
            if (!$brname || !$ifaces->{$brname}) {
                if ($iface =~ /^$PVE::Network::PHYSICAL_NIC_RE/) {
@@ -1476,8 +1482,7 @@ sub __write_etc_network_interfaces {
        if ($d->{type} eq 'OVSBridge' && $d->{ovs_ports}) {
            foreach my $p (split (/\s+/, $d->{ovs_ports})) {
                my $n = $ifaces->{$p};
-               die "OVS bridge '$iface' - unable to find port '$p'\n"
-                   if !$n;
+               die "OVS bridge '$iface' - unable to find port '$p'\n" if !$n;
                $n->{autostart} = 0;
                if ($n->{type} eq 'eth') {
                    $n->{type} = 'OVSPort';
@@ -1501,10 +1506,9 @@ sub __write_etc_network_interfaces {
            foreach my $p (split (/\s+/, $d->{ovs_bonds})) {
                my $n = $ifaces->{$p};
                $n->{autostart} = 1;
-               die "OVS bond '$iface' - unable to find slave '$p'\n"
-                   if !$n;
-               die "OVS bond '$iface' - wrong interface type on slave '$p' " .
-                   "('$n->{type}' != 'eth')\n" if $n->{type} ne 'eth';
+               die "OVS bond '$iface' - unable to find slave '$p'\n" if !$n;
+               die "OVS bond '$iface' - wrong interface type on slave '$p' ('$n->{type}' != 'eth')\n"
+                   if $n->{type} ne 'eth';
                &$check_mtu($ifaces, $iface, $p);
            }
        }
@@ -1733,6 +1737,11 @@ NETWORKDOC
            }
        }
 
+       # if 'inet6' is the only family
+       if (scalar($d->{families}->@*) == 1 && $d->{families}[0] eq 'inet6') {
+           $d->{comments6} = delete $d->{comments};
+       }
+
        my $i = 0; # some options should be printed only once
        $raw .= __interface_to_string($iface, $d, $_, !$i++, $ifupdown2) foreach @{$d->{families}};
     }