]> git.proxmox.com Git - pve-storage.git/blobdiff - PVE/Storage.pm
APIAGE followup: fix typo and print versions in error message
[pve-storage.git] / PVE / Storage.pm
index d733380596552bd54ba250ab856ab07743e78d89..8b9957dedac4fd93e971d0d417f2a759f7242023 100755 (executable)
@@ -28,6 +28,7 @@ use PVE::Storage::NFSPlugin;
 use PVE::Storage::CIFSPlugin;
 use PVE::Storage::ISCSIPlugin;
 use PVE::Storage::RBDPlugin;
+use PVE::Storage::CephFSPlugin;
 use PVE::Storage::SheepdogPlugin;
 use PVE::Storage::ISCSIDirectPlugin;
 use PVE::Storage::GlusterfsPlugin;
@@ -36,7 +37,11 @@ use PVE::Storage::ZFSPlugin;
 use PVE::Storage::DRBDPlugin;
 
 # Storage API version. Icrement it on changes in storage API interface.
-use constant APIVER => 1;
+use constant APIVER => 2;
+# Age is the number of versions we're backward compatible with.
+# This is like having 'current=APIVER' and age='APIAGE' in libtool,
+# see https://www.gnu.org/software/libtool/manual/html_node/Libtool-versioning.html
+use constant APIAGE => 1;
 
 # load standard plugins
 PVE::Storage::DirPlugin->register();
@@ -46,6 +51,7 @@ PVE::Storage::NFSPlugin->register();
 PVE::Storage::CIFSPlugin->register();
 PVE::Storage::ISCSIPlugin->register();
 PVE::Storage::RBDPlugin->register();
+PVE::Storage::CephFSPlugin->register();
 PVE::Storage::SheepdogPlugin->register();
 PVE::Storage::ISCSIDirectPlugin->register();
 PVE::Storage::GlusterfsPlugin->register();
@@ -63,18 +69,29 @@ if ( -d '/usr/share/perl5/PVE/Storage/Custom' ) {
 
        eval {
            require $file;
+
+           # Check perl interface:
+           die "not derived from PVE::Storage::Plugin\n"
+               if !$modname->isa('PVE::Storage::Plugin');
+           die "does not provide an api() method\n"
+               if !$modname->can('api');
+           # Check storage API version and that file is really storage plugin.
+           my $version = $modname->api();
+           die "implements an API version newer than current ($version > " . APIVER . ")\n"
+               if $version > APIVER;
+           my $min_version = (APIVER - APIAGE);
+           die "API version too old, please update the plugin ($version < $min_version)\n"
+               if $version < $min_version;
+           import $file;
+           $modname->register();
+
+           # If we got this far and the API version is not the same, make some
+           # noise:
+           warn "Plugin \"$modname\" is implementing an older storage API, an upgrade is recommended\n"
+               if $version != APIVER;
        };
        if ($@) {
-           warn $@;
-       # Check storage API version and that file is really storage plugin.
-       } elsif ($modname->isa('PVE::Storage::Plugin') && $modname->can('api') && $modname->api() == APIVER) {
-            eval {
-               import $file;
-               $modname->register();
-            };
-            warn $@ if $@;
-       } else {
-           warn "Error loading storage plugin \"$modname\" because of API version mismatch. Please, update it.\n"
+           warn "Error loading storage plugin \"$modname\": $@";
        }
     });
 }
@@ -669,6 +686,30 @@ sub vdisk_create_base {
     });
 }
 
+sub map_volume {
+    my ($cfg, $volid, $snapname) = @_;
+
+    my ($storeid, $volname) = parse_volume_id($volid);
+
+    my $scfg = storage_config($cfg, $storeid);
+
+    my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
+
+    return $plugin->map_volume($storeid, $scfg, $volname, $snapname);
+}
+
+sub unmap_volume {
+    my ($cfg, $volid, $snapname) = @_;
+
+    my ($storeid, $volname) = parse_volume_id($volid);
+
+    my $scfg = storage_config($cfg, $storeid);
+
+    my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
+
+    return $plugin->unmap_volume($storeid, $scfg, $volname, $snapname);
+}
+
 sub vdisk_alloc {
     my ($cfg, $storeid, $vmid, $fmt, $name, $size) = @_;
 
@@ -1645,4 +1686,16 @@ sub get_bandwidth_limit {
     return $override;
 }
 
+# checks if the storage id is available and dies if not
+sub assert_sid_unused {
+    my ($sid) = @_;
+
+    my $cfg = config();
+    if (my $scfg = storage_config($cfg, $sid, 1)) {
+       die "storage ID '$sid' already defined\n";
+    }
+
+    return undef;
+}
+
 1;