[pve-devel] [PATCH v2 storage 14/28] pvesm import: return and print the allocated volume ID
Fabian Ebner
f.ebner at proxmox.com
Mon Feb 24 13:44:04 CET 2020
In preparation to the introduction of a parameter which allows
pvesm to pick a different name on collision.
In Storage.pm's volume_import, when a plugin returns 'undef',
it can be assumed that the import with the requested volid was
successful (it should've died otherwise) and so volid is returned.
This is done for backwards compatibility with foreign plugins.
Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---
PVE/CLI/pvesm.pm | 13 ++++++++-----
PVE/Storage.pm | 2 +-
PVE/Storage/LVMPlugin.pm | 2 ++
PVE/Storage/Plugin.pm | 2 ++
PVE/Storage/ZFSPoolPlugin.pm | 2 +-
5 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/PVE/CLI/pvesm.pm b/PVE/CLI/pvesm.pm
index 510faba..7b83ec8 100755
--- a/PVE/CLI/pvesm.pm
+++ b/PVE/CLI/pvesm.pm
@@ -299,7 +299,7 @@ __PACKAGE__->register_method ({
},
},
},
- returns => { type => 'null' },
+ returns => { type => 'string' },
code => sub {
my ($param) = @_;
@@ -352,11 +352,11 @@ __PACKAGE__->register_method ({
my $cfg = PVE::Storage::config();
my $volume = $param->{volume};
my $delete = $param->{'delete-snapshot'};
- PVE::Storage::volume_import($cfg, $infh, $volume, $param->{format},
+ my $imported_volid = PVE::Storage::volume_import($cfg, $infh, $volume, $param->{format},
$param->{base}, $param->{'with-snapshots'});
- PVE::Storage::volume_snapshot_delete($cfg, $volume, $delete)
+ PVE::Storage::volume_snapshot_delete($cfg, $imported_volid, $delete)
if defined($delete);
- return;
+ return $imported_volid;
}
});
@@ -777,7 +777,10 @@ our $cmddef = {
path => [ __PACKAGE__, 'path', ['volume']],
extractconfig => [__PACKAGE__, 'extractconfig', ['volume']],
export => [ __PACKAGE__, 'export', ['volume', 'format', 'filename']],
- import => [ __PACKAGE__, 'import', ['volume', 'format', 'filename']],
+ import => [ __PACKAGE__, 'import', ['volume', 'format', 'filename'], {}, sub {
+ my $volid = shift;
+ print "successfully imported '$volid'\n";
+ }],
};
1;
diff --git a/PVE/Storage.pm b/PVE/Storage.pm
index a46550c..38341f6 100755
--- a/PVE/Storage.pm
+++ b/PVE/Storage.pm
@@ -1426,7 +1426,7 @@ sub volume_import {
my $scfg = storage_config($cfg, $storeid);
my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
return $plugin->volume_import($scfg, $storeid, $fh, $volname, $format,
- $base_snapshot, $with_snapshots);
+ $base_snapshot, $with_snapshots) // $volid;
}
sub volume_export_formats {
diff --git a/PVE/Storage/LVMPlugin.pm b/PVE/Storage/LVMPlugin.pm
index f02c110..fcd48ef 100644
--- a/PVE/Storage/LVMPlugin.pm
+++ b/PVE/Storage/LVMPlugin.pm
@@ -661,6 +661,8 @@ sub volume_import {
warn $@ if $@;
die $err;
}
+
+ return "$storeid:$volname";
}
sub volume_import_write {
diff --git a/PVE/Storage/Plugin.pm b/PVE/Storage/Plugin.pm
index eab73f5..0a35ce5 100644
--- a/PVE/Storage/Plugin.pm
+++ b/PVE/Storage/Plugin.pm
@@ -1242,6 +1242,8 @@ sub volume_import {
warn $@ if $@;
die $err;
}
+
+ return "$storeid:$volname";
}
sub volume_import_formats {
diff --git a/PVE/Storage/ZFSPoolPlugin.pm b/PVE/Storage/ZFSPoolPlugin.pm
index b538e3b..b618e06 100644
--- a/PVE/Storage/ZFSPoolPlugin.pm
+++ b/PVE/Storage/ZFSPoolPlugin.pm
@@ -773,7 +773,7 @@ sub volume_import {
die $err;
}
- return;
+ return "$storeid:$dataset";
}
sub volume_import_formats {
--
2.20.1
More information about the pve-devel
mailing list