[pve-devel] [PATCH pve-container] Make volume create and mount code independent of storage plugin types

Dmitry Petuhov mityapetuhov at gmail.com
Sun Sep 11 08:07:36 CEST 2016


Instead, rely on plugin-defined supported formats to decide if it
supports subvols.

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.

Signed-off-by: Dmitry Petuhov <mityapetuhov at gmail.com>
---
 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..70d13e4 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -1238,12 +1238,8 @@ 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') {
-		$mounted_dev = $path;
-		&$domount($path);
 	    } else {
-		die "unsupported storage type '$scfg->{type}'\n";
+		&$domount($path);
 	    }
 	    return wantarray ? ($path, $use_loopdev, $mounted_dev) : $path;
 	} else {
@@ -1330,37 +1326,26 @@ sub create_disks {
 
 		my $size_kb = int(${size_gb}*1024) * 1024;
 
-		my $scfg = PVE::Storage::storage_config($storecfg, $storage);
 		# 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) {
+		    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};
+
+		    $volid = PVE::Storage::vdisk_alloc($storecfg, $storage, $vmid, 'raw',
+						       undef, $size_kb);
+                    format_disk($storecfg, $volid, $rootuid, $rootgid);
+                } else {
+                    my ($defFormat, $validFormats) = PVE::Storage::storage_default_format($storecfg, $storage);
+	            if (grep { $_ eq 'subvol' } @$validFormats) {
 			$volid = PVE::Storage::vdisk_alloc($storecfg, $storage, $vmid, 'subvol',
 							   undef, 0);
 			push @$chown_vollist, $volid;
-		    }
-		} elsif ($scfg->{type} eq 'zfspool') {
+                    } else {
+                        die "Selected storage does not support subvols. Please, specify image size or select another storage";
+                    }
+                }
 
-		    $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;
-- 
2.1.4



More information about the pve-devel mailing list