From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id C396370B9F for ; Wed, 15 Jun 2022 10:12:36 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id B488C27286 for ; Wed, 15 Jun 2022 10:12:06 +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)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id D3CDC2727B for ; Wed, 15 Jun 2022 10:12:04 +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 A4DF443B4A for ; Wed, 15 Jun 2022 10:12:04 +0200 (CEST) Date: Wed, 15 Jun 2022 10:11:56 +0200 From: Fabian =?iso-8859-1?q?Gr=FCnbichler?= To: Proxmox VE development discussion References: <20220614122242.320670-1-d.tschlatscher@proxmox.com> <1655211024.erde2ks6ir.astroid@nora.none> In-Reply-To: MIME-Version: 1.0 User-Agent: astroid/0.15.0 (https://github.com/astroidmail/astroid) Message-Id: <1655280267.gyaahrizk0.astroid@nora.none> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-SPAM-LEVEL: Spam detection results: 0 AWL -0.231 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_ASCII_DIVIDERS 0.8 Spam that uses ascii formatting tricks KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [proxmox.com, lxc.pm] Subject: Re: [pve-devel] [PATCH container] fix: cloning a locked container creates an empty config X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Jun 2022 08:12:36 -0000 On June 14, 2022 3:43 pm, Daniel Tschlatscher wrote: >=20 >=20 > On 6/14/22 14:51, Fabian Gr=C3=BCnbichler wrote: >> On June 14, 2022 2:22 pm, Daniel Tschlatscher wrote: >>> When an attempt was made to clone a locked container the API would >>> correctly present the error 'CT is locked (disk)' but create the >>> config files for the new container anyway and then abort. >>> >>> The fix is to simply check whether the CT config is locked before >>> creating the configs for the new container. >>=20 >> is there a reason for not just moving it to the start of the eval block=20 >> to avoid the same problem being re-introduced in the future? any error=20 >> occuring inside the eval block will then trigger a cleanup.. >>=20 >=20 > When an error occurs and the cleanup is triggered, the cleanup tries to > release the lock again. >=20 > Moving the set_lock function into the eval block would create a problem > here: > If the lock was created by another process (and if it is a 'disk' lock) > set_lock would emit an error and the lock would be incorrectly released > by this process, which did not originally acquire it. my suggestion was not to move it *into* the eval block, but next to the=20 *start* of the eval block, like so: my $newconf =3D {}; my $mountpoints =3D {}; my $fullclone =3D {}; my $vollist =3D []; my $running; my $src_conf =3D PVE::LXC::Config->set_lock($vmid, 'disk'); $running =3D PVE::LXC::check_running($vmid) || 0; my $full =3D extract_param($param, 'full'); if (!defined($full)) { $full =3D !PVE::LXC::Config->is_template($src_conf); } my $lock_and_reload =3D sub { my ($vmid, $code) =3D @_; return PVE::LXC::Config->lock_config($vmid, sub { my $conf =3D PVE::LXC::Config->load_config($vmid); die "Lost 'create' config lock, aborting.\n" if !PVE::LXC::Config->has_lock($conf, 'create'); return $code->($conf); }); }; PVE::LXC::Config->create_and_lock_config($newid, 0); PVE::Firewall::clone_vmfw_conf($vmid, $newid); # error handling for this block will cleanup configs eval { die "parameter 'storage' not allowed for linked clones\n" if defined($storage) && !$full; to reduce the chances of re-introducing the bug by adding potentially=20 failing calls between create_and_lock_config and the eval block. and now=20 that I took a second look I realized that clone_vm_fw_conf is exactly=20 such a call, and should therefore be moved into the eval ;) >=20 >>> >>> Signed-off-by: Daniel Tschlatscher >>> --- >>> src/PVE/API2/LXC.pm | 6 +++--- >>> 1 file changed, 3 insertions(+), 3 deletions(-) >>> >>> diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm >>> index 64724cb..e1b4cd3 100644 >>> --- a/src/PVE/API2/LXC.pm >>> +++ b/src/PVE/API2/LXC.pm >>> @@ -1461,9 +1461,6 @@ __PACKAGE__->register_method({ >>> my $vollist =3D []; >>> my $running; >>> =20 >>> - PVE::LXC::Config->create_and_lock_config($newid, 0); >>> - PVE::Firewall::clone_vmfw_conf($vmid, $newid); >>> - >>> my $lock_and_reload =3D sub { >>> my ($vmid, $code) =3D @_; >>> return PVE::LXC::Config->lock_config($vmid, sub { >>> @@ -1477,6 +1474,9 @@ __PACKAGE__->register_method({ >>> =20 >>> my $src_conf =3D PVE::LXC::Config->set_lock($vmid, 'disk'); >>> =20 >>> + PVE::LXC::Config->create_and_lock_config($newid, 0); >>> + PVE::Firewall::clone_vmfw_conf($vmid, $newid); >>> + >>> $running =3D PVE::LXC::check_running($vmid) || 0; >>> =20 >>> my $full =3D extract_param($param, 'full'); >>> --=20 >>> 2.30.2 >>> >>> >>> >>> _______________________________________________ >>> pve-devel mailing list >>> pve-devel@lists.proxmox.com >>> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel >>> >>> >>> >>=20 >>=20 >> _______________________________________________ >> pve-devel mailing list >> pve-devel@lists.proxmox.com >> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel >>=20 >>=20 >=20 >=20 > _______________________________________________ > pve-devel mailing list > pve-devel@lists.proxmox.com > https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel >=20