From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <t.lamprecht@proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id 4AB3D72AF2
 for <pve-devel@lists.proxmox.com>; Sat,  3 Jul 2021 00:33:31 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 337EADA70
 for <pve-devel@lists.proxmox.com>; Sat,  3 Jul 2021 00:33:01 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [94.136.29.106])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS id D3436DA5F
 for <pve-devel@lists.proxmox.com>; Sat,  3 Jul 2021 00:32:59 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 972F2404E2
 for <pve-devel@lists.proxmox.com>; Sat,  3 Jul 2021 00:32:59 +0200 (CEST)
Message-ID: <ac3be8f7-b90f-d58b-fc9c-764745c6853e@proxmox.com>
Date: Sat, 3 Jul 2021 00:32:42 +0200
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:90.0) Gecko/20100101
 Thunderbird/90.0
Content-Language: en-US
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>,
 Stoiko Ivanov <s.ivanov@proxmox.com>
References: <20210702182152.485913-1-s.ivanov@proxmox.com>
 <20210702182152.485913-3-s.ivanov@proxmox.com>
From: Thomas Lamprecht <t.lamprecht@proxmox.com>
In-Reply-To: <20210702182152.485913-3-s.ivanov@proxmox.com>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.136 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 KAM_NUMSUBJECT 0.5 Subject ends in numbers excluding current years
 NICE_REPLY_A           -0.001 Looks like a legit reply (A)
 POISEN_SPAM_PILL          0.1 Meta: its spam
 POISEN_SPAM_PILL_1        0.1 random spam to be learned in bayes
 POISEN_SPAM_PILL_3        0.1 random spam to be learned in bayes
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See
 http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more
 information. [pve6to7.pm]
Subject: Re: [pve-devel] [PATCH manager 1/1] pve6to7: check for containers
 not supporting pure cgroupv2
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Fri, 02 Jul 2021 22:33:31 -0000

On 02.07.21 20:21, Stoiko Ivanov wrote:
> Ordered as much as possible to exit early, still might take quite some
> time on systems with many containers (which do support cgroupv2).

The early abort once one is found seems like a good idea in general, but
I still do not really like that happening unconditionally, this could get hidden
behind and  opt-in CLI option flag - with a single skip log if not taken.

An admin with only bleeding-edge Arch Linux container then could then just
snicker over software from the stone age and just continue ;)

Also, you're currently missing some cheap optimizations like skipping devuan/alpine
config ostypes early, doing needless work for them.

> 
> needs a versioned bump on pve-container

I'd rather prefer copying the required helpers over, as this is mainly required
for stable-6, and it would make it way easier than having versioned dependency
handling for just this in two releases.

> 
> Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
> ---
>  PVE/CLI/pve6to7.pm | 68 ++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 68 insertions(+)
> 
> diff --git a/PVE/CLI/pve6to7.pm b/PVE/CLI/pve6to7.pm
> index 60edac11..3d7c67bd 100644
> --- a/PVE/CLI/pve6to7.pm
> +++ b/PVE/CLI/pve6to7.pm
> @@ -23,6 +23,9 @@ use PVE::Tools qw(run_command split_list);
>  use PVE::QemuConfig;
>  use PVE::QemuServer;
>  use PVE::VZDump::Common;
> +use PVE::LXC;
> +use PVE::LXC::Config;
> +use PVE::LXC::Setup;
>  
>  use Term::ANSIColor;
>  
> @@ -890,6 +893,70 @@ sub check_storage_content {
>  	log_pass("no problems found");
>      }
>  }
> +sub check_containers_cgroup_compat {
> +
> +    my $kernel_cli = PVE::Tools::file_get_contents('/proc/cmdline');
> +    if ($kernel_cli =~ /systemd.unified_cgroup_hierarchy=0/){
> +	log_skip("System explicitly configured for legacy hybrid cgroup hierarchy.");
> +	return;
> +    }
> +
> +    my $cts = eval { PVE::API2::LXC->vmlist({ node => $nodename }) };
> +    if ($@) {
> +	log_warn("Failed to retrieve information about this node's CTs - $@");
> +	return;
> +    }
> +
> +    if (!defined($cts) || !scalar(@$cts)) {
> +	log_skip("No containers on node detected.");
> +	return;
> +    }
> +    my @running_vmids = map { $_->{status} eq 'running' ? $_->{vmid} : () } @$cts;
> +    my @offline_vmids = map { $_->{status} ne 'running' ? $_->{vmid} : () } @$cts;

nit, but why not grep? Would make it a bit more explicit here, avoiding that any
innocent reader thinks map makes this not work and then spent time getting proved
otherwise ;-)

> +
> +    my $legacy_container=0;
> +
> +    for my $ctid (@running_vmids) {
> +	my $pid = eval { PVE::LXC::find_lxc_pid($ctid) };
> +	if (my $err = $@) {
> +	    log_warn("Failed to get PID for running CT $ctid - $err");
> +	    next;
> +	}
> +	my $rootdir = "/proc/$pid/root";
> +	my $conf = PVE::LXC::Config->load_config($ctid);
> +	my $lxc_setup = PVE::LXC::Setup->new($conf, $rootdir);
> +	if (!$lxc_setup->unified_cgroupv2_support()) {
> +	    log_warn("CT $ctid does not support running in a unified cgroup v2 layout - either " .

Maybe start with "Found at least one CT ($ctid) which does not supp...", makes the
nature of the check slightly less subtle IMO.

> +		"upgrade it or set systemd.unified_cgroup_hierarchy=0 in the kernel cmdline - "  .
> +		"skipping further checks");

> +	    return;
> +	}
> +    }
> +
> +    my $storage_cfg = PVE::Storage::config();
> +    for my $ctid (@offline_vmids) {
> +	my ($conf, $rootdir, $lxc_setup);
> +	eval {
> +	    $conf = PVE::LXC::Config->load_config($ctid);
> +	    $rootdir = PVE::LXC::mount_all($ctid, $storage_cfg, $conf);
> +	    $lxc_setup = PVE::LXC::Setup->new($conf, $rootdir);
> +	};
> +	if (my $err = $@) {
> +	    log_warn("Failed to load config and mount CT $ctid - $err");
> +	    eval { PVE::LXC::umount_all($ctid, $storage_cfg, $conf) };
> +	    next;
> +	}
> +	if (!$lxc_setup->unified_cgroupv2_support()) {
> +	    log_warn("CT $ctid does not support running in a unified cgroup v2 layout - either " .
> +		"upgrade it or set systemd.unified_cgroup_hierarchy=0 in the kernel cmdline - "  .
> +		"skipping further checks");

maybe factor out the common part of that specific log message

> +	    eval { PVE::LXC::umount_all($ctid, $storage_cfg, $conf) };
> +	    last;
> +	}
> +
> +	eval { PVE::LXC::umount_all($ctid, $storage_cfg, $conf) };
> +    }
> +};
>  
>  sub check_misc {
>      print_header("MISCELLANEOUS CHECKS");
> @@ -986,6 +1053,7 @@ sub check_misc {
>      check_custom_pool_roles();
>      check_description_lengths();
>      check_storage_content();
> +    check_containers_cgroup_compat();
>  }
>  
>  __PACKAGE__->register_method ({
>