]> git.proxmox.com Git - pve-storage.git/blobdiff - PVE/Storage/CephFSPlugin.pm
pbs: allow setting up a master key
[pve-storage.git] / PVE / Storage / CephFSPlugin.pm
index bc1ca3e6b86239119ccc0015f7872ba81e599b27..480dc57727d187578b940466a815f1118eb9226f 100644 (file)
@@ -7,11 +7,12 @@ use IO::File;
 use Net::IP;
 use File::Path;
 
-use PVE::Tools qw(run_command file_set_contents);
+use PVE::CephConfig;
+use PVE::JSONSchema qw(get_standard_option);
 use PVE::ProcFSTools;
 use PVE::Storage::Plugin;
-use PVE::JSONSchema qw(get_standard_option);
-use PVE::CephConfig;
+use PVE::Systemd;
+use PVE::Tools qw(run_command file_set_contents);
 
 use base qw(PVE::Storage::Plugin);
 
@@ -37,25 +38,6 @@ sub cephfs_is_mounted {
     return undef;
 }
 
-
-# FIXME: duplicate of api/diskmanage one, move to common helper (pve-common's
-#        Tools or Systemd ?)
-sub systemd_escape {
-    my ($val, $is_path) = @_;
-
-    # NOTE: this is not complete, but enough for our needs. normally all
-    # characters which are not alpha-numerical, '.' or '_' would need escaping
-    $val =~ s/\-/\\x2d/g;
-
-    if ($is_path) {
-       $val =~ s/^\///g;
-       $val =~ s/\/$//g;
-    }
-    $val =~ s/\//-/g;
-
-    return $val;
-}
-
 # FIXME: remove in PVE 7.0 where systemd is recent enough to not have those
 #        local-fs/remote-fs dependency cycles generated for _netdev mounts...
 sub systemd_netmount {
@@ -83,10 +65,14 @@ Type=${type}
 Options=${opts}
 EOF
 
-    my $unit_fn = systemd_escape($where, 1) . ".mount";
+    my $unit_fn = PVE::Systemd::escape_unit($where, 1) . ".mount";
     my $unit_path = "/run/systemd/system/$unit_fn";
+    my $daemon_needs_reload = -e $unit_path;
 
     file_set_contents($unit_path, $unit);
+
+    run_command(['systemctl', 'daemon-reload'], errmsg => "daemon-reload error")
+       if $daemon_needs_reload;
     run_command(['systemctl', 'start', $unit_fn], errmsg => "mount error");
 
 }
@@ -94,7 +80,6 @@ EOF
 sub cephfs_mount {
     my ($scfg, $storeid) = @_;
 
-    my $cmd;
     my $mountpoint = $scfg->{path};
     my $subdir = $scfg->{subdir} // '/';
 
@@ -102,31 +87,26 @@ sub cephfs_mount {
     my $configfile = $cmd_option->{ceph_conf};
     my $secretfile = $cmd_option->{keyring};
     my $server = $cmd_option->{mon_host} // PVE::CephConfig::get_monaddr_list($configfile);
+    my $type = 'ceph';
 
-    # fuse -> client-enforced quotas (kernel doesn't), updates w/ ceph-fuse pkg
-    # kernel -> better performance, less frequent updates
+    my @opts = ();
     if ($scfg->{fuse}) {
-           # FIXME: ceph-fuse client complains about missing ceph.conf or keyring if
-           # not provided on its default locations but still connects. Fix upstream??
-           $cmd = ['/usr/bin/ceph-fuse', '-n', "client.$cmd_option->{userid}", '-m', $server];
-           push @$cmd, '--keyfile', $secretfile if defined($secretfile);
-           push @$cmd, '-r', $subdir if !($subdir =~ m|^/$|);
-           push @$cmd, $mountpoint;
-           push @$cmd, '--conf', $configfile if defined($configfile);
-
-           if ($scfg->{options}) {
-               push @$cmd, '-o', $scfg->{options};
-           }
-
-           run_command($cmd, errmsg => "mount error");
+       $type = 'fuse.ceph';
+       push @opts, "ceph.id=$cmd_option->{userid}";
+       push @opts, "ceph.keyfile=$secretfile" if defined($secretfile);
+       push @opts, "ceph.conf=$configfile" if defined($configfile);
     } else {
-       my $source = "$server:$subdir";
-       my @opts = ( "name=$cmd_option->{userid}" );
+       push @opts, "name=$cmd_option->{userid}";
        push @opts, "secretfile=$secretfile" if defined($secretfile);
-       push @opts, $scfg->{options} if $scfg->{options};
 
-       systemd_netmount($mountpoint, 'ceph', $source, join(',', @opts));
+       # FIXME: remove version check in PVE 7.0, only needed for Luminous -> Nautilus
+       my ($subversions) = PVE::CephConfig::local_ceph_version();
+       push @opts, "conf=$configfile" if defined($configfile) && @$subversions[0] > 12;
     }
+
+    push @opts, $scfg->{options} if $scfg->{options};
+
+    systemd_netmount($mountpoint, $type, "$server:$subdir", join(',', @opts));
 }
 
 # Configuration
@@ -170,6 +150,7 @@ sub options {
        fuse => { optional => 1 },
        bwlimit => { optional => 1 },
        maxfiles => { optional => 1 },
+       'prune-backups' => { optional => 1 },
     };
 }
 
@@ -189,6 +170,8 @@ sub on_add_hook {
     return if defined($scfg->{monhost}); # nothing to do if not pve managed ceph
 
     PVE::CephConfig::ceph_create_keyfile($scfg->{type}, $storeid);
+
+    return;
 }
 
 sub on_delete_hook {
@@ -197,6 +180,8 @@ sub on_delete_hook {
     return if defined($scfg->{monhost}); # nothing to do if not pve managed ceph
 
     PVE::CephConfig::ceph_remove_keyfile($scfg->{type}, $storeid);
+
+    return;
 }
 
 sub status {
@@ -241,4 +226,14 @@ sub deactivate_storage {
     }
 }
 
+sub get_volume_notes {
+    my $class = shift;
+    PVE::Storage::DirPlugin::get_volume_notes($class, @_);
+}
+
+sub update_volume_notes {
+    my $class = shift;
+    PVE::Storage::DirPlugin::update_volume_notes($class, @_);
+}
+
 1;