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 287E463D2F for ; Wed, 25 Nov 2020 15:08:33 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 123831AFFC for ; Wed, 25 Nov 2020 15:08:03 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (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 73BE01AFF2 for ; Wed, 25 Nov 2020 15:08:02 +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 3EBE6415E5 for ; Wed, 25 Nov 2020 15:08:02 +0100 (CET) From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= To: pve-devel@lists.proxmox.com Date: Wed, 25 Nov 2020 15:07:49 +0100 Message-Id: <20201125140750.2851534-1-f.gruenbichler@proxmox.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.024 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust 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. [create.pm, lxc.pm] Subject: [pve-devel] [PATCH container 1/2] restore: pass target vmid to config recovery 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, 25 Nov 2020 14:08:33 -0000 so that we get the correct warning prefix when the config contains bogus lines. Signed-off-by: Fabian Grünbichler --- src/PVE/API2/LXC.pm | 4 ++-- src/PVE/LXC/Create.pm | 19 +++++++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm index 9ecfb12..a263104 100644 --- a/src/PVE/API2/LXC.pm +++ b/src/PVE/API2/LXC.pm @@ -354,7 +354,7 @@ __PACKAGE__->register_method({ die "can't overwrite running container\n" if PVE::LXC::check_running($vmid); if ($is_root && $archive ne '-') { my $orig_conf; - ($orig_conf, $orig_mp_param) = PVE::LXC::Create::recover_config($storage_cfg, $archive); + ($orig_conf, $orig_mp_param) = PVE::LXC::Create::recover_config($storage_cfg, $archive, $vmid); $was_template = delete $orig_conf->{template}; # When we're root call 'restore_configuration' with restricted=0, # causing it to restore the raw lxc entries, among which there may be @@ -366,7 +366,7 @@ __PACKAGE__->register_method({ if ($storage_only_mode) { if ($restore) { if (!defined($orig_mp_param)) { - (undef, $orig_mp_param) = PVE::LXC::Create::recover_config($storage_cfg, $archive); + (undef, $orig_mp_param) = PVE::LXC::Create::recover_config($storage_cfg, $archive, $vmid); } $mp_param = $orig_mp_param; die "rootfs configuration could not be recovered, please check and specify manually!\n" diff --git a/src/PVE/LXC/Create.pm b/src/PVE/LXC/Create.pm index 39902a2..d3939de 100644 --- a/src/PVE/LXC/Create.pm +++ b/src/PVE/LXC/Create.pm @@ -173,22 +173,24 @@ sub restore_tar_archive { } sub recover_config { - my ($storage_cfg, $volid) = @_; + my ($storage_cfg, $volid, $vmid) = @_; my ($storeid, $volname) = PVE::Storage::parse_volume_id($volid, 1); if (defined($storeid)) { my $scfg = PVE::Storage::storage_check_enabled($storage_cfg, $storeid); if ($scfg->{type} eq 'pbs') { - return recover_config_from_proxmox_backup($storage_cfg, $volid); + return recover_config_from_proxmox_backup($storage_cfg, $volid, $vmid); } } my $archive = PVE::Storage::abs_filesystem_path($storage_cfg, $volid); - recover_config_from_tar($archive); + recover_config_from_tar($archive, $vmid); } sub recover_config_from_proxmox_backup { - my ($storage_cfg, $volid) = @_; + my ($storage_cfg, $volid, $vmid) = @_; + + $vmid //= 0; my ($storeid, $volname) = PVE::Storage::parse_volume_id($volid); my $scfg = PVE::Storage::storage_config($storage_cfg, $storeid); @@ -208,7 +210,7 @@ sub recover_config_from_proxmox_backup { PVE::Storage::PBSPlugin::run_raw_client_cmd( $scfg, $storeid, $cmd, $param, outfunc => $outfunc); - my $conf = PVE::LXC::Config::parse_pct_config("/lxc/0.conf" , $raw); + my $conf = PVE::LXC::Config::parse_pct_config("/lxc/${vmid}.conf" , $raw); delete $conf->{snapshots}; @@ -222,15 +224,16 @@ sub recover_config_from_proxmox_backup { } sub recover_config_from_tar { - my ($archive) = @_; + my ($archive, $vmid) = @_; my ($raw, $conf_file) = PVE::Storage::extract_vzdump_config_tar($archive, qr!(\./etc/vzdump/(pct|vps)\.conf)$!); my $conf; my $mp_param = {}; + $vmid //= 0; if ($conf_file =~ m/pct\.conf/) { - $conf = PVE::LXC::Config::parse_pct_config("/lxc/0.conf" , $raw); + $conf = PVE::LXC::Config::parse_pct_config("/lxc/${vmid}.conf" , $raw); delete $conf->{snapshots}; @@ -273,7 +276,7 @@ sub restore_configuration_from_proxmox_backup { my ($vtype, $name, undef, undef, undef, undef, $format) = PVE::Storage::parse_volname($storage_cfg, $archive); - my $oldconf = recover_config_from_proxmox_backup($storage_cfg, $archive); + my $oldconf = recover_config_from_proxmox_backup($storage_cfg, $archive, $vmid); sanitize_and_merge_config($conf, $oldconf, $restricted, $unique); -- 2.20.1