[pve-devel] [PATCH container] Add paramter map in used storage methods
Alwin Antreich
a.antreich at proxmox.com
Fri Aug 17 15:44:27 CEST 2018
This patch updates the paramter list of methods called from pve-storage
to support the use of the flag map. The pve-container code now calls for
an explicit device mapping. Checks for krbd support are removed.
Signed-off-by: Alwin Antreich <a.antreich at proxmox.com>
---
src/PVE/API2/LXC.pm | 30 +++++++++++++++---------------
src/PVE/CLI/pct.pm | 2 +-
src/PVE/LXC.pm | 46 ++++++++++++++++++++--------------------------
src/PVE/LXC/Config.pm | 4 ++--
src/PVE/LXC/Migrate.pm | 10 +++++-----
src/PVE/VZDump/LXC.pm | 4 ++--
6 files changed, 45 insertions(+), 51 deletions(-)
diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm
index cbcc393..75dca10 100644
--- a/src/PVE/API2/LXC.pm
+++ b/src/PVE/API2/LXC.pm
@@ -418,7 +418,7 @@ __PACKAGE__->register_method({
};
my $err = $@;
PVE::LXC::umount_all($vmid, $storage_cfg, $conf, $err ? 1 : 0);
- PVE::Storage::deactivate_volumes($storage_cfg, PVE::LXC::Config->get_vm_volumes($conf));
+ PVE::Storage::deactivate_volumes($storage_cfg, PVE::LXC::Config->get_vm_volumes($conf), undef, 1);
die $err if $err;
# set some defaults
$conf->{hostname} ||= "CT$vmid";
@@ -1447,7 +1447,7 @@ __PACKAGE__->register_method({
local $SIG{QUIT} =
local $SIG{HUP} = sub { die "interrupted by signal\n"; };
- PVE::Storage::activate_volumes($storecfg, $vollist, $snapname);
+ PVE::Storage::activate_volumes($storecfg, $vollist, $snapname, 1);
foreach my $opt (keys %$mountpoints) {
my $mp = $mountpoints->{$opt};
@@ -1460,7 +1460,7 @@ __PACKAGE__->register_method({
$newvolid = PVE::LXC::copy_volume($mp, $newid, $target_storage, $storecfg, $newconf, $snapname);
} else {
print "create linked clone of mount point $opt ($volid)\n";
- $newvolid = PVE::Storage::vdisk_clone($storecfg, $volid, $newid, $snapname);
+ $newvolid = PVE::Storage::vdisk_clone($storecfg, $volid, $newid, $snapname, 1);
}
push @$newvollist, $newvolid;
@@ -1474,8 +1474,8 @@ __PACKAGE__->register_method({
if ($target) {
# always deactivate volumes - avoid lvm LVs to be active on several nodes
- PVE::Storage::deactivate_volumes($storecfg, $vollist, $snapname) if !$running;
- PVE::Storage::deactivate_volumes($storecfg, $newvollist);
+ PVE::Storage::deactivate_volumes($storecfg, $vollist, $snapname, 1) if !$running;
+ PVE::Storage::deactivate_volumes($storecfg, $newvollist, undef, 1);
my $newconffile = PVE::LXC::Config->config_file($newid, $target);
die "Failed to move config to node '$target' - rename failed: $!\n"
@@ -1495,7 +1495,7 @@ __PACKAGE__->register_method({
sleep 1; # some storages like rbd need to wait before release volume - really?
foreach my $volid (@$newvollist) {
- eval { PVE::Storage::vdisk_free($storecfg, $volid); };
+ eval { PVE::Storage::vdisk_free($storecfg, $volid, 1); };
warn $@ if $@;
}
die "clone failed: $err";
@@ -1598,7 +1598,7 @@ __PACKAGE__->register_method({
$rpcenv->check($authuser, "/storage/$storeid", ['Datastore.AllocateSpace']);
- PVE::Storage::activate_volumes($storage_cfg, [$volid]);
+ PVE::Storage::activate_volumes($storage_cfg, [$volid], undef, 1);
my $size = PVE::Storage::volume_size_info($storage_cfg, $volid, 5);
$newsize += $size if $ext;
@@ -1611,8 +1611,8 @@ __PACKAGE__->register_method({
PVE::Cluster::log_msg('info', $authuser, "update CT $vmid: resize --disk $disk --size $sizestr");
my $realcmd = sub {
# Note: PVE::Storage::volume_resize doesn't do anything if $running=1, so
- # we pass 0 here (parameter only makes sense for qemu)
- PVE::Storage::volume_resize($storage_cfg, $volid, $newsize, 0);
+ # we pass 0 here (parameter only makes sense for qemu), $map=1 to request a mapped drive
+ PVE::Storage::volume_resize($storage_cfg, $volid, $newsize, 0, 1);
$mp->{size} = $newsize;
$conf->{$disk} = PVE::LXC::Config->print_ct_mountpoint($mp, $disk eq 'rootfs');
@@ -1620,7 +1620,7 @@ __PACKAGE__->register_method({
PVE::LXC::Config->write_config($vmid, $conf);
if ($format eq 'raw') {
- my $path = PVE::Storage::path($storage_cfg, $volid, undef);
+ my $path = PVE::Storage::path($storage_cfg, $volid, undef, 1);
if ($running) {
$mp->{mp} = '/';
@@ -1755,7 +1755,7 @@ __PACKAGE__->register_method({
my $new_volid;
eval {
- PVE::Storage::activate_volumes($storage_cfg, [ $old_volid ]);
+ PVE::Storage::activate_volumes($storage_cfg, [ $old_volid ], undef, 1);
$new_volid = PVE::LXC::copy_volume($mpdata, $vmid, $storage, $storage_cfg, $conf);
$mpdata->{volume} = $new_volid;
@@ -1773,13 +1773,13 @@ __PACKAGE__->register_method({
eval {
# try to deactivate volumes - avoid lvm LVs to be active on several nodes
- PVE::Storage::deactivate_volumes($storage_cfg, [ $new_volid ])
+ PVE::Storage::deactivate_volumes($storage_cfg, [ $new_volid ], undef, 1)
};
warn $@ if $@;
};
if (my $err = $@) {
eval {
- PVE::Storage::vdisk_free($storage_cfg, $new_volid)
+ PVE::Storage::vdisk_free($storage_cfg, $new_volid, 1)
if defined($new_volid);
};
warn $@ if $@;
@@ -1788,8 +1788,8 @@ __PACKAGE__->register_method({
if ($param->{delete}) {
eval {
- PVE::Storage::deactivate_volumes($storage_cfg, [ $old_volid ]);
- PVE::Storage::vdisk_free($storage_cfg, $old_volid);
+ PVE::Storage::deactivate_volumes($storage_cfg, [ $old_volid ], undef, 1);
+ PVE::Storage::vdisk_free($storage_cfg, $old_volid, 1);
};
warn $@ if $@;
}
diff --git a/src/PVE/CLI/pct.pm b/src/PVE/CLI/pct.pm
index 6296d6f..18b0f6b 100755
--- a/src/PVE/CLI/pct.pm
+++ b/src/PVE/CLI/pct.pm
@@ -241,7 +241,7 @@ __PACKAGE__->register_method ({
die "unable to run fsck for '$volid' (format == $format)\n"
if $format ne 'raw';
- $path = PVE::Storage::path($storage_cfg, $volid);
+ $path = PVE::Storage::path($storage_cfg, $volid, undef, 1);
} else {
if (($volid =~ m|^/.+|) && (-b $volid)) {
diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index 1504bd0..a03e8c4 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -624,7 +624,7 @@ sub delete_mountpoint_volume {
return if PVE::LXC::Config->classify_mountpoint($volume) ne 'volume';
my ($vtype, $name, $owner) = PVE::Storage::parse_volname($storage_cfg, $volume);
- PVE::Storage::vdisk_free($storage_cfg, $volume) if $vmid == $owner;
+ PVE::Storage::vdisk_free($storage_cfg, $volume, 1) if $vmid == $owner;
}
sub destroy_lxc_container {
@@ -655,7 +655,7 @@ sub vm_stop_cleanup {
if (!$keepActive) {
my $vollist = PVE::LXC::Config->get_vm_volumes($conf);
- PVE::Storage::deactivate_volumes($storage_cfg, $vollist);
+ PVE::Storage::deactivate_volumes($storage_cfg, $vollist, undef, 1);
}
};
warn $@ if $@; # avoid errors - just warn
@@ -964,7 +964,7 @@ sub template_create {
my $volid = $mountpoint->{volume};
- PVE::Storage::activate_volumes($storecfg, [$volid]);
+ PVE::Storage::activate_volumes($storecfg, [$volid], undef, 1);
my $template_volid = PVE::Storage::vdisk_create_base($storecfg, $volid);
$mountpoint->{volume} = $template_volid;
@@ -1049,7 +1049,7 @@ sub mount_all {
File::Path::make_path($rootdir);
my $volid_list = PVE::LXC::Config->get_vm_volumes($conf);
- PVE::Storage::activate_volumes($storage_cfg, $volid_list);
+ PVE::Storage::activate_volumes($storage_cfg, $volid_list, undef, 1);
eval {
PVE::LXC::Config->foreach_mountpoint($conf, sub {
@@ -1296,12 +1296,7 @@ sub mountpoint_mount {
my $scfg = PVE::Storage::storage_config($storage_cfg, $storage);
- # early sanity checks:
- # we otherwise call realpath on the rbd url
- die "containers on rbd storage without krbd are not supported\n"
- if $scfg->{type} eq 'rbd' && !$scfg->{krbd};
-
- my $path = PVE::Storage::path($storage_cfg, $volid, $snapname);
+ my $path = PVE::Storage::path($storage_cfg, $volid, $snapname, 1);
my ($vtype, undef, undef, undef, undef, $isBase, $format) =
PVE::Storage::parse_volname($storage_cfg, $volid);
@@ -1406,9 +1401,9 @@ sub format_disk {
die "cannot format volume '$volid' with no storage\n" if !$storage;
- PVE::Storage::activate_volumes($storage_cfg, [$volid]);
+ PVE::Storage::activate_volumes($storage_cfg, [$volid], undef, 1);
- my $path = PVE::Storage::path($storage_cfg, $volid);
+ my $path = PVE::Storage::path($storage_cfg, $volid, undef, 1);
my ($vtype, undef, undef, undef, undef, $isBase, $format) =
PVE::Storage::parse_volname($storage_cfg, $volid);
@@ -1423,7 +1418,7 @@ sub destroy_disks {
my ($storecfg, $vollist) = @_;
foreach my $volid (@$vollist) {
- eval { PVE::Storage::vdisk_free($storecfg, $volid); };
+ eval { PVE::Storage::vdisk_free($storecfg, $volid, 1); };
warn $@ if $@;
}
}
@@ -1442,27 +1437,26 @@ sub alloc_disk {
if ($scfg->{type} eq 'dir' || $scfg->{type} eq 'nfs' || $scfg->{type} eq 'cifs' ) {
if ($size_kb > 0) {
$volid = PVE::Storage::vdisk_alloc($storecfg, $storage, $vmid, 'raw',
- undef, $size_kb);
+ undef, $size_kb, 1);
$do_format = 1;
} else {
$volid = PVE::Storage::vdisk_alloc($storecfg, $storage, $vmid, 'subvol',
- undef, 0);
+ undef, 0, 1);
$needs_chown = 1;
}
} elsif ($scfg->{type} eq 'zfspool') {
$volid = PVE::Storage::vdisk_alloc($storecfg, $storage, $vmid, 'subvol',
- undef, $size_kb);
+ undef, $size_kb, 1);
$needs_chown = 1;
} elsif ($scfg->{type} eq 'drbd' || $scfg->{type} eq 'lvm' || $scfg->{type} eq 'lvmthin') {
- $volid = PVE::Storage::vdisk_alloc($storecfg, $storage, $vmid, 'raw', undef, $size_kb);
+ $volid = PVE::Storage::vdisk_alloc($storecfg, $storage, $vmid, 'raw', undef, $size_kb, 1);
$do_format = 1;
} elsif ($scfg->{type} eq 'rbd') {
- die "krbd option must be enabled on storage type '$scfg->{type}'\n" if !$scfg->{krbd};
- $volid = PVE::Storage::vdisk_alloc($storecfg, $storage, $vmid, 'raw', undef, $size_kb);
+ $volid = PVE::Storage::vdisk_alloc($storecfg, $storage, $vmid, 'raw', undef, $size_kb, 1);
$do_format = 1;
} else {
die "unable to create containers on storage type '$scfg->{type}'\n";
@@ -1472,7 +1466,7 @@ sub alloc_disk {
if (my $err = $@) {
# in case formatting got interrupted:
if (defined($volid)) {
- eval { PVE::Storage::vdisk_free($storecfg, $volid); };
+ eval { PVE::Storage::vdisk_free($storecfg, $volid, 1); };
warn $@ if $@;
}
die $err;
@@ -1517,12 +1511,12 @@ sub create_disks {
}
});
- PVE::Storage::activate_volumes($storecfg, $chown_vollist, undef);
+ PVE::Storage::activate_volumes($storecfg, $chown_vollist, undef, 1);
foreach my $volid (@$chown_vollist) {
- my $path = PVE::Storage::path($storecfg, $volid, undef);
+ my $path = PVE::Storage::path($storecfg, $volid, undef, 1);
chown($rootuid, $rootgid, $path);
}
- PVE::Storage::deactivate_volumes($storecfg, $chown_vollist, undef);
+ PVE::Storage::deactivate_volumes($storecfg, $chown_vollist, undef, 1);
};
# free allocated images on error
if (my $err = $@) {
@@ -1775,8 +1769,8 @@ sub copy_volume {
my $needs_chown;
($new_volid, $needs_chown) = alloc_disk($storage_cfg, $vmid, $storage, $mp->{size}/1024, $rootuid, $rootgid);
if ($needs_chown) {
- PVE::Storage::activate_volumes($storage_cfg, [$new_volid], undef);
- my $path = PVE::Storage::path($storage_cfg, $new_volid, undef);
+ PVE::Storage::activate_volumes($storage_cfg, [$new_volid], undef, 1);
+ my $path = PVE::Storage::path($storage_cfg, $new_volid, undef, 1);
chown($rootuid, $rootgid, $path);
}
@@ -1785,7 +1779,7 @@ sub copy_volume {
});
};
if (my $err = $@) {
- PVE::Storage::vdisk_free($storage_cfg, $new_volid)
+ PVE::Storage::vdisk_free($storage_cfg, $new_volid, 1)
if defined($new_volid);
die $err;
}
diff --git a/src/PVE/LXC/Config.pm b/src/PVE/LXC/Config.pm
index f90ac3b..48c495a 100644
--- a/src/PVE/LXC/Config.pm
+++ b/src/PVE/LXC/Config.pm
@@ -143,7 +143,7 @@ sub __snapshot_delete_vol_snapshot {
!$class->mountpoint_backup_enabled($ms, $mountpoint);
my $storecfg = PVE::Storage::config();
- PVE::Storage::volume_snapshot_delete($storecfg, $mountpoint->{volume}, $snapname);
+ PVE::Storage::volume_snapshot_delete($storecfg, $mountpoint->{volume}, $snapname, 1, 1);
push @$unused, $mountpoint->{volume};
}
@@ -1338,7 +1338,7 @@ sub get_replicatable_volumes {
my $scfg = PVE::Storage::storage_config($storecfg, $storeid);
return if $scfg->{shared};
- my ($path, $owner, $vtype) = PVE::Storage::path($storecfg, $volid);
+ my ($path, $owner, $vtype) = PVE::Storage::path($storecfg, $volid, 1);
return if !$owner || ($owner != $vmid);
die "unable to replicate volume '$volid', type '$vtype'\n" if $vtype ne 'images';
diff --git a/src/PVE/LXC/Migrate.pm b/src/PVE/LXC/Migrate.pm
index 1364b8d..c46e571 100644
--- a/src/PVE/LXC/Migrate.pm
+++ b/src/PVE/LXC/Migrate.pm
@@ -90,7 +90,7 @@ sub prepare {
});
- PVE::Storage::activate_volumes($self->{storecfg}, $need_activate);
+ PVE::Storage::activate_volumes($self->{storecfg}, $need_activate, undef, 1);
# todo: test if VM uses local resources
@@ -158,7 +158,7 @@ sub phase1 {
$volhash->{$volid}->{ref} = defined($snapname) ? 'snapshot' : 'config';
$volhash->{$volid}->{snapshots} = defined($snapname);
- my ($path, $owner) = PVE::Storage::path($self->{storecfg}, $volid);
+ my ($path, $owner) = PVE::Storage::path($self->{storecfg}, $volid, undef, 1);
die "owned by other guest (owner = $owner)\n"
if !$owner || ($owner != $self->{vmid});
@@ -283,7 +283,7 @@ sub phase1 {
my ($sid, $volname) = PVE::Storage::parse_volume_id($volid);
push @{$self->{volumes}}, $volid;
my $with_snapshots = $volhash->{$volid}->{snapshots};
- PVE::Storage::storage_migrate($self->{storecfg}, $volid, $self->{ssh_info}, $sid, undef, undef, undef, undef, $insecure, $with_snapshots);
+ PVE::Storage::storage_migrate($self->{storecfg}, $volid, $self->{ssh_info}, $sid, undef, undef, undef, undef, $insecure, $with_snapshots, undef, 1);
}
my $conffile = PVE::LXC::Config->config_file($vmid);
@@ -301,7 +301,7 @@ sub phase1 {
#to be sure there are no active volumes
my $vollist = PVE::LXC::Config->get_vm_volumes($conf);
- PVE::Storage::deactivate_volumes($self->{storecfg}, $vollist);
+ PVE::Storage::deactivate_volumes($self->{storecfg}, $vollist, undef, 1);
# transfer replication state before move config
$self->transfer_replication_state() if $rep_volumes;
@@ -335,7 +335,7 @@ sub phase3 {
# destroy local copies
foreach my $volid (@$volids) {
- eval { PVE::Storage::vdisk_free($self->{storecfg}, $volid); };
+ eval { PVE::Storage::vdisk_free($self->{storecfg}, $volid, 1); };
if (my $err = $@) {
$self->log('err', "removing local copy of '$volid' failed - $err");
$self->{errors} = 1;
diff --git a/src/PVE/VZDump/LXC.pm b/src/PVE/VZDump/LXC.pm
index ae793dc..ec27188 100644
--- a/src/PVE/VZDump/LXC.pm
+++ b/src/PVE/VZDump/LXC.pm
@@ -160,7 +160,7 @@ sub prepare {
my $rootdir = $default_mount_point;
mkpath $rootdir;
&$check_mountpoint_empty($rootdir);
- PVE::Storage::activate_volumes($storage_cfg, $volids);
+ PVE::Storage::activate_volumes($storage_cfg, $volids, undef, 1);
} elsif ($mode eq 'suspend') {
my $pid = PVE::LXC::find_lxc_pid($vmid);
foreach my $disk (@$disks) {
@@ -216,7 +216,7 @@ sub snapshot {
my $rootdir = $default_mount_point;
my $storage_cfg = $self->{storecfg};
- PVE::Storage::activate_volumes($storage_cfg, $volids, 'vzdump');
+ PVE::Storage::activate_volumes($storage_cfg, $volids, 'vzdump', 1);
foreach my $disk (@$disks) {
$disk->{dir} = "${rootdir}$disk->{mp}";
PVE::LXC::mountpoint_mount($disk, $rootdir, $storage_cfg, 'vzdump');
--
2.11.0
More information about the pve-devel
mailing list