]>
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";
89 file_set_contents
($unit_path, $unit);
90 run_command
(['systemctl', 'start', $unit_fn], errmsg
=> "mount error");
95 my ($scfg, $storeid) = @_;
97 my $mountpoint = $scfg->{path
};
98 my $subdir = $scfg->{subdir
} // '/';
100 my $cmd_option = PVE
::CephConfig
::ceph_connect_option
($scfg, $storeid);
101 my $configfile = $cmd_option->{ceph_conf
};
102 my $secretfile = $cmd_option->{keyring
};
103 my $server = $cmd_option->{mon_host
} // PVE
::CephConfig
::get_monaddr_list
($configfile);
109 push @opts, "ceph.id=$cmd_option->{userid}";
110 push @opts, "ceph.keyfile=$secretfile" if defined($secretfile);
111 push @opts, "ceph.conf=$configfile" if defined($configfile);
113 push @opts, "name=$cmd_option->{userid}";
114 push @opts, "secretfile=$secretfile" if defined($secretfile);
115 push @opts, "conf=$configfile" if defined($configfile);
118 push @opts, $scfg->{options
} if $scfg->{options
};
120 systemd_netmount
($mountpoint, $type, "$server:$subdir", join(',', @opts));
131 content
=> [ { vztmpl
=> 1, iso
=> 1, backup
=> 1, snippets
=> 1},
139 description
=> "Mount CephFS through FUSE.",
143 description
=> "Subdir to mount.",
144 type
=> 'string', format
=> 'pve-storage-path',
151 path
=> { fixed
=> 1 },
152 monhost
=> { optional
=> 1},
153 nodes
=> { optional
=> 1 },
154 subdir
=> { optional
=> 1 },
155 disable
=> { optional
=> 1 },
156 options
=> { optional
=> 1 },
157 username
=> { optional
=> 1 },
158 content
=> { optional
=> 1 },
159 format
=> { optional
=> 1 },
160 mkdir => { optional
=> 1 },
161 fuse
=> { optional
=> 1 },
162 bwlimit
=> { optional
=> 1 },
163 maxfiles
=> { optional
=> 1 },
168 my ($class, $sectionId, $config, $create, $skipSchemaCheck) = @_;
170 $config->{path
} = "/mnt/pve/$sectionId" if $create && !$config->{path
};
172 return $class->SUPER::check_config
($sectionId, $config, $create, $skipSchemaCheck);
175 # Storage implementation
178 my ($class, $storeid, $scfg, %param) = @_;
180 return if defined($scfg->{monhost
}); # nothing to do if not pve managed ceph
182 PVE
::CephConfig
::ceph_create_keyfile
($scfg->{type
}, $storeid);
186 my ($class, $storeid, $scfg) = @_;
188 return if defined($scfg->{monhost
}); # nothing to do if not pve managed ceph
190 PVE
::CephConfig
::ceph_remove_keyfile
($scfg->{type
}, $storeid);
194 my ($class, $storeid, $scfg, $cache) = @_;
196 $cache->{mountdata
} //= PVE
::ProcFSTools
::parse_proc_mounts
();
198 return undef if !cephfs_is_mounted
($scfg, $storeid, $cache->{mountdata
});
200 return $class->SUPER::status
($storeid, $scfg, $cache);
203 sub activate_storage
{
204 my ($class, $storeid, $scfg, $cache) = @_;
206 $cache->{mountdata
} //= PVE
::ProcFSTools
::parse_proc_mounts
();
208 # NOTE: mkpath may hang if storage is mounted but not reachable
209 if (!cephfs_is_mounted
($scfg, $storeid, $cache->{mountdata
})) {
210 my $path = $scfg->{path
};
212 mkpath
$path if !(defined($scfg->{mkdir}) && !$scfg->{mkdir});
214 die "unable to activate storage '$storeid' - " .
215 "directory '$path' does not exist\n" if ! -d
$path;
217 cephfs_mount
($scfg, $storeid);
220 $class->SUPER::activate_storage
($storeid, $scfg, $cache);
223 sub deactivate_storage
{
224 my ($class, $storeid, $scfg, $cache) = @_;
226 $cache->{mountdata
} //= PVE
::ProcFSTools
::parse_proc_mounts
();
228 my $path = $scfg->{path
};
230 if (cephfs_is_mounted
($scfg, $storeid, $cache->{mountdata
})) {
231 run_command
(['/bin/umount', $path], errmsg
=> 'umount error');