]> git.proxmox.com Git - pve-storage.git/blobdiff - PVE/Storage.pm
lvm: volume import: handle worker returned by free_image
[pve-storage.git] / PVE / Storage.pm
index 19f675d5bd2045ead97c23b56c35fb7bce73e57b..f2231f2f8c67beb40df19cc9ad907dc2badbbb72 100755 (executable)
@@ -37,7 +37,6 @@ use PVE::Storage::ISCSIDirectPlugin;
 use PVE::Storage::GlusterfsPlugin;
 use PVE::Storage::ZFSPoolPlugin;
 use PVE::Storage::ZFSPlugin;
-use PVE::Storage::DRBDPlugin;
 use PVE::Storage::PBSPlugin;
 
 # Storage API version. Increment it on changes in storage API interface.
@@ -60,7 +59,6 @@ PVE::Storage::ISCSIDirectPlugin->register();
 PVE::Storage::GlusterfsPlugin->register();
 PVE::Storage::ZFSPoolPlugin->register();
 PVE::Storage::ZFSPlugin->register();
-PVE::Storage::DRBDPlugin->register();
 PVE::Storage::PBSPlugin->register();
 
 # load third-party plugins
@@ -75,10 +73,8 @@ if ( -d '/usr/share/perl5/PVE/Storage/Custom' ) {
            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');
+           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"
@@ -86,11 +82,11 @@ if ( -d '/usr/share/perl5/PVE/Storage/Custom' ) {
            my $min_version = (APIVER - APIAGE);
            die "API version too old, please update the plugin ($version < $min_version)\n"
                if $version < $min_version;
+           # all OK, do import and register (i.e., "use")
            import $file;
            $modname->register();
 
-           # If we got this far and the API version is not the same, make some
-           # noise:
+           # 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;
        };
@@ -127,7 +123,7 @@ sub lock_storage_config {
     }
 }
 
-# FIXME remove maxfiles for PVE 7.0
+# FIXME remove maxfiles for PVE 8.0 or PVE 9.0
 my $convert_maxfiles_to_prune_backups = sub {
     my ($scfg) = @_;
 
@@ -609,22 +605,22 @@ sub path {
 }
 
 sub abs_filesystem_path {
-    my ($cfg, $volid) = @_;
+    my ($cfg, $volid, $allow_blockdev) = @_;
 
     my $path;
     if (parse_volume_id ($volid, 1)) {
        activate_volumes($cfg, [ $volid ]);
        $path = PVE::Storage::path($cfg, $volid);
     } else {
-       if (-f $volid) {
+       if (-f $volid || ($allow_blockdev && -b $volid)) {
            my $abspath = abs_path($volid);
            if ($abspath && $abspath =~ m|^(/.+)$|) {
                $path = $1; # untaint any path
            }
        }
     }
-
-    die "can't find file '$volid'\n" if !($path && -f $path);
+    die "can't find file '$volid'\n"
+       if !($path && (-f $path || ($allow_blockdev && -b $path)));
 
     return $path;
 }
@@ -932,7 +928,7 @@ sub vdisk_free {
 }
 
 sub vdisk_list {
-    my ($cfg, $storeid, $vmid, $vollist) = @_;
+    my ($cfg, $storeid, $vmid, $vollist, $ctype) = @_;
 
     my $ids = $cfg->{ids};
 
@@ -955,6 +951,7 @@ sub vdisk_list {
            next if $storeid && $storeid ne $sid;
            next if !storage_check_enabled($cfg, $sid, undef, 1);
            my $content = $ids->{$sid}->{content};
+           next if defined($ctype) && !$content->{$ctype};
            next if !($content->{rootdir} || $content->{images});
            push @$storage_list, $sid;
        }
@@ -965,7 +962,9 @@ sub vdisk_list {
     activate_storage_list($cfg, $storage_list, $cache);
 
     # FIXME PVE 7.0: only scan storages with the correct content types
-    foreach my $sid (keys %$ids) {
+    my $scan = defined($ctype) ? $storage_list : [ keys %{$ids} ];
+
+    foreach my $sid (@{$scan}) {
        next if $storeid && $storeid ne $sid;
        next if !storage_check_enabled($cfg, $sid, undef, 1);
 
@@ -1627,6 +1626,8 @@ sub prune_backups {
        $keep = PVE::JSONSchema::parse_property_string('prune-backups', $scfg->{'prune-backups'});
     }
 
+    activate_storage($cfg, $storeid);
+
     my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
     return $plugin->prune_backups($scfg, $storeid, $keep, $vmid, $type, $dryrun, $logfunc);
 }