]>
git.proxmox.com Git - pve-storage.git/blob - PVE/Storage/CephFSPlugin.pm
1 package PVE
::Storage
::CephFSPlugin
;
10 use PVE
::Tools
qw(run_command);
12 use PVE
::Storage
::Plugin
;
13 use PVE
::JSONSchema
qw(get_standard_option);
16 use base
qw(PVE::Storage::Plugin);
18 sub cephfs_is_mounted
{
19 my ($scfg, $storeid, $mountdata) = @_;
21 my $cmd_option = PVE
::CephConfig
::ceph_connect_option
($scfg, $storeid);
22 my $configfile = $cmd_option->{ceph_conf
};
23 my $server = $cmd_option->{mon_host
} // PVE
::CephConfig
::get_monaddr_list
($configfile);
25 my $subdir = $scfg->{subdir
} // '/';
26 my $mountpoint = $scfg->{path
};
27 my $source = "$server:$subdir";
29 $mountdata = PVE
::ProcFSTools
::parse_proc_mounts
() if !$mountdata;
30 return $mountpoint if grep {
31 $_->[2] =~ m
#^ceph|fuse\.ceph-fuse# &&
32 $_->[0] =~ m
#^\Q$source\E|ceph-fuse$# &&
33 $_->[1] eq $mountpoint
36 warn "A filesystem is already mounted on $mountpoint\n"
37 if grep { $_->[1] eq $mountpoint } @$mountdata;
43 my ($scfg, $storeid) = @_;
46 my $mountpoint = $scfg->{path
};
47 my $subdir = $scfg->{subdir
} // '/';
49 my $cmd_option = PVE
::CephConfig
::ceph_connect_option
($scfg, $storeid);
50 my $configfile = $cmd_option->{ceph_conf
};
51 my $secretfile = $cmd_option->{keyring
};
52 my $server = $cmd_option->{mon_host
} // PVE
::CephConfig
::get_monaddr_list
($configfile);
54 # fuse -> client-enforced quotas (kernel doesn't), updates w/ ceph-fuse pkg
55 # kernel -> better performance, less frequent updates
57 # FIXME: ceph-fuse client complains about missing ceph.conf or keyring if
58 # not provided on its default locations but still connects. Fix upstream??
59 $cmd = ['/usr/bin/ceph-fuse', '-n', "client.$cmd_option->{userid}", '-m', $server];
60 push @$cmd, '--keyfile', $secretfile if defined($secretfile);
61 push @$cmd, '-r', $subdir if !($subdir =~ m
|^/$|);
62 push @$cmd, $mountpoint;
63 push @$cmd, '--conf', $configfile if defined($configfile);
65 my $source = "$server:$subdir";
66 $cmd = ['/bin/mount', '-t', 'ceph', $source, $mountpoint, '-o', "name=$cmd_option->{userid}"];
67 push @$cmd, '-o', "secretfile=$secretfile" if defined($secretfile);
69 # tell systemd that we're network dependent, else it umounts us to late
70 # on shutdown, when we couldn't connect to the active MDS and thus
71 # unmount hangs and delays shutdown/reboot (man systemd.mount).
72 push @$cmd, '-o', '_netdev';
75 if ($scfg->{options
}) {
76 push @$cmd, '-o', $scfg->{options
};
79 run_command
($cmd, errmsg
=> "mount error");
90 content
=> [ { vztmpl
=> 1, iso
=> 1, backup
=> 1, snippets
=> 1},
98 description
=> "Mount CephFS through FUSE.",
102 description
=> "Subdir to mount.",
103 type
=> 'string', format
=> 'pve-storage-path',
110 path
=> { fixed
=> 1 },
111 monhost
=> { optional
=> 1},
112 nodes
=> { optional
=> 1 },
113 subdir
=> { optional
=> 1 },
114 disable
=> { optional
=> 1 },
115 options
=> { optional
=> 1 },
116 username
=> { optional
=> 1 },
117 content
=> { optional
=> 1 },
118 format
=> { optional
=> 1 },
119 mkdir => { optional
=> 1 },
120 fuse
=> { optional
=> 1 },
121 bwlimit
=> { optional
=> 1 },
122 maxfiles
=> { optional
=> 1 },
127 my ($class, $sectionId, $config, $create, $skipSchemaCheck) = @_;
129 $config->{path
} = "/mnt/pve/$sectionId" if $create && !$config->{path
};
131 return $class->SUPER::check_config
($sectionId, $config, $create, $skipSchemaCheck);
134 # Storage implementation
137 my ($class, $storeid, $scfg, %param) = @_;
139 return if defined($scfg->{monhost
}); # nothing to do if not pve managed ceph
141 PVE
::CephConfig
::ceph_create_keyfile
($scfg->{type
}, $storeid);
145 my ($class, $storeid, $scfg) = @_;
147 return if defined($scfg->{monhost
}); # nothing to do if not pve managed ceph
149 PVE
::CephConfig
::ceph_remove_keyfile
($scfg->{type
}, $storeid);
153 my ($class, $storeid, $scfg, $cache) = @_;
155 $cache->{mountdata
} //= PVE
::ProcFSTools
::parse_proc_mounts
();
157 return undef if !cephfs_is_mounted
($scfg, $storeid, $cache->{mountdata
});
159 return $class->SUPER::status
($storeid, $scfg, $cache);
162 sub activate_storage
{
163 my ($class, $storeid, $scfg, $cache) = @_;
165 $cache->{mountdata
} //= PVE
::ProcFSTools
::parse_proc_mounts
();
167 # NOTE: mkpath may hang if storage is mounted but not reachable
168 if (!cephfs_is_mounted
($scfg, $storeid, $cache->{mountdata
})) {
169 my $path = $scfg->{path
};
171 mkpath
$path if !(defined($scfg->{mkdir}) && !$scfg->{mkdir});
173 die "unable to activate storage '$storeid' - " .
174 "directory '$path' does not exist\n" if ! -d
$path;
176 cephfs_mount
($scfg, $storeid);
179 $class->SUPER::activate_storage
($storeid, $scfg, $cache);
182 sub deactivate_storage
{
183 my ($class, $storeid, $scfg, $cache) = @_;
185 $cache->{mountdata
} //= PVE
::ProcFSTools
::parse_proc_mounts
();
187 my $path = $scfg->{path
};
189 if (cephfs_is_mounted
($scfg, $storeid, $cache->{mountdata
})) {
190 run_command
(['/bin/umount', $path], errmsg
=> 'umount error');