]> git.proxmox.com Git - pve-storage.git/blobdiff - PVE/Storage/BTRFSPlugin.pm
zfs: list: only cache and list images for requested storage/pool
[pve-storage.git] / PVE / Storage / BTRFSPlugin.pm
index 09b38a2405716d66c6365ffddef4b3f149bde99e..1db4e4f8712fd23ebb8e2eba6292ac836cfd6432 100644 (file)
@@ -6,7 +6,7 @@ use warnings;
 use base qw(PVE::Storage::Plugin);
 
 use Fcntl qw(S_ISDIR O_WRONLY O_CREAT O_EXCL);
-use File::Basename qw(dirname);
+use File::Basename qw(basename dirname);
 use File::Path qw(mkpath);
 use IO::Dir;
 use POSIX qw(EEXIST);
@@ -67,12 +67,14 @@ sub options {
        shared => { optional => 1 },
        disable => { optional => 1 },
        maxfiles => { optional => 1 },
-       'prune-backups'=> { optional => 1 },
+       'prune-backups' => { optional => 1 },
+       'max-protected-backups' => { optional => 1 },
        content => { optional => 1 },
        format => { optional => 1 },
        is_mountpoint => { optional => 1 },
        nocow => { optional => 1 },
        mkdir => { optional => 1 },
+       preallocation => { optional => 1 },
        # TODO: The new variant of mkdir with  `populate` vs `create`...
     };
 }
@@ -121,7 +123,7 @@ sub activate_storage {
     }
 
     my $mp = PVE::Storage::DirPlugin::parse_is_mountpoint($scfg);
-    if (defined($mp) && !path_is_mounted($mp, $cache->{mountdata})) {
+    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";
     }
@@ -136,9 +138,22 @@ sub status {
     return PVE::Storage::DirPlugin::status($class, $storeid, $scfg, $cache);
 }
 
-# TODO: sub get_volume_notes {}
+sub get_volume_attribute {
+    my ($class, $scfg, $storeid, $volname, $attribute) = @_;
+    return PVE::Storage::DirPlugin::get_volume_attribute($class, $scfg, $storeid, $volname, $attribute);
+}
 
-# TODO: sub update_volume_notes {}
+sub update_volume_attribute {
+    my ($class, $scfg, $storeid, $volname, $attribute, $value) = @_;
+    return PVE::Storage::DirPlugin::update_volume_attribute(
+       $class,
+       $scfg,
+       $storeid,
+       $volname,
+       $attribute,
+       $value,
+    );
+}
 
 # croak would not include the caller from within this module
 sub __error {
@@ -180,13 +195,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";
@@ -309,7 +324,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:
@@ -409,8 +424,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 $class->SUPER::free_image($storeid, $scfg, $volname, $isBase, $_format);
     }
 
     my $path = $class->filesystem_path($scfg, $volname);
@@ -421,9 +436,11 @@ sub free_image {
     }
 
     my $dir = dirname($subvol);
+    my $basename = basename($subvol);
     my @snapshot_vols;
     foreach_subvol($dir, sub {
        my ($volume, $name, $snapshot) = @_;
+       return if $name ne $basename;
        return if !defined $snapshot;
        push @snapshot_vols, "$dir/$volume";
     });
@@ -465,7 +482,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
@@ -513,7 +530,7 @@ sub volume_snapshot {
 }
 
 sub volume_rollback_is_possible {
-    my ($class, $scfg, $storeid, $volname, $snap) = @_; 
+    my ($class, $scfg, $storeid, $volname, $snap, $blockers) = @_;
 
     return 1; 
 }
@@ -589,18 +606,21 @@ sub volume_has_feature {
            current => { raw => 1 },
            snap => { raw => 1 },
        },
-       template => { current => { qcow2 => 1, raw => 1, vmdk => 1, subvol => 1 } },
+       template => {
+           current => { qcow2 => 1, raw => 1, vmdk => 1, subvol => 1 },
+       },
        copy => {
            base => { qcow2 => 1, raw => 1, subvol => 1, vmdk => 1 },
            current => { qcow2 => 1, raw => 1, subvol => 1, vmdk => 1 },
            snap => { qcow2 => 1, raw => 1, subvol => 1 },
        },
-       sparseinit => { base => {qcow2 => 1, raw => 1, vmdk => 1 },
-                       current => {qcow2 => 1, raw => 1, vmdk => 1 } },
+       sparseinit => {
+           base => { qcow2 => 1, raw => 1, vmdk => 1 },
+           current => { qcow2 => 1, raw => 1, vmdk => 1 },
+       },
     };
 
-    my ($vtype, $name, $vmid, $basename, $basevmid, $isBase, $format) =
-       $class->parse_volname($volname);
+    my ($vtype, $name, $vmid, $basename, $basevmid, $isBase, $format) = $class->parse_volname($volname);
 
     my $key = undef;
     if ($snapname) {