Signed-off-by: Fiona Ebner <[email protected]>
---
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
[email protected]
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel