Re: [pve-devel] [PATCH] fix hotplug ip configuration V4
and I don't known if the lxc root pid is always the first in the tasks list ? I don't think you can assume that. ___ pve-devel mailing list pve-devel@pve.proxmox.com http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
Re: [pve-devel] [PATCH] fix hotplug ip configuration V4
to find the lxc pid, it's possible to find it here /sys/fs/cgroup/systemd/lxc/$name/tasks but the tasks have all pid, of all running process running in the container. and I don't known if the lxc root pid is always the first in the tasks list ? - Mail original - De: dietmar diet...@proxmox.com À: aderumier aderum...@odiso.com, pve-devel pve-devel@pve.proxmox.com Envoyé: Mardi 30 Juin 2015 08:11:17 Objet: Re: [pve-devel] [PATCH] fix hotplug ip configuration V4 applied, thanks! ___ pve-devel mailing list pve-devel@pve.proxmox.com http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
Re: [pve-devel] [PATCH] fix hotplug ip configuration V4
applied, thanks! ___ pve-devel mailing list pve-devel@pve.proxmox.com http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
Re: [pve-devel] [PATCH] fix hotplug ip configuration
On June 29, 2015 at 2:09 PM Alexandre DERUMIER aderum...@odiso.com wrote: - die no network bridge defined\n if !$net-{bridge}; - - my $res = bridge=$net-{bridge}; + my $res = {}; why? In case we want to switch to a new bridge, and a failure occur - unplug tap from initial bridge write config - plug tap to new bridge -failed Technically, it's not a problem to have a veth not plugged in a bridge. But why do you set $rest to '{}', instead of ''? And I think the resulting value starts with ','? - Mail original - De: dietmar diet...@proxmox.com À: aderumier aderum...@odiso.com, pve-devel pve-devel@pve.proxmox.com Envoyé: Lundi 29 Juin 2015 12:43:12 Objet: Re: [pve-devel] [PATCH] fix hotplug ip configuration diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm index 76c512d..2b7069b 100644 --- a/src/PVE/LXC.pm +++ b/src/PVE/LXC.pm @@ -775,11 +775,9 @@ sub vmstatus { sub print_lxc_network { my $net = shift; - die no network bridge defined\n if !$net-{bridge}; - - my $res = bridge=$net-{bridge}; + my $res = {}; why? - foreach my $k (qw(hwaddr mtu name ip gw ip6 gw6 firewall tag)) { + foreach my $k (qw(bridge hwaddr mtu name ip gw ip6 gw6 firewall tag)) { next if !defined($net-{$k}); $res .= ,$k=$net-{$k}; } @@ -852,6 +850,19 @@ sub find_lxc_console_pids { return $res; } ___ pve-devel mailing list pve-devel@pve.proxmox.com http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
Re: [pve-devel] [PATCH] fix hotplug ip configuration
- die no network bridge defined\n if !$net-{bridge}; - - my $res = bridge=$net-{bridge}; + my $res = {}; why? In case we want to switch to a new bridge, and a failure occur - unplug tap from initial bridge write config - plug tap to new bridge -failed Technically, it's not a problem to have a veth not plugged in a bridge. - Mail original - De: dietmar diet...@proxmox.com À: aderumier aderum...@odiso.com, pve-devel pve-devel@pve.proxmox.com Envoyé: Lundi 29 Juin 2015 12:43:12 Objet: Re: [pve-devel] [PATCH] fix hotplug ip configuration diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm index 76c512d..2b7069b 100644 --- a/src/PVE/LXC.pm +++ b/src/PVE/LXC.pm @@ -775,11 +775,9 @@ sub vmstatus { sub print_lxc_network { my $net = shift; - die no network bridge defined\n if !$net-{bridge}; - - my $res = bridge=$net-{bridge}; + my $res = {}; why? - foreach my $k (qw(hwaddr mtu name ip gw ip6 gw6 firewall tag)) { + foreach my $k (qw(bridge hwaddr mtu name ip gw ip6 gw6 firewall tag)) { next if !defined($net-{$k}); $res .= ,$k=$net-{$k}; } @@ -852,6 +850,19 @@ sub find_lxc_console_pids { return $res; } ___ pve-devel mailing list pve-devel@pve.proxmox.com http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
Re: [pve-devel] [PATCH] fix hotplug ip configuration
I wonder if we can avoid running lxc-info, by using something similar we have in: sub find_lxc_console_pids { ... } We can get the pids of all running containers, including pids for console, and we can also replace list_active_containers() ? yes, I think it better too if we can need to run lxc-info. I'll check that. - Mail original - De: dietmar diet...@proxmox.com À: aderumier aderum...@odiso.com, pve-devel pve-devel@pve.proxmox.com Envoyé: Lundi 29 Juin 2015 12:52:44 Objet: Re: [pve-devel] [PATCH] fix hotplug ip configuration +sub find_lxc_pid { + my ($vmid) = @_; + + my $pid = undef; + my $parser = sub { + my $line = shift; + $pid = $1 if $line =~ m/PID:\s+(\d+)/; + }; + PVE::Tools::run_command(['lxc-info', '-n', $vmid], outfunc = $parser); + + return $pid; +} + I wonder if we can avoid running lxc-info, by using something similar we have in: sub find_lxc_console_pids { ... } We can get the pids of all running containers, including pids for console, and we can also replace list_active_containers() ? ___ pve-devel mailing list pve-devel@pve.proxmox.com http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
Re: [pve-devel] [PATCH] fix hotplug ip configuration
diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm index 76c512d..2b7069b 100644 --- a/src/PVE/LXC.pm +++ b/src/PVE/LXC.pm @@ -775,11 +775,9 @@ sub vmstatus { sub print_lxc_network { my $net = shift; -die no network bridge defined\n if !$net-{bridge}; - -my $res = bridge=$net-{bridge}; +my $res = {}; why? -foreach my $k (qw(hwaddr mtu name ip gw ip6 gw6 firewall tag)) { +foreach my $k (qw(bridge hwaddr mtu name ip gw ip6 gw6 firewall tag)) { next if !defined($net-{$k}); $res .= ,$k=$net-{$k}; } @@ -852,6 +850,19 @@ sub find_lxc_console_pids { return $res; } ___ pve-devel mailing list pve-devel@pve.proxmox.com http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
Re: [pve-devel] [PATCH] fix hotplug ip configuration
But why do you set $rest to '{}', instead of ''? And I think the resulting value starts with ','? oh,yes, don't known what I have done here... I think I have mixed print_lxc_network and parse_lxc_network, ... sorry ... maybe simply sub print_lxc_network { my ($data) = @_; die no network name defined\n if !$net-{name}; my $res = name=$net-{name}; foreach my $k (qw(bridge hwaddr mtu ip gw ip6 gw6 firewall tag)) { } as name is mandatory - Mail original - De: dietmar diet...@proxmox.com À: aderumier aderum...@odiso.com Cc: pve-devel pve-devel@pve.proxmox.com Envoyé: Lundi 29 Juin 2015 16:03:23 Objet: Re: [pve-devel] [PATCH] fix hotplug ip configuration On June 29, 2015 at 2:09 PM Alexandre DERUMIER aderum...@odiso.com wrote: - die no network bridge defined\n if !$net-{bridge}; - - my $res = bridge=$net-{bridge}; + my $res = {}; why? In case we want to switch to a new bridge, and a failure occur - unplug tap from initial bridge write config - plug tap to new bridge -failed Technically, it's not a problem to have a veth not plugged in a bridge. But why do you set $rest to '{}', instead of ''? And I think the resulting value starts with ','? - Mail original - De: dietmar diet...@proxmox.com À: aderumier aderum...@odiso.com, pve-devel pve-devel@pve.proxmox.com Envoyé: Lundi 29 Juin 2015 12:43:12 Objet: Re: [pve-devel] [PATCH] fix hotplug ip configuration diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm index 76c512d..2b7069b 100644 --- a/src/PVE/LXC.pm +++ b/src/PVE/LXC.pm @@ -775,11 +775,9 @@ sub vmstatus { sub print_lxc_network { my $net = shift; - die no network bridge defined\n if !$net-{bridge}; - - my $res = bridge=$net-{bridge}; + my $res = {}; why? - foreach my $k (qw(hwaddr mtu name ip gw ip6 gw6 firewall tag)) { + foreach my $k (qw(bridge hwaddr mtu name ip gw ip6 gw6 firewall tag)) { next if !defined($net-{$k}); $res .= ,$k=$net-{$k}; } @@ -852,6 +850,19 @@ sub find_lxc_console_pids { return $res; } ___ pve-devel mailing list pve-devel@pve.proxmox.com http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
Re: [pve-devel] [PATCH] fix hotplug ip configuration V3
I am not sure if that always works. AFAIK the init process can be an arbitrary name, and that is why lxc-info calls a monitor command to get the PID? Also, your code opens/close many files. So I think the original approach calling lxc-info is better for now. And it is more efficient once we have perl bindings for LXC? +sub find_lxc_pid { +my ($vmid) = @_; + +my $res = undef; + +PVE::Tools::dir_glob_foreach('/proc', '\d+', sub { +my ($pid) = @_; + +my $cmdline = PVE::Tools::file_read_firstline(/proc/$pid/cmdline); +return if !$cmdline; + +if($cmdline =~ m/^init \[2\]/) { +my $line = PVE::Tools::file_read_firstline(/proc/$pid/cpuset); +$res = $pid if $line eq /lxc/$vmid; +} +}); +return $res; +} ___ pve-devel mailing list pve-devel@pve.proxmox.com http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
Re: [pve-devel] [PATCH] fix hotplug ip configuration V3
I am not sure if that always works. AFAIK the init process can be an arbitrary name, oh, ok, didn't known that and that is why lxc-info calls a monitor command to get the PID? I really don't known, don't have dig inside the lxc-info code Also, your code opens/close many files. So I think the original approach calling lxc-info is better for now. Ok, I'll resend a v4 with previous code And it is more efficient once we have perl bindings for LXC? yes, sure. - Mail original - De: dietmar diet...@proxmox.com À: aderumier aderum...@odiso.com, pve-devel pve-devel@pve.proxmox.com Envoyé: Lundi 29 Juin 2015 17:45:53 Objet: Re: [pve-devel] [PATCH] fix hotplug ip configuration V3 I am not sure if that always works. AFAIK the init process can be an arbitrary name, and that is why lxc-info calls a monitor command to get the PID? Also, your code opens/close many files. So I think the original approach calling lxc-info is better for now. And it is more efficient once we have perl bindings for LXC? +sub find_lxc_pid { + my ($vmid) = @_; + + my $res = undef; + + PVE::Tools::dir_glob_foreach('/proc', '\d+', sub { + my ($pid) = @_; + + my $cmdline = PVE::Tools::file_read_firstline(/proc/$pid/cmdline); + return if !$cmdline; + + if($cmdline =~ m/^init \[2\]/) { + my $line = PVE::Tools::file_read_firstline(/proc/$pid/cpuset); + $res = $pid if $line eq /lxc/$vmid; + } + }); + return $res; +} ___ pve-devel mailing list pve-devel@pve.proxmox.com http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
Re: [pve-devel] [PATCH] fix hotplug ip configuration
+sub find_lxc_pid { +my ($vmid) = @_; + +my $pid = undef; +my $parser = sub { + my $line = shift; + $pid = $1 if $line =~ m/PID:\s+(\d+)/; +}; +PVE::Tools::run_command(['lxc-info', '-n', $vmid], outfunc = $parser); + + return $pid; +} + I wonder if we can avoid running lxc-info, by using something similar we have in: sub find_lxc_console_pids { ... } We can get the pids of all running containers, including pids for console, and we can also replace list_active_containers() ? ___ pve-devel mailing list pve-devel@pve.proxmox.com http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel