]> git.proxmox.com Git - pve-storage.git/blobdiff - PVE/Storage/BTRFSPlugin.pm
fix prune-backups validation (again)
[pve-storage.git] / PVE / Storage / BTRFSPlugin.pm
index dc5894a28d96b3b4edd901e8f67bad8a8b879be1..dbc1244842a6fafaf2d39a79b6aa4e4d1ba20680 100644 (file)
@@ -67,10 +67,12 @@ sub options {
        shared => { optional => 1 },
        disable => { optional => 1 },
        maxfiles => { optional => 1 },
+       'prune-backups'=> { optional => 1 },
        content => { optional => 1 },
        format => { optional => 1 },
        is_mountpoint => { optional => 1 },
        nocow => { optional => 1 },
+       mkdir => { optional => 1 },
        # TODO: The new variant of mkdir with  `populate` vs `create`...
     };
 }
@@ -112,8 +114,21 @@ my sub assert_btrfs($) {
 
 sub activate_storage {
     my ($class, $storeid, $scfg, $cache) = @_;
-    PVE::Storage::DirPlugin::activate_storage($class, $storeid, $scfg, $cache);
-    assert_btrfs($scfg->{path});
+
+    my $path = $scfg->{path};
+    if (!defined($scfg->{mkdir}) || $scfg->{mkdir}) {
+       mkpath $path;
+    }
+
+    my $mp = PVE::Storage::DirPlugin::parse_is_mountpoint($scfg);
+    if (defined($mp) && !PVE::Storage::DirPlugin::path_is_mounted($mp, $cache->{mountdata})) {
+       die "unable to activate storage '$storeid' - directory is expected to be a mount point but"
+       ." is not mounted: '$mp'\n";
+    }
+
+    assert_btrfs($path); # only assert this stuff now, ensures $path is there and better UX
+
+    $class->SUPER::activate_storage($storeid, $scfg, $cache);
 }
 
 sub status {
@@ -165,13 +180,13 @@ sub filesystem_path {
 
     $path .= "/$vmid" if $vtype eq 'images';
 
-    if ($format eq 'raw') {
+    if (defined($format) && $format eq 'raw') {
        my $dir = raw_name_to_dir($name);
        if ($snapname) {
            $dir .= "\@$snapname";
        }
        $path .= "/$dir/disk.raw";
-    } elsif ($format eq 'subvol') {
+    } elsif (defined($format) && $format eq 'subvol') {
        $path .= "/$name";
        if ($snapname) {
            $path .= "\@$snapname";
@@ -294,7 +309,7 @@ sub alloc_image {
     my ($class, $storeid, $scfg, $vmid, $fmt, $name, $size) = @_;
 
     if ($fmt ne 'raw' && $fmt ne 'subvol') {
-       return PVE::Storage::DirPlugin::alloc_image(@_);
+       return $class->SUPER::alloc_image($storeid, $scfg, $vmid, $fmt, $name, $size);
     }
 
     # From Plugin.pm:
@@ -394,8 +409,8 @@ sub free_image {
     my (undef, undef, $vmid, undef, undef, undef, $format) =
        $class->parse_volname($volname);
 
-    if ($format ne 'subvol' && $format ne 'raw') {
-       return PVE::Storage::DirPlugin::free_image(@_);
+    if (!defined($format) || ($format ne 'subvol' && $format ne 'raw')) {
+       return PVE::Storage::DirPlugin->free_image($storeid, $scfg, $volname, $isBase, $_format);
     }
 
     my $path = $class->filesystem_path($scfg, $volname);
@@ -450,7 +465,7 @@ sub volume_size_info {
 
     my $format = ($class->parse_volname($volname))[6];
 
-    if ($format eq 'subvol') {
+    if (defined($format) && $format eq 'subvol') {
        my $ctime = (stat($path))[10];
        my ($used, $size) = (0, 0);
        #my ($used, $size) = btrfs_subvol_quota($class, $path); # uses wantarray