]> git.proxmox.com Git - pve-storage.git/blobdiff - PVE/Storage/Plugin.pm
plugin: change name, separator and error message for dir overrides
[pve-storage.git] / PVE / Storage / Plugin.pm
index 8a41df10b94b7112bf566561409305505fc8e67c..a3aac611b5a77fa7a5bb07b7bb00eaa2b84cbf2d 100644 (file)
@@ -181,6 +181,11 @@ my $defaultData = {
            default => 'metadata',
            optional => 1,
        },
+       'content-dirs' => {
+           description => "Overrides for default content type directories.",
+           type => "string", format => "pve-dir-override-list",
+           optional => 1,
+       },
     },
 };
 
@@ -205,6 +210,12 @@ sub valid_content_types {
     return $def->{content}->[0];
 }
 
+sub dirs_hash_to_string {
+    my $hash = shift;
+
+    return join(',', map { "$_=$hash->{$_}" } sort keys %$hash);
+}
+
 sub default_format {
     my ($scfg) = @_;
 
@@ -335,6 +346,18 @@ sub parse_volume_id {
     die "unable to parse volume ID '$volid'\n";
 }
 
+PVE::JSONSchema::register_format('pve-dir-override', \&verify_dir_override);
+sub verify_dir_override {
+    my ($value, $noerr) = @_;
+
+    if($value =~ m/^([a-z]+)=\/.+$/ &&
+       verify_content($1, $noerr)) {
+       return $value;
+    }
+
+    return undef if $noerr;
+    die "invalid override '$value'\n";
+}
 
 sub private {
     return $defaultData;
@@ -405,6 +428,22 @@ sub decode_value {
        #    die "storage '$storeid' does not allow node restrictions\n";
        #}
 
+       return $res;
+    } elsif ($key eq 'content-dirs') {
+       my $valid_content = $def->{content}->[0];
+       my $res = {};
+
+       foreach my $dir (PVE::Tools::split_list($value)) {
+           my ($content, $path) = split(/=/, $dir, 2);
+
+           if (!$valid_content->{$content}) {
+               warn "storage does not support content type '$content'\n";
+               next;
+           }
+
+           $res->{$content} = $path;
+       }
+
        return $res;
     }
 
@@ -419,6 +458,9 @@ sub encode_value {
     } elsif ($key eq 'content') {
        my $res = content_hash_to_string($value) || 'none';
        return $res;
+    } elsif ($key eq 'content-dirs') {
+       my $res = dirs_hash_to_string($value);
+       return $res;
     }
 
     return $value;
@@ -610,12 +652,11 @@ sub get_subdir {
     my $path = $scfg->{path};
 
     die "storage definition has no path\n" if !$path;
+    die "unknown vtype '$vtype'\n" if !exists($vtype_subdirs->{$vtype});
 
-    my $subdir = $vtype_subdirs->{$vtype};
-
-    die "unknown vtype '$vtype'\n" if !defined($subdir);
+    my $subdir = $scfg->{"content-dirs"}->{$vtype} // "/".$vtype_subdirs->{$vtype};
 
-    return "$path/$subdir";
+    return $path.$subdir;
 }
 
 sub filesystem_path {