[pve-devel] [PATCH v2 storage 5/6] api: add import/export format querying

Wolfgang Bumiller w.bumiller at proxmox.com
Thu May 11 10:24:12 CEST 2017


---
The parameters are pretty much the same as for the actual import/export
implementation functions since the format type may depend on what kind
of transfer is required (incremental, using snapshots, subvolume vs
image...)

 PVE/Storage.pm               | 41 +++++++++++++++++++++++++++++++++++++++++
 PVE/Storage/Plugin.pm        | 10 ++++++++++
 PVE/Storage/ZFSPoolPlugin.pm | 16 ++++++++++++++++
 3 files changed, 67 insertions(+)

diff --git a/PVE/Storage.pm b/PVE/Storage.pm
index 41a9cb5..4c8b9d1 100755
--- a/PVE/Storage.pm
+++ b/PVE/Storage.pm
@@ -1504,6 +1504,47 @@ sub volume_import {
     }
 }
 
+sub volume_export_formats {
+    my ($cfg, $volid, $snapshot, $base_snapshot, $with_snapshots) = @_;
+
+    my ($storeid, $volname) = parse_volume_id($volid, 1);
+    if ($storeid) {
+	my $scfg = storage_config($cfg, $storeid);
+	my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
+	return $plugin->volume_export_formats($scfg, $storeid, $volname,
+	                                      $base_snapshot, $with_snapshots);
+    } elsif ($volid =~ m|^(/.+)$| && -e $volid) {
+	return; # TODO raw files
+    } else {
+	return;
+    }
+}
+
+sub volume_import_formats {
+    my ($cfg, $volid, $base_snapshot, $with_snapshots) = @_;
+
+    my ($storeid, $volname) = parse_volume_id($volid, 1);
+    if ($storeid) {
+	my $scfg = storage_config($cfg, $storeid);
+	my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
+	return $plugin->volume_import_formats($scfg, $storeid, $volname,
+	                                      $base_snapshot, $with_snapshots);
+    } elsif ($volid =~ m|^(/.+)$| && -e $volid) {
+	return; # TODO raw files
+    } else {
+	return;
+    }
+}
+
+sub volume_transfer_formats {
+    my ($cfg, $volid, $snapshot, $base_snapshot, $with_snapshots) = @_;
+    my @export_formats = volume_export_formats($cfg, $volid, $snapshot, $base_snapshot, $with_snapshots);
+    my @import_formats = volume_import_formats($cfg, $volid, $base_snapshot, $with_snapshots);
+    my %import_hash = map { $_ => 1 } @import_formats;
+    my @common = grep { $import_hash{$_} } @export_formats;
+    return @common;
+}
+
 # bash completion helper
 
 sub complete_storage {
diff --git a/PVE/Storage/Plugin.pm b/PVE/Storage/Plugin.pm
index b7ec261..4df6608 100644
--- a/PVE/Storage/Plugin.pm
+++ b/PVE/Storage/Plugin.pm
@@ -894,10 +894,20 @@ sub volume_export {
     die "volume export not implemented for $class";
 }
 
+sub volume_export_formats {
+    my ($class, $scfg, $storeid, $volname, $snapshot, $base_snapshot, $with_snapshots) = @_;
+    die "volume export formats not implemented for $class";
+}
+
 # Import data from a stream, creating a new or replacing or adding to an existing volume.
 sub volume_import {
     my ($class, $scfg, $storeid, $fh, $volname, $format, $base_snapshot, $with_snapshots) = @_;
     die "volume import not implemented for $class";
 }
 
+sub volume_import_formats {
+    my ($class, $scfg, $storeid, $volname, $base_snapshot, $with_snapshots) = @_;
+    die "volume import formats not implemented for $class";
+}
+
 1;
diff --git a/PVE/Storage/ZFSPoolPlugin.pm b/PVE/Storage/ZFSPoolPlugin.pm
index ceeb065..ca350a9 100644
--- a/PVE/Storage/ZFSPoolPlugin.pm
+++ b/PVE/Storage/ZFSPoolPlugin.pm
@@ -676,6 +676,16 @@ sub volume_export {
     return;
 }
 
+sub volume_export_formats {
+    my ($class, $scfg, $storeid, $volname, $snapshot, $base_snapshot, $with_snapshots) = @_;
+
+    my @formats = ('zfs');
+    # TODOs:
+    # push @formats, 'fies' if $volname !~ /^(?:basevol|subvol)-/;
+    # push @formats, 'raw' if !$base_snapshot && !$with_snapshots;
+    return @formats;
+}
+
 sub volume_import {
     my ($class, $scfg, $storeid, $fh, $volname, $format, $base_snapshot, $with_snapshots) = @_;
 
@@ -701,4 +711,10 @@ sub volume_import {
     return;
 }
 
+sub volume_import_formats {
+    my ($class, $scfg, $storeid, $volname, $base_snapshot, $with_snapshots) = @_;
+
+    return $class->volume_export_formats($scfg, $storeid, $volname, undef, $base_snapshot, $with_snapshots);
+}
+
 1;
-- 
2.11.0





More information about the pve-devel mailing list