]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | /* | |
4 | * Ceph - scalable distributed file system | |
5 | * | |
6 | * Copyright (C) 2017 Red Hat Ltd | |
7 | * | |
8 | * This is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU Lesser General Public | |
10 | * License version 2.1, as published by the Free Software | |
11 | * Foundation. See file COPYING. | |
12 | * | |
13 | */ | |
14 | ||
15 | ||
16 | #include "OSDMonitor.h" | |
7c673cae FG |
17 | |
18 | #include "FSCommands.h" | |
19 | #include "MDSMonitor.h" | |
11fdf7f2 | 20 | #include "MgrStatMonitor.h" |
f67539c2 | 21 | #include "mds/cephfs_features.h" |
7c673cae | 22 | |
9f95a23c | 23 | using TOPNSPC::common::cmd_getval; |
7c673cae | 24 | |
f67539c2 TL |
25 | using std::dec; |
26 | using std::hex; | |
27 | using std::list; | |
28 | using std::map; | |
29 | using std::make_pair; | |
30 | using std::ostream; | |
31 | using std::ostringstream; | |
32 | using std::pair; | |
33 | using std::set; | |
34 | using std::string; | |
35 | using std::stringstream; | |
36 | using std::to_string; | |
37 | using std::vector; | |
38 | ||
39 | using ceph::bufferlist; | |
40 | using ceph::decode; | |
41 | using ceph::encode; | |
42 | using ceph::ErasureCodeInterfaceRef; | |
43 | using ceph::ErasureCodeProfile; | |
44 | using ceph::Formatter; | |
45 | using ceph::JSONFormatter; | |
46 | using ceph::make_message; | |
47 | using ceph::mono_clock; | |
48 | using ceph::mono_time; | |
7c673cae FG |
49 | |
50 | class FlagSetHandler : public FileSystemCommandHandler | |
51 | { | |
52 | public: | |
53 | FlagSetHandler() | |
54 | : FileSystemCommandHandler("fs flag set") | |
55 | { | |
56 | } | |
57 | ||
58 | int handle( | |
59 | Monitor *mon, | |
f67539c2 | 60 | FSMap& fsmap, |
7c673cae | 61 | MonOpRequestRef op, |
11fdf7f2 | 62 | const cmdmap_t& cmdmap, |
7c673cae FG |
63 | std::stringstream &ss) override |
64 | { | |
65 | string flag_name; | |
9f95a23c | 66 | cmd_getval(cmdmap, "flag_name", flag_name); |
7c673cae FG |
67 | |
68 | string flag_val; | |
9f95a23c | 69 | cmd_getval(cmdmap, "val", flag_val); |
7c673cae | 70 | |
11fdf7f2 | 71 | bool sure = false; |
9f95a23c | 72 | cmd_getval(cmdmap, "yes_i_really_mean_it", sure); |
7c673cae FG |
73 | |
74 | if (flag_name == "enable_multiple") { | |
75 | bool flag_bool = false; | |
76 | int r = parse_bool(flag_val, &flag_bool, ss); | |
77 | if (r != 0) { | |
78 | ss << "Invalid boolean value '" << flag_val << "'"; | |
79 | return r; | |
80 | } | |
81 | ||
7c673cae FG |
82 | fsmap.set_enable_multiple(flag_bool); |
83 | return 0; | |
84 | } else { | |
85 | ss << "Unknown flag '" << flag_name << "'"; | |
86 | return -EINVAL; | |
87 | } | |
88 | } | |
89 | }; | |
90 | ||
11fdf7f2 TL |
91 | class FailHandler : public FileSystemCommandHandler |
92 | { | |
93 | public: | |
94 | FailHandler() | |
95 | : FileSystemCommandHandler("fs fail") | |
96 | { | |
97 | } | |
98 | ||
99 | int handle( | |
100 | Monitor* mon, | |
101 | FSMap& fsmap, | |
102 | MonOpRequestRef op, | |
103 | const cmdmap_t& cmdmap, | |
104 | std::stringstream& ss) override | |
105 | { | |
106 | if (!mon->osdmon()->is_writeable()) { | |
107 | // not allowed to write yet, so retry when we can | |
108 | mon->osdmon()->wait_for_writeable(op, new PaxosService::C_RetryMessage(mon->mdsmon(), op)); | |
109 | return -EAGAIN; | |
110 | } | |
111 | ||
112 | std::string fs_name; | |
9f95a23c | 113 | if (!cmd_getval(cmdmap, "fs_name", fs_name) || fs_name.empty()) { |
11fdf7f2 TL |
114 | ss << "Missing filesystem name"; |
115 | return -EINVAL; | |
116 | } | |
117 | ||
118 | auto fs = fsmap.get_filesystem(fs_name); | |
11fdf7f2 TL |
119 | |
120 | auto f = [](auto fs) { | |
121 | fs->mds_map.set_flag(CEPH_MDSMAP_NOT_JOINABLE); | |
122 | }; | |
123 | fsmap.modify_filesystem(fs->fscid, std::move(f)); | |
124 | ||
125 | std::vector<mds_gid_t> to_fail; | |
126 | for (const auto& p : fs->mds_map.get_mds_info()) { | |
127 | to_fail.push_back(p.first); | |
128 | } | |
129 | ||
130 | for (const auto& gid : to_fail) { | |
131 | mon->mdsmon()->fail_mds_gid(fsmap, gid); | |
132 | } | |
133 | if (!to_fail.empty()) { | |
134 | mon->osdmon()->propose_pending(); | |
135 | } | |
136 | ||
137 | ss << fs_name; | |
138 | ss << " marked not joinable; MDS cannot join the cluster. All MDS ranks marked failed."; | |
139 | ||
140 | return 0; | |
141 | } | |
142 | }; | |
143 | ||
7c673cae FG |
144 | class FsNewHandler : public FileSystemCommandHandler |
145 | { | |
146 | public: | |
11fdf7f2 | 147 | explicit FsNewHandler(Paxos *paxos) |
c07f9fc5 | 148 | : FileSystemCommandHandler("fs new"), m_paxos(paxos) |
7c673cae FG |
149 | { |
150 | } | |
151 | ||
c07f9fc5 FG |
152 | bool batched_propose() override { |
153 | return true; | |
154 | } | |
155 | ||
7c673cae FG |
156 | int handle( |
157 | Monitor *mon, | |
f67539c2 | 158 | FSMap& fsmap, |
7c673cae | 159 | MonOpRequestRef op, |
11fdf7f2 | 160 | const cmdmap_t& cmdmap, |
31f18b77 | 161 | std::stringstream &ss) override |
7c673cae | 162 | { |
11fdf7f2 | 163 | ceph_assert(m_paxos->is_plugged()); |
c07f9fc5 | 164 | |
7c673cae | 165 | string metadata_name; |
9f95a23c | 166 | cmd_getval(cmdmap, "metadata", metadata_name); |
7c673cae FG |
167 | int64_t metadata = mon->osdmon()->osdmap.lookup_pg_pool_name(metadata_name); |
168 | if (metadata < 0) { | |
169 | ss << "pool '" << metadata_name << "' does not exist"; | |
170 | return -ENOENT; | |
171 | } | |
172 | ||
7c673cae | 173 | string data_name; |
9f95a23c | 174 | cmd_getval(cmdmap, "data", data_name); |
7c673cae FG |
175 | int64_t data = mon->osdmon()->osdmap.lookup_pg_pool_name(data_name); |
176 | if (data < 0) { | |
177 | ss << "pool '" << data_name << "' does not exist"; | |
178 | return -ENOENT; | |
179 | } | |
180 | if (data == 0) { | |
181 | ss << "pool '" << data_name << "' has id 0, which CephFS does not allow. Use another pool or recreate it to get a non-zero pool id."; | |
182 | return -EINVAL; | |
183 | } | |
c07f9fc5 | 184 | |
7c673cae | 185 | string fs_name; |
9f95a23c | 186 | cmd_getval(cmdmap, "fs_name", fs_name); |
7c673cae FG |
187 | if (fs_name.empty()) { |
188 | // Ensure fs name is not empty so that we can implement | |
189 | // commmands that refer to FS by name in future. | |
190 | ss << "Filesystem name may not be empty"; | |
191 | return -EINVAL; | |
192 | } | |
193 | ||
194 | if (fsmap.get_filesystem(fs_name)) { | |
195 | auto fs = fsmap.get_filesystem(fs_name); | |
196 | if (*(fs->mds_map.get_data_pools().begin()) == data | |
197 | && fs->mds_map.get_metadata_pool() == metadata) { | |
198 | // Identical FS created already, this is a no-op | |
199 | ss << "filesystem '" << fs_name << "' already exists"; | |
200 | return 0; | |
201 | } else { | |
202 | ss << "filesystem already exists with name '" << fs_name << "'"; | |
203 | return -EINVAL; | |
204 | } | |
205 | } | |
206 | ||
11fdf7f2 | 207 | bool force = false; |
9f95a23c | 208 | cmd_getval(cmdmap, "force", force); |
11fdf7f2 TL |
209 | |
210 | const pool_stat_t *stat = mon->mgrstatmon()->get_pool_stat(metadata); | |
211 | if (stat) { | |
212 | int64_t metadata_num_objects = stat->stats.sum.num_objects; | |
213 | if (!force && metadata_num_objects > 0) { | |
214 | ss << "pool '" << metadata_name | |
215 | << "' already contains some objects. Use an empty pool instead."; | |
216 | return -EINVAL; | |
217 | } | |
218 | } | |
219 | ||
7c673cae FG |
220 | if (fsmap.filesystem_count() > 0 |
221 | && !fsmap.get_enable_multiple()) { | |
222 | ss << "Creation of multiple filesystems is disabled. To enable " | |
223 | "this experimental feature, use 'ceph fs flag set enable_multiple " | |
224 | "true'"; | |
225 | return -EINVAL; | |
226 | } | |
227 | ||
11fdf7f2 | 228 | for (auto& fs : fsmap.get_filesystems()) { |
31f18b77 | 229 | const std::vector<int64_t> &data_pools = fs->mds_map.get_data_pools(); |
11fdf7f2 TL |
230 | |
231 | bool sure = false; | |
9f95a23c | 232 | cmd_getval(cmdmap, |
11fdf7f2 TL |
233 | "allow_dangerous_metadata_overlay", sure); |
234 | ||
31f18b77 | 235 | if ((std::find(data_pools.begin(), data_pools.end(), data) != data_pools.end() |
7c673cae | 236 | || fs->mds_map.get_metadata_pool() == metadata) |
11fdf7f2 | 237 | && !sure) { |
7c673cae FG |
238 | ss << "Filesystem '" << fs_name |
239 | << "' is already using one of the specified RADOS pools. This should ONLY be done in emergencies and after careful reading of the documentation. Pass --allow-dangerous-metadata-overlay to permit this."; | |
240 | return -EEXIST; | |
241 | } | |
242 | } | |
243 | ||
244 | pg_pool_t const *data_pool = mon->osdmon()->osdmap.get_pg_pool(data); | |
11fdf7f2 | 245 | ceph_assert(data_pool != NULL); // Checked it existed above |
7c673cae | 246 | pg_pool_t const *metadata_pool = mon->osdmon()->osdmap.get_pg_pool(metadata); |
11fdf7f2 | 247 | ceph_assert(metadata_pool != NULL); // Checked it existed above |
7c673cae | 248 | |
92f5a8d4 | 249 | int r = _check_pool(mon->osdmon()->osdmap, data, POOL_DATA_DEFAULT, force, &ss); |
7c673cae FG |
250 | if (r < 0) { |
251 | return r; | |
252 | } | |
253 | ||
92f5a8d4 | 254 | r = _check_pool(mon->osdmon()->osdmap, metadata, POOL_METADATA, force, &ss); |
7c673cae FG |
255 | if (r < 0) { |
256 | return r; | |
257 | } | |
35e4c445 | 258 | |
11fdf7f2 TL |
259 | if (!mon->osdmon()->is_writeable()) { |
260 | // not allowed to write yet, so retry when we can | |
261 | mon->osdmon()->wait_for_writeable(op, new PaxosService::C_RetryMessage(mon->mdsmon(), op)); | |
262 | return -EAGAIN; | |
35e4c445 | 263 | } |
11fdf7f2 TL |
264 | mon->osdmon()->do_application_enable(data, |
265 | pg_pool_t::APPLICATION_NAME_CEPHFS, | |
1911f103 | 266 | "data", fs_name, true); |
11fdf7f2 TL |
267 | mon->osdmon()->do_application_enable(metadata, |
268 | pg_pool_t::APPLICATION_NAME_CEPHFS, | |
1911f103 | 269 | "metadata", fs_name, true); |
494da23a TL |
270 | mon->osdmon()->do_set_pool_opt(metadata, |
271 | pool_opts_t::RECOVERY_PRIORITY, | |
272 | static_cast<int64_t>(5)); | |
273 | mon->osdmon()->do_set_pool_opt(metadata, | |
274 | pool_opts_t::PG_NUM_MIN, | |
275 | static_cast<int64_t>(16)); | |
276 | mon->osdmon()->do_set_pool_opt(metadata, | |
277 | pool_opts_t::PG_AUTOSCALE_BIAS, | |
278 | static_cast<double>(4.0)); | |
11fdf7f2 | 279 | mon->osdmon()->propose_pending(); |
c07f9fc5 | 280 | |
7c673cae | 281 | // All checks passed, go ahead and create. |
11fdf7f2 TL |
282 | auto&& fs = fsmap.create_filesystem(fs_name, metadata, data, |
283 | mon->get_quorum_con_features()); | |
284 | ||
7c673cae | 285 | ss << "new fs with metadata pool " << metadata << " and data pool " << data; |
11fdf7f2 TL |
286 | |
287 | // assign a standby to rank 0 to avoid health warnings | |
9f95a23c | 288 | auto info = fsmap.find_replacement_for({fs->fscid, 0}); |
11fdf7f2 | 289 | |
9f95a23c TL |
290 | if (info) { |
291 | mon->clog->info() << info->human_name() << " assigned to filesystem " | |
11fdf7f2 | 292 | << fs_name << " as rank 0"; |
9f95a23c | 293 | fsmap.promote(info->global_id, *fs, 0); |
11fdf7f2 TL |
294 | } |
295 | ||
7c673cae FG |
296 | return 0; |
297 | } | |
c07f9fc5 FG |
298 | |
299 | private: | |
300 | Paxos *m_paxos; | |
7c673cae FG |
301 | }; |
302 | ||
303 | class SetHandler : public FileSystemCommandHandler | |
304 | { | |
305 | public: | |
306 | SetHandler() | |
307 | : FileSystemCommandHandler("fs set") | |
308 | {} | |
309 | ||
310 | int handle( | |
311 | Monitor *mon, | |
f67539c2 | 312 | FSMap& fsmap, |
7c673cae | 313 | MonOpRequestRef op, |
11fdf7f2 | 314 | const cmdmap_t& cmdmap, |
7c673cae FG |
315 | std::stringstream &ss) override |
316 | { | |
317 | std::string fs_name; | |
9f95a23c | 318 | if (!cmd_getval(cmdmap, "fs_name", fs_name) || fs_name.empty()) { |
7c673cae FG |
319 | ss << "Missing filesystem name"; |
320 | return -EINVAL; | |
321 | } | |
322 | ||
323 | auto fs = fsmap.get_filesystem(fs_name); | |
7c673cae | 324 | string var; |
9f95a23c | 325 | if (!cmd_getval(cmdmap, "var", var) || var.empty()) { |
7c673cae FG |
326 | ss << "Invalid variable"; |
327 | return -EINVAL; | |
328 | } | |
329 | string val; | |
330 | string interr; | |
331 | int64_t n = 0; | |
9f95a23c | 332 | if (!cmd_getval(cmdmap, "val", val)) { |
7c673cae FG |
333 | return -EINVAL; |
334 | } | |
335 | // we got a string. see if it contains an int. | |
336 | n = strict_strtoll(val.c_str(), 10, &interr); | |
337 | if (var == "max_mds") { | |
338 | // NOTE: see also "mds set_max_mds", which can modify the same field. | |
339 | if (interr.length()) { | |
340 | ss << interr; | |
341 | return -EINVAL; | |
342 | } | |
343 | ||
344 | if (n <= 0) { | |
345 | ss << "You must specify at least one MDS"; | |
346 | return -EINVAL; | |
347 | } | |
f67539c2 | 348 | |
11fdf7f2 TL |
349 | if (n > 1 && n > fs->mds_map.get_max_mds()) { |
350 | if (fs->mds_map.was_snaps_ever_allowed() && | |
351 | !fs->mds_map.allows_multimds_snaps()) { | |
352 | ss << "multi-active MDS is not allowed while there are snapshots possibly created by pre-mimic MDS"; | |
353 | return -EINVAL; | |
354 | } | |
7c673cae FG |
355 | } |
356 | if (n > MAX_MDS) { | |
357 | ss << "may not have more than " << MAX_MDS << " MDS ranks"; | |
358 | return -EINVAL; | |
359 | } | |
11fdf7f2 | 360 | |
7c673cae FG |
361 | fsmap.modify_filesystem( |
362 | fs->fscid, | |
363 | [n](std::shared_ptr<Filesystem> fs) | |
364 | { | |
11fdf7f2 | 365 | fs->mds_map.clear_flag(CEPH_MDSMAP_NOT_JOINABLE); |
7c673cae FG |
366 | fs->mds_map.set_max_mds(n); |
367 | }); | |
368 | } else if (var == "inline_data") { | |
369 | bool enable_inline = false; | |
370 | int r = parse_bool(val, &enable_inline, ss); | |
371 | if (r != 0) { | |
372 | return r; | |
373 | } | |
374 | ||
375 | if (enable_inline) { | |
11fdf7f2 | 376 | bool confirm = false; |
9f95a23c | 377 | cmd_getval(cmdmap, "yes_i_really_really_mean_it", confirm); |
11fdf7f2 | 378 | if (!confirm) { |
9f95a23c TL |
379 | ss << "Inline data support is deprecated and will be removed in a future release. " |
380 | << "Add --yes-i-really-really-mean-it if you are certain you want this enabled."; | |
7c673cae FG |
381 | return -EPERM; |
382 | } | |
383 | ss << "inline data enabled"; | |
384 | ||
385 | fsmap.modify_filesystem( | |
386 | fs->fscid, | |
387 | [](std::shared_ptr<Filesystem> fs) | |
388 | { | |
389 | fs->mds_map.set_inline_data_enabled(true); | |
390 | }); | |
391 | ||
392 | // Update `compat` | |
393 | CompatSet c = fsmap.get_compat(); | |
394 | c.incompat.insert(MDS_FEATURE_INCOMPAT_INLINE); | |
395 | fsmap.update_compat(c); | |
396 | } else { | |
397 | ss << "inline data disabled"; | |
398 | fsmap.modify_filesystem( | |
399 | fs->fscid, | |
400 | [](std::shared_ptr<Filesystem> fs) | |
401 | { | |
402 | fs->mds_map.set_inline_data_enabled(false); | |
403 | }); | |
404 | } | |
405 | } else if (var == "balancer") { | |
31f18b77 FG |
406 | if (val.empty()) { |
407 | ss << "unsetting the metadata load balancer"; | |
408 | } else { | |
409 | ss << "setting the metadata load balancer to " << val; | |
410 | } | |
411 | fsmap.modify_filesystem( | |
412 | fs->fscid, | |
413 | [val](std::shared_ptr<Filesystem> fs) | |
7c673cae FG |
414 | { |
415 | fs->mds_map.set_balancer(val); | |
416 | }); | |
417 | return true; | |
418 | } else if (var == "max_file_size") { | |
419 | if (interr.length()) { | |
420 | ss << var << " requires an integer value"; | |
421 | return -EINVAL; | |
422 | } | |
423 | if (n < CEPH_MIN_STRIPE_UNIT) { | |
424 | ss << var << " must at least " << CEPH_MIN_STRIPE_UNIT; | |
425 | return -ERANGE; | |
426 | } | |
427 | fsmap.modify_filesystem( | |
428 | fs->fscid, | |
429 | [n](std::shared_ptr<Filesystem> fs) | |
430 | { | |
431 | fs->mds_map.set_max_filesize(n); | |
432 | }); | |
433 | } else if (var == "allow_new_snaps") { | |
434 | bool enable_snaps = false; | |
435 | int r = parse_bool(val, &enable_snaps, ss); | |
436 | if (r != 0) { | |
437 | return r; | |
438 | } | |
439 | ||
440 | if (!enable_snaps) { | |
441 | fsmap.modify_filesystem( | |
442 | fs->fscid, | |
443 | [](std::shared_ptr<Filesystem> fs) | |
444 | { | |
445 | fs->mds_map.clear_snaps_allowed(); | |
446 | }); | |
447 | ss << "disabled new snapshots"; | |
448 | } else { | |
7c673cae FG |
449 | fsmap.modify_filesystem( |
450 | fs->fscid, | |
451 | [](std::shared_ptr<Filesystem> fs) | |
452 | { | |
453 | fs->mds_map.set_snaps_allowed(); | |
454 | }); | |
455 | ss << "enabled new snapshots"; | |
456 | } | |
457 | } else if (var == "allow_multimds") { | |
11fdf7f2 TL |
458 | ss << "Multiple MDS is always enabled. Use the max_mds" |
459 | << " parameter to control the number of active MDSs" | |
460 | << " allowed. This command is DEPRECATED and will be" | |
461 | << " REMOVED from future releases."; | |
462 | } else if (var == "allow_multimds_snaps") { | |
463 | bool enable = false; | |
464 | int r = parse_bool(val, &enable, ss); | |
7c673cae | 465 | if (r != 0) { |
11fdf7f2 | 466 | return r; |
7c673cae FG |
467 | } |
468 | ||
11fdf7f2 | 469 | string confirm; |
9f95a23c | 470 | if (!cmd_getval(cmdmap, "confirm", confirm) || |
11fdf7f2 TL |
471 | confirm != "--yes-i-am-really-a-mds") { |
472 | ss << "Warning! This command is for MDS only. Do not run it manually"; | |
473 | return -EPERM; | |
474 | } | |
475 | ||
476 | if (enable) { | |
477 | ss << "enabled multimds with snapshot"; | |
7c673cae FG |
478 | fsmap.modify_filesystem( |
479 | fs->fscid, | |
480 | [](std::shared_ptr<Filesystem> fs) | |
481 | { | |
11fdf7f2 | 482 | fs->mds_map.set_multimds_snaps_allowed(); |
7c673cae | 483 | }); |
7c673cae | 484 | } else { |
11fdf7f2 | 485 | ss << "disabled multimds with snapshot"; |
7c673cae FG |
486 | fsmap.modify_filesystem( |
487 | fs->fscid, | |
488 | [](std::shared_ptr<Filesystem> fs) | |
489 | { | |
11fdf7f2 | 490 | fs->mds_map.clear_multimds_snaps_allowed(); |
7c673cae | 491 | }); |
7c673cae | 492 | } |
11fdf7f2 TL |
493 | } else if (var == "allow_dirfrags") { |
494 | ss << "Directory fragmentation is now permanently enabled." | |
495 | << " This command is DEPRECATED and will be REMOVED from future releases."; | |
496 | } else if (var == "down") { | |
7c673cae FG |
497 | bool is_down = false; |
498 | int r = parse_bool(val, &is_down, ss); | |
499 | if (r != 0) { | |
500 | return r; | |
501 | } | |
502 | ||
11fdf7f2 TL |
503 | ss << fs->mds_map.get_fs_name(); |
504 | ||
7c673cae FG |
505 | fsmap.modify_filesystem( |
506 | fs->fscid, | |
507 | [is_down](std::shared_ptr<Filesystem> fs) | |
508 | { | |
11fdf7f2 TL |
509 | if (is_down) { |
510 | if (fs->mds_map.get_max_mds() > 0) { | |
511 | fs->mds_map.set_old_max_mds(); | |
512 | fs->mds_map.set_max_mds(0); | |
513 | } /* else already down! */ | |
514 | } else { | |
515 | mds_rank_t oldmax = fs->mds_map.get_old_max_mds(); | |
516 | fs->mds_map.set_max_mds(oldmax ? oldmax : 1); | |
517 | } | |
518 | }); | |
519 | ||
520 | if (is_down) { | |
521 | ss << " marked down. "; | |
522 | } else { | |
523 | ss << " marked up, max_mds = " << fs->mds_map.get_max_mds(); | |
524 | } | |
525 | } else if (var == "cluster_down" || var == "joinable") { | |
526 | bool joinable = true; | |
527 | int r = parse_bool(val, &joinable, ss); | |
528 | if (r != 0) { | |
529 | return r; | |
530 | } | |
531 | if (var == "cluster_down") { | |
532 | joinable = !joinable; | |
533 | } | |
534 | ||
535 | ss << fs->mds_map.get_fs_name(); | |
536 | ||
537 | fsmap.modify_filesystem( | |
538 | fs->fscid, | |
539 | [joinable](std::shared_ptr<Filesystem> fs) | |
540 | { | |
541 | if (joinable) { | |
542 | fs->mds_map.clear_flag(CEPH_MDSMAP_NOT_JOINABLE); | |
543 | } else { | |
544 | fs->mds_map.set_flag(CEPH_MDSMAP_NOT_JOINABLE); | |
545 | } | |
7c673cae FG |
546 | }); |
547 | ||
11fdf7f2 TL |
548 | if (joinable) { |
549 | ss << " marked joinable; MDS may join as newly active."; | |
550 | } else { | |
551 | ss << " marked not joinable; MDS cannot join as newly active."; | |
552 | } | |
553 | ||
554 | if (var == "cluster_down") { | |
555 | ss << " WARNING: cluster_down flag is deprecated and will be" | |
556 | << " removed in a future version. Please use \"joinable\"."; | |
557 | } | |
7c673cae FG |
558 | } else if (var == "standby_count_wanted") { |
559 | if (interr.length()) { | |
560 | ss << var << " requires an integer value"; | |
561 | return -EINVAL; | |
562 | } | |
563 | if (n < 0) { | |
564 | ss << var << " must be non-negative"; | |
565 | return -ERANGE; | |
566 | } | |
567 | fsmap.modify_filesystem( | |
568 | fs->fscid, | |
569 | [n](std::shared_ptr<Filesystem> fs) | |
570 | { | |
571 | fs->mds_map.set_standby_count_wanted(n); | |
572 | }); | |
f64942e4 AA |
573 | } else if (var == "session_timeout") { |
574 | if (interr.length()) { | |
575 | ss << var << " requires an integer value"; | |
576 | return -EINVAL; | |
577 | } | |
578 | if (n < 30) { | |
579 | ss << var << " must be at least 30s"; | |
580 | return -ERANGE; | |
581 | } | |
582 | fsmap.modify_filesystem( | |
583 | fs->fscid, | |
584 | [n](std::shared_ptr<Filesystem> fs) | |
585 | { | |
586 | fs->mds_map.set_session_timeout((uint32_t)n); | |
587 | }); | |
588 | } else if (var == "session_autoclose") { | |
589 | if (interr.length()) { | |
590 | ss << var << " requires an integer value"; | |
591 | return -EINVAL; | |
592 | } | |
593 | if (n < 30) { | |
594 | ss << var << " must be at least 30s"; | |
595 | return -ERANGE; | |
596 | } | |
597 | fsmap.modify_filesystem( | |
598 | fs->fscid, | |
599 | [n](std::shared_ptr<Filesystem> fs) | |
600 | { | |
601 | fs->mds_map.set_session_autoclose((uint32_t)n); | |
602 | }); | |
11fdf7f2 TL |
603 | } else if (var == "allow_standby_replay") { |
604 | bool allow = false; | |
605 | int r = parse_bool(val, &allow, ss); | |
606 | if (r != 0) { | |
607 | return r; | |
608 | } | |
609 | ||
f67539c2 TL |
610 | if (!allow) { |
611 | if (!mon->osdmon()->is_writeable()) { | |
612 | // not allowed to write yet, so retry when we can | |
613 | mon->osdmon()->wait_for_writeable(op, new PaxosService::C_RetryMessage(mon->mdsmon(), op)); | |
614 | return -EAGAIN; | |
615 | } | |
616 | std::vector<mds_gid_t> to_fail; | |
617 | for (const auto& [gid, info]: fs->mds_map.get_mds_info()) { | |
618 | if (info.state == MDSMap::STATE_STANDBY_REPLAY) { | |
619 | to_fail.push_back(gid); | |
620 | } | |
621 | } | |
622 | ||
623 | for (const auto& gid : to_fail) { | |
624 | mon->mdsmon()->fail_mds_gid(fsmap, gid); | |
625 | } | |
626 | if (!to_fail.empty()) { | |
627 | mon->osdmon()->propose_pending(); | |
628 | } | |
629 | } | |
630 | ||
11fdf7f2 TL |
631 | auto f = [allow](auto& fs) { |
632 | if (allow) { | |
633 | fs->mds_map.set_standby_replay_allowed(); | |
634 | } else { | |
635 | fs->mds_map.clear_standby_replay_allowed(); | |
636 | } | |
637 | }; | |
638 | fsmap.modify_filesystem(fs->fscid, std::move(f)); | |
639 | } else if (var == "min_compat_client") { | |
9f95a23c TL |
640 | auto vno = ceph_release_from_name(val.c_str()); |
641 | if (!vno) { | |
11fdf7f2 TL |
642 | ss << "version " << val << " is not recognized"; |
643 | return -EINVAL; | |
644 | } | |
b3b6e05e TL |
645 | ss << "WARNING: setting min_compat_client is deprecated" |
646 | " and may not do what you want.\n" | |
647 | "The oldest release to set is octopus.\n" | |
648 | "Please migrate to `ceph fs required_client_features ...`."; | |
9f95a23c TL |
649 | auto f = [vno](auto&& fs) { |
650 | fs->mds_map.set_min_compat_client(vno); | |
651 | }; | |
652 | fsmap.modify_filesystem(fs->fscid, std::move(f)); | |
7c673cae FG |
653 | } else { |
654 | ss << "unknown variable " << var; | |
655 | return -EINVAL; | |
656 | } | |
657 | ||
658 | return 0; | |
659 | } | |
660 | }; | |
661 | ||
f67539c2 TL |
662 | class RequiredClientFeaturesHandler : public FileSystemCommandHandler |
663 | { | |
664 | public: | |
665 | RequiredClientFeaturesHandler() | |
666 | : FileSystemCommandHandler("fs required_client_features") | |
667 | { | |
668 | } | |
669 | ||
670 | int handle( | |
671 | Monitor *mon, | |
672 | FSMap &fsmap, | |
673 | MonOpRequestRef op, | |
674 | const cmdmap_t& cmdmap, | |
675 | std::stringstream &ss) override | |
676 | { | |
677 | std::string fs_name; | |
678 | if (!cmd_getval(cmdmap, "fs_name", fs_name) || fs_name.empty()) { | |
679 | ss << "Missing filesystem name"; | |
680 | return -EINVAL; | |
681 | } | |
682 | auto fs = fsmap.get_filesystem(fs_name); | |
683 | if (fs == nullptr) { | |
684 | ss << "Not found: '" << fs_name << "'"; | |
685 | return -ENOENT; | |
686 | } | |
687 | string subop; | |
688 | if (!cmd_getval(cmdmap, "subop", subop) || | |
689 | (subop != "add" && subop != "rm")) { | |
690 | ss << "Must either add or rm a feature; " << subop << " is not recognized"; | |
691 | return -EINVAL; | |
692 | } | |
693 | string val; | |
694 | if (!cmd_getval(cmdmap, "val", val) || val.empty()) { | |
695 | ss << "Missing feature id/name"; | |
696 | return -EINVAL; | |
697 | } | |
698 | ||
699 | int feature = cephfs_feature_from_name(val); | |
700 | if (feature < 0) { | |
701 | string err; | |
702 | feature = strict_strtol(val.c_str(), 10, &err); | |
703 | if (err.length()) { | |
704 | ss << "Invalid feature name: " << val; | |
705 | return -EINVAL; | |
706 | } | |
707 | if (feature < 0 || feature > CEPHFS_FEATURE_MAX) { | |
708 | ss << "Invalid feature id: " << feature; | |
709 | return -EINVAL; | |
710 | } | |
711 | } | |
712 | ||
713 | if (subop == "add") { | |
714 | bool ret = false; | |
715 | fsmap.modify_filesystem( | |
716 | fs->fscid, | |
717 | [feature, &ret](auto&& fs) | |
718 | { | |
719 | if (fs->mds_map.get_required_client_features().test(feature)) | |
720 | return; | |
721 | fs->mds_map.add_required_client_feature(feature); | |
722 | ret = true; | |
723 | }); | |
724 | if (ret) { | |
725 | ss << "added feature '" << cephfs_feature_name(feature) << "' to required_client_features"; | |
726 | } else { | |
727 | ss << "feature '" << cephfs_feature_name(feature) << "' is already set"; | |
728 | } | |
729 | } else { | |
730 | bool ret = false; | |
731 | fsmap.modify_filesystem( | |
732 | fs->fscid, | |
733 | [feature, &ret](auto&& fs) | |
734 | { | |
735 | if (!fs->mds_map.get_required_client_features().test(feature)) | |
736 | return; | |
737 | fs->mds_map.remove_required_client_feature(feature); | |
738 | ret = true; | |
739 | }); | |
740 | if (ret) { | |
741 | ss << "removed feature '" << cephfs_feature_name(feature) << "' from required_client_features"; | |
742 | } else { | |
743 | ss << "feature '" << cephfs_feature_name(feature) << "' is already unset"; | |
744 | } | |
745 | } | |
746 | return 0; | |
747 | } | |
748 | }; | |
749 | ||
750 | ||
7c673cae FG |
751 | class AddDataPoolHandler : public FileSystemCommandHandler |
752 | { | |
753 | public: | |
11fdf7f2 | 754 | explicit AddDataPoolHandler(Paxos *paxos) |
c07f9fc5 | 755 | : FileSystemCommandHandler("fs add_data_pool"), m_paxos(paxos) |
7c673cae FG |
756 | {} |
757 | ||
c07f9fc5 FG |
758 | bool batched_propose() override { |
759 | return true; | |
760 | } | |
761 | ||
7c673cae FG |
762 | int handle( |
763 | Monitor *mon, | |
f67539c2 | 764 | FSMap& fsmap, |
7c673cae | 765 | MonOpRequestRef op, |
11fdf7f2 | 766 | const cmdmap_t& cmdmap, |
7c673cae FG |
767 | std::stringstream &ss) override |
768 | { | |
11fdf7f2 | 769 | ceph_assert(m_paxos->is_plugged()); |
c07f9fc5 | 770 | |
7c673cae | 771 | string poolname; |
9f95a23c | 772 | cmd_getval(cmdmap, "pool", poolname); |
7c673cae FG |
773 | |
774 | std::string fs_name; | |
9f95a23c | 775 | if (!cmd_getval(cmdmap, "fs_name", fs_name) |
7c673cae FG |
776 | || fs_name.empty()) { |
777 | ss << "Missing filesystem name"; | |
778 | return -EINVAL; | |
779 | } | |
780 | ||
7c673cae FG |
781 | int64_t poolid = mon->osdmon()->osdmap.lookup_pg_pool_name(poolname); |
782 | if (poolid < 0) { | |
783 | string err; | |
784 | poolid = strict_strtol(poolname.c_str(), 10, &err); | |
785 | if (err.length()) { | |
786 | ss << "pool '" << poolname << "' does not exist"; | |
787 | return -ENOENT; | |
788 | } | |
789 | } | |
790 | ||
92f5a8d4 | 791 | int r = _check_pool(mon->osdmon()->osdmap, poolid, POOL_DATA_EXTRA, false, &ss); |
7c673cae FG |
792 | if (r != 0) { |
793 | return r; | |
794 | } | |
795 | ||
f67539c2 | 796 | auto fs = fsmap.get_filesystem(fs_name); |
31f18b77 FG |
797 | // no-op when the data_pool already on fs |
798 | if (fs->mds_map.is_data_pool(poolid)) { | |
799 | ss << "data pool " << poolid << " is already on fs " << fs_name; | |
800 | return 0; | |
801 | } | |
802 | ||
11fdf7f2 TL |
803 | if (!mon->osdmon()->is_writeable()) { |
804 | // not allowed to write yet, so retry when we can | |
805 | mon->osdmon()->wait_for_writeable(op, new PaxosService::C_RetryMessage(mon->mdsmon(), op)); | |
806 | return -EAGAIN; | |
b5b8bbf5 | 807 | } |
11fdf7f2 TL |
808 | mon->osdmon()->do_application_enable(poolid, |
809 | pg_pool_t::APPLICATION_NAME_CEPHFS, | |
1911f103 | 810 | "data", fs_name, true); |
11fdf7f2 | 811 | mon->osdmon()->propose_pending(); |
c07f9fc5 | 812 | |
7c673cae FG |
813 | fsmap.modify_filesystem( |
814 | fs->fscid, | |
815 | [poolid](std::shared_ptr<Filesystem> fs) | |
816 | { | |
817 | fs->mds_map.add_data_pool(poolid); | |
818 | }); | |
819 | ||
820 | ss << "added data pool " << poolid << " to fsmap"; | |
821 | ||
822 | return 0; | |
823 | } | |
c07f9fc5 FG |
824 | |
825 | private: | |
826 | Paxos *m_paxos; | |
7c673cae FG |
827 | }; |
828 | ||
829 | class SetDefaultHandler : public FileSystemCommandHandler | |
830 | { | |
831 | public: | |
832 | SetDefaultHandler() | |
833 | : FileSystemCommandHandler("fs set-default") | |
834 | {} | |
835 | ||
836 | int handle( | |
837 | Monitor *mon, | |
f67539c2 | 838 | FSMap& fsmap, |
7c673cae | 839 | MonOpRequestRef op, |
11fdf7f2 | 840 | const cmdmap_t& cmdmap, |
7c673cae FG |
841 | std::stringstream &ss) override |
842 | { | |
843 | std::string fs_name; | |
9f95a23c | 844 | cmd_getval(cmdmap, "fs_name", fs_name); |
7c673cae FG |
845 | auto fs = fsmap.get_filesystem(fs_name); |
846 | if (fs == nullptr) { | |
847 | ss << "filesystem '" << fs_name << "' does not exist"; | |
848 | return -ENOENT; | |
849 | } | |
850 | ||
851 | fsmap.set_legacy_client_fscid(fs->fscid); | |
852 | return 0; | |
853 | } | |
854 | }; | |
855 | ||
856 | class RemoveFilesystemHandler : public FileSystemCommandHandler | |
857 | { | |
858 | public: | |
859 | RemoveFilesystemHandler() | |
860 | : FileSystemCommandHandler("fs rm") | |
861 | {} | |
862 | ||
863 | int handle( | |
864 | Monitor *mon, | |
f67539c2 | 865 | FSMap& fsmap, |
7c673cae | 866 | MonOpRequestRef op, |
11fdf7f2 | 867 | const cmdmap_t& cmdmap, |
7c673cae FG |
868 | std::stringstream &ss) override |
869 | { | |
f67539c2 | 870 | /* We may need to blocklist ranks. */ |
a8e16298 TL |
871 | if (!mon->osdmon()->is_writeable()) { |
872 | // not allowed to write yet, so retry when we can | |
873 | mon->osdmon()->wait_for_writeable(op, new PaxosService::C_RetryMessage(mon->mdsmon(), op)); | |
874 | return -EAGAIN; | |
875 | } | |
876 | ||
7c673cae FG |
877 | // Check caller has correctly named the FS to delete |
878 | // (redundant while there is only one FS, but command | |
879 | // syntax should apply to multi-FS future) | |
880 | string fs_name; | |
9f95a23c | 881 | cmd_getval(cmdmap, "fs_name", fs_name); |
7c673cae FG |
882 | auto fs = fsmap.get_filesystem(fs_name); |
883 | if (fs == nullptr) { | |
884 | // Consider absence success to make deletes idempotent | |
885 | ss << "filesystem '" << fs_name << "' does not exist"; | |
886 | return 0; | |
887 | } | |
888 | ||
889 | // Check that no MDS daemons are active | |
890 | if (fs->mds_map.get_num_up_mds() > 0) { | |
11fdf7f2 | 891 | ss << "all MDS daemons must be inactive/failed before removing filesystem. See `ceph fs fail`."; |
7c673cae FG |
892 | return -EINVAL; |
893 | } | |
894 | ||
895 | // Check for confirmation flag | |
11fdf7f2 | 896 | bool sure = false; |
9f95a23c | 897 | cmd_getval(cmdmap, "yes_i_really_mean_it", sure); |
11fdf7f2 | 898 | if (!sure) { |
7c673cae FG |
899 | ss << "this is a DESTRUCTIVE operation and will make data in your filesystem permanently" \ |
900 | " inaccessible. Add --yes-i-really-mean-it if you are sure you wish to continue."; | |
901 | return -EPERM; | |
902 | } | |
903 | ||
904 | if (fsmap.get_legacy_client_fscid() == fs->fscid) { | |
905 | fsmap.set_legacy_client_fscid(FS_CLUSTER_ID_NONE); | |
906 | } | |
907 | ||
908 | std::vector<mds_gid_t> to_fail; | |
909 | // There may be standby_replay daemons left here | |
910 | for (const auto &i : fs->mds_map.get_mds_info()) { | |
11fdf7f2 | 911 | ceph_assert(i.second.state == MDSMap::STATE_STANDBY_REPLAY); |
7c673cae FG |
912 | to_fail.push_back(i.first); |
913 | } | |
914 | ||
915 | for (const auto &gid : to_fail) { | |
916 | // Standby replays don't write, so it isn't important to | |
917 | // wait for an osdmap propose here: ignore return value. | |
1adf2230 | 918 | mon->mdsmon()->fail_mds_gid(fsmap, gid); |
7c673cae | 919 | } |
a8e16298 | 920 | if (!to_fail.empty()) { |
f67539c2 | 921 | mon->osdmon()->propose_pending(); /* maybe new blocklists */ |
a8e16298 | 922 | } |
7c673cae FG |
923 | |
924 | fsmap.erase_filesystem(fs->fscid); | |
925 | ||
926 | return 0; | |
927 | } | |
928 | }; | |
929 | ||
930 | class ResetFilesystemHandler : public FileSystemCommandHandler | |
931 | { | |
932 | public: | |
933 | ResetFilesystemHandler() | |
934 | : FileSystemCommandHandler("fs reset") | |
935 | {} | |
936 | ||
937 | int handle( | |
938 | Monitor *mon, | |
f67539c2 | 939 | FSMap& fsmap, |
7c673cae | 940 | MonOpRequestRef op, |
11fdf7f2 | 941 | const cmdmap_t& cmdmap, |
7c673cae FG |
942 | std::stringstream &ss) override |
943 | { | |
944 | string fs_name; | |
9f95a23c | 945 | cmd_getval(cmdmap, "fs_name", fs_name); |
7c673cae FG |
946 | auto fs = fsmap.get_filesystem(fs_name); |
947 | if (fs == nullptr) { | |
948 | ss << "filesystem '" << fs_name << "' does not exist"; | |
949 | // Unlike fs rm, we consider this case an error | |
950 | return -ENOENT; | |
951 | } | |
952 | ||
953 | // Check that no MDS daemons are active | |
954 | if (fs->mds_map.get_num_up_mds() > 0) { | |
955 | ss << "all MDS daemons must be inactive before resetting filesystem: set the cluster_down flag" | |
956 | " and use `ceph mds fail` to make this so"; | |
957 | return -EINVAL; | |
958 | } | |
959 | ||
960 | // Check for confirmation flag | |
11fdf7f2 | 961 | bool sure = false; |
9f95a23c | 962 | cmd_getval(cmdmap, "yes_i_really_mean_it", sure); |
11fdf7f2 | 963 | if (!sure) { |
7c673cae FG |
964 | ss << "this is a potentially destructive operation, only for use by experts in disaster recovery. " |
965 | "Add --yes-i-really-mean-it if you are sure you wish to continue."; | |
966 | return -EPERM; | |
967 | } | |
968 | ||
969 | fsmap.reset_filesystem(fs->fscid); | |
970 | ||
971 | return 0; | |
972 | } | |
973 | }; | |
974 | ||
975 | class RemoveDataPoolHandler : public FileSystemCommandHandler | |
976 | { | |
977 | public: | |
978 | RemoveDataPoolHandler() | |
979 | : FileSystemCommandHandler("fs rm_data_pool") | |
980 | {} | |
981 | ||
982 | int handle( | |
983 | Monitor *mon, | |
f67539c2 | 984 | FSMap& fsmap, |
7c673cae | 985 | MonOpRequestRef op, |
11fdf7f2 | 986 | const cmdmap_t& cmdmap, |
7c673cae FG |
987 | std::stringstream &ss) override |
988 | { | |
989 | string poolname; | |
9f95a23c | 990 | cmd_getval(cmdmap, "pool", poolname); |
7c673cae FG |
991 | |
992 | std::string fs_name; | |
9f95a23c | 993 | if (!cmd_getval(cmdmap, "fs_name", fs_name) |
7c673cae FG |
994 | || fs_name.empty()) { |
995 | ss << "Missing filesystem name"; | |
996 | return -EINVAL; | |
997 | } | |
998 | ||
7c673cae FG |
999 | int64_t poolid = mon->osdmon()->osdmap.lookup_pg_pool_name(poolname); |
1000 | if (poolid < 0) { | |
1001 | string err; | |
1002 | poolid = strict_strtol(poolname.c_str(), 10, &err); | |
1003 | if (err.length()) { | |
1004 | ss << "pool '" << poolname << "' does not exist"; | |
1005 | return -ENOENT; | |
1006 | } else if (poolid < 0) { | |
1007 | ss << "invalid pool id '" << poolid << "'"; | |
1008 | return -EINVAL; | |
1009 | } | |
1010 | } | |
1011 | ||
11fdf7f2 | 1012 | ceph_assert(poolid >= 0); // Checked by parsing code above |
7c673cae | 1013 | |
f67539c2 | 1014 | auto fs = fsmap.get_filesystem(fs_name); |
7c673cae FG |
1015 | if (fs->mds_map.get_first_data_pool() == poolid) { |
1016 | ss << "cannot remove default data pool"; | |
1017 | return -EINVAL; | |
1018 | } | |
1019 | ||
7c673cae FG |
1020 | int r = 0; |
1021 | fsmap.modify_filesystem(fs->fscid, | |
1022 | [&r, poolid](std::shared_ptr<Filesystem> fs) | |
1023 | { | |
1024 | r = fs->mds_map.remove_data_pool(poolid); | |
1025 | }); | |
1026 | if (r == -ENOENT) { | |
1027 | // It was already removed, succeed in silence | |
1028 | return 0; | |
1029 | } else if (r == 0) { | |
1030 | // We removed it, succeed | |
1031 | ss << "removed data pool " << poolid << " from fsmap"; | |
1032 | return 0; | |
1033 | } else { | |
1034 | // Unexpected error, bubble up | |
1035 | return r; | |
1036 | } | |
1037 | } | |
1038 | }; | |
1039 | ||
7c673cae FG |
1040 | /** |
1041 | * For commands with an alternative prefix | |
1042 | */ | |
1043 | template<typename T> | |
1044 | class AliasHandler : public T | |
1045 | { | |
1046 | std::string alias_prefix; | |
1047 | ||
1048 | public: | |
11fdf7f2 | 1049 | explicit AliasHandler(const std::string &new_prefix) |
7c673cae FG |
1050 | : T() |
1051 | { | |
1052 | alias_prefix = new_prefix; | |
1053 | } | |
1054 | ||
f67539c2 | 1055 | std::string const &get_prefix() const override {return alias_prefix;} |
7c673cae FG |
1056 | |
1057 | int handle( | |
1058 | Monitor *mon, | |
f67539c2 | 1059 | FSMap& fsmap, |
7c673cae | 1060 | MonOpRequestRef op, |
11fdf7f2 | 1061 | const cmdmap_t& cmdmap, |
7c673cae FG |
1062 | std::stringstream &ss) override |
1063 | { | |
1064 | return T::handle(mon, fsmap, op, cmdmap, ss); | |
1065 | } | |
1066 | }; | |
1067 | ||
f67539c2 TL |
1068 | class MirrorHandlerEnable : public FileSystemCommandHandler |
1069 | { | |
1070 | public: | |
1071 | MirrorHandlerEnable() | |
1072 | : FileSystemCommandHandler("fs mirror enable") | |
1073 | {} | |
1074 | ||
1075 | int handle(Monitor *mon, | |
1076 | FSMap &fsmap, MonOpRequestRef op, | |
1077 | const cmdmap_t& cmdmap, std::stringstream &ss) override { | |
1078 | std::string fs_name; | |
1079 | if (!cmd_getval(cmdmap, "fs_name", fs_name) || fs_name.empty()) { | |
1080 | ss << "Missing filesystem name"; | |
1081 | return -EINVAL; | |
1082 | } | |
1083 | ||
1084 | auto fs = fsmap.get_filesystem(fs_name); | |
1085 | if (fs == nullptr) { | |
1086 | ss << "Filesystem '" << fs_name << "' not found"; | |
1087 | return -ENOENT; | |
1088 | } | |
1089 | ||
1090 | if (fs->mirror_info.is_mirrored()) { | |
1091 | return 0; | |
1092 | } | |
1093 | ||
1094 | auto f = [](auto &&fs) { | |
1095 | fs->mirror_info.enable_mirroring(); | |
1096 | }; | |
1097 | fsmap.modify_filesystem(fs->fscid, std::move(f)); | |
1098 | ||
1099 | return 0; | |
1100 | } | |
1101 | }; | |
1102 | ||
1103 | class MirrorHandlerDisable : public FileSystemCommandHandler | |
1104 | { | |
1105 | public: | |
1106 | MirrorHandlerDisable() | |
1107 | : FileSystemCommandHandler("fs mirror disable") | |
1108 | {} | |
1109 | ||
1110 | int handle(Monitor *mon, | |
1111 | FSMap &fsmap, MonOpRequestRef op, | |
1112 | const cmdmap_t& cmdmap, std::stringstream &ss) override { | |
1113 | std::string fs_name; | |
1114 | if (!cmd_getval(cmdmap, "fs_name", fs_name) || fs_name.empty()) { | |
1115 | ss << "Missing filesystem name"; | |
1116 | return -EINVAL; | |
1117 | } | |
1118 | ||
1119 | auto fs = fsmap.get_filesystem(fs_name); | |
1120 | if (fs == nullptr) { | |
1121 | ss << "Filesystem '" << fs_name << "' not found"; | |
1122 | return -ENOENT; | |
1123 | } | |
1124 | ||
1125 | if (!fs->mirror_info.is_mirrored()) { | |
1126 | return 0; | |
1127 | } | |
1128 | ||
1129 | auto f = [](auto &&fs) { | |
1130 | fs->mirror_info.disable_mirroring(); | |
1131 | }; | |
1132 | fsmap.modify_filesystem(fs->fscid, std::move(f)); | |
1133 | ||
1134 | return 0; | |
1135 | } | |
1136 | }; | |
1137 | ||
1138 | class MirrorHandlerAddPeer : public FileSystemCommandHandler | |
1139 | { | |
1140 | public: | |
1141 | MirrorHandlerAddPeer() | |
1142 | : FileSystemCommandHandler("fs mirror peer_add") | |
1143 | {} | |
1144 | ||
1145 | boost::optional<std::pair<string, string>> | |
1146 | extract_remote_cluster_conf(const std::string &spec) { | |
1147 | auto pos = spec.find("@"); | |
1148 | if (pos == std::string_view::npos) { | |
1149 | return boost::optional<std::pair<string, string>>(); | |
1150 | } | |
1151 | ||
1152 | auto client = spec.substr(0, pos); | |
1153 | auto cluster = spec.substr(pos+1); | |
1154 | ||
1155 | return std::make_pair(client, cluster); | |
1156 | } | |
1157 | ||
1158 | bool peer_add(FSMap &fsmap, Filesystem::const_ref &&fs, | |
1159 | const cmdmap_t &cmdmap, std::stringstream &ss) { | |
1160 | string peer_uuid; | |
1161 | string remote_spec; | |
1162 | string remote_fs_name; | |
1163 | cmd_getval(cmdmap, "uuid", peer_uuid); | |
1164 | cmd_getval(cmdmap, "remote_cluster_spec", remote_spec); | |
1165 | cmd_getval(cmdmap, "remote_fs_name", remote_fs_name); | |
1166 | ||
1167 | // verify (and extract) remote cluster specification | |
1168 | auto remote_conf = extract_remote_cluster_conf(remote_spec); | |
1169 | if (!remote_conf) { | |
1170 | ss << "invalid remote cluster spec -- should be <client>@<cluster>"; | |
1171 | return false; | |
1172 | } | |
1173 | ||
1174 | if (fs->mirror_info.has_peer(peer_uuid)) { | |
1175 | ss << "peer already exists"; | |
1176 | return true; | |
1177 | } | |
1178 | if (fs->mirror_info.has_peer((*remote_conf).first, (*remote_conf).second, | |
1179 | remote_fs_name)) { | |
1180 | ss << "peer already exists"; | |
1181 | return true; | |
1182 | } | |
1183 | ||
1184 | auto f = [peer_uuid, remote_conf, remote_fs_name](auto &&fs) { | |
1185 | fs->mirror_info.peer_add(peer_uuid, (*remote_conf).first, | |
1186 | (*remote_conf).second, remote_fs_name); | |
1187 | }; | |
1188 | fsmap.modify_filesystem(fs->fscid, std::move(f)); | |
1189 | return true; | |
1190 | } | |
1191 | ||
1192 | int handle(Monitor *mon, | |
1193 | FSMap &fsmap, MonOpRequestRef op, | |
1194 | const cmdmap_t& cmdmap, std::stringstream &ss) override { | |
1195 | std::string fs_name; | |
1196 | if (!cmd_getval(cmdmap, "fs_name", fs_name) || fs_name.empty()) { | |
1197 | ss << "Missing filesystem name"; | |
1198 | return -EINVAL; | |
1199 | } | |
1200 | ||
1201 | auto fs = fsmap.get_filesystem(fs_name); | |
1202 | if (fs == nullptr) { | |
1203 | ss << "Filesystem '" << fs_name << "' not found"; | |
1204 | return -ENOENT; | |
1205 | } | |
1206 | ||
1207 | if (!fs->mirror_info.is_mirrored()) { | |
1208 | ss << "Mirroring not enabled for filesystem '" << fs_name << "'"; | |
1209 | return -EINVAL; | |
1210 | } | |
1211 | ||
1212 | auto res = peer_add(fsmap, std::move(fs), cmdmap, ss); | |
1213 | if (!res) { | |
1214 | return -EINVAL; | |
1215 | } | |
1216 | ||
1217 | return 0; | |
1218 | } | |
1219 | }; | |
1220 | ||
1221 | class MirrorHandlerRemovePeer : public FileSystemCommandHandler | |
1222 | { | |
1223 | public: | |
1224 | MirrorHandlerRemovePeer() | |
1225 | : FileSystemCommandHandler("fs mirror peer_remove") | |
1226 | {} | |
1227 | ||
1228 | bool peer_remove(FSMap &fsmap, Filesystem::const_ref &&fs, | |
1229 | const cmdmap_t &cmdmap, std::stringstream &ss) { | |
1230 | string peer_uuid; | |
1231 | cmd_getval(cmdmap, "uuid", peer_uuid); | |
1232 | ||
1233 | if (!fs->mirror_info.has_peer(peer_uuid)) { | |
1234 | ss << "cannot find peer with uuid: " << peer_uuid; | |
1235 | return true; | |
1236 | } | |
1237 | ||
1238 | auto f = [peer_uuid](auto &&fs) { | |
1239 | fs->mirror_info.peer_remove(peer_uuid); | |
1240 | }; | |
1241 | fsmap.modify_filesystem(fs->fscid, std::move(f)); | |
1242 | return true; | |
1243 | } | |
1244 | ||
1245 | int handle(Monitor *mon, | |
1246 | FSMap &fsmap, MonOpRequestRef op, | |
1247 | const cmdmap_t& cmdmap, std::stringstream &ss) override { | |
1248 | std::string fs_name; | |
1249 | if (!cmd_getval(cmdmap, "fs_name", fs_name) || fs_name.empty()) { | |
1250 | ss << "Missing filesystem name"; | |
1251 | return -EINVAL; | |
1252 | } | |
1253 | ||
1254 | auto fs = fsmap.get_filesystem(fs_name); | |
1255 | if (fs == nullptr) { | |
1256 | ss << "Filesystem '" << fs_name << "' not found"; | |
1257 | return -ENOENT; | |
1258 | } | |
1259 | ||
1260 | if (!fs->mirror_info.is_mirrored()) { | |
1261 | ss << "Mirroring not enabled for filesystem '" << fs_name << "'"; | |
1262 | return -EINVAL; | |
1263 | } | |
1264 | ||
1265 | auto res = peer_remove(fsmap, std::move(fs), cmdmap, ss); | |
1266 | if (!res) { | |
1267 | return -EINVAL; | |
1268 | } | |
1269 | ||
1270 | return 0; | |
1271 | } | |
1272 | }; | |
7c673cae | 1273 | |
c07f9fc5 FG |
1274 | std::list<std::shared_ptr<FileSystemCommandHandler> > |
1275 | FileSystemCommandHandler::load(Paxos *paxos) | |
7c673cae FG |
1276 | { |
1277 | std::list<std::shared_ptr<FileSystemCommandHandler> > handlers; | |
1278 | ||
1279 | handlers.push_back(std::make_shared<SetHandler>()); | |
11fdf7f2 | 1280 | handlers.push_back(std::make_shared<FailHandler>()); |
7c673cae | 1281 | handlers.push_back(std::make_shared<FlagSetHandler>()); |
f67539c2 | 1282 | handlers.push_back(std::make_shared<RequiredClientFeaturesHandler>()); |
c07f9fc5 | 1283 | handlers.push_back(std::make_shared<AddDataPoolHandler>(paxos)); |
7c673cae | 1284 | handlers.push_back(std::make_shared<RemoveDataPoolHandler>()); |
c07f9fc5 | 1285 | handlers.push_back(std::make_shared<FsNewHandler>(paxos)); |
7c673cae FG |
1286 | handlers.push_back(std::make_shared<RemoveFilesystemHandler>()); |
1287 | handlers.push_back(std::make_shared<ResetFilesystemHandler>()); | |
1288 | ||
1289 | handlers.push_back(std::make_shared<SetDefaultHandler>()); | |
1290 | handlers.push_back(std::make_shared<AliasHandler<SetDefaultHandler> >( | |
1291 | "fs set_default")); | |
f67539c2 TL |
1292 | handlers.push_back(std::make_shared<MirrorHandlerEnable>()); |
1293 | handlers.push_back(std::make_shared<MirrorHandlerDisable>()); | |
1294 | handlers.push_back(std::make_shared<MirrorHandlerAddPeer>()); | |
1295 | handlers.push_back(std::make_shared<MirrorHandlerRemovePeer>()); | |
7c673cae FG |
1296 | |
1297 | return handlers; | |
1298 | } | |
1299 | ||
7c673cae FG |
1300 | int FileSystemCommandHandler::_check_pool( |
1301 | OSDMap &osd_map, | |
1302 | const int64_t pool_id, | |
92f5a8d4 | 1303 | int type, |
c07f9fc5 | 1304 | bool force, |
7c673cae FG |
1305 | std::stringstream *ss) const |
1306 | { | |
11fdf7f2 | 1307 | ceph_assert(ss != NULL); |
7c673cae FG |
1308 | |
1309 | const pg_pool_t *pool = osd_map.get_pg_pool(pool_id); | |
1310 | if (!pool) { | |
1311 | *ss << "pool id '" << pool_id << "' does not exist"; | |
1312 | return -ENOENT; | |
1313 | } | |
1314 | ||
1315 | const string& pool_name = osd_map.get_pool_name(pool_id); | |
1316 | ||
92f5a8d4 TL |
1317 | if (pool->is_erasure()) { |
1318 | if (type == POOL_METADATA) { | |
7c673cae FG |
1319 | *ss << "pool '" << pool_name << "' (id '" << pool_id << "')" |
1320 | << " is an erasure-coded pool. Use of erasure-coded pools" | |
1321 | << " for CephFS metadata is not permitted"; | |
92f5a8d4 TL |
1322 | return -EINVAL; |
1323 | } else if (type == POOL_DATA_DEFAULT && !force) { | |
7c673cae | 1324 | *ss << "pool '" << pool_name << "' (id '" << pool_id << "')" |
92f5a8d4 TL |
1325 | " is an erasure-coded pool." |
1326 | " Use of an EC pool for the default data pool is discouraged;" | |
1327 | " see the online CephFS documentation for more information." | |
1328 | " Use --force to override."; | |
7c673cae | 1329 | return -EINVAL; |
92f5a8d4 TL |
1330 | } else if (!pool->allows_ecoverwrites()) { |
1331 | // non-overwriteable EC pools are only acceptable with a cache tier overlay | |
1332 | if (!pool->has_tiers() || !pool->has_read_tier() || !pool->has_write_tier()) { | |
1333 | *ss << "pool '" << pool_name << "' (id '" << pool_id << "')" | |
1334 | << " is an erasure-coded pool, with no overwrite support"; | |
1335 | return -EINVAL; | |
1336 | } | |
7c673cae | 1337 | |
92f5a8d4 TL |
1338 | // That cache tier overlay must be writeback, not readonly (it's the |
1339 | // write operations like modify+truncate we care about support for) | |
1340 | const pg_pool_t *write_tier = osd_map.get_pg_pool( | |
1341 | pool->write_tier); | |
1342 | ceph_assert(write_tier != NULL); // OSDMonitor shouldn't allow DNE tier | |
1343 | if (write_tier->cache_mode == pg_pool_t::CACHEMODE_FORWARD | |
1344 | || write_tier->cache_mode == pg_pool_t::CACHEMODE_READONLY) { | |
1345 | *ss << "EC pool '" << pool_name << "' has a write tier (" | |
1346 | << osd_map.get_pool_name(pool->write_tier) | |
1347 | << ") that is configured " | |
1348 | "to forward writes. Use a cache mode such as 'writeback' for " | |
1349 | "CephFS"; | |
1350 | return -EINVAL; | |
1351 | } | |
7c673cae FG |
1352 | } |
1353 | } | |
1354 | ||
1355 | if (pool->is_tier()) { | |
1356 | *ss << " pool '" << pool_name << "' (id '" << pool_id | |
1357 | << "') is already in use as a cache tier."; | |
1358 | return -EINVAL; | |
1359 | } | |
1360 | ||
c07f9fc5 FG |
1361 | if (!force && !pool->application_metadata.empty() && |
1362 | pool->application_metadata.count( | |
1363 | pg_pool_t::APPLICATION_NAME_CEPHFS) == 0) { | |
1364 | *ss << " pool '" << pool_name << "' (id '" << pool_id | |
1365 | << "') has a non-CephFS application enabled."; | |
1366 | return -EINVAL; | |
1367 | } | |
1368 | ||
7c673cae FG |
1369 | // Nothing special about this pool, so it is permissible |
1370 | return 0; | |
1371 | } | |
1372 | ||
f67539c2 TL |
1373 | int FileSystemCommandHandler::is_op_allowed( |
1374 | const MonOpRequestRef& op, const FSMap& fsmap, const cmdmap_t& cmdmap, | |
1375 | std::stringstream &ss) const | |
1376 | { | |
1377 | string fs_name; | |
1378 | cmd_getval(cmdmap, "fs_name", fs_name); | |
1379 | ||
1380 | // so that fsmap can filtered and the original copy is untouched. | |
1381 | FSMap fsmap_copy = fsmap; | |
1382 | fsmap_copy.filter(op->get_session()->get_allowed_fs_names()); | |
1383 | ||
1384 | auto fs = fsmap_copy.get_filesystem(fs_name); | |
1385 | if (fs == nullptr) { | |
1386 | /* let "fs rm" handle idempotent case where file system does not exist */ | |
1387 | if (!(get_prefix() == "fs rm" && fsmap.get_filesystem(fs_name) == nullptr)) { | |
1388 | ss << "Filesystem not found: '" << fs_name << "'"; | |
1389 | return -ENOENT; | |
1390 | } | |
1391 | } | |
1392 | ||
1393 | if (!op->get_session()->fs_name_capable(fs_name, MON_CAP_W)) { | |
1394 | ss << "Permission denied: '" << fs_name << "'"; | |
1395 | return -EPERM; | |
1396 | } | |
1397 | ||
1398 | return 1; | |
1399 | } |