]>
git.proxmox.com Git - pve-storage.git/blob - PVE/Storage/CephFSPlugin.pm
f75c1b87189319126ed4eba45c6e97e0ea62d250
1 package PVE
::Storage
::CephFSPlugin
;
11 use PVE
::JSONSchema
qw(get_standard_option);
13 use PVE
::Storage
::Plugin
;
15 use PVE
::Tools
qw(run_command file_set_contents);
17 use base
qw(PVE::Storage::Plugin);
19 sub cephfs_is_mounted
{
20 my ($scfg, $storeid, $mountdata) = @_;
22 my $cmd_option = PVE
::CephConfig
::ceph_connect_option
($scfg, $storeid);
23 my $configfile = $cmd_option->{ceph_conf
};
25 my $subdir = $scfg->{subdir
} // '/';
26 my $mountpoint = $scfg->{path
};
28 $mountdata = PVE
::ProcFSTools
::parse_proc_mounts
() if !$mountdata;
29 return $mountpoint if grep {
30 $_->[2] =~ m
#^ceph|fuse\.ceph-fuse# &&
31 $_->[0] =~ m
#\Q:$subdir\E$|^ceph-fuse$# &&
32 $_->[1] eq $mountpoint
35 warn "A filesystem is already mounted on $mountpoint\n"
36 if grep { $_->[1] eq $mountpoint } @$mountdata;
41 # FIXME: remove once it's possible to specify _netdev for fuse.ceph mounts
42 sub systemd_netmount
{
43 my ($where, $type, $what, $opts) = @_;
45 # don't do default deps, systemd v241 generator produces ordering deps on both
46 # local-fs(-pre) and remote-fs(-pre) targets if we use the required _netdev
47 # option. Over three corners this gets us an ordering cycle on shutdown, which
48 # may make shutdown hang if the random cycle breaking hits the "wrong" unit to
53 DefaultDependencies=no
55 Wants=network-online.target
56 Before=umount.target remote-fs.target
57 After=systemd-journald.socket system.slice network.target -.mount remote-fs-pre.target network-online.target
58 Conflicts=umount.target
67 my $unit_fn = PVE
::Systemd
::escape_unit
($where, 1) . ".mount";
68 my $unit_path = "/run/systemd/system/$unit_fn";
69 my $daemon_needs_reload = -e
$unit_path;
71 file_set_contents
($unit_path, $unit);
73 run_command
(['systemctl', 'daemon-reload'], errmsg
=> "daemon-reload error")
74 if $daemon_needs_reload;
75 run_command
(['systemctl', 'start', $unit_fn], errmsg
=> "mount error");
80 my ($scfg, $storeid) = @_;
82 my $mountpoint = $scfg->{path
};
83 my $subdir = $scfg->{subdir
} // '/';
85 my $cmd_option = PVE
::CephConfig
::ceph_connect_option
($scfg, $storeid);
86 my $configfile = $cmd_option->{ceph_conf
};
87 my $secretfile = $cmd_option->{keyring
};
88 my $server = $cmd_option->{mon_host
} // PVE
::CephConfig
::get_monaddr_list
($configfile);
90 my $fs_name = $scfg->{'fs-name'};
95 push @opts, "ceph.id=$cmd_option->{userid}";
96 push @opts, "ceph.keyfile=$secretfile" if defined($secretfile);
97 push @opts, "ceph.conf=$configfile" if defined($configfile);
98 push @opts, "ceph.client_fs=$fs_name" if defined($fs_name);
100 push @opts, "name=$cmd_option->{userid}";
101 push @opts, "secretfile=$secretfile" if defined($secretfile);
102 push @opts, "conf=$configfile" if defined($configfile);
103 push @opts, "fs=$fs_name" if defined($fs_name);
106 push @opts, $scfg->{options
} if $scfg->{options
};
108 systemd_netmount
($mountpoint, $type, "$server:$subdir", join(',', @opts));
119 content
=> [ { vztmpl
=> 1, iso
=> 1, backup
=> 1, snippets
=> 1},
127 description
=> "Mount CephFS through FUSE.",
131 description
=> "Subdir to mount.",
132 type
=> 'string', format
=> 'pve-storage-path',
135 description
=> "The Ceph filesystem name.",
136 type
=> 'string', format
=> 'pve-configid',
143 path
=> { fixed
=> 1 },
144 monhost
=> { optional
=> 1},
145 nodes
=> { optional
=> 1 },
146 subdir
=> { optional
=> 1 },
147 disable
=> { optional
=> 1 },
148 options
=> { optional
=> 1 },
149 username
=> { optional
=> 1 },
150 content
=> { optional
=> 1 },
151 format
=> { optional
=> 1 },
152 mkdir => { optional
=> 1 },
153 fuse
=> { optional
=> 1 },
154 bwlimit
=> { optional
=> 1 },
155 maxfiles
=> { optional
=> 1 },
156 keyring
=> { optional
=> 1 },
157 'prune-backups' => { optional
=> 1 },
158 'fs-name' => { optional
=> 1 },
163 my ($class, $sectionId, $config, $create, $skipSchemaCheck) = @_;
165 $config->{path
} = "/mnt/pve/$sectionId" if $create && !$config->{path
};
167 return $class->SUPER::check_config
($sectionId, $config, $create, $skipSchemaCheck);
170 # Storage implementation
173 my ($class, $storeid, $scfg, %param) = @_;
175 my $secret = $param{keyring
} if defined $param{keyring
} // undef;
176 PVE
::CephConfig
::ceph_create_keyfile
($scfg->{type
}, $storeid, $secret);
182 my ($class, $storeid, $scfg, %param) = @_;
184 if (exists($param{keyring
})) {
185 if (defined($param{keyring
})) {
186 PVE
::CephConfig
::ceph_create_keyfile
($scfg->{type
}, $storeid, $param{keyring
});
188 PVE
::CephConfig
::ceph_remove_keyfile
($scfg->{type
}, $storeid);
196 my ($class, $storeid, $scfg) = @_;
197 PVE
::CephConfig
::ceph_remove_keyfile
($scfg->{type
}, $storeid);
202 my ($class, $storeid, $scfg, $cache) = @_;
204 $cache->{mountdata
} //= PVE
::ProcFSTools
::parse_proc_mounts
();
206 return undef if !cephfs_is_mounted
($scfg, $storeid, $cache->{mountdata
});
208 return $class->SUPER::status
($storeid, $scfg, $cache);
211 sub activate_storage
{
212 my ($class, $storeid, $scfg, $cache) = @_;
214 $cache->{mountdata
} //= PVE
::ProcFSTools
::parse_proc_mounts
();
216 # NOTE: mkpath may hang if storage is mounted but not reachable
217 if (!cephfs_is_mounted
($scfg, $storeid, $cache->{mountdata
})) {
218 my $path = $scfg->{path
};
220 mkpath
$path if !(defined($scfg->{mkdir}) && !$scfg->{mkdir});
222 die "unable to activate storage '$storeid' - " .
223 "directory '$path' does not exist\n" if ! -d
$path;
225 cephfs_mount
($scfg, $storeid);
228 $class->SUPER::activate_storage
($storeid, $scfg, $cache);
231 sub deactivate_storage
{
232 my ($class, $storeid, $scfg, $cache) = @_;
234 $cache->{mountdata
} //= PVE
::ProcFSTools
::parse_proc_mounts
();
236 my $path = $scfg->{path
};
238 if (cephfs_is_mounted
($scfg, $storeid, $cache->{mountdata
})) {
239 run_command
(['/bin/umount', $path], errmsg
=> 'umount error');
243 # FIXME remove on the next APIAGE reset.
244 # Deprecated, use get_volume_attribute instead.
245 sub get_volume_notes
{
247 PVE
::Storage
::DirPlugin
::get_volume_notes
($class, @_);
250 # FIXME remove on the next APIAGE reset.
251 # Deprecated, use update_volume_attribute instead.
252 sub update_volume_notes
{
254 PVE
::Storage
::DirPlugin
::update_volume_notes
($class, @_);
257 sub get_volume_attribute
{
258 return PVE
::Storage
::DirPlugin
::get_volume_attribute
(@_);
261 sub update_volume_attribute
{
262 return PVE
::Storage
::DirPlugin
::update_volume_attribute
(@_);