]> git.proxmox.com Git - pve-storage.git/blobdiff - PVE/Storage/CephFSPlugin.pm
lvm thin: add missing newline to error message
[pve-storage.git] / PVE / Storage / CephFSPlugin.pm
index 53491edb533ad0ed5af3f128ab2ab19cfcdd59ea..f75c1b87189319126ed4eba45c6e97e0ea62d250 100644 (file)
@@ -7,11 +7,12 @@ use IO::File;
 use Net::IP;
 use File::Path;
 
-use PVE::Tools qw(run_command);
+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);
 
@@ -20,16 +21,14 @@ sub cephfs_is_mounted {
 
     my $cmd_option = PVE::CephConfig::ceph_connect_option($scfg, $storeid);
     my $configfile = $cmd_option->{ceph_conf};
-    my $server = $cmd_option->{mon_host} // PVE::CephConfig::get_monaddr_list($configfile);
 
     my $subdir = $scfg->{subdir} // '/';
     my $mountpoint = $scfg->{path};
-    my $source = "$server:$subdir";
 
     $mountdata = PVE::ProcFSTools::parse_proc_mounts() if !$mountdata;
     return $mountpoint if grep {
        $_->[2] =~ m#^ceph|fuse\.ceph-fuse# &&
-       $_->[0] =~ m#^\Q$source\E|ceph-fuse$# &&
+       $_->[0] =~ m#\Q:$subdir\E$|^ceph-fuse$# &&
        $_->[1] eq $mountpoint
     } @$mountdata;
 
@@ -39,10 +38,47 @@ sub cephfs_is_mounted {
     return undef;
 }
 
+# FIXME: remove once it's possible to specify _netdev for fuse.ceph mounts
+sub systemd_netmount {
+    my ($where, $type, $what, $opts) = @_;
+
+# don't do default deps, systemd v241 generator produces ordering deps on both
+# local-fs(-pre) and remote-fs(-pre) targets if we use the required _netdev
+# option. Over three corners this gets us an ordering cycle on shutdown, which
+# may make shutdown hang if the random cycle breaking hits the "wrong" unit to
+# delete.
+    my $unit =  <<"EOF";
+[Unit]
+Description=${where}
+DefaultDependencies=no
+Requires=system.slice
+Wants=network-online.target
+Before=umount.target remote-fs.target
+After=systemd-journald.socket system.slice network.target -.mount remote-fs-pre.target network-online.target
+Conflicts=umount.target
+
+[Mount]
+Where=${where}
+What=${what}
+Type=${type}
+Options=${opts}
+EOF
+
+    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");
+
+}
+
 sub cephfs_mount {
     my ($scfg, $storeid) = @_;
 
-    my $cmd;
     my $mountpoint = $scfg->{path};
     my $subdir = $scfg->{subdir} // '/';
 
@@ -50,33 +86,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';
+    my $fs_name = $scfg->{'fs-name'};
 
-    # 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);
+       $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);
+       push @opts, "ceph.client_fs=$fs_name" if defined($fs_name);
     } else {
-       my $source = "$server:$subdir";
-       $cmd = ['/bin/mount', '-t', 'ceph', $source, $mountpoint, '-o', "name=$cmd_option->{userid}"];
-       push @$cmd, '-o', "secretfile=$secretfile" if defined($secretfile);
-
-       # tell systemd that we're network dependent, else it umounts us to late
-       # on shutdown, when we couldn't connect to the active MDS and thus
-       # unmount hangs and delays shutdown/reboot (man systemd.mount).
-       push @$cmd, '-o', '_netdev';
+       push @opts, "name=$cmd_option->{userid}";
+       push @opts, "secretfile=$secretfile" if defined($secretfile);
+       push @opts, "conf=$configfile" if defined($configfile);
+       push @opts, "fs=$fs_name" if defined($fs_name);
     }
 
-    if ($scfg->{options}) {
-       push @$cmd, '-o', $scfg->{options};
-    }
+    push @opts, $scfg->{options} if $scfg->{options};
 
-    run_command($cmd, errmsg => "mount error");
+    systemd_netmount($mountpoint, $type, "$server:$subdir", join(',', @opts));
 }
 
 # Configuration
@@ -102,6 +131,10 @@ sub properties {
            description => "Subdir to mount.",
            type => 'string', format => 'pve-storage-path',
        },
+       'fs-name' => {
+           description => "The Ceph filesystem name.",
+           type => 'string', format => 'pve-configid',
+       },
     };
 }
 
@@ -120,6 +153,9 @@ sub options {
        fuse => { optional => 1 },
        bwlimit => { optional => 1 },
        maxfiles => { optional => 1 },
+       keyring => { optional => 1 },
+       'prune-backups' => { optional => 1 },
+       'fs-name' => { optional => 1 },
     };
 }
 
@@ -136,17 +172,30 @@ sub check_config {
 sub on_add_hook {
     my ($class, $storeid, $scfg, %param) = @_;
 
-    return if defined($scfg->{monhost}); # nothing to do if not pve managed ceph
+    my $secret = $param{keyring} if defined $param{keyring} // undef;
+    PVE::CephConfig::ceph_create_keyfile($scfg->{type}, $storeid, $secret);
 
-    PVE::CephConfig::ceph_create_keyfile($scfg->{type}, $storeid);
+    return;
 }
 
-sub on_delete_hook {
-    my ($class, $storeid, $scfg) = @_;
+sub on_update_hook {
+    my ($class, $storeid, $scfg, %param) = @_;
 
-    return if defined($scfg->{monhost}); # nothing to do if not pve managed ceph
+    if (exists($param{keyring})) {
+       if (defined($param{keyring})) {
+           PVE::CephConfig::ceph_create_keyfile($scfg->{type}, $storeid, $param{keyring});
+       } else {
+           PVE::CephConfig::ceph_remove_keyfile($scfg->{type}, $storeid);
+       }
+    }
+
+    return;
+}
 
+sub on_delete_hook {
+    my ($class, $storeid, $scfg) = @_;
     PVE::CephConfig::ceph_remove_keyfile($scfg->{type}, $storeid);
+    return;
 }
 
 sub status {
@@ -191,4 +240,26 @@ sub deactivate_storage {
     }
 }
 
+# FIXME remove on the next APIAGE reset.
+# Deprecated, use get_volume_attribute instead.
+sub get_volume_notes {
+    my $class = shift;
+    PVE::Storage::DirPlugin::get_volume_notes($class, @_);
+}
+
+# FIXME remove on the next APIAGE reset.
+# Deprecated, use update_volume_attribute instead.
+sub update_volume_notes {
+    my $class = shift;
+    PVE::Storage::DirPlugin::update_volume_notes($class, @_);
+}
+
+sub get_volume_attribute {
+    return PVE::Storage::DirPlugin::get_volume_attribute(@_);
+}
+
+sub update_volume_attribute {
+    return PVE::Storage::DirPlugin::update_volume_attribute(@_);
+}
+
 1;