]>
git.proxmox.com Git - pve-storage.git/blob - PVE/Storage/CephFSPlugin.pm
1 package PVE
::Storage
::CephFSPlugin
;
10 use PVE
::Tools
qw(run_command file_set_contents);
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
};
24 my $subdir = $scfg->{subdir
} // '/';
25 my $mountpoint = $scfg->{path
};
27 $mountdata = PVE
::ProcFSTools
::parse_proc_mounts
() if !$mountdata;
28 return $mountpoint if grep {
29 $_->[2] =~ m
#^ceph|fuse\.ceph-fuse# &&
30 $_->[0] =~ m
#\Q:$subdir\E$|^ceph-fuse$# &&
31 $_->[1] eq $mountpoint
34 warn "A filesystem is already mounted on $mountpoint\n"
35 if grep { $_->[1] eq $mountpoint } @$mountdata;
41 # FIXME: duplicate of api/diskmanage one, move to common helper (pve-common's
44 my ($val, $is_path) = @_;
46 # NOTE: this is not complete, but enough for our needs. normally all
47 # characters which are not alpha-numerical, '.' or '_' would need escaping
59 # FIXME: remove in PVE 7.0 where systemd is recent enough to not have those
60 # local-fs/remote-fs dependency cycles generated for _netdev mounts...
61 sub systemd_netmount
{
62 my ($where, $type, $what, $opts) = @_;
64 # don't do default deps, systemd v241 generator produces ordering deps on both
65 # local-fs(-pre) and remote-fs(-pre) targets if we use the required _netdev
66 # option. Over thre corners this gets us an ordering cycle on shutdown, which
67 # may make shutdown hang if the random cycle breaking hits the "wrong" unit to
72 DefaultDependencies=no
74 Wants=network-online.target
75 Before=umount.target remote-fs.target
76 After=systemd-journald.socket system.slice network.target -.mount remote-fs-pre.target network-online.target
77 Conflicts=umount.target
86 my $unit_fn = systemd_escape
($where, 1) . ".mount";
87 my $unit_path = "/run/systemd/system/$unit_fn";
88 my $daemon_needs_reload = -e
$unit_path;
90 file_set_contents
($unit_path, $unit);
92 run_command
(['systemctl', 'daemon-reload'], errmsg
=> "daemon-reload error")
93 if $daemon_needs_reload;
94 run_command
(['systemctl', 'start', $unit_fn], errmsg
=> "mount error");
99 my ($scfg, $storeid) = @_;
101 my $mountpoint = $scfg->{path
};
102 my $subdir = $scfg->{subdir
} // '/';
104 my $cmd_option = PVE
::CephConfig
::ceph_connect_option
($scfg, $storeid);
105 my $configfile = $cmd_option->{ceph_conf
};
106 my $secretfile = $cmd_option->{keyring
};
107 my $server = $cmd_option->{mon_host
} // PVE
::CephConfig
::get_monaddr_list
($configfile);
113 push @opts, "ceph.id=$cmd_option->{userid}";
114 push @opts, "ceph.keyfile=$secretfile" if defined($secretfile);
115 push @opts, "ceph.conf=$configfile" if defined($configfile);
117 push @opts, "name=$cmd_option->{userid}";
118 push @opts, "secretfile=$secretfile" if defined($secretfile);
119 push @opts, "conf=$configfile" if defined($configfile);
122 push @opts, $scfg->{options
} if $scfg->{options
};
124 systemd_netmount
($mountpoint, $type, "$server:$subdir", join(',', @opts));
135 content
=> [ { vztmpl
=> 1, iso
=> 1, backup
=> 1, snippets
=> 1},
143 description
=> "Mount CephFS through FUSE.",
147 description
=> "Subdir to mount.",
148 type
=> 'string', format
=> 'pve-storage-path',
155 path
=> { fixed
=> 1 },
156 monhost
=> { optional
=> 1},
157 nodes
=> { optional
=> 1 },
158 subdir
=> { optional
=> 1 },
159 disable
=> { optional
=> 1 },
160 options
=> { optional
=> 1 },
161 username
=> { optional
=> 1 },
162 content
=> { optional
=> 1 },
163 format
=> { optional
=> 1 },
164 mkdir => { optional
=> 1 },
165 fuse
=> { optional
=> 1 },
166 bwlimit
=> { optional
=> 1 },
167 maxfiles
=> { optional
=> 1 },
172 my ($class, $sectionId, $config, $create, $skipSchemaCheck) = @_;
174 $config->{path
} = "/mnt/pve/$sectionId" if $create && !$config->{path
};
176 return $class->SUPER::check_config
($sectionId, $config, $create, $skipSchemaCheck);
179 # Storage implementation
182 my ($class, $storeid, $scfg, %param) = @_;
184 return if defined($scfg->{monhost
}); # nothing to do if not pve managed ceph
186 PVE
::CephConfig
::ceph_create_keyfile
($scfg->{type
}, $storeid);
190 my ($class, $storeid, $scfg) = @_;
192 return if defined($scfg->{monhost
}); # nothing to do if not pve managed ceph
194 PVE
::CephConfig
::ceph_remove_keyfile
($scfg->{type
}, $storeid);
198 my ($class, $storeid, $scfg, $cache) = @_;
200 $cache->{mountdata
} //= PVE
::ProcFSTools
::parse_proc_mounts
();
202 return undef if !cephfs_is_mounted
($scfg, $storeid, $cache->{mountdata
});
204 return $class->SUPER::status
($storeid, $scfg, $cache);
207 sub activate_storage
{
208 my ($class, $storeid, $scfg, $cache) = @_;
210 $cache->{mountdata
} //= PVE
::ProcFSTools
::parse_proc_mounts
();
212 # NOTE: mkpath may hang if storage is mounted but not reachable
213 if (!cephfs_is_mounted
($scfg, $storeid, $cache->{mountdata
})) {
214 my $path = $scfg->{path
};
216 mkpath
$path if !(defined($scfg->{mkdir}) && !$scfg->{mkdir});
218 die "unable to activate storage '$storeid' - " .
219 "directory '$path' does not exist\n" if ! -d
$path;
221 cephfs_mount
($scfg, $storeid);
224 $class->SUPER::activate_storage
($storeid, $scfg, $cache);
227 sub deactivate_storage
{
228 my ($class, $storeid, $scfg, $cache) = @_;
230 $cache->{mountdata
} //= PVE
::ProcFSTools
::parse_proc_mounts
();
232 my $path = $scfg->{path
};
234 if (cephfs_is_mounted
($scfg, $storeid, $cache->{mountdata
})) {
235 run_command
(['/bin/umount', $path], errmsg
=> 'umount error');