[pve-devel] [PATCH] add rbd storage type support

Alexandre Derumier aderumier at odiso.com
Wed Aug 12 11:08:02 CEST 2015


Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 src/PVE/API2/LXC.pm  | 7 ++++++-
 src/PVE/LXC.pm       | 2 +-
 src/PVE/LXCCreate.pm | 5 ++++-
 3 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm
index 4819295..7a65402 100644
--- a/src/PVE/API2/LXC.pm
+++ b/src/PVE/API2/LXC.pm
@@ -72,7 +72,12 @@ my $alloc_rootfs = sub {
 	} elsif ($scfg->{type} eq 'drbd') {
 
 	    $volid = PVE::Storage::vdisk_alloc($storage_conf, $storage, $vmid, 'raw', undef, $size);
-	    
+
+	} 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($storage_conf, $storage, $vmid, 'raw', undef, $size);
+
 	} else {
 	    die "unable to create containers on storage type '$scfg->{type}'\n";
 	}
diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index dadaaf7..a1a5197 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -943,7 +943,7 @@ sub update_lxc_config {
     } elsif ($scfg->{type} eq 'zfspool') {
 	my $rootfs = PVE::Storage::path($storage_cfg, $volid);
 	$raw .= "lxc.rootfs = $rootfs\n";
-    } elsif ($scfg->{type} eq 'drbd') {
+    } elsif ($scfg->{type} eq 'drbd' || $scfg->{type} eq 'rbd') {
 	my $rootdev = PVE::Storage::path($storage_cfg, $volid);
 	$raw .= "lxc.rootfs = $rootdev\n";
     } else {
diff --git a/src/PVE/LXCCreate.pm b/src/PVE/LXCCreate.pm
index 8847edc..4e742c0 100644
--- a/src/PVE/LXCCreate.pm
+++ b/src/PVE/LXCCreate.pm
@@ -289,13 +289,16 @@ sub create_rootfs {
 	create_rootfs_subvol($storage_cfg, $storage, $volid, $vmid, $conf, $archive, $password, $restore);
     } elsif ($format eq 'raw') {
 	my $scfg = PVE::Storage::storage_config($storage_cfg, $storage);
+	PVE::Storage::activate_storage($storage_cfg, $storage);
+	PVE::Storage::activate_volumes($storage_cfg, [$volid]);
 	if ($scfg->{path}) {
 	    create_rootfs_dir_loop($storage_cfg, $storage, $volid, $vmid, $conf, $archive, $password, $restore);
-	} elsif ($scfg->{type} eq 'drbd') {
+	} elsif ($scfg->{type} eq 'drbd' || $scfg->{type} eq 'rbd') {
 	    create_rootfs_dev($storage_cfg, $storage, $volid, $vmid, $conf, $archive, $password, $restore);
 	} else {
 	    die "unable to create containers on storage type '$scfg->{type}'\n";
 	}
+	PVE::Storage::deactivate_volumes($storage_cfg, [$volid]);
     } else {
 	die "unsupported image format '$format'\n";
     }
-- 
2.1.4




More information about the pve-devel mailing list