From 14770890e285fbc0c4ac469736a787b7e58dc215 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Fri, 20 Mar 2015 17:44:15 +0100 Subject: [PATCH] add dummy for DRBD9 --- PVE/Storage.pm | 2 + PVE/Storage/DRBDPlugin.pm | 229 ++++++++++++++++++++++++++++++++++++++ PVE/Storage/Makefile | 2 +- 3 files changed, 232 insertions(+), 1 deletion(-) create mode 100644 PVE/Storage/DRBDPlugin.pm diff --git a/PVE/Storage.pm b/PVE/Storage.pm index e46bc77..b97279c 100755 --- a/PVE/Storage.pm +++ b/PVE/Storage.pm @@ -29,6 +29,7 @@ use PVE::Storage::ISCSIDirectPlugin; use PVE::Storage::GlusterfsPlugin; use PVE::Storage::ZFSPoolPlugin; use PVE::Storage::ZFSPlugin; +use PVE::Storage::DRBDPlugin; # load and initialize all plugins PVE::Storage::DirPlugin->register(); @@ -41,6 +42,7 @@ PVE::Storage::ISCSIDirectPlugin->register(); PVE::Storage::GlusterfsPlugin->register(); PVE::Storage::ZFSPoolPlugin->register(); PVE::Storage::ZFSPlugin->register(); +PVE::Storage::DRBDPlugin->register(); PVE::Storage::Plugin->init(); my $UDEVADM = '/sbin/udevadm'; diff --git a/PVE/Storage/DRBDPlugin.pm b/PVE/Storage/DRBDPlugin.pm new file mode 100644 index 0000000..41540c5 --- /dev/null +++ b/PVE/Storage/DRBDPlugin.pm @@ -0,0 +1,229 @@ +package PVE::Storage::DRBDPlugin; + +use strict; +use warnings; +use IO::File; +use PVE::Tools qw(run_command trim); +use PVE::Storage::Plugin; +use PVE::JSONSchema qw(get_standard_option); + +use base qw(PVE::Storage::Plugin); + +# Configuration + +sub type { + return 'drbd'; +} + +sub plugindata { + return { + content => [ {images => 1}, { images => 1 }], + }; +} + +sub properties { + return { + redundancy => { + description => "The redundancy count specifies the number of nodes to which the resource should be deployed. It must be at least 1 and at most the number of nodes in the cluster.", + type => 'integer', + minimum => 1, + maximum => 16, + default => 2, + }, + }; +} + +sub options { + return { + redundancy => { optional => 1 }, + nodes => { optional => 1 }, + disable => { optional => 1 }, + }; +} + +# Storage implementation + +sub parse_volname { + my ($class, $volname) = @_; + + if ($volname =~ m/^(vm-(\d+)-[a-z][a-z0-9\-\_\.]*[a-z0-9]+)$/) { + return ('images', $1, $2); + } + + die "unable to parse lvm volume name '$volname'\n"; +} + +sub filesystem_path { + my ($class, $scfg, $volname) = @_; + + my ($vtype, $name, $vmid) = $class->parse_volname($volname); + + die "fixme"; + + my $vg = $scfg->{vgname}; + + my $path = "/dev/$vg/$name"; + + return wantarray ? ($path, $vmid, $vtype) : $path; +} + +sub create_base { + my ($class, $storeid, $scfg, $volname) = @_; + + die "can't create base images in drbd storage\n"; +} + +sub clone_image { + my ($class, $scfg, $storeid, $volname, $vmid, $snap) = @_; + + die "can't clone images in drbd storage\n"; +} + +sub alloc_image { + my ($class, $storeid, $scfg, $vmid, $fmt, $name, $size) = @_; + + die "unsupported format '$fmt'" if $fmt ne 'raw'; + + die "illegal name '$name' - sould be 'vm-$vmid-*'\n" + if $name && $name !~ m/^vm-$vmid-/; + + + if (!$name) { + die "fixme"; + + my $lvs = {}; + + for (my $i = 1; $i < 100; $i++) { + my $tn = "vm-$vmid-disk-$i"; + if (!defined ($lvs->{fixme})) { + $name = $tn; + last; + } + } + } + + die "unable to allocate an image name for VM $vmid in storage '$storeid'\n" + if !$name; + + my $cmd = ['drbdmanage', 'new-volume', $name]; + + # fixme: deploy + + run_command($cmd, errmsg => "drbdmanage new-volume error"); + + return $name; +} + +sub free_image { + my ($class, $storeid, $scfg, $volname, $isBase) = @_; + + my $cmd = ['drbdmanage', 'remove-volume', $volname]; + + # fixme: undeploy + + run_command($cmd, errmsg => "drbdmanage remove-volume error"); + + return undef; +} + +sub list_images { + my ($class, $storeid, $scfg, $vmid, $vollist, $cache) = @_; + + my $vgname = $scfg->{vgname}; + + #$cache->{lvs} = lvm_lvs() if !$cache->{lvs}; + + my $res = []; + + die "fixme"; + + return $res; +} + +sub status { + my ($class, $storeid, $scfg, $cache) = @_; + + die "fixme"; + + return undef; +} + +sub activate_storage { + my ($class, $storeid, $scfg, $cache) = @_; + + return undef; +} + +sub deactivate_storage { + my ($class, $storeid, $scfg, $cache) = @_; + + return undef; +} + +sub activate_volume { + my ($class, $storeid, $scfg, $volname, $exclusive, $cache) = @_; + + return undef; +} + +sub deactivate_volume { + my ($class, $storeid, $scfg, $volname, $cache) = @_; + + return undef; +} + +sub volume_resize { + my ($class, $scfg, $storeid, $volname, $size, $running) = @_; + + $size = ($size/1024/1024) . "M"; + + my $path = $class->path($scfg, $volname); + + die "fixme"; + + #my $cmd = ['/sbin/lvextend', '-L', $size, $path]; + #run_command($cmd, errmsg => "error resizing volume '$path'"); + + return 1; +} + +sub volume_snapshot { + my ($class, $scfg, $storeid, $volname, $snap, $running) = @_; + + die "drbd snapshot is not implemented"; +} + +sub volume_snapshot_rollback { + my ($class, $scfg, $storeid, $volname, $snap) = @_; + + die "drbd snapshot rollback is not implemented"; +} + +sub volume_snapshot_delete { + my ($class, $scfg, $storeid, $volname, $snap) = @_; + + die "drbd snapshot delete is not implemented"; +} + +sub volume_has_feature { + my ($class, $scfg, $feature, $storeid, $volname, $snapname, $running) = @_; + + my $features = { + copy => { base => 1, current => 1}, + }; + + my ($vtype, $name, $vmid, $basename, $basevmid, $isBase) = + $class->parse_volname($volname); + + my $key = undef; + if($snapname){ + $key = 'snap'; + }else{ + $key = $isBase ? 'base' : 'current'; + } + return 1 if $features->{$feature}->{$key}; + + return undef; +} + +1; diff --git a/PVE/Storage/Makefile b/PVE/Storage/Makefile index f28d5d5..11de4d3 100644 --- a/PVE/Storage/Makefile +++ b/PVE/Storage/Makefile @@ -1,4 +1,4 @@ -SOURCES=Plugin.pm DirPlugin.pm LVMPlugin.pm NFSPlugin.pm ISCSIPlugin.pm RBDPlugin.pm SheepdogPlugin.pm ISCSIDirectPlugin.pm GlusterfsPlugin.pm ZFSPoolPlugin.pm ZFSPlugin.pm +SOURCES=Plugin.pm DirPlugin.pm LVMPlugin.pm NFSPlugin.pm ISCSIPlugin.pm RBDPlugin.pm SheepdogPlugin.pm ISCSIDirectPlugin.pm GlusterfsPlugin.pm ZFSPoolPlugin.pm ZFSPlugin.pm DRBDPlugin.pm .PHONY: install install: -- 2.39.2