]>
git.proxmox.com Git - pve-storage.git/blob - PVE/Storage/CephFSPlugin.pm
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 in PVE 7.0 where systemd is recent enough to not have those
42 # local-fs/remote-fs dependency cycles generated for _netdev mounts...
43 sub systemd_netmount
{
44 my ($where, $type, $what, $opts) = @_;
46 # don't do default deps, systemd v241 generator produces ordering deps on both
47 # local-fs(-pre) and remote-fs(-pre) targets if we use the required _netdev
48 # option. Over thre corners this gets us an ordering cycle on shutdown, which
49 # may make shutdown hang if the random cycle breaking hits the "wrong" unit to
54 DefaultDependencies=no
56 Wants=network-online.target
57 Before=umount.target remote-fs.target
58 After=systemd-journald.socket system.slice network.target -.mount remote-fs-pre.target network-online.target
59 Conflicts=umount.target
68 my $unit_fn = PVE
::Systemd
::escape_unit
($where, 1) . ".mount";
69 my $unit_path = "/run/systemd/system/$unit_fn";
70 my $daemon_needs_reload = -e
$unit_path;
72 file_set_contents
($unit_path, $unit);
74 run_command
(['systemctl', 'daemon-reload'], errmsg
=> "daemon-reload error")
75 if $daemon_needs_reload;
76 run_command
(['systemctl', 'start', $unit_fn], errmsg
=> "mount error");
81 my ($scfg, $storeid) = @_;
83 my $mountpoint = $scfg->{path
};
84 my $subdir = $scfg->{subdir
} // '/';
86 my $cmd_option = PVE
::CephConfig
::ceph_connect_option
($scfg, $storeid);
87 my $configfile = $cmd_option->{ceph_conf
};
88 my $secretfile = $cmd_option->{keyring
};
89 my $server = $cmd_option->{mon_host
} // PVE
::CephConfig
::get_monaddr_list
($configfile);
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);
99 push @opts, "name=$cmd_option->{userid}";
100 push @opts, "secretfile=$secretfile" if defined($secretfile);
102 # FIXME: remove version check in PVE 7.0, only needed for Luminous -> Nautilus
103 my ($subversions) = PVE
::CephConfig
::local_ceph_version
();
104 push @opts, "conf=$configfile" if defined($configfile) && @$subversions[0] > 12;
107 push @opts, $scfg->{options
} if $scfg->{options
};
109 systemd_netmount
($mountpoint, $type, "$server:$subdir", join(',', @opts));
120 content
=> [ { vztmpl
=> 1, iso
=> 1, backup
=> 1, snippets
=> 1},
128 description
=> "Mount CephFS through FUSE.",
132 description
=> "Subdir to mount.",
133 type
=> 'string', format
=> 'pve-storage-path',
140 path
=> { fixed
=> 1 },
141 monhost
=> { optional
=> 1},
142 nodes
=> { optional
=> 1 },
143 subdir
=> { optional
=> 1 },
144 disable
=> { optional
=> 1 },
145 options
=> { optional
=> 1 },
146 username
=> { optional
=> 1 },
147 content
=> { optional
=> 1 },
148 format
=> { optional
=> 1 },
149 mkdir => { optional
=> 1 },
150 fuse
=> { optional
=> 1 },
151 bwlimit
=> { optional
=> 1 },
152 maxfiles
=> { optional
=> 1 },
153 'prune-backups' => { optional
=> 1 },
158 my ($class, $sectionId, $config, $create, $skipSchemaCheck) = @_;
160 $config->{path
} = "/mnt/pve/$sectionId" if $create && !$config->{path
};
162 return $class->SUPER::check_config
($sectionId, $config, $create, $skipSchemaCheck);
165 # Storage implementation
168 my ($class, $storeid, $scfg, %param) = @_;
170 return if defined($scfg->{monhost
}); # nothing to do if not pve managed ceph
172 PVE
::CephConfig
::ceph_create_keyfile
($scfg->{type
}, $storeid);
178 my ($class, $storeid, $scfg) = @_;
180 return if defined($scfg->{monhost
}); # nothing to do if not pve managed ceph
182 PVE
::CephConfig
::ceph_remove_keyfile
($scfg->{type
}, $storeid);
188 my ($class, $storeid, $scfg, $cache) = @_;
190 $cache->{mountdata
} //= PVE
::ProcFSTools
::parse_proc_mounts
();
192 return undef if !cephfs_is_mounted
($scfg, $storeid, $cache->{mountdata
});
194 return $class->SUPER::status
($storeid, $scfg, $cache);
197 sub activate_storage
{
198 my ($class, $storeid, $scfg, $cache) = @_;
200 $cache->{mountdata
} //= PVE
::ProcFSTools
::parse_proc_mounts
();
202 # NOTE: mkpath may hang if storage is mounted but not reachable
203 if (!cephfs_is_mounted
($scfg, $storeid, $cache->{mountdata
})) {
204 my $path = $scfg->{path
};
206 mkpath
$path if !(defined($scfg->{mkdir}) && !$scfg->{mkdir});
208 die "unable to activate storage '$storeid' - " .
209 "directory '$path' does not exist\n" if ! -d
$path;
211 cephfs_mount
($scfg, $storeid);
214 $class->SUPER::activate_storage
($storeid, $scfg, $cache);
217 sub deactivate_storage
{
218 my ($class, $storeid, $scfg, $cache) = @_;
220 $cache->{mountdata
} //= PVE
::ProcFSTools
::parse_proc_mounts
();
222 my $path = $scfg->{path
};
224 if (cephfs_is_mounted
($scfg, $storeid, $cache->{mountdata
})) {
225 run_command
(['/bin/umount', $path], errmsg
=> 'umount error');
229 sub get_volume_notes
{
231 PVE
::Storage
::DirPlugin
::get_volume_notes
($class, @_);
234 sub update_volume_notes
{
236 PVE
::Storage
::DirPlugin
::update_volume_notes
($class, @_);