cephfs plugin: followup with some code cleanups
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
@ -2,9 +2,11 @@ package PVE::Storage::CephFSPlugin;
|
|||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
use IO::File;
|
use IO::File;
|
||||||
use Net::IP;
|
use Net::IP;
|
||||||
use File::Path;
|
use File::Path;
|
||||||
|
|
||||||
use PVE::Tools qw(run_command);
|
use PVE::Tools qw(run_command);
|
||||||
use PVE::ProcFSTools;
|
use PVE::ProcFSTools;
|
||||||
use PVE::Storage::Plugin;
|
use PVE::Storage::Plugin;
|
||||||
@ -59,7 +61,7 @@ sub cephfs_mount {
|
|||||||
push @$cmd, '-r', $subdir if !($subdir =~ m|^/$|);
|
push @$cmd, '-r', $subdir if !($subdir =~ m|^/$|);
|
||||||
push @$cmd, $mountpoint;
|
push @$cmd, $mountpoint;
|
||||||
push @$cmd, '--conf', $configfile if defined($configfile);
|
push @$cmd, '--conf', $configfile if defined($configfile);
|
||||||
}else {
|
} else {
|
||||||
my $source = "$server:$subdir";
|
my $source = "$server:$subdir";
|
||||||
$cmd = ['/bin/mount', '-t', 'ceph', $source, $mountpoint, '-o', "name=$cmd_option->{userid}"];
|
$cmd = ['/bin/mount', '-t', 'ceph', $source, $mountpoint, '-o', "name=$cmd_option->{userid}"];
|
||||||
push @$cmd, '-o', "secretfile=$secretfile" if defined($secretfile);
|
push @$cmd, '-o', "secretfile=$secretfile" if defined($secretfile);
|
||||||
@ -139,14 +141,12 @@ sub on_delete_hook {
|
|||||||
return if defined($scfg->{monhost}); # nothing to do if not pve managed ceph
|
return if defined($scfg->{monhost}); # nothing to do if not pve managed ceph
|
||||||
|
|
||||||
PVE::Storage::CephTools::ceph_remove_keyfile($scfg->{type}, $storeid);
|
PVE::Storage::CephTools::ceph_remove_keyfile($scfg->{type}, $storeid);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub status {
|
sub status {
|
||||||
my ($class, $storeid, $scfg, $cache) = @_;
|
my ($class, $storeid, $scfg, $cache) = @_;
|
||||||
|
|
||||||
$cache->{mountdata} = PVE::ProcFSTools::parse_proc_mounts()
|
$cache->{mountdata} //= PVE::ProcFSTools::parse_proc_mounts();
|
||||||
if !$cache->{mountdata};
|
|
||||||
|
|
||||||
return undef if !cephfs_is_mounted($scfg, $storeid, $cache->{mountdata});
|
return undef if !cephfs_is_mounted($scfg, $storeid, $cache->{mountdata});
|
||||||
|
|
||||||
@ -156,15 +156,11 @@ sub status {
|
|||||||
sub activate_storage {
|
sub activate_storage {
|
||||||
my ($class, $storeid, $scfg, $cache) = @_;
|
my ($class, $storeid, $scfg, $cache) = @_;
|
||||||
|
|
||||||
$cache->{mountdata} = PVE::ProcFSTools::parse_proc_mounts()
|
$cache->{mountdata} //= PVE::ProcFSTools::parse_proc_mounts();
|
||||||
if !$cache->{mountdata};
|
|
||||||
|
|
||||||
my $path = $scfg->{path};
|
|
||||||
|
|
||||||
|
# NOTE: mkpath may hang if storage is mounted but not reachable
|
||||||
if (!cephfs_is_mounted($scfg, $storeid, $cache->{mountdata})) {
|
if (!cephfs_is_mounted($scfg, $storeid, $cache->{mountdata})) {
|
||||||
|
my $path = $scfg->{path};
|
||||||
# NOTE: only call mkpath when not mounted (avoid hang
|
|
||||||
# when cephfs is offline
|
|
||||||
|
|
||||||
mkpath $path if !(defined($scfg->{mkdir}) && !$scfg->{mkdir});
|
mkpath $path if !(defined($scfg->{mkdir}) && !$scfg->{mkdir});
|
||||||
|
|
||||||
@ -180,14 +176,12 @@ sub activate_storage {
|
|||||||
sub deactivate_storage {
|
sub deactivate_storage {
|
||||||
my ($class, $storeid, $scfg, $cache) = @_;
|
my ($class, $storeid, $scfg, $cache) = @_;
|
||||||
|
|
||||||
$cache->{mountdata} = PVE::ProcFSTools::parse_proc_mounts()
|
$cache->{mountdata} //= PVE::ProcFSTools::parse_proc_mounts();
|
||||||
if !$cache->{mountdata};
|
|
||||||
|
|
||||||
my $path = $scfg->{path};
|
my $path = $scfg->{path};
|
||||||
|
|
||||||
if (cephfs_is_mounted($scfg, $storeid, $cache->{mountdata})) {
|
if (cephfs_is_mounted($scfg, $storeid, $cache->{mountdata})) {
|
||||||
my $cmd = ['/bin/umount', $path];
|
run_command(['/bin/umount', $path], errmsg => 'umount error');
|
||||||
run_command($cmd, errmsg => 'umount error');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user