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) server-digest SHA256) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id BD0D891972 for ; Thu, 22 Dec 2022 13:54:27 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 57CCC1B731 for ; Thu, 22 Dec 2022 13:54:27 +0100 (CET) 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 for ; Thu, 22 Dec 2022 13:54:24 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 1B6BA420B7 for ; Thu, 22 Dec 2022 13:54:24 +0100 (CET) Date: Thu, 22 Dec 2022 13:54:12 +0100 From: Fabian =?iso-8859-1?q?Gr=FCnbichler?= To: Proxmox VE development discussion References: <20221129140019.203126-1-d.tschlatscher@proxmox.com> In-Reply-To: <20221129140019.203126-1-d.tschlatscher@proxmox.com> MIME-Version: 1.0 User-Agent: astroid/0.16.0 (https://github.com/astroidmail/astroid) Message-Id: <1671713625.f22m9tmm1x.astroid@yuna.none> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-SPAM-LEVEL: Spam detection results: 0 AWL 0.132 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 SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] applied-series: [PATCH container v2 1/2] restore: clean up config when invalid source archive is given 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: Thu, 22 Dec 2022 12:54:27 -0000 thanks! On November 29, 2022 3:00 pm, Daniel Tschlatscher wrote: > Before, if a non-existent source archive parameter was passed when > restoring a container, the task would fail but leave an empty config > file behind. The same with invalid mount point configurations. > In both cases, the empty config will now be removed. >=20 > Signed-off-by: Daniel Tschlatscher > --- > Changes from v1: > * According to Thomas' suggestion I revised the code so that all > errors are now handled centrally in the lower clean up handler which > before was only used for the case when the config was unrecoverable > and merged the two consecutive eval blocks into one. > For this, I repurposed the $remove_lock variable and renamed it to > better reflect its new usage. >=20 > src/PVE/API2/LXC.pm | 19 +++++++++---------- > 1 file changed, 9 insertions(+), 10 deletions(-) >=20 > diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm > index 03d7ea0..f2113de 100644 > --- a/src/PVE/API2/LXC.pm > +++ b/src/PVE/API2/LXC.pm > @@ -372,12 +372,13 @@ __PACKAGE__->register_method({ > eval { PVE::LXC::Config->create_and_lock_config($vmid, $force) }; > die "$emsg $@" if $@; > =20 > - my $remove_lock =3D 1; > + my $destroy_config_on_error =3D !$same_container_exists; > =20 > my $code =3D sub { > my $old_conf =3D PVE::LXC::Config->load_config($vmid); > my $was_template; > =20 > + my $vollist =3D []; > eval { > my $orig_mp_param; # only used if $restore > if ($restore) { > @@ -444,14 +445,10 @@ __PACKAGE__->register_method({ > $mp_param->{rootfs} =3D "$storage:4"; # defaults to 4GB > } > } > - }; > - die "$emsg $@" if $@; > =20 > - # up until here we did not modify the container, besides the lock > - $remove_lock =3D 0; > + # up until here we did not modify the container, besides the lock > + $destroy_config_on_error =3D 1; > =20 > - my $vollist =3D []; > - eval { > $vollist =3D PVE::LXC::create_disks($storage_cfg, $vmid, $mp_param, $c= onf); > =20 > # we always have the 'create' lock so check for more than 1 entry > @@ -499,8 +496,10 @@ __PACKAGE__->register_method({ > }; > if (my $err =3D $@) { > PVE::LXC::destroy_disks($storage_cfg, $vollist); > - eval { PVE::LXC::Config->destroy_config($vmid) }; > - warn $@ if $@; > + if ($destroy_config_on_error) { > + eval { PVE::LXC::Config->destroy_config($vmid) }; > + warn $@ if $@; > + } > die "$emsg $err"; > } > PVE::AccessControl::add_vm_to_pool($vmid, $pool) if $pool; > @@ -516,7 +515,7 @@ __PACKAGE__->register_method({ > }; > if (my $err =3D $@) { > # if we aborted before changing the container, we must remove the crea= te lock > - if ($remove_lock) { > + if (!$destroy_config_on_error) { > PVE::LXC::Config->remove_lock($vmid, 'create'); > } > die $err; > --=20 > 2.30.2 >=20 >=20 >=20 > _______________________________________________ > pve-devel mailing list > pve-devel@lists.proxmox.com > https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel >=20 >=20 >=20