From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id BCCEB1FF13E for ; Fri, 23 Jan 2026 15:35:44 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 5A79CFEF2; Fri, 23 Jan 2026 15:35:34 +0100 (CET) From: Fiona Ebner To: pve-devel@lists.proxmox.com Date: Fri, 23 Jan 2026 15:34:23 +0100 Message-ID: <20260123143454.150800-4-f.ebner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260123143454.150800-1-f.ebner@proxmox.com> References: <20260123143454.150800-1-f.ebner@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1769178839056 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.015 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy 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] [PATCH container v3 3/8] api: create: factor out create_ct_determine_mp_param helper 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: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" Signed-off-by: Fiona Ebner --- New in v3. Avoided running make tidy here to make it easier to review. The next patch can be squashed into this when applying for that. src/PVE/API2/LXC.pm | 157 ++++++++++++++++++++++++++------------------ 1 file changed, 94 insertions(+), 63 deletions(-) diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm index 4370c57..ede8f62 100644 --- a/src/PVE/API2/LXC.pm +++ b/src/PVE/API2/LXC.pm @@ -135,6 +135,89 @@ __PACKAGE__->register_method({ }, }); +my sub create_ct_determine_mp_param { + my ( + $storage_cfg, + $vmid, + $archive, + $api_mp_param, + $orig_mp_param, + $restore, + $storage, + $storage_only_mode, + $is_root, + ) = @_; + + my $mp_param; + my $delayed_mp_param = {}; + + if (!$storage_only_mode) { + $mp_param = $api_mp_param; + return ($mp_param, $delayed_mp_param); + } + + if (!$restore) { + $mp_param = $api_mp_param; + $mp_param->{rootfs} = "$storage:4"; # defaults to 4GB + return ($mp_param, $delayed_mp_param); + } + + if (!defined($orig_mp_param)) { + print "recovering backed-up configuration from '$archive'\n"; + (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" + if !defined($mp_param->{rootfs}); + PVE::LXC::Config->foreach_volume( + $mp_param, + sub { + my ($ms, $mountpoint) = @_; + my $type = $mountpoint->{type}; + if ($type eq 'volume') { + die + "unable to detect disk size - please specify $ms (size)\n" + if !defined($mountpoint->{size}); + my $disksize = $mountpoint->{size} / (1024 * 1024 * 1024); # create_disks expects GB as unit size + delete $mountpoint->{size}; + $mountpoint->{volume} = "$storage:$disksize"; + $mp_param->{$ms} = PVE::LXC::Config->print_ct_mountpoint( + $mountpoint, + $ms eq 'rootfs', + ); + } else { + my $type = $mountpoint->{type}; + die + "restoring rootfs to $type mount is only possible by specifying -rootfs manually!\n" + if ($ms eq 'rootfs'); + die + "restoring '$ms' to $type mount is only possible for root\n" + if !$is_root; + + if ($mountpoint->{backup}) { + warn "WARNING - unsupported configuration!\n"; + warn + "backup was enabled for $type mount point $ms ('$mountpoint->{mp}')\n"; + warn + "mount point configuration will be restored after archive extraction!\n"; + warn + "contained files will be restored to wrong directory!\n"; + } + delete $mp_param->{$ms}; # actually delay bind/dev mps + $delayed_mp_param->{$ms} = + PVE::LXC::Config->print_ct_mountpoint( + $mountpoint, + $ms eq 'rootfs', + ); + } + }, + ); + + return ($mp_param, $delayed_mp_param); +} + __PACKAGE__->register_method({ name => 'create_vm', path => '', @@ -465,69 +548,17 @@ __PACKAGE__->register_method({ } } - my $mp_param; - my $delayed_mp_param = {}; - if ($storage_only_mode) { - if ($restore) { - if (!defined($orig_mp_param)) { - print "recovering backed-up configuration from '$archive'\n"; - (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" - if !defined($mp_param->{rootfs}); - PVE::LXC::Config->foreach_volume( - $mp_param, - sub { - my ($ms, $mountpoint) = @_; - my $type = $mountpoint->{type}; - if ($type eq 'volume') { - die - "unable to detect disk size - please specify $ms (size)\n" - if !defined($mountpoint->{size}); - my $disksize = $mountpoint->{size} / (1024 * 1024 * 1024); # create_disks expects GB as unit size - delete $mountpoint->{size}; - $mountpoint->{volume} = "$storage:$disksize"; - $mp_param->{$ms} = PVE::LXC::Config->print_ct_mountpoint( - $mountpoint, - $ms eq 'rootfs', - ); - } else { - my $type = $mountpoint->{type}; - die - "restoring rootfs to $type mount is only possible by specifying -rootfs manually!\n" - if ($ms eq 'rootfs'); - die - "restoring '$ms' to $type mount is only possible for root\n" - if !$is_root; - - if ($mountpoint->{backup}) { - warn "WARNING - unsupported configuration!\n"; - warn - "backup was enabled for $type mount point $ms ('$mountpoint->{mp}')\n"; - warn - "mount point configuration will be restored after archive extraction!\n"; - warn - "contained files will be restored to wrong directory!\n"; - } - delete $mp_param->{$ms}; # actually delay bind/dev mps - $delayed_mp_param->{$ms} = - PVE::LXC::Config->print_ct_mountpoint( - $mountpoint, - $ms eq 'rootfs', - ); - } - }, - ); - } else { - $mp_param = $api_mp_param; - $mp_param->{rootfs} = "$storage:4"; # defaults to 4GB - } - } else { - $mp_param = $api_mp_param; - } + my ($mp_param, $delayed_mp_param) = create_ct_determine_mp_param( + $storage_cfg, + $vmid, + $archive, + $api_mp_param, + $orig_mp_param, + $restore, + $storage, + $storage_only_mode, + $is_root, + ); # up until here we did not modify the container, besides the lock $destroy_config_on_error = 1; -- 2.47.3 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel