From: Fiona Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH container v3 3/8] api: create: factor out create_ct_determine_mp_param helper
Date: Fri, 23 Jan 2026 15:34:23 +0100 [thread overview]
Message-ID: <20260123143454.150800-4-f.ebner@proxmox.com> (raw)
In-Reply-To: <20260123143454.150800-1-f.ebner@proxmox.com>
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
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
next prev parent reply other threads:[~2026-01-23 14:35 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-23 14:34 [pve-devel] [PATCH-SERIES container/manager v3 0/8] api: restore: allow keeping not backed-up volumes Fiona Ebner
2026-01-23 14:34 ` [pve-devel] [PATCH container v3 1/8] api: create: move delayed_mp_param variable closer to usage Fiona Ebner
2026-01-23 14:34 ` [pve-devel] [PATCH container v3 2/8] api: create: reduce scope for $mp_param variable Fiona Ebner
2026-01-23 14:34 ` Fiona Ebner [this message]
2026-01-23 14:34 ` [pve-devel] [PATCH container v3 4/8] run make tidy Fiona Ebner
2026-01-23 14:34 ` [pve-devel] [PATCH container v3 5/8] api: create: create_ct_determine_mp_param: improve code style Fiona Ebner
2026-01-23 14:34 ` [pve-devel] [PATCH container v3 6/8] api: create: get rid of $storage_only_mode variable Fiona Ebner
2026-01-23 14:34 ` [pve-devel] [PATCH container v3 7/8] api: restore: allow keeping not backed-up volumes Fiona Ebner
2026-01-23 14:34 ` [pve-devel] [PATCH manager v3 8/8] ui: restore: enable safeguarding of mount point volumes by default Fiona Ebner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260123143454.150800-4-f.ebner@proxmox.com \
--to=f.ebner@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox