[pve-devel] [PATCH pve-container v2] Make volume create and mount code independent of storage plugin types
Dmitry Petuhov
mityapetuhov at gmail.com
Mon Sep 19 12:57:17 CEST 2016
Instead, rely on plugin-defined supported formats to decide if it
supports subvols.
Signed-off-by: Dmitry Petuhov <mityapetuhov at gmail.com>
---
Still workaround 'rbd' plugin, that cannot be used for LXC without
krbd. Maybe better way is to pass $scfg into plugin's plugindata()
in storage code? So plugin could show instance's capabilities
instead of whole plugin's capabilities, that may or may not be available
in instance.
Also workaround special-case 'rbdpool' storage, where we allways want to
use subvols with LXC. Maybe signal that plugin wants such behaviour via
plugindata() too? Like set default format to subvol instead of raw in
zfspool?
src/PVE/LXC.pm | 45 +++++++++++++++------------------------------
1 file changed, 15 insertions(+), 30 deletions(-)
diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index 35ce796..70d3b50 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -1238,12 +1238,9 @@ sub mountpoint_mount {
if ($scfg->{path}) {
$mounted_dev = run_with_loopdev($domount, $path);
$use_loopdev = 1;
- } elsif ($scfg->{type} eq 'drbd' || $scfg->{type} eq 'lvm' ||
- $scfg->{type} eq 'rbd' || $scfg->{type} eq 'lvmthin') {
+ } else {
$mounted_dev = $path;
&$domount($path);
- } else {
- die "unsupported storage type '$scfg->{type}'\n";
}
return wantarray ? ($path, $use_loopdev, $mounted_dev) : $path;
} else {
@@ -1331,43 +1328,31 @@ sub create_disks {
my $size_kb = int(${size_gb}*1024) * 1024;
my $scfg = PVE::Storage::storage_config($storecfg, $storage);
+ die "krbd option must be enabled on storage type 'rbd'\n" if ($scfg->{type} eq 'rbd') && !$scfg->{krbd};
# fixme: use better naming ct-$vmid-disk-X.raw?
- if ($scfg->{type} eq 'dir' || $scfg->{type} eq 'nfs') {
- if ($size_kb > 0) {
- $volid = PVE::Storage::vdisk_alloc($storecfg, $storage, $vmid, 'raw',
- undef, $size_kb);
- format_disk($storecfg, $volid, $rootuid, $rootgid);
- } else {
+ if ($size_kb > 0 && $scfg->{type} ne 'zfspool') {
+ $volid = PVE::Storage::vdisk_alloc($storecfg, $storage, $vmid, 'raw',
+ undef, $size_kb);
+ format_disk($storecfg, $volid, $rootuid, $rootgid);
+ } else {
+ my (undef, $valid_formats) = PVE::Storage::storage_default_format($storecfg, $storage);
+ if (grep { $_ eq 'subvol' } @$valid_formats) {
$volid = PVE::Storage::vdisk_alloc($storecfg, $storage, $vmid, 'subvol',
- undef, 0);
+ undef, $size_kb);
push @$chown_vollist, $volid;
+ } else {
+ die "Selected storage does not support subvols. Please, specify image size or select another storage";
}
- } elsif ($scfg->{type} eq 'zfspool') {
-
- $volid = PVE::Storage::vdisk_alloc($storecfg, $storage, $vmid, 'subvol',
- undef, $size_kb);
- push @$chown_vollist, $volid;
- } 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);
- format_disk($storecfg, $volid, $rootuid, $rootgid);
-
- } 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);
- format_disk($storecfg, $volid, $rootuid, $rootgid);
- } else {
- die "unable to create containers on storage type '$scfg->{type}'\n";
}
+
push @$vollist, $volid;
$mountpoint->{volume} = $volid;
$mountpoint->{size} = $size_kb * 1024;
$conf->{$ms} = PVE::LXC::Config->print_ct_mountpoint($mountpoint, $ms eq 'rootfs');
} else {
- # use specified/existing volid/dir/device
- $conf->{$ms} = PVE::LXC::Config->print_ct_mountpoint($mountpoint, $ms eq 'rootfs');
+ # use specified/existing volid/dir/device
+ $conf->{$ms} = PVE::LXC::Config->print_ct_mountpoint($mountpoint, $ms eq 'rootfs');
}
});
--
2.1.4
More information about the pve-devel
mailing list