From 5bb8e01076dee7034225761f9bc1724ee49b7ce3 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Thu, 22 Jan 2015 07:54:10 +0100 Subject: [PATCH] ZFSDirPlugin: new plugin for local zfs storage We also want to use this as base class for ZFSPlugin, to increase code sharing. --- PVE/Storage.pm | 2 ++ PVE/Storage/Makefile | 2 +- PVE/Storage/ZFSDirPlugin.pm | 63 +++++++++++++++++++++++++++++++++++++ PVE/Storage/ZFSPlugin.pm | 31 ++---------------- 4 files changed, 68 insertions(+), 30 deletions(-) create mode 100644 PVE/Storage/ZFSDirPlugin.pm diff --git a/PVE/Storage.pm b/PVE/Storage.pm index 3cc9581..380fbdf 100755 --- a/PVE/Storage.pm +++ b/PVE/Storage.pm @@ -27,6 +27,7 @@ use PVE::Storage::RBDPlugin; use PVE::Storage::SheepdogPlugin; use PVE::Storage::ISCSIDirectPlugin; use PVE::Storage::GlusterfsPlugin; +use PVE::Storage::ZFSDirPlugin; use PVE::Storage::ZFSPlugin; # load and initialize all plugins @@ -38,6 +39,7 @@ PVE::Storage::RBDPlugin->register(); PVE::Storage::SheepdogPlugin->register(); PVE::Storage::ISCSIDirectPlugin->register(); PVE::Storage::GlusterfsPlugin->register(); +PVE::Storage::ZFSDirPlugin->register(); PVE::Storage::ZFSPlugin->register(); PVE::Storage::Plugin->init(); diff --git a/PVE/Storage/Makefile b/PVE/Storage/Makefile index 919c486..c993ea4 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 ZFSPlugin.pm +SOURCES=Plugin.pm DirPlugin.pm LVMPlugin.pm NFSPlugin.pm ISCSIPlugin.pm RBDPlugin.pm SheepdogPlugin.pm ISCSIDirectPlugin.pm GlusterfsPlugin.pm ZFSDirPlugin.pm ZFSPlugin.pm .PHONY: install install: diff --git a/PVE/Storage/ZFSDirPlugin.pm b/PVE/Storage/ZFSDirPlugin.pm new file mode 100644 index 0000000..91a3ef6 --- /dev/null +++ b/PVE/Storage/ZFSDirPlugin.pm @@ -0,0 +1,63 @@ +package PVE::Storage::ZFSDirPlugin; + +use strict; +use warnings; +use IO::File; +use POSIX; +use PVE::Tools qw(run_command); +use PVE::Storage::Plugin; + + +use base qw(PVE::Storage::Plugin); + +sub zfs_parse_size { + my ($text) = @_; + + return 0 if !$text; + + if ($text =~ m/^(\d+(\.\d+)?)([TGMK])?$/) { + my ($size, $reminder, $unit) = ($1, $2, $3); + return $size if !$unit; + if ($unit eq 'K') { + $size *= 1024; + } elsif ($unit eq 'M') { + $size *= 1024*1024; + } elsif ($unit eq 'G') { + $size *= 1024*1024*1024; + } elsif ($unit eq 'T') { + $size *= 1024*1024*1024*1024; + } + + if ($reminder) { + $size = ceil($size); + } + return $size; + } else { + return 0; + } +} + +sub type { + return 'zfsdir'; +} + +sub plugindata { + return { + content => [ { images => 1, rootdir => 1, vztmpl => 1, iso => 1, backup => 1}, + { images => 1 }], + }; +} + +sub options { + return { + path => { fixed => 1 }, + nodes => { optional => 1 }, + disable => { optional => 1 }, + maxfiles => { optional => 1 }, + content => { optional => 1 }, + }; +} + +# fixme: implement me + +1; diff --git a/PVE/Storage/ZFSPlugin.pm b/PVE/Storage/ZFSPlugin.pm index 44a8ccb..a7305dc 100644 --- a/PVE/Storage/ZFSPlugin.pm +++ b/PVE/Storage/ZFSPlugin.pm @@ -5,9 +5,9 @@ use warnings; use IO::File; use POSIX; use PVE::Tools qw(run_command); -use PVE::Storage::Plugin; +use PVE::Storage::ZFSDirPlugin; -use base qw(PVE::Storage::Plugin); +use base qw(PVE::Storage::ZFSDirPlugin); use PVE::Storage::LunCmd::Comstar; use PVE::Storage::LunCmd::Istgt; use PVE::Storage::LunCmd::Iet; @@ -91,33 +91,6 @@ sub zfs_request { return $msg; } -sub zfs_parse_size { - my ($text) = @_; - - return 0 if !$text; - - if ($text =~ m/^(\d+(\.\d+)?)([TGMK])?$/) { - my ($size, $reminder, $unit) = ($1, $2, $3); - return $size if !$unit; - if ($unit eq 'K') { - $size *= 1024; - } elsif ($unit eq 'M') { - $size *= 1024*1024; - } elsif ($unit eq 'G') { - $size *= 1024*1024*1024; - } elsif ($unit eq 'T') { - $size *= 1024*1024*1024*1024; - } - - if ($reminder) { - $size = ceil($size); - } - return $size; - } else { - return 0; - } -} - sub zfs_get_pool_stats { my ($scfg) = @_;