]> git.proxmox.com Git - pve-storage.git/blobdiff - PVE/Storage/Plugin.pm
map_volume: fall back to 'path'
[pve-storage.git] / PVE / Storage / Plugin.pm
index 8ae78e9e9fb09a6cda32edbf538be3ae9eef048b..cca0ed862c835d70842aa627ea2a8e3f100bdc7d 100644 (file)
@@ -5,6 +5,7 @@ use warnings;
 
 use File::chdir;
 use File::Path;
+use File::Basename;
 
 use PVE::Tools qw(run_command);
 use PVE::JSONSchema qw(get_standard_option);
@@ -326,7 +327,7 @@ sub parse_config {
            priority => 0, # force first entry
            path => '/var/lib/vz',
            maxfiles => 0,
-           content => { images => 1, rootdir => 1, vztmpl => 1, iso => 1},
+           content => { images => 1, rootdir => 1, vztmpl => 1, iso => 1, snippets => 1},
        };
     }
 
@@ -427,6 +428,8 @@ sub parse_volname {
            return ('backup', $fn, $2);
        }
        return ('backup', $fn);
+    } elsif ($volname =~ m!^snippets/([^/]+)$!) {
+       return ('snippets', $1);
     }
 
     die "unable to parse directory volume name '$volname'\n";
@@ -438,6 +441,7 @@ my $vtype_subdirs = {
     iso => 'template/iso',
     vztmpl => 'template/cache',
     backup => 'dump',
+    snippets => 'snippets',
 };
 
 sub get_subdir {
@@ -661,7 +665,12 @@ sub alloc_image {
        
        push @$cmd, '-f', $fmt, $path, "${size}K";
 
-       run_command($cmd, errmsg => "unable to create image");
+       eval { run_command($cmd, errmsg => "unable to create image"); };
+       if ($@) {
+           unlink $path;
+           rmdir $imagedir;
+           die "$@";
+       }
     }
     
     return "$vmid/$name";
@@ -689,6 +698,11 @@ sub free_image {
 
        unlink($path) || die "unlink '$path' failed - $!\n";
     }
+
+    # try to cleanup directory to not clutter storage with empty $vmid dirs if
+    # all images from a guest got deleted
+    my $dir = dirname($path);
+    rmdir($dir);
     
     return undef;
 }
@@ -949,6 +963,19 @@ sub deactivate_storage {
     # do nothing by default
 }
 
+sub map_volume {
+    my ($class, $storeid, $scfg, $volname, $snapname) = @_;
+
+    my ($path) = $class->path($scfg, $volname, $storeid, $snapname);
+    return $path;
+}
+
+sub unmap_volume {
+    my ($class, $storeid, $scfg, $volname, $snapname) = @_;
+
+    return 1;
+}
+
 sub activate_volume {
     my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_;