]>
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) 2004-2006 Sage Weil <sage@newdream.net> | |
7 | * Copyright (C) 2013,2014 Cloudwatt <libre.licensing@cloudwatt.com> | |
8 | * Copyright (C) 2014 Red Hat <contact@redhat.com> | |
9 | * | |
10 | * Author: Loic Dachary <loic@dachary.org> | |
11 | * | |
12 | * This is free software; you can redistribute it and/or | |
13 | * modify it under the terms of the GNU Lesser General Public | |
14 | * License version 2.1, as published by the Free Software | |
15 | * Foundation. See file COPYING. | |
16 | * | |
17 | */ | |
18 | ||
19 | #include <algorithm> | |
224ce89b WB |
20 | #include <boost/algorithm/string.hpp> |
21 | #include <locale> | |
7c673cae FG |
22 | #include <sstream> |
23 | ||
31f18b77 FG |
24 | #include "mon/OSDMonitor.h" |
25 | #include "mon/Monitor.h" | |
26 | #include "mon/MDSMonitor.h" | |
27 | #include "mon/PGMonitor.h" | |
28 | #include "mon/MgrStatMonitor.h" | |
29 | #include "mon/AuthMonitor.h" | |
30 | #include "mon/ConfigKeyService.h" | |
7c673cae | 31 | |
31f18b77 FG |
32 | #include "mon/MonitorDBStore.h" |
33 | #include "mon/Session.h" | |
7c673cae FG |
34 | |
35 | #include "crush/CrushWrapper.h" | |
36 | #include "crush/CrushTester.h" | |
37 | #include "crush/CrushTreeDumper.h" | |
38 | ||
39 | #include "messages/MOSDBeacon.h" | |
40 | #include "messages/MOSDFailure.h" | |
41 | #include "messages/MOSDMarkMeDown.h" | |
42 | #include "messages/MOSDFull.h" | |
43 | #include "messages/MOSDMap.h" | |
44 | #include "messages/MMonGetOSDMap.h" | |
45 | #include "messages/MOSDBoot.h" | |
46 | #include "messages/MOSDAlive.h" | |
47 | #include "messages/MPoolOp.h" | |
48 | #include "messages/MPoolOpReply.h" | |
49 | #include "messages/MOSDPGCreate.h" | |
50 | #include "messages/MOSDPGCreated.h" | |
51 | #include "messages/MOSDPGTemp.h" | |
52 | #include "messages/MMonCommand.h" | |
53 | #include "messages/MRemoveSnaps.h" | |
54 | #include "messages/MOSDScrub.h" | |
55 | #include "messages/MRoute.h" | |
56 | ||
57 | #include "common/TextTable.h" | |
58 | #include "common/Timer.h" | |
59 | #include "common/ceph_argparse.h" | |
60 | #include "common/perf_counters.h" | |
61 | #include "common/strtol.h" | |
62 | ||
63 | #include "common/config.h" | |
64 | #include "common/errno.h" | |
65 | ||
66 | #include "erasure-code/ErasureCodePlugin.h" | |
67 | #include "compressor/Compressor.h" | |
68 | #include "common/Checksummer.h" | |
69 | ||
70 | #include "include/compat.h" | |
71 | #include "include/assert.h" | |
72 | #include "include/stringify.h" | |
73 | #include "include/util.h" | |
74 | #include "common/cmdparse.h" | |
75 | #include "include/str_list.h" | |
76 | #include "include/str_map.h" | |
224ce89b | 77 | #include "include/scope_guard.h" |
7c673cae FG |
78 | |
79 | #include "json_spirit/json_spirit_reader.h" | |
80 | ||
c07f9fc5 FG |
81 | #include <boost/algorithm/string/predicate.hpp> |
82 | ||
7c673cae FG |
83 | #define dout_subsys ceph_subsys_mon |
84 | #define OSD_PG_CREATING_PREFIX "osd_pg_creating" | |
85 | ||
c07f9fc5 FG |
86 | namespace { |
87 | ||
88 | const uint32_t MAX_POOL_APPLICATIONS = 4; | |
89 | const uint32_t MAX_POOL_APPLICATION_KEYS = 64; | |
90 | const uint32_t MAX_POOL_APPLICATION_LENGTH = 128; | |
91 | ||
92 | } // anonymous namespace | |
93 | ||
7c673cae FG |
94 | void LastEpochClean::Lec::report(ps_t ps, epoch_t last_epoch_clean) |
95 | { | |
96 | if (epoch_by_pg.size() <= ps) { | |
97 | epoch_by_pg.resize(ps + 1, 0); | |
98 | } | |
99 | const auto old_lec = epoch_by_pg[ps]; | |
100 | if (old_lec >= last_epoch_clean) { | |
101 | // stale lec | |
102 | return; | |
103 | } | |
104 | epoch_by_pg[ps] = last_epoch_clean; | |
105 | if (last_epoch_clean < floor) { | |
106 | floor = last_epoch_clean; | |
107 | } else if (last_epoch_clean > floor) { | |
108 | if (old_lec == floor) { | |
109 | // probably should increase floor? | |
110 | auto new_floor = std::min_element(std::begin(epoch_by_pg), | |
111 | std::end(epoch_by_pg)); | |
112 | floor = *new_floor; | |
113 | } | |
114 | } | |
115 | if (ps != next_missing) { | |
116 | return; | |
117 | } | |
118 | for (; next_missing < epoch_by_pg.size(); next_missing++) { | |
119 | if (epoch_by_pg[next_missing] == 0) { | |
120 | break; | |
121 | } | |
122 | } | |
123 | } | |
124 | ||
125 | void LastEpochClean::remove_pool(uint64_t pool) | |
126 | { | |
127 | report_by_pool.erase(pool); | |
128 | } | |
129 | ||
130 | void LastEpochClean::report(const pg_t& pg, epoch_t last_epoch_clean) | |
131 | { | |
132 | auto& lec = report_by_pool[pg.pool()]; | |
133 | return lec.report(pg.ps(), last_epoch_clean); | |
134 | } | |
135 | ||
136 | epoch_t LastEpochClean::get_lower_bound(const OSDMap& latest) const | |
137 | { | |
138 | auto floor = latest.get_epoch(); | |
139 | for (auto& pool : latest.get_pools()) { | |
140 | auto reported = report_by_pool.find(pool.first); | |
141 | if (reported == report_by_pool.end()) { | |
142 | return 0; | |
143 | } | |
144 | if (reported->second.next_missing < pool.second.get_pg_num()) { | |
145 | return 0; | |
146 | } | |
147 | if (reported->second.floor < floor) { | |
148 | floor = reported->second.floor; | |
149 | } | |
150 | } | |
151 | return floor; | |
152 | } | |
153 | ||
154 | ||
155 | struct C_UpdateCreatingPGs : public Context { | |
156 | OSDMonitor *osdmon; | |
157 | utime_t start; | |
158 | epoch_t epoch; | |
159 | C_UpdateCreatingPGs(OSDMonitor *osdmon, epoch_t e) : | |
160 | osdmon(osdmon), start(ceph_clock_now()), epoch(e) {} | |
161 | void finish(int r) override { | |
162 | if (r >= 0) { | |
163 | utime_t end = ceph_clock_now(); | |
164 | dout(10) << "osdmap epoch " << epoch << " mapping took " | |
165 | << (end - start) << " seconds" << dendl; | |
166 | osdmon->update_creating_pgs(); | |
167 | osdmon->check_pg_creates_subs(); | |
168 | } | |
169 | } | |
170 | }; | |
171 | ||
172 | #undef dout_prefix | |
173 | #define dout_prefix _prefix(_dout, mon, osdmap) | |
174 | static ostream& _prefix(std::ostream *_dout, Monitor *mon, const OSDMap& osdmap) { | |
175 | return *_dout << "mon." << mon->name << "@" << mon->rank | |
176 | << "(" << mon->get_state_name() | |
177 | << ").osd e" << osdmap.get_epoch() << " "; | |
178 | } | |
179 | ||
180 | OSDMonitor::OSDMonitor( | |
181 | CephContext *cct, | |
182 | Monitor *mn, | |
183 | Paxos *p, | |
184 | const string& service_name) | |
185 | : PaxosService(mn, p, service_name), | |
186 | cct(cct), | |
187 | inc_osd_cache(g_conf->mon_osd_cache_size), | |
188 | full_osd_cache(g_conf->mon_osd_cache_size), | |
189 | last_attempted_minwait_time(utime_t()), | |
190 | mapper(mn->cct, &mn->cpu_tp), | |
191 | op_tracker(cct, true, 1) | |
192 | {} | |
193 | ||
194 | bool OSDMonitor::_have_pending_crush() | |
195 | { | |
196 | return pending_inc.crush.length() > 0; | |
197 | } | |
198 | ||
199 | CrushWrapper &OSDMonitor::_get_stable_crush() | |
200 | { | |
201 | return *osdmap.crush; | |
202 | } | |
203 | ||
204 | void OSDMonitor::_get_pending_crush(CrushWrapper& newcrush) | |
205 | { | |
206 | bufferlist bl; | |
207 | if (pending_inc.crush.length()) | |
208 | bl = pending_inc.crush; | |
209 | else | |
210 | osdmap.crush->encode(bl, CEPH_FEATURES_SUPPORTED_DEFAULT); | |
211 | ||
212 | bufferlist::iterator p = bl.begin(); | |
213 | newcrush.decode(p); | |
214 | } | |
215 | ||
216 | void OSDMonitor::create_initial() | |
217 | { | |
218 | dout(10) << "create_initial for " << mon->monmap->fsid << dendl; | |
219 | ||
220 | OSDMap newmap; | |
221 | ||
222 | bufferlist bl; | |
223 | mon->store->get("mkfs", "osdmap", bl); | |
224 | ||
225 | if (bl.length()) { | |
226 | newmap.decode(bl); | |
227 | newmap.set_fsid(mon->monmap->fsid); | |
228 | } else { | |
224ce89b | 229 | newmap.build_simple(g_ceph_context, 0, mon->monmap->fsid, 0); |
7c673cae FG |
230 | } |
231 | newmap.set_epoch(1); | |
232 | newmap.created = newmap.modified = ceph_clock_now(); | |
233 | ||
234 | // new clusters should sort bitwise by default. | |
235 | newmap.set_flag(CEPH_OSDMAP_SORTBITWISE); | |
236 | ||
237 | // new cluster should require latest by default | |
31f18b77 FG |
238 | if (g_conf->mon_debug_no_require_luminous) { |
239 | newmap.require_osd_release = CEPH_RELEASE_KRAKEN; | |
240 | derr << __func__ << " mon_debug_no_require_luminous=true" << dendl; | |
241 | } else { | |
242 | newmap.require_osd_release = CEPH_RELEASE_LUMINOUS; | |
c07f9fc5 | 243 | newmap.flags |= CEPH_OSDMAP_RECOVERY_DELETES; |
7c673cae FG |
244 | newmap.full_ratio = g_conf->mon_osd_full_ratio; |
245 | if (newmap.full_ratio > 1.0) newmap.full_ratio /= 100; | |
246 | newmap.backfillfull_ratio = g_conf->mon_osd_backfillfull_ratio; | |
247 | if (newmap.backfillfull_ratio > 1.0) newmap.backfillfull_ratio /= 100; | |
248 | newmap.nearfull_ratio = g_conf->mon_osd_nearfull_ratio; | |
249 | if (newmap.nearfull_ratio > 1.0) newmap.nearfull_ratio /= 100; | |
31f18b77 FG |
250 | int r = ceph_release_from_name( |
251 | g_conf->mon_osd_initial_require_min_compat_client.c_str()); | |
252 | if (r <= 0) { | |
253 | assert(0 == "mon_osd_initial_require_min_compat_client is not valid"); | |
254 | } | |
255 | newmap.require_min_compat_client = r; | |
7c673cae FG |
256 | } |
257 | ||
258 | // encode into pending incremental | |
259 | newmap.encode(pending_inc.fullmap, | |
260 | mon->get_quorum_con_features() | CEPH_FEATURE_RESERVED); | |
261 | pending_inc.full_crc = newmap.get_crc(); | |
262 | dout(20) << " full crc " << pending_inc.full_crc << dendl; | |
263 | } | |
264 | ||
265 | void OSDMonitor::get_store_prefixes(std::set<string>& s) | |
266 | { | |
267 | s.insert(service_name); | |
268 | s.insert(OSD_PG_CREATING_PREFIX); | |
269 | } | |
270 | ||
271 | void OSDMonitor::update_from_paxos(bool *need_bootstrap) | |
272 | { | |
273 | version_t version = get_last_committed(); | |
274 | if (version == osdmap.epoch) | |
275 | return; | |
276 | assert(version > osdmap.epoch); | |
277 | ||
278 | dout(15) << "update_from_paxos paxos e " << version | |
279 | << ", my e " << osdmap.epoch << dendl; | |
280 | ||
31f18b77 FG |
281 | if (mapping_job) { |
282 | if (!mapping_job->is_done()) { | |
283 | dout(1) << __func__ << " mapping job " | |
284 | << mapping_job.get() << " did not complete, " | |
285 | << mapping_job->shards << " left, canceling" << dendl; | |
286 | mapping_job->abort(); | |
287 | } | |
288 | mapping_job.reset(); | |
289 | } | |
7c673cae | 290 | |
224ce89b WB |
291 | load_health(); |
292 | ||
7c673cae FG |
293 | /* |
294 | * We will possibly have a stashed latest that *we* wrote, and we will | |
295 | * always be sure to have the oldest full map in the first..last range | |
296 | * due to encode_trim_extra(), which includes the oldest full map in the trim | |
297 | * transaction. | |
298 | * | |
299 | * encode_trim_extra() does not however write the full map's | |
300 | * version to 'full_latest'. This is only done when we are building the | |
301 | * full maps from the incremental versions. But don't panic! We make sure | |
302 | * that the following conditions find whichever full map version is newer. | |
303 | */ | |
304 | version_t latest_full = get_version_latest_full(); | |
305 | if (latest_full == 0 && get_first_committed() > 1) | |
306 | latest_full = get_first_committed(); | |
307 | ||
308 | if (get_first_committed() > 1 && | |
309 | latest_full < get_first_committed()) { | |
310 | // the monitor could be just sync'ed with its peer, and the latest_full key | |
311 | // is not encoded in the paxos commits in encode_pending(), so we need to | |
312 | // make sure we get it pointing to a proper version. | |
313 | version_t lc = get_last_committed(); | |
314 | version_t fc = get_first_committed(); | |
315 | ||
316 | dout(10) << __func__ << " looking for valid full map in interval" | |
317 | << " [" << fc << ", " << lc << "]" << dendl; | |
318 | ||
319 | latest_full = 0; | |
320 | for (version_t v = lc; v >= fc; v--) { | |
321 | string full_key = "full_" + stringify(v); | |
322 | if (mon->store->exists(get_service_name(), full_key)) { | |
323 | dout(10) << __func__ << " found latest full map v " << v << dendl; | |
324 | latest_full = v; | |
325 | break; | |
326 | } | |
327 | } | |
328 | ||
329 | assert(latest_full > 0); | |
330 | auto t(std::make_shared<MonitorDBStore::Transaction>()); | |
331 | put_version_latest_full(t, latest_full); | |
332 | mon->store->apply_transaction(t); | |
333 | dout(10) << __func__ << " updated the on-disk full map version to " | |
334 | << latest_full << dendl; | |
335 | } | |
336 | ||
337 | if ((latest_full > 0) && (latest_full > osdmap.epoch)) { | |
338 | bufferlist latest_bl; | |
339 | get_version_full(latest_full, latest_bl); | |
340 | assert(latest_bl.length() != 0); | |
341 | dout(7) << __func__ << " loading latest full map e" << latest_full << dendl; | |
342 | osdmap.decode(latest_bl); | |
343 | } | |
344 | ||
345 | if (mon->monmap->get_required_features().contains_all( | |
346 | ceph::features::mon::FEATURE_LUMINOUS)) { | |
347 | bufferlist bl; | |
348 | if (!mon->store->get(OSD_PG_CREATING_PREFIX, "creating", bl)) { | |
349 | auto p = bl.begin(); | |
350 | std::lock_guard<std::mutex> l(creating_pgs_lock); | |
351 | creating_pgs.decode(p); | |
352 | dout(7) << __func__ << " loading creating_pgs last_scan_epoch " | |
353 | << creating_pgs.last_scan_epoch | |
354 | << " with " << creating_pgs.pgs.size() << " pgs" << dendl; | |
355 | } else { | |
356 | dout(1) << __func__ << " missing creating pgs; upgrade from post-kraken?" | |
357 | << dendl; | |
358 | } | |
359 | } | |
360 | ||
31f18b77 FG |
361 | // make sure we're using the right pg service.. remove me post-luminous! |
362 | if (osdmap.require_osd_release >= CEPH_RELEASE_LUMINOUS) { | |
363 | dout(10) << __func__ << " pgservice is mgrstat" << dendl; | |
364 | mon->pgservice = mon->mgrstatmon()->get_pg_stat_service(); | |
365 | } else { | |
366 | dout(10) << __func__ << " pgservice is pg" << dendl; | |
367 | mon->pgservice = mon->pgmon()->get_pg_stat_service(); | |
368 | } | |
369 | ||
7c673cae FG |
370 | // walk through incrementals |
371 | MonitorDBStore::TransactionRef t; | |
372 | size_t tx_size = 0; | |
373 | while (version > osdmap.epoch) { | |
374 | bufferlist inc_bl; | |
375 | int err = get_version(osdmap.epoch+1, inc_bl); | |
376 | assert(err == 0); | |
377 | assert(inc_bl.length()); | |
378 | ||
379 | dout(7) << "update_from_paxos applying incremental " << osdmap.epoch+1 | |
380 | << dendl; | |
381 | OSDMap::Incremental inc(inc_bl); | |
382 | err = osdmap.apply_incremental(inc); | |
383 | assert(err == 0); | |
384 | ||
385 | if (!t) | |
386 | t.reset(new MonitorDBStore::Transaction); | |
387 | ||
388 | // Write out the full map for all past epochs. Encode the full | |
389 | // map with the same features as the incremental. If we don't | |
390 | // know, use the quorum features. If we don't know those either, | |
391 | // encode with all features. | |
392 | uint64_t f = inc.encode_features; | |
393 | if (!f) | |
394 | f = mon->get_quorum_con_features(); | |
395 | if (!f) | |
396 | f = -1; | |
397 | bufferlist full_bl; | |
398 | osdmap.encode(full_bl, f | CEPH_FEATURE_RESERVED); | |
399 | tx_size += full_bl.length(); | |
400 | ||
401 | bufferlist orig_full_bl; | |
402 | get_version_full(osdmap.epoch, orig_full_bl); | |
403 | if (orig_full_bl.length()) { | |
404 | // the primary provided the full map | |
405 | assert(inc.have_crc); | |
406 | if (inc.full_crc != osdmap.crc) { | |
407 | // This will happen if the mons were running mixed versions in | |
408 | // the past or some other circumstance made the full encoded | |
409 | // maps divergent. Reloading here will bring us back into | |
410 | // sync with the primary for this and all future maps. OSDs | |
411 | // will also be brought back into sync when they discover the | |
412 | // crc mismatch and request a full map from a mon. | |
413 | derr << __func__ << " full map CRC mismatch, resetting to canonical" | |
414 | << dendl; | |
415 | osdmap = OSDMap(); | |
416 | osdmap.decode(orig_full_bl); | |
417 | } | |
418 | } else { | |
419 | assert(!inc.have_crc); | |
420 | put_version_full(t, osdmap.epoch, full_bl); | |
421 | } | |
422 | put_version_latest_full(t, osdmap.epoch); | |
423 | ||
424 | // share | |
425 | dout(1) << osdmap << dendl; | |
426 | ||
427 | if (osdmap.epoch == 1) { | |
428 | t->erase("mkfs", "osdmap"); | |
429 | } | |
430 | ||
31f18b77 FG |
431 | // make sure we're using the right pg service.. remove me post-luminous! |
432 | if (osdmap.require_osd_release >= CEPH_RELEASE_LUMINOUS) { | |
433 | dout(10) << __func__ << " pgservice is mgrstat" << dendl; | |
434 | mon->pgservice = mon->mgrstatmon()->get_pg_stat_service(); | |
435 | } else { | |
436 | dout(10) << __func__ << " pgservice is pg" << dendl; | |
437 | mon->pgservice = mon->pgmon()->get_pg_stat_service(); | |
438 | } | |
439 | ||
7c673cae FG |
440 | if (tx_size > g_conf->mon_sync_max_payload_size*2) { |
441 | mon->store->apply_transaction(t); | |
442 | t = MonitorDBStore::TransactionRef(); | |
443 | tx_size = 0; | |
444 | } | |
445 | if (mon->monmap->get_required_features().contains_all( | |
446 | ceph::features::mon::FEATURE_LUMINOUS)) { | |
7c673cae FG |
447 | for (const auto &osd_state : inc.new_state) { |
448 | if (osd_state.second & CEPH_OSD_UP) { | |
449 | // could be marked up *or* down, but we're too lazy to check which | |
450 | last_osd_report.erase(osd_state.first); | |
451 | } | |
452 | if (osd_state.second & CEPH_OSD_EXISTS) { | |
453 | // could be created *or* destroyed, but we can safely drop it | |
454 | osd_epochs.erase(osd_state.first); | |
455 | } | |
456 | } | |
457 | } | |
458 | } | |
459 | ||
460 | if (t) { | |
461 | mon->store->apply_transaction(t); | |
462 | } | |
463 | ||
464 | for (int o = 0; o < osdmap.get_max_osd(); o++) { | |
465 | if (osdmap.is_out(o)) | |
466 | continue; | |
467 | auto found = down_pending_out.find(o); | |
468 | if (osdmap.is_down(o)) { | |
469 | // populate down -> out map | |
470 | if (found == down_pending_out.end()) { | |
471 | dout(10) << " adding osd." << o << " to down_pending_out map" << dendl; | |
472 | down_pending_out[o] = ceph_clock_now(); | |
473 | } | |
474 | } else { | |
475 | if (found != down_pending_out.end()) { | |
476 | dout(10) << " removing osd." << o << " from down_pending_out map" << dendl; | |
477 | down_pending_out.erase(found); | |
478 | } | |
479 | } | |
480 | } | |
481 | // XXX: need to trim MonSession connected with a osd whose id > max_osd? | |
482 | ||
483 | if (mon->is_leader()) { | |
484 | // kick pgmon, make sure it's seen the latest map | |
485 | mon->pgmon()->check_osd_map(osdmap.epoch); | |
486 | } | |
487 | ||
488 | check_osdmap_subs(); | |
489 | check_pg_creates_subs(); | |
490 | ||
491 | share_map_with_random_osd(); | |
492 | update_logger(); | |
493 | ||
494 | process_failures(); | |
495 | ||
496 | // make sure our feature bits reflect the latest map | |
497 | update_msgr_features(); | |
498 | ||
499 | if (!mon->is_leader()) { | |
500 | // will be called by on_active() on the leader, avoid doing so twice | |
501 | start_mapping(); | |
502 | } | |
503 | } | |
504 | ||
505 | void OSDMonitor::start_mapping() | |
506 | { | |
507 | // initiate mapping job | |
508 | if (mapping_job) { | |
509 | dout(10) << __func__ << " canceling previous mapping_job " << mapping_job.get() | |
510 | << dendl; | |
511 | mapping_job->abort(); | |
512 | } | |
224ce89b WB |
513 | if (!osdmap.get_pools().empty()) { |
514 | auto fin = new C_UpdateCreatingPGs(this, osdmap.get_epoch()); | |
515 | mapping_job = mapping.start_update(osdmap, mapper, | |
516 | g_conf->mon_osd_mapping_pgs_per_chunk); | |
517 | dout(10) << __func__ << " started mapping job " << mapping_job.get() | |
518 | << " at " << fin->start << dendl; | |
519 | mapping_job->set_finish_event(fin); | |
520 | } else { | |
521 | dout(10) << __func__ << " no pools, no mapping job" << dendl; | |
522 | mapping_job = nullptr; | |
523 | } | |
7c673cae FG |
524 | } |
525 | ||
526 | void OSDMonitor::update_msgr_features() | |
527 | { | |
528 | set<int> types; | |
529 | types.insert((int)entity_name_t::TYPE_OSD); | |
530 | types.insert((int)entity_name_t::TYPE_CLIENT); | |
531 | types.insert((int)entity_name_t::TYPE_MDS); | |
532 | types.insert((int)entity_name_t::TYPE_MON); | |
533 | for (set<int>::iterator q = types.begin(); q != types.end(); ++q) { | |
534 | uint64_t mask; | |
535 | uint64_t features = osdmap.get_features(*q, &mask); | |
536 | if ((mon->messenger->get_policy(*q).features_required & mask) != features) { | |
537 | dout(0) << "crush map has features " << features << ", adjusting msgr requires" << dendl; | |
538 | Messenger::Policy p = mon->messenger->get_policy(*q); | |
539 | p.features_required = (p.features_required & ~mask) | features; | |
540 | mon->messenger->set_policy(*q, p); | |
541 | } | |
542 | } | |
543 | } | |
544 | ||
545 | void OSDMonitor::on_active() | |
546 | { | |
547 | update_logger(); | |
548 | ||
549 | if (mon->is_leader()) { | |
224ce89b | 550 | mon->clog->debug() << "osdmap " << osdmap; |
7c673cae FG |
551 | } else { |
552 | list<MonOpRequestRef> ls; | |
553 | take_all_failures(ls); | |
554 | while (!ls.empty()) { | |
555 | MonOpRequestRef op = ls.front(); | |
556 | op->mark_osdmon_event(__func__); | |
557 | dispatch(op); | |
558 | ls.pop_front(); | |
559 | } | |
560 | } | |
561 | start_mapping(); | |
562 | } | |
563 | ||
564 | void OSDMonitor::on_restart() | |
565 | { | |
566 | last_osd_report.clear(); | |
31f18b77 FG |
567 | |
568 | if (mon->is_leader()) { | |
569 | // fix ruleset != ruleid | |
570 | if (osdmap.crush->has_legacy_rulesets() && | |
571 | !osdmap.crush->has_multirule_rulesets()) { | |
572 | CrushWrapper newcrush; | |
573 | _get_pending_crush(newcrush); | |
574 | int r = newcrush.renumber_rules_by_ruleset(); | |
575 | if (r >= 0) { | |
576 | dout(1) << __func__ << " crush map has ruleset != rule id; fixing" << dendl; | |
577 | pending_inc.crush.clear(); | |
578 | newcrush.encode(pending_inc.crush, mon->get_quorum_con_features()); | |
579 | } else { | |
580 | dout(10) << __func__ << " unable to renumber rules by ruleset" << dendl; | |
581 | } | |
582 | } | |
583 | } | |
7c673cae FG |
584 | } |
585 | ||
586 | void OSDMonitor::on_shutdown() | |
587 | { | |
588 | dout(10) << __func__ << dendl; | |
589 | if (mapping_job) { | |
590 | dout(10) << __func__ << " canceling previous mapping_job " << mapping_job.get() | |
591 | << dendl; | |
592 | mapping_job->abort(); | |
593 | } | |
594 | ||
595 | // discard failure info, waiters | |
596 | list<MonOpRequestRef> ls; | |
597 | take_all_failures(ls); | |
598 | ls.clear(); | |
599 | } | |
600 | ||
601 | void OSDMonitor::update_logger() | |
602 | { | |
603 | dout(10) << "update_logger" << dendl; | |
604 | ||
605 | mon->cluster_logger->set(l_cluster_num_osd, osdmap.get_num_osds()); | |
606 | mon->cluster_logger->set(l_cluster_num_osd_up, osdmap.get_num_up_osds()); | |
607 | mon->cluster_logger->set(l_cluster_num_osd_in, osdmap.get_num_in_osds()); | |
608 | mon->cluster_logger->set(l_cluster_osd_epoch, osdmap.get_epoch()); | |
609 | } | |
610 | ||
7c673cae FG |
611 | void OSDMonitor::create_pending() |
612 | { | |
613 | pending_inc = OSDMap::Incremental(osdmap.epoch+1); | |
614 | pending_inc.fsid = mon->monmap->fsid; | |
615 | ||
616 | dout(10) << "create_pending e " << pending_inc.epoch << dendl; | |
617 | ||
618 | // clean up pg_temp, primary_temp | |
619 | OSDMap::clean_temps(g_ceph_context, osdmap, &pending_inc); | |
620 | dout(10) << "create_pending did clean_temps" << dendl; | |
621 | ||
622 | // On upgrade OSDMap has new field set by mon_osd_backfillfull_ratio config | |
623 | // instead of osd_backfill_full_ratio config | |
624 | if (osdmap.backfillfull_ratio <= 0) { | |
625 | pending_inc.new_backfillfull_ratio = g_conf->mon_osd_backfillfull_ratio; | |
626 | if (pending_inc.new_backfillfull_ratio > 1.0) | |
627 | pending_inc.new_backfillfull_ratio /= 100; | |
628 | dout(1) << __func__ << " setting backfillfull_ratio = " | |
629 | << pending_inc.new_backfillfull_ratio << dendl; | |
630 | } | |
31f18b77 FG |
631 | if (osdmap.get_epoch() > 0 && |
632 | osdmap.require_osd_release < CEPH_RELEASE_LUMINOUS) { | |
7c673cae | 633 | // transition full ratios from PGMap to OSDMap (on upgrade) |
31f18b77 FG |
634 | float full_ratio = mon->pgservice->get_full_ratio(); |
635 | float nearfull_ratio = mon->pgservice->get_nearfull_ratio(); | |
636 | if (osdmap.full_ratio != full_ratio) { | |
7c673cae | 637 | dout(10) << __func__ << " full_ratio " << osdmap.full_ratio |
31f18b77 FG |
638 | << " -> " << full_ratio << " (from pgmap)" << dendl; |
639 | pending_inc.new_full_ratio = full_ratio; | |
7c673cae | 640 | } |
31f18b77 | 641 | if (osdmap.nearfull_ratio != nearfull_ratio) { |
7c673cae | 642 | dout(10) << __func__ << " nearfull_ratio " << osdmap.nearfull_ratio |
31f18b77 FG |
643 | << " -> " << nearfull_ratio << " (from pgmap)" << dendl; |
644 | pending_inc.new_nearfull_ratio = nearfull_ratio; | |
7c673cae FG |
645 | } |
646 | } else { | |
647 | // safety check (this shouldn't really happen) | |
648 | if (osdmap.full_ratio <= 0) { | |
649 | pending_inc.new_full_ratio = g_conf->mon_osd_full_ratio; | |
650 | if (pending_inc.new_full_ratio > 1.0) | |
651 | pending_inc.new_full_ratio /= 100; | |
652 | dout(1) << __func__ << " setting full_ratio = " | |
653 | << pending_inc.new_full_ratio << dendl; | |
654 | } | |
655 | if (osdmap.nearfull_ratio <= 0) { | |
656 | pending_inc.new_nearfull_ratio = g_conf->mon_osd_nearfull_ratio; | |
657 | if (pending_inc.new_nearfull_ratio > 1.0) | |
658 | pending_inc.new_nearfull_ratio /= 100; | |
659 | dout(1) << __func__ << " setting nearfull_ratio = " | |
660 | << pending_inc.new_nearfull_ratio << dendl; | |
661 | } | |
662 | } | |
663 | } | |
664 | ||
665 | creating_pgs_t | |
666 | OSDMonitor::update_pending_pgs(const OSDMap::Incremental& inc) | |
667 | { | |
31f18b77 | 668 | dout(10) << __func__ << dendl; |
7c673cae FG |
669 | creating_pgs_t pending_creatings; |
670 | { | |
671 | std::lock_guard<std::mutex> l(creating_pgs_lock); | |
672 | pending_creatings = creating_pgs; | |
673 | } | |
31f18b77 FG |
674 | // check for new or old pools |
675 | if (pending_creatings.last_scan_epoch < inc.epoch) { | |
676 | if (osdmap.get_epoch() && | |
677 | osdmap.require_osd_release < CEPH_RELEASE_LUMINOUS) { | |
678 | auto added = | |
679 | mon->pgservice->maybe_add_creating_pgs(creating_pgs.last_scan_epoch, | |
680 | osdmap.get_pools(), | |
681 | &pending_creatings); | |
682 | dout(7) << __func__ << " " << added << " pgs added from pgmap" << dendl; | |
683 | } | |
684 | unsigned queued = 0; | |
685 | queued += scan_for_creating_pgs(osdmap.get_pools(), | |
686 | inc.old_pools, | |
687 | inc.modified, | |
688 | &pending_creatings); | |
689 | queued += scan_for_creating_pgs(inc.new_pools, | |
690 | inc.old_pools, | |
691 | inc.modified, | |
692 | &pending_creatings); | |
693 | dout(10) << __func__ << " " << queued << " pools queued" << dendl; | |
694 | for (auto deleted_pool : inc.old_pools) { | |
695 | auto removed = pending_creatings.remove_pool(deleted_pool); | |
696 | dout(10) << __func__ << " " << removed | |
697 | << " pg removed because containing pool deleted: " | |
698 | << deleted_pool << dendl; | |
699 | last_epoch_clean.remove_pool(deleted_pool); | |
700 | } | |
701 | // pgmon updates its creating_pgs in check_osd_map() which is called by | |
702 | // on_active() and check_osd_map() could be delayed if lease expires, so its | |
703 | // creating_pgs could be stale in comparison with the one of osdmon. let's | |
704 | // trim them here. otherwise, they will be added back after being erased. | |
705 | unsigned removed = 0; | |
706 | for (auto& pg : pending_created_pgs) { | |
707 | dout(20) << __func__ << " noting created pg " << pg << dendl; | |
708 | pending_creatings.created_pools.insert(pg.pool()); | |
709 | removed += pending_creatings.pgs.erase(pg); | |
710 | } | |
711 | pending_created_pgs.clear(); | |
712 | dout(10) << __func__ << " " << removed | |
713 | << " pgs removed because they're created" << dendl; | |
714 | pending_creatings.last_scan_epoch = osdmap.get_epoch(); | |
715 | } | |
716 | ||
717 | // process queue | |
718 | unsigned max = MAX(1, g_conf->mon_osd_max_creating_pgs); | |
719 | const auto total = pending_creatings.pgs.size(); | |
720 | while (pending_creatings.pgs.size() < max && | |
721 | !pending_creatings.queue.empty()) { | |
722 | auto p = pending_creatings.queue.begin(); | |
723 | int64_t poolid = p->first; | |
724 | dout(10) << __func__ << " pool " << poolid | |
725 | << " created " << p->second.created | |
726 | << " modified " << p->second.modified | |
727 | << " [" << p->second.start << "-" << p->second.end << ")" | |
728 | << dendl; | |
729 | int n = MIN(max - pending_creatings.pgs.size(), | |
730 | p->second.end - p->second.start); | |
731 | ps_t first = p->second.start; | |
732 | ps_t end = first + n; | |
733 | for (ps_t ps = first; ps < end; ++ps) { | |
734 | const pg_t pgid{ps, static_cast<uint64_t>(poolid)}; | |
735 | // NOTE: use the *current* epoch as the PG creation epoch so that the | |
736 | // OSD does not have to generate a long set of PastIntervals. | |
737 | pending_creatings.pgs.emplace(pgid, make_pair(inc.epoch, | |
738 | p->second.modified)); | |
739 | dout(10) << __func__ << " adding " << pgid << dendl; | |
740 | } | |
741 | p->second.start = end; | |
742 | if (p->second.done()) { | |
743 | dout(10) << __func__ << " done with queue for " << poolid << dendl; | |
744 | pending_creatings.queue.erase(p); | |
745 | } else { | |
746 | dout(10) << __func__ << " pool " << poolid | |
747 | << " now [" << p->second.start << "-" << p->second.end << ")" | |
748 | << dendl; | |
749 | } | |
750 | } | |
751 | dout(10) << __func__ << " queue remaining: " << pending_creatings.queue.size() | |
752 | << " pools" << dendl; | |
c07f9fc5 FG |
753 | dout(10) << __func__ |
754 | << " " << (pending_creatings.pgs.size() - total) | |
755 | << "/" << pending_creatings.pgs.size() | |
31f18b77 | 756 | << " pgs added from queued pools" << dendl; |
7c673cae FG |
757 | return pending_creatings; |
758 | } | |
759 | ||
760 | void OSDMonitor::maybe_prime_pg_temp() | |
761 | { | |
762 | bool all = false; | |
763 | if (pending_inc.crush.length()) { | |
764 | dout(10) << __func__ << " new crush map, all" << dendl; | |
765 | all = true; | |
766 | } | |
767 | ||
768 | if (!pending_inc.new_up_client.empty()) { | |
769 | dout(10) << __func__ << " new up osds, all" << dendl; | |
770 | all = true; | |
771 | } | |
772 | ||
773 | // check for interesting OSDs | |
774 | set<int> osds; | |
31f18b77 | 775 | for (auto p = pending_inc.new_state.begin(); |
7c673cae FG |
776 | !all && p != pending_inc.new_state.end(); |
777 | ++p) { | |
778 | if ((p->second & CEPH_OSD_UP) && | |
779 | osdmap.is_up(p->first)) { | |
780 | osds.insert(p->first); | |
781 | } | |
782 | } | |
783 | for (map<int32_t,uint32_t>::iterator p = pending_inc.new_weight.begin(); | |
784 | !all && p != pending_inc.new_weight.end(); | |
785 | ++p) { | |
786 | if (p->second < osdmap.get_weight(p->first)) { | |
787 | // weight reduction | |
788 | osds.insert(p->first); | |
789 | } else { | |
790 | dout(10) << __func__ << " osd." << p->first << " weight increase, all" | |
791 | << dendl; | |
792 | all = true; | |
793 | } | |
794 | } | |
795 | ||
796 | if (!all && osds.empty()) | |
797 | return; | |
798 | ||
799 | if (!all) { | |
800 | unsigned estimate = | |
801 | mapping.get_osd_acting_pgs(*osds.begin()).size() * osds.size(); | |
802 | if (estimate > mapping.get_num_pgs() * | |
803 | g_conf->mon_osd_prime_pg_temp_max_estimate) { | |
804 | dout(10) << __func__ << " estimate " << estimate << " pgs on " | |
805 | << osds.size() << " osds >= " | |
806 | << g_conf->mon_osd_prime_pg_temp_max_estimate << " of total " | |
807 | << mapping.get_num_pgs() << " pgs, all" | |
808 | << dendl; | |
809 | all = true; | |
810 | } else { | |
811 | dout(10) << __func__ << " estimate " << estimate << " pgs on " | |
812 | << osds.size() << " osds" << dendl; | |
813 | } | |
814 | } | |
815 | ||
816 | OSDMap next; | |
817 | next.deepish_copy_from(osdmap); | |
818 | next.apply_incremental(pending_inc); | |
819 | ||
224ce89b WB |
820 | if (next.get_pools().empty()) { |
821 | dout(10) << __func__ << " no pools, no pg_temp priming" << dendl; | |
822 | } else if (all) { | |
7c673cae FG |
823 | PrimeTempJob job(next, this); |
824 | mapper.queue(&job, g_conf->mon_osd_mapping_pgs_per_chunk); | |
825 | if (job.wait_for(g_conf->mon_osd_prime_pg_temp_max_time)) { | |
826 | dout(10) << __func__ << " done in " << job.get_duration() << dendl; | |
827 | } else { | |
828 | dout(10) << __func__ << " did not finish in " | |
829 | << g_conf->mon_osd_prime_pg_temp_max_time | |
830 | << ", stopping" << dendl; | |
831 | job.abort(); | |
832 | } | |
833 | } else { | |
834 | dout(10) << __func__ << " " << osds.size() << " interesting osds" << dendl; | |
835 | utime_t stop = ceph_clock_now(); | |
836 | stop += g_conf->mon_osd_prime_pg_temp_max_time; | |
837 | const int chunk = 1000; | |
838 | int n = chunk; | |
839 | std::unordered_set<pg_t> did_pgs; | |
840 | for (auto osd : osds) { | |
841 | auto& pgs = mapping.get_osd_acting_pgs(osd); | |
842 | dout(20) << __func__ << " osd." << osd << " " << pgs << dendl; | |
843 | for (auto pgid : pgs) { | |
844 | if (!did_pgs.insert(pgid).second) { | |
845 | continue; | |
846 | } | |
847 | prime_pg_temp(next, pgid); | |
848 | if (--n <= 0) { | |
849 | n = chunk; | |
850 | if (ceph_clock_now() > stop) { | |
851 | dout(10) << __func__ << " consumed more than " | |
852 | << g_conf->mon_osd_prime_pg_temp_max_time | |
853 | << " seconds, stopping" | |
854 | << dendl; | |
855 | return; | |
856 | } | |
857 | } | |
858 | } | |
859 | } | |
860 | } | |
861 | } | |
862 | ||
863 | void OSDMonitor::prime_pg_temp( | |
864 | const OSDMap& next, | |
865 | pg_t pgid) | |
866 | { | |
867 | if (mon->monmap->get_required_features().contains_all( | |
868 | ceph::features::mon::FEATURE_LUMINOUS)) { | |
31f18b77 | 869 | // TODO: remove this creating_pgs direct access? |
7c673cae FG |
870 | if (creating_pgs.pgs.count(pgid)) { |
871 | return; | |
872 | } | |
873 | } else { | |
31f18b77 | 874 | if (mon->pgservice->is_creating_pg(pgid)) { |
7c673cae FG |
875 | return; |
876 | } | |
877 | } | |
878 | if (!osdmap.pg_exists(pgid)) { | |
879 | return; | |
880 | } | |
881 | ||
882 | vector<int> up, acting; | |
883 | mapping.get(pgid, &up, nullptr, &acting, nullptr); | |
884 | ||
885 | vector<int> next_up, next_acting; | |
886 | int next_up_primary, next_acting_primary; | |
887 | next.pg_to_up_acting_osds(pgid, &next_up, &next_up_primary, | |
888 | &next_acting, &next_acting_primary); | |
c07f9fc5 | 889 | if (acting == next_acting && next_up != next_acting) |
7c673cae FG |
890 | return; // no change since last epoch |
891 | ||
892 | if (acting.empty()) | |
893 | return; // if previously empty now we can be no worse off | |
894 | const pg_pool_t *pool = next.get_pg_pool(pgid.pool()); | |
895 | if (pool && acting.size() < pool->min_size) | |
896 | return; // can be no worse off than before | |
897 | ||
c07f9fc5 FG |
898 | if (next_up == next_acting) { |
899 | acting.clear(); | |
900 | dout(20) << __func__ << "next_up === next_acting now, clear pg_temp" | |
901 | << dendl; | |
902 | } | |
903 | ||
7c673cae FG |
904 | dout(20) << __func__ << " " << pgid << " " << up << "/" << acting |
905 | << " -> " << next_up << "/" << next_acting | |
906 | << ", priming " << acting | |
907 | << dendl; | |
908 | { | |
909 | Mutex::Locker l(prime_pg_temp_lock); | |
910 | // do not touch a mapping if a change is pending | |
911 | pending_inc.new_pg_temp.emplace( | |
912 | pgid, | |
913 | mempool::osdmap::vector<int>(acting.begin(), acting.end())); | |
914 | } | |
915 | } | |
916 | ||
917 | /** | |
918 | * @note receiving a transaction in this function gives a fair amount of | |
919 | * freedom to the service implementation if it does need it. It shouldn't. | |
920 | */ | |
921 | void OSDMonitor::encode_pending(MonitorDBStore::TransactionRef t) | |
922 | { | |
923 | dout(10) << "encode_pending e " << pending_inc.epoch | |
924 | << dendl; | |
925 | ||
926 | // finalize up pending_inc | |
927 | pending_inc.modified = ceph_clock_now(); | |
928 | ||
929 | int r = pending_inc.propagate_snaps_to_tiers(g_ceph_context, osdmap); | |
930 | assert(r == 0); | |
931 | ||
932 | if (mapping_job) { | |
933 | if (!mapping_job->is_done()) { | |
934 | dout(1) << __func__ << " skipping prime_pg_temp; mapping job " | |
935 | << mapping_job.get() << " did not complete, " | |
936 | << mapping_job->shards << " left" << dendl; | |
937 | mapping_job->abort(); | |
938 | } else if (mapping.get_epoch() < osdmap.get_epoch()) { | |
939 | dout(1) << __func__ << " skipping prime_pg_temp; mapping job " | |
940 | << mapping_job.get() << " is prior epoch " | |
941 | << mapping.get_epoch() << dendl; | |
942 | } else { | |
943 | if (g_conf->mon_osd_prime_pg_temp) { | |
944 | maybe_prime_pg_temp(); | |
945 | } | |
946 | } | |
947 | } else if (g_conf->mon_osd_prime_pg_temp) { | |
948 | dout(1) << __func__ << " skipping prime_pg_temp; mapping job did not start" | |
949 | << dendl; | |
950 | } | |
951 | mapping_job.reset(); | |
952 | ||
c07f9fc5 FG |
953 | // ensure we don't have blank new_state updates. these are interrpeted as |
954 | // CEPH_OSD_UP (and almost certainly not what we want!). | |
955 | auto p = pending_inc.new_state.begin(); | |
956 | while (p != pending_inc.new_state.end()) { | |
957 | if (p->second == 0) { | |
958 | dout(10) << "new_state for osd." << p->first << " is 0, removing" << dendl; | |
959 | p = pending_inc.new_state.erase(p); | |
960 | } else { | |
961 | ++p; | |
962 | } | |
963 | } | |
964 | ||
7c673cae FG |
965 | bufferlist bl; |
966 | ||
967 | { | |
968 | OSDMap tmp; | |
969 | tmp.deepish_copy_from(osdmap); | |
970 | tmp.apply_incremental(pending_inc); | |
971 | ||
31f18b77 | 972 | if (tmp.require_osd_release >= CEPH_RELEASE_LUMINOUS) { |
7c673cae FG |
973 | // set or clear full/nearfull? |
974 | int full, backfill, nearfull; | |
975 | tmp.count_full_nearfull_osds(&full, &backfill, &nearfull); | |
976 | if (full > 0) { | |
977 | if (!tmp.test_flag(CEPH_OSDMAP_FULL)) { | |
978 | dout(10) << __func__ << " setting full flag" << dendl; | |
979 | add_flag(CEPH_OSDMAP_FULL); | |
980 | remove_flag(CEPH_OSDMAP_NEARFULL); | |
981 | } | |
982 | } else { | |
983 | if (tmp.test_flag(CEPH_OSDMAP_FULL)) { | |
984 | dout(10) << __func__ << " clearing full flag" << dendl; | |
985 | remove_flag(CEPH_OSDMAP_FULL); | |
986 | } | |
987 | if (nearfull > 0) { | |
988 | if (!tmp.test_flag(CEPH_OSDMAP_NEARFULL)) { | |
989 | dout(10) << __func__ << " setting nearfull flag" << dendl; | |
990 | add_flag(CEPH_OSDMAP_NEARFULL); | |
991 | } | |
992 | } else { | |
993 | if (tmp.test_flag(CEPH_OSDMAP_NEARFULL)) { | |
994 | dout(10) << __func__ << " clearing nearfull flag" << dendl; | |
995 | remove_flag(CEPH_OSDMAP_NEARFULL); | |
996 | } | |
997 | } | |
998 | } | |
999 | ||
1000 | // min_compat_client? | |
31f18b77 | 1001 | if (tmp.require_min_compat_client == 0) { |
7c673cae | 1002 | auto mv = tmp.get_min_compat_client(); |
31f18b77 FG |
1003 | dout(1) << __func__ << " setting require_min_compat_client to currently " |
1004 | << "required " << ceph_release_name(mv) << dendl; | |
1005 | mon->clog->info() << "setting require_min_compat_client to currently " | |
1006 | << "required " << ceph_release_name(mv); | |
1007 | pending_inc.new_require_min_compat_client = mv; | |
7c673cae | 1008 | } |
224ce89b WB |
1009 | |
1010 | if (osdmap.require_osd_release < CEPH_RELEASE_LUMINOUS) { | |
1011 | // convert ec profile ruleset-* -> crush-* | |
1012 | for (auto& p : tmp.erasure_code_profiles) { | |
1013 | bool changed = false; | |
1014 | map<string,string> newprofile; | |
1015 | for (auto& q : p.second) { | |
1016 | if (q.first.find("ruleset-") == 0) { | |
1017 | string key = "crush-"; | |
1018 | key += q.first.substr(8); | |
1019 | newprofile[key] = q.second; | |
1020 | changed = true; | |
1021 | dout(20) << " updating ec profile " << p.first | |
1022 | << " key " << q.first << " -> " << key << dendl; | |
1023 | } else { | |
1024 | newprofile[q.first] = q.second; | |
1025 | } | |
1026 | } | |
1027 | if (changed) { | |
1028 | dout(10) << " updated ec profile " << p.first << ": " | |
1029 | << newprofile << dendl; | |
1030 | pending_inc.new_erasure_code_profiles[p.first] = newprofile; | |
1031 | } | |
1032 | } | |
c07f9fc5 FG |
1033 | |
1034 | // auto-enable pool applications upon upgrade | |
1035 | // NOTE: this can be removed post-Luminous assuming upgrades need to | |
1036 | // proceed through Luminous | |
1037 | for (auto &pool_pair : tmp.pools) { | |
1038 | int64_t pool_id = pool_pair.first; | |
1039 | pg_pool_t pg_pool = pool_pair.second; | |
1040 | if (pg_pool.is_tier()) { | |
1041 | continue; | |
1042 | } | |
1043 | ||
1044 | std::string pool_name = tmp.get_pool_name(pool_id); | |
1045 | uint32_t match_count = 0; | |
1046 | ||
1047 | // CephFS | |
1048 | FSMap const &pending_fsmap = mon->mdsmon()->get_pending(); | |
1049 | if (pending_fsmap.pool_in_use(pool_id)) { | |
1050 | dout(10) << __func__ << " auto-enabling CephFS on pool '" | |
1051 | << pool_name << "'" << dendl; | |
1052 | pg_pool.application_metadata.insert( | |
1053 | {pg_pool_t::APPLICATION_NAME_CEPHFS, {}}); | |
1054 | ++match_count; | |
1055 | } | |
1056 | ||
1057 | // RBD heuristics (default OpenStack pool names from docs and | |
1058 | // ceph-ansible) | |
1059 | if (boost::algorithm::contains(pool_name, "rbd") || | |
1060 | pool_name == "images" || pool_name == "volumes" || | |
1061 | pool_name == "backups" || pool_name == "vms") { | |
1062 | dout(10) << __func__ << " auto-enabling RBD on pool '" | |
1063 | << pool_name << "'" << dendl; | |
1064 | pg_pool.application_metadata.insert( | |
1065 | {pg_pool_t::APPLICATION_NAME_RBD, {}}); | |
1066 | ++match_count; | |
1067 | } | |
1068 | ||
1069 | // RGW heuristics | |
1070 | if (boost::algorithm::contains(pool_name, ".rgw") || | |
1071 | boost::algorithm::contains(pool_name, ".log") || | |
1072 | boost::algorithm::contains(pool_name, ".intent-log") || | |
1073 | boost::algorithm::contains(pool_name, ".usage") || | |
1074 | boost::algorithm::contains(pool_name, ".users")) { | |
1075 | dout(10) << __func__ << " auto-enabling RGW on pool '" | |
1076 | << pool_name << "'" << dendl; | |
1077 | pg_pool.application_metadata.insert( | |
1078 | {pg_pool_t::APPLICATION_NAME_RGW, {}}); | |
1079 | ++match_count; | |
1080 | } | |
1081 | ||
1082 | // OpenStack gnocchi (from ceph-ansible) | |
1083 | if (pool_name == "metrics" && match_count == 0) { | |
1084 | dout(10) << __func__ << " auto-enabling OpenStack Gnocchi on pool '" | |
1085 | << pool_name << "'" << dendl; | |
1086 | pg_pool.application_metadata.insert({"openstack_gnocchi", {}}); | |
1087 | ++match_count; | |
1088 | } | |
1089 | ||
1090 | if (match_count == 1) { | |
1091 | pg_pool.last_change = pending_inc.epoch; | |
1092 | pending_inc.new_pools[pool_id] = pg_pool; | |
1093 | } else if (match_count > 1) { | |
1094 | auto pstat = mon->pgservice->get_pool_stat(pool_id); | |
1095 | if (pstat != nullptr && pstat->stats.sum.num_objects > 0) { | |
1096 | mon->clog->info() << "unable to auto-enable application for pool " | |
1097 | << "'" << pool_name << "'"; | |
1098 | } | |
1099 | } | |
1100 | } | |
224ce89b | 1101 | } |
7c673cae FG |
1102 | } |
1103 | } | |
1104 | ||
1105 | // tell me about it | |
31f18b77 | 1106 | for (auto i = pending_inc.new_state.begin(); |
7c673cae FG |
1107 | i != pending_inc.new_state.end(); |
1108 | ++i) { | |
1109 | int s = i->second ? i->second : CEPH_OSD_UP; | |
1110 | if (s & CEPH_OSD_UP) | |
1111 | dout(2) << " osd." << i->first << " DOWN" << dendl; | |
1112 | if (s & CEPH_OSD_EXISTS) | |
1113 | dout(2) << " osd." << i->first << " DNE" << dendl; | |
1114 | } | |
1115 | for (map<int32_t,entity_addr_t>::iterator i = pending_inc.new_up_client.begin(); | |
1116 | i != pending_inc.new_up_client.end(); | |
1117 | ++i) { | |
1118 | //FIXME: insert cluster addresses too | |
1119 | dout(2) << " osd." << i->first << " UP " << i->second << dendl; | |
1120 | } | |
1121 | for (map<int32_t,uint32_t>::iterator i = pending_inc.new_weight.begin(); | |
1122 | i != pending_inc.new_weight.end(); | |
1123 | ++i) { | |
1124 | if (i->second == CEPH_OSD_OUT) { | |
1125 | dout(2) << " osd." << i->first << " OUT" << dendl; | |
1126 | } else if (i->second == CEPH_OSD_IN) { | |
1127 | dout(2) << " osd." << i->first << " IN" << dendl; | |
1128 | } else { | |
1129 | dout(2) << " osd." << i->first << " WEIGHT " << hex << i->second << dec << dendl; | |
1130 | } | |
1131 | } | |
1132 | ||
1133 | // features for osdmap and its incremental | |
1134 | uint64_t features = mon->get_quorum_con_features(); | |
1135 | ||
1136 | // encode full map and determine its crc | |
1137 | OSDMap tmp; | |
1138 | { | |
1139 | tmp.deepish_copy_from(osdmap); | |
1140 | tmp.apply_incremental(pending_inc); | |
1141 | ||
1142 | // determine appropriate features | |
31f18b77 | 1143 | if (tmp.require_osd_release < CEPH_RELEASE_LUMINOUS) { |
7c673cae FG |
1144 | dout(10) << __func__ << " encoding without feature SERVER_LUMINOUS" |
1145 | << dendl; | |
1146 | features &= ~CEPH_FEATURE_SERVER_LUMINOUS; | |
1147 | } | |
31f18b77 | 1148 | if (tmp.require_osd_release < CEPH_RELEASE_KRAKEN) { |
7c673cae FG |
1149 | dout(10) << __func__ << " encoding without feature SERVER_KRAKEN | " |
1150 | << "MSG_ADDR2" << dendl; | |
1151 | features &= ~(CEPH_FEATURE_SERVER_KRAKEN | | |
1152 | CEPH_FEATURE_MSG_ADDR2); | |
1153 | } | |
31f18b77 FG |
1154 | if (tmp.require_osd_release < CEPH_RELEASE_JEWEL) { |
1155 | dout(10) << __func__ << " encoding without feature SERVER_JEWEL" << dendl; | |
1156 | features &= ~CEPH_FEATURE_SERVER_JEWEL; | |
1157 | } | |
7c673cae FG |
1158 | dout(10) << __func__ << " encoding full map with " << features << dendl; |
1159 | ||
1160 | bufferlist fullbl; | |
1161 | ::encode(tmp, fullbl, features | CEPH_FEATURE_RESERVED); | |
1162 | pending_inc.full_crc = tmp.get_crc(); | |
1163 | ||
1164 | // include full map in the txn. note that old monitors will | |
1165 | // overwrite this. new ones will now skip the local full map | |
1166 | // encode and reload from this. | |
1167 | put_version_full(t, pending_inc.epoch, fullbl); | |
1168 | } | |
1169 | ||
1170 | // encode | |
1171 | assert(get_last_committed() + 1 == pending_inc.epoch); | |
1172 | ::encode(pending_inc, bl, features | CEPH_FEATURE_RESERVED); | |
1173 | ||
1174 | dout(20) << " full_crc " << tmp.get_crc() | |
1175 | << " inc_crc " << pending_inc.inc_crc << dendl; | |
1176 | ||
1177 | /* put everything in the transaction */ | |
1178 | put_version(t, pending_inc.epoch, bl); | |
1179 | put_last_committed(t, pending_inc.epoch); | |
1180 | ||
1181 | // metadata, too! | |
1182 | for (map<int,bufferlist>::iterator p = pending_metadata.begin(); | |
1183 | p != pending_metadata.end(); | |
1184 | ++p) | |
1185 | t->put(OSD_METADATA_PREFIX, stringify(p->first), p->second); | |
1186 | for (set<int>::iterator p = pending_metadata_rm.begin(); | |
1187 | p != pending_metadata_rm.end(); | |
1188 | ++p) | |
1189 | t->erase(OSD_METADATA_PREFIX, stringify(*p)); | |
1190 | pending_metadata.clear(); | |
1191 | pending_metadata_rm.clear(); | |
1192 | ||
1193 | // and pg creating, also! | |
1194 | if (mon->monmap->get_required_features().contains_all( | |
1195 | ceph::features::mon::FEATURE_LUMINOUS)) { | |
1196 | auto pending_creatings = update_pending_pgs(pending_inc); | |
31f18b77 FG |
1197 | if (osdmap.get_epoch() && |
1198 | osdmap.require_osd_release < CEPH_RELEASE_LUMINOUS) { | |
7c673cae FG |
1199 | dout(7) << __func__ << " in the middle of upgrading, " |
1200 | << " trimming pending creating_pgs using pgmap" << dendl; | |
31f18b77 | 1201 | mon->pgservice->maybe_trim_creating_pgs(&pending_creatings); |
7c673cae FG |
1202 | } |
1203 | bufferlist creatings_bl; | |
1204 | ::encode(pending_creatings, creatings_bl); | |
1205 | t->put(OSD_PG_CREATING_PREFIX, "creating", creatings_bl); | |
1206 | } | |
224ce89b WB |
1207 | |
1208 | // health | |
1209 | health_check_map_t next; | |
1210 | tmp.check_health(&next); | |
1211 | encode_health(next, t); | |
7c673cae FG |
1212 | } |
1213 | ||
1214 | void OSDMonitor::trim_creating_pgs(creating_pgs_t* creating_pgs, | |
31f18b77 | 1215 | const ceph::unordered_map<pg_t,pg_stat_t>& pg_stat) |
7c673cae FG |
1216 | { |
1217 | auto p = creating_pgs->pgs.begin(); | |
1218 | while (p != creating_pgs->pgs.end()) { | |
31f18b77 FG |
1219 | auto q = pg_stat.find(p->first); |
1220 | if (q != pg_stat.end() && | |
7c673cae FG |
1221 | !(q->second.state & PG_STATE_CREATING)) { |
1222 | dout(20) << __func__ << " pgmap shows " << p->first << " is created" | |
1223 | << dendl; | |
1224 | p = creating_pgs->pgs.erase(p); | |
7c673cae FG |
1225 | } else { |
1226 | ++p; | |
1227 | } | |
1228 | } | |
1229 | } | |
1230 | ||
1231 | int OSDMonitor::load_metadata(int osd, map<string, string>& m, ostream *err) | |
1232 | { | |
1233 | bufferlist bl; | |
1234 | int r = mon->store->get(OSD_METADATA_PREFIX, stringify(osd), bl); | |
1235 | if (r < 0) | |
1236 | return r; | |
1237 | try { | |
1238 | bufferlist::iterator p = bl.begin(); | |
1239 | ::decode(m, p); | |
1240 | } | |
1241 | catch (buffer::error& e) { | |
1242 | if (err) | |
1243 | *err << "osd." << osd << " metadata is corrupt"; | |
1244 | return -EIO; | |
1245 | } | |
1246 | return 0; | |
1247 | } | |
1248 | ||
c07f9fc5 | 1249 | void OSDMonitor::count_metadata(const string& field, map<string,int> *out) |
31f18b77 | 1250 | { |
31f18b77 FG |
1251 | for (int osd = 0; osd < osdmap.get_max_osd(); ++osd) { |
1252 | if (osdmap.is_up(osd)) { | |
1253 | map<string,string> meta; | |
1254 | load_metadata(osd, meta, nullptr); | |
1255 | auto p = meta.find(field); | |
1256 | if (p == meta.end()) { | |
c07f9fc5 | 1257 | (*out)["unknown"]++; |
31f18b77 | 1258 | } else { |
c07f9fc5 | 1259 | (*out)[p->second]++; |
31f18b77 FG |
1260 | } |
1261 | } | |
1262 | } | |
c07f9fc5 FG |
1263 | } |
1264 | ||
1265 | void OSDMonitor::count_metadata(const string& field, Formatter *f) | |
1266 | { | |
1267 | map<string,int> by_val; | |
1268 | count_metadata(field, &by_val); | |
31f18b77 FG |
1269 | f->open_object_section(field.c_str()); |
1270 | for (auto& p : by_val) { | |
1271 | f->dump_int(p.first.c_str(), p.second); | |
1272 | } | |
1273 | f->close_section(); | |
1274 | } | |
1275 | ||
7c673cae FG |
1276 | int OSDMonitor::get_osd_objectstore_type(int osd, string *type) |
1277 | { | |
1278 | map<string, string> metadata; | |
1279 | int r = load_metadata(osd, metadata, nullptr); | |
1280 | if (r < 0) | |
1281 | return r; | |
1282 | ||
1283 | auto it = metadata.find("osd_objectstore"); | |
1284 | if (it == metadata.end()) | |
1285 | return -ENOENT; | |
1286 | *type = it->second; | |
1287 | return 0; | |
1288 | } | |
1289 | ||
1290 | bool OSDMonitor::is_pool_currently_all_bluestore(int64_t pool_id, | |
1291 | const pg_pool_t &pool, | |
1292 | ostream *err) | |
1293 | { | |
1294 | // just check a few pgs for efficiency - this can't give a guarantee anyway, | |
1295 | // since filestore osds could always join the pool later | |
1296 | set<int> checked_osds; | |
1297 | for (unsigned ps = 0; ps < MIN(8, pool.get_pg_num()); ++ps) { | |
1298 | vector<int> up, acting; | |
1299 | pg_t pgid(ps, pool_id, -1); | |
1300 | osdmap.pg_to_up_acting_osds(pgid, up, acting); | |
1301 | for (int osd : up) { | |
1302 | if (checked_osds.find(osd) != checked_osds.end()) | |
1303 | continue; | |
1304 | string objectstore_type; | |
1305 | int r = get_osd_objectstore_type(osd, &objectstore_type); | |
1306 | // allow with missing metadata, e.g. due to an osd never booting yet | |
1307 | if (r < 0 || objectstore_type == "bluestore") { | |
1308 | checked_osds.insert(osd); | |
1309 | continue; | |
1310 | } | |
1311 | *err << "osd." << osd << " uses " << objectstore_type; | |
1312 | return false; | |
1313 | } | |
1314 | } | |
1315 | return true; | |
1316 | } | |
1317 | ||
1318 | int OSDMonitor::dump_osd_metadata(int osd, Formatter *f, ostream *err) | |
1319 | { | |
1320 | map<string,string> m; | |
1321 | if (int r = load_metadata(osd, m, err)) | |
1322 | return r; | |
1323 | for (map<string,string>::iterator p = m.begin(); p != m.end(); ++p) | |
1324 | f->dump_string(p->first.c_str(), p->second); | |
1325 | return 0; | |
1326 | } | |
1327 | ||
1328 | void OSDMonitor::print_nodes(Formatter *f) | |
1329 | { | |
1330 | // group OSDs by their hosts | |
1331 | map<string, list<int> > osds; // hostname => osd | |
1332 | for (int osd = 0; osd < osdmap.get_max_osd(); osd++) { | |
1333 | map<string, string> m; | |
1334 | if (load_metadata(osd, m, NULL)) { | |
1335 | continue; | |
1336 | } | |
1337 | map<string, string>::iterator hostname = m.find("hostname"); | |
1338 | if (hostname == m.end()) { | |
1339 | // not likely though | |
1340 | continue; | |
1341 | } | |
1342 | osds[hostname->second].push_back(osd); | |
1343 | } | |
1344 | ||
1345 | dump_services(f, osds, "osd"); | |
1346 | } | |
1347 | ||
1348 | void OSDMonitor::share_map_with_random_osd() | |
1349 | { | |
1350 | if (osdmap.get_num_up_osds() == 0) { | |
1351 | dout(10) << __func__ << " no up osds, don't share with anyone" << dendl; | |
1352 | return; | |
1353 | } | |
1354 | ||
1355 | MonSession *s = mon->session_map.get_random_osd_session(&osdmap); | |
1356 | if (!s) { | |
1357 | dout(10) << __func__ << " no up osd on our session map" << dendl; | |
1358 | return; | |
1359 | } | |
1360 | ||
1361 | dout(10) << "committed, telling random " << s->inst << " all about it" << dendl; | |
1362 | // whatev, they'll request more if they need it | |
1363 | MOSDMap *m = build_incremental(osdmap.get_epoch() - 1, osdmap.get_epoch()); | |
1364 | s->con->send_message(m); | |
1365 | // NOTE: do *not* record osd has up to this epoch (as we do | |
1366 | // elsewhere) as they may still need to request older values. | |
1367 | } | |
1368 | ||
1369 | version_t OSDMonitor::get_trim_to() | |
1370 | { | |
31f18b77 FG |
1371 | if (mon->get_quorum().empty()) { |
1372 | dout(10) << __func__ << ": quorum not formed" << dendl; | |
1373 | return 0; | |
1374 | } | |
7c673cae | 1375 | |
31f18b77 | 1376 | epoch_t floor; |
7c673cae FG |
1377 | if (mon->monmap->get_required_features().contains_all( |
1378 | ceph::features::mon::FEATURE_LUMINOUS)) { | |
1379 | { | |
31f18b77 | 1380 | // TODO: Get this hidden in PGStatService |
7c673cae FG |
1381 | std::lock_guard<std::mutex> l(creating_pgs_lock); |
1382 | if (!creating_pgs.pgs.empty()) { | |
1383 | return 0; | |
1384 | } | |
1385 | } | |
1386 | floor = get_min_last_epoch_clean(); | |
1387 | } else { | |
31f18b77 | 1388 | if (!mon->pgservice->is_readable()) |
7c673cae | 1389 | return 0; |
31f18b77 | 1390 | if (mon->pgservice->have_creating_pgs()) { |
7c673cae FG |
1391 | return 0; |
1392 | } | |
31f18b77 | 1393 | floor = mon->pgservice->get_min_last_epoch_clean(); |
7c673cae FG |
1394 | } |
1395 | { | |
1396 | dout(10) << " min_last_epoch_clean " << floor << dendl; | |
1397 | if (g_conf->mon_osd_force_trim_to > 0 && | |
1398 | g_conf->mon_osd_force_trim_to < (int)get_last_committed()) { | |
1399 | floor = g_conf->mon_osd_force_trim_to; | |
1400 | dout(10) << " explicit mon_osd_force_trim_to = " << floor << dendl; | |
1401 | } | |
1402 | unsigned min = g_conf->mon_min_osdmap_epochs; | |
1403 | if (floor + min > get_last_committed()) { | |
1404 | if (min < get_last_committed()) | |
1405 | floor = get_last_committed() - min; | |
1406 | else | |
1407 | floor = 0; | |
1408 | } | |
1409 | if (floor > get_first_committed()) | |
1410 | return floor; | |
1411 | } | |
1412 | return 0; | |
1413 | } | |
1414 | ||
1415 | epoch_t OSDMonitor::get_min_last_epoch_clean() const | |
1416 | { | |
1417 | auto floor = last_epoch_clean.get_lower_bound(osdmap); | |
1418 | // also scan osd epochs | |
1419 | // don't trim past the oldest reported osd epoch | |
1420 | for (auto& osd_epoch : osd_epochs) { | |
1421 | if (osd_epoch.second < floor) { | |
1422 | floor = osd_epoch.second; | |
1423 | } | |
1424 | } | |
1425 | return floor; | |
1426 | } | |
1427 | ||
1428 | void OSDMonitor::encode_trim_extra(MonitorDBStore::TransactionRef tx, | |
1429 | version_t first) | |
1430 | { | |
1431 | dout(10) << __func__ << " including full map for e " << first << dendl; | |
1432 | bufferlist bl; | |
1433 | get_version_full(first, bl); | |
1434 | put_version_full(tx, first, bl); | |
1435 | } | |
1436 | ||
1437 | // ------------- | |
1438 | ||
1439 | bool OSDMonitor::preprocess_query(MonOpRequestRef op) | |
1440 | { | |
1441 | op->mark_osdmon_event(__func__); | |
1442 | Message *m = op->get_req(); | |
1443 | dout(10) << "preprocess_query " << *m << " from " << m->get_orig_source_inst() << dendl; | |
1444 | ||
1445 | switch (m->get_type()) { | |
1446 | // READs | |
1447 | case MSG_MON_COMMAND: | |
1448 | return preprocess_command(op); | |
1449 | case CEPH_MSG_MON_GET_OSDMAP: | |
1450 | return preprocess_get_osdmap(op); | |
1451 | ||
1452 | // damp updates | |
1453 | case MSG_OSD_MARK_ME_DOWN: | |
1454 | return preprocess_mark_me_down(op); | |
1455 | case MSG_OSD_FULL: | |
1456 | return preprocess_full(op); | |
1457 | case MSG_OSD_FAILURE: | |
1458 | return preprocess_failure(op); | |
1459 | case MSG_OSD_BOOT: | |
1460 | return preprocess_boot(op); | |
1461 | case MSG_OSD_ALIVE: | |
1462 | return preprocess_alive(op); | |
1463 | case MSG_OSD_PG_CREATED: | |
1464 | return preprocess_pg_created(op); | |
1465 | case MSG_OSD_PGTEMP: | |
1466 | return preprocess_pgtemp(op); | |
1467 | case MSG_OSD_BEACON: | |
1468 | return preprocess_beacon(op); | |
1469 | ||
1470 | case CEPH_MSG_POOLOP: | |
1471 | return preprocess_pool_op(op); | |
1472 | ||
1473 | case MSG_REMOVE_SNAPS: | |
1474 | return preprocess_remove_snaps(op); | |
1475 | ||
1476 | default: | |
1477 | ceph_abort(); | |
1478 | return true; | |
1479 | } | |
1480 | } | |
1481 | ||
1482 | bool OSDMonitor::prepare_update(MonOpRequestRef op) | |
1483 | { | |
1484 | op->mark_osdmon_event(__func__); | |
1485 | Message *m = op->get_req(); | |
1486 | dout(7) << "prepare_update " << *m << " from " << m->get_orig_source_inst() << dendl; | |
1487 | ||
1488 | switch (m->get_type()) { | |
1489 | // damp updates | |
1490 | case MSG_OSD_MARK_ME_DOWN: | |
1491 | return prepare_mark_me_down(op); | |
1492 | case MSG_OSD_FULL: | |
1493 | return prepare_full(op); | |
1494 | case MSG_OSD_FAILURE: | |
1495 | return prepare_failure(op); | |
1496 | case MSG_OSD_BOOT: | |
1497 | return prepare_boot(op); | |
1498 | case MSG_OSD_ALIVE: | |
1499 | return prepare_alive(op); | |
1500 | case MSG_OSD_PG_CREATED: | |
1501 | return prepare_pg_created(op); | |
1502 | case MSG_OSD_PGTEMP: | |
1503 | return prepare_pgtemp(op); | |
1504 | case MSG_OSD_BEACON: | |
1505 | return prepare_beacon(op); | |
1506 | ||
1507 | case MSG_MON_COMMAND: | |
1508 | return prepare_command(op); | |
1509 | ||
1510 | case CEPH_MSG_POOLOP: | |
1511 | return prepare_pool_op(op); | |
1512 | ||
1513 | case MSG_REMOVE_SNAPS: | |
1514 | return prepare_remove_snaps(op); | |
1515 | ||
1516 | ||
1517 | default: | |
1518 | ceph_abort(); | |
1519 | } | |
1520 | ||
1521 | return false; | |
1522 | } | |
1523 | ||
1524 | bool OSDMonitor::should_propose(double& delay) | |
1525 | { | |
1526 | dout(10) << "should_propose" << dendl; | |
1527 | ||
1528 | // if full map, propose immediately! any subsequent changes will be clobbered. | |
1529 | if (pending_inc.fullmap.length()) | |
1530 | return true; | |
1531 | ||
1532 | // adjust osd weights? | |
1533 | if (!osd_weight.empty() && | |
1534 | osd_weight.size() == (unsigned)osdmap.get_max_osd()) { | |
1535 | dout(0) << " adjusting osd weights based on " << osd_weight << dendl; | |
1536 | osdmap.adjust_osd_weights(osd_weight, pending_inc); | |
1537 | delay = 0.0; | |
1538 | osd_weight.clear(); | |
1539 | return true; | |
1540 | } | |
1541 | ||
1542 | // propose as fast as possible if updating up_thru or pg_temp | |
1543 | // want to merge OSDMap changes as much as possible | |
1544 | if ((pending_inc.new_primary_temp.size() == 1 | |
1545 | || pending_inc.new_up_thru.size() == 1) | |
1546 | && pending_inc.new_state.size() < 2) { | |
1547 | dout(15) << " propose as fast as possible for up_thru/pg_temp" << dendl; | |
1548 | ||
1549 | utime_t now = ceph_clock_now(); | |
1550 | if (now - last_attempted_minwait_time > g_conf->paxos_propose_interval | |
1551 | && now - paxos->get_last_commit_time() > g_conf->paxos_min_wait) { | |
1552 | delay = g_conf->paxos_min_wait; | |
1553 | last_attempted_minwait_time = now; | |
1554 | return true; | |
1555 | } | |
1556 | } | |
1557 | ||
1558 | return PaxosService::should_propose(delay); | |
1559 | } | |
1560 | ||
1561 | ||
1562 | ||
1563 | // --------------------------- | |
1564 | // READs | |
1565 | ||
1566 | bool OSDMonitor::preprocess_get_osdmap(MonOpRequestRef op) | |
1567 | { | |
1568 | op->mark_osdmon_event(__func__); | |
1569 | MMonGetOSDMap *m = static_cast<MMonGetOSDMap*>(op->get_req()); | |
1570 | dout(10) << __func__ << " " << *m << dendl; | |
1571 | MOSDMap *reply = new MOSDMap(mon->monmap->fsid); | |
1572 | epoch_t first = get_first_committed(); | |
1573 | epoch_t last = osdmap.get_epoch(); | |
1574 | int max = g_conf->osd_map_message_max; | |
1575 | for (epoch_t e = MAX(first, m->get_full_first()); | |
1576 | e <= MIN(last, m->get_full_last()) && max > 0; | |
1577 | ++e, --max) { | |
1578 | int r = get_version_full(e, reply->maps[e]); | |
1579 | assert(r >= 0); | |
1580 | } | |
1581 | for (epoch_t e = MAX(first, m->get_inc_first()); | |
1582 | e <= MIN(last, m->get_inc_last()) && max > 0; | |
1583 | ++e, --max) { | |
1584 | int r = get_version(e, reply->incremental_maps[e]); | |
1585 | assert(r >= 0); | |
1586 | } | |
1587 | reply->oldest_map = first; | |
1588 | reply->newest_map = last; | |
1589 | mon->send_reply(op, reply); | |
1590 | return true; | |
1591 | } | |
1592 | ||
1593 | ||
1594 | // --------------------------- | |
1595 | // UPDATEs | |
1596 | ||
1597 | // failure -- | |
1598 | ||
1599 | bool OSDMonitor::check_source(PaxosServiceMessage *m, uuid_d fsid) { | |
1600 | // check permissions | |
1601 | MonSession *session = m->get_session(); | |
1602 | if (!session) | |
1603 | return true; | |
1604 | if (!session->is_capable("osd", MON_CAP_X)) { | |
1605 | dout(0) << "got MOSDFailure from entity with insufficient caps " | |
1606 | << session->caps << dendl; | |
1607 | return true; | |
1608 | } | |
1609 | if (fsid != mon->monmap->fsid) { | |
1610 | dout(0) << "check_source: on fsid " << fsid | |
1611 | << " != " << mon->monmap->fsid << dendl; | |
1612 | return true; | |
1613 | } | |
1614 | return false; | |
1615 | } | |
1616 | ||
1617 | ||
1618 | bool OSDMonitor::preprocess_failure(MonOpRequestRef op) | |
1619 | { | |
1620 | op->mark_osdmon_event(__func__); | |
1621 | MOSDFailure *m = static_cast<MOSDFailure*>(op->get_req()); | |
1622 | // who is target_osd | |
1623 | int badboy = m->get_target().name.num(); | |
1624 | ||
1625 | // check permissions | |
1626 | if (check_source(m, m->fsid)) | |
1627 | goto didit; | |
1628 | ||
1629 | // first, verify the reporting host is valid | |
1630 | if (m->get_orig_source().is_osd()) { | |
1631 | int from = m->get_orig_source().num(); | |
1632 | if (!osdmap.exists(from) || | |
1633 | osdmap.get_addr(from) != m->get_orig_source_inst().addr || | |
1634 | (osdmap.is_down(from) && m->if_osd_failed())) { | |
1635 | dout(5) << "preprocess_failure from dead osd." << from << ", ignoring" << dendl; | |
1636 | send_incremental(op, m->get_epoch()+1); | |
1637 | goto didit; | |
1638 | } | |
1639 | } | |
1640 | ||
1641 | ||
1642 | // weird? | |
1643 | if (osdmap.is_down(badboy)) { | |
1644 | dout(5) << "preprocess_failure dne(/dup?): " << m->get_target() << ", from " << m->get_orig_source_inst() << dendl; | |
1645 | if (m->get_epoch() < osdmap.get_epoch()) | |
1646 | send_incremental(op, m->get_epoch()+1); | |
1647 | goto didit; | |
1648 | } | |
1649 | if (osdmap.get_inst(badboy) != m->get_target()) { | |
1650 | dout(5) << "preprocess_failure wrong osd: report " << m->get_target() << " != map's " << osdmap.get_inst(badboy) | |
1651 | << ", from " << m->get_orig_source_inst() << dendl; | |
1652 | if (m->get_epoch() < osdmap.get_epoch()) | |
1653 | send_incremental(op, m->get_epoch()+1); | |
1654 | goto didit; | |
1655 | } | |
1656 | ||
1657 | // already reported? | |
1658 | if (osdmap.is_down(badboy) || | |
1659 | osdmap.get_up_from(badboy) > m->get_epoch()) { | |
1660 | dout(5) << "preprocess_failure dup/old: " << m->get_target() << ", from " << m->get_orig_source_inst() << dendl; | |
1661 | if (m->get_epoch() < osdmap.get_epoch()) | |
1662 | send_incremental(op, m->get_epoch()+1); | |
1663 | goto didit; | |
1664 | } | |
1665 | ||
1666 | if (!can_mark_down(badboy)) { | |
1667 | dout(5) << "preprocess_failure ignoring report of " << m->get_target() << " from " << m->get_orig_source_inst() << dendl; | |
1668 | goto didit; | |
1669 | } | |
1670 | ||
1671 | dout(10) << "preprocess_failure new: " << m->get_target() << ", from " << m->get_orig_source_inst() << dendl; | |
1672 | return false; | |
1673 | ||
1674 | didit: | |
1675 | return true; | |
1676 | } | |
1677 | ||
1678 | class C_AckMarkedDown : public C_MonOp { | |
1679 | OSDMonitor *osdmon; | |
1680 | public: | |
1681 | C_AckMarkedDown( | |
1682 | OSDMonitor *osdmon, | |
1683 | MonOpRequestRef op) | |
1684 | : C_MonOp(op), osdmon(osdmon) {} | |
1685 | ||
1686 | void _finish(int) override { | |
1687 | MOSDMarkMeDown *m = static_cast<MOSDMarkMeDown*>(op->get_req()); | |
1688 | osdmon->mon->send_reply( | |
1689 | op, | |
1690 | new MOSDMarkMeDown( | |
1691 | m->fsid, | |
1692 | m->get_target(), | |
1693 | m->get_epoch(), | |
1694 | false)); // ACK itself does not request an ack | |
1695 | } | |
1696 | ~C_AckMarkedDown() override { | |
1697 | } | |
1698 | }; | |
1699 | ||
1700 | bool OSDMonitor::preprocess_mark_me_down(MonOpRequestRef op) | |
1701 | { | |
1702 | op->mark_osdmon_event(__func__); | |
1703 | MOSDMarkMeDown *m = static_cast<MOSDMarkMeDown*>(op->get_req()); | |
1704 | int requesting_down = m->get_target().name.num(); | |
1705 | int from = m->get_orig_source().num(); | |
1706 | ||
1707 | // check permissions | |
1708 | if (check_source(m, m->fsid)) | |
1709 | goto reply; | |
1710 | ||
1711 | // first, verify the reporting host is valid | |
1712 | if (!m->get_orig_source().is_osd()) | |
1713 | goto reply; | |
1714 | ||
1715 | if (!osdmap.exists(from) || | |
1716 | osdmap.is_down(from) || | |
1717 | osdmap.get_addr(from) != m->get_target().addr) { | |
1718 | dout(5) << "preprocess_mark_me_down from dead osd." | |
1719 | << from << ", ignoring" << dendl; | |
1720 | send_incremental(op, m->get_epoch()+1); | |
1721 | goto reply; | |
1722 | } | |
1723 | ||
1724 | // no down might be set | |
1725 | if (!can_mark_down(requesting_down)) | |
1726 | goto reply; | |
1727 | ||
1728 | dout(10) << "MOSDMarkMeDown for: " << m->get_target() << dendl; | |
1729 | return false; | |
1730 | ||
1731 | reply: | |
1732 | if (m->request_ack) { | |
1733 | Context *c(new C_AckMarkedDown(this, op)); | |
1734 | c->complete(0); | |
1735 | } | |
1736 | return true; | |
1737 | } | |
1738 | ||
1739 | bool OSDMonitor::prepare_mark_me_down(MonOpRequestRef op) | |
1740 | { | |
1741 | op->mark_osdmon_event(__func__); | |
1742 | MOSDMarkMeDown *m = static_cast<MOSDMarkMeDown*>(op->get_req()); | |
1743 | int target_osd = m->get_target().name.num(); | |
1744 | ||
1745 | assert(osdmap.is_up(target_osd)); | |
1746 | assert(osdmap.get_addr(target_osd) == m->get_target().addr); | |
1747 | ||
1748 | mon->clog->info() << "osd." << target_osd << " marked itself down"; | |
1749 | pending_inc.new_state[target_osd] = CEPH_OSD_UP; | |
1750 | if (m->request_ack) | |
1751 | wait_for_finished_proposal(op, new C_AckMarkedDown(this, op)); | |
1752 | return true; | |
1753 | } | |
1754 | ||
1755 | bool OSDMonitor::can_mark_down(int i) | |
1756 | { | |
1757 | if (osdmap.test_flag(CEPH_OSDMAP_NODOWN)) { | |
31f18b77 FG |
1758 | dout(5) << __func__ << " NODOWN flag set, will not mark osd." << i |
1759 | << " down" << dendl; | |
1760 | return false; | |
1761 | } | |
1762 | ||
1763 | if (osdmap.is_nodown(i)) { | |
1764 | dout(5) << __func__ << " osd." << i << " is marked as nodown, " | |
1765 | << "will not mark it down" << dendl; | |
7c673cae FG |
1766 | return false; |
1767 | } | |
31f18b77 | 1768 | |
7c673cae FG |
1769 | int num_osds = osdmap.get_num_osds(); |
1770 | if (num_osds == 0) { | |
31f18b77 | 1771 | dout(5) << __func__ << " no osds" << dendl; |
7c673cae FG |
1772 | return false; |
1773 | } | |
1774 | int up = osdmap.get_num_up_osds() - pending_inc.get_net_marked_down(&osdmap); | |
1775 | float up_ratio = (float)up / (float)num_osds; | |
1776 | if (up_ratio < g_conf->mon_osd_min_up_ratio) { | |
31f18b77 | 1777 | dout(2) << __func__ << " current up_ratio " << up_ratio << " < min " |
7c673cae FG |
1778 | << g_conf->mon_osd_min_up_ratio |
1779 | << ", will not mark osd." << i << " down" << dendl; | |
1780 | return false; | |
1781 | } | |
1782 | return true; | |
1783 | } | |
1784 | ||
1785 | bool OSDMonitor::can_mark_up(int i) | |
1786 | { | |
1787 | if (osdmap.test_flag(CEPH_OSDMAP_NOUP)) { | |
31f18b77 FG |
1788 | dout(5) << __func__ << " NOUP flag set, will not mark osd." << i |
1789 | << " up" << dendl; | |
1790 | return false; | |
1791 | } | |
1792 | ||
1793 | if (osdmap.is_noup(i)) { | |
1794 | dout(5) << __func__ << " osd." << i << " is marked as noup, " | |
1795 | << "will not mark it up" << dendl; | |
7c673cae FG |
1796 | return false; |
1797 | } | |
31f18b77 | 1798 | |
7c673cae FG |
1799 | return true; |
1800 | } | |
1801 | ||
1802 | /** | |
1803 | * @note the parameter @p i apparently only exists here so we can output the | |
1804 | * osd's id on messages. | |
1805 | */ | |
1806 | bool OSDMonitor::can_mark_out(int i) | |
1807 | { | |
1808 | if (osdmap.test_flag(CEPH_OSDMAP_NOOUT)) { | |
1809 | dout(5) << __func__ << " NOOUT flag set, will not mark osds out" << dendl; | |
1810 | return false; | |
1811 | } | |
31f18b77 FG |
1812 | |
1813 | if (osdmap.is_noout(i)) { | |
1814 | dout(5) << __func__ << " osd." << i << " is marked as noout, " | |
1815 | << "will not mark it out" << dendl; | |
1816 | return false; | |
1817 | } | |
1818 | ||
7c673cae FG |
1819 | int num_osds = osdmap.get_num_osds(); |
1820 | if (num_osds == 0) { | |
1821 | dout(5) << __func__ << " no osds" << dendl; | |
1822 | return false; | |
1823 | } | |
1824 | int in = osdmap.get_num_in_osds() - pending_inc.get_net_marked_out(&osdmap); | |
1825 | float in_ratio = (float)in / (float)num_osds; | |
1826 | if (in_ratio < g_conf->mon_osd_min_in_ratio) { | |
1827 | if (i >= 0) | |
1828 | dout(5) << __func__ << " current in_ratio " << in_ratio << " < min " | |
1829 | << g_conf->mon_osd_min_in_ratio | |
1830 | << ", will not mark osd." << i << " out" << dendl; | |
1831 | else | |
1832 | dout(5) << __func__ << " current in_ratio " << in_ratio << " < min " | |
1833 | << g_conf->mon_osd_min_in_ratio | |
1834 | << ", will not mark osds out" << dendl; | |
1835 | return false; | |
1836 | } | |
1837 | ||
1838 | return true; | |
1839 | } | |
1840 | ||
1841 | bool OSDMonitor::can_mark_in(int i) | |
1842 | { | |
1843 | if (osdmap.test_flag(CEPH_OSDMAP_NOIN)) { | |
31f18b77 FG |
1844 | dout(5) << __func__ << " NOIN flag set, will not mark osd." << i |
1845 | << " in" << dendl; | |
1846 | return false; | |
1847 | } | |
1848 | ||
1849 | if (osdmap.is_noin(i)) { | |
1850 | dout(5) << __func__ << " osd." << i << " is marked as noin, " | |
1851 | << "will not mark it in" << dendl; | |
7c673cae FG |
1852 | return false; |
1853 | } | |
31f18b77 | 1854 | |
7c673cae FG |
1855 | return true; |
1856 | } | |
1857 | ||
1858 | bool OSDMonitor::check_failures(utime_t now) | |
1859 | { | |
1860 | bool found_failure = false; | |
1861 | for (map<int,failure_info_t>::iterator p = failure_info.begin(); | |
1862 | p != failure_info.end(); | |
1863 | ++p) { | |
1864 | if (can_mark_down(p->first)) { | |
1865 | found_failure |= check_failure(now, p->first, p->second); | |
1866 | } | |
1867 | } | |
1868 | return found_failure; | |
1869 | } | |
1870 | ||
1871 | bool OSDMonitor::check_failure(utime_t now, int target_osd, failure_info_t& fi) | |
1872 | { | |
1873 | // already pending failure? | |
1874 | if (pending_inc.new_state.count(target_osd) && | |
1875 | pending_inc.new_state[target_osd] & CEPH_OSD_UP) { | |
1876 | dout(10) << " already pending failure" << dendl; | |
1877 | return true; | |
1878 | } | |
1879 | ||
1880 | set<string> reporters_by_subtree; | |
1881 | string reporter_subtree_level = g_conf->mon_osd_reporter_subtree_level; | |
1882 | utime_t orig_grace(g_conf->osd_heartbeat_grace, 0); | |
1883 | utime_t max_failed_since = fi.get_failed_since(); | |
1884 | utime_t failed_for = now - max_failed_since; | |
1885 | ||
1886 | utime_t grace = orig_grace; | |
1887 | double my_grace = 0, peer_grace = 0; | |
1888 | double decay_k = 0; | |
1889 | if (g_conf->mon_osd_adjust_heartbeat_grace) { | |
1890 | double halflife = (double)g_conf->mon_osd_laggy_halflife; | |
1891 | decay_k = ::log(.5) / halflife; | |
1892 | ||
1893 | // scale grace period based on historical probability of 'lagginess' | |
1894 | // (false positive failures due to slowness). | |
1895 | const osd_xinfo_t& xi = osdmap.get_xinfo(target_osd); | |
1896 | double decay = exp((double)failed_for * decay_k); | |
1897 | dout(20) << " halflife " << halflife << " decay_k " << decay_k | |
1898 | << " failed_for " << failed_for << " decay " << decay << dendl; | |
1899 | my_grace = decay * (double)xi.laggy_interval * xi.laggy_probability; | |
1900 | grace += my_grace; | |
1901 | } | |
1902 | ||
1903 | // consider the peers reporting a failure a proxy for a potential | |
1904 | // 'subcluster' over the overall cluster that is similarly | |
1905 | // laggy. this is clearly not true in all cases, but will sometimes | |
1906 | // help us localize the grace correction to a subset of the system | |
1907 | // (say, a rack with a bad switch) that is unhappy. | |
1908 | assert(fi.reporters.size()); | |
1909 | for (map<int,failure_reporter_t>::iterator p = fi.reporters.begin(); | |
1910 | p != fi.reporters.end(); | |
1911 | ++p) { | |
1912 | // get the parent bucket whose type matches with "reporter_subtree_level". | |
1913 | // fall back to OSD if the level doesn't exist. | |
1914 | map<string, string> reporter_loc = osdmap.crush->get_full_location(p->first); | |
1915 | map<string, string>::iterator iter = reporter_loc.find(reporter_subtree_level); | |
1916 | if (iter == reporter_loc.end()) { | |
1917 | reporters_by_subtree.insert("osd." + to_string(p->first)); | |
1918 | } else { | |
1919 | reporters_by_subtree.insert(iter->second); | |
1920 | } | |
1921 | if (g_conf->mon_osd_adjust_heartbeat_grace) { | |
1922 | const osd_xinfo_t& xi = osdmap.get_xinfo(p->first); | |
1923 | utime_t elapsed = now - xi.down_stamp; | |
1924 | double decay = exp((double)elapsed * decay_k); | |
1925 | peer_grace += decay * (double)xi.laggy_interval * xi.laggy_probability; | |
1926 | } | |
1927 | } | |
1928 | ||
1929 | if (g_conf->mon_osd_adjust_heartbeat_grace) { | |
1930 | peer_grace /= (double)fi.reporters.size(); | |
1931 | grace += peer_grace; | |
1932 | } | |
1933 | ||
1934 | dout(10) << " osd." << target_osd << " has " | |
1935 | << fi.reporters.size() << " reporters, " | |
1936 | << grace << " grace (" << orig_grace << " + " << my_grace | |
1937 | << " + " << peer_grace << "), max_failed_since " << max_failed_since | |
1938 | << dendl; | |
1939 | ||
1940 | if (failed_for >= grace && | |
1941 | (int)reporters_by_subtree.size() >= g_conf->mon_osd_min_down_reporters) { | |
1942 | dout(1) << " we have enough reporters to mark osd." << target_osd | |
1943 | << " down" << dendl; | |
1944 | pending_inc.new_state[target_osd] = CEPH_OSD_UP; | |
1945 | ||
31f18b77 FG |
1946 | mon->clog->info() << "osd." << target_osd << " failed (" |
1947 | << osdmap.crush->get_full_location_ordered_string( | |
1948 | target_osd) | |
1949 | << ") (" | |
1950 | << (int)reporters_by_subtree.size() | |
1951 | << " reporters from different " | |
7c673cae FG |
1952 | << reporter_subtree_level << " after " |
1953 | << failed_for << " >= grace " << grace << ")"; | |
1954 | return true; | |
1955 | } | |
1956 | return false; | |
1957 | } | |
1958 | ||
224ce89b | 1959 | void OSDMonitor::force_failure(int target_osd, int by) |
7c673cae FG |
1960 | { |
1961 | // already pending failure? | |
1962 | if (pending_inc.new_state.count(target_osd) && | |
1963 | pending_inc.new_state[target_osd] & CEPH_OSD_UP) { | |
1964 | dout(10) << " already pending failure" << dendl; | |
1965 | return; | |
1966 | } | |
1967 | ||
1968 | dout(1) << " we're forcing failure of osd." << target_osd << dendl; | |
1969 | pending_inc.new_state[target_osd] = CEPH_OSD_UP; | |
1970 | ||
31f18b77 FG |
1971 | mon->clog->info() << "osd." << target_osd << " failed (" |
1972 | << osdmap.crush->get_full_location_ordered_string(target_osd) | |
1973 | << ") (connection refused reported by osd." << by << ")"; | |
7c673cae FG |
1974 | return; |
1975 | } | |
1976 | ||
1977 | bool OSDMonitor::prepare_failure(MonOpRequestRef op) | |
1978 | { | |
1979 | op->mark_osdmon_event(__func__); | |
1980 | MOSDFailure *m = static_cast<MOSDFailure*>(op->get_req()); | |
1981 | dout(1) << "prepare_failure " << m->get_target() | |
1982 | << " from " << m->get_orig_source_inst() | |
1983 | << " is reporting failure:" << m->if_osd_failed() << dendl; | |
1984 | ||
1985 | int target_osd = m->get_target().name.num(); | |
1986 | int reporter = m->get_orig_source().num(); | |
1987 | assert(osdmap.is_up(target_osd)); | |
1988 | assert(osdmap.get_addr(target_osd) == m->get_target().addr); | |
1989 | ||
1990 | if (m->if_osd_failed()) { | |
1991 | // calculate failure time | |
1992 | utime_t now = ceph_clock_now(); | |
1993 | utime_t failed_since = | |
1994 | m->get_recv_stamp() - utime_t(m->failed_for, 0); | |
1995 | ||
1996 | // add a report | |
1997 | if (m->is_immediate()) { | |
1998 | mon->clog->debug() << m->get_target() << " reported immediately failed by " | |
1999 | << m->get_orig_source_inst(); | |
224ce89b | 2000 | force_failure(target_osd, reporter); |
7c673cae FG |
2001 | return true; |
2002 | } | |
2003 | mon->clog->debug() << m->get_target() << " reported failed by " | |
2004 | << m->get_orig_source_inst(); | |
2005 | ||
2006 | failure_info_t& fi = failure_info[target_osd]; | |
2007 | MonOpRequestRef old_op = fi.add_report(reporter, failed_since, op); | |
2008 | if (old_op) { | |
2009 | mon->no_reply(old_op); | |
2010 | } | |
2011 | ||
2012 | return check_failure(now, target_osd, fi); | |
2013 | } else { | |
2014 | // remove the report | |
2015 | mon->clog->debug() << m->get_target() << " failure report canceled by " | |
2016 | << m->get_orig_source_inst(); | |
2017 | if (failure_info.count(target_osd)) { | |
2018 | failure_info_t& fi = failure_info[target_osd]; | |
2019 | MonOpRequestRef report_op = fi.cancel_report(reporter); | |
2020 | if (report_op) { | |
2021 | mon->no_reply(report_op); | |
2022 | } | |
2023 | if (fi.reporters.empty()) { | |
2024 | dout(10) << " removing last failure_info for osd." << target_osd | |
2025 | << dendl; | |
2026 | failure_info.erase(target_osd); | |
2027 | } else { | |
2028 | dout(10) << " failure_info for osd." << target_osd << " now " | |
2029 | << fi.reporters.size() << " reporters" << dendl; | |
2030 | } | |
2031 | } else { | |
2032 | dout(10) << " no failure_info for osd." << target_osd << dendl; | |
2033 | } | |
2034 | mon->no_reply(op); | |
2035 | } | |
2036 | ||
2037 | return false; | |
2038 | } | |
2039 | ||
2040 | void OSDMonitor::process_failures() | |
2041 | { | |
2042 | map<int,failure_info_t>::iterator p = failure_info.begin(); | |
2043 | while (p != failure_info.end()) { | |
2044 | if (osdmap.is_up(p->first)) { | |
2045 | ++p; | |
2046 | } else { | |
2047 | dout(10) << "process_failures osd." << p->first << dendl; | |
2048 | list<MonOpRequestRef> ls; | |
2049 | p->second.take_report_messages(ls); | |
2050 | failure_info.erase(p++); | |
2051 | ||
2052 | while (!ls.empty()) { | |
2053 | MonOpRequestRef o = ls.front(); | |
2054 | if (o) { | |
2055 | o->mark_event(__func__); | |
2056 | MOSDFailure *m = o->get_req<MOSDFailure>(); | |
2057 | send_latest(o, m->get_epoch()); | |
2058 | } | |
2059 | ls.pop_front(); | |
2060 | } | |
2061 | } | |
2062 | } | |
2063 | } | |
2064 | ||
2065 | void OSDMonitor::take_all_failures(list<MonOpRequestRef>& ls) | |
2066 | { | |
2067 | dout(10) << __func__ << " on " << failure_info.size() << " osds" << dendl; | |
2068 | ||
2069 | for (map<int,failure_info_t>::iterator p = failure_info.begin(); | |
2070 | p != failure_info.end(); | |
2071 | ++p) { | |
2072 | p->second.take_report_messages(ls); | |
2073 | } | |
2074 | failure_info.clear(); | |
2075 | } | |
2076 | ||
2077 | ||
2078 | // boot -- | |
2079 | ||
2080 | bool OSDMonitor::preprocess_boot(MonOpRequestRef op) | |
2081 | { | |
2082 | op->mark_osdmon_event(__func__); | |
2083 | MOSDBoot *m = static_cast<MOSDBoot*>(op->get_req()); | |
2084 | int from = m->get_orig_source_inst().name.num(); | |
2085 | ||
2086 | // check permissions, ignore if failed (no response expected) | |
2087 | MonSession *session = m->get_session(); | |
2088 | if (!session) | |
2089 | goto ignore; | |
2090 | if (!session->is_capable("osd", MON_CAP_X)) { | |
2091 | dout(0) << "got preprocess_boot message from entity with insufficient caps" | |
2092 | << session->caps << dendl; | |
2093 | goto ignore; | |
2094 | } | |
2095 | ||
2096 | if (m->sb.cluster_fsid != mon->monmap->fsid) { | |
2097 | dout(0) << "preprocess_boot on fsid " << m->sb.cluster_fsid | |
2098 | << " != " << mon->monmap->fsid << dendl; | |
2099 | goto ignore; | |
2100 | } | |
2101 | ||
2102 | if (m->get_orig_source_inst().addr.is_blank_ip()) { | |
2103 | dout(0) << "preprocess_boot got blank addr for " << m->get_orig_source_inst() << dendl; | |
2104 | goto ignore; | |
2105 | } | |
2106 | ||
2107 | assert(m->get_orig_source_inst().name.is_osd()); | |
2108 | ||
2109 | // check if osd has required features to boot | |
2110 | if ((osdmap.get_features(CEPH_ENTITY_TYPE_OSD, NULL) & | |
2111 | CEPH_FEATURE_OSD_ERASURE_CODES) && | |
2112 | !(m->get_connection()->get_features() & CEPH_FEATURE_OSD_ERASURE_CODES)) { | |
2113 | dout(0) << __func__ << " osdmap requires erasure code but osd at " | |
2114 | << m->get_orig_source_inst() | |
2115 | << " doesn't announce support -- ignore" << dendl; | |
2116 | goto ignore; | |
2117 | } | |
2118 | ||
2119 | if ((osdmap.get_features(CEPH_ENTITY_TYPE_OSD, NULL) & | |
2120 | CEPH_FEATURE_ERASURE_CODE_PLUGINS_V2) && | |
2121 | !(m->get_connection()->get_features() & CEPH_FEATURE_ERASURE_CODE_PLUGINS_V2)) { | |
2122 | dout(0) << __func__ << " osdmap requires erasure code plugins v2 but osd at " | |
2123 | << m->get_orig_source_inst() | |
2124 | << " doesn't announce support -- ignore" << dendl; | |
2125 | goto ignore; | |
2126 | } | |
2127 | ||
2128 | if ((osdmap.get_features(CEPH_ENTITY_TYPE_OSD, NULL) & | |
2129 | CEPH_FEATURE_ERASURE_CODE_PLUGINS_V3) && | |
2130 | !(m->get_connection()->get_features() & CEPH_FEATURE_ERASURE_CODE_PLUGINS_V3)) { | |
2131 | dout(0) << __func__ << " osdmap requires erasure code plugins v3 but osd at " | |
2132 | << m->get_orig_source_inst() | |
2133 | << " doesn't announce support -- ignore" << dendl; | |
2134 | goto ignore; | |
2135 | } | |
2136 | ||
31f18b77 | 2137 | if (osdmap.require_osd_release >= CEPH_RELEASE_LUMINOUS && |
7c673cae FG |
2138 | !HAVE_FEATURE(m->osd_features, SERVER_LUMINOUS)) { |
2139 | mon->clog->info() << "disallowing boot of OSD " | |
2140 | << m->get_orig_source_inst() | |
2141 | << " because the osdmap requires" | |
2142 | << " CEPH_FEATURE_SERVER_LUMINOUS" | |
2143 | << " but the osd lacks CEPH_FEATURE_SERVER_LUMINOUS"; | |
2144 | goto ignore; | |
2145 | } | |
2146 | ||
31f18b77 | 2147 | if (osdmap.require_osd_release >= CEPH_RELEASE_JEWEL && |
7c673cae FG |
2148 | !(m->osd_features & CEPH_FEATURE_SERVER_JEWEL)) { |
2149 | mon->clog->info() << "disallowing boot of OSD " | |
2150 | << m->get_orig_source_inst() | |
2151 | << " because the osdmap requires" | |
2152 | << " CEPH_FEATURE_SERVER_JEWEL" | |
2153 | << " but the osd lacks CEPH_FEATURE_SERVER_JEWEL"; | |
2154 | goto ignore; | |
2155 | } | |
2156 | ||
31f18b77 | 2157 | if (osdmap.require_osd_release >= CEPH_RELEASE_KRAKEN && |
7c673cae FG |
2158 | !HAVE_FEATURE(m->osd_features, SERVER_KRAKEN)) { |
2159 | mon->clog->info() << "disallowing boot of OSD " | |
2160 | << m->get_orig_source_inst() | |
2161 | << " because the osdmap requires" | |
2162 | << " CEPH_FEATURE_SERVER_KRAKEN" | |
2163 | << " but the osd lacks CEPH_FEATURE_SERVER_KRAKEN"; | |
2164 | goto ignore; | |
2165 | } | |
2166 | ||
2167 | if (osdmap.test_flag(CEPH_OSDMAP_SORTBITWISE) && | |
2168 | !(m->osd_features & CEPH_FEATURE_OSD_BITWISE_HOBJ_SORT)) { | |
2169 | mon->clog->info() << "disallowing boot of OSD " | |
2170 | << m->get_orig_source_inst() | |
2171 | << " because 'sortbitwise' osdmap flag is set and OSD lacks the OSD_BITWISE_HOBJ_SORT feature"; | |
2172 | goto ignore; | |
2173 | } | |
2174 | ||
c07f9fc5 FG |
2175 | if (osdmap.test_flag(CEPH_OSDMAP_RECOVERY_DELETES) && |
2176 | !(m->osd_features & CEPH_FEATURE_OSD_RECOVERY_DELETES)) { | |
2177 | mon->clog->info() << "disallowing boot of OSD " | |
2178 | << m->get_orig_source_inst() | |
2179 | << " because 'recovery_deletes' osdmap flag is set and OSD lacks the OSD_RECOVERY_DELETES feature"; | |
2180 | goto ignore; | |
2181 | } | |
2182 | ||
7c673cae FG |
2183 | if (any_of(osdmap.get_pools().begin(), |
2184 | osdmap.get_pools().end(), | |
2185 | [](const std::pair<int64_t,pg_pool_t>& pool) | |
2186 | { return pool.second.use_gmt_hitset; })) { | |
2187 | assert(osdmap.get_num_up_osds() == 0 || | |
2188 | osdmap.get_up_osd_features() & CEPH_FEATURE_OSD_HITSET_GMT); | |
2189 | if (!(m->osd_features & CEPH_FEATURE_OSD_HITSET_GMT)) { | |
2190 | dout(0) << __func__ << " one or more pools uses GMT hitsets but osd at " | |
2191 | << m->get_orig_source_inst() | |
2192 | << " doesn't announce support -- ignore" << dendl; | |
2193 | goto ignore; | |
2194 | } | |
2195 | } | |
2196 | ||
2197 | // make sure upgrades stop at luminous | |
2198 | if (HAVE_FEATURE(m->osd_features, SERVER_M) && | |
31f18b77 | 2199 | osdmap.require_osd_release < CEPH_RELEASE_LUMINOUS) { |
7c673cae FG |
2200 | mon->clog->info() << "disallowing boot of post-luminous OSD " |
2201 | << m->get_orig_source_inst() | |
31f18b77 | 2202 | << " because require_osd_release < luminous"; |
7c673cae FG |
2203 | goto ignore; |
2204 | } | |
2205 | ||
2206 | // make sure upgrades stop at jewel | |
2207 | if (HAVE_FEATURE(m->osd_features, SERVER_KRAKEN) && | |
31f18b77 | 2208 | osdmap.require_osd_release < CEPH_RELEASE_JEWEL) { |
7c673cae FG |
2209 | mon->clog->info() << "disallowing boot of post-jewel OSD " |
2210 | << m->get_orig_source_inst() | |
31f18b77 | 2211 | << " because require_osd_release < jewel"; |
7c673cae FG |
2212 | goto ignore; |
2213 | } | |
2214 | ||
2215 | // make sure upgrades stop at hammer | |
2216 | // * HAMMER_0_94_4 is the required hammer feature | |
2217 | // * MON_METADATA is the first post-hammer feature | |
2218 | if (osdmap.get_num_up_osds() > 0) { | |
2219 | if ((m->osd_features & CEPH_FEATURE_MON_METADATA) && | |
2220 | !(osdmap.get_up_osd_features() & CEPH_FEATURE_HAMMER_0_94_4)) { | |
2221 | mon->clog->info() << "disallowing boot of post-hammer OSD " | |
2222 | << m->get_orig_source_inst() | |
2223 | << " because one or more up OSDs is pre-hammer v0.94.4"; | |
2224 | goto ignore; | |
2225 | } | |
2226 | if (!(m->osd_features & CEPH_FEATURE_HAMMER_0_94_4) && | |
2227 | (osdmap.get_up_osd_features() & CEPH_FEATURE_MON_METADATA)) { | |
2228 | mon->clog->info() << "disallowing boot of pre-hammer v0.94.4 OSD " | |
2229 | << m->get_orig_source_inst() | |
2230 | << " because all up OSDs are post-hammer"; | |
2231 | goto ignore; | |
2232 | } | |
2233 | } | |
2234 | ||
2235 | // already booted? | |
2236 | if (osdmap.is_up(from) && | |
2237 | osdmap.get_inst(from) == m->get_orig_source_inst() && | |
2238 | osdmap.get_cluster_addr(from) == m->cluster_addr) { | |
2239 | // yup. | |
2240 | dout(7) << "preprocess_boot dup from " << m->get_orig_source_inst() | |
2241 | << " == " << osdmap.get_inst(from) << dendl; | |
2242 | _booted(op, false); | |
2243 | return true; | |
2244 | } | |
2245 | ||
2246 | if (osdmap.exists(from) && | |
2247 | !osdmap.get_uuid(from).is_zero() && | |
2248 | osdmap.get_uuid(from) != m->sb.osd_fsid) { | |
2249 | dout(7) << __func__ << " from " << m->get_orig_source_inst() | |
2250 | << " clashes with existing osd: different fsid" | |
2251 | << " (ours: " << osdmap.get_uuid(from) | |
2252 | << " ; theirs: " << m->sb.osd_fsid << ")" << dendl; | |
2253 | goto ignore; | |
2254 | } | |
2255 | ||
2256 | if (osdmap.exists(from) && | |
2257 | osdmap.get_info(from).up_from > m->version && | |
2258 | osdmap.get_most_recent_inst(from) == m->get_orig_source_inst()) { | |
2259 | dout(7) << "prepare_boot msg from before last up_from, ignoring" << dendl; | |
2260 | send_latest(op, m->sb.current_epoch+1); | |
2261 | return true; | |
2262 | } | |
2263 | ||
2264 | // noup? | |
2265 | if (!can_mark_up(from)) { | |
2266 | dout(7) << "preprocess_boot ignoring boot from " << m->get_orig_source_inst() << dendl; | |
2267 | send_latest(op, m->sb.current_epoch+1); | |
2268 | return true; | |
2269 | } | |
2270 | ||
2271 | dout(10) << "preprocess_boot from " << m->get_orig_source_inst() << dendl; | |
2272 | return false; | |
2273 | ||
2274 | ignore: | |
2275 | return true; | |
2276 | } | |
2277 | ||
2278 | bool OSDMonitor::prepare_boot(MonOpRequestRef op) | |
2279 | { | |
2280 | op->mark_osdmon_event(__func__); | |
2281 | MOSDBoot *m = static_cast<MOSDBoot*>(op->get_req()); | |
2282 | dout(7) << __func__ << " from " << m->get_orig_source_inst() << " sb " << m->sb | |
2283 | << " cluster_addr " << m->cluster_addr | |
2284 | << " hb_back_addr " << m->hb_back_addr | |
2285 | << " hb_front_addr " << m->hb_front_addr | |
2286 | << dendl; | |
2287 | ||
2288 | assert(m->get_orig_source().is_osd()); | |
2289 | int from = m->get_orig_source().num(); | |
2290 | ||
2291 | // does this osd exist? | |
2292 | if (from >= osdmap.get_max_osd()) { | |
2293 | dout(1) << "boot from osd." << from << " >= max_osd " | |
2294 | << osdmap.get_max_osd() << dendl; | |
2295 | return false; | |
2296 | } | |
2297 | ||
2298 | int oldstate = osdmap.exists(from) ? osdmap.get_state(from) : CEPH_OSD_NEW; | |
2299 | if (pending_inc.new_state.count(from)) | |
2300 | oldstate ^= pending_inc.new_state[from]; | |
2301 | ||
2302 | // already up? mark down first? | |
2303 | if (osdmap.is_up(from)) { | |
2304 | dout(7) << __func__ << " was up, first marking down " | |
2305 | << osdmap.get_inst(from) << dendl; | |
2306 | // preprocess should have caught these; if not, assert. | |
2307 | assert(osdmap.get_inst(from) != m->get_orig_source_inst() || | |
2308 | osdmap.get_cluster_addr(from) != m->cluster_addr); | |
2309 | assert(osdmap.get_uuid(from) == m->sb.osd_fsid); | |
2310 | ||
2311 | if (pending_inc.new_state.count(from) == 0 || | |
2312 | (pending_inc.new_state[from] & CEPH_OSD_UP) == 0) { | |
2313 | // mark previous guy down | |
2314 | pending_inc.new_state[from] = CEPH_OSD_UP; | |
2315 | } | |
2316 | wait_for_finished_proposal(op, new C_RetryMessage(this, op)); | |
2317 | } else if (pending_inc.new_up_client.count(from)) { | |
2318 | // already prepared, just wait | |
2319 | dout(7) << __func__ << " already prepared, waiting on " | |
2320 | << m->get_orig_source_addr() << dendl; | |
2321 | wait_for_finished_proposal(op, new C_RetryMessage(this, op)); | |
2322 | } else { | |
2323 | // mark new guy up. | |
2324 | pending_inc.new_up_client[from] = m->get_orig_source_addr(); | |
2325 | if (!m->cluster_addr.is_blank_ip()) | |
2326 | pending_inc.new_up_cluster[from] = m->cluster_addr; | |
2327 | pending_inc.new_hb_back_up[from] = m->hb_back_addr; | |
2328 | if (!m->hb_front_addr.is_blank_ip()) | |
2329 | pending_inc.new_hb_front_up[from] = m->hb_front_addr; | |
2330 | ||
2331 | down_pending_out.erase(from); // if any | |
2332 | ||
2333 | if (m->sb.weight) | |
2334 | osd_weight[from] = m->sb.weight; | |
2335 | ||
2336 | // set uuid? | |
2337 | dout(10) << " setting osd." << from << " uuid to " << m->sb.osd_fsid | |
2338 | << dendl; | |
2339 | if (!osdmap.exists(from) || osdmap.get_uuid(from) != m->sb.osd_fsid) { | |
2340 | // preprocess should have caught this; if not, assert. | |
2341 | assert(!osdmap.exists(from) || osdmap.get_uuid(from).is_zero()); | |
2342 | pending_inc.new_uuid[from] = m->sb.osd_fsid; | |
2343 | } | |
2344 | ||
2345 | // fresh osd? | |
2346 | if (m->sb.newest_map == 0 && osdmap.exists(from)) { | |
2347 | const osd_info_t& i = osdmap.get_info(from); | |
2348 | if (i.up_from > i.lost_at) { | |
2349 | dout(10) << " fresh osd; marking lost_at too" << dendl; | |
2350 | pending_inc.new_lost[from] = osdmap.get_epoch(); | |
2351 | } | |
2352 | } | |
2353 | ||
2354 | // metadata | |
2355 | bufferlist osd_metadata; | |
2356 | ::encode(m->metadata, osd_metadata); | |
2357 | pending_metadata[from] = osd_metadata; | |
31f18b77 | 2358 | pending_metadata_rm.erase(from); |
7c673cae FG |
2359 | |
2360 | // adjust last clean unmount epoch? | |
2361 | const osd_info_t& info = osdmap.get_info(from); | |
2362 | dout(10) << " old osd_info: " << info << dendl; | |
2363 | if (m->sb.mounted > info.last_clean_begin || | |
2364 | (m->sb.mounted == info.last_clean_begin && | |
2365 | m->sb.clean_thru > info.last_clean_end)) { | |
2366 | epoch_t begin = m->sb.mounted; | |
2367 | epoch_t end = m->sb.clean_thru; | |
2368 | ||
2369 | dout(10) << __func__ << " osd." << from << " last_clean_interval " | |
2370 | << "[" << info.last_clean_begin << "," << info.last_clean_end | |
2371 | << ") -> [" << begin << "-" << end << ")" | |
2372 | << dendl; | |
2373 | pending_inc.new_last_clean_interval[from] = | |
2374 | pair<epoch_t,epoch_t>(begin, end); | |
2375 | } | |
2376 | ||
2377 | osd_xinfo_t xi = osdmap.get_xinfo(from); | |
2378 | if (m->boot_epoch == 0) { | |
2379 | xi.laggy_probability *= (1.0 - g_conf->mon_osd_laggy_weight); | |
2380 | xi.laggy_interval *= (1.0 - g_conf->mon_osd_laggy_weight); | |
2381 | dout(10) << " not laggy, new xi " << xi << dendl; | |
2382 | } else { | |
2383 | if (xi.down_stamp.sec()) { | |
2384 | int interval = ceph_clock_now().sec() - | |
2385 | xi.down_stamp.sec(); | |
2386 | if (g_conf->mon_osd_laggy_max_interval && | |
2387 | (interval > g_conf->mon_osd_laggy_max_interval)) { | |
2388 | interval = g_conf->mon_osd_laggy_max_interval; | |
2389 | } | |
2390 | xi.laggy_interval = | |
2391 | interval * g_conf->mon_osd_laggy_weight + | |
2392 | xi.laggy_interval * (1.0 - g_conf->mon_osd_laggy_weight); | |
2393 | } | |
2394 | xi.laggy_probability = | |
2395 | g_conf->mon_osd_laggy_weight + | |
2396 | xi.laggy_probability * (1.0 - g_conf->mon_osd_laggy_weight); | |
2397 | dout(10) << " laggy, now xi " << xi << dendl; | |
2398 | } | |
2399 | ||
2400 | // set features shared by the osd | |
2401 | if (m->osd_features) | |
2402 | xi.features = m->osd_features; | |
2403 | else | |
2404 | xi.features = m->get_connection()->get_features(); | |
2405 | ||
2406 | // mark in? | |
2407 | if ((g_conf->mon_osd_auto_mark_auto_out_in && | |
2408 | (oldstate & CEPH_OSD_AUTOOUT)) || | |
2409 | (g_conf->mon_osd_auto_mark_new_in && (oldstate & CEPH_OSD_NEW)) || | |
2410 | (g_conf->mon_osd_auto_mark_in)) { | |
2411 | if (can_mark_in(from)) { | |
2412 | if (osdmap.osd_xinfo[from].old_weight > 0) { | |
2413 | pending_inc.new_weight[from] = osdmap.osd_xinfo[from].old_weight; | |
2414 | xi.old_weight = 0; | |
2415 | } else { | |
2416 | pending_inc.new_weight[from] = CEPH_OSD_IN; | |
2417 | } | |
2418 | } else { | |
2419 | dout(7) << __func__ << " NOIN set, will not mark in " | |
2420 | << m->get_orig_source_addr() << dendl; | |
2421 | } | |
2422 | } | |
2423 | ||
2424 | pending_inc.new_xinfo[from] = xi; | |
2425 | ||
2426 | // wait | |
2427 | wait_for_finished_proposal(op, new C_Booted(this, op)); | |
2428 | } | |
2429 | return true; | |
2430 | } | |
2431 | ||
2432 | void OSDMonitor::_booted(MonOpRequestRef op, bool logit) | |
2433 | { | |
2434 | op->mark_osdmon_event(__func__); | |
2435 | MOSDBoot *m = static_cast<MOSDBoot*>(op->get_req()); | |
2436 | dout(7) << "_booted " << m->get_orig_source_inst() | |
2437 | << " w " << m->sb.weight << " from " << m->sb.current_epoch << dendl; | |
2438 | ||
2439 | if (logit) { | |
2440 | mon->clog->info() << m->get_orig_source_inst() << " boot"; | |
2441 | } | |
2442 | ||
2443 | send_latest(op, m->sb.current_epoch+1); | |
2444 | } | |
2445 | ||
2446 | ||
2447 | // ------------- | |
2448 | // full | |
2449 | ||
2450 | bool OSDMonitor::preprocess_full(MonOpRequestRef op) | |
2451 | { | |
2452 | op->mark_osdmon_event(__func__); | |
2453 | MOSDFull *m = static_cast<MOSDFull*>(op->get_req()); | |
2454 | int from = m->get_orig_source().num(); | |
2455 | set<string> state; | |
2456 | unsigned mask = CEPH_OSD_NEARFULL | CEPH_OSD_BACKFILLFULL | CEPH_OSD_FULL; | |
2457 | ||
2458 | // check permissions, ignore if failed | |
2459 | MonSession *session = m->get_session(); | |
2460 | if (!session) | |
2461 | goto ignore; | |
2462 | if (!session->is_capable("osd", MON_CAP_X)) { | |
2463 | dout(0) << "MOSDFull from entity with insufficient privileges:" | |
2464 | << session->caps << dendl; | |
2465 | goto ignore; | |
2466 | } | |
2467 | ||
2468 | // ignore a full message from the osd instance that already went down | |
2469 | if (!osdmap.exists(from)) { | |
2470 | dout(7) << __func__ << " ignoring full message from nonexistent " | |
2471 | << m->get_orig_source_inst() << dendl; | |
2472 | goto ignore; | |
2473 | } | |
2474 | if ((!osdmap.is_up(from) && | |
2475 | osdmap.get_most_recent_inst(from) == m->get_orig_source_inst()) || | |
2476 | (osdmap.is_up(from) && | |
2477 | osdmap.get_inst(from) != m->get_orig_source_inst())) { | |
2478 | dout(7) << __func__ << " ignoring full message from down " | |
2479 | << m->get_orig_source_inst() << dendl; | |
2480 | goto ignore; | |
2481 | } | |
2482 | ||
2483 | OSDMap::calc_state_set(osdmap.get_state(from), state); | |
2484 | ||
2485 | if ((osdmap.get_state(from) & mask) == m->state) { | |
2486 | dout(7) << __func__ << " state already " << state << " for osd." << from | |
2487 | << " " << m->get_orig_source_inst() << dendl; | |
2488 | _reply_map(op, m->version); | |
2489 | goto ignore; | |
2490 | } | |
2491 | ||
2492 | dout(10) << __func__ << " want state " << state << " for osd." << from | |
2493 | << " " << m->get_orig_source_inst() << dendl; | |
2494 | return false; | |
2495 | ||
2496 | ignore: | |
2497 | return true; | |
2498 | } | |
2499 | ||
2500 | bool OSDMonitor::prepare_full(MonOpRequestRef op) | |
2501 | { | |
2502 | op->mark_osdmon_event(__func__); | |
2503 | const MOSDFull *m = static_cast<MOSDFull*>(op->get_req()); | |
2504 | const int from = m->get_orig_source().num(); | |
2505 | ||
2506 | const unsigned mask = CEPH_OSD_NEARFULL | CEPH_OSD_BACKFILLFULL | CEPH_OSD_FULL; | |
2507 | const unsigned want_state = m->state & mask; // safety first | |
2508 | ||
2509 | unsigned cur_state = osdmap.get_state(from); | |
2510 | auto p = pending_inc.new_state.find(from); | |
2511 | if (p != pending_inc.new_state.end()) { | |
2512 | cur_state ^= p->second; | |
2513 | } | |
2514 | cur_state &= mask; | |
2515 | ||
2516 | set<string> want_state_set, cur_state_set; | |
2517 | OSDMap::calc_state_set(want_state, want_state_set); | |
2518 | OSDMap::calc_state_set(cur_state, cur_state_set); | |
2519 | ||
2520 | if (cur_state != want_state) { | |
2521 | if (p != pending_inc.new_state.end()) { | |
2522 | p->second &= ~mask; | |
2523 | } else { | |
2524 | pending_inc.new_state[from] = 0; | |
2525 | } | |
2526 | pending_inc.new_state[from] |= (osdmap.get_state(from) & mask) ^ want_state; | |
2527 | dout(7) << __func__ << " osd." << from << " " << cur_state_set | |
2528 | << " -> " << want_state_set << dendl; | |
2529 | } else { | |
2530 | dout(7) << __func__ << " osd." << from << " " << cur_state_set | |
2531 | << " = wanted " << want_state_set << ", just waiting" << dendl; | |
2532 | } | |
2533 | ||
2534 | wait_for_finished_proposal(op, new C_ReplyMap(this, op, m->version)); | |
2535 | return true; | |
2536 | } | |
2537 | ||
2538 | // ------------- | |
2539 | // alive | |
2540 | ||
2541 | bool OSDMonitor::preprocess_alive(MonOpRequestRef op) | |
2542 | { | |
2543 | op->mark_osdmon_event(__func__); | |
2544 | MOSDAlive *m = static_cast<MOSDAlive*>(op->get_req()); | |
2545 | int from = m->get_orig_source().num(); | |
2546 | ||
2547 | // check permissions, ignore if failed | |
2548 | MonSession *session = m->get_session(); | |
2549 | if (!session) | |
2550 | goto ignore; | |
2551 | if (!session->is_capable("osd", MON_CAP_X)) { | |
2552 | dout(0) << "attempt to send MOSDAlive from entity with insufficient privileges:" | |
2553 | << session->caps << dendl; | |
2554 | goto ignore; | |
2555 | } | |
2556 | ||
2557 | if (!osdmap.is_up(from) || | |
2558 | osdmap.get_inst(from) != m->get_orig_source_inst()) { | |
2559 | dout(7) << "preprocess_alive ignoring alive message from down " << m->get_orig_source_inst() << dendl; | |
2560 | goto ignore; | |
2561 | } | |
2562 | ||
2563 | if (osdmap.get_up_thru(from) >= m->want) { | |
2564 | // yup. | |
2565 | dout(7) << "preprocess_alive want up_thru " << m->want << " dup from " << m->get_orig_source_inst() << dendl; | |
2566 | _reply_map(op, m->version); | |
2567 | return true; | |
2568 | } | |
2569 | ||
2570 | dout(10) << "preprocess_alive want up_thru " << m->want | |
2571 | << " from " << m->get_orig_source_inst() << dendl; | |
2572 | return false; | |
2573 | ||
2574 | ignore: | |
2575 | return true; | |
2576 | } | |
2577 | ||
2578 | bool OSDMonitor::prepare_alive(MonOpRequestRef op) | |
2579 | { | |
2580 | op->mark_osdmon_event(__func__); | |
2581 | MOSDAlive *m = static_cast<MOSDAlive*>(op->get_req()); | |
2582 | int from = m->get_orig_source().num(); | |
2583 | ||
2584 | if (0) { // we probably don't care much about these | |
2585 | mon->clog->debug() << m->get_orig_source_inst() << " alive"; | |
2586 | } | |
2587 | ||
2588 | dout(7) << "prepare_alive want up_thru " << m->want << " have " << m->version | |
2589 | << " from " << m->get_orig_source_inst() << dendl; | |
2590 | ||
2591 | update_up_thru(from, m->version); // set to the latest map the OSD has | |
2592 | wait_for_finished_proposal(op, new C_ReplyMap(this, op, m->version)); | |
2593 | return true; | |
2594 | } | |
2595 | ||
2596 | void OSDMonitor::_reply_map(MonOpRequestRef op, epoch_t e) | |
2597 | { | |
2598 | op->mark_osdmon_event(__func__); | |
2599 | dout(7) << "_reply_map " << e | |
2600 | << " from " << op->get_req()->get_orig_source_inst() | |
2601 | << dendl; | |
2602 | send_latest(op, e); | |
2603 | } | |
2604 | ||
2605 | // pg_created | |
2606 | bool OSDMonitor::preprocess_pg_created(MonOpRequestRef op) | |
2607 | { | |
2608 | op->mark_osdmon_event(__func__); | |
2609 | auto m = static_cast<MOSDPGCreated*>(op->get_req()); | |
2610 | dout(10) << __func__ << " " << *m << dendl; | |
2611 | auto session = m->get_session(); | |
2612 | if (!session) { | |
2613 | dout(10) << __func__ << ": no monitor session!" << dendl; | |
2614 | return true; | |
2615 | } | |
2616 | if (!session->is_capable("osd", MON_CAP_X)) { | |
2617 | derr << __func__ << " received from entity " | |
2618 | << "with insufficient privileges " << session->caps << dendl; | |
2619 | return true; | |
2620 | } | |
2621 | // always forward the "created!" to the leader | |
2622 | return false; | |
2623 | } | |
2624 | ||
2625 | bool OSDMonitor::prepare_pg_created(MonOpRequestRef op) | |
2626 | { | |
2627 | op->mark_osdmon_event(__func__); | |
2628 | auto m = static_cast<MOSDPGCreated*>(op->get_req()); | |
2629 | dout(10) << __func__ << " " << *m << dendl; | |
2630 | auto src = m->get_orig_source(); | |
2631 | auto from = src.num(); | |
2632 | if (!src.is_osd() || | |
2633 | !mon->osdmon()->osdmap.is_up(from) || | |
2634 | m->get_orig_source_inst() != mon->osdmon()->osdmap.get_inst(from)) { | |
2635 | dout(1) << __func__ << " ignoring stats from non-active osd." << dendl; | |
2636 | return false; | |
2637 | } | |
2638 | pending_created_pgs.push_back(m->pgid); | |
2639 | return true; | |
2640 | } | |
2641 | ||
2642 | // ------------- | |
2643 | // pg_temp changes | |
2644 | ||
2645 | bool OSDMonitor::preprocess_pgtemp(MonOpRequestRef op) | |
2646 | { | |
2647 | MOSDPGTemp *m = static_cast<MOSDPGTemp*>(op->get_req()); | |
2648 | dout(10) << "preprocess_pgtemp " << *m << dendl; | |
2649 | mempool::osdmap::vector<int> empty; | |
2650 | int from = m->get_orig_source().num(); | |
2651 | size_t ignore_cnt = 0; | |
2652 | ||
2653 | // check caps | |
2654 | MonSession *session = m->get_session(); | |
2655 | if (!session) | |
2656 | goto ignore; | |
2657 | if (!session->is_capable("osd", MON_CAP_X)) { | |
2658 | dout(0) << "attempt to send MOSDPGTemp from entity with insufficient caps " | |
2659 | << session->caps << dendl; | |
2660 | goto ignore; | |
2661 | } | |
2662 | ||
2663 | if (!osdmap.is_up(from) || | |
2664 | osdmap.get_inst(from) != m->get_orig_source_inst()) { | |
2665 | dout(7) << "ignoring pgtemp message from down " << m->get_orig_source_inst() << dendl; | |
2666 | goto ignore; | |
2667 | } | |
2668 | ||
2669 | for (auto p = m->pg_temp.begin(); p != m->pg_temp.end(); ++p) { | |
2670 | dout(20) << " " << p->first | |
31f18b77 | 2671 | << (osdmap.pg_temp->count(p->first) ? osdmap.pg_temp->get(p->first) : empty) |
7c673cae FG |
2672 | << " -> " << p->second << dendl; |
2673 | ||
2674 | // does the pool exist? | |
2675 | if (!osdmap.have_pg_pool(p->first.pool())) { | |
2676 | /* | |
2677 | * 1. If the osdmap does not have the pool, it means the pool has been | |
2678 | * removed in-between the osd sending this message and us handling it. | |
2679 | * 2. If osdmap doesn't have the pool, it is safe to assume the pool does | |
2680 | * not exist in the pending either, as the osds would not send a | |
2681 | * message about a pool they know nothing about (yet). | |
2682 | * 3. However, if the pool does exist in the pending, then it must be a | |
2683 | * new pool, and not relevant to this message (see 1). | |
2684 | */ | |
2685 | dout(10) << __func__ << " ignore " << p->first << " -> " << p->second | |
2686 | << ": pool has been removed" << dendl; | |
2687 | ignore_cnt++; | |
2688 | continue; | |
2689 | } | |
2690 | ||
2691 | int acting_primary = -1; | |
2692 | osdmap.pg_to_up_acting_osds( | |
2693 | p->first, nullptr, nullptr, nullptr, &acting_primary); | |
2694 | if (acting_primary != from) { | |
2695 | /* If the source isn't the primary based on the current osdmap, we know | |
2696 | * that the interval changed and that we can discard this message. | |
2697 | * Indeed, we must do so to avoid 16127 since we can't otherwise determine | |
2698 | * which of two pg temp mappings on the same pg is more recent. | |
2699 | */ | |
2700 | dout(10) << __func__ << " ignore " << p->first << " -> " << p->second | |
2701 | << ": primary has changed" << dendl; | |
2702 | ignore_cnt++; | |
2703 | continue; | |
2704 | } | |
2705 | ||
2706 | // removal? | |
2707 | if (p->second.empty() && (osdmap.pg_temp->count(p->first) || | |
2708 | osdmap.primary_temp->count(p->first))) | |
2709 | return false; | |
2710 | // change? | |
2711 | // NOTE: we assume that this will clear pg_primary, so consider | |
2712 | // an existing pg_primary field to imply a change | |
2713 | if (p->second.size() && | |
2714 | (osdmap.pg_temp->count(p->first) == 0 || | |
31f18b77 | 2715 | !vectors_equal(osdmap.pg_temp->get(p->first), p->second) || |
7c673cae FG |
2716 | osdmap.primary_temp->count(p->first))) |
2717 | return false; | |
2718 | } | |
2719 | ||
2720 | // should we ignore all the pgs? | |
2721 | if (ignore_cnt == m->pg_temp.size()) | |
2722 | goto ignore; | |
2723 | ||
2724 | dout(7) << "preprocess_pgtemp e" << m->map_epoch << " no changes from " << m->get_orig_source_inst() << dendl; | |
2725 | _reply_map(op, m->map_epoch); | |
2726 | return true; | |
2727 | ||
2728 | ignore: | |
2729 | return true; | |
2730 | } | |
2731 | ||
2732 | void OSDMonitor::update_up_thru(int from, epoch_t up_thru) | |
2733 | { | |
2734 | epoch_t old_up_thru = osdmap.get_up_thru(from); | |
2735 | auto ut = pending_inc.new_up_thru.find(from); | |
2736 | if (ut != pending_inc.new_up_thru.end()) { | |
2737 | old_up_thru = ut->second; | |
2738 | } | |
2739 | if (up_thru > old_up_thru) { | |
2740 | // set up_thru too, so the osd doesn't have to ask again | |
2741 | pending_inc.new_up_thru[from] = up_thru; | |
2742 | } | |
2743 | } | |
2744 | ||
2745 | bool OSDMonitor::prepare_pgtemp(MonOpRequestRef op) | |
2746 | { | |
2747 | op->mark_osdmon_event(__func__); | |
2748 | MOSDPGTemp *m = static_cast<MOSDPGTemp*>(op->get_req()); | |
2749 | int from = m->get_orig_source().num(); | |
2750 | dout(7) << "prepare_pgtemp e" << m->map_epoch << " from " << m->get_orig_source_inst() << dendl; | |
2751 | for (map<pg_t,vector<int32_t> >::iterator p = m->pg_temp.begin(); p != m->pg_temp.end(); ++p) { | |
2752 | uint64_t pool = p->first.pool(); | |
2753 | if (pending_inc.old_pools.count(pool)) { | |
2754 | dout(10) << __func__ << " ignore " << p->first << " -> " << p->second | |
2755 | << ": pool pending removal" << dendl; | |
2756 | continue; | |
2757 | } | |
2758 | if (!osdmap.have_pg_pool(pool)) { | |
2759 | dout(10) << __func__ << " ignore " << p->first << " -> " << p->second | |
2760 | << ": pool has been removed" << dendl; | |
2761 | continue; | |
2762 | } | |
2763 | pending_inc.new_pg_temp[p->first] = | |
2764 | mempool::osdmap::vector<int>(p->second.begin(), p->second.end()); | |
2765 | ||
2766 | // unconditionally clear pg_primary (until this message can encode | |
2767 | // a change for that, too.. at which point we need to also fix | |
2768 | // preprocess_pg_temp) | |
2769 | if (osdmap.primary_temp->count(p->first) || | |
2770 | pending_inc.new_primary_temp.count(p->first)) | |
2771 | pending_inc.new_primary_temp[p->first] = -1; | |
2772 | } | |
2773 | ||
2774 | // set up_thru too, so the osd doesn't have to ask again | |
2775 | update_up_thru(from, m->map_epoch); | |
2776 | ||
2777 | wait_for_finished_proposal(op, new C_ReplyMap(this, op, m->map_epoch)); | |
2778 | return true; | |
2779 | } | |
2780 | ||
2781 | ||
2782 | // --- | |
2783 | ||
2784 | bool OSDMonitor::preprocess_remove_snaps(MonOpRequestRef op) | |
2785 | { | |
2786 | op->mark_osdmon_event(__func__); | |
2787 | MRemoveSnaps *m = static_cast<MRemoveSnaps*>(op->get_req()); | |
2788 | dout(7) << "preprocess_remove_snaps " << *m << dendl; | |
2789 | ||
2790 | // check privilege, ignore if failed | |
2791 | MonSession *session = m->get_session(); | |
2792 | if (!session) | |
2793 | goto ignore; | |
2794 | if (!session->caps.is_capable( | |
2795 | g_ceph_context, | |
2796 | CEPH_ENTITY_TYPE_MON, | |
2797 | session->entity_name, | |
2798 | "osd", "osd pool rmsnap", {}, true, true, false)) { | |
2799 | dout(0) << "got preprocess_remove_snaps from entity with insufficient caps " | |
2800 | << session->caps << dendl; | |
2801 | goto ignore; | |
2802 | } | |
2803 | ||
2804 | for (map<int, vector<snapid_t> >::iterator q = m->snaps.begin(); | |
2805 | q != m->snaps.end(); | |
2806 | ++q) { | |
2807 | if (!osdmap.have_pg_pool(q->first)) { | |
2808 | dout(10) << " ignoring removed_snaps " << q->second << " on non-existent pool " << q->first << dendl; | |
2809 | continue; | |
2810 | } | |
2811 | const pg_pool_t *pi = osdmap.get_pg_pool(q->first); | |
2812 | for (vector<snapid_t>::iterator p = q->second.begin(); | |
2813 | p != q->second.end(); | |
2814 | ++p) { | |
2815 | if (*p > pi->get_snap_seq() || | |
2816 | !pi->removed_snaps.contains(*p)) | |
2817 | return false; | |
2818 | } | |
2819 | } | |
2820 | ||
2821 | ignore: | |
2822 | return true; | |
2823 | } | |
2824 | ||
2825 | bool OSDMonitor::prepare_remove_snaps(MonOpRequestRef op) | |
2826 | { | |
2827 | op->mark_osdmon_event(__func__); | |
2828 | MRemoveSnaps *m = static_cast<MRemoveSnaps*>(op->get_req()); | |
2829 | dout(7) << "prepare_remove_snaps " << *m << dendl; | |
2830 | ||
2831 | for (map<int, vector<snapid_t> >::iterator p = m->snaps.begin(); | |
2832 | p != m->snaps.end(); | |
2833 | ++p) { | |
2834 | ||
2835 | if (!osdmap.have_pg_pool(p->first)) { | |
2836 | dout(10) << " ignoring removed_snaps " << p->second << " on non-existent pool " << p->first << dendl; | |
2837 | continue; | |
2838 | } | |
2839 | ||
2840 | pg_pool_t& pi = osdmap.pools[p->first]; | |
2841 | for (vector<snapid_t>::iterator q = p->second.begin(); | |
2842 | q != p->second.end(); | |
2843 | ++q) { | |
2844 | if (!pi.removed_snaps.contains(*q) && | |
2845 | (!pending_inc.new_pools.count(p->first) || | |
2846 | !pending_inc.new_pools[p->first].removed_snaps.contains(*q))) { | |
2847 | pg_pool_t *newpi = pending_inc.get_new_pool(p->first, &pi); | |
2848 | newpi->removed_snaps.insert(*q); | |
2849 | dout(10) << " pool " << p->first << " removed_snaps added " << *q | |
2850 | << " (now " << newpi->removed_snaps << ")" << dendl; | |
2851 | if (*q > newpi->get_snap_seq()) { | |
2852 | dout(10) << " pool " << p->first << " snap_seq " << newpi->get_snap_seq() << " -> " << *q << dendl; | |
2853 | newpi->set_snap_seq(*q); | |
2854 | } | |
2855 | newpi->set_snap_epoch(pending_inc.epoch); | |
2856 | } | |
2857 | } | |
2858 | } | |
2859 | return true; | |
2860 | } | |
2861 | ||
2862 | // osd beacon | |
2863 | bool OSDMonitor::preprocess_beacon(MonOpRequestRef op) | |
2864 | { | |
2865 | op->mark_osdmon_event(__func__); | |
2866 | auto beacon = static_cast<MOSDBeacon*>(op->get_req()); | |
2867 | // check caps | |
2868 | auto session = beacon->get_session(); | |
2869 | if (!session) { | |
2870 | dout(10) << __func__ << " no monitor session!" << dendl; | |
2871 | return true; | |
2872 | } | |
2873 | if (!session->is_capable("osd", MON_CAP_X)) { | |
2874 | derr << __func__ << " received from entity " | |
2875 | << "with insufficient privileges " << session->caps << dendl; | |
2876 | return true; | |
2877 | } | |
2878 | // Always forward the beacon to the leader, even if they are the same as | |
2879 | // the old one. The leader will mark as down osds that haven't sent | |
2880 | // beacon for a few minutes. | |
2881 | return false; | |
2882 | } | |
2883 | ||
2884 | bool OSDMonitor::prepare_beacon(MonOpRequestRef op) | |
2885 | { | |
2886 | op->mark_osdmon_event(__func__); | |
2887 | const auto beacon = static_cast<MOSDBeacon*>(op->get_req()); | |
2888 | const auto src = beacon->get_orig_source(); | |
2889 | dout(10) << __func__ << " " << *beacon | |
2890 | << " from " << src << dendl; | |
2891 | int from = src.num(); | |
2892 | ||
2893 | if (!src.is_osd() || | |
2894 | !osdmap.is_up(from) || | |
2895 | beacon->get_orig_source_inst() != osdmap.get_inst(from)) { | |
2896 | dout(1) << " ignoring beacon from non-active osd." << dendl; | |
2897 | return false; | |
2898 | } | |
2899 | ||
2900 | last_osd_report[from] = ceph_clock_now(); | |
2901 | osd_epochs[from] = beacon->version; | |
2902 | ||
2903 | for (const auto& pg : beacon->pgs) { | |
2904 | last_epoch_clean.report(pg, beacon->min_last_epoch_clean); | |
2905 | } | |
2906 | return false; | |
2907 | } | |
2908 | ||
2909 | // --------------- | |
2910 | // map helpers | |
2911 | ||
2912 | void OSDMonitor::send_latest(MonOpRequestRef op, epoch_t start) | |
2913 | { | |
2914 | op->mark_osdmon_event(__func__); | |
2915 | dout(5) << "send_latest to " << op->get_req()->get_orig_source_inst() | |
2916 | << " start " << start << dendl; | |
2917 | if (start == 0) | |
2918 | send_full(op); | |
2919 | else | |
2920 | send_incremental(op, start); | |
2921 | } | |
2922 | ||
2923 | ||
2924 | MOSDMap *OSDMonitor::build_latest_full() | |
2925 | { | |
2926 | MOSDMap *r = new MOSDMap(mon->monmap->fsid); | |
2927 | get_version_full(osdmap.get_epoch(), r->maps[osdmap.get_epoch()]); | |
2928 | r->oldest_map = get_first_committed(); | |
2929 | r->newest_map = osdmap.get_epoch(); | |
2930 | return r; | |
2931 | } | |
2932 | ||
2933 | MOSDMap *OSDMonitor::build_incremental(epoch_t from, epoch_t to) | |
2934 | { | |
2935 | dout(10) << "build_incremental [" << from << ".." << to << "]" << dendl; | |
2936 | MOSDMap *m = new MOSDMap(mon->monmap->fsid); | |
2937 | m->oldest_map = get_first_committed(); | |
2938 | m->newest_map = osdmap.get_epoch(); | |
2939 | ||
2940 | for (epoch_t e = to; e >= from && e > 0; e--) { | |
2941 | bufferlist bl; | |
2942 | int err = get_version(e, bl); | |
2943 | if (err == 0) { | |
2944 | assert(bl.length()); | |
2945 | // if (get_version(e, bl) > 0) { | |
2946 | dout(20) << "build_incremental inc " << e << " " | |
2947 | << bl.length() << " bytes" << dendl; | |
2948 | m->incremental_maps[e] = bl; | |
2949 | } else { | |
2950 | assert(err == -ENOENT); | |
2951 | assert(!bl.length()); | |
2952 | get_version_full(e, bl); | |
2953 | if (bl.length() > 0) { | |
2954 | //else if (get_version("full", e, bl) > 0) { | |
2955 | dout(20) << "build_incremental full " << e << " " | |
2956 | << bl.length() << " bytes" << dendl; | |
2957 | m->maps[e] = bl; | |
2958 | } else { | |
2959 | ceph_abort(); // we should have all maps. | |
2960 | } | |
2961 | } | |
2962 | } | |
2963 | return m; | |
2964 | } | |
2965 | ||
2966 | void OSDMonitor::send_full(MonOpRequestRef op) | |
2967 | { | |
2968 | op->mark_osdmon_event(__func__); | |
2969 | dout(5) << "send_full to " << op->get_req()->get_orig_source_inst() << dendl; | |
2970 | mon->send_reply(op, build_latest_full()); | |
2971 | } | |
2972 | ||
2973 | void OSDMonitor::send_incremental(MonOpRequestRef op, epoch_t first) | |
2974 | { | |
2975 | op->mark_osdmon_event(__func__); | |
2976 | ||
2977 | MonSession *s = op->get_session(); | |
2978 | assert(s); | |
2979 | ||
2980 | if (s->proxy_con && | |
2981 | s->proxy_con->has_feature(CEPH_FEATURE_MON_ROUTE_OSDMAP)) { | |
2982 | // oh, we can tell the other mon to do it | |
2983 | dout(10) << __func__ << " asking proxying mon to send_incremental from " | |
2984 | << first << dendl; | |
2985 | MRoute *r = new MRoute(s->proxy_tid, NULL); | |
2986 | r->send_osdmap_first = first; | |
2987 | s->proxy_con->send_message(r); | |
2988 | op->mark_event("reply: send routed send_osdmap_first reply"); | |
2989 | } else { | |
2990 | // do it ourselves | |
2991 | send_incremental(first, s, false, op); | |
2992 | } | |
2993 | } | |
2994 | ||
2995 | void OSDMonitor::send_incremental(epoch_t first, | |
2996 | MonSession *session, | |
2997 | bool onetime, | |
2998 | MonOpRequestRef req) | |
2999 | { | |
3000 | dout(5) << "send_incremental [" << first << ".." << osdmap.get_epoch() << "]" | |
3001 | << " to " << session->inst << dendl; | |
3002 | ||
3003 | if (first <= session->osd_epoch) { | |
31f18b77 | 3004 | dout(10) << __func__ << " " << session->inst << " should already have epoch " |
7c673cae FG |
3005 | << session->osd_epoch << dendl; |
3006 | first = session->osd_epoch + 1; | |
3007 | } | |
3008 | ||
3009 | if (first < get_first_committed()) { | |
3010 | first = get_first_committed(); | |
3011 | bufferlist bl; | |
3012 | int err = get_version_full(first, bl); | |
3013 | assert(err == 0); | |
3014 | assert(bl.length()); | |
3015 | ||
3016 | dout(20) << "send_incremental starting with base full " | |
3017 | << first << " " << bl.length() << " bytes" << dendl; | |
3018 | ||
3019 | MOSDMap *m = new MOSDMap(osdmap.get_fsid()); | |
3020 | m->oldest_map = get_first_committed(); | |
3021 | m->newest_map = osdmap.get_epoch(); | |
3022 | m->maps[first] = bl; | |
3023 | ||
3024 | if (req) { | |
3025 | mon->send_reply(req, m); | |
3026 | session->osd_epoch = first; | |
3027 | return; | |
3028 | } else { | |
3029 | session->con->send_message(m); | |
3030 | session->osd_epoch = first; | |
3031 | } | |
3032 | first++; | |
3033 | } | |
3034 | ||
3035 | while (first <= osdmap.get_epoch()) { | |
3036 | epoch_t last = MIN(first + g_conf->osd_map_message_max - 1, | |
3037 | osdmap.get_epoch()); | |
3038 | MOSDMap *m = build_incremental(first, last); | |
3039 | ||
3040 | if (req) { | |
3041 | // send some maps. it may not be all of them, but it will get them | |
3042 | // started. | |
3043 | mon->send_reply(req, m); | |
3044 | } else { | |
3045 | session->con->send_message(m); | |
3046 | first = last + 1; | |
3047 | } | |
3048 | session->osd_epoch = last; | |
3049 | if (onetime || req) | |
3050 | break; | |
3051 | } | |
3052 | } | |
3053 | ||
3054 | int OSDMonitor::get_version(version_t ver, bufferlist& bl) | |
3055 | { | |
3056 | if (inc_osd_cache.lookup(ver, &bl)) { | |
3057 | return 0; | |
3058 | } | |
3059 | int ret = PaxosService::get_version(ver, bl); | |
3060 | if (!ret) { | |
3061 | inc_osd_cache.add(ver, bl); | |
3062 | } | |
3063 | return ret; | |
3064 | } | |
3065 | ||
3066 | int OSDMonitor::get_version_full(version_t ver, bufferlist& bl) | |
3067 | { | |
3068 | if (full_osd_cache.lookup(ver, &bl)) { | |
3069 | return 0; | |
3070 | } | |
3071 | int ret = PaxosService::get_version_full(ver, bl); | |
3072 | if (!ret) { | |
3073 | full_osd_cache.add(ver, bl); | |
3074 | } | |
3075 | return ret; | |
3076 | } | |
3077 | ||
3078 | epoch_t OSDMonitor::blacklist(const entity_addr_t& a, utime_t until) | |
3079 | { | |
3080 | dout(10) << "blacklist " << a << " until " << until << dendl; | |
3081 | pending_inc.new_blacklist[a] = until; | |
3082 | return pending_inc.epoch; | |
3083 | } | |
3084 | ||
3085 | ||
3086 | void OSDMonitor::check_osdmap_subs() | |
3087 | { | |
3088 | dout(10) << __func__ << dendl; | |
3089 | if (!osdmap.get_epoch()) { | |
3090 | return; | |
3091 | } | |
3092 | auto osdmap_subs = mon->session_map.subs.find("osdmap"); | |
3093 | if (osdmap_subs == mon->session_map.subs.end()) { | |
3094 | return; | |
3095 | } | |
3096 | auto p = osdmap_subs->second->begin(); | |
3097 | while (!p.end()) { | |
3098 | auto sub = *p; | |
3099 | ++p; | |
3100 | check_osdmap_sub(sub); | |
3101 | } | |
3102 | } | |
3103 | ||
3104 | void OSDMonitor::check_osdmap_sub(Subscription *sub) | |
3105 | { | |
3106 | dout(10) << __func__ << " " << sub << " next " << sub->next | |
3107 | << (sub->onetime ? " (onetime)":" (ongoing)") << dendl; | |
3108 | if (sub->next <= osdmap.get_epoch()) { | |
3109 | if (sub->next >= 1) | |
3110 | send_incremental(sub->next, sub->session, sub->incremental_onetime); | |
3111 | else | |
3112 | sub->session->con->send_message(build_latest_full()); | |
3113 | if (sub->onetime) | |
3114 | mon->session_map.remove_sub(sub); | |
3115 | else | |
3116 | sub->next = osdmap.get_epoch() + 1; | |
3117 | } | |
3118 | } | |
3119 | ||
3120 | void OSDMonitor::check_pg_creates_subs() | |
3121 | { | |
3122 | if (!mon->monmap->get_required_features().contains_all( | |
3123 | ceph::features::mon::FEATURE_LUMINOUS)) { | |
3124 | // PGMonitor takes care of this in pre-luminous era. | |
3125 | return; | |
3126 | } | |
3127 | if (!osdmap.get_num_up_osds()) { | |
3128 | return; | |
3129 | } | |
3130 | assert(osdmap.get_up_osd_features() & CEPH_FEATURE_MON_STATEFUL_SUB); | |
3131 | mon->with_session_map([this](const MonSessionMap& session_map) { | |
3132 | auto pg_creates_subs = session_map.subs.find("osd_pg_creates"); | |
3133 | if (pg_creates_subs == session_map.subs.end()) { | |
3134 | return; | |
3135 | } | |
3136 | for (auto sub : *pg_creates_subs->second) { | |
3137 | check_pg_creates_sub(sub); | |
3138 | } | |
3139 | }); | |
3140 | } | |
3141 | ||
3142 | void OSDMonitor::check_pg_creates_sub(Subscription *sub) | |
3143 | { | |
3144 | dout(20) << __func__ << " .. " << sub->session->inst << dendl; | |
3145 | assert(sub->type == "osd_pg_creates"); | |
3146 | // only send these if the OSD is up. we will check_subs() when they do | |
3147 | // come up so they will get the creates then. | |
3148 | if (sub->session->inst.name.is_osd() && | |
3149 | mon->osdmon()->osdmap.is_up(sub->session->inst.name.num())) { | |
3150 | sub->next = send_pg_creates(sub->session->inst.name.num(), | |
3151 | sub->session->con.get(), | |
3152 | sub->next); | |
3153 | } | |
3154 | } | |
3155 | ||
c07f9fc5 FG |
3156 | void OSDMonitor::do_application_enable(int64_t pool_id, |
3157 | const std::string &app_name) | |
3158 | { | |
3159 | assert(paxos->is_plugged()); | |
3160 | ||
3161 | dout(20) << __func__ << ": pool_id=" << pool_id << ", app_name=" << app_name | |
3162 | << dendl; | |
3163 | ||
3164 | auto pp = osdmap.get_pg_pool(pool_id); | |
3165 | assert(pp != nullptr); | |
3166 | ||
3167 | pg_pool_t p = *pp; | |
3168 | if (pending_inc.new_pools.count(pool_id)) { | |
3169 | p = pending_inc.new_pools[pool_id]; | |
3170 | } | |
3171 | ||
3172 | p.application_metadata.insert({app_name, {}}); | |
3173 | p.last_change = pending_inc.epoch; | |
3174 | pending_inc.new_pools[pool_id] = p; | |
3175 | } | |
3176 | ||
31f18b77 | 3177 | unsigned OSDMonitor::scan_for_creating_pgs( |
7c673cae FG |
3178 | const mempool::osdmap::map<int64_t,pg_pool_t>& pools, |
3179 | const mempool::osdmap::set<int64_t>& removed_pools, | |
3180 | utime_t modified, | |
3181 | creating_pgs_t* creating_pgs) const | |
3182 | { | |
31f18b77 | 3183 | unsigned queued = 0; |
7c673cae FG |
3184 | for (auto& p : pools) { |
3185 | int64_t poolid = p.first; | |
3186 | const pg_pool_t& pool = p.second; | |
31f18b77 | 3187 | int ruleno = osdmap.crush->find_rule(pool.get_crush_rule(), |
7c673cae FG |
3188 | pool.get_type(), pool.get_size()); |
3189 | if (ruleno < 0 || !osdmap.crush->rule_exists(ruleno)) | |
3190 | continue; | |
3191 | ||
3192 | const auto last_scan_epoch = creating_pgs->last_scan_epoch; | |
3193 | const auto created = pool.get_last_change(); | |
3194 | if (last_scan_epoch && created <= last_scan_epoch) { | |
3195 | dout(10) << __func__ << " no change in pool " << poolid | |
3196 | << " " << pool << dendl; | |
3197 | continue; | |
3198 | } | |
3199 | if (removed_pools.count(poolid)) { | |
3200 | dout(10) << __func__ << " pool is being removed: " << poolid | |
3201 | << " " << pool << dendl; | |
3202 | continue; | |
3203 | } | |
31f18b77 | 3204 | dout(10) << __func__ << " queueing pool create for " << poolid |
7c673cae | 3205 | << " " << pool << dendl; |
31f18b77 FG |
3206 | if (creating_pgs->create_pool(poolid, pool.get_pg_num(), |
3207 | created, modified)) { | |
3208 | queued++; | |
7c673cae FG |
3209 | } |
3210 | } | |
31f18b77 | 3211 | return queued; |
7c673cae FG |
3212 | } |
3213 | ||
3214 | void OSDMonitor::update_creating_pgs() | |
3215 | { | |
31f18b77 FG |
3216 | dout(10) << __func__ << " " << creating_pgs.pgs.size() << " pgs creating, " |
3217 | << creating_pgs.queue.size() << " pools in queue" << dendl; | |
7c673cae FG |
3218 | decltype(creating_pgs_by_osd_epoch) new_pgs_by_osd_epoch; |
3219 | std::lock_guard<std::mutex> l(creating_pgs_lock); | |
c07f9fc5 | 3220 | for (const auto& pg : creating_pgs.pgs) { |
7c673cae FG |
3221 | int acting_primary = -1; |
3222 | auto pgid = pg.first; | |
3223 | auto mapped = pg.second.first; | |
c07f9fc5 | 3224 | dout(20) << __func__ << " looking up " << pgid << "@" << mapped << dendl; |
7c673cae FG |
3225 | mapping.get(pgid, nullptr, nullptr, nullptr, &acting_primary); |
3226 | // check the previous creating_pgs, look for the target to whom the pg was | |
3227 | // previously mapped | |
3228 | for (const auto& pgs_by_epoch : creating_pgs_by_osd_epoch) { | |
3229 | const auto last_acting_primary = pgs_by_epoch.first; | |
3230 | for (auto& pgs: pgs_by_epoch.second) { | |
3231 | if (pgs.second.count(pgid)) { | |
3232 | if (last_acting_primary == acting_primary) { | |
3233 | mapped = pgs.first; | |
3234 | } else { | |
3235 | dout(20) << __func__ << " " << pgid << " " | |
3236 | << " acting_primary:" << last_acting_primary | |
3237 | << " -> " << acting_primary << dendl; | |
3238 | // note epoch if the target of the create message changed. | |
3239 | mapped = mapping.get_epoch(); | |
3240 | } | |
3241 | break; | |
31f18b77 FG |
3242 | } else { |
3243 | // newly creating | |
3244 | mapped = mapping.get_epoch(); | |
3245 | } | |
7c673cae FG |
3246 | } |
3247 | } | |
3248 | dout(10) << __func__ << " will instruct osd." << acting_primary | |
c07f9fc5 | 3249 | << " to create " << pgid << "@" << mapped << dendl; |
7c673cae FG |
3250 | new_pgs_by_osd_epoch[acting_primary][mapped].insert(pgid); |
3251 | } | |
3252 | creating_pgs_by_osd_epoch = std::move(new_pgs_by_osd_epoch); | |
3253 | creating_pgs_epoch = mapping.get_epoch(); | |
3254 | } | |
3255 | ||
c07f9fc5 | 3256 | epoch_t OSDMonitor::send_pg_creates(int osd, Connection *con, epoch_t next) const |
7c673cae FG |
3257 | { |
3258 | dout(30) << __func__ << " osd." << osd << " next=" << next | |
3259 | << " " << creating_pgs_by_osd_epoch << dendl; | |
3260 | std::lock_guard<std::mutex> l(creating_pgs_lock); | |
3261 | auto creating_pgs_by_epoch = creating_pgs_by_osd_epoch.find(osd); | |
3262 | if (creating_pgs_by_epoch == creating_pgs_by_osd_epoch.end()) | |
3263 | return next; | |
3264 | assert(!creating_pgs_by_epoch->second.empty()); | |
3265 | ||
3266 | MOSDPGCreate *m = nullptr; | |
3267 | epoch_t last = 0; | |
3268 | for (auto epoch_pgs = creating_pgs_by_epoch->second.lower_bound(next); | |
3269 | epoch_pgs != creating_pgs_by_epoch->second.end(); ++epoch_pgs) { | |
3270 | auto epoch = epoch_pgs->first; | |
3271 | auto& pgs = epoch_pgs->second; | |
3272 | dout(20) << __func__ << " osd." << osd << " from " << next | |
3273 | << " : epoch " << epoch << " " << pgs.size() << " pgs" << dendl; | |
3274 | last = epoch; | |
3275 | for (auto& pg : pgs) { | |
3276 | if (!m) | |
3277 | m = new MOSDPGCreate(creating_pgs_epoch); | |
3278 | // Need the create time from the monitor using its clock to set | |
3279 | // last_scrub_stamp upon pg creation. | |
c07f9fc5 FG |
3280 | auto create = creating_pgs.pgs.find(pg); |
3281 | assert(create != creating_pgs.pgs.end()); | |
3282 | m->mkpg.emplace(pg, pg_create_t{create->second.first, pg, 0}); | |
3283 | m->ctimes.emplace(pg, create->second.second); | |
7c673cae | 3284 | dout(20) << __func__ << " will create " << pg |
c07f9fc5 | 3285 | << " at " << create->second.first << dendl; |
7c673cae FG |
3286 | } |
3287 | } | |
3288 | if (!m) { | |
3289 | dout(20) << __func__ << " osd." << osd << " from " << next | |
3290 | << " has nothing to send" << dendl; | |
3291 | return next; | |
3292 | } | |
3293 | con->send_message(m); | |
3294 | // sub is current through last + 1 | |
3295 | return last + 1; | |
3296 | } | |
3297 | ||
3298 | // TICK | |
3299 | ||
3300 | ||
3301 | void OSDMonitor::tick() | |
3302 | { | |
3303 | if (!is_active()) return; | |
3304 | ||
3305 | dout(10) << osdmap << dendl; | |
3306 | ||
3307 | if (!mon->is_leader()) return; | |
3308 | ||
3309 | bool do_propose = false; | |
3310 | utime_t now = ceph_clock_now(); | |
3311 | ||
31f18b77 | 3312 | if (osdmap.require_osd_release >= CEPH_RELEASE_LUMINOUS && |
7c673cae FG |
3313 | mon->monmap->get_required_features().contains_all( |
3314 | ceph::features::mon::FEATURE_LUMINOUS)) { | |
3315 | if (handle_osd_timeouts(now, last_osd_report)) { | |
3316 | do_propose = true; | |
3317 | } | |
3318 | } | |
3319 | ||
3320 | // mark osds down? | |
3321 | if (check_failures(now)) | |
3322 | do_propose = true; | |
3323 | ||
3324 | // mark down osds out? | |
3325 | ||
3326 | /* can_mark_out() checks if we can mark osds as being out. The -1 has no | |
3327 | * influence at all. The decision is made based on the ratio of "in" osds, | |
3328 | * and the function returns false if this ratio is lower that the minimum | |
3329 | * ratio set by g_conf->mon_osd_min_in_ratio. So it's not really up to us. | |
3330 | */ | |
3331 | if (can_mark_out(-1)) { | |
3332 | set<int> down_cache; // quick cache of down subtrees | |
3333 | ||
3334 | map<int,utime_t>::iterator i = down_pending_out.begin(); | |
3335 | while (i != down_pending_out.end()) { | |
3336 | int o = i->first; | |
3337 | utime_t down = now; | |
3338 | down -= i->second; | |
3339 | ++i; | |
3340 | ||
3341 | if (osdmap.is_down(o) && | |
3342 | osdmap.is_in(o) && | |
3343 | can_mark_out(o)) { | |
3344 | utime_t orig_grace(g_conf->mon_osd_down_out_interval, 0); | |
3345 | utime_t grace = orig_grace; | |
3346 | double my_grace = 0.0; | |
3347 | ||
3348 | if (g_conf->mon_osd_adjust_down_out_interval) { | |
3349 | // scale grace period the same way we do the heartbeat grace. | |
3350 | const osd_xinfo_t& xi = osdmap.get_xinfo(o); | |
3351 | double halflife = (double)g_conf->mon_osd_laggy_halflife; | |
3352 | double decay_k = ::log(.5) / halflife; | |
3353 | double decay = exp((double)down * decay_k); | |
3354 | dout(20) << "osd." << o << " laggy halflife " << halflife << " decay_k " << decay_k | |
3355 | << " down for " << down << " decay " << decay << dendl; | |
3356 | my_grace = decay * (double)xi.laggy_interval * xi.laggy_probability; | |
3357 | grace += my_grace; | |
3358 | } | |
3359 | ||
3360 | // is this an entire large subtree down? | |
3361 | if (g_conf->mon_osd_down_out_subtree_limit.length()) { | |
3362 | int type = osdmap.crush->get_type_id(g_conf->mon_osd_down_out_subtree_limit); | |
3363 | if (type > 0) { | |
3364 | if (osdmap.containing_subtree_is_down(g_ceph_context, o, type, &down_cache)) { | |
3365 | dout(10) << "tick entire containing " << g_conf->mon_osd_down_out_subtree_limit | |
3366 | << " subtree for osd." << o << " is down; resetting timer" << dendl; | |
3367 | // reset timer, too. | |
3368 | down_pending_out[o] = now; | |
3369 | continue; | |
3370 | } | |
3371 | } | |
3372 | } | |
3373 | ||
c07f9fc5 FG |
3374 | bool down_out = !osdmap.is_destroyed(o) && |
3375 | g_conf->mon_osd_down_out_interval > 0 && down.sec() >= grace; | |
3376 | bool destroyed_out = osdmap.is_destroyed(o) && | |
3377 | g_conf->mon_osd_destroyed_out_interval > 0 && | |
3378 | // this is not precise enough as we did not make a note when this osd | |
3379 | // was marked as destroyed, but let's not bother with that | |
3380 | // complexity for now. | |
3381 | down.sec() >= g_conf->mon_osd_destroyed_out_interval; | |
3382 | if (down_out || destroyed_out) { | |
7c673cae FG |
3383 | dout(10) << "tick marking osd." << o << " OUT after " << down |
3384 | << " sec (target " << grace << " = " << orig_grace << " + " << my_grace << ")" << dendl; | |
3385 | pending_inc.new_weight[o] = CEPH_OSD_OUT; | |
3386 | ||
3387 | // set the AUTOOUT bit. | |
3388 | if (pending_inc.new_state.count(o) == 0) | |
3389 | pending_inc.new_state[o] = 0; | |
3390 | pending_inc.new_state[o] |= CEPH_OSD_AUTOOUT; | |
3391 | ||
3392 | // remember previous weight | |
3393 | if (pending_inc.new_xinfo.count(o) == 0) | |
3394 | pending_inc.new_xinfo[o] = osdmap.osd_xinfo[o]; | |
3395 | pending_inc.new_xinfo[o].old_weight = osdmap.osd_weight[o]; | |
3396 | ||
3397 | do_propose = true; | |
3398 | ||
224ce89b WB |
3399 | mon->clog->info() << "Marking osd." << o << " out (has been down for " |
3400 | << int(down.sec()) << " seconds)"; | |
7c673cae FG |
3401 | } else |
3402 | continue; | |
3403 | } | |
3404 | ||
3405 | down_pending_out.erase(o); | |
3406 | } | |
3407 | } else { | |
3408 | dout(10) << "tick NOOUT flag set, not checking down osds" << dendl; | |
3409 | } | |
3410 | ||
3411 | // expire blacklisted items? | |
3412 | for (ceph::unordered_map<entity_addr_t,utime_t>::iterator p = osdmap.blacklist.begin(); | |
3413 | p != osdmap.blacklist.end(); | |
3414 | ++p) { | |
3415 | if (p->second < now) { | |
3416 | dout(10) << "expiring blacklist item " << p->first << " expired " << p->second << " < now " << now << dendl; | |
3417 | pending_inc.old_blacklist.push_back(p->first); | |
3418 | do_propose = true; | |
3419 | } | |
3420 | } | |
3421 | ||
3422 | // if map full setting has changed, get that info out there! | |
31f18b77 FG |
3423 | if (osdmap.require_osd_release < CEPH_RELEASE_LUMINOUS && |
3424 | mon->pgservice->is_readable()) { | |
7c673cae | 3425 | // for pre-luminous compat only! |
31f18b77 | 3426 | if (mon->pgservice->have_full_osds()) { |
7c673cae FG |
3427 | dout(5) << "There are full osds, setting full flag" << dendl; |
3428 | add_flag(CEPH_OSDMAP_FULL); | |
3429 | } else if (osdmap.test_flag(CEPH_OSDMAP_FULL)){ | |
3430 | dout(10) << "No full osds, removing full flag" << dendl; | |
3431 | remove_flag(CEPH_OSDMAP_FULL); | |
3432 | } | |
3433 | ||
31f18b77 | 3434 | if (mon->pgservice->have_nearfull_osds()) { |
7c673cae FG |
3435 | dout(5) << "There are near full osds, setting nearfull flag" << dendl; |
3436 | add_flag(CEPH_OSDMAP_NEARFULL); | |
3437 | } else if (osdmap.test_flag(CEPH_OSDMAP_NEARFULL)){ | |
3438 | dout(10) << "No near full osds, removing nearfull flag" << dendl; | |
3439 | remove_flag(CEPH_OSDMAP_NEARFULL); | |
3440 | } | |
3441 | if (pending_inc.new_flags != -1 && | |
3442 | (pending_inc.new_flags ^ osdmap.flags) & (CEPH_OSDMAP_FULL | CEPH_OSDMAP_NEARFULL)) { | |
3443 | dout(1) << "New setting for" << | |
3444 | (pending_inc.new_flags & CEPH_OSDMAP_FULL ? " CEPH_OSDMAP_FULL" : "") << | |
3445 | (pending_inc.new_flags & CEPH_OSDMAP_NEARFULL ? " CEPH_OSDMAP_NEARFULL" : "") | |
3446 | << " -- doing propose" << dendl; | |
3447 | do_propose = true; | |
3448 | } | |
3449 | } | |
3450 | ||
3451 | if (update_pools_status()) | |
3452 | do_propose = true; | |
3453 | ||
3454 | if (do_propose || | |
3455 | !pending_inc.new_pg_temp.empty()) // also propose if we adjusted pg_temp | |
3456 | propose_pending(); | |
3457 | } | |
3458 | ||
3459 | bool OSDMonitor::handle_osd_timeouts(const utime_t &now, | |
3460 | std::map<int,utime_t> &last_osd_report) | |
3461 | { | |
3462 | utime_t timeo(g_conf->mon_osd_report_timeout, 0); | |
3463 | if (now - mon->get_leader_since() < timeo) { | |
3464 | // We haven't been the leader for long enough to consider OSD timeouts | |
3465 | return false; | |
3466 | } | |
3467 | ||
3468 | int max_osd = osdmap.get_max_osd(); | |
3469 | bool new_down = false; | |
3470 | ||
3471 | for (int i=0; i < max_osd; ++i) { | |
3472 | dout(30) << __func__ << ": checking up on osd " << i << dendl; | |
c07f9fc5 FG |
3473 | if (!osdmap.exists(i)) { |
3474 | last_osd_report.erase(i); // if any | |
3475 | continue; | |
3476 | } | |
7c673cae FG |
3477 | if (!osdmap.is_up(i)) |
3478 | continue; | |
3479 | const std::map<int,utime_t>::const_iterator t = last_osd_report.find(i); | |
3480 | if (t == last_osd_report.end()) { | |
3481 | // it wasn't in the map; start the timer. | |
3482 | last_osd_report[i] = now; | |
3483 | } else if (can_mark_down(i)) { | |
3484 | utime_t diff = now - t->second; | |
3485 | if (diff > timeo) { | |
31f18b77 FG |
3486 | mon->clog->info() << "osd." << i << " marked down after no beacon for " |
3487 | << diff << " seconds"; | |
3488 | derr << "no beacon from osd." << i << " since " << t->second | |
3489 | << ", " << diff << " seconds ago. marking down" << dendl; | |
7c673cae FG |
3490 | pending_inc.new_state[i] = CEPH_OSD_UP; |
3491 | new_down = true; | |
3492 | } | |
3493 | } | |
3494 | } | |
3495 | return new_down; | |
3496 | } | |
3497 | ||
3498 | void OSDMonitor::get_health(list<pair<health_status_t,string> >& summary, | |
3499 | list<pair<health_status_t,string> > *detail, | |
3500 | CephContext *cct) const | |
3501 | { | |
3502 | int num_osds = osdmap.get_num_osds(); | |
3503 | ||
3504 | if (num_osds == 0) { | |
3505 | summary.push_back(make_pair(HEALTH_ERR, "no osds")); | |
3506 | } else { | |
3507 | int num_in_osds = 0; | |
3508 | int num_down_in_osds = 0; | |
3509 | set<int> osds; | |
31f18b77 FG |
3510 | set<int> down_in_osds; |
3511 | set<int> up_in_osds; | |
3512 | set<int> subtree_up; | |
3513 | unordered_map<int, set<int> > subtree_type_down; | |
3514 | unordered_map<int, int> num_osds_subtree; | |
3515 | int max_type = osdmap.crush->get_max_type_id(); | |
3516 | ||
7c673cae FG |
3517 | for (int i = 0; i < osdmap.get_max_osd(); i++) { |
3518 | if (!osdmap.exists(i)) { | |
3519 | if (osdmap.crush->item_exists(i)) { | |
3520 | osds.insert(i); | |
3521 | } | |
31f18b77 | 3522 | continue; |
224ce89b | 3523 | } |
7c673cae FG |
3524 | if (osdmap.is_out(i)) |
3525 | continue; | |
3526 | ++num_in_osds; | |
31f18b77 FG |
3527 | if (down_in_osds.count(i) || up_in_osds.count(i)) |
3528 | continue; | |
7c673cae | 3529 | if (!osdmap.is_up(i)) { |
31f18b77 FG |
3530 | down_in_osds.insert(i); |
3531 | int parent_id = 0; | |
3532 | int current = i; | |
3533 | for (int type = 0; type <= max_type; type++) { | |
3534 | if (!osdmap.crush->get_type_name(type)) | |
3535 | continue; | |
3536 | int r = osdmap.crush->get_immediate_parent_id(current, &parent_id); | |
3537 | if (r == -ENOENT) | |
3538 | break; | |
3539 | // break early if this parent is already marked as up | |
3540 | if (subtree_up.count(parent_id)) | |
3541 | break; | |
3542 | type = osdmap.crush->get_bucket_type(parent_id); | |
3543 | if (!osdmap.subtree_type_is_down( | |
3544 | g_ceph_context, parent_id, type, | |
3545 | &down_in_osds, &up_in_osds, &subtree_up, &subtree_type_down)) | |
3546 | break; | |
3547 | current = parent_id; | |
3548 | } | |
3549 | } | |
3550 | } | |
3551 | ||
3552 | // calculate the number of down osds in each down subtree and | |
3553 | // store it in num_osds_subtree | |
3554 | for (int type = 1; type <= max_type; type++) { | |
3555 | if (!osdmap.crush->get_type_name(type)) | |
3556 | continue; | |
3557 | for (auto j = subtree_type_down[type].begin(); | |
3558 | j != subtree_type_down[type].end(); | |
3559 | ++j) { | |
3560 | if (type == 1) { | |
3561 | list<int> children; | |
3562 | int num = osdmap.crush->get_children(*j, &children); | |
3563 | num_osds_subtree[*j] = num; | |
3564 | } else { | |
3565 | list<int> children; | |
3566 | int num = 0; | |
3567 | int num_children = osdmap.crush->get_children(*j, &children); | |
3568 | if (num_children == 0) | |
3569 | continue; | |
3570 | for (auto l = children.begin(); l != children.end(); ++l) { | |
3571 | if (num_osds_subtree[*l] > 0) { | |
3572 | num = num + num_osds_subtree[*l]; | |
3573 | } | |
3574 | } | |
3575 | num_osds_subtree[*j] = num; | |
7c673cae FG |
3576 | } |
3577 | } | |
3578 | } | |
31f18b77 | 3579 | num_down_in_osds = down_in_osds.size(); |
7c673cae FG |
3580 | assert(num_down_in_osds <= num_in_osds); |
3581 | if (num_down_in_osds > 0) { | |
31f18b77 FG |
3582 | // summary of down subtree types and osds |
3583 | for (int type = max_type; type > 0; type--) { | |
3584 | if (!osdmap.crush->get_type_name(type)) | |
3585 | continue; | |
3586 | if (subtree_type_down[type].size() > 0) { | |
3587 | ostringstream ss; | |
3588 | ss << subtree_type_down[type].size() << " " | |
3589 | << osdmap.crush->get_type_name(type); | |
3590 | if (subtree_type_down[type].size() > 1) { | |
3591 | ss << "s"; | |
3592 | } | |
3593 | int sum_down_osds = 0; | |
3594 | for (auto j = subtree_type_down[type].begin(); | |
3595 | j != subtree_type_down[type].end(); | |
3596 | ++j) { | |
3597 | sum_down_osds = sum_down_osds + num_osds_subtree[*j]; | |
3598 | } | |
3599 | ss << " (" << sum_down_osds << " osds) down"; | |
3600 | summary.push_back(make_pair(HEALTH_WARN, ss.str())); | |
3601 | } | |
3602 | } | |
7c673cae | 3603 | ostringstream ss; |
31f18b77 | 3604 | ss << down_in_osds.size() << " osds down"; |
7c673cae | 3605 | summary.push_back(make_pair(HEALTH_WARN, ss.str())); |
31f18b77 FG |
3606 | |
3607 | if (detail) { | |
3608 | // details of down subtree types | |
3609 | for (int type = max_type; type > 0; type--) { | |
3610 | if (!osdmap.crush->get_type_name(type)) | |
3611 | continue; | |
3612 | for (auto j = subtree_type_down[type].rbegin(); | |
3613 | j != subtree_type_down[type].rend(); | |
3614 | ++j) { | |
3615 | ostringstream ss; | |
3616 | ss << osdmap.crush->get_type_name(type); | |
3617 | ss << " "; | |
3618 | ss << osdmap.crush->get_item_name(*j); | |
3619 | // at the top level, do not print location | |
3620 | if (type != max_type) { | |
3621 | ss << " ("; | |
3622 | ss << osdmap.crush->get_full_location_ordered_string(*j); | |
3623 | ss << ")"; | |
3624 | } | |
3625 | int num = num_osds_subtree[*j]; | |
3626 | ss << " (" << num << " osds)"; | |
3627 | ss << " is down"; | |
3628 | detail->push_back(make_pair(HEALTH_WARN, ss.str())); | |
3629 | } | |
3630 | } | |
3631 | // details of down osds | |
3632 | for (auto it = down_in_osds.begin(); it != down_in_osds.end(); ++it) { | |
3633 | ostringstream ss; | |
3634 | ss << "osd." << *it << " ("; | |
3635 | ss << osdmap.crush->get_full_location_ordered_string(*it); | |
3636 | ss << ") is down"; | |
3637 | detail->push_back(make_pair(HEALTH_WARN, ss.str())); | |
3638 | } | |
3639 | } | |
7c673cae FG |
3640 | } |
3641 | ||
3642 | if (!osds.empty()) { | |
3643 | ostringstream ss; | |
31f18b77 | 3644 | ss << osds.size() << " osds exist in the crush map but not in the osdmap"; |
7c673cae FG |
3645 | summary.push_back(make_pair(HEALTH_WARN, ss.str())); |
3646 | if (detail) { | |
31f18b77 | 3647 | ss << " (osds: " << osds << ")"; |
7c673cae FG |
3648 | detail->push_back(make_pair(HEALTH_WARN, ss.str())); |
3649 | } | |
3650 | } | |
3651 | ||
7c673cae FG |
3652 | // note: we leave it to ceph-mgr to generate details health warnings |
3653 | // with actual osd utilizations | |
3654 | ||
3655 | // warn about flags | |
3656 | uint64_t warn_flags = | |
3657 | CEPH_OSDMAP_FULL | | |
3658 | CEPH_OSDMAP_PAUSERD | | |
3659 | CEPH_OSDMAP_PAUSEWR | | |
3660 | CEPH_OSDMAP_PAUSEREC | | |
3661 | CEPH_OSDMAP_NOUP | | |
3662 | CEPH_OSDMAP_NODOWN | | |
3663 | CEPH_OSDMAP_NOIN | | |
3664 | CEPH_OSDMAP_NOOUT | | |
3665 | CEPH_OSDMAP_NOBACKFILL | | |
3666 | CEPH_OSDMAP_NORECOVER | | |
3667 | CEPH_OSDMAP_NOSCRUB | | |
3668 | CEPH_OSDMAP_NODEEP_SCRUB | | |
3669 | CEPH_OSDMAP_NOTIERAGENT | | |
3670 | CEPH_OSDMAP_NOREBALANCE; | |
3671 | if (osdmap.test_flag(warn_flags)) { | |
3672 | ostringstream ss; | |
3673 | ss << osdmap.get_flag_string(osdmap.get_flags() & warn_flags) | |
3674 | << " flag(s) set"; | |
3675 | summary.push_back(make_pair(HEALTH_WARN, ss.str())); | |
3676 | if (detail) | |
3677 | detail->push_back(make_pair(HEALTH_WARN, ss.str())); | |
3678 | } | |
3679 | ||
3680 | // old crush tunables? | |
3681 | if (g_conf->mon_warn_on_legacy_crush_tunables) { | |
3682 | string min = osdmap.crush->get_min_required_version(); | |
3683 | if (min < g_conf->mon_crush_min_required_version) { | |
3684 | ostringstream ss; | |
3685 | ss << "crush map has legacy tunables (require " << min | |
3686 | << ", min is " << g_conf->mon_crush_min_required_version << ")"; | |
3687 | summary.push_back(make_pair(HEALTH_WARN, ss.str())); | |
3688 | if (detail) { | |
3689 | ss << "; see http://docs.ceph.com/docs/master/rados/operations/crush-map/#tunables"; | |
3690 | detail->push_back(make_pair(HEALTH_WARN, ss.str())); | |
3691 | } | |
3692 | } | |
3693 | } | |
3694 | if (g_conf->mon_warn_on_crush_straw_calc_version_zero) { | |
3695 | if (osdmap.crush->get_straw_calc_version() == 0) { | |
3696 | ostringstream ss; | |
3697 | ss << "crush map has straw_calc_version=0"; | |
3698 | summary.push_back(make_pair(HEALTH_WARN, ss.str())); | |
3699 | if (detail) { | |
3700 | ss << "; see http://docs.ceph.com/docs/master/rados/operations/crush-map/#tunables"; | |
3701 | detail->push_back(make_pair(HEALTH_WARN, ss.str())); | |
3702 | } | |
3703 | } | |
3704 | } | |
3705 | ||
3706 | // hit_set-less cache_mode? | |
3707 | if (g_conf->mon_warn_on_cache_pools_without_hit_sets) { | |
3708 | int problem_cache_pools = 0; | |
3709 | for (map<int64_t, pg_pool_t>::const_iterator p = osdmap.pools.begin(); | |
3710 | p != osdmap.pools.end(); | |
3711 | ++p) { | |
3712 | const pg_pool_t& info = p->second; | |
3713 | if (info.cache_mode_requires_hit_set() && | |
3714 | info.hit_set_params.get_type() == HitSet::TYPE_NONE) { | |
3715 | ++problem_cache_pools; | |
3716 | if (detail) { | |
3717 | ostringstream ss; | |
3718 | ss << "pool '" << osdmap.get_pool_name(p->first) | |
3719 | << "' with cache_mode " << info.get_cache_mode_name() | |
3720 | << " needs hit_set_type to be set but it is not"; | |
3721 | detail->push_back(make_pair(HEALTH_WARN, ss.str())); | |
3722 | } | |
3723 | } | |
3724 | } | |
3725 | if (problem_cache_pools) { | |
3726 | ostringstream ss; | |
3727 | ss << problem_cache_pools << " cache pools are missing hit_sets"; | |
3728 | summary.push_back(make_pair(HEALTH_WARN, ss.str())); | |
3729 | } | |
3730 | } | |
3731 | ||
31f18b77 FG |
3732 | if (osdmap.crush->has_multirule_rulesets()) { |
3733 | ostringstream ss; | |
3734 | ss << "CRUSH map contains multirule rulesets"; | |
3735 | summary.push_back(make_pair(HEALTH_WARN, ss.str())); | |
3736 | if (detail) { | |
3737 | ss << "; please manually fix the map"; | |
3738 | detail->push_back(make_pair(HEALTH_WARN, ss.str())); | |
3739 | } | |
3740 | } | |
3741 | ||
7c673cae FG |
3742 | // Not using 'sortbitwise' and should be? |
3743 | if (!osdmap.test_flag(CEPH_OSDMAP_SORTBITWISE) && | |
3744 | (osdmap.get_up_osd_features() & | |
3745 | CEPH_FEATURE_OSD_BITWISE_HOBJ_SORT)) { | |
3746 | ostringstream ss; | |
3747 | ss << "no legacy OSD present but 'sortbitwise' flag is not set"; | |
3748 | summary.push_back(make_pair(HEALTH_WARN, ss.str())); | |
3749 | } | |
3750 | ||
3751 | // Warn if 'mon_osd_down_out_interval' is set to zero. | |
3752 | // Having this option set to zero on the leader acts much like the | |
3753 | // 'noout' flag. It's hard to figure out what's going wrong with clusters | |
3754 | // without the 'noout' flag set but acting like that just the same, so | |
3755 | // we report a HEALTH_WARN in case this option is set to zero. | |
3756 | // This is an ugly hack to get the warning out, but until we find a way | |
3757 | // to spread global options throughout the mon cluster and have all mons | |
3758 | // using a base set of the same options, we need to work around this sort | |
3759 | // of things. | |
3760 | // There's also the obvious drawback that if this is set on a single | |
3761 | // monitor on a 3-monitor cluster, this warning will only be shown every | |
3762 | // third monitor connection. | |
3763 | if (g_conf->mon_warn_on_osd_down_out_interval_zero && | |
3764 | g_conf->mon_osd_down_out_interval == 0) { | |
3765 | ostringstream ss; | |
3766 | ss << "mon." << mon->name << " has mon_osd_down_out_interval set to 0"; | |
3767 | summary.push_back(make_pair(HEALTH_WARN, ss.str())); | |
3768 | if (detail) { | |
3769 | ss << "; this has the same effect as the 'noout' flag"; | |
3770 | detail->push_back(make_pair(HEALTH_WARN, ss.str())); | |
3771 | } | |
3772 | } | |
3773 | ||
3774 | // warn about upgrade flags that can be set but are not. | |
3775 | if (g_conf->mon_debug_no_require_luminous) { | |
3776 | // ignore these checks | |
3777 | } else if (HAVE_FEATURE(osdmap.get_up_osd_features(), SERVER_LUMINOUS) && | |
31f18b77 FG |
3778 | osdmap.require_osd_release < CEPH_RELEASE_LUMINOUS) { |
3779 | string msg = "all OSDs are running luminous or later but" | |
3780 | " require_osd_release < luminous"; | |
7c673cae FG |
3781 | summary.push_back(make_pair(HEALTH_WARN, msg)); |
3782 | if (detail) { | |
3783 | detail->push_back(make_pair(HEALTH_WARN, msg)); | |
3784 | } | |
3785 | } else if (HAVE_FEATURE(osdmap.get_up_osd_features(), SERVER_KRAKEN) && | |
31f18b77 FG |
3786 | osdmap.require_osd_release < CEPH_RELEASE_KRAKEN) { |
3787 | string msg = "all OSDs are running kraken or later but" | |
3788 | " require_osd_release < kraken"; | |
7c673cae FG |
3789 | summary.push_back(make_pair(HEALTH_WARN, msg)); |
3790 | if (detail) { | |
3791 | detail->push_back(make_pair(HEALTH_WARN, msg)); | |
3792 | } | |
3793 | } else if (HAVE_FEATURE(osdmap.get_up_osd_features(), SERVER_JEWEL) && | |
31f18b77 FG |
3794 | osdmap.require_osd_release < CEPH_RELEASE_JEWEL) { |
3795 | string msg = "all OSDs are running jewel or later but" | |
3796 | " require_osd_release < jewel"; | |
7c673cae FG |
3797 | summary.push_back(make_pair(HEALTH_WARN, msg)); |
3798 | if (detail) { | |
3799 | detail->push_back(make_pair(HEALTH_WARN, msg)); | |
3800 | } | |
3801 | } | |
3802 | ||
224ce89b WB |
3803 | for (auto it : osdmap.get_pools()) { |
3804 | const pg_pool_t &pool = it.second; | |
3805 | if (pool.has_flag(pg_pool_t::FLAG_FULL)) { | |
3806 | const string& pool_name = osdmap.get_pool_name(it.first); | |
3807 | stringstream ss; | |
3808 | ss << "pool '" << pool_name << "' is full"; | |
3809 | summary.push_back(make_pair(HEALTH_WARN, ss.str())); | |
3810 | if (detail) | |
3811 | detail->push_back(make_pair(HEALTH_WARN, ss.str())); | |
3812 | } | |
3813 | } | |
7c673cae FG |
3814 | } |
3815 | } | |
3816 | ||
3817 | void OSDMonitor::dump_info(Formatter *f) | |
3818 | { | |
3819 | f->open_object_section("osdmap"); | |
3820 | osdmap.dump(f); | |
3821 | f->close_section(); | |
3822 | ||
3823 | f->open_array_section("osd_metadata"); | |
3824 | for (int i=0; i<osdmap.get_max_osd(); ++i) { | |
3825 | if (osdmap.exists(i)) { | |
3826 | f->open_object_section("osd"); | |
3827 | f->dump_unsigned("id", i); | |
3828 | dump_osd_metadata(i, f, NULL); | |
3829 | f->close_section(); | |
3830 | } | |
3831 | } | |
3832 | f->close_section(); | |
3833 | ||
3834 | f->dump_unsigned("osdmap_first_committed", get_first_committed()); | |
3835 | f->dump_unsigned("osdmap_last_committed", get_last_committed()); | |
3836 | ||
3837 | f->open_object_section("crushmap"); | |
3838 | osdmap.crush->dump(f); | |
3839 | f->close_section(); | |
3840 | } | |
3841 | ||
3842 | namespace { | |
3843 | enum osd_pool_get_choices { | |
3844 | SIZE, MIN_SIZE, CRASH_REPLAY_INTERVAL, | |
31f18b77 | 3845 | PG_NUM, PGP_NUM, CRUSH_RULE, HASHPSPOOL, |
7c673cae FG |
3846 | NODELETE, NOPGCHANGE, NOSIZECHANGE, |
3847 | WRITE_FADVISE_DONTNEED, NOSCRUB, NODEEP_SCRUB, | |
3848 | HIT_SET_TYPE, HIT_SET_PERIOD, HIT_SET_COUNT, HIT_SET_FPP, | |
3849 | USE_GMT_HITSET, AUID, TARGET_MAX_OBJECTS, TARGET_MAX_BYTES, | |
3850 | CACHE_TARGET_DIRTY_RATIO, CACHE_TARGET_DIRTY_HIGH_RATIO, | |
3851 | CACHE_TARGET_FULL_RATIO, | |
3852 | CACHE_MIN_FLUSH_AGE, CACHE_MIN_EVICT_AGE, | |
3853 | ERASURE_CODE_PROFILE, MIN_READ_RECENCY_FOR_PROMOTE, | |
3854 | MIN_WRITE_RECENCY_FOR_PROMOTE, FAST_READ, | |
3855 | HIT_SET_GRADE_DECAY_RATE, HIT_SET_SEARCH_LAST_N, | |
3856 | SCRUB_MIN_INTERVAL, SCRUB_MAX_INTERVAL, DEEP_SCRUB_INTERVAL, | |
3857 | RECOVERY_PRIORITY, RECOVERY_OP_PRIORITY, SCRUB_PRIORITY, | |
3858 | COMPRESSION_MODE, COMPRESSION_ALGORITHM, COMPRESSION_REQUIRED_RATIO, | |
3859 | COMPRESSION_MAX_BLOB_SIZE, COMPRESSION_MIN_BLOB_SIZE, | |
3860 | CSUM_TYPE, CSUM_MAX_BLOCK, CSUM_MIN_BLOCK }; | |
3861 | ||
3862 | std::set<osd_pool_get_choices> | |
3863 | subtract_second_from_first(const std::set<osd_pool_get_choices>& first, | |
3864 | const std::set<osd_pool_get_choices>& second) | |
3865 | { | |
3866 | std::set<osd_pool_get_choices> result; | |
3867 | std::set_difference(first.begin(), first.end(), | |
3868 | second.begin(), second.end(), | |
3869 | std::inserter(result, result.end())); | |
3870 | return result; | |
3871 | } | |
3872 | } | |
3873 | ||
3874 | ||
3875 | bool OSDMonitor::preprocess_command(MonOpRequestRef op) | |
3876 | { | |
3877 | op->mark_osdmon_event(__func__); | |
3878 | MMonCommand *m = static_cast<MMonCommand*>(op->get_req()); | |
3879 | int r = 0; | |
3880 | bufferlist rdata; | |
3881 | stringstream ss, ds; | |
3882 | ||
3883 | map<string, cmd_vartype> cmdmap; | |
3884 | if (!cmdmap_from_json(m->cmd, &cmdmap, ss)) { | |
3885 | string rs = ss.str(); | |
3886 | mon->reply_command(op, -EINVAL, rs, get_last_committed()); | |
3887 | return true; | |
3888 | } | |
3889 | ||
3890 | MonSession *session = m->get_session(); | |
3891 | if (!session) { | |
3892 | mon->reply_command(op, -EACCES, "access denied", get_last_committed()); | |
3893 | return true; | |
3894 | } | |
3895 | ||
3896 | string prefix; | |
3897 | cmd_getval(g_ceph_context, cmdmap, "prefix", prefix); | |
3898 | ||
3899 | string format; | |
3900 | cmd_getval(g_ceph_context, cmdmap, "format", format, string("plain")); | |
3901 | boost::scoped_ptr<Formatter> f(Formatter::create(format)); | |
3902 | ||
3903 | if (prefix == "osd stat") { | |
224ce89b | 3904 | osdmap.print_summary(f.get(), ds, ""); |
7c673cae FG |
3905 | if (f) |
3906 | f->flush(rdata); | |
3907 | else | |
3908 | rdata.append(ds); | |
3909 | } | |
3910 | else if (prefix == "osd perf" || | |
3911 | prefix == "osd blocked-by") { | |
31f18b77 FG |
3912 | r = mon->pgservice->process_pg_command(prefix, cmdmap, |
3913 | osdmap, f.get(), &ss, &rdata); | |
7c673cae FG |
3914 | } |
3915 | else if (prefix == "osd dump" || | |
3916 | prefix == "osd tree" || | |
3917 | prefix == "osd ls" || | |
3918 | prefix == "osd getmap" || | |
31f18b77 FG |
3919 | prefix == "osd getcrushmap" || |
3920 | prefix == "osd ls-tree") { | |
7c673cae FG |
3921 | string val; |
3922 | ||
3923 | epoch_t epoch = 0; | |
3924 | int64_t epochnum; | |
3925 | cmd_getval(g_ceph_context, cmdmap, "epoch", epochnum, (int64_t)osdmap.get_epoch()); | |
3926 | epoch = epochnum; | |
3927 | ||
3928 | bufferlist osdmap_bl; | |
3929 | int err = get_version_full(epoch, osdmap_bl); | |
3930 | if (err == -ENOENT) { | |
3931 | r = -ENOENT; | |
3932 | ss << "there is no map for epoch " << epoch; | |
3933 | goto reply; | |
3934 | } | |
3935 | assert(err == 0); | |
3936 | assert(osdmap_bl.length()); | |
3937 | ||
3938 | OSDMap *p; | |
3939 | if (epoch == osdmap.get_epoch()) { | |
3940 | p = &osdmap; | |
3941 | } else { | |
3942 | p = new OSDMap; | |
3943 | p->decode(osdmap_bl); | |
3944 | } | |
3945 | ||
224ce89b WB |
3946 | auto sg = make_scope_guard([&] { |
3947 | if (p != &osdmap) { | |
3948 | delete p; | |
3949 | } | |
3950 | }); | |
3951 | ||
7c673cae FG |
3952 | if (prefix == "osd dump") { |
3953 | stringstream ds; | |
3954 | if (f) { | |
3955 | f->open_object_section("osdmap"); | |
3956 | p->dump(f.get()); | |
3957 | f->close_section(); | |
3958 | f->flush(ds); | |
3959 | } else { | |
3960 | p->print(ds); | |
3961 | } | |
3962 | rdata.append(ds); | |
3963 | if (!f) | |
3964 | ds << " "; | |
3965 | } else if (prefix == "osd ls") { | |
3966 | if (f) { | |
3967 | f->open_array_section("osds"); | |
3968 | for (int i = 0; i < osdmap.get_max_osd(); i++) { | |
3969 | if (osdmap.exists(i)) { | |
3970 | f->dump_int("osd", i); | |
3971 | } | |
3972 | } | |
3973 | f->close_section(); | |
3974 | f->flush(ds); | |
3975 | } else { | |
3976 | bool first = true; | |
3977 | for (int i = 0; i < osdmap.get_max_osd(); i++) { | |
3978 | if (osdmap.exists(i)) { | |
3979 | if (!first) | |
3980 | ds << "\n"; | |
3981 | first = false; | |
3982 | ds << i; | |
3983 | } | |
3984 | } | |
3985 | } | |
3986 | rdata.append(ds); | |
3987 | } else if (prefix == "osd tree") { | |
31f18b77 FG |
3988 | vector<string> states; |
3989 | cmd_getval(g_ceph_context, cmdmap, "states", states); | |
3990 | unsigned filter = 0; | |
3991 | for (auto& s : states) { | |
3992 | if (s == "up") { | |
3993 | filter |= OSDMap::DUMP_UP; | |
3994 | } else if (s == "down") { | |
3995 | filter |= OSDMap::DUMP_DOWN; | |
3996 | } else if (s == "in") { | |
3997 | filter |= OSDMap::DUMP_IN; | |
3998 | } else if (s == "out") { | |
3999 | filter |= OSDMap::DUMP_OUT; | |
c07f9fc5 FG |
4000 | } else if (s == "destroyed") { |
4001 | filter |= OSDMap::DUMP_DESTROYED; | |
31f18b77 FG |
4002 | } else { |
4003 | ss << "unrecognized state '" << s << "'"; | |
4004 | r = -EINVAL; | |
4005 | goto reply; | |
4006 | } | |
4007 | } | |
4008 | if ((filter & (OSDMap::DUMP_IN|OSDMap::DUMP_OUT)) == | |
c07f9fc5 FG |
4009 | (OSDMap::DUMP_IN|OSDMap::DUMP_OUT)) { |
4010 | ss << "cannot specify both 'in' and 'out'"; | |
4011 | r = -EINVAL; | |
4012 | goto reply; | |
4013 | } | |
4014 | if (((filter & (OSDMap::DUMP_UP|OSDMap::DUMP_DOWN)) == | |
4015 | (OSDMap::DUMP_UP|OSDMap::DUMP_DOWN)) || | |
4016 | ((filter & (OSDMap::DUMP_UP|OSDMap::DUMP_DESTROYED)) == | |
4017 | (OSDMap::DUMP_UP|OSDMap::DUMP_DESTROYED)) || | |
4018 | ((filter & (OSDMap::DUMP_DOWN|OSDMap::DUMP_DESTROYED)) == | |
4019 | (OSDMap::DUMP_DOWN|OSDMap::DUMP_DESTROYED))) { | |
4020 | ss << "can specify only one of 'up', 'down' and 'destroyed'"; | |
31f18b77 FG |
4021 | r = -EINVAL; |
4022 | goto reply; | |
4023 | } | |
7c673cae FG |
4024 | if (f) { |
4025 | f->open_object_section("tree"); | |
31f18b77 | 4026 | p->print_tree(f.get(), NULL, filter); |
7c673cae FG |
4027 | f->close_section(); |
4028 | f->flush(ds); | |
4029 | } else { | |
31f18b77 | 4030 | p->print_tree(NULL, &ds, filter); |
7c673cae FG |
4031 | } |
4032 | rdata.append(ds); | |
4033 | } else if (prefix == "osd getmap") { | |
4034 | rdata.append(osdmap_bl); | |
4035 | ss << "got osdmap epoch " << p->get_epoch(); | |
4036 | } else if (prefix == "osd getcrushmap") { | |
4037 | p->crush->encode(rdata, mon->get_quorum_con_features()); | |
31f18b77 FG |
4038 | ss << p->get_crush_version(); |
4039 | } else if (prefix == "osd ls-tree") { | |
4040 | string bucket_name; | |
4041 | cmd_getval(g_ceph_context, cmdmap, "name", bucket_name); | |
4042 | set<int> osds; | |
4043 | r = p->get_osds_by_bucket_name(bucket_name, &osds); | |
4044 | if (r == -ENOENT) { | |
4045 | ss << "\"" << bucket_name << "\" does not exist"; | |
4046 | goto reply; | |
4047 | } else if (r < 0) { | |
4048 | ss << "can not parse bucket name:\"" << bucket_name << "\""; | |
4049 | goto reply; | |
4050 | } | |
4051 | ||
4052 | if (f) { | |
4053 | f->open_array_section("osds"); | |
4054 | for (auto &i : osds) { | |
4055 | if (osdmap.exists(i)) { | |
4056 | f->dump_int("osd", i); | |
4057 | } | |
4058 | } | |
4059 | f->close_section(); | |
4060 | f->flush(ds); | |
4061 | } else { | |
4062 | bool first = true; | |
4063 | for (auto &i : osds) { | |
4064 | if (osdmap.exists(i)) { | |
4065 | if (!first) | |
4066 | ds << "\n"; | |
4067 | first = false; | |
4068 | ds << i; | |
4069 | } | |
4070 | } | |
4071 | } | |
4072 | ||
4073 | rdata.append(ds); | |
7c673cae | 4074 | } |
7c673cae FG |
4075 | } else if (prefix == "osd df") { |
4076 | string method; | |
4077 | cmd_getval(g_ceph_context, cmdmap, "output_method", method); | |
31f18b77 FG |
4078 | print_osd_utilization(osdmap, mon->pgservice, ds, |
4079 | f.get(), method == "tree"); | |
7c673cae FG |
4080 | rdata.append(ds); |
4081 | } else if (prefix == "osd getmaxosd") { | |
4082 | if (f) { | |
4083 | f->open_object_section("getmaxosd"); | |
4084 | f->dump_unsigned("epoch", osdmap.get_epoch()); | |
4085 | f->dump_int("max_osd", osdmap.get_max_osd()); | |
4086 | f->close_section(); | |
4087 | f->flush(rdata); | |
4088 | } else { | |
4089 | ds << "max_osd = " << osdmap.get_max_osd() << " in epoch " << osdmap.get_epoch(); | |
4090 | rdata.append(ds); | |
4091 | } | |
4092 | } else if (prefix == "osd utilization") { | |
4093 | string out; | |
4094 | osdmap.summarize_mapping_stats(NULL, NULL, &out, f.get()); | |
4095 | if (f) | |
4096 | f->flush(rdata); | |
4097 | else | |
4098 | rdata.append(out); | |
4099 | r = 0; | |
4100 | goto reply; | |
4101 | } else if (prefix == "osd find") { | |
4102 | int64_t osd; | |
4103 | if (!cmd_getval(g_ceph_context, cmdmap, "id", osd)) { | |
4104 | ss << "unable to parse osd id value '" | |
4105 | << cmd_vartype_stringify(cmdmap["id"]) << "'"; | |
4106 | r = -EINVAL; | |
4107 | goto reply; | |
4108 | } | |
4109 | if (!osdmap.exists(osd)) { | |
4110 | ss << "osd." << osd << " does not exist"; | |
4111 | r = -ENOENT; | |
4112 | goto reply; | |
4113 | } | |
4114 | string format; | |
4115 | cmd_getval(g_ceph_context, cmdmap, "format", format); | |
4116 | boost::scoped_ptr<Formatter> f(Formatter::create(format, "json-pretty", "json-pretty")); | |
4117 | f->open_object_section("osd_location"); | |
4118 | f->dump_int("osd", osd); | |
4119 | f->dump_stream("ip") << osdmap.get_addr(osd); | |
4120 | f->open_object_section("crush_location"); | |
4121 | map<string,string> loc = osdmap.crush->get_full_location(osd); | |
4122 | for (map<string,string>::iterator p = loc.begin(); p != loc.end(); ++p) | |
4123 | f->dump_string(p->first.c_str(), p->second); | |
4124 | f->close_section(); | |
4125 | f->close_section(); | |
4126 | f->flush(rdata); | |
4127 | } else if (prefix == "osd metadata") { | |
4128 | int64_t osd = -1; | |
4129 | if (cmd_vartype_stringify(cmdmap["id"]).size() && | |
4130 | !cmd_getval(g_ceph_context, cmdmap, "id", osd)) { | |
4131 | ss << "unable to parse osd id value '" | |
4132 | << cmd_vartype_stringify(cmdmap["id"]) << "'"; | |
4133 | r = -EINVAL; | |
4134 | goto reply; | |
4135 | } | |
4136 | if (osd >= 0 && !osdmap.exists(osd)) { | |
4137 | ss << "osd." << osd << " does not exist"; | |
4138 | r = -ENOENT; | |
4139 | goto reply; | |
4140 | } | |
4141 | string format; | |
4142 | cmd_getval(g_ceph_context, cmdmap, "format", format); | |
4143 | boost::scoped_ptr<Formatter> f(Formatter::create(format, "json-pretty", "json-pretty")); | |
4144 | if (osd >= 0) { | |
4145 | f->open_object_section("osd_metadata"); | |
4146 | f->dump_unsigned("id", osd); | |
4147 | r = dump_osd_metadata(osd, f.get(), &ss); | |
4148 | if (r < 0) | |
4149 | goto reply; | |
4150 | f->close_section(); | |
4151 | } else { | |
4152 | r = 0; | |
4153 | f->open_array_section("osd_metadata"); | |
4154 | for (int i=0; i<osdmap.get_max_osd(); ++i) { | |
4155 | if (osdmap.exists(i)) { | |
4156 | f->open_object_section("osd"); | |
4157 | f->dump_unsigned("id", i); | |
4158 | r = dump_osd_metadata(i, f.get(), NULL); | |
4159 | if (r == -EINVAL || r == -ENOENT) { | |
4160 | // Drop error, continue to get other daemons' metadata | |
4161 | dout(4) << "No metadata for osd." << i << dendl; | |
4162 | r = 0; | |
4163 | } else if (r < 0) { | |
4164 | // Unexpected error | |
4165 | goto reply; | |
4166 | } | |
4167 | f->close_section(); | |
4168 | } | |
4169 | } | |
4170 | f->close_section(); | |
4171 | } | |
4172 | f->flush(rdata); | |
31f18b77 FG |
4173 | } else if (prefix == "osd versions") { |
4174 | if (!f) | |
4175 | f.reset(Formatter::create("json-pretty")); | |
4176 | count_metadata("ceph_version", f.get()); | |
4177 | f->flush(rdata); | |
4178 | r = 0; | |
4179 | } else if (prefix == "osd count-metadata") { | |
4180 | if (!f) | |
4181 | f.reset(Formatter::create("json-pretty")); | |
4182 | string field; | |
4183 | cmd_getval(g_ceph_context, cmdmap, "property", field); | |
4184 | count_metadata(field, f.get()); | |
4185 | f->flush(rdata); | |
4186 | r = 0; | |
7c673cae FG |
4187 | } else if (prefix == "osd map") { |
4188 | string poolstr, objstr, namespacestr; | |
4189 | cmd_getval(g_ceph_context, cmdmap, "pool", poolstr); | |
4190 | cmd_getval(g_ceph_context, cmdmap, "object", objstr); | |
4191 | cmd_getval(g_ceph_context, cmdmap, "nspace", namespacestr); | |
4192 | ||
4193 | int64_t pool = osdmap.lookup_pg_pool_name(poolstr.c_str()); | |
4194 | if (pool < 0) { | |
4195 | ss << "pool " << poolstr << " does not exist"; | |
4196 | r = -ENOENT; | |
4197 | goto reply; | |
4198 | } | |
4199 | object_locator_t oloc(pool, namespacestr); | |
4200 | object_t oid(objstr); | |
4201 | pg_t pgid = osdmap.object_locator_to_pg(oid, oloc); | |
4202 | pg_t mpgid = osdmap.raw_pg_to_pg(pgid); | |
4203 | vector<int> up, acting; | |
4204 | int up_p, acting_p; | |
4205 | osdmap.pg_to_up_acting_osds(mpgid, &up, &up_p, &acting, &acting_p); | |
4206 | ||
4207 | string fullobjname; | |
4208 | if (!namespacestr.empty()) | |
4209 | fullobjname = namespacestr + string("/") + oid.name; | |
4210 | else | |
4211 | fullobjname = oid.name; | |
4212 | if (f) { | |
4213 | f->open_object_section("osd_map"); | |
4214 | f->dump_unsigned("epoch", osdmap.get_epoch()); | |
4215 | f->dump_string("pool", poolstr); | |
4216 | f->dump_int("pool_id", pool); | |
4217 | f->dump_stream("objname") << fullobjname; | |
4218 | f->dump_stream("raw_pgid") << pgid; | |
4219 | f->dump_stream("pgid") << mpgid; | |
4220 | f->open_array_section("up"); | |
4221 | for (vector<int>::iterator p = up.begin(); p != up.end(); ++p) | |
4222 | f->dump_int("osd", *p); | |
4223 | f->close_section(); | |
4224 | f->dump_int("up_primary", up_p); | |
4225 | f->open_array_section("acting"); | |
4226 | for (vector<int>::iterator p = acting.begin(); p != acting.end(); ++p) | |
4227 | f->dump_int("osd", *p); | |
4228 | f->close_section(); | |
4229 | f->dump_int("acting_primary", acting_p); | |
4230 | f->close_section(); // osd_map | |
4231 | f->flush(rdata); | |
4232 | } else { | |
4233 | ds << "osdmap e" << osdmap.get_epoch() | |
4234 | << " pool '" << poolstr << "' (" << pool << ")" | |
4235 | << " object '" << fullobjname << "' ->" | |
4236 | << " pg " << pgid << " (" << mpgid << ")" | |
4237 | << " -> up (" << pg_vector_string(up) << ", p" << up_p << ") acting (" | |
4238 | << pg_vector_string(acting) << ", p" << acting_p << ")"; | |
4239 | rdata.append(ds); | |
4240 | } | |
4241 | ||
4242 | } else if (prefix == "pg map") { | |
4243 | pg_t pgid; | |
4244 | string pgidstr; | |
4245 | cmd_getval(g_ceph_context, cmdmap, "pgid", pgidstr); | |
4246 | if (!pgid.parse(pgidstr.c_str())) { | |
4247 | ss << "invalid pgid '" << pgidstr << "'"; | |
4248 | r = -EINVAL; | |
4249 | goto reply; | |
4250 | } | |
4251 | vector<int> up, acting; | |
4252 | if (!osdmap.have_pg_pool(pgid.pool())) { | |
4253 | ss << "pg '" << pgidstr << "' does not exist"; | |
4254 | r = -ENOENT; | |
4255 | goto reply; | |
4256 | } | |
4257 | pg_t mpgid = osdmap.raw_pg_to_pg(pgid); | |
4258 | osdmap.pg_to_up_acting_osds(pgid, up, acting); | |
4259 | if (f) { | |
4260 | f->open_object_section("pg_map"); | |
4261 | f->dump_unsigned("epoch", osdmap.get_epoch()); | |
4262 | f->dump_stream("raw_pgid") << pgid; | |
4263 | f->dump_stream("pgid") << mpgid; | |
4264 | f->open_array_section("up"); | |
4265 | for (auto osd : up) { | |
4266 | f->dump_int("up_osd", osd); | |
4267 | } | |
4268 | f->close_section(); | |
4269 | f->open_array_section("acting"); | |
4270 | for (auto osd : acting) { | |
4271 | f->dump_int("acting_osd", osd); | |
4272 | } | |
4273 | f->close_section(); | |
4274 | f->close_section(); | |
4275 | f->flush(rdata); | |
4276 | } else { | |
4277 | ds << "osdmap e" << osdmap.get_epoch() | |
4278 | << " pg " << pgid << " (" << mpgid << ")" | |
4279 | << " -> up " << up << " acting " << acting; | |
4280 | rdata.append(ds); | |
4281 | } | |
4282 | goto reply; | |
4283 | ||
224ce89b WB |
4284 | } else if (prefix == "osd scrub" || |
4285 | prefix == "osd deep-scrub" || | |
4286 | prefix == "osd repair") { | |
7c673cae FG |
4287 | string whostr; |
4288 | cmd_getval(g_ceph_context, cmdmap, "who", whostr); | |
4289 | vector<string> pvec; | |
4290 | get_str_vec(prefix, pvec); | |
4291 | ||
224ce89b | 4292 | if (whostr == "*" || whostr == "all" || whostr == "any") { |
7c673cae FG |
4293 | ss << "osds "; |
4294 | int c = 0; | |
4295 | for (int i = 0; i < osdmap.get_max_osd(); i++) | |
4296 | if (osdmap.is_up(i)) { | |
4297 | ss << (c++ ? "," : "") << i; | |
4298 | mon->try_send_message(new MOSDScrub(osdmap.get_fsid(), | |
4299 | pvec.back() == "repair", | |
4300 | pvec.back() == "deep-scrub"), | |
4301 | osdmap.get_inst(i)); | |
4302 | } | |
4303 | r = 0; | |
4304 | ss << " instructed to " << pvec.back(); | |
4305 | } else { | |
4306 | long osd = parse_osd_id(whostr.c_str(), &ss); | |
4307 | if (osd < 0) { | |
4308 | r = -EINVAL; | |
4309 | } else if (osdmap.is_up(osd)) { | |
4310 | mon->try_send_message(new MOSDScrub(osdmap.get_fsid(), | |
4311 | pvec.back() == "repair", | |
4312 | pvec.back() == "deep-scrub"), | |
4313 | osdmap.get_inst(osd)); | |
4314 | ss << "osd." << osd << " instructed to " << pvec.back(); | |
4315 | } else { | |
4316 | ss << "osd." << osd << " is not up"; | |
4317 | r = -EAGAIN; | |
4318 | } | |
4319 | } | |
4320 | } else if (prefix == "osd lspools") { | |
4321 | int64_t auid; | |
4322 | cmd_getval(g_ceph_context, cmdmap, "auid", auid, int64_t(0)); | |
4323 | if (f) | |
4324 | f->open_array_section("pools"); | |
4325 | for (map<int64_t, pg_pool_t>::iterator p = osdmap.pools.begin(); | |
4326 | p != osdmap.pools.end(); | |
4327 | ++p) { | |
4328 | if (!auid || p->second.auid == (uint64_t)auid) { | |
4329 | if (f) { | |
4330 | f->open_object_section("pool"); | |
4331 | f->dump_int("poolnum", p->first); | |
4332 | f->dump_string("poolname", osdmap.pool_name[p->first]); | |
4333 | f->close_section(); | |
4334 | } else { | |
4335 | ds << p->first << ' ' << osdmap.pool_name[p->first] << ','; | |
4336 | } | |
4337 | } | |
4338 | } | |
4339 | if (f) { | |
4340 | f->close_section(); | |
4341 | f->flush(ds); | |
4342 | } | |
4343 | rdata.append(ds); | |
4344 | } else if (prefix == "osd blacklist ls") { | |
4345 | if (f) | |
4346 | f->open_array_section("blacklist"); | |
4347 | ||
4348 | for (ceph::unordered_map<entity_addr_t,utime_t>::iterator p = osdmap.blacklist.begin(); | |
4349 | p != osdmap.blacklist.end(); | |
4350 | ++p) { | |
4351 | if (f) { | |
4352 | f->open_object_section("entry"); | |
4353 | f->dump_stream("addr") << p->first; | |
4354 | f->dump_stream("until") << p->second; | |
4355 | f->close_section(); | |
4356 | } else { | |
4357 | stringstream ss; | |
4358 | string s; | |
4359 | ss << p->first << " " << p->second; | |
4360 | getline(ss, s); | |
4361 | s += "\n"; | |
4362 | rdata.append(s); | |
4363 | } | |
4364 | } | |
4365 | if (f) { | |
4366 | f->close_section(); | |
4367 | f->flush(rdata); | |
4368 | } | |
4369 | ss << "listed " << osdmap.blacklist.size() << " entries"; | |
4370 | ||
4371 | } else if (prefix == "osd pool ls") { | |
4372 | string detail; | |
4373 | cmd_getval(g_ceph_context, cmdmap, "detail", detail); | |
4374 | if (!f && detail == "detail") { | |
4375 | ostringstream ss; | |
4376 | osdmap.print_pools(ss); | |
4377 | rdata.append(ss.str()); | |
4378 | } else { | |
4379 | if (f) | |
4380 | f->open_array_section("pools"); | |
4381 | for (map<int64_t,pg_pool_t>::const_iterator it = osdmap.get_pools().begin(); | |
4382 | it != osdmap.get_pools().end(); | |
4383 | ++it) { | |
4384 | if (f) { | |
4385 | if (detail == "detail") { | |
4386 | f->open_object_section("pool"); | |
4387 | f->dump_string("pool_name", osdmap.get_pool_name(it->first)); | |
4388 | it->second.dump(f.get()); | |
4389 | f->close_section(); | |
4390 | } else { | |
4391 | f->dump_string("pool_name", osdmap.get_pool_name(it->first)); | |
4392 | } | |
4393 | } else { | |
4394 | rdata.append(osdmap.get_pool_name(it->first) + "\n"); | |
4395 | } | |
4396 | } | |
4397 | if (f) { | |
4398 | f->close_section(); | |
4399 | f->flush(rdata); | |
4400 | } | |
4401 | } | |
4402 | ||
4403 | } else if (prefix == "osd crush get-tunable") { | |
4404 | string tunable; | |
4405 | cmd_getval(g_ceph_context, cmdmap, "tunable", tunable); | |
4406 | ostringstream rss; | |
4407 | if (f) | |
4408 | f->open_object_section("tunable"); | |
4409 | if (tunable == "straw_calc_version") { | |
4410 | if (f) | |
4411 | f->dump_int(tunable.c_str(), osdmap.crush->get_straw_calc_version()); | |
4412 | else | |
4413 | rss << osdmap.crush->get_straw_calc_version() << "\n"; | |
4414 | } else { | |
4415 | r = -EINVAL; | |
4416 | goto reply; | |
4417 | } | |
4418 | if (f) { | |
4419 | f->close_section(); | |
4420 | f->flush(rdata); | |
4421 | } else { | |
4422 | rdata.append(rss.str()); | |
4423 | } | |
4424 | r = 0; | |
4425 | ||
4426 | } else if (prefix == "osd pool get") { | |
4427 | string poolstr; | |
4428 | cmd_getval(g_ceph_context, cmdmap, "pool", poolstr); | |
4429 | int64_t pool = osdmap.lookup_pg_pool_name(poolstr.c_str()); | |
4430 | if (pool < 0) { | |
4431 | ss << "unrecognized pool '" << poolstr << "'"; | |
4432 | r = -ENOENT; | |
4433 | goto reply; | |
4434 | } | |
4435 | ||
4436 | const pg_pool_t *p = osdmap.get_pg_pool(pool); | |
4437 | string var; | |
4438 | cmd_getval(g_ceph_context, cmdmap, "var", var); | |
4439 | ||
4440 | typedef std::map<std::string, osd_pool_get_choices> choices_map_t; | |
4441 | const choices_map_t ALL_CHOICES = { | |
4442 | {"size", SIZE}, | |
4443 | {"min_size", MIN_SIZE}, | |
4444 | {"crash_replay_interval", CRASH_REPLAY_INTERVAL}, | |
4445 | {"pg_num", PG_NUM}, {"pgp_num", PGP_NUM}, | |
4446 | {"crush_rule", CRUSH_RULE}, | |
7c673cae FG |
4447 | {"hashpspool", HASHPSPOOL}, {"nodelete", NODELETE}, |
4448 | {"nopgchange", NOPGCHANGE}, {"nosizechange", NOSIZECHANGE}, | |
4449 | {"noscrub", NOSCRUB}, {"nodeep-scrub", NODEEP_SCRUB}, | |
4450 | {"write_fadvise_dontneed", WRITE_FADVISE_DONTNEED}, | |
4451 | {"hit_set_type", HIT_SET_TYPE}, {"hit_set_period", HIT_SET_PERIOD}, | |
4452 | {"hit_set_count", HIT_SET_COUNT}, {"hit_set_fpp", HIT_SET_FPP}, | |
4453 | {"use_gmt_hitset", USE_GMT_HITSET}, | |
4454 | {"auid", AUID}, {"target_max_objects", TARGET_MAX_OBJECTS}, | |
4455 | {"target_max_bytes", TARGET_MAX_BYTES}, | |
4456 | {"cache_target_dirty_ratio", CACHE_TARGET_DIRTY_RATIO}, | |
4457 | {"cache_target_dirty_high_ratio", CACHE_TARGET_DIRTY_HIGH_RATIO}, | |
4458 | {"cache_target_full_ratio", CACHE_TARGET_FULL_RATIO}, | |
4459 | {"cache_min_flush_age", CACHE_MIN_FLUSH_AGE}, | |
4460 | {"cache_min_evict_age", CACHE_MIN_EVICT_AGE}, | |
4461 | {"erasure_code_profile", ERASURE_CODE_PROFILE}, | |
4462 | {"min_read_recency_for_promote", MIN_READ_RECENCY_FOR_PROMOTE}, | |
4463 | {"min_write_recency_for_promote", MIN_WRITE_RECENCY_FOR_PROMOTE}, | |
4464 | {"fast_read", FAST_READ}, | |
4465 | {"hit_set_grade_decay_rate", HIT_SET_GRADE_DECAY_RATE}, | |
4466 | {"hit_set_search_last_n", HIT_SET_SEARCH_LAST_N}, | |
4467 | {"scrub_min_interval", SCRUB_MIN_INTERVAL}, | |
4468 | {"scrub_max_interval", SCRUB_MAX_INTERVAL}, | |
4469 | {"deep_scrub_interval", DEEP_SCRUB_INTERVAL}, | |
4470 | {"recovery_priority", RECOVERY_PRIORITY}, | |
4471 | {"recovery_op_priority", RECOVERY_OP_PRIORITY}, | |
4472 | {"scrub_priority", SCRUB_PRIORITY}, | |
4473 | {"compression_mode", COMPRESSION_MODE}, | |
4474 | {"compression_algorithm", COMPRESSION_ALGORITHM}, | |
4475 | {"compression_required_ratio", COMPRESSION_REQUIRED_RATIO}, | |
4476 | {"compression_max_blob_size", COMPRESSION_MAX_BLOB_SIZE}, | |
4477 | {"compression_min_blob_size", COMPRESSION_MIN_BLOB_SIZE}, | |
4478 | {"csum_type", CSUM_TYPE}, | |
4479 | {"csum_max_block", CSUM_MAX_BLOCK}, | |
4480 | {"csum_min_block", CSUM_MIN_BLOCK}, | |
4481 | }; | |
4482 | ||
4483 | typedef std::set<osd_pool_get_choices> choices_set_t; | |
4484 | ||
4485 | const choices_set_t ONLY_TIER_CHOICES = { | |
4486 | HIT_SET_TYPE, HIT_SET_PERIOD, HIT_SET_COUNT, HIT_SET_FPP, | |
4487 | TARGET_MAX_OBJECTS, TARGET_MAX_BYTES, CACHE_TARGET_FULL_RATIO, | |
4488 | CACHE_TARGET_DIRTY_RATIO, CACHE_TARGET_DIRTY_HIGH_RATIO, | |
4489 | CACHE_MIN_FLUSH_AGE, CACHE_MIN_EVICT_AGE, | |
4490 | MIN_READ_RECENCY_FOR_PROMOTE, | |
c07f9fc5 | 4491 | MIN_WRITE_RECENCY_FOR_PROMOTE, |
7c673cae FG |
4492 | HIT_SET_GRADE_DECAY_RATE, HIT_SET_SEARCH_LAST_N |
4493 | }; | |
4494 | const choices_set_t ONLY_ERASURE_CHOICES = { | |
4495 | ERASURE_CODE_PROFILE | |
4496 | }; | |
4497 | ||
4498 | choices_set_t selected_choices; | |
4499 | if (var == "all") { | |
4500 | for(choices_map_t::const_iterator it = ALL_CHOICES.begin(); | |
4501 | it != ALL_CHOICES.end(); ++it) { | |
4502 | selected_choices.insert(it->second); | |
4503 | } | |
4504 | ||
4505 | if(!p->is_tier()) { | |
4506 | selected_choices = subtract_second_from_first(selected_choices, | |
4507 | ONLY_TIER_CHOICES); | |
4508 | } | |
4509 | ||
4510 | if(!p->is_erasure()) { | |
4511 | selected_choices = subtract_second_from_first(selected_choices, | |
4512 | ONLY_ERASURE_CHOICES); | |
4513 | } | |
4514 | } else /* var != "all" */ { | |
4515 | choices_map_t::const_iterator found = ALL_CHOICES.find(var); | |
4516 | osd_pool_get_choices selected = found->second; | |
4517 | ||
4518 | if (!p->is_tier() && | |
4519 | ONLY_TIER_CHOICES.find(selected) != ONLY_TIER_CHOICES.end()) { | |
4520 | ss << "pool '" << poolstr | |
4521 | << "' is not a tier pool: variable not applicable"; | |
4522 | r = -EACCES; | |
4523 | goto reply; | |
4524 | } | |
4525 | ||
4526 | if (!p->is_erasure() && | |
4527 | ONLY_ERASURE_CHOICES.find(selected) | |
4528 | != ONLY_ERASURE_CHOICES.end()) { | |
4529 | ss << "pool '" << poolstr | |
4530 | << "' is not a erasure pool: variable not applicable"; | |
4531 | r = -EACCES; | |
4532 | goto reply; | |
4533 | } | |
4534 | ||
4535 | selected_choices.insert(selected); | |
4536 | } | |
4537 | ||
4538 | if (f) { | |
4539 | for(choices_set_t::const_iterator it = selected_choices.begin(); | |
4540 | it != selected_choices.end(); ++it) { | |
4541 | choices_map_t::const_iterator i; | |
c07f9fc5 FG |
4542 | for (i = ALL_CHOICES.begin(); i != ALL_CHOICES.end(); ++i) { |
4543 | if (i->second == *it) { | |
4544 | break; | |
4545 | } | |
4546 | } | |
4547 | assert(i != ALL_CHOICES.end()); | |
4548 | bool pool_opt = pool_opts_t::is_opt_name(i->first); | |
4549 | if (!pool_opt) { | |
4550 | f->open_object_section("pool"); | |
4551 | f->dump_string("pool", poolstr); | |
4552 | f->dump_int("pool_id", pool); | |
4553 | } | |
7c673cae FG |
4554 | switch(*it) { |
4555 | case PG_NUM: | |
4556 | f->dump_int("pg_num", p->get_pg_num()); | |
4557 | break; | |
4558 | case PGP_NUM: | |
4559 | f->dump_int("pgp_num", p->get_pgp_num()); | |
4560 | break; | |
4561 | case AUID: | |
4562 | f->dump_int("auid", p->get_auid()); | |
4563 | break; | |
4564 | case SIZE: | |
4565 | f->dump_int("size", p->get_size()); | |
4566 | break; | |
4567 | case MIN_SIZE: | |
4568 | f->dump_int("min_size", p->get_min_size()); | |
4569 | break; | |
4570 | case CRASH_REPLAY_INTERVAL: | |
4571 | f->dump_int("crash_replay_interval", | |
4572 | p->get_crash_replay_interval()); | |
4573 | break; | |
4574 | case CRUSH_RULE: | |
31f18b77 | 4575 | if (osdmap.crush->rule_exists(p->get_crush_rule())) { |
7c673cae | 4576 | f->dump_string("crush_rule", osdmap.crush->get_rule_name( |
31f18b77 | 4577 | p->get_crush_rule())); |
7c673cae | 4578 | } else { |
31f18b77 | 4579 | f->dump_string("crush_rule", stringify(p->get_crush_rule())); |
7c673cae FG |
4580 | } |
4581 | break; | |
7c673cae FG |
4582 | case HASHPSPOOL: |
4583 | case NODELETE: | |
4584 | case NOPGCHANGE: | |
4585 | case NOSIZECHANGE: | |
4586 | case WRITE_FADVISE_DONTNEED: | |
4587 | case NOSCRUB: | |
4588 | case NODEEP_SCRUB: | |
7c673cae FG |
4589 | f->dump_string(i->first.c_str(), |
4590 | p->has_flag(pg_pool_t::get_flag_by_name(i->first)) ? | |
4591 | "true" : "false"); | |
4592 | break; | |
4593 | case HIT_SET_PERIOD: | |
4594 | f->dump_int("hit_set_period", p->hit_set_period); | |
4595 | break; | |
4596 | case HIT_SET_COUNT: | |
4597 | f->dump_int("hit_set_count", p->hit_set_count); | |
4598 | break; | |
4599 | case HIT_SET_TYPE: | |
4600 | f->dump_string("hit_set_type", | |
4601 | HitSet::get_type_name(p->hit_set_params.get_type())); | |
4602 | break; | |
4603 | case HIT_SET_FPP: | |
4604 | { | |
4605 | if (p->hit_set_params.get_type() == HitSet::TYPE_BLOOM) { | |
4606 | BloomHitSet::Params *bloomp = | |
4607 | static_cast<BloomHitSet::Params*>(p->hit_set_params.impl.get()); | |
4608 | f->dump_float("hit_set_fpp", bloomp->get_fpp()); | |
4609 | } else if(var != "all") { | |
4610 | f->close_section(); | |
4611 | ss << "hit set is not of type Bloom; " << | |
4612 | "invalid to get a false positive rate!"; | |
4613 | r = -EINVAL; | |
4614 | goto reply; | |
4615 | } | |
4616 | } | |
4617 | break; | |
4618 | case USE_GMT_HITSET: | |
4619 | f->dump_bool("use_gmt_hitset", p->use_gmt_hitset); | |
4620 | break; | |
4621 | case TARGET_MAX_OBJECTS: | |
4622 | f->dump_unsigned("target_max_objects", p->target_max_objects); | |
4623 | break; | |
4624 | case TARGET_MAX_BYTES: | |
4625 | f->dump_unsigned("target_max_bytes", p->target_max_bytes); | |
4626 | break; | |
4627 | case CACHE_TARGET_DIRTY_RATIO: | |
4628 | f->dump_unsigned("cache_target_dirty_ratio_micro", | |
4629 | p->cache_target_dirty_ratio_micro); | |
4630 | f->dump_float("cache_target_dirty_ratio", | |
4631 | ((float)p->cache_target_dirty_ratio_micro/1000000)); | |
4632 | break; | |
4633 | case CACHE_TARGET_DIRTY_HIGH_RATIO: | |
4634 | f->dump_unsigned("cache_target_dirty_high_ratio_micro", | |
4635 | p->cache_target_dirty_high_ratio_micro); | |
4636 | f->dump_float("cache_target_dirty_high_ratio", | |
4637 | ((float)p->cache_target_dirty_high_ratio_micro/1000000)); | |
4638 | break; | |
4639 | case CACHE_TARGET_FULL_RATIO: | |
4640 | f->dump_unsigned("cache_target_full_ratio_micro", | |
4641 | p->cache_target_full_ratio_micro); | |
4642 | f->dump_float("cache_target_full_ratio", | |
4643 | ((float)p->cache_target_full_ratio_micro/1000000)); | |
4644 | break; | |
4645 | case CACHE_MIN_FLUSH_AGE: | |
4646 | f->dump_unsigned("cache_min_flush_age", p->cache_min_flush_age); | |
4647 | break; | |
4648 | case CACHE_MIN_EVICT_AGE: | |
4649 | f->dump_unsigned("cache_min_evict_age", p->cache_min_evict_age); | |
4650 | break; | |
4651 | case ERASURE_CODE_PROFILE: | |
4652 | f->dump_string("erasure_code_profile", p->erasure_code_profile); | |
4653 | break; | |
4654 | case MIN_READ_RECENCY_FOR_PROMOTE: | |
4655 | f->dump_int("min_read_recency_for_promote", | |
4656 | p->min_read_recency_for_promote); | |
4657 | break; | |
4658 | case MIN_WRITE_RECENCY_FOR_PROMOTE: | |
4659 | f->dump_int("min_write_recency_for_promote", | |
4660 | p->min_write_recency_for_promote); | |
4661 | break; | |
4662 | case FAST_READ: | |
4663 | f->dump_int("fast_read", p->fast_read); | |
4664 | break; | |
4665 | case HIT_SET_GRADE_DECAY_RATE: | |
4666 | f->dump_int("hit_set_grade_decay_rate", | |
4667 | p->hit_set_grade_decay_rate); | |
4668 | break; | |
4669 | case HIT_SET_SEARCH_LAST_N: | |
4670 | f->dump_int("hit_set_search_last_n", | |
4671 | p->hit_set_search_last_n); | |
4672 | break; | |
4673 | case SCRUB_MIN_INTERVAL: | |
4674 | case SCRUB_MAX_INTERVAL: | |
4675 | case DEEP_SCRUB_INTERVAL: | |
4676 | case RECOVERY_PRIORITY: | |
4677 | case RECOVERY_OP_PRIORITY: | |
4678 | case SCRUB_PRIORITY: | |
4679 | case COMPRESSION_MODE: | |
4680 | case COMPRESSION_ALGORITHM: | |
4681 | case COMPRESSION_REQUIRED_RATIO: | |
4682 | case COMPRESSION_MAX_BLOB_SIZE: | |
4683 | case COMPRESSION_MIN_BLOB_SIZE: | |
4684 | case CSUM_TYPE: | |
4685 | case CSUM_MAX_BLOCK: | |
4686 | case CSUM_MIN_BLOCK: | |
c07f9fc5 FG |
4687 | pool_opts_t::key_t key = pool_opts_t::get_opt_desc(i->first).key; |
4688 | if (p->opts.is_set(key)) { | |
4689 | f->open_object_section("pool"); | |
4690 | f->dump_string("pool", poolstr); | |
4691 | f->dump_int("pool_id", pool); | |
4692 | if(*it == CSUM_TYPE) { | |
4693 | int val; | |
4694 | p->opts.get(pool_opts_t::CSUM_TYPE, &val); | |
4695 | f->dump_string(i->first.c_str(), Checksummer::get_csum_type_string(val)); | |
4696 | } else { | |
4697 | p->opts.dump(i->first, f.get()); | |
4698 | } | |
4699 | f->close_section(); | |
4700 | f->flush(rdata); | |
7c673cae FG |
4701 | } |
4702 | break; | |
4703 | } | |
c07f9fc5 FG |
4704 | if (!pool_opt) { |
4705 | f->close_section(); | |
4706 | f->flush(rdata); | |
4707 | } | |
7c673cae FG |
4708 | } |
4709 | ||
4710 | } else /* !f */ { | |
4711 | for(choices_set_t::const_iterator it = selected_choices.begin(); | |
4712 | it != selected_choices.end(); ++it) { | |
4713 | choices_map_t::const_iterator i; | |
4714 | switch(*it) { | |
4715 | case PG_NUM: | |
4716 | ss << "pg_num: " << p->get_pg_num() << "\n"; | |
4717 | break; | |
4718 | case PGP_NUM: | |
4719 | ss << "pgp_num: " << p->get_pgp_num() << "\n"; | |
4720 | break; | |
4721 | case AUID: | |
4722 | ss << "auid: " << p->get_auid() << "\n"; | |
4723 | break; | |
4724 | case SIZE: | |
4725 | ss << "size: " << p->get_size() << "\n"; | |
4726 | break; | |
4727 | case MIN_SIZE: | |
4728 | ss << "min_size: " << p->get_min_size() << "\n"; | |
4729 | break; | |
4730 | case CRASH_REPLAY_INTERVAL: | |
4731 | ss << "crash_replay_interval: " << | |
4732 | p->get_crash_replay_interval() << "\n"; | |
4733 | break; | |
4734 | case CRUSH_RULE: | |
31f18b77 | 4735 | if (osdmap.crush->rule_exists(p->get_crush_rule())) { |
7c673cae | 4736 | ss << "crush_rule: " << osdmap.crush->get_rule_name( |
31f18b77 | 4737 | p->get_crush_rule()) << "\n"; |
7c673cae | 4738 | } else { |
31f18b77 | 4739 | ss << "crush_rule: " << p->get_crush_rule() << "\n"; |
7c673cae FG |
4740 | } |
4741 | break; | |
7c673cae FG |
4742 | case HIT_SET_PERIOD: |
4743 | ss << "hit_set_period: " << p->hit_set_period << "\n"; | |
4744 | break; | |
4745 | case HIT_SET_COUNT: | |
4746 | ss << "hit_set_count: " << p->hit_set_count << "\n"; | |
4747 | break; | |
4748 | case HIT_SET_TYPE: | |
4749 | ss << "hit_set_type: " << | |
4750 | HitSet::get_type_name(p->hit_set_params.get_type()) << "\n"; | |
4751 | break; | |
4752 | case HIT_SET_FPP: | |
4753 | { | |
4754 | if (p->hit_set_params.get_type() == HitSet::TYPE_BLOOM) { | |
4755 | BloomHitSet::Params *bloomp = | |
4756 | static_cast<BloomHitSet::Params*>(p->hit_set_params.impl.get()); | |
4757 | ss << "hit_set_fpp: " << bloomp->get_fpp() << "\n"; | |
4758 | } else if(var != "all") { | |
4759 | ss << "hit set is not of type Bloom; " << | |
4760 | "invalid to get a false positive rate!"; | |
4761 | r = -EINVAL; | |
4762 | goto reply; | |
4763 | } | |
4764 | } | |
4765 | break; | |
4766 | case USE_GMT_HITSET: | |
4767 | ss << "use_gmt_hitset: " << p->use_gmt_hitset << "\n"; | |
4768 | break; | |
4769 | case TARGET_MAX_OBJECTS: | |
4770 | ss << "target_max_objects: " << p->target_max_objects << "\n"; | |
4771 | break; | |
4772 | case TARGET_MAX_BYTES: | |
4773 | ss << "target_max_bytes: " << p->target_max_bytes << "\n"; | |
4774 | break; | |
4775 | case CACHE_TARGET_DIRTY_RATIO: | |
4776 | ss << "cache_target_dirty_ratio: " | |
4777 | << ((float)p->cache_target_dirty_ratio_micro/1000000) << "\n"; | |
4778 | break; | |
4779 | case CACHE_TARGET_DIRTY_HIGH_RATIO: | |
4780 | ss << "cache_target_dirty_high_ratio: " | |
4781 | << ((float)p->cache_target_dirty_high_ratio_micro/1000000) << "\n"; | |
4782 | break; | |
4783 | case CACHE_TARGET_FULL_RATIO: | |
4784 | ss << "cache_target_full_ratio: " | |
4785 | << ((float)p->cache_target_full_ratio_micro/1000000) << "\n"; | |
4786 | break; | |
4787 | case CACHE_MIN_FLUSH_AGE: | |
4788 | ss << "cache_min_flush_age: " << p->cache_min_flush_age << "\n"; | |
4789 | break; | |
4790 | case CACHE_MIN_EVICT_AGE: | |
4791 | ss << "cache_min_evict_age: " << p->cache_min_evict_age << "\n"; | |
4792 | break; | |
4793 | case ERASURE_CODE_PROFILE: | |
4794 | ss << "erasure_code_profile: " << p->erasure_code_profile << "\n"; | |
4795 | break; | |
4796 | case MIN_READ_RECENCY_FOR_PROMOTE: | |
4797 | ss << "min_read_recency_for_promote: " << | |
4798 | p->min_read_recency_for_promote << "\n"; | |
4799 | break; | |
4800 | case HIT_SET_GRADE_DECAY_RATE: | |
4801 | ss << "hit_set_grade_decay_rate: " << | |
4802 | p->hit_set_grade_decay_rate << "\n"; | |
4803 | break; | |
4804 | case HIT_SET_SEARCH_LAST_N: | |
4805 | ss << "hit_set_search_last_n: " << | |
4806 | p->hit_set_search_last_n << "\n"; | |
4807 | break; | |
4808 | case HASHPSPOOL: | |
4809 | case NODELETE: | |
4810 | case NOPGCHANGE: | |
4811 | case NOSIZECHANGE: | |
4812 | case WRITE_FADVISE_DONTNEED: | |
4813 | case NOSCRUB: | |
4814 | case NODEEP_SCRUB: | |
4815 | for (i = ALL_CHOICES.begin(); i != ALL_CHOICES.end(); ++i) { | |
4816 | if (i->second == *it) | |
4817 | break; | |
4818 | } | |
4819 | assert(i != ALL_CHOICES.end()); | |
4820 | ss << i->first << ": " << | |
4821 | (p->has_flag(pg_pool_t::get_flag_by_name(i->first)) ? | |
4822 | "true" : "false") << "\n"; | |
4823 | break; | |
4824 | case MIN_WRITE_RECENCY_FOR_PROMOTE: | |
4825 | ss << "min_write_recency_for_promote: " << | |
4826 | p->min_write_recency_for_promote << "\n"; | |
4827 | break; | |
4828 | case FAST_READ: | |
4829 | ss << "fast_read: " << p->fast_read << "\n"; | |
4830 | break; | |
4831 | case SCRUB_MIN_INTERVAL: | |
4832 | case SCRUB_MAX_INTERVAL: | |
4833 | case DEEP_SCRUB_INTERVAL: | |
4834 | case RECOVERY_PRIORITY: | |
4835 | case RECOVERY_OP_PRIORITY: | |
4836 | case SCRUB_PRIORITY: | |
4837 | case COMPRESSION_MODE: | |
4838 | case COMPRESSION_ALGORITHM: | |
4839 | case COMPRESSION_REQUIRED_RATIO: | |
4840 | case COMPRESSION_MAX_BLOB_SIZE: | |
4841 | case COMPRESSION_MIN_BLOB_SIZE: | |
4842 | case CSUM_TYPE: | |
4843 | case CSUM_MAX_BLOCK: | |
4844 | case CSUM_MIN_BLOCK: | |
4845 | for (i = ALL_CHOICES.begin(); i != ALL_CHOICES.end(); ++i) { | |
4846 | if (i->second == *it) | |
4847 | break; | |
4848 | } | |
4849 | assert(i != ALL_CHOICES.end()); | |
4850 | { | |
4851 | pool_opts_t::key_t key = pool_opts_t::get_opt_desc(i->first).key; | |
4852 | if (p->opts.is_set(key)) { | |
4853 | if(key == pool_opts_t::CSUM_TYPE) { | |
4854 | int val; | |
4855 | p->opts.get(key, &val); | |
4856 | ss << i->first << ": " << Checksummer::get_csum_type_string(val) << "\n"; | |
4857 | } else { | |
4858 | ss << i->first << ": " << p->opts.get(key) << "\n"; | |
4859 | } | |
4860 | } | |
4861 | } | |
4862 | break; | |
4863 | } | |
4864 | rdata.append(ss.str()); | |
4865 | ss.str(""); | |
4866 | } | |
4867 | } | |
4868 | r = 0; | |
4869 | } else if (prefix == "osd pool stats") { | |
31f18b77 FG |
4870 | r = mon->pgservice->process_pg_command(prefix, cmdmap, |
4871 | osdmap, f.get(), &ss, &rdata); | |
7c673cae FG |
4872 | } else if (prefix == "osd pool get-quota") { |
4873 | string pool_name; | |
4874 | cmd_getval(g_ceph_context, cmdmap, "pool", pool_name); | |
4875 | ||
4876 | int64_t poolid = osdmap.lookup_pg_pool_name(pool_name); | |
4877 | if (poolid < 0) { | |
4878 | assert(poolid == -ENOENT); | |
4879 | ss << "unrecognized pool '" << pool_name << "'"; | |
4880 | r = -ENOENT; | |
4881 | goto reply; | |
4882 | } | |
4883 | const pg_pool_t *p = osdmap.get_pg_pool(poolid); | |
4884 | ||
4885 | if (f) { | |
4886 | f->open_object_section("pool_quotas"); | |
4887 | f->dump_string("pool_name", pool_name); | |
4888 | f->dump_unsigned("pool_id", poolid); | |
4889 | f->dump_unsigned("quota_max_objects", p->quota_max_objects); | |
4890 | f->dump_unsigned("quota_max_bytes", p->quota_max_bytes); | |
4891 | f->close_section(); | |
4892 | f->flush(rdata); | |
4893 | } else { | |
4894 | stringstream rs; | |
4895 | rs << "quotas for pool '" << pool_name << "':\n" | |
4896 | << " max objects: "; | |
4897 | if (p->quota_max_objects == 0) | |
4898 | rs << "N/A"; | |
4899 | else | |
4900 | rs << si_t(p->quota_max_objects) << " objects"; | |
4901 | rs << "\n" | |
4902 | << " max bytes : "; | |
4903 | if (p->quota_max_bytes == 0) | |
4904 | rs << "N/A"; | |
4905 | else | |
4906 | rs << si_t(p->quota_max_bytes) << "B"; | |
4907 | rdata.append(rs.str()); | |
4908 | } | |
4909 | rdata.append("\n"); | |
4910 | r = 0; | |
4911 | } else if (prefix == "osd crush rule list" || | |
4912 | prefix == "osd crush rule ls") { | |
c07f9fc5 FG |
4913 | if (f) { |
4914 | f->open_array_section("rules"); | |
4915 | osdmap.crush->list_rules(f.get()); | |
4916 | f->close_section(); | |
4917 | f->flush(rdata); | |
4918 | } else { | |
4919 | ostringstream ss; | |
4920 | osdmap.crush->list_rules(&ss); | |
4921 | rdata.append(ss.str()); | |
4922 | } | |
7c673cae FG |
4923 | } else if (prefix == "osd crush rule dump") { |
4924 | string name; | |
4925 | cmd_getval(g_ceph_context, cmdmap, "name", name); | |
4926 | string format; | |
4927 | cmd_getval(g_ceph_context, cmdmap, "format", format); | |
4928 | boost::scoped_ptr<Formatter> f(Formatter::create(format, "json-pretty", "json-pretty")); | |
4929 | if (name == "") { | |
4930 | f->open_array_section("rules"); | |
4931 | osdmap.crush->dump_rules(f.get()); | |
4932 | f->close_section(); | |
4933 | } else { | |
4934 | int ruleno = osdmap.crush->get_rule_id(name); | |
4935 | if (ruleno < 0) { | |
31f18b77 | 4936 | ss << "unknown crush rule '" << name << "'"; |
7c673cae FG |
4937 | r = ruleno; |
4938 | goto reply; | |
4939 | } | |
4940 | osdmap.crush->dump_rule(ruleno, f.get()); | |
4941 | } | |
4942 | ostringstream rs; | |
4943 | f->flush(rs); | |
4944 | rs << "\n"; | |
4945 | rdata.append(rs.str()); | |
4946 | } else if (prefix == "osd crush dump") { | |
4947 | string format; | |
4948 | cmd_getval(g_ceph_context, cmdmap, "format", format); | |
4949 | boost::scoped_ptr<Formatter> f(Formatter::create(format, "json-pretty", "json-pretty")); | |
4950 | f->open_object_section("crush_map"); | |
4951 | osdmap.crush->dump(f.get()); | |
4952 | f->close_section(); | |
4953 | ostringstream rs; | |
4954 | f->flush(rs); | |
4955 | rs << "\n"; | |
4956 | rdata.append(rs.str()); | |
4957 | } else if (prefix == "osd crush show-tunables") { | |
4958 | string format; | |
4959 | cmd_getval(g_ceph_context, cmdmap, "format", format); | |
4960 | boost::scoped_ptr<Formatter> f(Formatter::create(format, "json-pretty", "json-pretty")); | |
4961 | f->open_object_section("crush_map_tunables"); | |
4962 | osdmap.crush->dump_tunables(f.get()); | |
4963 | f->close_section(); | |
4964 | ostringstream rs; | |
4965 | f->flush(rs); | |
4966 | rs << "\n"; | |
4967 | rdata.append(rs.str()); | |
4968 | } else if (prefix == "osd crush tree") { | |
c07f9fc5 FG |
4969 | string shadow; |
4970 | cmd_getval(g_ceph_context, cmdmap, "shadow", shadow); | |
4971 | bool show_shadow = shadow == "--show-shadow"; | |
4972 | boost::scoped_ptr<Formatter> f(Formatter::create(format)); | |
4973 | if (f) { | |
4974 | osdmap.crush->dump_tree(nullptr, | |
4975 | f.get(), | |
4976 | osdmap.get_pool_names(), | |
4977 | show_shadow); | |
4978 | f->flush(rdata); | |
4979 | } else { | |
4980 | ostringstream ss; | |
4981 | osdmap.crush->dump_tree(&ss, | |
4982 | nullptr, | |
4983 | osdmap.get_pool_names(), | |
4984 | show_shadow); | |
4985 | rdata.append(ss.str()); | |
4986 | } | |
d2e6a577 FG |
4987 | } else if (prefix == "osd crush ls") { |
4988 | string name; | |
4989 | if (!cmd_getval(g_ceph_context, cmdmap, "node", name)) { | |
4990 | ss << "no node specified"; | |
4991 | r = -EINVAL; | |
4992 | goto reply; | |
4993 | } | |
4994 | if (!osdmap.crush->name_exists(name)) { | |
4995 | ss << "node '" << name << "' does not exist"; | |
4996 | r = -ENOENT; | |
4997 | goto reply; | |
4998 | } | |
4999 | int id = osdmap.crush->get_item_id(name); | |
5000 | list<int> result; | |
5001 | if (id >= 0) { | |
5002 | result.push_back(id); | |
5003 | } else { | |
5004 | int num = osdmap.crush->get_bucket_size(id); | |
5005 | for (int i = 0; i < num; ++i) { | |
5006 | result.push_back(osdmap.crush->get_bucket_item(id, i)); | |
5007 | } | |
5008 | } | |
5009 | if (f) { | |
5010 | f->open_array_section("items"); | |
5011 | for (auto i : result) { | |
5012 | f->dump_string("item", osdmap.crush->get_item_name(i)); | |
5013 | } | |
5014 | f->close_section(); | |
5015 | f->flush(rdata); | |
5016 | } else { | |
5017 | ostringstream ss; | |
5018 | for (auto i : result) { | |
5019 | ss << osdmap.crush->get_item_name(i) << "\n"; | |
5020 | } | |
5021 | rdata.append(ss.str()); | |
5022 | } | |
5023 | r = 0; | |
7c673cae FG |
5024 | } else if (prefix == "osd crush class ls") { |
5025 | boost::scoped_ptr<Formatter> f(Formatter::create(format, "json-pretty", "json-pretty")); | |
5026 | f->open_array_section("crush_classes"); | |
5027 | for (auto i : osdmap.crush->class_name) | |
5028 | f->dump_string("class", i.second); | |
5029 | f->close_section(); | |
5030 | f->flush(rdata); | |
224ce89b WB |
5031 | } else if (prefix == "osd crush class ls-osd") { |
5032 | string name; | |
5033 | cmd_getval(g_ceph_context, cmdmap, "class", name); | |
5034 | boost::scoped_ptr<Formatter> f(Formatter::create(format, "json-pretty", "json-pretty")); | |
5035 | set<int> osds; | |
5036 | osdmap.crush->get_devices_by_class(name, &osds); | |
5037 | f->open_array_section("osds"); | |
5038 | for (auto& osd : osds) | |
5039 | f->dump_int("osd", osd); | |
5040 | f->close_section(); | |
5041 | f->flush(rdata); | |
7c673cae FG |
5042 | } else if (prefix == "osd erasure-code-profile ls") { |
5043 | const auto &profiles = osdmap.get_erasure_code_profiles(); | |
5044 | if (f) | |
5045 | f->open_array_section("erasure-code-profiles"); | |
5046 | for (auto i = profiles.begin(); i != profiles.end(); ++i) { | |
5047 | if (f) | |
5048 | f->dump_string("profile", i->first.c_str()); | |
5049 | else | |
5050 | rdata.append(i->first + "\n"); | |
5051 | } | |
5052 | if (f) { | |
5053 | f->close_section(); | |
5054 | ostringstream rs; | |
5055 | f->flush(rs); | |
5056 | rs << "\n"; | |
5057 | rdata.append(rs.str()); | |
5058 | } | |
c07f9fc5 FG |
5059 | } else if (prefix == "osd crush weight-set ls") { |
5060 | boost::scoped_ptr<Formatter> f(Formatter::create(format)); | |
5061 | if (f) { | |
5062 | f->open_array_section("weight_sets"); | |
5063 | if (osdmap.crush->have_choose_args(CrushWrapper::DEFAULT_CHOOSE_ARGS)) { | |
5064 | f->dump_string("pool", "(compat)"); | |
5065 | } | |
5066 | for (auto& i : osdmap.crush->choose_args) { | |
5067 | if (i.first >= 0) { | |
5068 | f->dump_string("pool", osdmap.get_pool_name(i.first)); | |
5069 | } | |
5070 | } | |
5071 | f->close_section(); | |
5072 | f->flush(rdata); | |
5073 | } else { | |
5074 | ostringstream rs; | |
5075 | if (osdmap.crush->have_choose_args(CrushWrapper::DEFAULT_CHOOSE_ARGS)) { | |
5076 | rs << "(compat)\n"; | |
5077 | } | |
5078 | for (auto& i : osdmap.crush->choose_args) { | |
5079 | if (i.first >= 0) { | |
5080 | rs << osdmap.get_pool_name(i.first) << "\n"; | |
5081 | } | |
5082 | } | |
5083 | rdata.append(rs.str()); | |
5084 | } | |
5085 | } else if (prefix == "osd crush weight-set dump") { | |
5086 | boost::scoped_ptr<Formatter> f(Formatter::create(format, "json-pretty", | |
5087 | "json-pretty")); | |
5088 | osdmap.crush->dump_choose_args(f.get()); | |
5089 | f->flush(rdata); | |
7c673cae FG |
5090 | } else if (prefix == "osd erasure-code-profile get") { |
5091 | string name; | |
5092 | cmd_getval(g_ceph_context, cmdmap, "name", name); | |
5093 | if (!osdmap.has_erasure_code_profile(name)) { | |
5094 | ss << "unknown erasure code profile '" << name << "'"; | |
5095 | r = -ENOENT; | |
5096 | goto reply; | |
5097 | } | |
5098 | const map<string,string> &profile = osdmap.get_erasure_code_profile(name); | |
5099 | if (f) | |
5100 | f->open_object_section("profile"); | |
5101 | for (map<string,string>::const_iterator i = profile.begin(); | |
5102 | i != profile.end(); | |
5103 | ++i) { | |
5104 | if (f) | |
5105 | f->dump_string(i->first.c_str(), i->second.c_str()); | |
5106 | else | |
5107 | rdata.append(i->first + "=" + i->second + "\n"); | |
5108 | } | |
5109 | if (f) { | |
5110 | f->close_section(); | |
5111 | ostringstream rs; | |
5112 | f->flush(rs); | |
5113 | rs << "\n"; | |
5114 | rdata.append(rs.str()); | |
5115 | } | |
5116 | } else { | |
5117 | // try prepare update | |
5118 | return false; | |
5119 | } | |
5120 | ||
5121 | reply: | |
5122 | string rs; | |
5123 | getline(ss, rs); | |
5124 | mon->reply_command(op, r, rs, rdata, get_last_committed()); | |
5125 | return true; | |
5126 | } | |
5127 | ||
5128 | void OSDMonitor::update_pool_flags(int64_t pool_id, uint64_t flags) | |
5129 | { | |
5130 | const pg_pool_t *pool = osdmap.get_pg_pool(pool_id); | |
5131 | pending_inc.get_new_pool(pool_id, pool)->flags = flags; | |
5132 | } | |
5133 | ||
5134 | bool OSDMonitor::update_pools_status() | |
5135 | { | |
31f18b77 | 5136 | if (!mon->pgservice->is_readable()) |
7c673cae FG |
5137 | return false; |
5138 | ||
5139 | bool ret = false; | |
5140 | ||
5141 | auto& pools = osdmap.get_pools(); | |
5142 | for (auto it = pools.begin(); it != pools.end(); ++it) { | |
31f18b77 FG |
5143 | const pool_stat_t *pstat = mon->pgservice->get_pool_stat(it->first); |
5144 | if (!pstat) | |
7c673cae | 5145 | continue; |
31f18b77 | 5146 | const object_stat_sum_t& sum = pstat->stats.sum; |
7c673cae FG |
5147 | const pg_pool_t &pool = it->second; |
5148 | const string& pool_name = osdmap.get_pool_name(it->first); | |
5149 | ||
5150 | bool pool_is_full = | |
5151 | (pool.quota_max_bytes > 0 && (uint64_t)sum.num_bytes >= pool.quota_max_bytes) || | |
5152 | (pool.quota_max_objects > 0 && (uint64_t)sum.num_objects >= pool.quota_max_objects); | |
5153 | ||
5154 | if (pool.has_flag(pg_pool_t::FLAG_FULL)) { | |
5155 | if (pool_is_full) | |
5156 | continue; | |
5157 | ||
5158 | mon->clog->info() << "pool '" << pool_name | |
5159 | << "' no longer full; removing FULL flag"; | |
5160 | ||
5161 | update_pool_flags(it->first, pool.get_flags() & ~pg_pool_t::FLAG_FULL); | |
5162 | ret = true; | |
5163 | } else { | |
5164 | if (!pool_is_full) | |
5165 | continue; | |
5166 | ||
5167 | if (pool.quota_max_bytes > 0 && | |
5168 | (uint64_t)sum.num_bytes >= pool.quota_max_bytes) { | |
5169 | mon->clog->warn() << "pool '" << pool_name << "' is full" | |
5170 | << " (reached quota's max_bytes: " | |
5171 | << si_t(pool.quota_max_bytes) << ")"; | |
5172 | } | |
5173 | if (pool.quota_max_objects > 0 && | |
5174 | (uint64_t)sum.num_objects >= pool.quota_max_objects) { | |
5175 | mon->clog->warn() << "pool '" << pool_name << "' is full" | |
5176 | << " (reached quota's max_objects: " | |
5177 | << pool.quota_max_objects << ")"; | |
5178 | } | |
5179 | update_pool_flags(it->first, pool.get_flags() | pg_pool_t::FLAG_FULL); | |
5180 | ret = true; | |
5181 | } | |
5182 | } | |
5183 | return ret; | |
5184 | } | |
5185 | ||
7c673cae FG |
5186 | int OSDMonitor::prepare_new_pool(MonOpRequestRef op) |
5187 | { | |
5188 | op->mark_osdmon_event(__func__); | |
5189 | MPoolOp *m = static_cast<MPoolOp*>(op->get_req()); | |
5190 | dout(10) << "prepare_new_pool from " << m->get_connection() << dendl; | |
5191 | MonSession *session = m->get_session(); | |
5192 | if (!session) | |
5193 | return -EPERM; | |
5194 | string erasure_code_profile; | |
5195 | stringstream ss; | |
31f18b77 | 5196 | string rule_name; |
7c673cae | 5197 | if (m->auid) |
31f18b77 | 5198 | return prepare_new_pool(m->name, m->auid, m->crush_rule, rule_name, |
7c673cae FG |
5199 | 0, 0, |
5200 | erasure_code_profile, | |
5201 | pg_pool_t::TYPE_REPLICATED, 0, FAST_READ_OFF, &ss); | |
5202 | else | |
31f18b77 | 5203 | return prepare_new_pool(m->name, session->auid, m->crush_rule, rule_name, |
7c673cae FG |
5204 | 0, 0, |
5205 | erasure_code_profile, | |
5206 | pg_pool_t::TYPE_REPLICATED, 0, FAST_READ_OFF, &ss); | |
5207 | } | |
5208 | ||
5209 | int OSDMonitor::crush_rename_bucket(const string& srcname, | |
5210 | const string& dstname, | |
5211 | ostream *ss) | |
5212 | { | |
5213 | int ret; | |
5214 | // | |
5215 | // Avoid creating a pending crush if it does not already exists and | |
5216 | // the rename would fail. | |
5217 | // | |
5218 | if (!_have_pending_crush()) { | |
5219 | ret = _get_stable_crush().can_rename_bucket(srcname, | |
5220 | dstname, | |
5221 | ss); | |
5222 | if (ret) | |
5223 | return ret; | |
5224 | } | |
5225 | ||
5226 | CrushWrapper newcrush; | |
5227 | _get_pending_crush(newcrush); | |
5228 | ||
5229 | ret = newcrush.rename_bucket(srcname, | |
5230 | dstname, | |
5231 | ss); | |
5232 | if (ret) | |
5233 | return ret; | |
5234 | ||
5235 | pending_inc.crush.clear(); | |
5236 | newcrush.encode(pending_inc.crush, mon->get_quorum_con_features()); | |
5237 | *ss << "renamed bucket " << srcname << " into " << dstname; | |
5238 | return 0; | |
5239 | } | |
5240 | ||
5241 | void OSDMonitor::check_legacy_ec_plugin(const string& plugin, const string& profile) const | |
5242 | { | |
5243 | string replacement = ""; | |
5244 | ||
5245 | if (plugin == "jerasure_generic" || | |
5246 | plugin == "jerasure_sse3" || | |
5247 | plugin == "jerasure_sse4" || | |
5248 | plugin == "jerasure_neon") { | |
5249 | replacement = "jerasure"; | |
5250 | } else if (plugin == "shec_generic" || | |
5251 | plugin == "shec_sse3" || | |
5252 | plugin == "shec_sse4" || | |
5253 | plugin == "shec_neon") { | |
5254 | replacement = "shec"; | |
5255 | } | |
5256 | ||
5257 | if (replacement != "") { | |
5258 | dout(0) << "WARNING: erasure coding profile " << profile << " uses plugin " | |
5259 | << plugin << " that has been deprecated. Please use " | |
5260 | << replacement << " instead." << dendl; | |
5261 | } | |
5262 | } | |
5263 | ||
5264 | int OSDMonitor::normalize_profile(const string& profilename, | |
5265 | ErasureCodeProfile &profile, | |
5266 | bool force, | |
5267 | ostream *ss) | |
5268 | { | |
5269 | ErasureCodeInterfaceRef erasure_code; | |
5270 | ErasureCodePluginRegistry &instance = ErasureCodePluginRegistry::instance(); | |
5271 | ErasureCodeProfile::const_iterator plugin = profile.find("plugin"); | |
5272 | check_legacy_ec_plugin(plugin->second, profilename); | |
5273 | int err = instance.factory(plugin->second, | |
5274 | g_conf->get_val<std::string>("erasure_code_dir"), | |
5275 | profile, &erasure_code, ss); | |
5276 | if (err) { | |
5277 | return err; | |
5278 | } | |
5279 | ||
5280 | err = erasure_code->init(profile, ss); | |
5281 | if (err) { | |
5282 | return err; | |
5283 | } | |
5284 | ||
5285 | auto it = profile.find("stripe_unit"); | |
5286 | if (it != profile.end()) { | |
5287 | string err_str; | |
5288 | uint32_t stripe_unit = strict_si_cast<uint32_t>(it->second.c_str(), &err_str); | |
5289 | if (!err_str.empty()) { | |
5290 | *ss << "could not parse stripe_unit '" << it->second | |
5291 | << "': " << err_str << std::endl; | |
5292 | return -EINVAL; | |
5293 | } | |
5294 | uint32_t data_chunks = erasure_code->get_data_chunk_count(); | |
5295 | uint32_t chunk_size = erasure_code->get_chunk_size(stripe_unit * data_chunks); | |
5296 | if (chunk_size != stripe_unit) { | |
5297 | *ss << "stripe_unit " << stripe_unit << " does not match ec profile " | |
5298 | << "alignment. Would be padded to " << chunk_size | |
5299 | << std::endl; | |
5300 | return -EINVAL; | |
5301 | } | |
5302 | if ((stripe_unit % 4096) != 0 && !force) { | |
5303 | *ss << "stripe_unit should be a multiple of 4096 bytes for best performance." | |
5304 | << "use --force to override this check" << std::endl; | |
5305 | return -EINVAL; | |
5306 | } | |
5307 | } | |
5308 | return 0; | |
5309 | } | |
5310 | ||
31f18b77 | 5311 | int OSDMonitor::crush_rule_create_erasure(const string &name, |
7c673cae | 5312 | const string &profile, |
31f18b77 | 5313 | int *rule, |
7c673cae FG |
5314 | ostream *ss) |
5315 | { | |
5316 | int ruleid = osdmap.crush->get_rule_id(name); | |
5317 | if (ruleid != -ENOENT) { | |
31f18b77 | 5318 | *rule = osdmap.crush->get_rule_mask_ruleset(ruleid); |
7c673cae FG |
5319 | return -EEXIST; |
5320 | } | |
5321 | ||
5322 | CrushWrapper newcrush; | |
5323 | _get_pending_crush(newcrush); | |
5324 | ||
5325 | ruleid = newcrush.get_rule_id(name); | |
5326 | if (ruleid != -ENOENT) { | |
31f18b77 | 5327 | *rule = newcrush.get_rule_mask_ruleset(ruleid); |
7c673cae FG |
5328 | return -EALREADY; |
5329 | } else { | |
5330 | ErasureCodeInterfaceRef erasure_code; | |
5331 | int err = get_erasure_code(profile, &erasure_code, ss); | |
5332 | if (err) { | |
5333 | *ss << "failed to load plugin using profile " << profile << std::endl; | |
5334 | return err; | |
5335 | } | |
5336 | ||
224ce89b | 5337 | err = erasure_code->create_rule(name, newcrush, ss); |
7c673cae FG |
5338 | erasure_code.reset(); |
5339 | if (err < 0) | |
5340 | return err; | |
31f18b77 | 5341 | *rule = err; |
7c673cae FG |
5342 | pending_inc.crush.clear(); |
5343 | newcrush.encode(pending_inc.crush, mon->get_quorum_con_features()); | |
5344 | return 0; | |
5345 | } | |
5346 | } | |
5347 | ||
5348 | int OSDMonitor::get_erasure_code(const string &erasure_code_profile, | |
5349 | ErasureCodeInterfaceRef *erasure_code, | |
5350 | ostream *ss) const | |
5351 | { | |
5352 | if (pending_inc.has_erasure_code_profile(erasure_code_profile)) | |
5353 | return -EAGAIN; | |
5354 | ErasureCodeProfile profile = | |
5355 | osdmap.get_erasure_code_profile(erasure_code_profile); | |
5356 | ErasureCodeProfile::const_iterator plugin = | |
5357 | profile.find("plugin"); | |
5358 | if (plugin == profile.end()) { | |
5359 | *ss << "cannot determine the erasure code plugin" | |
5360 | << " because there is no 'plugin' entry in the erasure_code_profile " | |
5361 | << profile << std::endl; | |
5362 | return -EINVAL; | |
5363 | } | |
5364 | check_legacy_ec_plugin(plugin->second, erasure_code_profile); | |
5365 | ErasureCodePluginRegistry &instance = ErasureCodePluginRegistry::instance(); | |
5366 | return instance.factory(plugin->second, | |
5367 | g_conf->get_val<std::string>("erasure_code_dir"), | |
5368 | profile, erasure_code, ss); | |
5369 | } | |
5370 | ||
5371 | int OSDMonitor::check_cluster_features(uint64_t features, | |
5372 | stringstream &ss) | |
5373 | { | |
5374 | stringstream unsupported_ss; | |
5375 | int unsupported_count = 0; | |
5376 | if ((mon->get_quorum_con_features() & features) != features) { | |
5377 | unsupported_ss << "the monitor cluster"; | |
5378 | ++unsupported_count; | |
5379 | } | |
5380 | ||
5381 | set<int32_t> up_osds; | |
5382 | osdmap.get_up_osds(up_osds); | |
5383 | for (set<int32_t>::iterator it = up_osds.begin(); | |
5384 | it != up_osds.end(); ++it) { | |
5385 | const osd_xinfo_t &xi = osdmap.get_xinfo(*it); | |
5386 | if ((xi.features & features) != features) { | |
5387 | if (unsupported_count > 0) | |
5388 | unsupported_ss << ", "; | |
5389 | unsupported_ss << "osd." << *it; | |
5390 | unsupported_count ++; | |
5391 | } | |
5392 | } | |
5393 | ||
5394 | if (unsupported_count > 0) { | |
5395 | ss << "features " << features << " unsupported by: " | |
5396 | << unsupported_ss.str(); | |
5397 | return -ENOTSUP; | |
5398 | } | |
5399 | ||
5400 | // check pending osd state, too! | |
5401 | for (map<int32_t,osd_xinfo_t>::const_iterator p = | |
5402 | pending_inc.new_xinfo.begin(); | |
5403 | p != pending_inc.new_xinfo.end(); ++p) { | |
5404 | const osd_xinfo_t &xi = p->second; | |
5405 | if ((xi.features & features) != features) { | |
5406 | dout(10) << __func__ << " pending osd." << p->first | |
5407 | << " features are insufficient; retry" << dendl; | |
5408 | return -EAGAIN; | |
5409 | } | |
5410 | } | |
5411 | ||
5412 | return 0; | |
5413 | } | |
5414 | ||
5415 | bool OSDMonitor::validate_crush_against_features(const CrushWrapper *newcrush, | |
5416 | stringstream& ss) | |
5417 | { | |
5418 | OSDMap::Incremental new_pending = pending_inc; | |
5419 | ::encode(*newcrush, new_pending.crush, mon->get_quorum_con_features()); | |
5420 | OSDMap newmap; | |
5421 | newmap.deepish_copy_from(osdmap); | |
5422 | newmap.apply_incremental(new_pending); | |
5423 | ||
5424 | // client compat | |
31f18b77 | 5425 | if (newmap.require_min_compat_client > 0) { |
7c673cae | 5426 | auto mv = newmap.get_min_compat_client(); |
31f18b77 FG |
5427 | if (mv > newmap.require_min_compat_client) { |
5428 | ss << "new crush map requires client version " << ceph_release_name(mv) | |
7c673cae | 5429 | << " but require_min_compat_client is " |
31f18b77 | 5430 | << ceph_release_name(newmap.require_min_compat_client); |
7c673cae FG |
5431 | return false; |
5432 | } | |
5433 | } | |
5434 | ||
5435 | // osd compat | |
5436 | uint64_t features = | |
5437 | newmap.get_features(CEPH_ENTITY_TYPE_MON, NULL) | | |
5438 | newmap.get_features(CEPH_ENTITY_TYPE_OSD, NULL); | |
5439 | stringstream features_ss; | |
5440 | int r = check_cluster_features(features, features_ss); | |
5441 | if (r) { | |
5442 | ss << "Could not change CRUSH: " << features_ss.str(); | |
5443 | return false; | |
5444 | } | |
5445 | ||
5446 | return true; | |
5447 | } | |
5448 | ||
5449 | bool OSDMonitor::erasure_code_profile_in_use( | |
5450 | const mempool::osdmap::map<int64_t, pg_pool_t> &pools, | |
5451 | const string &profile, | |
5452 | ostream *ss) | |
5453 | { | |
5454 | bool found = false; | |
5455 | for (map<int64_t, pg_pool_t>::const_iterator p = pools.begin(); | |
5456 | p != pools.end(); | |
5457 | ++p) { | |
5458 | if (p->second.erasure_code_profile == profile) { | |
5459 | *ss << osdmap.pool_name[p->first] << " "; | |
5460 | found = true; | |
5461 | } | |
5462 | } | |
5463 | if (found) { | |
5464 | *ss << "pool(s) are using the erasure code profile '" << profile << "'"; | |
5465 | } | |
5466 | return found; | |
5467 | } | |
5468 | ||
5469 | int OSDMonitor::parse_erasure_code_profile(const vector<string> &erasure_code_profile, | |
5470 | map<string,string> *erasure_code_profile_map, | |
5471 | ostream *ss) | |
5472 | { | |
5473 | int r = get_json_str_map(g_conf->osd_pool_default_erasure_code_profile, | |
5474 | *ss, | |
5475 | erasure_code_profile_map); | |
5476 | if (r) | |
5477 | return r; | |
5478 | assert((*erasure_code_profile_map).count("plugin")); | |
5479 | string default_plugin = (*erasure_code_profile_map)["plugin"]; | |
5480 | map<string,string> user_map; | |
5481 | for (vector<string>::const_iterator i = erasure_code_profile.begin(); | |
5482 | i != erasure_code_profile.end(); | |
5483 | ++i) { | |
5484 | size_t equal = i->find('='); | |
5485 | if (equal == string::npos) { | |
5486 | user_map[*i] = string(); | |
5487 | (*erasure_code_profile_map)[*i] = string(); | |
5488 | } else { | |
5489 | const string key = i->substr(0, equal); | |
5490 | equal++; | |
5491 | const string value = i->substr(equal); | |
5492 | user_map[key] = value; | |
5493 | (*erasure_code_profile_map)[key] = value; | |
5494 | } | |
5495 | } | |
5496 | ||
5497 | if (user_map.count("plugin") && user_map["plugin"] != default_plugin) | |
5498 | (*erasure_code_profile_map) = user_map; | |
5499 | ||
5500 | return 0; | |
5501 | } | |
5502 | ||
5503 | int OSDMonitor::prepare_pool_size(const unsigned pool_type, | |
5504 | const string &erasure_code_profile, | |
5505 | unsigned *size, unsigned *min_size, | |
5506 | ostream *ss) | |
5507 | { | |
5508 | int err = 0; | |
5509 | switch (pool_type) { | |
5510 | case pg_pool_t::TYPE_REPLICATED: | |
5511 | *size = g_conf->osd_pool_default_size; | |
5512 | *min_size = g_conf->get_osd_pool_default_min_size(); | |
5513 | break; | |
5514 | case pg_pool_t::TYPE_ERASURE: | |
5515 | { | |
5516 | ErasureCodeInterfaceRef erasure_code; | |
5517 | err = get_erasure_code(erasure_code_profile, &erasure_code, ss); | |
5518 | if (err == 0) { | |
5519 | *size = erasure_code->get_chunk_count(); | |
5520 | *min_size = MIN(erasure_code->get_data_chunk_count() + 1, *size); | |
5521 | } | |
5522 | } | |
5523 | break; | |
5524 | default: | |
5525 | *ss << "prepare_pool_size: " << pool_type << " is not a known pool type"; | |
5526 | err = -EINVAL; | |
5527 | break; | |
5528 | } | |
5529 | return err; | |
5530 | } | |
5531 | ||
5532 | int OSDMonitor::prepare_pool_stripe_width(const unsigned pool_type, | |
5533 | const string &erasure_code_profile, | |
5534 | uint32_t *stripe_width, | |
5535 | ostream *ss) | |
5536 | { | |
5537 | int err = 0; | |
5538 | switch (pool_type) { | |
5539 | case pg_pool_t::TYPE_REPLICATED: | |
5540 | // ignored | |
5541 | break; | |
5542 | case pg_pool_t::TYPE_ERASURE: | |
5543 | { | |
5544 | ErasureCodeProfile profile = | |
5545 | osdmap.get_erasure_code_profile(erasure_code_profile); | |
5546 | ErasureCodeInterfaceRef erasure_code; | |
5547 | err = get_erasure_code(erasure_code_profile, &erasure_code, ss); | |
5548 | if (err) | |
5549 | break; | |
5550 | uint32_t data_chunks = erasure_code->get_data_chunk_count(); | |
5551 | uint32_t stripe_unit = g_conf->osd_pool_erasure_code_stripe_unit; | |
5552 | auto it = profile.find("stripe_unit"); | |
5553 | if (it != profile.end()) { | |
5554 | string err_str; | |
5555 | stripe_unit = strict_si_cast<uint32_t>(it->second.c_str(), &err_str); | |
5556 | assert(err_str.empty()); | |
5557 | } | |
5558 | *stripe_width = data_chunks * | |
5559 | erasure_code->get_chunk_size(stripe_unit * data_chunks); | |
5560 | } | |
5561 | break; | |
5562 | default: | |
5563 | *ss << "prepare_pool_stripe_width: " | |
5564 | << pool_type << " is not a known pool type"; | |
5565 | err = -EINVAL; | |
5566 | break; | |
5567 | } | |
5568 | return err; | |
5569 | } | |
5570 | ||
31f18b77 | 5571 | int OSDMonitor::prepare_pool_crush_rule(const unsigned pool_type, |
224ce89b WB |
5572 | const string &erasure_code_profile, |
5573 | const string &rule_name, | |
5574 | int *crush_rule, | |
5575 | ostream *ss) | |
7c673cae FG |
5576 | { |
5577 | ||
31f18b77 | 5578 | if (*crush_rule < 0) { |
7c673cae FG |
5579 | switch (pool_type) { |
5580 | case pg_pool_t::TYPE_REPLICATED: | |
5581 | { | |
31f18b77 | 5582 | if (rule_name == "") { |
224ce89b | 5583 | // Use default rule |
31f18b77 FG |
5584 | *crush_rule = osdmap.crush->get_osd_pool_default_crush_replicated_ruleset(g_ceph_context); |
5585 | if (*crush_rule < 0) { | |
5586 | // Errors may happen e.g. if no valid rule is available | |
5587 | *ss << "No suitable CRUSH rule exists, check " | |
7c673cae FG |
5588 | << "'osd pool default crush *' config options"; |
5589 | return -ENOENT; | |
5590 | } | |
5591 | } else { | |
31f18b77 | 5592 | return get_crush_rule(rule_name, crush_rule, ss); |
7c673cae FG |
5593 | } |
5594 | } | |
5595 | break; | |
5596 | case pg_pool_t::TYPE_ERASURE: | |
5597 | { | |
31f18b77 | 5598 | int err = crush_rule_create_erasure(rule_name, |
7c673cae | 5599 | erasure_code_profile, |
31f18b77 | 5600 | crush_rule, ss); |
7c673cae FG |
5601 | switch (err) { |
5602 | case -EALREADY: | |
31f18b77 FG |
5603 | dout(20) << "prepare_pool_crush_rule: rule " |
5604 | << rule_name << " try again" << dendl; | |
7c673cae FG |
5605 | // fall through |
5606 | case 0: | |
5607 | // need to wait for the crush rule to be proposed before proceeding | |
5608 | err = -EAGAIN; | |
5609 | break; | |
5610 | case -EEXIST: | |
5611 | err = 0; | |
5612 | break; | |
5613 | } | |
5614 | return err; | |
5615 | } | |
5616 | break; | |
5617 | default: | |
31f18b77 | 5618 | *ss << "prepare_pool_crush_rule: " << pool_type |
7c673cae FG |
5619 | << " is not a known pool type"; |
5620 | return -EINVAL; | |
5621 | break; | |
5622 | } | |
5623 | } else { | |
31f18b77 FG |
5624 | if (!osdmap.crush->ruleset_exists(*crush_rule)) { |
5625 | *ss << "CRUSH rule " << *crush_rule << " not found"; | |
7c673cae FG |
5626 | return -ENOENT; |
5627 | } | |
5628 | } | |
5629 | ||
5630 | return 0; | |
5631 | } | |
5632 | ||
31f18b77 | 5633 | int OSDMonitor::get_crush_rule(const string &rule_name, |
224ce89b WB |
5634 | int *crush_rule, |
5635 | ostream *ss) | |
7c673cae FG |
5636 | { |
5637 | int ret; | |
31f18b77 | 5638 | ret = osdmap.crush->get_rule_id(rule_name); |
7c673cae FG |
5639 | if (ret != -ENOENT) { |
5640 | // found it, use it | |
31f18b77 | 5641 | *crush_rule = ret; |
7c673cae FG |
5642 | } else { |
5643 | CrushWrapper newcrush; | |
5644 | _get_pending_crush(newcrush); | |
5645 | ||
31f18b77 | 5646 | ret = newcrush.get_rule_id(rule_name); |
7c673cae FG |
5647 | if (ret != -ENOENT) { |
5648 | // found it, wait for it to be proposed | |
31f18b77 | 5649 | dout(20) << __func__ << ": rule " << rule_name |
7c673cae FG |
5650 | << " try again" << dendl; |
5651 | return -EAGAIN; | |
5652 | } else { | |
224ce89b | 5653 | // Cannot find it , return error |
31f18b77 | 5654 | *ss << "specified rule " << rule_name << " doesn't exist"; |
7c673cae FG |
5655 | return ret; |
5656 | } | |
5657 | } | |
5658 | return 0; | |
5659 | } | |
5660 | ||
5661 | /** | |
5662 | * @param name The name of the new pool | |
5663 | * @param auid The auid of the pool owner. Can be -1 | |
31f18b77 FG |
5664 | * @param crush_rule The crush rule to use. If <0, will use the system default |
5665 | * @param crush_rule_name The crush rule to use, if crush_rulset <0 | |
7c673cae FG |
5666 | * @param pg_num The pg_num to use. If set to 0, will use the system default |
5667 | * @param pgp_num The pgp_num to use. If set to 0, will use the system default | |
5668 | * @param erasure_code_profile The profile name in OSDMap to be used for erasure code | |
5669 | * @param pool_type TYPE_ERASURE, or TYPE_REP | |
5670 | * @param expected_num_objects expected number of objects on the pool | |
5671 | * @param fast_read fast read type. | |
5672 | * @param ss human readable error message, if any. | |
5673 | * | |
5674 | * @return 0 on success, negative errno on failure. | |
5675 | */ | |
5676 | int OSDMonitor::prepare_new_pool(string& name, uint64_t auid, | |
31f18b77 FG |
5677 | int crush_rule, |
5678 | const string &crush_rule_name, | |
7c673cae FG |
5679 | unsigned pg_num, unsigned pgp_num, |
5680 | const string &erasure_code_profile, | |
5681 | const unsigned pool_type, | |
5682 | const uint64_t expected_num_objects, | |
5683 | FastReadType fast_read, | |
5684 | ostream *ss) | |
5685 | { | |
5686 | if (name.length() == 0) | |
5687 | return -EINVAL; | |
5688 | if (pg_num == 0) | |
5689 | pg_num = g_conf->osd_pool_default_pg_num; | |
5690 | if (pgp_num == 0) | |
5691 | pgp_num = g_conf->osd_pool_default_pgp_num; | |
5692 | if (pg_num > (unsigned)g_conf->mon_max_pool_pg_num) { | |
5693 | *ss << "'pg_num' must be greater than 0 and less than or equal to " | |
5694 | << g_conf->mon_max_pool_pg_num | |
5695 | << " (you may adjust 'mon max pool pg num' for higher values)"; | |
5696 | return -ERANGE; | |
5697 | } | |
5698 | if (pgp_num > pg_num) { | |
5699 | *ss << "'pgp_num' must be greater than 0 and lower or equal than 'pg_num'" | |
5700 | << ", which in this case is " << pg_num; | |
5701 | return -ERANGE; | |
5702 | } | |
5703 | if (pool_type == pg_pool_t::TYPE_REPLICATED && fast_read == FAST_READ_ON) { | |
5704 | *ss << "'fast_read' can only apply to erasure coding pool"; | |
5705 | return -EINVAL; | |
5706 | } | |
5707 | int r; | |
31f18b77 FG |
5708 | r = prepare_pool_crush_rule(pool_type, erasure_code_profile, |
5709 | crush_rule_name, &crush_rule, ss); | |
7c673cae | 5710 | if (r) { |
31f18b77 | 5711 | dout(10) << " prepare_pool_crush_rule returns " << r << dendl; |
7c673cae FG |
5712 | return r; |
5713 | } | |
224ce89b WB |
5714 | if (g_conf->mon_osd_crush_smoke_test) { |
5715 | CrushWrapper newcrush; | |
5716 | _get_pending_crush(newcrush); | |
5717 | ostringstream err; | |
5718 | CrushTester tester(newcrush, err); | |
5719 | tester.set_max_x(50); | |
5720 | tester.set_rule(crush_rule); | |
5721 | r = tester.test_with_fork(g_conf->mon_lease); | |
5722 | if (r < 0) { | |
5723 | dout(10) << " tester.test_with_fork returns " << r | |
5724 | << ": " << err.str() << dendl; | |
5725 | *ss << "crush test failed with " << r << ": " << err.str(); | |
5726 | return r; | |
5727 | } | |
7c673cae FG |
5728 | } |
5729 | unsigned size, min_size; | |
5730 | r = prepare_pool_size(pool_type, erasure_code_profile, &size, &min_size, ss); | |
5731 | if (r) { | |
5732 | dout(10) << " prepare_pool_size returns " << r << dendl; | |
5733 | return r; | |
5734 | } | |
5735 | ||
31f18b77 | 5736 | if (!osdmap.crush->check_crush_rule(crush_rule, pool_type, size, *ss)) { |
7c673cae FG |
5737 | return -EINVAL; |
5738 | } | |
5739 | ||
5740 | uint32_t stripe_width = 0; | |
5741 | r = prepare_pool_stripe_width(pool_type, erasure_code_profile, &stripe_width, ss); | |
5742 | if (r) { | |
5743 | dout(10) << " prepare_pool_stripe_width returns " << r << dendl; | |
5744 | return r; | |
5745 | } | |
5746 | ||
5747 | bool fread = false; | |
5748 | if (pool_type == pg_pool_t::TYPE_ERASURE) { | |
5749 | switch (fast_read) { | |
5750 | case FAST_READ_OFF: | |
5751 | fread = false; | |
5752 | break; | |
5753 | case FAST_READ_ON: | |
5754 | fread = true; | |
5755 | break; | |
5756 | case FAST_READ_DEFAULT: | |
5757 | fread = g_conf->mon_osd_pool_ec_fast_read; | |
5758 | break; | |
5759 | default: | |
5760 | *ss << "invalid fast_read setting: " << fast_read; | |
5761 | return -EINVAL; | |
5762 | } | |
5763 | } | |
5764 | ||
5765 | for (map<int64_t,string>::iterator p = pending_inc.new_pool_names.begin(); | |
5766 | p != pending_inc.new_pool_names.end(); | |
5767 | ++p) { | |
5768 | if (p->second == name) | |
5769 | return 0; | |
5770 | } | |
5771 | ||
5772 | if (-1 == pending_inc.new_pool_max) | |
5773 | pending_inc.new_pool_max = osdmap.pool_max; | |
5774 | int64_t pool = ++pending_inc.new_pool_max; | |
5775 | pg_pool_t empty; | |
5776 | pg_pool_t *pi = pending_inc.get_new_pool(pool, &empty); | |
5777 | pi->type = pool_type; | |
5778 | pi->fast_read = fread; | |
5779 | pi->flags = g_conf->osd_pool_default_flags; | |
5780 | if (g_conf->osd_pool_default_flag_hashpspool) | |
5781 | pi->set_flag(pg_pool_t::FLAG_HASHPSPOOL); | |
5782 | if (g_conf->osd_pool_default_flag_nodelete) | |
5783 | pi->set_flag(pg_pool_t::FLAG_NODELETE); | |
5784 | if (g_conf->osd_pool_default_flag_nopgchange) | |
5785 | pi->set_flag(pg_pool_t::FLAG_NOPGCHANGE); | |
5786 | if (g_conf->osd_pool_default_flag_nosizechange) | |
5787 | pi->set_flag(pg_pool_t::FLAG_NOSIZECHANGE); | |
5788 | if (g_conf->osd_pool_use_gmt_hitset && | |
5789 | (osdmap.get_up_osd_features() & CEPH_FEATURE_OSD_HITSET_GMT)) | |
5790 | pi->use_gmt_hitset = true; | |
5791 | else | |
5792 | pi->use_gmt_hitset = false; | |
5793 | ||
5794 | pi->size = size; | |
5795 | pi->min_size = min_size; | |
31f18b77 | 5796 | pi->crush_rule = crush_rule; |
7c673cae FG |
5797 | pi->expected_num_objects = expected_num_objects; |
5798 | pi->object_hash = CEPH_STR_HASH_RJENKINS; | |
5799 | pi->set_pg_num(pg_num); | |
5800 | pi->set_pgp_num(pgp_num); | |
5801 | pi->last_change = pending_inc.epoch; | |
5802 | pi->auid = auid; | |
5803 | pi->erasure_code_profile = erasure_code_profile; | |
5804 | pi->stripe_width = stripe_width; | |
5805 | pi->cache_target_dirty_ratio_micro = | |
5806 | g_conf->osd_pool_default_cache_target_dirty_ratio * 1000000; | |
5807 | pi->cache_target_dirty_high_ratio_micro = | |
5808 | g_conf->osd_pool_default_cache_target_dirty_high_ratio * 1000000; | |
5809 | pi->cache_target_full_ratio_micro = | |
5810 | g_conf->osd_pool_default_cache_target_full_ratio * 1000000; | |
5811 | pi->cache_min_flush_age = g_conf->osd_pool_default_cache_min_flush_age; | |
5812 | pi->cache_min_evict_age = g_conf->osd_pool_default_cache_min_evict_age; | |
5813 | pending_inc.new_pool_names[pool] = name; | |
5814 | return 0; | |
5815 | } | |
5816 | ||
5817 | bool OSDMonitor::prepare_set_flag(MonOpRequestRef op, int flag) | |
5818 | { | |
5819 | op->mark_osdmon_event(__func__); | |
5820 | ostringstream ss; | |
5821 | if (pending_inc.new_flags < 0) | |
5822 | pending_inc.new_flags = osdmap.get_flags(); | |
5823 | pending_inc.new_flags |= flag; | |
5824 | ss << OSDMap::get_flag_string(flag) << " is set"; | |
5825 | wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, 0, ss.str(), | |
5826 | get_last_committed() + 1)); | |
5827 | return true; | |
5828 | } | |
5829 | ||
5830 | bool OSDMonitor::prepare_unset_flag(MonOpRequestRef op, int flag) | |
5831 | { | |
5832 | op->mark_osdmon_event(__func__); | |
5833 | ostringstream ss; | |
5834 | if (pending_inc.new_flags < 0) | |
5835 | pending_inc.new_flags = osdmap.get_flags(); | |
5836 | pending_inc.new_flags &= ~flag; | |
5837 | ss << OSDMap::get_flag_string(flag) << " is unset"; | |
5838 | wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, 0, ss.str(), | |
5839 | get_last_committed() + 1)); | |
5840 | return true; | |
5841 | } | |
5842 | ||
7c673cae FG |
5843 | int OSDMonitor::prepare_command_pool_set(map<string,cmd_vartype> &cmdmap, |
5844 | stringstream& ss) | |
5845 | { | |
5846 | string poolstr; | |
5847 | cmd_getval(g_ceph_context, cmdmap, "pool", poolstr); | |
5848 | int64_t pool = osdmap.lookup_pg_pool_name(poolstr.c_str()); | |
5849 | if (pool < 0) { | |
5850 | ss << "unrecognized pool '" << poolstr << "'"; | |
5851 | return -ENOENT; | |
5852 | } | |
5853 | string var; | |
5854 | cmd_getval(g_ceph_context, cmdmap, "var", var); | |
5855 | ||
5856 | pg_pool_t p = *osdmap.get_pg_pool(pool); | |
5857 | if (pending_inc.new_pools.count(pool)) | |
5858 | p = pending_inc.new_pools[pool]; | |
5859 | ||
5860 | // accept val as a json string in the normal case (current | |
5861 | // generation monitor). parse out int or float values from the | |
5862 | // string as needed. however, if it is not a string, try to pull | |
5863 | // out an int, in case an older monitor with an older json schema is | |
5864 | // forwarding a request. | |
5865 | string val; | |
5866 | string interr, floaterr; | |
5867 | int64_t n = 0; | |
5868 | double f = 0; | |
5869 | int64_t uf = 0; // micro-f | |
5870 | if (!cmd_getval(g_ceph_context, cmdmap, "val", val)) { | |
5871 | // wasn't a string; maybe an older mon forwarded json with an int? | |
5872 | if (!cmd_getval(g_ceph_context, cmdmap, "val", n)) | |
5873 | return -EINVAL; // no value! | |
5874 | } else { | |
5875 | // we got a string. see if it contains an int. | |
5876 | n = strict_strtoll(val.c_str(), 10, &interr); | |
5877 | // or a float | |
5878 | f = strict_strtod(val.c_str(), &floaterr); | |
5879 | uf = llrintl(f * (double)1000000.0); | |
5880 | } | |
5881 | ||
5882 | if (!p.is_tier() && | |
5883 | (var == "hit_set_type" || var == "hit_set_period" || | |
5884 | var == "hit_set_count" || var == "hit_set_fpp" || | |
5885 | var == "target_max_objects" || var == "target_max_bytes" || | |
5886 | var == "cache_target_full_ratio" || var == "cache_target_dirty_ratio" || | |
5887 | var == "cache_target_dirty_high_ratio" || var == "use_gmt_hitset" || | |
5888 | var == "cache_min_flush_age" || var == "cache_min_evict_age" || | |
5889 | var == "hit_set_grade_decay_rate" || var == "hit_set_search_last_n" || | |
5890 | var == "min_read_recency_for_promote" || var == "min_write_recency_for_promote")) { | |
5891 | return -EACCES; | |
5892 | } | |
5893 | ||
5894 | if (var == "size") { | |
5895 | if (p.has_flag(pg_pool_t::FLAG_NOSIZECHANGE)) { | |
5896 | ss << "pool size change is disabled; you must unset nosizechange flag for the pool first"; | |
5897 | return -EPERM; | |
5898 | } | |
5899 | if (p.type == pg_pool_t::TYPE_ERASURE) { | |
5900 | ss << "can not change the size of an erasure-coded pool"; | |
5901 | return -ENOTSUP; | |
5902 | } | |
5903 | if (interr.length()) { | |
5904 | ss << "error parsing integer value '" << val << "': " << interr; | |
5905 | return -EINVAL; | |
5906 | } | |
5907 | if (n <= 0 || n > 10) { | |
5908 | ss << "pool size must be between 1 and 10"; | |
5909 | return -EINVAL; | |
5910 | } | |
5911 | p.size = n; | |
5912 | if (n < p.min_size) | |
5913 | p.min_size = n; | |
5914 | } else if (var == "min_size") { | |
5915 | if (p.has_flag(pg_pool_t::FLAG_NOSIZECHANGE)) { | |
5916 | ss << "pool min size change is disabled; you must unset nosizechange flag for the pool first"; | |
5917 | return -EPERM; | |
5918 | } | |
5919 | if (interr.length()) { | |
5920 | ss << "error parsing integer value '" << val << "': " << interr; | |
5921 | return -EINVAL; | |
5922 | } | |
5923 | ||
5924 | if (p.type != pg_pool_t::TYPE_ERASURE) { | |
5925 | if (n < 1 || n > p.size) { | |
5926 | ss << "pool min_size must be between 1 and " << (int)p.size; | |
5927 | return -EINVAL; | |
5928 | } | |
5929 | } else { | |
5930 | ErasureCodeInterfaceRef erasure_code; | |
5931 | int k; | |
5932 | stringstream tmp; | |
5933 | int err = get_erasure_code(p.erasure_code_profile, &erasure_code, &tmp); | |
5934 | if (err == 0) { | |
5935 | k = erasure_code->get_data_chunk_count(); | |
5936 | } else { | |
5937 | ss << __func__ << " get_erasure_code failed: " << tmp.rdbuf(); | |
5938 | return err; | |
5939 | } | |
5940 | ||
5941 | if (n < k || n > p.size) { | |
5942 | ss << "pool min_size must be between " << k << " and " << (int)p.size; | |
5943 | return -EINVAL; | |
5944 | } | |
5945 | } | |
5946 | p.min_size = n; | |
5947 | } else if (var == "auid") { | |
5948 | if (interr.length()) { | |
5949 | ss << "error parsing integer value '" << val << "': " << interr; | |
5950 | return -EINVAL; | |
5951 | } | |
5952 | p.auid = n; | |
5953 | } else if (var == "crash_replay_interval") { | |
5954 | if (interr.length()) { | |
5955 | ss << "error parsing integer value '" << val << "': " << interr; | |
5956 | return -EINVAL; | |
5957 | } | |
5958 | p.crash_replay_interval = n; | |
5959 | } else if (var == "pg_num") { | |
5960 | if (p.has_flag(pg_pool_t::FLAG_NOPGCHANGE)) { | |
5961 | ss << "pool pg_num change is disabled; you must unset nopgchange flag for the pool first"; | |
5962 | return -EPERM; | |
5963 | } | |
5964 | if (interr.length()) { | |
5965 | ss << "error parsing integer value '" << val << "': " << interr; | |
5966 | return -EINVAL; | |
5967 | } | |
5968 | if (n <= (int)p.get_pg_num()) { | |
5969 | ss << "specified pg_num " << n << " <= current " << p.get_pg_num(); | |
5970 | if (n < (int)p.get_pg_num()) | |
5971 | return -EEXIST; | |
5972 | return 0; | |
5973 | } | |
c07f9fc5 FG |
5974 | if (n > (unsigned)g_conf->mon_max_pool_pg_num) { |
5975 | ss << "'pg_num' must be greater than 0 and less than or equal to " | |
5976 | << g_conf->mon_max_pool_pg_num | |
5977 | << " (you may adjust 'mon max pool pg num' for higher values)"; | |
5978 | return -ERANGE; | |
5979 | } | |
7c673cae FG |
5980 | string force; |
5981 | cmd_getval(g_ceph_context,cmdmap, "force", force); | |
5982 | if (p.cache_mode != pg_pool_t::CACHEMODE_NONE && | |
5983 | force != "--yes-i-really-mean-it") { | |
5984 | ss << "splits in cache pools must be followed by scrubs and leave sufficient free space to avoid overfilling. use --yes-i-really-mean-it to force."; | |
5985 | return -EPERM; | |
5986 | } | |
5987 | int expected_osds = MIN(p.get_pg_num(), osdmap.get_num_osds()); | |
5988 | int64_t new_pgs = n - p.get_pg_num(); | |
5989 | if (new_pgs > g_conf->mon_osd_max_split_count * expected_osds) { | |
5990 | ss << "specified pg_num " << n << " is too large (creating " | |
5991 | << new_pgs << " new PGs on ~" << expected_osds | |
5992 | << " OSDs exceeds per-OSD max of " << g_conf->mon_osd_max_split_count | |
5993 | << ')'; | |
5994 | return -E2BIG; | |
5995 | } | |
5996 | p.set_pg_num(n); | |
5997 | // force pre-luminous clients to resend their ops, since they | |
5998 | // don't understand that split PGs now form a new interval. | |
5999 | p.last_force_op_resend_preluminous = pending_inc.epoch; | |
6000 | } else if (var == "pgp_num") { | |
6001 | if (p.has_flag(pg_pool_t::FLAG_NOPGCHANGE)) { | |
6002 | ss << "pool pgp_num change is disabled; you must unset nopgchange flag for the pool first"; | |
6003 | return -EPERM; | |
6004 | } | |
6005 | if (interr.length()) { | |
6006 | ss << "error parsing integer value '" << val << "': " << interr; | |
6007 | return -EINVAL; | |
6008 | } | |
6009 | if (n <= 0) { | |
6010 | ss << "specified pgp_num must > 0, but you set to " << n; | |
6011 | return -EINVAL; | |
6012 | } | |
6013 | if (n > (int)p.get_pg_num()) { | |
6014 | ss << "specified pgp_num " << n << " > pg_num " << p.get_pg_num(); | |
6015 | return -EINVAL; | |
6016 | } | |
6017 | p.set_pgp_num(n); | |
6018 | } else if (var == "crush_rule") { | |
6019 | int id = osdmap.crush->get_rule_id(val); | |
6020 | if (id == -ENOENT) { | |
6021 | ss << "crush rule " << val << " does not exist"; | |
6022 | return -ENOENT; | |
6023 | } | |
6024 | if (id < 0) { | |
6025 | ss << cpp_strerror(id); | |
6026 | return -ENOENT; | |
6027 | } | |
6028 | if (!osdmap.crush->check_crush_rule(id, p.get_type(), p.get_size(), ss)) { | |
6029 | return -EINVAL; | |
6030 | } | |
31f18b77 | 6031 | p.crush_rule = id; |
7c673cae FG |
6032 | } else if (var == "nodelete" || var == "nopgchange" || |
6033 | var == "nosizechange" || var == "write_fadvise_dontneed" || | |
6034 | var == "noscrub" || var == "nodeep-scrub") { | |
6035 | uint64_t flag = pg_pool_t::get_flag_by_name(var); | |
6036 | // make sure we only compare against 'n' if we didn't receive a string | |
6037 | if (val == "true" || (interr.empty() && n == 1)) { | |
6038 | p.set_flag(flag); | |
6039 | } else if (val == "false" || (interr.empty() && n == 0)) { | |
6040 | p.unset_flag(flag); | |
6041 | } else { | |
6042 | ss << "expecting value 'true', 'false', '0', or '1'"; | |
6043 | return -EINVAL; | |
6044 | } | |
6045 | } else if (var == "hashpspool") { | |
6046 | uint64_t flag = pg_pool_t::get_flag_by_name(var); | |
6047 | string force; | |
6048 | cmd_getval(g_ceph_context, cmdmap, "force", force); | |
6049 | if (force != "--yes-i-really-mean-it") { | |
6050 | ss << "are you SURE? this will remap all placement groups in this pool," | |
6051 | " this triggers large data movement," | |
6052 | " pass --yes-i-really-mean-it if you really do."; | |
6053 | return -EPERM; | |
6054 | } | |
6055 | // make sure we only compare against 'n' if we didn't receive a string | |
6056 | if (val == "true" || (interr.empty() && n == 1)) { | |
6057 | p.set_flag(flag); | |
6058 | } else if (val == "false" || (interr.empty() && n == 0)) { | |
6059 | p.unset_flag(flag); | |
6060 | } else { | |
6061 | ss << "expecting value 'true', 'false', '0', or '1'"; | |
6062 | return -EINVAL; | |
6063 | } | |
6064 | } else if (var == "hit_set_type") { | |
6065 | if (val == "none") | |
6066 | p.hit_set_params = HitSet::Params(); | |
6067 | else { | |
6068 | int err = check_cluster_features(CEPH_FEATURE_OSD_CACHEPOOL, ss); | |
6069 | if (err) | |
6070 | return err; | |
6071 | if (val == "bloom") { | |
6072 | BloomHitSet::Params *bsp = new BloomHitSet::Params; | |
6073 | bsp->set_fpp(g_conf->osd_pool_default_hit_set_bloom_fpp); | |
6074 | p.hit_set_params = HitSet::Params(bsp); | |
6075 | } else if (val == "explicit_hash") | |
6076 | p.hit_set_params = HitSet::Params(new ExplicitHashHitSet::Params); | |
6077 | else if (val == "explicit_object") | |
6078 | p.hit_set_params = HitSet::Params(new ExplicitObjectHitSet::Params); | |
6079 | else { | |
6080 | ss << "unrecognized hit_set type '" << val << "'"; | |
6081 | return -EINVAL; | |
6082 | } | |
6083 | } | |
6084 | } else if (var == "hit_set_period") { | |
6085 | if (interr.length()) { | |
6086 | ss << "error parsing integer value '" << val << "': " << interr; | |
6087 | return -EINVAL; | |
6088 | } | |
6089 | p.hit_set_period = n; | |
6090 | } else if (var == "hit_set_count") { | |
6091 | if (interr.length()) { | |
6092 | ss << "error parsing integer value '" << val << "': " << interr; | |
6093 | return -EINVAL; | |
6094 | } | |
6095 | p.hit_set_count = n; | |
6096 | } else if (var == "hit_set_fpp") { | |
6097 | if (floaterr.length()) { | |
6098 | ss << "error parsing floating point value '" << val << "': " << floaterr; | |
6099 | return -EINVAL; | |
6100 | } | |
6101 | if (p.hit_set_params.get_type() != HitSet::TYPE_BLOOM) { | |
6102 | ss << "hit set is not of type Bloom; invalid to set a false positive rate!"; | |
6103 | return -EINVAL; | |
6104 | } | |
6105 | BloomHitSet::Params *bloomp = static_cast<BloomHitSet::Params*>(p.hit_set_params.impl.get()); | |
6106 | bloomp->set_fpp(f); | |
6107 | } else if (var == "use_gmt_hitset") { | |
6108 | if (val == "true" || (interr.empty() && n == 1)) { | |
6109 | if (!(osdmap.get_up_osd_features() & CEPH_FEATURE_OSD_HITSET_GMT)) { | |
6110 | ss << "not all OSDs support GMT hit set."; | |
6111 | return -EINVAL; | |
6112 | } | |
6113 | p.use_gmt_hitset = true; | |
6114 | } else { | |
6115 | ss << "expecting value 'true' or '1'"; | |
6116 | return -EINVAL; | |
6117 | } | |
6118 | } else if (var == "allow_ec_overwrites") { | |
6119 | if (!p.is_erasure()) { | |
6120 | ss << "ec overwrites can only be enabled for an erasure coded pool"; | |
6121 | return -EINVAL; | |
6122 | } | |
224ce89b WB |
6123 | stringstream err; |
6124 | if (!g_conf->mon_debug_no_require_bluestore_for_ec_overwrites && | |
6125 | !is_pool_currently_all_bluestore(pool, p, &err)) { | |
6126 | ss << "pool must only be stored on bluestore for scrubbing to work: " << err.str(); | |
6127 | return -EINVAL; | |
6128 | } | |
7c673cae FG |
6129 | if (val == "true" || (interr.empty() && n == 1)) { |
6130 | p.flags |= pg_pool_t::FLAG_EC_OVERWRITES; | |
6131 | } else if (val == "false" || (interr.empty() && n == 0)) { | |
6132 | ss << "ec overwrites cannot be disabled once enabled"; | |
6133 | return -EINVAL; | |
6134 | } else { | |
6135 | ss << "expecting value 'true', 'false', '0', or '1'"; | |
6136 | return -EINVAL; | |
6137 | } | |
7c673cae FG |
6138 | } else if (var == "target_max_objects") { |
6139 | if (interr.length()) { | |
6140 | ss << "error parsing int '" << val << "': " << interr; | |
6141 | return -EINVAL; | |
6142 | } | |
6143 | p.target_max_objects = n; | |
6144 | } else if (var == "target_max_bytes") { | |
6145 | if (interr.length()) { | |
6146 | ss << "error parsing int '" << val << "': " << interr; | |
6147 | return -EINVAL; | |
6148 | } | |
6149 | p.target_max_bytes = n; | |
6150 | } else if (var == "cache_target_dirty_ratio") { | |
6151 | if (floaterr.length()) { | |
6152 | ss << "error parsing float '" << val << "': " << floaterr; | |
6153 | return -EINVAL; | |
6154 | } | |
6155 | if (f < 0 || f > 1.0) { | |
6156 | ss << "value must be in the range 0..1"; | |
6157 | return -ERANGE; | |
6158 | } | |
6159 | p.cache_target_dirty_ratio_micro = uf; | |
6160 | } else if (var == "cache_target_dirty_high_ratio") { | |
6161 | if (floaterr.length()) { | |
6162 | ss << "error parsing float '" << val << "': " << floaterr; | |
6163 | return -EINVAL; | |
6164 | } | |
6165 | if (f < 0 || f > 1.0) { | |
6166 | ss << "value must be in the range 0..1"; | |
6167 | return -ERANGE; | |
6168 | } | |
6169 | p.cache_target_dirty_high_ratio_micro = uf; | |
6170 | } else if (var == "cache_target_full_ratio") { | |
6171 | if (floaterr.length()) { | |
6172 | ss << "error parsing float '" << val << "': " << floaterr; | |
6173 | return -EINVAL; | |
6174 | } | |
6175 | if (f < 0 || f > 1.0) { | |
6176 | ss << "value must be in the range 0..1"; | |
6177 | return -ERANGE; | |
6178 | } | |
6179 | p.cache_target_full_ratio_micro = uf; | |
6180 | } else if (var == "cache_min_flush_age") { | |
6181 | if (interr.length()) { | |
6182 | ss << "error parsing int '" << val << "': " << interr; | |
6183 | return -EINVAL; | |
6184 | } | |
6185 | p.cache_min_flush_age = n; | |
6186 | } else if (var == "cache_min_evict_age") { | |
6187 | if (interr.length()) { | |
6188 | ss << "error parsing int '" << val << "': " << interr; | |
6189 | return -EINVAL; | |
6190 | } | |
6191 | p.cache_min_evict_age = n; | |
6192 | } else if (var == "min_read_recency_for_promote") { | |
6193 | if (interr.length()) { | |
6194 | ss << "error parsing integer value '" << val << "': " << interr; | |
6195 | return -EINVAL; | |
6196 | } | |
6197 | p.min_read_recency_for_promote = n; | |
6198 | } else if (var == "hit_set_grade_decay_rate") { | |
6199 | if (interr.length()) { | |
6200 | ss << "error parsing integer value '" << val << "': " << interr; | |
6201 | return -EINVAL; | |
6202 | } | |
6203 | if (n > 100 || n < 0) { | |
6204 | ss << "value out of range,valid range is 0 - 100"; | |
6205 | return -EINVAL; | |
6206 | } | |
6207 | p.hit_set_grade_decay_rate = n; | |
6208 | } else if (var == "hit_set_search_last_n") { | |
6209 | if (interr.length()) { | |
6210 | ss << "error parsing integer value '" << val << "': " << interr; | |
6211 | return -EINVAL; | |
6212 | } | |
6213 | if (n > p.hit_set_count || n < 0) { | |
6214 | ss << "value out of range,valid range is 0 - hit_set_count"; | |
6215 | return -EINVAL; | |
6216 | } | |
6217 | p.hit_set_search_last_n = n; | |
6218 | } else if (var == "min_write_recency_for_promote") { | |
6219 | if (interr.length()) { | |
6220 | ss << "error parsing integer value '" << val << "': " << interr; | |
6221 | return -EINVAL; | |
6222 | } | |
6223 | p.min_write_recency_for_promote = n; | |
6224 | } else if (var == "fast_read") { | |
6225 | if (p.is_replicated()) { | |
6226 | ss << "fast read is not supported in replication pool"; | |
6227 | return -EINVAL; | |
6228 | } | |
6229 | if (val == "true" || (interr.empty() && n == 1)) { | |
6230 | p.fast_read = true; | |
6231 | } else if (val == "false" || (interr.empty() && n == 0)) { | |
6232 | p.fast_read = false; | |
6233 | } else { | |
6234 | ss << "expecting value 'true', 'false', '0', or '1'"; | |
6235 | return -EINVAL; | |
6236 | } | |
6237 | } else if (pool_opts_t::is_opt_name(var)) { | |
224ce89b | 6238 | bool unset = val == "unset"; |
7c673cae | 6239 | if (var == "compression_mode") { |
224ce89b WB |
6240 | if (!unset) { |
6241 | auto cmode = Compressor::get_comp_mode_type(val); | |
6242 | if (!cmode) { | |
6243 | ss << "unrecognized compression mode '" << val << "'"; | |
6244 | return -EINVAL; | |
6245 | } | |
7c673cae FG |
6246 | } |
6247 | } else if (var == "compression_algorithm") { | |
224ce89b WB |
6248 | if (!unset) { |
6249 | auto alg = Compressor::get_comp_alg_type(val); | |
6250 | if (!alg) { | |
6251 | ss << "unrecognized compression_algorithm '" << val << "'"; | |
6252 | return -EINVAL; | |
6253 | } | |
7c673cae FG |
6254 | } |
6255 | } else if (var == "compression_required_ratio") { | |
6256 | if (floaterr.length()) { | |
6257 | ss << "error parsing float value '" << val << "': " << floaterr; | |
6258 | return -EINVAL; | |
6259 | } | |
224ce89b | 6260 | if (f < 0 || f > 1) { |
7c673cae | 6261 | ss << "compression_required_ratio is out of range (0-1): '" << val << "'"; |
224ce89b | 6262 | return -EINVAL; |
7c673cae FG |
6263 | } |
6264 | } else if (var == "csum_type") { | |
224ce89b | 6265 | auto t = unset ? 0 : Checksummer::get_csum_string_type(val); |
7c673cae FG |
6266 | if (t < 0 ) { |
6267 | ss << "unrecognized csum_type '" << val << "'"; | |
224ce89b | 6268 | return -EINVAL; |
7c673cae FG |
6269 | } |
6270 | //preserve csum_type numeric value | |
6271 | n = t; | |
6272 | interr.clear(); | |
6273 | } else if (var == "compression_max_blob_size" || | |
6274 | var == "compression_min_blob_size" || | |
6275 | var == "csum_max_block" || | |
6276 | var == "csum_min_block") { | |
6277 | if (interr.length()) { | |
6278 | ss << "error parsing int value '" << val << "': " << interr; | |
6279 | return -EINVAL; | |
6280 | } | |
6281 | } | |
6282 | ||
6283 | pool_opts_t::opt_desc_t desc = pool_opts_t::get_opt_desc(var); | |
6284 | switch (desc.type) { | |
6285 | case pool_opts_t::STR: | |
224ce89b | 6286 | if (unset) { |
7c673cae FG |
6287 | p.opts.unset(desc.key); |
6288 | } else { | |
6289 | p.opts.set(desc.key, static_cast<std::string>(val)); | |
6290 | } | |
6291 | break; | |
6292 | case pool_opts_t::INT: | |
6293 | if (interr.length()) { | |
6294 | ss << "error parsing integer value '" << val << "': " << interr; | |
6295 | return -EINVAL; | |
6296 | } | |
6297 | if (n == 0) { | |
6298 | p.opts.unset(desc.key); | |
6299 | } else { | |
6300 | p.opts.set(desc.key, static_cast<int>(n)); | |
6301 | } | |
6302 | break; | |
6303 | case pool_opts_t::DOUBLE: | |
6304 | if (floaterr.length()) { | |
6305 | ss << "error parsing floating point value '" << val << "': " << floaterr; | |
6306 | return -EINVAL; | |
6307 | } | |
6308 | if (f == 0) { | |
6309 | p.opts.unset(desc.key); | |
6310 | } else { | |
6311 | p.opts.set(desc.key, static_cast<double>(f)); | |
6312 | } | |
6313 | break; | |
6314 | default: | |
6315 | assert(!"unknown type"); | |
6316 | } | |
6317 | } else { | |
6318 | ss << "unrecognized variable '" << var << "'"; | |
6319 | return -EINVAL; | |
6320 | } | |
224ce89b WB |
6321 | if (val != "unset") { |
6322 | ss << "set pool " << pool << " " << var << " to " << val; | |
6323 | } else { | |
6324 | ss << "unset pool " << pool << " " << var; | |
6325 | } | |
7c673cae FG |
6326 | p.last_change = pending_inc.epoch; |
6327 | pending_inc.new_pools[pool] = p; | |
6328 | return 0; | |
6329 | } | |
6330 | ||
c07f9fc5 FG |
6331 | int OSDMonitor::prepare_command_pool_application(const string &prefix, |
6332 | map<string,cmd_vartype> &cmdmap, | |
6333 | stringstream& ss) | |
6334 | { | |
6335 | string pool_name; | |
6336 | cmd_getval(g_ceph_context, cmdmap, "pool", pool_name); | |
6337 | int64_t pool = osdmap.lookup_pg_pool_name(pool_name.c_str()); | |
6338 | if (pool < 0) { | |
6339 | ss << "unrecognized pool '" << pool_name << "'"; | |
6340 | return -ENOENT; | |
6341 | } | |
6342 | ||
6343 | pg_pool_t p = *osdmap.get_pg_pool(pool); | |
6344 | if (pending_inc.new_pools.count(pool)) { | |
6345 | p = pending_inc.new_pools[pool]; | |
6346 | } | |
6347 | ||
6348 | string app; | |
6349 | cmd_getval(g_ceph_context, cmdmap, "app", app); | |
6350 | bool app_exists = (p.application_metadata.count(app) > 0); | |
6351 | ||
6352 | if (boost::algorithm::ends_with(prefix, "enable")) { | |
6353 | if (app.empty()) { | |
6354 | ss << "application name must be provided"; | |
6355 | return -EINVAL; | |
6356 | } | |
6357 | ||
6358 | if (p.is_tier()) { | |
6359 | ss << "application must be enabled on base tier"; | |
6360 | return -EINVAL; | |
6361 | } | |
6362 | ||
6363 | string force; | |
6364 | cmd_getval(g_ceph_context, cmdmap, "force", force); | |
6365 | ||
6366 | if (!app_exists && !p.application_metadata.empty() && | |
6367 | force != "--yes-i-really-mean-it") { | |
6368 | ss << "Are you SURE? Pool '" << pool_name << "' already has an enabled " | |
6369 | << "application; pass --yes-i-really-mean-it to proceed anyway"; | |
6370 | return -EPERM; | |
6371 | } | |
6372 | ||
6373 | if (!app_exists && p.application_metadata.size() >= MAX_POOL_APPLICATIONS) { | |
6374 | ss << "too many enabled applications on pool '" << pool_name << "'; " | |
6375 | << "max " << MAX_POOL_APPLICATIONS; | |
6376 | return -EINVAL; | |
6377 | } | |
6378 | ||
6379 | if (app.length() > MAX_POOL_APPLICATION_LENGTH) { | |
6380 | ss << "application name '" << app << "' too long; max length " | |
6381 | << MAX_POOL_APPLICATION_LENGTH; | |
6382 | return -EINVAL; | |
6383 | } | |
6384 | ||
6385 | if (!app_exists) { | |
6386 | p.application_metadata[app] = {}; | |
6387 | } | |
6388 | ss << "enabled application '" << app << "' on pool '" << pool_name << "'"; | |
6389 | ||
6390 | } else if (boost::algorithm::ends_with(prefix, "disable")) { | |
6391 | string force; | |
6392 | cmd_getval(g_ceph_context, cmdmap, "force", force); | |
6393 | ||
6394 | if (force != "--yes-i-really-mean-it") { | |
6395 | ss << "Are you SURE? Disabling an application within a pool might result " | |
6396 | << "in loss of application functionality; pass " | |
6397 | << "--yes-i-really-mean-it to proceed anyway"; | |
6398 | return -EPERM; | |
6399 | } | |
6400 | ||
6401 | if (!app_exists) { | |
6402 | ss << "application '" << app << "' is not enabled on pool '" << pool_name | |
6403 | << "'"; | |
6404 | return 0; // idempotent | |
6405 | } | |
6406 | ||
6407 | p.application_metadata.erase(app); | |
6408 | ss << "disable application '" << app << "' on pool '" << pool_name << "'"; | |
6409 | ||
6410 | } else if (boost::algorithm::ends_with(prefix, "set")) { | |
6411 | if (p.is_tier()) { | |
6412 | ss << "application metadata must be set on base tier"; | |
6413 | return -EINVAL; | |
6414 | } | |
6415 | ||
6416 | if (!app_exists) { | |
6417 | ss << "application '" << app << "' is not enabled on pool '" << pool_name | |
6418 | << "'"; | |
6419 | return -ENOENT; | |
6420 | } | |
6421 | ||
6422 | string key; | |
6423 | cmd_getval(g_ceph_context, cmdmap, "key", key); | |
6424 | ||
6425 | if (key.empty()) { | |
6426 | ss << "key must be provided"; | |
6427 | return -EINVAL; | |
6428 | } | |
6429 | ||
6430 | auto &app_keys = p.application_metadata[app]; | |
6431 | if (app_keys.count(key) == 0 && | |
6432 | app_keys.size() >= MAX_POOL_APPLICATION_KEYS) { | |
6433 | ss << "too many keys set for application '" << app << "' on pool '" | |
6434 | << pool_name << "'; max " << MAX_POOL_APPLICATION_KEYS; | |
6435 | return -EINVAL; | |
6436 | } | |
6437 | ||
6438 | if (key.length() > MAX_POOL_APPLICATION_LENGTH) { | |
6439 | ss << "key '" << app << "' too long; max length " | |
6440 | << MAX_POOL_APPLICATION_LENGTH; | |
6441 | return -EINVAL; | |
6442 | } | |
6443 | ||
6444 | string value; | |
6445 | cmd_getval(g_ceph_context, cmdmap, "value", value); | |
6446 | if (value.length() > MAX_POOL_APPLICATION_LENGTH) { | |
6447 | ss << "value '" << value << "' too long; max length " | |
6448 | << MAX_POOL_APPLICATION_LENGTH; | |
6449 | return -EINVAL; | |
6450 | } | |
6451 | ||
6452 | p.application_metadata[app][key] = value; | |
6453 | ss << "set application '" << app << "' key '" << key << "' to '" | |
6454 | << value << "' on pool '" << pool_name << "'"; | |
6455 | } else if (boost::algorithm::ends_with(prefix, "rm")) { | |
6456 | if (!app_exists) { | |
6457 | ss << "application '" << app << "' is not enabled on pool '" << pool_name | |
6458 | << "'"; | |
6459 | return -ENOENT; | |
6460 | } | |
6461 | ||
6462 | string key; | |
6463 | cmd_getval(g_ceph_context, cmdmap, "key", key); | |
6464 | auto it = p.application_metadata[app].find(key); | |
6465 | if (it == p.application_metadata[app].end()) { | |
6466 | ss << "application '" << app << "' on pool '" << pool_name | |
6467 | << "' does not have key '" << key << "'"; | |
6468 | return 0; // idempotent | |
6469 | } | |
6470 | ||
6471 | p.application_metadata[app].erase(it); | |
6472 | ss << "removed application '" << app << "' key '" << key << "' on pool '" | |
6473 | << pool_name << "'"; | |
6474 | } else { | |
6475 | assert(false); | |
6476 | } | |
6477 | ||
6478 | p.last_change = pending_inc.epoch; | |
6479 | pending_inc.new_pools[pool] = p; | |
6480 | return 0; | |
6481 | } | |
6482 | ||
31f18b77 FG |
6483 | int OSDMonitor::_prepare_command_osd_crush_remove( |
6484 | CrushWrapper &newcrush, | |
6485 | int32_t id, | |
6486 | int32_t ancestor, | |
6487 | bool has_ancestor, | |
6488 | bool unlink_only) | |
6489 | { | |
6490 | int err = 0; | |
6491 | ||
6492 | if (has_ancestor) { | |
6493 | err = newcrush.remove_item_under(g_ceph_context, id, ancestor, | |
6494 | unlink_only); | |
6495 | } else { | |
6496 | err = newcrush.remove_item(g_ceph_context, id, unlink_only); | |
6497 | } | |
6498 | return err; | |
6499 | } | |
6500 | ||
6501 | void OSDMonitor::do_osd_crush_remove(CrushWrapper& newcrush) | |
6502 | { | |
6503 | pending_inc.crush.clear(); | |
6504 | newcrush.encode(pending_inc.crush, mon->get_quorum_con_features()); | |
6505 | } | |
6506 | ||
6507 | int OSDMonitor::prepare_command_osd_crush_remove( | |
6508 | CrushWrapper &newcrush, | |
6509 | int32_t id, | |
6510 | int32_t ancestor, | |
6511 | bool has_ancestor, | |
6512 | bool unlink_only) | |
6513 | { | |
6514 | int err = _prepare_command_osd_crush_remove( | |
6515 | newcrush, id, ancestor, | |
6516 | has_ancestor, unlink_only); | |
6517 | ||
6518 | if (err < 0) | |
6519 | return err; | |
6520 | ||
6521 | assert(err == 0); | |
6522 | do_osd_crush_remove(newcrush); | |
6523 | ||
6524 | return 0; | |
6525 | } | |
6526 | ||
6527 | int OSDMonitor::prepare_command_osd_remove(int32_t id) | |
6528 | { | |
6529 | if (osdmap.is_up(id)) { | |
6530 | return -EBUSY; | |
6531 | } | |
6532 | ||
6533 | pending_inc.new_state[id] = osdmap.get_state(id); | |
6534 | pending_inc.new_uuid[id] = uuid_d(); | |
6535 | pending_metadata_rm.insert(id); | |
6536 | pending_metadata.erase(id); | |
6537 | ||
6538 | return 0; | |
6539 | } | |
6540 | ||
6541 | int32_t OSDMonitor::_allocate_osd_id(int32_t* existing_id) | |
6542 | { | |
6543 | assert(existing_id); | |
6544 | *existing_id = -1; | |
6545 | ||
6546 | for (int32_t i = 0; i < osdmap.get_max_osd(); ++i) { | |
6547 | if (!osdmap.exists(i) && | |
6548 | pending_inc.new_up_client.count(i) == 0 && | |
6549 | (pending_inc.new_state.count(i) == 0 || | |
6550 | (pending_inc.new_state[i] & CEPH_OSD_EXISTS) == 0)) { | |
6551 | *existing_id = i; | |
6552 | return -1; | |
6553 | } | |
6554 | } | |
6555 | ||
6556 | if (pending_inc.new_max_osd < 0) { | |
6557 | return osdmap.get_max_osd(); | |
6558 | } | |
6559 | return pending_inc.new_max_osd; | |
6560 | } | |
6561 | ||
6562 | void OSDMonitor::do_osd_create( | |
6563 | const int32_t id, | |
6564 | const uuid_d& uuid, | |
6565 | int32_t* new_id) | |
6566 | { | |
6567 | dout(10) << __func__ << " uuid " << uuid << dendl; | |
6568 | assert(new_id); | |
6569 | ||
6570 | // We presume validation has been performed prior to calling this | |
6571 | // function. We assert with prejudice. | |
6572 | ||
6573 | int32_t allocated_id = -1; // declare here so we can jump | |
6574 | int32_t existing_id = -1; | |
6575 | if (!uuid.is_zero()) { | |
6576 | existing_id = osdmap.identify_osd(uuid); | |
6577 | if (existing_id >= 0) { | |
6578 | assert(id < 0 || id == existing_id); | |
6579 | *new_id = existing_id; | |
6580 | goto out; | |
6581 | } else if (id >= 0) { | |
6582 | // uuid does not exist, and id has been provided, so just create | |
6583 | // the new osd.id | |
6584 | *new_id = id; | |
6585 | goto out; | |
6586 | } | |
6587 | } | |
6588 | ||
6589 | // allocate a new id | |
6590 | allocated_id = _allocate_osd_id(&existing_id); | |
6591 | dout(10) << __func__ << " allocated id " << allocated_id | |
6592 | << " existing id " << existing_id << dendl; | |
6593 | if (existing_id >= 0) { | |
6594 | assert(existing_id < osdmap.get_max_osd()); | |
6595 | assert(allocated_id < 0); | |
6596 | pending_inc.new_weight[existing_id] = CEPH_OSD_OUT; | |
6597 | *new_id = existing_id; | |
6598 | ||
6599 | } else if (allocated_id >= 0) { | |
6600 | assert(existing_id < 0); | |
6601 | // raise max_osd | |
6602 | if (pending_inc.new_max_osd < 0) { | |
6603 | pending_inc.new_max_osd = osdmap.get_max_osd() + 1; | |
6604 | } else { | |
6605 | ++pending_inc.new_max_osd; | |
6606 | } | |
6607 | *new_id = pending_inc.new_max_osd - 1; | |
6608 | assert(*new_id == allocated_id); | |
6609 | } else { | |
6610 | assert(0 == "unexpected condition"); | |
6611 | } | |
6612 | ||
6613 | out: | |
6614 | dout(10) << __func__ << " using id " << *new_id << dendl; | |
6615 | if (osdmap.get_max_osd() <= *new_id && pending_inc.new_max_osd <= *new_id) { | |
6616 | pending_inc.new_max_osd = *new_id + 1; | |
6617 | } | |
6618 | ||
6619 | pending_inc.new_state[*new_id] |= CEPH_OSD_EXISTS | CEPH_OSD_NEW; | |
6620 | if (!uuid.is_zero()) | |
6621 | pending_inc.new_uuid[*new_id] = uuid; | |
6622 | } | |
6623 | ||
6624 | int OSDMonitor::validate_osd_create( | |
6625 | const int32_t id, | |
6626 | const uuid_d& uuid, | |
6627 | const bool check_osd_exists, | |
6628 | int32_t* existing_id, | |
6629 | stringstream& ss) | |
6630 | { | |
6631 | ||
6632 | dout(10) << __func__ << " id " << id << " uuid " << uuid | |
6633 | << " check_osd_exists " << check_osd_exists << dendl; | |
6634 | ||
6635 | assert(existing_id); | |
6636 | ||
6637 | if (id < 0 && uuid.is_zero()) { | |
6638 | // we have nothing to validate | |
6639 | *existing_id = -1; | |
6640 | return 0; | |
6641 | } else if (uuid.is_zero()) { | |
6642 | // we have an id but we will ignore it - because that's what | |
6643 | // `osd create` does. | |
6644 | return 0; | |
6645 | } | |
6646 | ||
6647 | /* | |
6648 | * This function will be used to validate whether we are able to | |
6649 | * create a new osd when the `uuid` is specified. | |
6650 | * | |
6651 | * It will be used by both `osd create` and `osd new`, as the checks | |
6652 | * are basically the same when it pertains to osd id and uuid validation. | |
6653 | * However, `osd create` presumes an `uuid` is optional, for legacy | |
6654 | * reasons, while `osd new` requires the `uuid` to be provided. This | |
6655 | * means that `osd create` will not be idempotent if an `uuid` is not | |
6656 | * provided, but we will always guarantee the idempotency of `osd new`. | |
6657 | */ | |
6658 | ||
6659 | assert(!uuid.is_zero()); | |
6660 | if (pending_inc.identify_osd(uuid) >= 0) { | |
6661 | // osd is about to exist | |
6662 | return -EAGAIN; | |
6663 | } | |
6664 | ||
6665 | int32_t i = osdmap.identify_osd(uuid); | |
6666 | if (i >= 0) { | |
6667 | // osd already exists | |
6668 | if (id >= 0 && i != id) { | |
6669 | ss << "uuid " << uuid << " already in use for different id " << i; | |
6670 | return -EEXIST; | |
6671 | } | |
6672 | // return a positive errno to distinguish between a blocking error | |
6673 | // and an error we consider to not be a problem (i.e., this would be | |
6674 | // an idempotent operation). | |
6675 | *existing_id = i; | |
6676 | return EEXIST; | |
6677 | } | |
6678 | // i < 0 | |
6679 | if (id >= 0) { | |
6680 | if (pending_inc.new_state.count(id)) { | |
6681 | // osd is about to exist | |
6682 | return -EAGAIN; | |
6683 | } | |
6684 | // we may not care if an osd exists if we are recreating a previously | |
6685 | // destroyed osd. | |
6686 | if (check_osd_exists && osdmap.exists(id)) { | |
6687 | ss << "id " << id << " already in use and does not match uuid " | |
6688 | << uuid; | |
6689 | return -EINVAL; | |
6690 | } | |
6691 | } | |
6692 | return 0; | |
6693 | } | |
6694 | ||
6695 | int OSDMonitor::prepare_command_osd_create( | |
6696 | const int32_t id, | |
6697 | const uuid_d& uuid, | |
6698 | int32_t* existing_id, | |
6699 | stringstream& ss) | |
6700 | { | |
6701 | dout(10) << __func__ << " id " << id << " uuid " << uuid << dendl; | |
6702 | assert(existing_id); | |
6703 | ||
6704 | if (uuid.is_zero()) { | |
6705 | dout(10) << __func__ << " no uuid; assuming legacy `osd create`" << dendl; | |
6706 | } | |
6707 | ||
6708 | return validate_osd_create(id, uuid, true, existing_id, ss); | |
6709 | } | |
6710 | ||
6711 | int OSDMonitor::prepare_command_osd_new( | |
6712 | MonOpRequestRef op, | |
6713 | const map<string,cmd_vartype>& cmdmap, | |
6714 | const map<string,string>& secrets, | |
6715 | stringstream &ss, | |
6716 | Formatter *f) | |
6717 | { | |
6718 | uuid_d uuid; | |
6719 | string uuidstr; | |
6720 | int64_t id = -1; | |
6721 | ||
6722 | assert(paxos->is_plugged()); | |
6723 | ||
6724 | dout(10) << __func__ << " " << op << dendl; | |
6725 | ||
6726 | /* validate command. abort now if something's wrong. */ | |
6727 | ||
6728 | /* `osd new` will expect a `uuid` to be supplied; `id` is optional. | |
6729 | * | |
6730 | * If `id` is not specified, we will identify any existing osd based | |
6731 | * on `uuid`. Operation will be idempotent iff secrets match. | |
6732 | * | |
6733 | * If `id` is specified, we will identify any existing osd based on | |
6734 | * `uuid` and match against `id`. If they match, operation will be | |
6735 | * idempotent iff secrets match. | |
6736 | * | |
6737 | * `-i secrets.json` will be optional. If supplied, will be used | |
6738 | * to check for idempotency when `id` and `uuid` match. | |
6739 | * | |
6740 | * If `id` is not specified, and `uuid` does not exist, an id will | |
6741 | * be found or allocated for the osd. | |
6742 | * | |
6743 | * If `id` is specified, and the osd has been previously marked | |
6744 | * as destroyed, then the `id` will be reused. | |
6745 | */ | |
6746 | if (!cmd_getval(g_ceph_context, cmdmap, "uuid", uuidstr)) { | |
6747 | ss << "requires the OSD's UUID to be specified."; | |
6748 | return -EINVAL; | |
6749 | } else if (!uuid.parse(uuidstr.c_str())) { | |
6750 | ss << "invalid UUID value '" << uuidstr << "'."; | |
6751 | return -EINVAL; | |
6752 | } | |
6753 | ||
6754 | if (cmd_getval(g_ceph_context, cmdmap, "id", id) && | |
6755 | (id < 0)) { | |
6756 | ss << "invalid OSD id; must be greater or equal than zero."; | |
6757 | return -EINVAL; | |
6758 | } | |
6759 | ||
6760 | // are we running an `osd create`-like command, or recreating | |
6761 | // a previously destroyed osd? | |
6762 | ||
6763 | bool is_recreate_destroyed = (id >= 0 && osdmap.is_destroyed(id)); | |
6764 | ||
6765 | // we will care about `id` to assess whether osd is `destroyed`, or | |
6766 | // to create a new osd. | |
6767 | // we will need an `id` by the time we reach auth. | |
6768 | ||
6769 | int32_t existing_id = -1; | |
6770 | int err = validate_osd_create(id, uuid, !is_recreate_destroyed, | |
6771 | &existing_id, ss); | |
6772 | ||
6773 | bool may_be_idempotent = false; | |
6774 | if (err == EEXIST) { | |
6775 | // this is idempotent from the osdmon's point-of-view | |
6776 | may_be_idempotent = true; | |
6777 | assert(existing_id >= 0); | |
6778 | id = existing_id; | |
6779 | } else if (err < 0) { | |
6780 | return err; | |
6781 | } | |
6782 | ||
6783 | if (!may_be_idempotent) { | |
6784 | // idempotency is out of the window. We are either creating a new | |
6785 | // osd or recreating a destroyed osd. | |
6786 | // | |
6787 | // We now need to figure out if we have an `id` (and if it's valid), | |
6788 | // of find an `id` if we don't have one. | |
6789 | ||
6790 | // NOTE: we need to consider the case where the `id` is specified for | |
6791 | // `osd create`, and we must honor it. So this means checking if | |
6792 | // the `id` is destroyed, and if so assume the destroy; otherwise, | |
6793 | // check if it `exists` - in which case we complain about not being | |
6794 | // `destroyed`. In the end, if nothing fails, we must allow the | |
6795 | // creation, so that we are compatible with `create`. | |
6796 | if (id >= 0 && osdmap.exists(id) && !osdmap.is_destroyed(id)) { | |
6797 | dout(10) << __func__ << " osd." << id << " isn't destroyed" << dendl; | |
6798 | ss << "OSD " << id << " has not yet been destroyed"; | |
6799 | return -EINVAL; | |
6800 | } else if (id < 0) { | |
6801 | // find an `id` | |
6802 | id = _allocate_osd_id(&existing_id); | |
6803 | if (id < 0) { | |
6804 | assert(existing_id >= 0); | |
6805 | id = existing_id; | |
6806 | } | |
6807 | dout(10) << __func__ << " found id " << id << " to use" << dendl; | |
6808 | } else if (id >= 0 && osdmap.is_destroyed(id)) { | |
6809 | dout(10) << __func__ << " recreating osd." << id << dendl; | |
6810 | } else { | |
6811 | dout(10) << __func__ << " creating new osd." << id << dendl; | |
6812 | } | |
6813 | } else { | |
6814 | assert(id >= 0); | |
6815 | assert(osdmap.exists(id)); | |
6816 | } | |
6817 | ||
6818 | // we are now able to either create a brand new osd or reuse an existing | |
6819 | // osd that has been previously destroyed. | |
6820 | ||
6821 | dout(10) << __func__ << " id " << id << " uuid " << uuid << dendl; | |
6822 | ||
6823 | if (may_be_idempotent && secrets.empty()) { | |
6824 | // nothing to do, really. | |
6825 | dout(10) << __func__ << " idempotent and no secrets -- no op." << dendl; | |
6826 | assert(id >= 0); | |
6827 | if (f) { | |
6828 | f->open_object_section("created_osd"); | |
6829 | f->dump_int("osdid", id); | |
6830 | f->close_section(); | |
6831 | } else { | |
6832 | ss << id; | |
6833 | } | |
6834 | return EEXIST; | |
6835 | } | |
6836 | ||
6837 | string cephx_secret, lockbox_secret, dmcrypt_key; | |
6838 | bool has_lockbox = false; | |
6839 | bool has_secrets = (!secrets.empty()); | |
6840 | ||
6841 | ConfigKeyService *svc = nullptr; | |
6842 | AuthMonitor::auth_entity_t cephx_entity, lockbox_entity; | |
6843 | ||
6844 | if (has_secrets) { | |
6845 | if (secrets.count("cephx_secret") == 0) { | |
6846 | ss << "requires a cephx secret."; | |
6847 | return -EINVAL; | |
6848 | } | |
6849 | cephx_secret = secrets.at("cephx_secret"); | |
6850 | ||
6851 | bool has_lockbox_secret = (secrets.count("cephx_lockbox_secret") > 0); | |
6852 | bool has_dmcrypt_key = (secrets.count("dmcrypt_key") > 0); | |
6853 | ||
6854 | dout(10) << __func__ << " has lockbox " << has_lockbox_secret | |
6855 | << " dmcrypt " << has_dmcrypt_key << dendl; | |
6856 | ||
6857 | if (has_lockbox_secret && has_dmcrypt_key) { | |
6858 | has_lockbox = true; | |
6859 | lockbox_secret = secrets.at("cephx_lockbox_secret"); | |
6860 | dmcrypt_key = secrets.at("dmcrypt_key"); | |
6861 | } else if (!has_lockbox_secret != !has_dmcrypt_key) { | |
6862 | ss << "requires both a cephx lockbox secret and a dm-crypt key."; | |
6863 | return -EINVAL; | |
6864 | } | |
6865 | ||
6866 | dout(10) << __func__ << " validate secrets using osd id " << id << dendl; | |
6867 | ||
6868 | err = mon->authmon()->validate_osd_new(id, uuid, | |
6869 | cephx_secret, | |
6870 | lockbox_secret, | |
6871 | cephx_entity, | |
6872 | lockbox_entity, | |
6873 | ss); | |
6874 | if (err < 0) { | |
6875 | return err; | |
6876 | } else if (may_be_idempotent && err != EEXIST) { | |
6877 | // for this to be idempotent, `id` should already be >= 0; no need | |
6878 | // to use validate_id. | |
6879 | assert(id >= 0); | |
6880 | ss << "osd." << id << " exists but secrets do not match"; | |
6881 | return -EEXIST; | |
6882 | } | |
6883 | ||
6884 | if (has_lockbox) { | |
6885 | svc = (ConfigKeyService*)mon->config_key_service; | |
6886 | err = svc->validate_osd_new(uuid, dmcrypt_key, ss); | |
6887 | if (err < 0) { | |
6888 | return err; | |
6889 | } else if (may_be_idempotent && err != EEXIST) { | |
6890 | assert(id >= 0); | |
6891 | ss << "osd." << id << " exists but dm-crypt key does not match."; | |
6892 | return -EEXIST; | |
6893 | } | |
6894 | } | |
6895 | } | |
6896 | assert(!has_secrets || !cephx_secret.empty()); | |
6897 | assert(!has_lockbox || !lockbox_secret.empty()); | |
6898 | ||
6899 | if (may_be_idempotent) { | |
6900 | // we have nothing to do for either the osdmon or the authmon, | |
6901 | // and we have no lockbox - so the config key service will not be | |
6902 | // touched. This is therefore an idempotent operation, and we can | |
6903 | // just return right away. | |
6904 | dout(10) << __func__ << " idempotent -- no op." << dendl; | |
6905 | assert(id >= 0); | |
6906 | if (f) { | |
6907 | f->open_object_section("created_osd"); | |
6908 | f->dump_int("osdid", id); | |
6909 | f->close_section(); | |
6910 | } else { | |
6911 | ss << id; | |
6912 | } | |
6913 | return EEXIST; | |
6914 | } | |
6915 | assert(!may_be_idempotent); | |
6916 | ||
6917 | // perform updates. | |
6918 | if (has_secrets) { | |
6919 | assert(!cephx_secret.empty()); | |
6920 | assert((lockbox_secret.empty() && dmcrypt_key.empty()) || | |
6921 | (!lockbox_secret.empty() && !dmcrypt_key.empty())); | |
6922 | ||
6923 | err = mon->authmon()->do_osd_new(cephx_entity, | |
6924 | lockbox_entity, | |
6925 | has_lockbox); | |
6926 | assert(0 == err); | |
6927 | ||
6928 | if (has_lockbox) { | |
6929 | assert(nullptr != svc); | |
6930 | svc->do_osd_new(uuid, dmcrypt_key); | |
6931 | } | |
6932 | } | |
6933 | ||
6934 | if (is_recreate_destroyed) { | |
6935 | assert(id >= 0); | |
6936 | assert(osdmap.is_destroyed(id)); | |
6937 | pending_inc.new_weight[id] = CEPH_OSD_OUT; | |
6938 | pending_inc.new_state[id] |= CEPH_OSD_DESTROYED | CEPH_OSD_NEW; | |
c07f9fc5 FG |
6939 | if (osdmap.get_state(id) & CEPH_OSD_UP) { |
6940 | // due to http://tracker.ceph.com/issues/20751 some clusters may | |
6941 | // have UP set for non-existent OSDs; make sure it is cleared | |
6942 | // for a newly created osd. | |
6943 | pending_inc.new_state[id] |= CEPH_OSD_UP; | |
6944 | } | |
31f18b77 FG |
6945 | pending_inc.new_uuid[id] = uuid; |
6946 | } else { | |
6947 | assert(id >= 0); | |
6948 | int32_t new_id = -1; | |
6949 | do_osd_create(id, uuid, &new_id); | |
6950 | assert(new_id >= 0); | |
6951 | assert(id == new_id); | |
6952 | } | |
6953 | ||
6954 | if (f) { | |
6955 | f->open_object_section("created_osd"); | |
6956 | f->dump_int("osdid", id); | |
6957 | f->close_section(); | |
6958 | } else { | |
6959 | ss << id; | |
6960 | } | |
6961 | ||
6962 | return 0; | |
6963 | } | |
6964 | ||
7c673cae FG |
6965 | bool OSDMonitor::prepare_command(MonOpRequestRef op) |
6966 | { | |
6967 | op->mark_osdmon_event(__func__); | |
6968 | MMonCommand *m = static_cast<MMonCommand*>(op->get_req()); | |
6969 | stringstream ss; | |
6970 | map<string, cmd_vartype> cmdmap; | |
6971 | if (!cmdmap_from_json(m->cmd, &cmdmap, ss)) { | |
6972 | string rs = ss.str(); | |
6973 | mon->reply_command(op, -EINVAL, rs, get_last_committed()); | |
6974 | return true; | |
6975 | } | |
6976 | ||
6977 | MonSession *session = m->get_session(); | |
6978 | if (!session) { | |
6979 | mon->reply_command(op, -EACCES, "access denied", get_last_committed()); | |
6980 | return true; | |
6981 | } | |
6982 | ||
6983 | return prepare_command_impl(op, cmdmap); | |
6984 | } | |
6985 | ||
6986 | static int parse_reweights(CephContext *cct, | |
6987 | const map<string,cmd_vartype> &cmdmap, | |
6988 | const OSDMap& osdmap, | |
6989 | map<int32_t, uint32_t>* weights) | |
6990 | { | |
6991 | string weights_str; | |
6992 | if (!cmd_getval(g_ceph_context, cmdmap, "weights", weights_str)) { | |
6993 | return -EINVAL; | |
6994 | } | |
6995 | std::replace(begin(weights_str), end(weights_str), '\'', '"'); | |
6996 | json_spirit::mValue json_value; | |
6997 | if (!json_spirit::read(weights_str, json_value)) { | |
6998 | return -EINVAL; | |
6999 | } | |
7000 | if (json_value.type() != json_spirit::obj_type) { | |
7001 | return -EINVAL; | |
7002 | } | |
7003 | const auto obj = json_value.get_obj(); | |
7004 | try { | |
7005 | for (auto& osd_weight : obj) { | |
7006 | auto osd_id = std::stoi(osd_weight.first); | |
7007 | if (!osdmap.exists(osd_id)) { | |
7008 | return -ENOENT; | |
7009 | } | |
7010 | if (osd_weight.second.type() != json_spirit::str_type) { | |
7011 | return -EINVAL; | |
7012 | } | |
7013 | auto weight = std::stoul(osd_weight.second.get_str()); | |
7014 | weights->insert({osd_id, weight}); | |
7015 | } | |
7016 | } catch (const std::logic_error& e) { | |
7017 | return -EINVAL; | |
7018 | } | |
7019 | return 0; | |
7020 | } | |
7021 | ||
31f18b77 FG |
7022 | int OSDMonitor::prepare_command_osd_destroy( |
7023 | int32_t id, | |
7024 | stringstream& ss) | |
7025 | { | |
7026 | assert(paxos->is_plugged()); | |
7027 | ||
7028 | // we check if the osd exists for the benefit of `osd purge`, which may | |
7029 | // have previously removed the osd. If the osd does not exist, return | |
7030 | // -ENOENT to convey this, and let the caller deal with it. | |
7031 | // | |
7032 | // we presume that all auth secrets and config keys were removed prior | |
7033 | // to this command being called. if they exist by now, we also assume | |
7034 | // they must have been created by some other command and do not pertain | |
7035 | // to this non-existent osd. | |
7036 | if (!osdmap.exists(id)) { | |
7037 | dout(10) << __func__ << " osd." << id << " does not exist." << dendl; | |
7038 | return -ENOENT; | |
7039 | } | |
7040 | ||
7041 | uuid_d uuid = osdmap.get_uuid(id); | |
7042 | dout(10) << __func__ << " destroying osd." << id | |
7043 | << " uuid " << uuid << dendl; | |
7044 | ||
7045 | // if it has been destroyed, we assume our work here is done. | |
7046 | if (osdmap.is_destroyed(id)) { | |
7047 | ss << "destroyed osd." << id; | |
7048 | return 0; | |
7049 | } | |
7050 | ||
7051 | EntityName cephx_entity, lockbox_entity; | |
7052 | bool idempotent_auth = false, idempotent_cks = false; | |
7053 | ||
7054 | int err = mon->authmon()->validate_osd_destroy(id, uuid, | |
7055 | cephx_entity, | |
7056 | lockbox_entity, | |
7057 | ss); | |
7058 | if (err < 0) { | |
7059 | if (err == -ENOENT) { | |
7060 | idempotent_auth = true; | |
31f18b77 FG |
7061 | } else { |
7062 | return err; | |
7063 | } | |
7064 | } | |
7065 | ||
7066 | ConfigKeyService *svc = (ConfigKeyService*)mon->config_key_service; | |
7067 | err = svc->validate_osd_destroy(id, uuid); | |
7068 | if (err < 0) { | |
7069 | assert(err == -ENOENT); | |
7070 | err = 0; | |
7071 | idempotent_cks = true; | |
7072 | } | |
7073 | ||
7074 | if (!idempotent_auth) { | |
7075 | err = mon->authmon()->do_osd_destroy(cephx_entity, lockbox_entity); | |
7076 | assert(0 == err); | |
7077 | } | |
7078 | ||
7079 | if (!idempotent_cks) { | |
7080 | svc->do_osd_destroy(id, uuid); | |
7081 | } | |
7082 | ||
7083 | pending_inc.new_state[id] = CEPH_OSD_DESTROYED; | |
7084 | pending_inc.new_uuid[id] = uuid_d(); | |
7085 | ||
7086 | // we can only propose_pending() once per service, otherwise we'll be | |
7087 | // defying PaxosService and all laws of nature. Therefore, as we may | |
7088 | // be used during 'osd purge', let's keep the caller responsible for | |
7089 | // proposing. | |
7090 | assert(err == 0); | |
7091 | return 0; | |
7092 | } | |
7093 | ||
7094 | int OSDMonitor::prepare_command_osd_purge( | |
7095 | int32_t id, | |
7096 | stringstream& ss) | |
7097 | { | |
7098 | assert(paxos->is_plugged()); | |
7099 | dout(10) << __func__ << " purging osd." << id << dendl; | |
7100 | ||
7101 | assert(!osdmap.is_up(id)); | |
7102 | ||
7103 | /* | |
7104 | * This may look a bit weird, but this is what's going to happen: | |
7105 | * | |
7106 | * 1. we make sure that removing from crush works | |
7107 | * 2. we call `prepare_command_osd_destroy()`. If it returns an | |
7108 | * error, then we abort the whole operation, as no updates | |
7109 | * have been made. However, we this function will have | |
7110 | * side-effects, thus we need to make sure that all operations | |
7111 | * performed henceforth will *always* succeed. | |
7112 | * 3. we call `prepare_command_osd_remove()`. Although this | |
7113 | * function can return an error, it currently only checks if the | |
7114 | * osd is up - and we have made sure that it is not so, so there | |
7115 | * is no conflict, and it is effectively an update. | |
7116 | * 4. finally, we call `do_osd_crush_remove()`, which will perform | |
7117 | * the crush update we delayed from before. | |
7118 | */ | |
7119 | ||
7120 | CrushWrapper newcrush; | |
7121 | _get_pending_crush(newcrush); | |
7122 | ||
7123 | bool may_be_idempotent = false; | |
7124 | ||
7125 | int err = _prepare_command_osd_crush_remove(newcrush, id, 0, false, false); | |
7126 | if (err == -ENOENT) { | |
7127 | err = 0; | |
7128 | may_be_idempotent = true; | |
7129 | } else if (err < 0) { | |
7130 | ss << "error removing osd." << id << " from crush"; | |
7131 | return err; | |
7132 | } | |
7133 | ||
7134 | // no point destroying the osd again if it has already been marked destroyed | |
7135 | if (!osdmap.is_destroyed(id)) { | |
7136 | err = prepare_command_osd_destroy(id, ss); | |
7137 | if (err < 0) { | |
7138 | if (err == -ENOENT) { | |
7139 | err = 0; | |
7140 | } else { | |
7141 | return err; | |
7142 | } | |
7143 | } else { | |
7144 | may_be_idempotent = false; | |
7145 | } | |
7146 | } | |
7147 | assert(0 == err); | |
7148 | ||
7149 | if (may_be_idempotent && !osdmap.exists(id)) { | |
7150 | dout(10) << __func__ << " osd." << id << " does not exist and " | |
7151 | << "we are idempotent." << dendl; | |
7152 | return -ENOENT; | |
7153 | } | |
7154 | ||
7155 | err = prepare_command_osd_remove(id); | |
7156 | // we should not be busy, as we should have made sure this id is not up. | |
7157 | assert(0 == err); | |
7158 | ||
7159 | do_osd_crush_remove(newcrush); | |
7160 | return 0; | |
7161 | } | |
7162 | ||
7c673cae FG |
7163 | bool OSDMonitor::prepare_command_impl(MonOpRequestRef op, |
7164 | map<string,cmd_vartype> &cmdmap) | |
7165 | { | |
7166 | op->mark_osdmon_event(__func__); | |
7167 | MMonCommand *m = static_cast<MMonCommand*>(op->get_req()); | |
7168 | bool ret = false; | |
7169 | stringstream ss; | |
7170 | string rs; | |
7171 | bufferlist rdata; | |
7172 | int err = 0; | |
7173 | ||
7174 | string format; | |
7175 | cmd_getval(g_ceph_context, cmdmap, "format", format, string("plain")); | |
7176 | boost::scoped_ptr<Formatter> f(Formatter::create(format)); | |
7177 | ||
7178 | string prefix; | |
7179 | cmd_getval(g_ceph_context, cmdmap, "prefix", prefix); | |
7180 | ||
7181 | int64_t osdid; | |
7182 | string name; | |
7183 | bool osdid_present = cmd_getval(g_ceph_context, cmdmap, "id", osdid); | |
7184 | if (osdid_present) { | |
7185 | ostringstream oss; | |
7186 | oss << "osd." << osdid; | |
7187 | name = oss.str(); | |
7188 | } | |
7189 | ||
7190 | // Even if there's a pending state with changes that could affect | |
7191 | // a command, considering that said state isn't yet committed, we | |
7192 | // just don't care about those changes if the command currently being | |
7193 | // handled acts as a no-op against the current committed state. | |
7194 | // In a nutshell, we assume this command happens *before*. | |
7195 | // | |
7196 | // Let me make this clearer: | |
7197 | // | |
7198 | // - If we have only one client, and that client issues some | |
7199 | // operation that would conflict with this operation but is | |
7200 | // still on the pending state, then we would be sure that said | |
7201 | // operation wouldn't have returned yet, so the client wouldn't | |
7202 | // issue this operation (unless the client didn't wait for the | |
7203 | // operation to finish, and that would be the client's own fault). | |
7204 | // | |
7205 | // - If we have more than one client, each client will observe | |
7206 | // whatever is the state at the moment of the commit. So, if we | |
7207 | // have two clients, one issuing an unlink and another issuing a | |
7208 | // link, and if the link happens while the unlink is still on the | |
7209 | // pending state, from the link's point-of-view this is a no-op. | |
7210 | // If different clients are issuing conflicting operations and | |
7211 | // they care about that, then the clients should make sure they | |
7212 | // enforce some kind of concurrency mechanism -- from our | |
7213 | // perspective that's what Douglas Adams would call an SEP. | |
7214 | // | |
7215 | // This should be used as a general guideline for most commands handled | |
7216 | // in this function. Adapt as you see fit, but please bear in mind that | |
7217 | // this is the expected behavior. | |
7218 | ||
7219 | ||
7220 | if (prefix == "osd setcrushmap" || | |
7221 | (prefix == "osd crush set" && !osdid_present)) { | |
31f18b77 FG |
7222 | if (pending_inc.crush.length()) { |
7223 | dout(10) << __func__ << " waiting for pending crush update " << dendl; | |
7224 | wait_for_finished_proposal(op, new C_RetryMessage(this, op)); | |
7225 | return true; | |
7226 | } | |
7c673cae FG |
7227 | dout(10) << "prepare_command setting new crush map" << dendl; |
7228 | bufferlist data(m->get_data()); | |
7229 | CrushWrapper crush; | |
7230 | try { | |
7231 | bufferlist::iterator bl(data.begin()); | |
7232 | crush.decode(bl); | |
7233 | } | |
7234 | catch (const std::exception &e) { | |
7235 | err = -EINVAL; | |
7236 | ss << "Failed to parse crushmap: " << e.what(); | |
7237 | goto reply; | |
7238 | } | |
31f18b77 FG |
7239 | |
7240 | int64_t prior_version = 0; | |
7241 | if (cmd_getval(g_ceph_context, cmdmap, "prior_version", prior_version)) { | |
7242 | if (prior_version == osdmap.get_crush_version() - 1) { | |
7243 | // see if we are a resend of the last update. this is imperfect | |
7244 | // (multiple racing updaters may not both get reliable success) | |
7245 | // but we expect crush updaters (via this interface) to be rare-ish. | |
7246 | bufferlist current, proposed; | |
7247 | osdmap.crush->encode(current, mon->get_quorum_con_features()); | |
7248 | crush.encode(proposed, mon->get_quorum_con_features()); | |
7249 | if (current.contents_equal(proposed)) { | |
7250 | dout(10) << __func__ | |
7251 | << " proposed matches current and version equals previous" | |
7252 | << dendl; | |
7253 | err = 0; | |
7254 | ss << osdmap.get_crush_version(); | |
7255 | goto reply; | |
7256 | } | |
7257 | } | |
7258 | if (prior_version != osdmap.get_crush_version()) { | |
7259 | err = -EPERM; | |
7260 | ss << "prior_version " << prior_version << " != crush version " | |
7261 | << osdmap.get_crush_version(); | |
7262 | goto reply; | |
7263 | } | |
7264 | } | |
7c673cae | 7265 | |
31f18b77 FG |
7266 | if (crush.has_legacy_rulesets()) { |
7267 | err = -EINVAL; | |
7268 | ss << "crush maps with ruleset != ruleid are no longer allowed"; | |
7269 | goto reply; | |
7270 | } | |
7c673cae FG |
7271 | if (!validate_crush_against_features(&crush, ss)) { |
7272 | err = -EINVAL; | |
7273 | goto reply; | |
7274 | } | |
31f18b77 | 7275 | |
7c673cae FG |
7276 | const auto& osdmap_pools = osdmap.get_pools(); |
7277 | for (auto pit = osdmap_pools.begin(); pit != osdmap_pools.end(); ++pit) { | |
7278 | const int64_t pool_id = pit->first; | |
7279 | const pg_pool_t &pool = pit->second; | |
31f18b77 | 7280 | int ruleno = pool.get_crush_rule(); |
7c673cae FG |
7281 | if (!crush.rule_exists(ruleno)) { |
7282 | ss << " the crush rule no "<< ruleno << " for pool id " << pool_id << " is in use"; | |
7283 | err = -EINVAL; | |
7284 | goto reply; | |
7285 | } | |
7286 | } | |
7287 | ||
224ce89b WB |
7288 | if (g_conf->mon_osd_crush_smoke_test) { |
7289 | // sanity check: test some inputs to make sure this map isn't | |
7290 | // totally broken | |
7291 | dout(10) << " testing map" << dendl; | |
7292 | stringstream ess; | |
7293 | CrushTester tester(crush, ess); | |
7294 | tester.set_max_x(50); | |
7295 | int r = tester.test_with_fork(g_conf->mon_lease); | |
7296 | if (r < 0) { | |
7297 | dout(10) << " tester.test_with_fork returns " << r | |
7298 | << ": " << ess.str() << dendl; | |
7299 | ss << "crush smoke test failed with " << r << ": " << ess.str(); | |
7300 | err = r; | |
7301 | goto reply; | |
7302 | } | |
7303 | dout(10) << " crush test result " << ess.str() << dendl; | |
7c673cae FG |
7304 | } |
7305 | ||
7c673cae | 7306 | pending_inc.crush = data; |
31f18b77 | 7307 | ss << osdmap.get_crush_version() + 1; |
7c673cae FG |
7308 | goto update; |
7309 | ||
7310 | } else if (prefix == "osd crush set-device-class") { | |
224ce89b WB |
7311 | if (osdmap.require_osd_release < CEPH_RELEASE_LUMINOUS) { |
7312 | ss << "you must complete the upgrade and 'ceph osd require-osd-release " | |
7313 | << "luminous' before using crush device classes"; | |
7314 | err = -EPERM; | |
7c673cae FG |
7315 | goto reply; |
7316 | } | |
7317 | ||
7318 | string device_class; | |
7319 | if (!cmd_getval(g_ceph_context, cmdmap, "class", device_class)) { | |
7320 | err = -EINVAL; // no value! | |
7321 | goto reply; | |
7322 | } | |
7323 | ||
224ce89b WB |
7324 | bool stop = false; |
7325 | vector<string> idvec; | |
7326 | cmd_getval(g_ceph_context, cmdmap, "ids", idvec); | |
7c673cae FG |
7327 | CrushWrapper newcrush; |
7328 | _get_pending_crush(newcrush); | |
224ce89b WB |
7329 | set<int> updated; |
7330 | for (unsigned j = 0; j < idvec.size() && !stop; j++) { | |
7331 | set<int> osds; | |
7332 | // wildcard? | |
7333 | if (j == 0 && | |
7334 | (idvec[0] == "any" || idvec[0] == "all" || idvec[0] == "*")) { | |
7335 | osdmap.get_all_osds(osds); | |
7336 | stop = true; | |
7337 | } else { | |
7338 | // try traditional single osd way | |
7339 | long osd = parse_osd_id(idvec[j].c_str(), &ss); | |
7340 | if (osd < 0) { | |
7341 | // ss has reason for failure | |
7342 | ss << ", unable to parse osd id:\"" << idvec[j] << "\". "; | |
7343 | err = -EINVAL; | |
7344 | continue; | |
7345 | } | |
7346 | osds.insert(osd); | |
7347 | } | |
7c673cae | 7348 | |
224ce89b WB |
7349 | for (auto &osd : osds) { |
7350 | if (!osdmap.exists(osd)) { | |
7351 | ss << "osd." << osd << " does not exist. "; | |
7352 | continue; | |
7353 | } | |
7c673cae | 7354 | |
224ce89b WB |
7355 | ostringstream oss; |
7356 | oss << "osd." << osd; | |
7357 | string name = oss.str(); | |
7c673cae | 7358 | |
224ce89b WB |
7359 | string action; |
7360 | if (newcrush.item_exists(osd)) { | |
7361 | action = "updating"; | |
7362 | } else { | |
7363 | action = "creating"; | |
7364 | newcrush.set_item_name(osd, name); | |
7365 | } | |
7c673cae | 7366 | |
224ce89b WB |
7367 | dout(5) << action << " crush item id " << osd << " name '" << name |
7368 | << "' device_class '" << device_class << "'" | |
7369 | << dendl; | |
7370 | err = newcrush.update_device_class(osd, device_class, name, &ss); | |
7371 | if (err < 0) { | |
7372 | goto reply; | |
7373 | } | |
7374 | if (err == 0 && !_have_pending_crush()) { | |
7375 | if (!stop) { | |
7376 | // for single osd only, wildcard makes too much noise | |
7377 | ss << "set-device-class item id " << osd << " name '" << name | |
7378 | << "' device_class '" << device_class << "': no change"; | |
7379 | } | |
7380 | } else { | |
7381 | updated.insert(osd); | |
7382 | } | |
7383 | } | |
7c673cae FG |
7384 | } |
7385 | ||
224ce89b WB |
7386 | if (!updated.empty()) { |
7387 | pending_inc.crush.clear(); | |
7388 | newcrush.encode(pending_inc.crush, mon->get_quorum_con_features()); | |
7389 | ss << "set osd(s) " << updated << " to class '" << device_class << "'"; | |
7390 | getline(ss, rs); | |
7391 | wait_for_finished_proposal(op, | |
7392 | new Monitor::C_Command(mon,op, 0, rs, get_last_committed() + 1)); | |
7393 | return true; | |
7394 | } | |
7c673cae | 7395 | |
c07f9fc5 FG |
7396 | } else if (prefix == "osd crush rm-device-class") { |
7397 | bool stop = false; | |
7398 | vector<string> idvec; | |
7399 | cmd_getval(g_ceph_context, cmdmap, "ids", idvec); | |
7400 | CrushWrapper newcrush; | |
7401 | _get_pending_crush(newcrush); | |
7402 | set<int> updated; | |
7403 | ||
7404 | for (unsigned j = 0; j < idvec.size() && !stop; j++) { | |
7405 | set<int> osds; | |
7406 | ||
7407 | // wildcard? | |
7408 | if (j == 0 && | |
7409 | (idvec[0] == "any" || idvec[0] == "all" || idvec[0] == "*")) { | |
7410 | osdmap.get_all_osds(osds); | |
7411 | stop = true; | |
7412 | } else { | |
7413 | // try traditional single osd way | |
7414 | long osd = parse_osd_id(idvec[j].c_str(), &ss); | |
7415 | if (osd < 0) { | |
7416 | // ss has reason for failure | |
7417 | ss << ", unable to parse osd id:\"" << idvec[j] << "\". "; | |
7418 | err = -EINVAL; | |
7419 | goto reply; | |
7420 | } | |
7421 | osds.insert(osd); | |
7422 | } | |
7423 | ||
7424 | for (auto &osd : osds) { | |
7425 | if (!osdmap.exists(osd)) { | |
7426 | ss << "osd." << osd << " does not exist. "; | |
7427 | continue; | |
7428 | } | |
7429 | ||
7430 | auto class_name = newcrush.get_item_class(osd); | |
c07f9fc5 FG |
7431 | if (!class_name) { |
7432 | ss << "osd." << osd << " belongs to no class, "; | |
7433 | continue; | |
7434 | } | |
7435 | // note that we do not verify if class_is_in_use here | |
7436 | // in case the device is misclassified and user wants | |
7437 | // to overridely reset... | |
7438 | ||
7439 | err = newcrush.remove_device_class(g_ceph_context, osd, &ss); | |
7440 | if (err < 0) { | |
7441 | // ss has reason for failure | |
7442 | goto reply; | |
7443 | } | |
7444 | updated.insert(osd); | |
7445 | } | |
7446 | } | |
7447 | ||
7448 | if (!updated.empty()) { | |
7449 | pending_inc.crush.clear(); | |
7450 | newcrush.encode(pending_inc.crush, mon->get_quorum_con_features()); | |
7451 | ss << "done removing class of osd(s): " << updated; | |
7452 | getline(ss, rs); | |
7453 | wait_for_finished_proposal(op, | |
7454 | new Monitor::C_Command(mon,op, 0, rs, get_last_committed() + 1)); | |
7455 | return true; | |
7456 | } | |
7457 | ||
7c673cae FG |
7458 | } else if (prefix == "osd crush add-bucket") { |
7459 | // os crush add-bucket <name> <type> | |
7460 | string name, typestr; | |
7461 | cmd_getval(g_ceph_context, cmdmap, "name", name); | |
7462 | cmd_getval(g_ceph_context, cmdmap, "type", typestr); | |
7463 | ||
7464 | if (!_have_pending_crush() && | |
7465 | _get_stable_crush().name_exists(name)) { | |
7466 | ss << "bucket '" << name << "' already exists"; | |
7467 | goto reply; | |
7468 | } | |
7469 | ||
7470 | CrushWrapper newcrush; | |
7471 | _get_pending_crush(newcrush); | |
7472 | ||
7473 | if (newcrush.name_exists(name)) { | |
7474 | ss << "bucket '" << name << "' already exists"; | |
7475 | goto update; | |
7476 | } | |
7477 | int type = newcrush.get_type_id(typestr); | |
7478 | if (type < 0) { | |
7479 | ss << "type '" << typestr << "' does not exist"; | |
7480 | err = -EINVAL; | |
7481 | goto reply; | |
7482 | } | |
7483 | if (type == 0) { | |
7484 | ss << "type '" << typestr << "' is for devices, not buckets"; | |
7485 | err = -EINVAL; | |
7486 | goto reply; | |
7487 | } | |
7488 | int bucketno; | |
7489 | err = newcrush.add_bucket(0, 0, | |
7490 | CRUSH_HASH_DEFAULT, type, 0, NULL, | |
7491 | NULL, &bucketno); | |
7492 | if (err < 0) { | |
7493 | ss << "add_bucket error: '" << cpp_strerror(err) << "'"; | |
7494 | goto reply; | |
7495 | } | |
7496 | err = newcrush.set_item_name(bucketno, name); | |
7497 | if (err < 0) { | |
7498 | ss << "error setting bucket name to '" << name << "'"; | |
7499 | goto reply; | |
7500 | } | |
7501 | ||
7502 | pending_inc.crush.clear(); | |
7503 | newcrush.encode(pending_inc.crush, mon->get_quorum_con_features()); | |
7504 | ss << "added bucket " << name << " type " << typestr | |
7505 | << " to crush map"; | |
7506 | goto update; | |
7507 | } else if (prefix == "osd crush rename-bucket") { | |
7508 | string srcname, dstname; | |
7509 | cmd_getval(g_ceph_context, cmdmap, "srcname", srcname); | |
7510 | cmd_getval(g_ceph_context, cmdmap, "dstname", dstname); | |
7511 | ||
7512 | err = crush_rename_bucket(srcname, dstname, &ss); | |
7513 | if (err == -EALREADY) // equivalent to success for idempotency | |
7514 | err = 0; | |
7515 | if (err) | |
7516 | goto reply; | |
7517 | else | |
7518 | goto update; | |
c07f9fc5 FG |
7519 | } else if (prefix == "osd crush weight-set create" || |
7520 | prefix == "osd crush weight-set create-compat") { | |
7521 | CrushWrapper newcrush; | |
7522 | _get_pending_crush(newcrush); | |
7523 | int64_t pool; | |
7524 | int positions; | |
7525 | if (newcrush.has_non_straw2_buckets()) { | |
7526 | ss << "crush map contains one or more bucket(s) that are not straw2"; | |
224ce89b WB |
7527 | err = -EPERM; |
7528 | goto reply; | |
7529 | } | |
c07f9fc5 FG |
7530 | if (prefix == "osd crush weight-set create") { |
7531 | if (osdmap.require_min_compat_client > 0 && | |
7532 | osdmap.require_min_compat_client < CEPH_RELEASE_LUMINOUS) { | |
7533 | ss << "require_min_compat_client " | |
7534 | << ceph_release_name(osdmap.require_min_compat_client) | |
7535 | << " < luminous, which is required for per-pool weight-sets. " | |
7536 | << "Try 'ceph osd set-require-min-compat-client luminous' " | |
7537 | << "before using the new interface"; | |
7538 | err = -EPERM; | |
7539 | goto reply; | |
7540 | } | |
7541 | string poolname, mode; | |
7542 | cmd_getval(g_ceph_context, cmdmap, "pool", poolname); | |
7543 | pool = osdmap.lookup_pg_pool_name(poolname.c_str()); | |
7544 | if (pool < 0) { | |
7545 | ss << "pool '" << poolname << "' not found"; | |
7546 | err = -ENOENT; | |
7547 | goto reply; | |
7548 | } | |
7549 | cmd_getval(g_ceph_context, cmdmap, "mode", mode); | |
7550 | if (mode != "flat" && mode != "positional") { | |
7551 | ss << "unrecognized weight-set mode '" << mode << "'"; | |
7552 | err = -EINVAL; | |
7553 | goto reply; | |
7554 | } | |
7555 | positions = mode == "flat" ? 1 : osdmap.get_pg_pool(pool)->get_size(); | |
7556 | } else { | |
7557 | pool = CrushWrapper::DEFAULT_CHOOSE_ARGS; | |
7558 | positions = 1; | |
224ce89b | 7559 | } |
c07f9fc5 FG |
7560 | newcrush.create_choose_args(pool, positions); |
7561 | pending_inc.crush.clear(); | |
7562 | newcrush.encode(pending_inc.crush, mon->get_quorum_con_features()); | |
7563 | goto update; | |
224ce89b | 7564 | |
c07f9fc5 FG |
7565 | } else if (prefix == "osd crush weight-set rm" || |
7566 | prefix == "osd crush weight-set rm-compat") { | |
224ce89b WB |
7567 | CrushWrapper newcrush; |
7568 | _get_pending_crush(newcrush); | |
c07f9fc5 FG |
7569 | int64_t pool; |
7570 | if (prefix == "osd crush weight-set rm") { | |
7571 | string poolname; | |
7572 | cmd_getval(g_ceph_context, cmdmap, "pool", poolname); | |
7573 | pool = osdmap.lookup_pg_pool_name(poolname.c_str()); | |
7574 | if (pool < 0) { | |
7575 | ss << "pool '" << poolname << "' not found"; | |
7576 | err = -ENOENT; | |
7577 | goto reply; | |
7578 | } | |
7579 | } else { | |
7580 | pool = CrushWrapper::DEFAULT_CHOOSE_ARGS; | |
224ce89b | 7581 | } |
c07f9fc5 FG |
7582 | newcrush.rm_choose_args(pool); |
7583 | pending_inc.crush.clear(); | |
7584 | newcrush.encode(pending_inc.crush, mon->get_quorum_con_features()); | |
7585 | goto update; | |
224ce89b | 7586 | |
c07f9fc5 FG |
7587 | } else if (prefix == "osd crush weight-set reweight" || |
7588 | prefix == "osd crush weight-set reweight-compat") { | |
7589 | string poolname, item; | |
7590 | vector<double> weight; | |
7591 | cmd_getval(g_ceph_context, cmdmap, "pool", poolname); | |
7592 | cmd_getval(g_ceph_context, cmdmap, "item", item); | |
7593 | cmd_getval(g_ceph_context, cmdmap, "weight", weight); | |
7594 | CrushWrapper newcrush; | |
7595 | _get_pending_crush(newcrush); | |
7596 | int64_t pool; | |
7597 | if (prefix == "osd crush weight-set reweight") { | |
7598 | pool = osdmap.lookup_pg_pool_name(poolname.c_str()); | |
7599 | if (pool < 0) { | |
7600 | ss << "pool '" << poolname << "' not found"; | |
7601 | err = -ENOENT; | |
7602 | goto reply; | |
7603 | } | |
7604 | if (!newcrush.have_choose_args(pool)) { | |
7605 | ss << "no weight-set for pool '" << poolname << "'"; | |
7606 | err = -ENOENT; | |
7607 | goto reply; | |
7608 | } | |
7609 | auto arg_map = newcrush.choose_args_get(pool); | |
7610 | int positions = newcrush.get_choose_args_positions(arg_map); | |
7611 | if (weight.size() != (size_t)positions) { | |
7612 | ss << "must specify exact " << positions << " weight values"; | |
7613 | err = -EINVAL; | |
7614 | goto reply; | |
7615 | } | |
7616 | } else { | |
7617 | pool = CrushWrapper::DEFAULT_CHOOSE_ARGS; | |
7618 | if (!newcrush.have_choose_args(pool)) { | |
7619 | ss << "no backward-compatible weight-set"; | |
7620 | err = -ENOENT; | |
7621 | goto reply; | |
7622 | } | |
224ce89b | 7623 | } |
c07f9fc5 FG |
7624 | if (!newcrush.name_exists(item)) { |
7625 | ss << "item '" << item << "' does not exist"; | |
7626 | err = -ENOENT; | |
224ce89b WB |
7627 | goto reply; |
7628 | } | |
c07f9fc5 FG |
7629 | err = newcrush.choose_args_adjust_item_weightf( |
7630 | g_ceph_context, | |
7631 | newcrush.choose_args_get(pool), | |
7632 | newcrush.get_item_id(item), | |
7633 | weight, | |
7634 | &ss); | |
224ce89b | 7635 | if (err < 0) { |
224ce89b WB |
7636 | goto reply; |
7637 | } | |
c07f9fc5 | 7638 | err = 0; |
224ce89b WB |
7639 | pending_inc.crush.clear(); |
7640 | newcrush.encode(pending_inc.crush, mon->get_quorum_con_features()); | |
224ce89b | 7641 | goto update; |
7c673cae FG |
7642 | } else if (osdid_present && |
7643 | (prefix == "osd crush set" || prefix == "osd crush add")) { | |
7644 | // <OsdName> is 'osd.<id>' or '<id>', passed as int64_t id | |
7645 | // osd crush set <OsdName> <weight> <loc1> [<loc2> ...] | |
7646 | // osd crush add <OsdName> <weight> <loc1> [<loc2> ...] | |
7647 | ||
7648 | if (!osdmap.exists(osdid)) { | |
7649 | err = -ENOENT; | |
c07f9fc5 | 7650 | ss << name << " does not exist. Create it before updating the crush map"; |
7c673cae FG |
7651 | goto reply; |
7652 | } | |
7653 | ||
7654 | double weight; | |
7655 | if (!cmd_getval(g_ceph_context, cmdmap, "weight", weight)) { | |
7656 | ss << "unable to parse weight value '" | |
7657 | << cmd_vartype_stringify(cmdmap["weight"]) << "'"; | |
7658 | err = -EINVAL; | |
7659 | goto reply; | |
7660 | } | |
7661 | ||
7662 | string args; | |
7663 | vector<string> argvec; | |
7664 | cmd_getval(g_ceph_context, cmdmap, "args", argvec); | |
7665 | map<string,string> loc; | |
7666 | CrushWrapper::parse_loc_map(argvec, &loc); | |
7667 | ||
7668 | if (prefix == "osd crush set" | |
7669 | && !_get_stable_crush().item_exists(osdid)) { | |
7670 | err = -ENOENT; | |
7671 | ss << "unable to set item id " << osdid << " name '" << name | |
7672 | << "' weight " << weight << " at location " << loc | |
7673 | << ": does not exist"; | |
7674 | goto reply; | |
7675 | } | |
7676 | ||
7677 | dout(5) << "adding/updating crush item id " << osdid << " name '" | |
7678 | << name << "' weight " << weight << " at location " | |
7679 | << loc << dendl; | |
7680 | CrushWrapper newcrush; | |
7681 | _get_pending_crush(newcrush); | |
7682 | ||
7683 | string action; | |
7684 | if (prefix == "osd crush set" || | |
7685 | newcrush.check_item_loc(g_ceph_context, osdid, loc, (int *)NULL)) { | |
7686 | action = "set"; | |
7687 | err = newcrush.update_item(g_ceph_context, osdid, weight, name, loc); | |
7688 | } else { | |
7689 | action = "add"; | |
7690 | err = newcrush.insert_item(g_ceph_context, osdid, weight, name, loc); | |
7691 | if (err == 0) | |
7692 | err = 1; | |
7693 | } | |
7694 | ||
7695 | if (err < 0) | |
7696 | goto reply; | |
7697 | ||
7698 | if (err == 0 && !_have_pending_crush()) { | |
7699 | ss << action << " item id " << osdid << " name '" << name << "' weight " | |
7700 | << weight << " at location " << loc << ": no change"; | |
7701 | goto reply; | |
7702 | } | |
7703 | ||
7704 | pending_inc.crush.clear(); | |
7705 | newcrush.encode(pending_inc.crush, mon->get_quorum_con_features()); | |
7706 | ss << action << " item id " << osdid << " name '" << name << "' weight " | |
7707 | << weight << " at location " << loc << " to crush map"; | |
7708 | getline(ss, rs); | |
7709 | wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, 0, rs, | |
7710 | get_last_committed() + 1)); | |
7711 | return true; | |
7712 | ||
7713 | } else if (prefix == "osd crush create-or-move") { | |
7714 | do { | |
7715 | // osd crush create-or-move <OsdName> <initial_weight> <loc1> [<loc2> ...] | |
7716 | if (!osdmap.exists(osdid)) { | |
7717 | err = -ENOENT; | |
7718 | ss << name << " does not exist. create it before updating the crush map"; | |
7719 | goto reply; | |
7720 | } | |
7721 | ||
7722 | double weight; | |
7723 | if (!cmd_getval(g_ceph_context, cmdmap, "weight", weight)) { | |
7724 | ss << "unable to parse weight value '" | |
7725 | << cmd_vartype_stringify(cmdmap["weight"]) << "'"; | |
7726 | err = -EINVAL; | |
7727 | goto reply; | |
7728 | } | |
7729 | ||
7730 | string args; | |
7731 | vector<string> argvec; | |
7732 | cmd_getval(g_ceph_context, cmdmap, "args", argvec); | |
7733 | map<string,string> loc; | |
7734 | CrushWrapper::parse_loc_map(argvec, &loc); | |
7735 | ||
7736 | dout(0) << "create-or-move crush item name '" << name << "' initial_weight " << weight | |
7737 | << " at location " << loc << dendl; | |
7738 | ||
7739 | CrushWrapper newcrush; | |
7740 | _get_pending_crush(newcrush); | |
7741 | ||
7742 | err = newcrush.create_or_move_item(g_ceph_context, osdid, weight, name, loc); | |
7743 | if (err == 0) { | |
7744 | ss << "create-or-move updated item name '" << name << "' weight " << weight | |
7745 | << " at location " << loc << " to crush map"; | |
7746 | break; | |
7747 | } | |
7748 | if (err > 0) { | |
7749 | pending_inc.crush.clear(); | |
7750 | newcrush.encode(pending_inc.crush, mon->get_quorum_con_features()); | |
7751 | ss << "create-or-move updating item name '" << name << "' weight " << weight | |
7752 | << " at location " << loc << " to crush map"; | |
7753 | getline(ss, rs); | |
7754 | wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, 0, rs, | |
7755 | get_last_committed() + 1)); | |
7756 | return true; | |
7757 | } | |
7758 | } while (false); | |
7759 | ||
7760 | } else if (prefix == "osd crush move") { | |
7761 | do { | |
7762 | // osd crush move <name> <loc1> [<loc2> ...] | |
7763 | ||
7764 | string args; | |
7765 | vector<string> argvec; | |
7766 | cmd_getval(g_ceph_context, cmdmap, "name", name); | |
7767 | cmd_getval(g_ceph_context, cmdmap, "args", argvec); | |
7768 | map<string,string> loc; | |
7769 | CrushWrapper::parse_loc_map(argvec, &loc); | |
7770 | ||
7771 | dout(0) << "moving crush item name '" << name << "' to location " << loc << dendl; | |
7772 | CrushWrapper newcrush; | |
7773 | _get_pending_crush(newcrush); | |
7774 | ||
7775 | if (!newcrush.name_exists(name)) { | |
7776 | err = -ENOENT; | |
7777 | ss << "item " << name << " does not exist"; | |
7778 | break; | |
7779 | } | |
7780 | int id = newcrush.get_item_id(name); | |
7781 | ||
7782 | if (!newcrush.check_item_loc(g_ceph_context, id, loc, (int *)NULL)) { | |
7783 | if (id >= 0) { | |
7784 | err = newcrush.create_or_move_item(g_ceph_context, id, 0, name, loc); | |
7785 | } else { | |
7786 | err = newcrush.move_bucket(g_ceph_context, id, loc); | |
7787 | } | |
7788 | if (err >= 0) { | |
7789 | ss << "moved item id " << id << " name '" << name << "' to location " << loc << " in crush map"; | |
7790 | pending_inc.crush.clear(); | |
7791 | newcrush.encode(pending_inc.crush, mon->get_quorum_con_features()); | |
7792 | getline(ss, rs); | |
7793 | wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, 0, rs, | |
7794 | get_last_committed() + 1)); | |
7795 | return true; | |
7796 | } | |
7797 | } else { | |
7798 | ss << "no need to move item id " << id << " name '" << name << "' to location " << loc << " in crush map"; | |
7799 | err = 0; | |
7800 | } | |
7801 | } while (false); | |
31f18b77 FG |
7802 | } else if (prefix == "osd crush swap-bucket") { |
7803 | string source, dest, force; | |
7804 | cmd_getval(g_ceph_context, cmdmap, "source", source); | |
7805 | cmd_getval(g_ceph_context, cmdmap, "dest", dest); | |
7806 | cmd_getval(g_ceph_context, cmdmap, "force", force); | |
7807 | CrushWrapper newcrush; | |
7808 | _get_pending_crush(newcrush); | |
7809 | if (!newcrush.name_exists(source)) { | |
7810 | ss << "source item " << source << " does not exist"; | |
7811 | err = -ENOENT; | |
7812 | goto reply; | |
7813 | } | |
7814 | if (!newcrush.name_exists(dest)) { | |
7815 | ss << "dest item " << dest << " does not exist"; | |
7816 | err = -ENOENT; | |
7817 | goto reply; | |
7818 | } | |
7819 | int sid = newcrush.get_item_id(source); | |
7820 | int did = newcrush.get_item_id(dest); | |
7821 | int sparent; | |
7822 | if (newcrush.get_immediate_parent_id(sid, &sparent) == 0 && | |
7823 | force != "--yes-i-really-mean-it") { | |
7824 | ss << "source item " << source << " is not an orphan bucket; pass --yes-i-really-mean-it to proceed anyway"; | |
7825 | err = -EPERM; | |
7826 | goto reply; | |
7827 | } | |
7828 | if (newcrush.get_bucket_alg(sid) != newcrush.get_bucket_alg(did) && | |
7829 | force != "--yes-i-really-mean-it") { | |
7830 | ss << "source bucket alg " << crush_alg_name(newcrush.get_bucket_alg(sid)) << " != " | |
7831 | << "dest bucket alg " << crush_alg_name(newcrush.get_bucket_alg(did)) | |
7832 | << "; pass --yes-i-really-mean-it to proceed anyway"; | |
7833 | err = -EPERM; | |
7834 | goto reply; | |
7835 | } | |
7836 | int r = newcrush.swap_bucket(g_ceph_context, sid, did); | |
7837 | if (r < 0) { | |
7838 | ss << "failed to swap bucket contents: " << cpp_strerror(r); | |
224ce89b | 7839 | err = r; |
31f18b77 FG |
7840 | goto reply; |
7841 | } | |
7842 | ss << "swapped bucket of " << source << " to " << dest; | |
7843 | pending_inc.crush.clear(); | |
7844 | newcrush.encode(pending_inc.crush, mon->get_quorum_con_features()); | |
7845 | wait_for_finished_proposal(op, | |
7846 | new Monitor::C_Command(mon, op, err, ss.str(), | |
7847 | get_last_committed() + 1)); | |
7848 | return true; | |
7849 | } else if (prefix == "osd crush link") { | |
7850 | // osd crush link <name> <loc1> [<loc2> ...] | |
7851 | string name; | |
7852 | cmd_getval(g_ceph_context, cmdmap, "name", name); | |
7853 | vector<string> argvec; | |
7854 | cmd_getval(g_ceph_context, cmdmap, "args", argvec); | |
7855 | map<string,string> loc; | |
7856 | CrushWrapper::parse_loc_map(argvec, &loc); | |
7857 | ||
7858 | // Need an explicit check for name_exists because get_item_id returns | |
7859 | // 0 on unfound. | |
7860 | int id = osdmap.crush->get_item_id(name); | |
7c673cae FG |
7861 | if (!osdmap.crush->name_exists(name)) { |
7862 | err = -ENOENT; | |
7863 | ss << "item " << name << " does not exist"; | |
7864 | goto reply; | |
7865 | } else { | |
7866 | dout(5) << "resolved crush name '" << name << "' to id " << id << dendl; | |
7867 | } | |
7868 | if (osdmap.crush->check_item_loc(g_ceph_context, id, loc, (int*) NULL)) { | |
7869 | ss << "no need to move item id " << id << " name '" << name | |
7870 | << "' to location " << loc << " in crush map"; | |
7871 | err = 0; | |
7872 | goto reply; | |
7873 | } | |
7874 | ||
7875 | dout(5) << "linking crush item name '" << name << "' at location " << loc << dendl; | |
7876 | CrushWrapper newcrush; | |
7877 | _get_pending_crush(newcrush); | |
7878 | ||
7879 | if (!newcrush.name_exists(name)) { | |
7880 | err = -ENOENT; | |
7881 | ss << "item " << name << " does not exist"; | |
7882 | goto reply; | |
7883 | } else { | |
7884 | int id = newcrush.get_item_id(name); | |
7885 | if (!newcrush.check_item_loc(g_ceph_context, id, loc, (int *)NULL)) { | |
7886 | err = newcrush.link_bucket(g_ceph_context, id, loc); | |
7887 | if (err >= 0) { | |
7888 | ss << "linked item id " << id << " name '" << name | |
7889 | << "' to location " << loc << " in crush map"; | |
7890 | pending_inc.crush.clear(); | |
7891 | newcrush.encode(pending_inc.crush, mon->get_quorum_con_features()); | |
7892 | } else { | |
7893 | ss << "cannot link item id " << id << " name '" << name | |
7894 | << "' to location " << loc; | |
7895 | goto reply; | |
7896 | } | |
7897 | } else { | |
7898 | ss << "no need to move item id " << id << " name '" << name | |
7899 | << "' to location " << loc << " in crush map"; | |
7900 | err = 0; | |
7901 | } | |
7902 | } | |
7903 | wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, err, ss.str(), | |
7904 | get_last_committed() + 1)); | |
7905 | return true; | |
7906 | } else if (prefix == "osd crush rm" || | |
7907 | prefix == "osd crush remove" || | |
7908 | prefix == "osd crush unlink") { | |
7909 | do { | |
7910 | // osd crush rm <id> [ancestor] | |
7911 | CrushWrapper newcrush; | |
7912 | _get_pending_crush(newcrush); | |
7913 | ||
7914 | string name; | |
7915 | cmd_getval(g_ceph_context, cmdmap, "name", name); | |
7916 | ||
7917 | if (!osdmap.crush->name_exists(name)) { | |
7918 | err = 0; | |
7919 | ss << "device '" << name << "' does not appear in the crush map"; | |
7920 | break; | |
7921 | } | |
7922 | if (!newcrush.name_exists(name)) { | |
7923 | err = 0; | |
7924 | ss << "device '" << name << "' does not appear in the crush map"; | |
7925 | getline(ss, rs); | |
7926 | wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, 0, rs, | |
7927 | get_last_committed() + 1)); | |
7928 | return true; | |
7929 | } | |
7930 | int id = newcrush.get_item_id(name); | |
31f18b77 FG |
7931 | int ancestor = 0; |
7932 | ||
7c673cae FG |
7933 | bool unlink_only = prefix == "osd crush unlink"; |
7934 | string ancestor_str; | |
7935 | if (cmd_getval(g_ceph_context, cmdmap, "ancestor", ancestor_str)) { | |
7936 | if (!newcrush.name_exists(ancestor_str)) { | |
7937 | err = -ENOENT; | |
7938 | ss << "ancestor item '" << ancestor_str | |
7939 | << "' does not appear in the crush map"; | |
7940 | break; | |
7941 | } | |
31f18b77 | 7942 | ancestor = newcrush.get_item_id(ancestor_str); |
7c673cae | 7943 | } |
31f18b77 FG |
7944 | |
7945 | err = prepare_command_osd_crush_remove( | |
7946 | newcrush, | |
7947 | id, ancestor, | |
7948 | (ancestor < 0), unlink_only); | |
7949 | ||
7c673cae FG |
7950 | if (err == -ENOENT) { |
7951 | ss << "item " << id << " does not appear in that position"; | |
7952 | err = 0; | |
7953 | break; | |
7954 | } | |
7955 | if (err == 0) { | |
7c673cae FG |
7956 | ss << "removed item id " << id << " name '" << name << "' from crush map"; |
7957 | getline(ss, rs); | |
7958 | wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, 0, rs, | |
7959 | get_last_committed() + 1)); | |
7960 | return true; | |
7961 | } | |
7962 | } while (false); | |
7963 | ||
7964 | } else if (prefix == "osd crush reweight-all") { | |
7c673cae FG |
7965 | CrushWrapper newcrush; |
7966 | _get_pending_crush(newcrush); | |
7967 | ||
7968 | newcrush.reweight(g_ceph_context); | |
7969 | pending_inc.crush.clear(); | |
7970 | newcrush.encode(pending_inc.crush, mon->get_quorum_con_features()); | |
7971 | ss << "reweighted crush hierarchy"; | |
7972 | getline(ss, rs); | |
7973 | wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, 0, rs, | |
7974 | get_last_committed() + 1)); | |
7975 | return true; | |
7976 | } else if (prefix == "osd crush reweight") { | |
7977 | // osd crush reweight <name> <weight> | |
7978 | CrushWrapper newcrush; | |
7979 | _get_pending_crush(newcrush); | |
7980 | ||
7981 | string name; | |
7982 | cmd_getval(g_ceph_context, cmdmap, "name", name); | |
7983 | if (!newcrush.name_exists(name)) { | |
7984 | err = -ENOENT; | |
7985 | ss << "device '" << name << "' does not appear in the crush map"; | |
7986 | goto reply; | |
7987 | } | |
7988 | ||
7989 | int id = newcrush.get_item_id(name); | |
7990 | if (id < 0) { | |
7991 | ss << "device '" << name << "' is not a leaf in the crush map"; | |
7992 | err = -EINVAL; | |
7993 | goto reply; | |
7994 | } | |
7995 | double w; | |
7996 | if (!cmd_getval(g_ceph_context, cmdmap, "weight", w)) { | |
7997 | ss << "unable to parse weight value '" | |
7998 | << cmd_vartype_stringify(cmdmap["weight"]) << "'"; | |
7999 | err = -EINVAL; | |
8000 | goto reply; | |
8001 | } | |
8002 | ||
8003 | err = newcrush.adjust_item_weightf(g_ceph_context, id, w); | |
8004 | if (err < 0) | |
8005 | goto reply; | |
8006 | pending_inc.crush.clear(); | |
8007 | newcrush.encode(pending_inc.crush, mon->get_quorum_con_features()); | |
8008 | ss << "reweighted item id " << id << " name '" << name << "' to " << w | |
8009 | << " in crush map"; | |
8010 | getline(ss, rs); | |
8011 | wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, 0, rs, | |
8012 | get_last_committed() + 1)); | |
8013 | return true; | |
8014 | } else if (prefix == "osd crush reweight-subtree") { | |
8015 | // osd crush reweight <name> <weight> | |
8016 | CrushWrapper newcrush; | |
8017 | _get_pending_crush(newcrush); | |
8018 | ||
8019 | string name; | |
8020 | cmd_getval(g_ceph_context, cmdmap, "name", name); | |
8021 | if (!newcrush.name_exists(name)) { | |
8022 | err = -ENOENT; | |
8023 | ss << "device '" << name << "' does not appear in the crush map"; | |
8024 | goto reply; | |
8025 | } | |
8026 | ||
8027 | int id = newcrush.get_item_id(name); | |
8028 | if (id >= 0) { | |
8029 | ss << "device '" << name << "' is not a subtree in the crush map"; | |
8030 | err = -EINVAL; | |
8031 | goto reply; | |
8032 | } | |
8033 | double w; | |
8034 | if (!cmd_getval(g_ceph_context, cmdmap, "weight", w)) { | |
8035 | ss << "unable to parse weight value '" | |
8036 | << cmd_vartype_stringify(cmdmap["weight"]) << "'"; | |
8037 | err = -EINVAL; | |
8038 | goto reply; | |
8039 | } | |
8040 | ||
8041 | err = newcrush.adjust_subtree_weightf(g_ceph_context, id, w); | |
8042 | if (err < 0) | |
8043 | goto reply; | |
8044 | pending_inc.crush.clear(); | |
8045 | newcrush.encode(pending_inc.crush, mon->get_quorum_con_features()); | |
8046 | ss << "reweighted subtree id " << id << " name '" << name << "' to " << w | |
8047 | << " in crush map"; | |
8048 | getline(ss, rs); | |
8049 | wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, 0, rs, | |
8050 | get_last_committed() + 1)); | |
8051 | return true; | |
8052 | } else if (prefix == "osd crush tunables") { | |
8053 | CrushWrapper newcrush; | |
8054 | _get_pending_crush(newcrush); | |
8055 | ||
8056 | err = 0; | |
8057 | string profile; | |
8058 | cmd_getval(g_ceph_context, cmdmap, "profile", profile); | |
8059 | if (profile == "legacy" || profile == "argonaut") { | |
8060 | newcrush.set_tunables_legacy(); | |
8061 | } else if (profile == "bobtail") { | |
8062 | newcrush.set_tunables_bobtail(); | |
8063 | } else if (profile == "firefly") { | |
8064 | newcrush.set_tunables_firefly(); | |
8065 | } else if (profile == "hammer") { | |
8066 | newcrush.set_tunables_hammer(); | |
8067 | } else if (profile == "jewel") { | |
8068 | newcrush.set_tunables_jewel(); | |
8069 | } else if (profile == "optimal") { | |
8070 | newcrush.set_tunables_optimal(); | |
8071 | } else if (profile == "default") { | |
8072 | newcrush.set_tunables_default(); | |
8073 | } else { | |
8074 | ss << "unrecognized profile '" << profile << "'"; | |
8075 | err = -EINVAL; | |
8076 | goto reply; | |
8077 | } | |
8078 | ||
8079 | if (!validate_crush_against_features(&newcrush, ss)) { | |
8080 | err = -EINVAL; | |
8081 | goto reply; | |
8082 | } | |
8083 | ||
8084 | pending_inc.crush.clear(); | |
8085 | newcrush.encode(pending_inc.crush, mon->get_quorum_con_features()); | |
8086 | ss << "adjusted tunables profile to " << profile; | |
8087 | getline(ss, rs); | |
8088 | wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, 0, rs, | |
8089 | get_last_committed() + 1)); | |
8090 | return true; | |
8091 | } else if (prefix == "osd crush set-tunable") { | |
8092 | CrushWrapper newcrush; | |
8093 | _get_pending_crush(newcrush); | |
8094 | ||
8095 | err = 0; | |
8096 | string tunable; | |
8097 | cmd_getval(g_ceph_context, cmdmap, "tunable", tunable); | |
8098 | ||
8099 | int64_t value = -1; | |
8100 | if (!cmd_getval(g_ceph_context, cmdmap, "value", value)) { | |
8101 | err = -EINVAL; | |
8102 | ss << "failed to parse integer value " << cmd_vartype_stringify(cmdmap["value"]); | |
8103 | goto reply; | |
8104 | } | |
8105 | ||
8106 | if (tunable == "straw_calc_version") { | |
224ce89b | 8107 | if (value != 0 && value != 1) { |
7c673cae FG |
8108 | ss << "value must be 0 or 1; got " << value; |
8109 | err = -EINVAL; | |
8110 | goto reply; | |
8111 | } | |
8112 | newcrush.set_straw_calc_version(value); | |
8113 | } else { | |
8114 | ss << "unrecognized tunable '" << tunable << "'"; | |
8115 | err = -EINVAL; | |
8116 | goto reply; | |
8117 | } | |
8118 | ||
8119 | if (!validate_crush_against_features(&newcrush, ss)) { | |
8120 | err = -EINVAL; | |
8121 | goto reply; | |
8122 | } | |
8123 | ||
8124 | pending_inc.crush.clear(); | |
8125 | newcrush.encode(pending_inc.crush, mon->get_quorum_con_features()); | |
8126 | ss << "adjusted tunable " << tunable << " to " << value; | |
8127 | getline(ss, rs); | |
8128 | wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, 0, rs, | |
8129 | get_last_committed() + 1)); | |
8130 | return true; | |
8131 | ||
8132 | } else if (prefix == "osd crush rule create-simple") { | |
8133 | string name, root, type, mode; | |
8134 | cmd_getval(g_ceph_context, cmdmap, "name", name); | |
8135 | cmd_getval(g_ceph_context, cmdmap, "root", root); | |
8136 | cmd_getval(g_ceph_context, cmdmap, "type", type); | |
8137 | cmd_getval(g_ceph_context, cmdmap, "mode", mode); | |
8138 | if (mode == "") | |
8139 | mode = "firstn"; | |
8140 | ||
8141 | if (osdmap.crush->rule_exists(name)) { | |
31f18b77 FG |
8142 | // The name is uniquely associated to a ruleid and the rule it contains |
8143 | // From the user point of view, the rule is more meaningfull. | |
8144 | ss << "rule " << name << " already exists"; | |
7c673cae FG |
8145 | err = 0; |
8146 | goto reply; | |
8147 | } | |
8148 | ||
8149 | CrushWrapper newcrush; | |
8150 | _get_pending_crush(newcrush); | |
8151 | ||
8152 | if (newcrush.rule_exists(name)) { | |
31f18b77 FG |
8153 | // The name is uniquely associated to a ruleid and the rule it contains |
8154 | // From the user point of view, the rule is more meaningfull. | |
8155 | ss << "rule " << name << " already exists"; | |
7c673cae FG |
8156 | err = 0; |
8157 | } else { | |
224ce89b | 8158 | int ruleno = newcrush.add_simple_rule(name, root, type, "", mode, |
7c673cae FG |
8159 | pg_pool_t::TYPE_REPLICATED, &ss); |
8160 | if (ruleno < 0) { | |
8161 | err = ruleno; | |
8162 | goto reply; | |
8163 | } | |
8164 | ||
8165 | pending_inc.crush.clear(); | |
8166 | newcrush.encode(pending_inc.crush, mon->get_quorum_con_features()); | |
8167 | } | |
8168 | getline(ss, rs); | |
8169 | wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, 0, rs, | |
8170 | get_last_committed() + 1)); | |
8171 | return true; | |
8172 | ||
224ce89b WB |
8173 | } else if (prefix == "osd crush rule create-replicated") { |
8174 | string name, root, type, device_class; | |
8175 | cmd_getval(g_ceph_context, cmdmap, "name", name); | |
8176 | cmd_getval(g_ceph_context, cmdmap, "root", root); | |
8177 | cmd_getval(g_ceph_context, cmdmap, "type", type); | |
8178 | cmd_getval(g_ceph_context, cmdmap, "class", device_class); | |
8179 | ||
8180 | if (!device_class.empty()) { | |
8181 | if (osdmap.require_osd_release < CEPH_RELEASE_LUMINOUS) { | |
8182 | ss << "you must complete the upgrade and 'ceph osd require-osd-release " | |
8183 | << "luminous' before using crush device classes"; | |
8184 | err = -EPERM; | |
8185 | goto reply; | |
8186 | } | |
8187 | } | |
8188 | ||
8189 | if (osdmap.crush->rule_exists(name)) { | |
8190 | // The name is uniquely associated to a ruleid and the rule it contains | |
8191 | // From the user point of view, the rule is more meaningfull. | |
8192 | ss << "rule " << name << " already exists"; | |
8193 | err = 0; | |
8194 | goto reply; | |
8195 | } | |
8196 | ||
8197 | CrushWrapper newcrush; | |
8198 | _get_pending_crush(newcrush); | |
8199 | ||
8200 | if (newcrush.rule_exists(name)) { | |
8201 | // The name is uniquely associated to a ruleid and the rule it contains | |
8202 | // From the user point of view, the rule is more meaningfull. | |
8203 | ss << "rule " << name << " already exists"; | |
8204 | err = 0; | |
8205 | } else { | |
8206 | int ruleno = newcrush.add_simple_rule( | |
8207 | name, root, type, device_class, | |
8208 | "firstn", pg_pool_t::TYPE_REPLICATED, &ss); | |
8209 | if (ruleno < 0) { | |
8210 | err = ruleno; | |
8211 | goto reply; | |
8212 | } | |
8213 | ||
8214 | pending_inc.crush.clear(); | |
8215 | newcrush.encode(pending_inc.crush, mon->get_quorum_con_features()); | |
8216 | } | |
8217 | getline(ss, rs); | |
8218 | wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, 0, rs, | |
8219 | get_last_committed() + 1)); | |
8220 | return true; | |
8221 | ||
7c673cae FG |
8222 | } else if (prefix == "osd erasure-code-profile rm") { |
8223 | string name; | |
8224 | cmd_getval(g_ceph_context, cmdmap, "name", name); | |
8225 | ||
8226 | if (erasure_code_profile_in_use(pending_inc.new_pools, name, &ss)) | |
8227 | goto wait; | |
8228 | ||
8229 | if (erasure_code_profile_in_use(osdmap.pools, name, &ss)) { | |
8230 | err = -EBUSY; | |
8231 | goto reply; | |
8232 | } | |
8233 | ||
8234 | if (osdmap.has_erasure_code_profile(name) || | |
8235 | pending_inc.new_erasure_code_profiles.count(name)) { | |
8236 | if (osdmap.has_erasure_code_profile(name)) { | |
8237 | pending_inc.old_erasure_code_profiles.push_back(name); | |
8238 | } else { | |
8239 | dout(20) << "erasure code profile rm " << name << ": creation canceled" << dendl; | |
8240 | pending_inc.new_erasure_code_profiles.erase(name); | |
8241 | } | |
8242 | ||
8243 | getline(ss, rs); | |
8244 | wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, 0, rs, | |
8245 | get_last_committed() + 1)); | |
8246 | return true; | |
8247 | } else { | |
8248 | ss << "erasure-code-profile " << name << " does not exist"; | |
8249 | err = 0; | |
8250 | goto reply; | |
8251 | } | |
8252 | ||
8253 | } else if (prefix == "osd erasure-code-profile set") { | |
8254 | string name; | |
8255 | cmd_getval(g_ceph_context, cmdmap, "name", name); | |
8256 | vector<string> profile; | |
8257 | cmd_getval(g_ceph_context, cmdmap, "profile", profile); | |
8258 | bool force; | |
8259 | if (profile.size() > 0 && profile.back() == "--force") { | |
8260 | profile.pop_back(); | |
8261 | force = true; | |
8262 | } else { | |
8263 | force = false; | |
8264 | } | |
8265 | map<string,string> profile_map; | |
8266 | err = parse_erasure_code_profile(profile, &profile_map, &ss); | |
8267 | if (err) | |
8268 | goto reply; | |
8269 | if (profile_map.find("plugin") == profile_map.end()) { | |
8270 | ss << "erasure-code-profile " << profile_map | |
8271 | << " must contain a plugin entry" << std::endl; | |
8272 | err = -EINVAL; | |
8273 | goto reply; | |
8274 | } | |
8275 | string plugin = profile_map["plugin"]; | |
8276 | ||
8277 | if (pending_inc.has_erasure_code_profile(name)) { | |
8278 | dout(20) << "erasure code profile " << name << " try again" << dendl; | |
8279 | goto wait; | |
8280 | } else { | |
8281 | if (plugin == "isa" || plugin == "lrc") { | |
8282 | err = check_cluster_features(CEPH_FEATURE_ERASURE_CODE_PLUGINS_V2, ss); | |
8283 | if (err == -EAGAIN) | |
8284 | goto wait; | |
8285 | if (err) | |
8286 | goto reply; | |
8287 | } else if (plugin == "shec") { | |
8288 | err = check_cluster_features(CEPH_FEATURE_ERASURE_CODE_PLUGINS_V3, ss); | |
8289 | if (err == -EAGAIN) | |
8290 | goto wait; | |
8291 | if (err) | |
8292 | goto reply; | |
8293 | } | |
8294 | err = normalize_profile(name, profile_map, force, &ss); | |
8295 | if (err) | |
8296 | goto reply; | |
8297 | ||
8298 | if (osdmap.has_erasure_code_profile(name)) { | |
8299 | ErasureCodeProfile existing_profile_map = | |
8300 | osdmap.get_erasure_code_profile(name); | |
8301 | err = normalize_profile(name, existing_profile_map, force, &ss); | |
8302 | if (err) | |
8303 | goto reply; | |
8304 | ||
8305 | if (existing_profile_map == profile_map) { | |
8306 | err = 0; | |
8307 | goto reply; | |
8308 | } | |
8309 | if (!force) { | |
8310 | err = -EPERM; | |
8311 | ss << "will not override erasure code profile " << name | |
8312 | << " because the existing profile " | |
8313 | << existing_profile_map | |
8314 | << " is different from the proposed profile " | |
8315 | << profile_map; | |
8316 | goto reply; | |
8317 | } | |
8318 | } | |
8319 | ||
8320 | dout(20) << "erasure code profile set " << name << "=" | |
8321 | << profile_map << dendl; | |
8322 | pending_inc.set_erasure_code_profile(name, profile_map); | |
8323 | } | |
8324 | ||
8325 | getline(ss, rs); | |
8326 | wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, 0, rs, | |
8327 | get_last_committed() + 1)); | |
8328 | return true; | |
8329 | ||
8330 | } else if (prefix == "osd crush rule create-erasure") { | |
8331 | err = check_cluster_features(CEPH_FEATURE_CRUSH_V2, ss); | |
8332 | if (err == -EAGAIN) | |
8333 | goto wait; | |
8334 | if (err) | |
8335 | goto reply; | |
8336 | string name, poolstr; | |
8337 | cmd_getval(g_ceph_context, cmdmap, "name", name); | |
8338 | string profile; | |
8339 | cmd_getval(g_ceph_context, cmdmap, "profile", profile); | |
8340 | if (profile == "") | |
8341 | profile = "default"; | |
8342 | if (profile == "default") { | |
8343 | if (!osdmap.has_erasure_code_profile(profile)) { | |
8344 | if (pending_inc.has_erasure_code_profile(profile)) { | |
8345 | dout(20) << "erasure code profile " << profile << " already pending" << dendl; | |
8346 | goto wait; | |
8347 | } | |
8348 | ||
8349 | map<string,string> profile_map; | |
8350 | err = osdmap.get_erasure_code_profile_default(g_ceph_context, | |
8351 | profile_map, | |
8352 | &ss); | |
8353 | if (err) | |
8354 | goto reply; | |
8355 | err = normalize_profile(name, profile_map, true, &ss); | |
8356 | if (err) | |
8357 | goto reply; | |
8358 | dout(20) << "erasure code profile set " << profile << "=" | |
8359 | << profile_map << dendl; | |
8360 | pending_inc.set_erasure_code_profile(profile, profile_map); | |
8361 | goto wait; | |
8362 | } | |
8363 | } | |
8364 | ||
31f18b77 FG |
8365 | int rule; |
8366 | err = crush_rule_create_erasure(name, profile, &rule, &ss); | |
7c673cae FG |
8367 | if (err < 0) { |
8368 | switch(err) { | |
8369 | case -EEXIST: // return immediately | |
8370 | ss << "rule " << name << " already exists"; | |
8371 | err = 0; | |
8372 | goto reply; | |
8373 | break; | |
8374 | case -EALREADY: // wait for pending to be proposed | |
8375 | ss << "rule " << name << " already exists"; | |
8376 | err = 0; | |
8377 | break; | |
8378 | default: // non recoverable error | |
8379 | goto reply; | |
8380 | break; | |
8381 | } | |
8382 | } else { | |
31f18b77 | 8383 | ss << "created rule " << name << " at " << rule; |
7c673cae FG |
8384 | } |
8385 | ||
8386 | getline(ss, rs); | |
8387 | wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, 0, rs, | |
8388 | get_last_committed() + 1)); | |
8389 | return true; | |
8390 | ||
8391 | } else if (prefix == "osd crush rule rm") { | |
8392 | string name; | |
8393 | cmd_getval(g_ceph_context, cmdmap, "name", name); | |
8394 | ||
8395 | if (!osdmap.crush->rule_exists(name)) { | |
8396 | ss << "rule " << name << " does not exist"; | |
8397 | err = 0; | |
8398 | goto reply; | |
8399 | } | |
8400 | ||
8401 | CrushWrapper newcrush; | |
8402 | _get_pending_crush(newcrush); | |
8403 | ||
8404 | if (!newcrush.rule_exists(name)) { | |
8405 | ss << "rule " << name << " does not exist"; | |
8406 | err = 0; | |
8407 | } else { | |
8408 | int ruleno = newcrush.get_rule_id(name); | |
8409 | assert(ruleno >= 0); | |
8410 | ||
8411 | // make sure it is not in use. | |
8412 | // FIXME: this is ok in some situations, but let's not bother with that | |
8413 | // complexity now. | |
8414 | int ruleset = newcrush.get_rule_mask_ruleset(ruleno); | |
8415 | if (osdmap.crush_ruleset_in_use(ruleset)) { | |
8416 | ss << "crush ruleset " << name << " " << ruleset << " is in use"; | |
8417 | err = -EBUSY; | |
8418 | goto reply; | |
8419 | } | |
8420 | ||
8421 | err = newcrush.remove_rule(ruleno); | |
8422 | if (err < 0) { | |
8423 | goto reply; | |
8424 | } | |
8425 | ||
8426 | pending_inc.crush.clear(); | |
8427 | newcrush.encode(pending_inc.crush, mon->get_quorum_con_features()); | |
8428 | } | |
8429 | getline(ss, rs); | |
8430 | wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, 0, rs, | |
8431 | get_last_committed() + 1)); | |
8432 | return true; | |
8433 | ||
8434 | } else if (prefix == "osd setmaxosd") { | |
8435 | int64_t newmax; | |
8436 | if (!cmd_getval(g_ceph_context, cmdmap, "newmax", newmax)) { | |
8437 | ss << "unable to parse 'newmax' value '" | |
8438 | << cmd_vartype_stringify(cmdmap["newmax"]) << "'"; | |
8439 | err = -EINVAL; | |
8440 | goto reply; | |
8441 | } | |
8442 | ||
8443 | if (newmax > g_conf->mon_max_osd) { | |
8444 | err = -ERANGE; | |
8445 | ss << "cannot set max_osd to " << newmax << " which is > conf.mon_max_osd (" | |
8446 | << g_conf->mon_max_osd << ")"; | |
8447 | goto reply; | |
8448 | } | |
8449 | ||
8450 | // Don't allow shrinking OSD number as this will cause data loss | |
8451 | // and may cause kernel crashes. | |
8452 | // Note: setmaxosd sets the maximum OSD number and not the number of OSDs | |
8453 | if (newmax < osdmap.get_max_osd()) { | |
8454 | // Check if the OSDs exist between current max and new value. | |
8455 | // If there are any OSDs exist, then don't allow shrinking number | |
8456 | // of OSDs. | |
8457 | for (int i = newmax; i < osdmap.get_max_osd(); i++) { | |
8458 | if (osdmap.exists(i)) { | |
8459 | err = -EBUSY; | |
8460 | ss << "cannot shrink max_osd to " << newmax | |
8461 | << " because osd." << i << " (and possibly others) still in use"; | |
8462 | goto reply; | |
8463 | } | |
8464 | } | |
8465 | } | |
8466 | ||
8467 | pending_inc.new_max_osd = newmax; | |
8468 | ss << "set new max_osd = " << pending_inc.new_max_osd; | |
8469 | getline(ss, rs); | |
8470 | wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, 0, rs, | |
8471 | get_last_committed() + 1)); | |
8472 | return true; | |
8473 | ||
8474 | } else if (prefix == "osd set-full-ratio" || | |
8475 | prefix == "osd set-backfillfull-ratio" || | |
8476 | prefix == "osd set-nearfull-ratio") { | |
31f18b77 | 8477 | if (osdmap.require_osd_release < CEPH_RELEASE_LUMINOUS) { |
224ce89b WB |
8478 | ss << "you must complete the upgrade and 'ceph osd require-osd-release " |
8479 | << "luminous' before using the new interface"; | |
7c673cae FG |
8480 | err = -EPERM; |
8481 | goto reply; | |
8482 | } | |
8483 | double n; | |
8484 | if (!cmd_getval(g_ceph_context, cmdmap, "ratio", n)) { | |
8485 | ss << "unable to parse 'ratio' value '" | |
224ce89b | 8486 | << cmd_vartype_stringify(cmdmap["ratio"]) << "'"; |
7c673cae FG |
8487 | err = -EINVAL; |
8488 | goto reply; | |
8489 | } | |
8490 | if (prefix == "osd set-full-ratio") | |
8491 | pending_inc.new_full_ratio = n; | |
8492 | else if (prefix == "osd set-backfillfull-ratio") | |
8493 | pending_inc.new_backfillfull_ratio = n; | |
8494 | else if (prefix == "osd set-nearfull-ratio") | |
8495 | pending_inc.new_nearfull_ratio = n; | |
8496 | ss << prefix << " " << n; | |
8497 | getline(ss, rs); | |
8498 | wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, 0, rs, | |
8499 | get_last_committed() + 1)); | |
8500 | return true; | |
8501 | } else if (prefix == "osd set-require-min-compat-client") { | |
31f18b77 | 8502 | if (osdmap.require_osd_release < CEPH_RELEASE_LUMINOUS) { |
224ce89b WB |
8503 | ss << "you must complete the upgrade and 'ceph osd require-osd-release " |
8504 | << "luminous' before using the new interface"; | |
7c673cae FG |
8505 | err = -EPERM; |
8506 | goto reply; | |
8507 | } | |
8508 | string v; | |
8509 | cmd_getval(g_ceph_context, cmdmap, "version", v); | |
31f18b77 FG |
8510 | int vno = ceph_release_from_name(v.c_str()); |
8511 | if (vno <= 0) { | |
7c673cae FG |
8512 | ss << "version " << v << " is not recognized"; |
8513 | err = -EINVAL; | |
8514 | goto reply; | |
8515 | } | |
8516 | OSDMap newmap; | |
8517 | newmap.deepish_copy_from(osdmap); | |
8518 | newmap.apply_incremental(pending_inc); | |
31f18b77 FG |
8519 | newmap.require_min_compat_client = vno; |
8520 | auto mvno = newmap.get_min_compat_client(); | |
8521 | if (vno < mvno) { | |
8522 | ss << "osdmap current utilizes features that require " | |
8523 | << ceph_release_name(mvno) | |
8524 | << "; cannot set require_min_compat_client below that to " | |
8525 | << ceph_release_name(vno); | |
7c673cae FG |
8526 | err = -EPERM; |
8527 | goto reply; | |
8528 | } | |
31f18b77 FG |
8529 | string sure; |
8530 | cmd_getval(g_ceph_context, cmdmap, "sure", sure); | |
8531 | if (sure != "--yes-i-really-mean-it") { | |
8532 | FeatureMap m; | |
8533 | mon->get_combined_feature_map(&m); | |
8534 | uint64_t features = ceph_release_features(vno); | |
8535 | bool first = true; | |
8536 | bool ok = true; | |
8537 | for (int type : { | |
8538 | CEPH_ENTITY_TYPE_CLIENT, | |
8539 | CEPH_ENTITY_TYPE_MDS, | |
8540 | CEPH_ENTITY_TYPE_MGR }) { | |
8541 | auto p = m.m.find(type); | |
8542 | if (p == m.m.end()) { | |
8543 | continue; | |
8544 | } | |
8545 | for (auto& q : p->second) { | |
8546 | uint64_t missing = ~q.first & features; | |
8547 | if (missing) { | |
8548 | if (first) { | |
8549 | ss << "cannot set require_min_compat_client to " << v << ": "; | |
8550 | } else { | |
8551 | ss << "; "; | |
8552 | } | |
8553 | first = false; | |
8554 | ss << q.second << " connected " << ceph_entity_type_name(type) | |
8555 | << "(s) look like " << ceph_release_name( | |
8556 | ceph_release_from_features(q.first)) | |
8557 | << " (missing 0x" << std::hex << missing << std::dec << ")"; | |
8558 | ok = false; | |
8559 | } | |
8560 | } | |
8561 | } | |
8562 | if (!ok) { | |
8563 | ss << "; add --yes-i-really-mean-it to do it anyway"; | |
8564 | err = -EPERM; | |
8565 | goto reply; | |
8566 | } | |
8567 | } | |
8568 | ss << "set require_min_compat_client to " << ceph_release_name(vno); | |
8569 | pending_inc.new_require_min_compat_client = vno; | |
7c673cae FG |
8570 | getline(ss, rs); |
8571 | wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, 0, rs, | |
8572 | get_last_committed() + 1)); | |
8573 | return true; | |
8574 | } else if (prefix == "osd pause") { | |
8575 | return prepare_set_flag(op, CEPH_OSDMAP_PAUSERD | CEPH_OSDMAP_PAUSEWR); | |
8576 | ||
8577 | } else if (prefix == "osd unpause") { | |
8578 | return prepare_unset_flag(op, CEPH_OSDMAP_PAUSERD | CEPH_OSDMAP_PAUSEWR); | |
8579 | ||
8580 | } else if (prefix == "osd set") { | |
8581 | string key; | |
8582 | cmd_getval(g_ceph_context, cmdmap, "key", key); | |
8583 | if (key == "full") | |
8584 | return prepare_set_flag(op, CEPH_OSDMAP_FULL); | |
8585 | else if (key == "pause") | |
8586 | return prepare_set_flag(op, CEPH_OSDMAP_PAUSERD | CEPH_OSDMAP_PAUSEWR); | |
8587 | else if (key == "noup") | |
8588 | return prepare_set_flag(op, CEPH_OSDMAP_NOUP); | |
8589 | else if (key == "nodown") | |
8590 | return prepare_set_flag(op, CEPH_OSDMAP_NODOWN); | |
8591 | else if (key == "noout") | |
8592 | return prepare_set_flag(op, CEPH_OSDMAP_NOOUT); | |
8593 | else if (key == "noin") | |
8594 | return prepare_set_flag(op, CEPH_OSDMAP_NOIN); | |
8595 | else if (key == "nobackfill") | |
8596 | return prepare_set_flag(op, CEPH_OSDMAP_NOBACKFILL); | |
8597 | else if (key == "norebalance") | |
8598 | return prepare_set_flag(op, CEPH_OSDMAP_NOREBALANCE); | |
8599 | else if (key == "norecover") | |
8600 | return prepare_set_flag(op, CEPH_OSDMAP_NORECOVER); | |
8601 | else if (key == "noscrub") | |
8602 | return prepare_set_flag(op, CEPH_OSDMAP_NOSCRUB); | |
8603 | else if (key == "nodeep-scrub") | |
8604 | return prepare_set_flag(op, CEPH_OSDMAP_NODEEP_SCRUB); | |
8605 | else if (key == "notieragent") | |
8606 | return prepare_set_flag(op, CEPH_OSDMAP_NOTIERAGENT); | |
8607 | else if (key == "sortbitwise") { | |
8608 | if (osdmap.get_up_osd_features() & CEPH_FEATURE_OSD_BITWISE_HOBJ_SORT) { | |
8609 | return prepare_set_flag(op, CEPH_OSDMAP_SORTBITWISE); | |
8610 | } else { | |
8611 | ss << "not all up OSDs have OSD_BITWISE_HOBJ_SORT feature"; | |
8612 | err = -EPERM; | |
31f18b77 | 8613 | goto reply; |
7c673cae | 8614 | } |
c07f9fc5 FG |
8615 | } else if (key == "recovery_deletes") { |
8616 | if (HAVE_FEATURE(osdmap.get_up_osd_features(), OSD_RECOVERY_DELETES)) { | |
8617 | return prepare_set_flag(op, CEPH_OSDMAP_RECOVERY_DELETES); | |
8618 | } else { | |
8619 | ss << "not all up OSDs have OSD_RECOVERY_DELETES feature"; | |
8620 | err = -EPERM; | |
8621 | goto reply; | |
8622 | } | |
7c673cae FG |
8623 | } else if (key == "require_jewel_osds") { |
8624 | if (!osdmap.test_flag(CEPH_OSDMAP_SORTBITWISE)) { | |
8625 | ss << "the sortbitwise flag must be set before require_jewel_osds"; | |
8626 | err = -EPERM; | |
31f18b77 FG |
8627 | goto reply; |
8628 | } else if (osdmap.require_osd_release >= CEPH_RELEASE_JEWEL) { | |
8629 | ss << "require_osd_release is already >= jewel"; | |
8630 | err = 0; | |
8631 | goto reply; | |
7c673cae FG |
8632 | } else if (HAVE_FEATURE(osdmap.get_up_osd_features(), SERVER_JEWEL)) { |
8633 | return prepare_set_flag(op, CEPH_OSDMAP_REQUIRE_JEWEL); | |
8634 | } else { | |
8635 | ss << "not all up OSDs have CEPH_FEATURE_SERVER_JEWEL feature"; | |
8636 | err = -EPERM; | |
8637 | } | |
8638 | } else if (key == "require_kraken_osds") { | |
8639 | if (!osdmap.test_flag(CEPH_OSDMAP_SORTBITWISE)) { | |
8640 | ss << "the sortbitwise flag must be set before require_kraken_osds"; | |
8641 | err = -EPERM; | |
31f18b77 FG |
8642 | goto reply; |
8643 | } else if (osdmap.require_osd_release >= CEPH_RELEASE_KRAKEN) { | |
8644 | ss << "require_osd_release is already >= kraken"; | |
8645 | err = 0; | |
8646 | goto reply; | |
7c673cae FG |
8647 | } else if (HAVE_FEATURE(osdmap.get_up_osd_features(), SERVER_KRAKEN)) { |
8648 | bool r = prepare_set_flag(op, CEPH_OSDMAP_REQUIRE_KRAKEN); | |
8649 | // ensure JEWEL is also set | |
8650 | pending_inc.new_flags |= CEPH_OSDMAP_REQUIRE_JEWEL; | |
8651 | return r; | |
8652 | } else { | |
8653 | ss << "not all up OSDs have CEPH_FEATURE_SERVER_KRAKEN feature"; | |
8654 | err = -EPERM; | |
8655 | } | |
7c673cae FG |
8656 | } else { |
8657 | ss << "unrecognized flag '" << key << "'"; | |
8658 | err = -EINVAL; | |
8659 | } | |
8660 | ||
8661 | } else if (prefix == "osd unset") { | |
8662 | string key; | |
8663 | cmd_getval(g_ceph_context, cmdmap, "key", key); | |
8664 | if (key == "full") | |
8665 | return prepare_unset_flag(op, CEPH_OSDMAP_FULL); | |
8666 | else if (key == "pause") | |
8667 | return prepare_unset_flag(op, CEPH_OSDMAP_PAUSERD | CEPH_OSDMAP_PAUSEWR); | |
8668 | else if (key == "noup") | |
8669 | return prepare_unset_flag(op, CEPH_OSDMAP_NOUP); | |
8670 | else if (key == "nodown") | |
8671 | return prepare_unset_flag(op, CEPH_OSDMAP_NODOWN); | |
8672 | else if (key == "noout") | |
8673 | return prepare_unset_flag(op, CEPH_OSDMAP_NOOUT); | |
8674 | else if (key == "noin") | |
8675 | return prepare_unset_flag(op, CEPH_OSDMAP_NOIN); | |
8676 | else if (key == "nobackfill") | |
8677 | return prepare_unset_flag(op, CEPH_OSDMAP_NOBACKFILL); | |
8678 | else if (key == "norebalance") | |
8679 | return prepare_unset_flag(op, CEPH_OSDMAP_NOREBALANCE); | |
8680 | else if (key == "norecover") | |
8681 | return prepare_unset_flag(op, CEPH_OSDMAP_NORECOVER); | |
8682 | else if (key == "noscrub") | |
8683 | return prepare_unset_flag(op, CEPH_OSDMAP_NOSCRUB); | |
8684 | else if (key == "nodeep-scrub") | |
8685 | return prepare_unset_flag(op, CEPH_OSDMAP_NODEEP_SCRUB); | |
8686 | else if (key == "notieragent") | |
8687 | return prepare_unset_flag(op, CEPH_OSDMAP_NOTIERAGENT); | |
224ce89b | 8688 | else { |
7c673cae FG |
8689 | ss << "unrecognized flag '" << key << "'"; |
8690 | err = -EINVAL; | |
8691 | } | |
8692 | ||
31f18b77 FG |
8693 | } else if (prefix == "osd require-osd-release") { |
8694 | string release; | |
8695 | cmd_getval(g_ceph_context, cmdmap, "release", release); | |
8696 | if (!osdmap.test_flag(CEPH_OSDMAP_SORTBITWISE)) { | |
8697 | ss << "the sortbitwise flag must be set first"; | |
8698 | err = -EPERM; | |
8699 | goto reply; | |
8700 | } | |
8701 | int rel = ceph_release_from_name(release.c_str()); | |
8702 | if (rel <= 0) { | |
8703 | ss << "unrecognized release " << release; | |
8704 | err = -EINVAL; | |
8705 | goto reply; | |
8706 | } | |
8707 | if (rel < CEPH_RELEASE_LUMINOUS) { | |
8708 | ss << "use this command only for luminous and later"; | |
8709 | err = -EINVAL; | |
8710 | goto reply; | |
8711 | } | |
d2e6a577 FG |
8712 | if (rel == osdmap.require_osd_release) { |
8713 | // idempotent | |
8714 | err = 0; | |
8715 | goto reply; | |
8716 | } | |
31f18b77 FG |
8717 | if (rel == CEPH_RELEASE_LUMINOUS) { |
8718 | if (!HAVE_FEATURE(osdmap.get_up_osd_features(), SERVER_LUMINOUS)) { | |
8719 | ss << "not all up OSDs have CEPH_FEATURE_SERVER_LUMINOUS feature"; | |
8720 | err = -EPERM; | |
8721 | goto reply; | |
8722 | } | |
8723 | } else { | |
8724 | ss << "not supported for this release yet"; | |
8725 | err = -EPERM; | |
8726 | goto reply; | |
8727 | } | |
8728 | if (rel < osdmap.require_osd_release) { | |
8729 | ss << "require_osd_release cannot be lowered once it has been set"; | |
8730 | err = -EPERM; | |
8731 | goto reply; | |
8732 | } | |
8733 | pending_inc.new_require_osd_release = rel; | |
c07f9fc5 FG |
8734 | if (rel >= CEPH_RELEASE_LUMINOUS && |
8735 | !osdmap.test_flag(CEPH_OSDMAP_RECOVERY_DELETES)) { | |
8736 | return prepare_set_flag(op, CEPH_OSDMAP_RECOVERY_DELETES); | |
8737 | } | |
31f18b77 | 8738 | goto update; |
7c673cae FG |
8739 | } else if (prefix == "osd cluster_snap") { |
8740 | // ** DISABLE THIS FOR NOW ** | |
8741 | ss << "cluster snapshot currently disabled (broken implementation)"; | |
8742 | // ** DISABLE THIS FOR NOW ** | |
8743 | ||
8744 | } else if (prefix == "osd down" || | |
8745 | prefix == "osd out" || | |
8746 | prefix == "osd in" || | |
8747 | prefix == "osd rm") { | |
8748 | ||
8749 | bool any = false; | |
31f18b77 FG |
8750 | bool stop = false; |
8751 | bool verbose = true; | |
7c673cae FG |
8752 | |
8753 | vector<string> idvec; | |
8754 | cmd_getval(g_ceph_context, cmdmap, "ids", idvec); | |
31f18b77 FG |
8755 | for (unsigned j = 0; j < idvec.size() && !stop; j++) { |
8756 | set<int> osds; | |
8757 | ||
8758 | // wildcard? | |
8759 | if (j == 0 && | |
8760 | (idvec[0] == "any" || idvec[0] == "all" || idvec[0] == "*")) { | |
8761 | if (prefix == "osd in") { | |
8762 | // touch out osds only | |
8763 | osdmap.get_out_osds(osds); | |
8764 | } else { | |
8765 | osdmap.get_all_osds(osds); | |
8766 | } | |
8767 | stop = true; | |
8768 | verbose = false; // so the output is less noisy. | |
8769 | } else { | |
8770 | long osd = parse_osd_id(idvec[j].c_str(), &ss); | |
8771 | if (osd < 0) { | |
8772 | ss << "invalid osd id" << osd; | |
8773 | err = -EINVAL; | |
8774 | continue; | |
8775 | } else if (!osdmap.exists(osd)) { | |
8776 | ss << "osd." << osd << " does not exist. "; | |
8777 | continue; | |
8778 | } | |
8779 | ||
8780 | osds.insert(osd); | |
7c673cae | 8781 | } |
31f18b77 FG |
8782 | |
8783 | for (auto &osd : osds) { | |
8784 | if (prefix == "osd down") { | |
8785 | if (osdmap.is_down(osd)) { | |
8786 | if (verbose) | |
8787 | ss << "osd." << osd << " is already down. "; | |
8788 | } else { | |
8789 | pending_inc.pending_osd_state_set(osd, CEPH_OSD_UP); | |
8790 | ss << "marked down osd." << osd << ". "; | |
8791 | any = true; | |
8792 | } | |
8793 | } else if (prefix == "osd out") { | |
8794 | if (osdmap.is_out(osd)) { | |
8795 | if (verbose) | |
8796 | ss << "osd." << osd << " is already out. "; | |
8797 | } else { | |
8798 | pending_inc.new_weight[osd] = CEPH_OSD_OUT; | |
8799 | if (osdmap.osd_weight[osd]) { | |
8800 | if (pending_inc.new_xinfo.count(osd) == 0) { | |
8801 | pending_inc.new_xinfo[osd] = osdmap.osd_xinfo[osd]; | |
8802 | } | |
8803 | pending_inc.new_xinfo[osd].old_weight = osdmap.osd_weight[osd]; | |
7c673cae | 8804 | } |
31f18b77 | 8805 | ss << "marked out osd." << osd << ". "; |
224ce89b WB |
8806 | std::ostringstream msg; |
8807 | msg << "Client " << op->get_session()->entity_name | |
8808 | << " marked osd." << osd << " out"; | |
8809 | if (osdmap.is_up(osd)) { | |
8810 | msg << ", while it was still marked up"; | |
8811 | } else { | |
8812 | msg << ", after it was down for " << int(down_pending_out[osd].sec()) | |
8813 | << " seconds"; | |
8814 | } | |
8815 | ||
8816 | mon->clog->info() << msg.str(); | |
31f18b77 | 8817 | any = true; |
7c673cae | 8818 | } |
31f18b77 FG |
8819 | } else if (prefix == "osd in") { |
8820 | if (osdmap.is_in(osd)) { | |
8821 | if (verbose) | |
8822 | ss << "osd." << osd << " is already in. "; | |
8823 | } else { | |
8824 | if (osdmap.osd_xinfo[osd].old_weight > 0) { | |
8825 | pending_inc.new_weight[osd] = osdmap.osd_xinfo[osd].old_weight; | |
8826 | if (pending_inc.new_xinfo.count(osd) == 0) { | |
8827 | pending_inc.new_xinfo[osd] = osdmap.osd_xinfo[osd]; | |
8828 | } | |
8829 | pending_inc.new_xinfo[osd].old_weight = 0; | |
8830 | } else { | |
8831 | pending_inc.new_weight[osd] = CEPH_OSD_IN; | |
7c673cae | 8832 | } |
31f18b77 FG |
8833 | ss << "marked in osd." << osd << ". "; |
8834 | any = true; | |
8835 | } | |
8836 | } else if (prefix == "osd rm") { | |
8837 | err = prepare_command_osd_remove(osd); | |
8838 | ||
8839 | if (err == -EBUSY) { | |
8840 | if (any) | |
8841 | ss << ", "; | |
8842 | ss << "osd." << osd << " is still up; must be down before removal. "; | |
7c673cae | 8843 | } else { |
31f18b77 FG |
8844 | assert(err == 0); |
8845 | if (any) { | |
8846 | ss << ", osd." << osd; | |
8847 | } else { | |
8848 | ss << "removed osd." << osd; | |
8849 | } | |
8850 | any = true; | |
7c673cae | 8851 | } |
31f18b77 FG |
8852 | } |
8853 | } | |
8854 | } | |
8855 | if (any) { | |
8856 | getline(ss, rs); | |
8857 | wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, err, rs, | |
8858 | get_last_committed() + 1)); | |
8859 | return true; | |
8860 | } | |
8861 | } else if (prefix == "osd add-noup" || | |
8862 | prefix == "osd add-nodown" || | |
8863 | prefix == "osd add-noin" || | |
8864 | prefix == "osd add-noout") { | |
8865 | ||
8866 | enum { | |
8867 | OP_NOUP, | |
8868 | OP_NODOWN, | |
8869 | OP_NOIN, | |
8870 | OP_NOOUT, | |
8871 | } option; | |
8872 | ||
8873 | if (prefix == "osd add-noup") { | |
8874 | option = OP_NOUP; | |
8875 | } else if (prefix == "osd add-nodown") { | |
8876 | option = OP_NODOWN; | |
8877 | } else if (prefix == "osd add-noin") { | |
8878 | option = OP_NOIN; | |
8879 | } else { | |
8880 | option = OP_NOOUT; | |
8881 | } | |
8882 | ||
8883 | bool any = false; | |
8884 | bool stop = false; | |
8885 | ||
8886 | vector<string> idvec; | |
8887 | cmd_getval(g_ceph_context, cmdmap, "ids", idvec); | |
8888 | for (unsigned j = 0; j < idvec.size() && !stop; j++) { | |
8889 | ||
8890 | set<int> osds; | |
8891 | ||
8892 | // wildcard? | |
8893 | if (j == 0 && | |
8894 | (idvec[0] == "any" || idvec[0] == "all" || idvec[0] == "*")) { | |
8895 | osdmap.get_all_osds(osds); | |
8896 | stop = true; | |
8897 | } else { | |
8898 | // try traditional single osd way | |
8899 | ||
8900 | long osd = parse_osd_id(idvec[j].c_str(), &ss); | |
8901 | if (osd < 0) { | |
8902 | // ss has reason for failure | |
8903 | ss << ", unable to parse osd id:\"" << idvec[j] << "\". "; | |
8904 | err = -EINVAL; | |
8905 | continue; | |
8906 | } | |
8907 | ||
8908 | osds.insert(osd); | |
8909 | } | |
8910 | ||
8911 | for (auto &osd : osds) { | |
8912 | ||
8913 | if (!osdmap.exists(osd)) { | |
8914 | ss << "osd." << osd << " does not exist. "; | |
8915 | continue; | |
8916 | } | |
8917 | ||
8918 | switch (option) { | |
8919 | case OP_NOUP: | |
8920 | if (osdmap.is_up(osd)) { | |
8921 | ss << "osd." << osd << " is already up. "; | |
8922 | continue; | |
8923 | } | |
8924 | ||
8925 | if (osdmap.is_noup(osd)) { | |
8926 | if (pending_inc.pending_osd_state_clear(osd, CEPH_OSD_NOUP)) | |
8927 | any = true; | |
7c673cae | 8928 | } else { |
31f18b77 FG |
8929 | pending_inc.pending_osd_state_set(osd, CEPH_OSD_NOUP); |
8930 | any = true; | |
7c673cae | 8931 | } |
31f18b77 FG |
8932 | |
8933 | break; | |
8934 | ||
8935 | case OP_NODOWN: | |
8936 | if (osdmap.is_down(osd)) { | |
8937 | ss << "osd." << osd << " is already down. "; | |
8938 | continue; | |
8939 | } | |
8940 | ||
8941 | if (osdmap.is_nodown(osd)) { | |
8942 | if (pending_inc.pending_osd_state_clear(osd, CEPH_OSD_NODOWN)) | |
8943 | any = true; | |
8944 | } else { | |
8945 | pending_inc.pending_osd_state_set(osd, CEPH_OSD_NODOWN); | |
8946 | any = true; | |
8947 | } | |
8948 | ||
8949 | break; | |
8950 | ||
8951 | case OP_NOIN: | |
8952 | if (osdmap.is_in(osd)) { | |
8953 | ss << "osd." << osd << " is already in. "; | |
8954 | continue; | |
8955 | } | |
8956 | ||
8957 | if (osdmap.is_noin(osd)) { | |
8958 | if (pending_inc.pending_osd_state_clear(osd, CEPH_OSD_NOIN)) | |
8959 | any = true; | |
8960 | } else { | |
8961 | pending_inc.pending_osd_state_set(osd, CEPH_OSD_NOIN); | |
8962 | any = true; | |
8963 | } | |
8964 | ||
8965 | break; | |
8966 | ||
8967 | case OP_NOOUT: | |
8968 | if (osdmap.is_out(osd)) { | |
8969 | ss << "osd." << osd << " is already out. "; | |
8970 | continue; | |
8971 | } | |
8972 | ||
8973 | if (osdmap.is_noout(osd)) { | |
8974 | if (pending_inc.pending_osd_state_clear(osd, CEPH_OSD_NOOUT)) | |
8975 | any = true; | |
8976 | } else { | |
8977 | pending_inc.pending_osd_state_set(osd, CEPH_OSD_NOOUT); | |
8978 | any = true; | |
8979 | } | |
8980 | ||
8981 | break; | |
8982 | ||
8983 | default: | |
8984 | assert(0 == "invalid option"); | |
8985 | } | |
7c673cae FG |
8986 | } |
8987 | } | |
31f18b77 | 8988 | |
7c673cae FG |
8989 | if (any) { |
8990 | getline(ss, rs); | |
8991 | wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, err, rs, | |
31f18b77 FG |
8992 | get_last_committed() + 1)); |
8993 | return true; | |
8994 | } | |
8995 | } else if (prefix == "osd rm-noup" || | |
8996 | prefix == "osd rm-nodown" || | |
8997 | prefix == "osd rm-noin" || | |
8998 | prefix == "osd rm-noout") { | |
8999 | ||
9000 | enum { | |
9001 | OP_NOUP, | |
9002 | OP_NODOWN, | |
9003 | OP_NOIN, | |
9004 | OP_NOOUT, | |
9005 | } option; | |
9006 | ||
9007 | if (prefix == "osd rm-noup") { | |
9008 | option = OP_NOUP; | |
9009 | } else if (prefix == "osd rm-nodown") { | |
9010 | option = OP_NODOWN; | |
9011 | } else if (prefix == "osd rm-noin") { | |
9012 | option = OP_NOIN; | |
9013 | } else { | |
9014 | option = OP_NOOUT; | |
9015 | } | |
9016 | ||
9017 | bool any = false; | |
9018 | bool stop = false; | |
9019 | ||
9020 | vector<string> idvec; | |
9021 | cmd_getval(g_ceph_context, cmdmap, "ids", idvec); | |
9022 | ||
9023 | for (unsigned j = 0; j < idvec.size() && !stop; j++) { | |
9024 | ||
9025 | vector<int> osds; | |
9026 | ||
9027 | // wildcard? | |
9028 | if (j == 0 && | |
9029 | (idvec[0] == "any" || idvec[0] == "all" || idvec[0] == "*")) { | |
9030 | ||
9031 | // touch previous noup/nodown/noin/noout osds only | |
9032 | switch (option) { | |
9033 | case OP_NOUP: | |
9034 | osdmap.get_noup_osds(&osds); | |
9035 | break; | |
9036 | case OP_NODOWN: | |
9037 | osdmap.get_nodown_osds(&osds); | |
9038 | break; | |
9039 | case OP_NOIN: | |
9040 | osdmap.get_noin_osds(&osds); | |
9041 | break; | |
9042 | case OP_NOOUT: | |
9043 | osdmap.get_noout_osds(&osds); | |
9044 | break; | |
9045 | default: | |
9046 | assert(0 == "invalid option"); | |
9047 | } | |
9048 | ||
9049 | // cancel any pending noup/nodown/noin/noout requests too | |
9050 | vector<int> pending_state_osds; | |
9051 | (void) pending_inc.get_pending_state_osds(&pending_state_osds); | |
9052 | for (auto &p : pending_state_osds) { | |
9053 | ||
9054 | switch (option) { | |
9055 | case OP_NOUP: | |
9056 | if (!osdmap.is_noup(p) && | |
9057 | pending_inc.pending_osd_state_clear(p, CEPH_OSD_NOUP)) { | |
9058 | any = true; | |
9059 | } | |
9060 | break; | |
9061 | ||
9062 | case OP_NODOWN: | |
9063 | if (!osdmap.is_nodown(p) && | |
9064 | pending_inc.pending_osd_state_clear(p, CEPH_OSD_NODOWN)) { | |
9065 | any = true; | |
9066 | } | |
9067 | break; | |
9068 | ||
9069 | case OP_NOIN: | |
9070 | if (!osdmap.is_noin(p) && | |
9071 | pending_inc.pending_osd_state_clear(p, CEPH_OSD_NOIN)) { | |
9072 | any = true; | |
9073 | } | |
9074 | break; | |
9075 | ||
9076 | case OP_NOOUT: | |
9077 | if (!osdmap.is_noout(p) && | |
9078 | pending_inc.pending_osd_state_clear(p, CEPH_OSD_NOOUT)) { | |
9079 | any = true; | |
9080 | } | |
9081 | break; | |
9082 | ||
9083 | default: | |
9084 | assert(0 == "invalid option"); | |
9085 | } | |
9086 | } | |
9087 | ||
9088 | stop = true; | |
9089 | } else { | |
9090 | // try traditional single osd way | |
9091 | ||
9092 | long osd = parse_osd_id(idvec[j].c_str(), &ss); | |
9093 | if (osd < 0) { | |
9094 | // ss has reason for failure | |
9095 | ss << ", unable to parse osd id:\"" << idvec[j] << "\". "; | |
9096 | err = -EINVAL; | |
9097 | continue; | |
9098 | } | |
9099 | ||
9100 | osds.push_back(osd); | |
9101 | } | |
9102 | ||
9103 | for (auto &osd : osds) { | |
9104 | ||
9105 | if (!osdmap.exists(osd)) { | |
9106 | ss << "osd." << osd << " does not exist. "; | |
9107 | continue; | |
9108 | } | |
9109 | ||
9110 | switch (option) { | |
9111 | case OP_NOUP: | |
9112 | if (osdmap.is_noup(osd)) { | |
9113 | pending_inc.pending_osd_state_set(osd, CEPH_OSD_NOUP); | |
9114 | any = true; | |
9115 | } else if (pending_inc.pending_osd_state_clear( | |
9116 | osd, CEPH_OSD_NOUP)) { | |
9117 | any = true; | |
9118 | } | |
9119 | break; | |
9120 | ||
9121 | case OP_NODOWN: | |
9122 | if (osdmap.is_nodown(osd)) { | |
9123 | pending_inc.pending_osd_state_set(osd, CEPH_OSD_NODOWN); | |
9124 | any = true; | |
9125 | } else if (pending_inc.pending_osd_state_clear( | |
9126 | osd, CEPH_OSD_NODOWN)) { | |
9127 | any = true; | |
9128 | } | |
9129 | break; | |
9130 | ||
9131 | case OP_NOIN: | |
9132 | if (osdmap.is_noin(osd)) { | |
9133 | pending_inc.pending_osd_state_set(osd, CEPH_OSD_NOIN); | |
9134 | any = true; | |
9135 | } else if (pending_inc.pending_osd_state_clear( | |
9136 | osd, CEPH_OSD_NOIN)) { | |
9137 | any = true; | |
9138 | } | |
9139 | break; | |
9140 | ||
9141 | case OP_NOOUT: | |
9142 | if (osdmap.is_noout(osd)) { | |
9143 | pending_inc.pending_osd_state_set(osd, CEPH_OSD_NOOUT); | |
9144 | any = true; | |
9145 | } else if (pending_inc.pending_osd_state_clear( | |
9146 | osd, CEPH_OSD_NOOUT)) { | |
9147 | any = true; | |
9148 | } | |
9149 | break; | |
9150 | ||
9151 | default: | |
9152 | assert(0 == "invalid option"); | |
9153 | } | |
9154 | } | |
9155 | } | |
9156 | ||
9157 | if (any) { | |
9158 | getline(ss, rs); | |
9159 | wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, err, rs, | |
9160 | get_last_committed() + 1)); | |
7c673cae FG |
9161 | return true; |
9162 | } | |
9163 | } else if (prefix == "osd pg-temp") { | |
9164 | string pgidstr; | |
9165 | if (!cmd_getval(g_ceph_context, cmdmap, "pgid", pgidstr)) { | |
9166 | ss << "unable to parse 'pgid' value '" | |
9167 | << cmd_vartype_stringify(cmdmap["pgid"]) << "'"; | |
9168 | err = -EINVAL; | |
9169 | goto reply; | |
9170 | } | |
9171 | pg_t pgid; | |
9172 | if (!pgid.parse(pgidstr.c_str())) { | |
9173 | ss << "invalid pgid '" << pgidstr << "'"; | |
9174 | err = -EINVAL; | |
9175 | goto reply; | |
9176 | } | |
9177 | if (!osdmap.pg_exists(pgid)) { | |
9178 | ss << "pg " << pgid << " does not exist"; | |
9179 | err = -ENOENT; | |
9180 | goto reply; | |
9181 | } | |
9182 | if (pending_inc.new_pg_temp.count(pgid)) { | |
9183 | dout(10) << __func__ << " waiting for pending update on " << pgid << dendl; | |
9184 | wait_for_finished_proposal(op, new C_RetryMessage(this, op)); | |
9185 | return true; | |
9186 | } | |
9187 | ||
9188 | vector<int64_t> id_vec; | |
9189 | vector<int32_t> new_pg_temp; | |
9190 | if (!cmd_getval(g_ceph_context, cmdmap, "id", id_vec)) { | |
9191 | ss << "unable to parse 'id' value(s) '" | |
9192 | << cmd_vartype_stringify(cmdmap["id"]) << "'"; | |
9193 | err = -EINVAL; | |
9194 | goto reply; | |
9195 | } | |
9196 | for (auto osd : id_vec) { | |
9197 | if (!osdmap.exists(osd)) { | |
9198 | ss << "osd." << osd << " does not exist"; | |
9199 | err = -ENOENT; | |
9200 | goto reply; | |
9201 | } | |
9202 | new_pg_temp.push_back(osd); | |
9203 | } | |
9204 | ||
224ce89b WB |
9205 | int pool_min_size = osdmap.get_pg_pool_min_size(pgid); |
9206 | if ((int)new_pg_temp.size() < pool_min_size) { | |
9207 | ss << "num of osds (" << new_pg_temp.size() <<") < pool min size (" | |
9208 | << pool_min_size << ")"; | |
9209 | err = -EINVAL; | |
9210 | goto reply; | |
9211 | } | |
9212 | ||
9213 | int pool_size = osdmap.get_pg_pool_size(pgid); | |
9214 | if ((int)new_pg_temp.size() > pool_size) { | |
9215 | ss << "num of osds (" << new_pg_temp.size() <<") > pool size (" | |
9216 | << pool_size << ")"; | |
9217 | err = -EINVAL; | |
9218 | goto reply; | |
9219 | } | |
9220 | ||
7c673cae FG |
9221 | pending_inc.new_pg_temp[pgid] = mempool::osdmap::vector<int>( |
9222 | new_pg_temp.begin(), new_pg_temp.end()); | |
9223 | ss << "set " << pgid << " pg_temp mapping to " << new_pg_temp; | |
9224 | goto update; | |
9225 | } else if (prefix == "osd primary-temp") { | |
9226 | string pgidstr; | |
9227 | if (!cmd_getval(g_ceph_context, cmdmap, "pgid", pgidstr)) { | |
9228 | ss << "unable to parse 'pgid' value '" | |
9229 | << cmd_vartype_stringify(cmdmap["pgid"]) << "'"; | |
9230 | err = -EINVAL; | |
9231 | goto reply; | |
9232 | } | |
9233 | pg_t pgid; | |
9234 | if (!pgid.parse(pgidstr.c_str())) { | |
9235 | ss << "invalid pgid '" << pgidstr << "'"; | |
9236 | err = -EINVAL; | |
9237 | goto reply; | |
9238 | } | |
9239 | if (!osdmap.pg_exists(pgid)) { | |
9240 | ss << "pg " << pgid << " does not exist"; | |
9241 | err = -ENOENT; | |
9242 | goto reply; | |
9243 | } | |
9244 | ||
9245 | int64_t osd; | |
9246 | if (!cmd_getval(g_ceph_context, cmdmap, "id", osd)) { | |
9247 | ss << "unable to parse 'id' value '" | |
9248 | << cmd_vartype_stringify(cmdmap["id"]) << "'"; | |
9249 | err = -EINVAL; | |
9250 | goto reply; | |
9251 | } | |
9252 | if (osd != -1 && !osdmap.exists(osd)) { | |
9253 | ss << "osd." << osd << " does not exist"; | |
9254 | err = -ENOENT; | |
9255 | goto reply; | |
9256 | } | |
9257 | ||
31f18b77 FG |
9258 | if (osdmap.require_min_compat_client > 0 && |
9259 | osdmap.require_min_compat_client < CEPH_RELEASE_FIREFLY) { | |
9260 | ss << "require_min_compat_client " | |
9261 | << ceph_release_name(osdmap.require_min_compat_client) | |
7c673cae FG |
9262 | << " < firefly, which is required for primary-temp"; |
9263 | err = -EPERM; | |
9264 | goto reply; | |
9265 | } else if (!g_conf->mon_osd_allow_primary_temp) { | |
9266 | ss << "you must enable 'mon osd allow primary temp = true' on the mons before you can set primary_temp mappings. note that this is for developers only: older clients/OSDs will break and there is no feature bit infrastructure in place."; | |
9267 | err = -EPERM; | |
9268 | goto reply; | |
9269 | } | |
9270 | ||
9271 | pending_inc.new_primary_temp[pgid] = osd; | |
9272 | ss << "set " << pgid << " primary_temp mapping to " << osd; | |
9273 | goto update; | |
224ce89b WB |
9274 | } else if (prefix == "osd pg-upmap" || |
9275 | prefix == "osd rm-pg-upmap" || | |
9276 | prefix == "osd pg-upmap-items" || | |
9277 | prefix == "osd rm-pg-upmap-items") { | |
31f18b77 | 9278 | if (osdmap.require_osd_release < CEPH_RELEASE_LUMINOUS) { |
224ce89b WB |
9279 | ss << "you must complete the upgrade and 'ceph osd require-osd-release " |
9280 | << "luminous' before using the new interface"; | |
7c673cae FG |
9281 | err = -EPERM; |
9282 | goto reply; | |
9283 | } | |
31f18b77 FG |
9284 | if (osdmap.require_min_compat_client < CEPH_RELEASE_LUMINOUS) { |
9285 | ss << "min_compat_client " | |
9286 | << ceph_release_name(osdmap.require_min_compat_client) | |
224ce89b WB |
9287 | << " < luminous, which is required for pg-upmap. " |
9288 | << "Try 'ceph osd set-require-min-compat-client luminous' " | |
9289 | << "before using the new interface"; | |
7c673cae FG |
9290 | err = -EPERM; |
9291 | goto reply; | |
9292 | } | |
9293 | err = check_cluster_features(CEPH_FEATUREMASK_OSDMAP_PG_UPMAP, ss); | |
9294 | if (err == -EAGAIN) | |
9295 | goto wait; | |
9296 | if (err < 0) | |
9297 | goto reply; | |
9298 | string pgidstr; | |
9299 | if (!cmd_getval(g_ceph_context, cmdmap, "pgid", pgidstr)) { | |
9300 | ss << "unable to parse 'pgid' value '" | |
9301 | << cmd_vartype_stringify(cmdmap["pgid"]) << "'"; | |
9302 | err = -EINVAL; | |
9303 | goto reply; | |
9304 | } | |
9305 | pg_t pgid; | |
9306 | if (!pgid.parse(pgidstr.c_str())) { | |
9307 | ss << "invalid pgid '" << pgidstr << "'"; | |
9308 | err = -EINVAL; | |
9309 | goto reply; | |
9310 | } | |
9311 | if (!osdmap.pg_exists(pgid)) { | |
9312 | ss << "pg " << pgid << " does not exist"; | |
9313 | err = -ENOENT; | |
9314 | goto reply; | |
9315 | } | |
224ce89b WB |
9316 | |
9317 | enum { | |
9318 | OP_PG_UPMAP, | |
9319 | OP_RM_PG_UPMAP, | |
9320 | OP_PG_UPMAP_ITEMS, | |
9321 | OP_RM_PG_UPMAP_ITEMS, | |
9322 | } option; | |
9323 | ||
9324 | if (prefix == "osd pg-upmap") { | |
9325 | option = OP_PG_UPMAP; | |
9326 | } else if (prefix == "osd rm-pg-upmap") { | |
9327 | option = OP_RM_PG_UPMAP; | |
9328 | } else if (prefix == "osd pg-upmap-items") { | |
9329 | option = OP_PG_UPMAP_ITEMS; | |
9330 | } else { | |
9331 | option = OP_RM_PG_UPMAP_ITEMS; | |
7c673cae | 9332 | } |
224ce89b WB |
9333 | |
9334 | // check pending upmap changes | |
9335 | switch (option) { | |
9336 | case OP_PG_UPMAP: // fall through | |
9337 | case OP_RM_PG_UPMAP: | |
9338 | if (pending_inc.new_pg_upmap.count(pgid) || | |
9339 | pending_inc.old_pg_upmap.count(pgid)) { | |
9340 | dout(10) << __func__ << " waiting for pending update on " | |
9341 | << pgid << dendl; | |
9342 | wait_for_finished_proposal(op, new C_RetryMessage(this, op)); | |
9343 | return true; | |
7c673cae | 9344 | } |
224ce89b | 9345 | break; |
7c673cae | 9346 | |
224ce89b WB |
9347 | case OP_PG_UPMAP_ITEMS: // fall through |
9348 | case OP_RM_PG_UPMAP_ITEMS: | |
9349 | if (pending_inc.new_pg_upmap_items.count(pgid) || | |
9350 | pending_inc.old_pg_upmap_items.count(pgid)) { | |
9351 | dout(10) << __func__ << " waiting for pending update on " | |
9352 | << pgid << dendl; | |
9353 | wait_for_finished_proposal(op, new C_RetryMessage(this, op)); | |
9354 | return true; | |
9355 | } | |
9356 | break; | |
7c673cae | 9357 | |
224ce89b WB |
9358 | default: |
9359 | assert(0 == "invalid option"); | |
7c673cae | 9360 | } |
224ce89b WB |
9361 | |
9362 | switch (option) { | |
9363 | case OP_PG_UPMAP: | |
9364 | { | |
9365 | vector<int64_t> id_vec; | |
9366 | if (!cmd_getval(g_ceph_context, cmdmap, "id", id_vec)) { | |
9367 | ss << "unable to parse 'id' value(s) '" | |
9368 | << cmd_vartype_stringify(cmdmap["id"]) << "'"; | |
9369 | err = -EINVAL; | |
9370 | goto reply; | |
9371 | } | |
9372 | ||
9373 | int pool_min_size = osdmap.get_pg_pool_min_size(pgid); | |
9374 | if ((int)id_vec.size() < pool_min_size) { | |
9375 | ss << "num of osds (" << id_vec.size() <<") < pool min size (" | |
9376 | << pool_min_size << ")"; | |
9377 | err = -EINVAL; | |
9378 | goto reply; | |
9379 | } | |
9380 | ||
9381 | int pool_size = osdmap.get_pg_pool_size(pgid); | |
9382 | if ((int)id_vec.size() > pool_size) { | |
9383 | ss << "num of osds (" << id_vec.size() <<") > pool size (" | |
9384 | << pool_size << ")"; | |
9385 | err = -EINVAL; | |
9386 | goto reply; | |
9387 | } | |
9388 | ||
9389 | vector<int32_t> new_pg_upmap; | |
9390 | for (auto osd : id_vec) { | |
9391 | if (osd != CRUSH_ITEM_NONE && !osdmap.exists(osd)) { | |
9392 | ss << "osd." << osd << " does not exist"; | |
9393 | err = -ENOENT; | |
9394 | goto reply; | |
9395 | } | |
9396 | auto it = std::find(new_pg_upmap.begin(), new_pg_upmap.end(), osd); | |
9397 | if (it != new_pg_upmap.end()) { | |
9398 | ss << "osd." << osd << " already exists, "; | |
9399 | continue; | |
9400 | } | |
9401 | new_pg_upmap.push_back(osd); | |
9402 | } | |
9403 | ||
9404 | if (new_pg_upmap.empty()) { | |
9405 | ss << "no valid upmap items(pairs) is specified"; | |
9406 | err = -EINVAL; | |
9407 | goto reply; | |
9408 | } | |
9409 | ||
9410 | pending_inc.new_pg_upmap[pgid] = mempool::osdmap::vector<int32_t>( | |
9411 | new_pg_upmap.begin(), new_pg_upmap.end()); | |
9412 | ss << "set " << pgid << " pg_upmap mapping to " << new_pg_upmap; | |
7c673cae | 9413 | } |
224ce89b WB |
9414 | break; |
9415 | ||
9416 | case OP_RM_PG_UPMAP: | |
9417 | { | |
9418 | pending_inc.old_pg_upmap.insert(pgid); | |
9419 | ss << "clear " << pgid << " pg_upmap mapping"; | |
7c673cae | 9420 | } |
224ce89b | 9421 | break; |
7c673cae | 9422 | |
224ce89b WB |
9423 | case OP_PG_UPMAP_ITEMS: |
9424 | { | |
9425 | vector<int64_t> id_vec; | |
9426 | if (!cmd_getval(g_ceph_context, cmdmap, "id", id_vec)) { | |
9427 | ss << "unable to parse 'id' value(s) '" | |
9428 | << cmd_vartype_stringify(cmdmap["id"]) << "'"; | |
9429 | err = -EINVAL; | |
9430 | goto reply; | |
9431 | } | |
9432 | ||
9433 | if (id_vec.size() % 2) { | |
9434 | ss << "you must specify pairs of osd ids to be remapped"; | |
9435 | err = -EINVAL; | |
9436 | goto reply; | |
9437 | } | |
9438 | ||
9439 | int pool_size = osdmap.get_pg_pool_size(pgid); | |
9440 | if ((int)(id_vec.size() / 2) > pool_size) { | |
9441 | ss << "num of osd pairs (" << id_vec.size() / 2 <<") > pool size (" | |
9442 | << pool_size << ")"; | |
9443 | err = -EINVAL; | |
9444 | goto reply; | |
9445 | } | |
9446 | ||
9447 | vector<pair<int32_t,int32_t>> new_pg_upmap_items; | |
9448 | ostringstream items; | |
9449 | items << "["; | |
9450 | for (auto p = id_vec.begin(); p != id_vec.end(); ++p) { | |
9451 | int from = *p++; | |
9452 | int to = *p; | |
9453 | if (from == to) { | |
9454 | ss << "from osd." << from << " == to osd." << to << ", "; | |
9455 | continue; | |
9456 | } | |
9457 | if (!osdmap.exists(from)) { | |
9458 | ss << "osd." << from << " does not exist"; | |
9459 | err = -ENOENT; | |
9460 | goto reply; | |
9461 | } | |
9462 | if (to != CRUSH_ITEM_NONE && !osdmap.exists(to)) { | |
9463 | ss << "osd." << to << " does not exist"; | |
9464 | err = -ENOENT; | |
9465 | goto reply; | |
9466 | } | |
c07f9fc5 FG |
9467 | pair<int32_t,int32_t> entry = make_pair(from, to); |
9468 | auto it = std::find(new_pg_upmap_items.begin(), | |
9469 | new_pg_upmap_items.end(), entry); | |
9470 | if (it != new_pg_upmap_items.end()) { | |
9471 | ss << "osd." << from << " -> osd." << to << " already exists, "; | |
9472 | continue; | |
9473 | } | |
9474 | new_pg_upmap_items.push_back(entry); | |
224ce89b WB |
9475 | items << from << "->" << to << ","; |
9476 | } | |
9477 | string out(items.str()); | |
9478 | out.resize(out.size() - 1); // drop last ',' | |
9479 | out += "]"; | |
9480 | ||
9481 | if (new_pg_upmap_items.empty()) { | |
9482 | ss << "no valid upmap items(pairs) is specified"; | |
9483 | err = -EINVAL; | |
9484 | goto reply; | |
9485 | } | |
9486 | ||
9487 | pending_inc.new_pg_upmap_items[pgid] = | |
9488 | mempool::osdmap::vector<pair<int32_t,int32_t>>( | |
9489 | new_pg_upmap_items.begin(), new_pg_upmap_items.end()); | |
9490 | ss << "set " << pgid << " pg_upmap_items mapping to " << out; | |
9491 | } | |
9492 | break; | |
9493 | ||
9494 | case OP_RM_PG_UPMAP_ITEMS: | |
9495 | { | |
9496 | pending_inc.old_pg_upmap_items.insert(pgid); | |
9497 | ss << "clear " << pgid << " pg_upmap_items mapping"; | |
9498 | } | |
9499 | break; | |
9500 | ||
9501 | default: | |
9502 | assert(0 == "invalid option"); | |
7c673cae FG |
9503 | } |
9504 | ||
7c673cae FG |
9505 | goto update; |
9506 | } else if (prefix == "osd primary-affinity") { | |
9507 | int64_t id; | |
9508 | if (!cmd_getval(g_ceph_context, cmdmap, "id", id)) { | |
9509 | ss << "invalid osd id value '" | |
9510 | << cmd_vartype_stringify(cmdmap["id"]) << "'"; | |
9511 | err = -EINVAL; | |
9512 | goto reply; | |
9513 | } | |
9514 | double w; | |
9515 | if (!cmd_getval(g_ceph_context, cmdmap, "weight", w)) { | |
9516 | ss << "unable to parse 'weight' value '" | |
9517 | << cmd_vartype_stringify(cmdmap["weight"]) << "'"; | |
9518 | err = -EINVAL; | |
9519 | goto reply; | |
9520 | } | |
9521 | long ww = (int)((double)CEPH_OSD_MAX_PRIMARY_AFFINITY*w); | |
9522 | if (ww < 0L) { | |
9523 | ss << "weight must be >= 0"; | |
9524 | err = -EINVAL; | |
9525 | goto reply; | |
9526 | } | |
31f18b77 FG |
9527 | if (osdmap.require_min_compat_client > 0 && |
9528 | osdmap.require_min_compat_client < CEPH_RELEASE_FIREFLY) { | |
9529 | ss << "require_min_compat_client " | |
9530 | << ceph_release_name(osdmap.require_min_compat_client) | |
7c673cae FG |
9531 | << " < firefly, which is required for primary-affinity"; |
9532 | err = -EPERM; | |
9533 | goto reply; | |
9534 | } else if (!g_conf->mon_osd_allow_primary_affinity) { | |
9535 | ss << "you must enable 'mon osd allow primary affinity = true' on the mons before you can adjust primary-affinity. note that older clients will no longer be able to communicate with the cluster."; | |
9536 | err = -EPERM; | |
9537 | goto reply; | |
9538 | } | |
9539 | err = check_cluster_features(CEPH_FEATURE_OSD_PRIMARY_AFFINITY, ss); | |
9540 | if (err == -EAGAIN) | |
9541 | goto wait; | |
9542 | if (err < 0) | |
9543 | goto reply; | |
9544 | if (osdmap.exists(id)) { | |
9545 | pending_inc.new_primary_affinity[id] = ww; | |
9546 | ss << "set osd." << id << " primary-affinity to " << w << " (" << ios::hex << ww << ios::dec << ")"; | |
9547 | getline(ss, rs); | |
9548 | wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, 0, rs, | |
9549 | get_last_committed() + 1)); | |
9550 | return true; | |
9551 | } else { | |
9552 | ss << "osd." << id << " does not exist"; | |
9553 | err = -ENOENT; | |
9554 | goto reply; | |
9555 | } | |
9556 | } else if (prefix == "osd reweight") { | |
9557 | int64_t id; | |
9558 | if (!cmd_getval(g_ceph_context, cmdmap, "id", id)) { | |
9559 | ss << "unable to parse osd id value '" | |
9560 | << cmd_vartype_stringify(cmdmap["id"]) << "'"; | |
9561 | err = -EINVAL; | |
9562 | goto reply; | |
9563 | } | |
9564 | double w; | |
9565 | if (!cmd_getval(g_ceph_context, cmdmap, "weight", w)) { | |
9566 | ss << "unable to parse weight value '" | |
9567 | << cmd_vartype_stringify(cmdmap["weight"]) << "'"; | |
9568 | err = -EINVAL; | |
9569 | goto reply; | |
9570 | } | |
9571 | long ww = (int)((double)CEPH_OSD_IN*w); | |
9572 | if (ww < 0L) { | |
9573 | ss << "weight must be >= 0"; | |
9574 | err = -EINVAL; | |
9575 | goto reply; | |
9576 | } | |
9577 | if (osdmap.exists(id)) { | |
9578 | pending_inc.new_weight[id] = ww; | |
9579 | ss << "reweighted osd." << id << " to " << w << " (" << std::hex << ww << std::dec << ")"; | |
9580 | getline(ss, rs); | |
9581 | wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, 0, rs, | |
9582 | get_last_committed() + 1)); | |
9583 | return true; | |
9584 | } else { | |
9585 | ss << "osd." << id << " does not exist"; | |
9586 | err = -ENOENT; | |
9587 | goto reply; | |
9588 | } | |
9589 | } else if (prefix == "osd reweightn") { | |
9590 | map<int32_t, uint32_t> weights; | |
9591 | err = parse_reweights(g_ceph_context, cmdmap, osdmap, &weights); | |
9592 | if (err) { | |
9593 | ss << "unable to parse 'weights' value '" | |
9594 | << cmd_vartype_stringify(cmdmap["weights"]) << "'"; | |
9595 | goto reply; | |
9596 | } | |
9597 | pending_inc.new_weight.insert(weights.begin(), weights.end()); | |
9598 | wait_for_finished_proposal( | |
9599 | op, | |
9600 | new Monitor::C_Command(mon, op, 0, rs, rdata, get_last_committed() + 1)); | |
224ce89b | 9601 | return true; |
7c673cae FG |
9602 | } else if (prefix == "osd lost") { |
9603 | int64_t id; | |
9604 | if (!cmd_getval(g_ceph_context, cmdmap, "id", id)) { | |
9605 | ss << "unable to parse osd id value '" | |
9606 | << cmd_vartype_stringify(cmdmap["id"]) << "'"; | |
9607 | err = -EINVAL; | |
9608 | goto reply; | |
9609 | } | |
9610 | string sure; | |
9611 | if (!cmd_getval(g_ceph_context, cmdmap, "sure", sure) || sure != "--yes-i-really-mean-it") { | |
9612 | ss << "are you SURE? this might mean real, permanent data loss. pass " | |
9613 | "--yes-i-really-mean-it if you really do."; | |
9614 | err = -EPERM; | |
9615 | goto reply; | |
9616 | } else if (!osdmap.exists(id)) { | |
9617 | ss << "osd." << id << " does not exist"; | |
9618 | err = -ENOENT; | |
9619 | goto reply; | |
9620 | } else if (!osdmap.is_down(id)) { | |
9621 | ss << "osd." << id << " is not down"; | |
9622 | err = -EBUSY; | |
9623 | goto reply; | |
9624 | } else { | |
9625 | epoch_t e = osdmap.get_info(id).down_at; | |
9626 | pending_inc.new_lost[id] = e; | |
9627 | ss << "marked osd lost in epoch " << e; | |
9628 | getline(ss, rs); | |
9629 | wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, 0, rs, | |
9630 | get_last_committed() + 1)); | |
9631 | return true; | |
9632 | } | |
9633 | ||
31f18b77 FG |
9634 | } else if (prefix == "osd destroy" || prefix == "osd purge") { |
9635 | /* Destroying an OSD means that we don't expect to further make use of | |
9636 | * the OSDs data (which may even become unreadable after this operation), | |
9637 | * and that we are okay with scrubbing all its cephx keys and config-key | |
9638 | * data (which may include lockbox keys, thus rendering the osd's data | |
9639 | * unreadable). | |
9640 | * | |
9641 | * The OSD will not be removed. Instead, we will mark it as destroyed, | |
9642 | * such that a subsequent call to `create` will not reuse the osd id. | |
9643 | * This will play into being able to recreate the OSD, at the same | |
9644 | * crush location, with minimal data movement. | |
9645 | */ | |
9646 | ||
9647 | // make sure authmon is writeable. | |
9648 | if (!mon->authmon()->is_writeable()) { | |
9649 | dout(10) << __func__ << " waiting for auth mon to be writeable for " | |
9650 | << "osd destroy" << dendl; | |
9651 | mon->authmon()->wait_for_writeable(op, new C_RetryMessage(this, op)); | |
9652 | return false; | |
9653 | } | |
9654 | ||
9655 | int64_t id; | |
9656 | if (!cmd_getval(g_ceph_context, cmdmap, "id", id)) { | |
9657 | ss << "unable to parse osd id value '" | |
9658 | << cmd_vartype_stringify(cmdmap["id"]) << ""; | |
9659 | err = -EINVAL; | |
9660 | goto reply; | |
9661 | } | |
9662 | ||
9663 | bool is_destroy = (prefix == "osd destroy"); | |
9664 | if (!is_destroy) { | |
9665 | assert("osd purge" == prefix); | |
9666 | } | |
9667 | ||
9668 | string sure; | |
9669 | if (!cmd_getval(g_ceph_context, cmdmap, "sure", sure) || | |
9670 | sure != "--yes-i-really-mean-it") { | |
9671 | ss << "Are you SURE? This will mean real, permanent data loss, as well " | |
9672 | << "as cephx and lockbox keys. Pass --yes-i-really-mean-it if you " | |
9673 | << "really do."; | |
9674 | err = -EPERM; | |
9675 | goto reply; | |
d2e6a577 | 9676 | } else if (!osdmap.exists(id)) { |
31f18b77 | 9677 | ss << "osd." << id << " does not exist"; |
d2e6a577 | 9678 | err = 0; // idempotent |
31f18b77 FG |
9679 | goto reply; |
9680 | } else if (osdmap.is_up(id)) { | |
9681 | ss << "osd." << id << " is not `down`."; | |
9682 | err = -EBUSY; | |
9683 | goto reply; | |
9684 | } else if (is_destroy && osdmap.is_destroyed(id)) { | |
9685 | ss << "destroyed osd." << id; | |
9686 | err = 0; | |
9687 | goto reply; | |
9688 | } | |
9689 | ||
9690 | bool goto_reply = false; | |
9691 | ||
9692 | paxos->plug(); | |
9693 | if (is_destroy) { | |
9694 | err = prepare_command_osd_destroy(id, ss); | |
9695 | // we checked above that it should exist. | |
9696 | assert(err != -ENOENT); | |
9697 | } else { | |
9698 | err = prepare_command_osd_purge(id, ss); | |
9699 | if (err == -ENOENT) { | |
9700 | err = 0; | |
9701 | ss << "osd." << id << " does not exist."; | |
9702 | goto_reply = true; | |
9703 | } | |
9704 | } | |
9705 | paxos->unplug(); | |
9706 | ||
9707 | if (err < 0 || goto_reply) { | |
9708 | goto reply; | |
9709 | } | |
9710 | ||
9711 | if (is_destroy) { | |
9712 | ss << "destroyed osd." << id; | |
9713 | } else { | |
9714 | ss << "purged osd." << id; | |
9715 | } | |
9716 | ||
9717 | getline(ss, rs); | |
9718 | wait_for_finished_proposal(op, | |
9719 | new Monitor::C_Command(mon, op, 0, rs, get_last_committed() + 1)); | |
9720 | force_immediate_propose(); | |
9721 | return true; | |
9722 | ||
9723 | } else if (prefix == "osd new") { | |
9724 | ||
9725 | // make sure authmon is writeable. | |
9726 | if (!mon->authmon()->is_writeable()) { | |
9727 | dout(10) << __func__ << " waiting for auth mon to be writeable for " | |
224ce89b | 9728 | << "osd new" << dendl; |
31f18b77 FG |
9729 | mon->authmon()->wait_for_writeable(op, new C_RetryMessage(this, op)); |
9730 | return false; | |
9731 | } | |
9732 | ||
9733 | map<string,string> secrets_map; | |
9734 | ||
9735 | bufferlist bl = m->get_data(); | |
9736 | string secrets_json = bl.to_str(); | |
9737 | dout(20) << __func__ << " osd new json = " << secrets_json << dendl; | |
9738 | ||
9739 | err = get_json_str_map(secrets_json, ss, &secrets_map); | |
9740 | if (err < 0) | |
9741 | goto reply; | |
9742 | ||
9743 | dout(20) << __func__ << " osd new secrets " << secrets_map << dendl; | |
9744 | ||
9745 | paxos->plug(); | |
9746 | err = prepare_command_osd_new(op, cmdmap, secrets_map, ss, f.get()); | |
9747 | paxos->unplug(); | |
9748 | ||
9749 | if (err < 0) { | |
9750 | goto reply; | |
9751 | } | |
9752 | ||
9753 | if (f) { | |
9754 | f->flush(rdata); | |
9755 | } else { | |
9756 | rdata.append(ss); | |
9757 | } | |
9758 | ||
9759 | if (err == EEXIST) { | |
9760 | // idempotent operation | |
9761 | err = 0; | |
9762 | goto reply; | |
9763 | } | |
9764 | ||
9765 | wait_for_finished_proposal(op, | |
9766 | new Monitor::C_Command(mon, op, 0, rs, rdata, | |
9767 | get_last_committed() + 1)); | |
9768 | force_immediate_propose(); | |
9769 | return true; | |
9770 | ||
7c673cae | 9771 | } else if (prefix == "osd create") { |
7c673cae FG |
9772 | |
9773 | // optional id provided? | |
31f18b77 FG |
9774 | int64_t id = -1, cmd_id = -1; |
9775 | if (cmd_getval(g_ceph_context, cmdmap, "id", cmd_id)) { | |
9776 | if (cmd_id < 0) { | |
9777 | ss << "invalid osd id value '" << cmd_id << "'"; | |
7c673cae FG |
9778 | err = -EINVAL; |
9779 | goto reply; | |
9780 | } | |
31f18b77 | 9781 | dout(10) << " osd create got id " << cmd_id << dendl; |
7c673cae FG |
9782 | } |
9783 | ||
7c673cae FG |
9784 | uuid_d uuid; |
9785 | string uuidstr; | |
9786 | if (cmd_getval(g_ceph_context, cmdmap, "uuid", uuidstr)) { | |
9787 | if (!uuid.parse(uuidstr.c_str())) { | |
31f18b77 FG |
9788 | ss << "invalid uuid value '" << uuidstr << "'"; |
9789 | err = -EINVAL; | |
9790 | goto reply; | |
7c673cae | 9791 | } |
31f18b77 FG |
9792 | // we only care about the id if we also have the uuid, to |
9793 | // ensure the operation's idempotency. | |
9794 | id = cmd_id; | |
7c673cae FG |
9795 | } |
9796 | ||
31f18b77 FG |
9797 | int32_t new_id = -1; |
9798 | err = prepare_command_osd_create(id, uuid, &new_id, ss); | |
9799 | if (err < 0) { | |
9800 | if (err == -EAGAIN) { | |
9801 | wait_for_finished_proposal(op, new C_RetryMessage(this, op)); | |
9802 | return true; | |
9803 | } | |
9804 | // a check has failed; reply to the user. | |
9805 | goto reply; | |
9806 | ||
9807 | } else if (err == EEXIST) { | |
9808 | // this is an idempotent operation; we can go ahead and reply. | |
9809 | if (f) { | |
9810 | f->open_object_section("created_osd"); | |
9811 | f->dump_int("osdid", new_id); | |
9812 | f->close_section(); | |
9813 | f->flush(rdata); | |
9814 | } else { | |
9815 | ss << new_id; | |
9816 | rdata.append(ss); | |
7c673cae | 9817 | } |
31f18b77 FG |
9818 | err = 0; |
9819 | goto reply; | |
7c673cae FG |
9820 | } |
9821 | ||
31f18b77 FG |
9822 | do_osd_create(id, uuid, &new_id); |
9823 | ||
7c673cae FG |
9824 | if (f) { |
9825 | f->open_object_section("created_osd"); | |
31f18b77 | 9826 | f->dump_int("osdid", new_id); |
7c673cae FG |
9827 | f->close_section(); |
9828 | f->flush(rdata); | |
9829 | } else { | |
31f18b77 | 9830 | ss << new_id; |
7c673cae FG |
9831 | rdata.append(ss); |
9832 | } | |
31f18b77 FG |
9833 | wait_for_finished_proposal(op, |
9834 | new Monitor::C_Command(mon, op, 0, rs, rdata, | |
9835 | get_last_committed() + 1)); | |
7c673cae FG |
9836 | return true; |
9837 | ||
9838 | } else if (prefix == "osd blacklist clear") { | |
9839 | pending_inc.new_blacklist.clear(); | |
9840 | std::list<std::pair<entity_addr_t,utime_t > > blacklist; | |
9841 | osdmap.get_blacklist(&blacklist); | |
9842 | for (const auto &entry : blacklist) { | |
9843 | pending_inc.old_blacklist.push_back(entry.first); | |
9844 | } | |
9845 | ss << " removed all blacklist entries"; | |
9846 | getline(ss, rs); | |
9847 | wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, 0, rs, | |
9848 | get_last_committed() + 1)); | |
9849 | return true; | |
9850 | } else if (prefix == "osd blacklist") { | |
9851 | string addrstr; | |
9852 | cmd_getval(g_ceph_context, cmdmap, "addr", addrstr); | |
9853 | entity_addr_t addr; | |
9854 | if (!addr.parse(addrstr.c_str(), 0)) { | |
9855 | ss << "unable to parse address " << addrstr; | |
9856 | err = -EINVAL; | |
9857 | goto reply; | |
9858 | } | |
9859 | else { | |
9860 | string blacklistop; | |
9861 | cmd_getval(g_ceph_context, cmdmap, "blacklistop", blacklistop); | |
9862 | if (blacklistop == "add") { | |
9863 | utime_t expires = ceph_clock_now(); | |
9864 | double d; | |
9865 | // default one hour | |
224ce89b WB |
9866 | cmd_getval(g_ceph_context, cmdmap, "expire", d, |
9867 | g_conf->mon_osd_blacklist_default_expire); | |
7c673cae FG |
9868 | expires += d; |
9869 | ||
9870 | pending_inc.new_blacklist[addr] = expires; | |
224ce89b WB |
9871 | |
9872 | { | |
9873 | // cancel any pending un-blacklisting request too | |
9874 | auto it = std::find(pending_inc.old_blacklist.begin(), | |
9875 | pending_inc.old_blacklist.end(), addr); | |
9876 | if (it != pending_inc.old_blacklist.end()) { | |
9877 | pending_inc.old_blacklist.erase(it); | |
9878 | } | |
9879 | } | |
9880 | ||
7c673cae FG |
9881 | ss << "blacklisting " << addr << " until " << expires << " (" << d << " sec)"; |
9882 | getline(ss, rs); | |
9883 | wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, 0, rs, | |
9884 | get_last_committed() + 1)); | |
9885 | return true; | |
9886 | } else if (blacklistop == "rm") { | |
9887 | if (osdmap.is_blacklisted(addr) || | |
9888 | pending_inc.new_blacklist.count(addr)) { | |
9889 | if (osdmap.is_blacklisted(addr)) | |
9890 | pending_inc.old_blacklist.push_back(addr); | |
9891 | else | |
9892 | pending_inc.new_blacklist.erase(addr); | |
9893 | ss << "un-blacklisting " << addr; | |
9894 | getline(ss, rs); | |
9895 | wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, 0, rs, | |
9896 | get_last_committed() + 1)); | |
9897 | return true; | |
9898 | } | |
9899 | ss << addr << " isn't blacklisted"; | |
9900 | err = 0; | |
9901 | goto reply; | |
9902 | } | |
9903 | } | |
9904 | } else if (prefix == "osd pool mksnap") { | |
9905 | string poolstr; | |
9906 | cmd_getval(g_ceph_context, cmdmap, "pool", poolstr); | |
9907 | int64_t pool = osdmap.lookup_pg_pool_name(poolstr.c_str()); | |
9908 | if (pool < 0) { | |
9909 | ss << "unrecognized pool '" << poolstr << "'"; | |
9910 | err = -ENOENT; | |
9911 | goto reply; | |
9912 | } | |
9913 | string snapname; | |
9914 | cmd_getval(g_ceph_context, cmdmap, "snap", snapname); | |
9915 | const pg_pool_t *p = osdmap.get_pg_pool(pool); | |
9916 | if (p->is_unmanaged_snaps_mode()) { | |
9917 | ss << "pool " << poolstr << " is in unmanaged snaps mode"; | |
9918 | err = -EINVAL; | |
9919 | goto reply; | |
9920 | } else if (p->snap_exists(snapname.c_str())) { | |
9921 | ss << "pool " << poolstr << " snap " << snapname << " already exists"; | |
9922 | err = 0; | |
9923 | goto reply; | |
9924 | } else if (p->is_tier()) { | |
9925 | ss << "pool " << poolstr << " is a cache tier"; | |
9926 | err = -EINVAL; | |
9927 | goto reply; | |
9928 | } | |
9929 | pg_pool_t *pp = 0; | |
9930 | if (pending_inc.new_pools.count(pool)) | |
9931 | pp = &pending_inc.new_pools[pool]; | |
9932 | if (!pp) { | |
9933 | pp = &pending_inc.new_pools[pool]; | |
9934 | *pp = *p; | |
9935 | } | |
9936 | if (pp->snap_exists(snapname.c_str())) { | |
9937 | ss << "pool " << poolstr << " snap " << snapname << " already exists"; | |
9938 | } else { | |
9939 | pp->add_snap(snapname.c_str(), ceph_clock_now()); | |
9940 | pp->set_snap_epoch(pending_inc.epoch); | |
9941 | ss << "created pool " << poolstr << " snap " << snapname; | |
9942 | } | |
9943 | getline(ss, rs); | |
9944 | wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, 0, rs, | |
9945 | get_last_committed() + 1)); | |
9946 | return true; | |
9947 | } else if (prefix == "osd pool rmsnap") { | |
9948 | string poolstr; | |
9949 | cmd_getval(g_ceph_context, cmdmap, "pool", poolstr); | |
9950 | int64_t pool = osdmap.lookup_pg_pool_name(poolstr.c_str()); | |
9951 | if (pool < 0) { | |
9952 | ss << "unrecognized pool '" << poolstr << "'"; | |
9953 | err = -ENOENT; | |
9954 | goto reply; | |
9955 | } | |
9956 | string snapname; | |
9957 | cmd_getval(g_ceph_context, cmdmap, "snap", snapname); | |
9958 | const pg_pool_t *p = osdmap.get_pg_pool(pool); | |
9959 | if (p->is_unmanaged_snaps_mode()) { | |
9960 | ss << "pool " << poolstr << " is in unmanaged snaps mode"; | |
9961 | err = -EINVAL; | |
9962 | goto reply; | |
9963 | } else if (!p->snap_exists(snapname.c_str())) { | |
9964 | ss << "pool " << poolstr << " snap " << snapname << " does not exist"; | |
9965 | err = 0; | |
9966 | goto reply; | |
9967 | } | |
9968 | pg_pool_t *pp = 0; | |
9969 | if (pending_inc.new_pools.count(pool)) | |
9970 | pp = &pending_inc.new_pools[pool]; | |
9971 | if (!pp) { | |
9972 | pp = &pending_inc.new_pools[pool]; | |
9973 | *pp = *p; | |
9974 | } | |
9975 | snapid_t sn = pp->snap_exists(snapname.c_str()); | |
9976 | if (sn) { | |
9977 | pp->remove_snap(sn); | |
9978 | pp->set_snap_epoch(pending_inc.epoch); | |
9979 | ss << "removed pool " << poolstr << " snap " << snapname; | |
9980 | } else { | |
9981 | ss << "already removed pool " << poolstr << " snap " << snapname; | |
9982 | } | |
9983 | getline(ss, rs); | |
9984 | wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, 0, rs, | |
9985 | get_last_committed() + 1)); | |
9986 | return true; | |
9987 | } else if (prefix == "osd pool create") { | |
9988 | int64_t pg_num; | |
9989 | int64_t pgp_num; | |
9990 | cmd_getval(g_ceph_context, cmdmap, "pg_num", pg_num, int64_t(0)); | |
9991 | cmd_getval(g_ceph_context, cmdmap, "pgp_num", pgp_num, pg_num); | |
9992 | ||
9993 | string pool_type_str; | |
9994 | cmd_getval(g_ceph_context, cmdmap, "pool_type", pool_type_str); | |
9995 | if (pool_type_str.empty()) | |
224ce89b | 9996 | pool_type_str = g_conf->osd_pool_default_type; |
7c673cae FG |
9997 | |
9998 | string poolstr; | |
9999 | cmd_getval(g_ceph_context, cmdmap, "pool", poolstr); | |
10000 | int64_t pool_id = osdmap.lookup_pg_pool_name(poolstr); | |
10001 | if (pool_id >= 0) { | |
10002 | const pg_pool_t *p = osdmap.get_pg_pool(pool_id); | |
10003 | if (pool_type_str != p->get_type_name()) { | |
10004 | ss << "pool '" << poolstr << "' cannot change to type " << pool_type_str; | |
10005 | err = -EINVAL; | |
10006 | } else { | |
10007 | ss << "pool '" << poolstr << "' already exists"; | |
10008 | err = 0; | |
10009 | } | |
10010 | goto reply; | |
10011 | } | |
10012 | ||
10013 | int pool_type; | |
10014 | if (pool_type_str == "replicated") { | |
10015 | pool_type = pg_pool_t::TYPE_REPLICATED; | |
10016 | } else if (pool_type_str == "erasure") { | |
10017 | err = check_cluster_features(CEPH_FEATURE_CRUSH_V2 | | |
10018 | CEPH_FEATURE_OSD_ERASURE_CODES, | |
10019 | ss); | |
10020 | if (err == -EAGAIN) | |
10021 | goto wait; | |
10022 | if (err) | |
10023 | goto reply; | |
10024 | pool_type = pg_pool_t::TYPE_ERASURE; | |
10025 | } else { | |
10026 | ss << "unknown pool type '" << pool_type_str << "'"; | |
10027 | err = -EINVAL; | |
10028 | goto reply; | |
10029 | } | |
10030 | ||
31f18b77 FG |
10031 | bool implicit_rule_creation = false; |
10032 | string rule_name; | |
10033 | cmd_getval(g_ceph_context, cmdmap, "rule", rule_name); | |
7c673cae FG |
10034 | string erasure_code_profile; |
10035 | cmd_getval(g_ceph_context, cmdmap, "erasure_code_profile", erasure_code_profile); | |
10036 | ||
10037 | if (pool_type == pg_pool_t::TYPE_ERASURE) { | |
10038 | if (erasure_code_profile == "") | |
10039 | erasure_code_profile = "default"; | |
10040 | //handle the erasure code profile | |
10041 | if (erasure_code_profile == "default") { | |
10042 | if (!osdmap.has_erasure_code_profile(erasure_code_profile)) { | |
10043 | if (pending_inc.has_erasure_code_profile(erasure_code_profile)) { | |
10044 | dout(20) << "erasure code profile " << erasure_code_profile << " already pending" << dendl; | |
10045 | goto wait; | |
10046 | } | |
10047 | ||
10048 | map<string,string> profile_map; | |
10049 | err = osdmap.get_erasure_code_profile_default(g_ceph_context, | |
10050 | profile_map, | |
10051 | &ss); | |
10052 | if (err) | |
10053 | goto reply; | |
10054 | dout(20) << "erasure code profile " << erasure_code_profile << " set" << dendl; | |
10055 | pending_inc.set_erasure_code_profile(erasure_code_profile, profile_map); | |
10056 | goto wait; | |
10057 | } | |
10058 | } | |
31f18b77 FG |
10059 | if (rule_name == "") { |
10060 | implicit_rule_creation = true; | |
7c673cae | 10061 | if (erasure_code_profile == "default") { |
31f18b77 | 10062 | rule_name = "erasure-code"; |
7c673cae | 10063 | } else { |
31f18b77 | 10064 | dout(1) << "implicitly use rule named after the pool: " |
7c673cae | 10065 | << poolstr << dendl; |
31f18b77 | 10066 | rule_name = poolstr; |
7c673cae FG |
10067 | } |
10068 | } | |
10069 | } else { | |
31f18b77 FG |
10070 | //NOTE:for replicated pool,cmd_map will put rule_name to erasure_code_profile field |
10071 | rule_name = erasure_code_profile; | |
7c673cae FG |
10072 | } |
10073 | ||
31f18b77 FG |
10074 | if (!implicit_rule_creation && rule_name != "") { |
10075 | int rule; | |
10076 | err = get_crush_rule(rule_name, &rule, &ss); | |
7c673cae FG |
10077 | if (err == -EAGAIN) { |
10078 | wait_for_finished_proposal(op, new C_RetryMessage(this, op)); | |
10079 | return true; | |
10080 | } | |
10081 | if (err) | |
10082 | goto reply; | |
10083 | } | |
10084 | ||
10085 | int64_t expected_num_objects; | |
10086 | cmd_getval(g_ceph_context, cmdmap, "expected_num_objects", expected_num_objects, int64_t(0)); | |
10087 | if (expected_num_objects < 0) { | |
10088 | ss << "'expected_num_objects' must be non-negative"; | |
10089 | err = -EINVAL; | |
10090 | goto reply; | |
10091 | } | |
10092 | ||
10093 | int64_t fast_read_param; | |
10094 | cmd_getval(g_ceph_context, cmdmap, "fast_read", fast_read_param, int64_t(-1)); | |
10095 | FastReadType fast_read = FAST_READ_DEFAULT; | |
10096 | if (fast_read_param == 0) | |
10097 | fast_read = FAST_READ_OFF; | |
10098 | else if (fast_read_param > 0) | |
10099 | fast_read = FAST_READ_ON; | |
10100 | ||
10101 | err = prepare_new_pool(poolstr, 0, // auid=0 for admin created pool | |
10102 | -1, // default crush rule | |
31f18b77 | 10103 | rule_name, |
7c673cae FG |
10104 | pg_num, pgp_num, |
10105 | erasure_code_profile, pool_type, | |
10106 | (uint64_t)expected_num_objects, | |
10107 | fast_read, | |
10108 | &ss); | |
10109 | if (err < 0) { | |
10110 | switch(err) { | |
10111 | case -EEXIST: | |
10112 | ss << "pool '" << poolstr << "' already exists"; | |
10113 | break; | |
10114 | case -EAGAIN: | |
10115 | wait_for_finished_proposal(op, new C_RetryMessage(this, op)); | |
10116 | return true; | |
10117 | case -ERANGE: | |
10118 | goto reply; | |
10119 | default: | |
10120 | goto reply; | |
10121 | break; | |
10122 | } | |
10123 | } else { | |
10124 | ss << "pool '" << poolstr << "' created"; | |
10125 | } | |
10126 | getline(ss, rs); | |
10127 | wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, 0, rs, | |
10128 | get_last_committed() + 1)); | |
10129 | return true; | |
10130 | ||
10131 | } else if (prefix == "osd pool delete" || | |
10132 | prefix == "osd pool rm") { | |
10133 | // osd pool delete/rm <poolname> <poolname again> --yes-i-really-really-mean-it | |
10134 | string poolstr, poolstr2, sure; | |
10135 | cmd_getval(g_ceph_context, cmdmap, "pool", poolstr); | |
10136 | cmd_getval(g_ceph_context, cmdmap, "pool2", poolstr2); | |
10137 | cmd_getval(g_ceph_context, cmdmap, "sure", sure); | |
10138 | int64_t pool = osdmap.lookup_pg_pool_name(poolstr.c_str()); | |
10139 | if (pool < 0) { | |
10140 | ss << "pool '" << poolstr << "' does not exist"; | |
10141 | err = 0; | |
10142 | goto reply; | |
10143 | } | |
10144 | ||
10145 | bool force_no_fake = sure == "--yes-i-really-really-mean-it-not-faking"; | |
10146 | if (poolstr2 != poolstr || | |
10147 | (sure != "--yes-i-really-really-mean-it" && !force_no_fake)) { | |
10148 | ss << "WARNING: this will *PERMANENTLY DESTROY* all data stored in pool " << poolstr | |
10149 | << ". If you are *ABSOLUTELY CERTAIN* that is what you want, pass the pool name *twice*, " | |
10150 | << "followed by --yes-i-really-really-mean-it."; | |
10151 | err = -EPERM; | |
10152 | goto reply; | |
10153 | } | |
10154 | err = _prepare_remove_pool(pool, &ss, force_no_fake); | |
10155 | if (err == -EAGAIN) { | |
10156 | wait_for_finished_proposal(op, new C_RetryMessage(this, op)); | |
10157 | return true; | |
10158 | } | |
10159 | if (err < 0) | |
10160 | goto reply; | |
10161 | goto update; | |
10162 | } else if (prefix == "osd pool rename") { | |
10163 | string srcpoolstr, destpoolstr; | |
10164 | cmd_getval(g_ceph_context, cmdmap, "srcpool", srcpoolstr); | |
10165 | cmd_getval(g_ceph_context, cmdmap, "destpool", destpoolstr); | |
10166 | int64_t pool_src = osdmap.lookup_pg_pool_name(srcpoolstr.c_str()); | |
10167 | int64_t pool_dst = osdmap.lookup_pg_pool_name(destpoolstr.c_str()); | |
10168 | ||
10169 | if (pool_src < 0) { | |
10170 | if (pool_dst >= 0) { | |
10171 | // src pool doesn't exist, dst pool does exist: to ensure idempotency | |
10172 | // of operations, assume this rename succeeded, as it is not changing | |
10173 | // the current state. Make sure we output something understandable | |
10174 | // for whoever is issuing the command, if they are paying attention, | |
10175 | // in case it was not intentional; or to avoid a "wtf?" and a bug | |
10176 | // report in case it was intentional, while expecting a failure. | |
10177 | ss << "pool '" << srcpoolstr << "' does not exist; pool '" | |
10178 | << destpoolstr << "' does -- assuming successful rename"; | |
10179 | err = 0; | |
10180 | } else { | |
10181 | ss << "unrecognized pool '" << srcpoolstr << "'"; | |
10182 | err = -ENOENT; | |
10183 | } | |
10184 | goto reply; | |
10185 | } else if (pool_dst >= 0) { | |
10186 | // source pool exists and so does the destination pool | |
10187 | ss << "pool '" << destpoolstr << "' already exists"; | |
10188 | err = -EEXIST; | |
10189 | goto reply; | |
10190 | } | |
10191 | ||
10192 | int ret = _prepare_rename_pool(pool_src, destpoolstr); | |
10193 | if (ret == 0) { | |
10194 | ss << "pool '" << srcpoolstr << "' renamed to '" << destpoolstr << "'"; | |
10195 | } else { | |
10196 | ss << "failed to rename pool '" << srcpoolstr << "' to '" << destpoolstr << "': " | |
10197 | << cpp_strerror(ret); | |
10198 | } | |
10199 | getline(ss, rs); | |
10200 | wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, ret, rs, | |
10201 | get_last_committed() + 1)); | |
10202 | return true; | |
10203 | ||
10204 | } else if (prefix == "osd pool set") { | |
10205 | err = prepare_command_pool_set(cmdmap, ss); | |
10206 | if (err == -EAGAIN) | |
10207 | goto wait; | |
10208 | if (err < 0) | |
10209 | goto reply; | |
10210 | ||
10211 | getline(ss, rs); | |
10212 | wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, 0, rs, | |
10213 | get_last_committed() + 1)); | |
10214 | return true; | |
10215 | } else if (prefix == "osd tier add") { | |
10216 | err = check_cluster_features(CEPH_FEATURE_OSD_CACHEPOOL, ss); | |
10217 | if (err == -EAGAIN) | |
10218 | goto wait; | |
10219 | if (err) | |
10220 | goto reply; | |
10221 | string poolstr; | |
10222 | cmd_getval(g_ceph_context, cmdmap, "pool", poolstr); | |
10223 | int64_t pool_id = osdmap.lookup_pg_pool_name(poolstr); | |
10224 | if (pool_id < 0) { | |
10225 | ss << "unrecognized pool '" << poolstr << "'"; | |
10226 | err = -ENOENT; | |
10227 | goto reply; | |
10228 | } | |
10229 | string tierpoolstr; | |
10230 | cmd_getval(g_ceph_context, cmdmap, "tierpool", tierpoolstr); | |
10231 | int64_t tierpool_id = osdmap.lookup_pg_pool_name(tierpoolstr); | |
10232 | if (tierpool_id < 0) { | |
10233 | ss << "unrecognized pool '" << tierpoolstr << "'"; | |
10234 | err = -ENOENT; | |
10235 | goto reply; | |
10236 | } | |
10237 | const pg_pool_t *p = osdmap.get_pg_pool(pool_id); | |
10238 | assert(p); | |
10239 | const pg_pool_t *tp = osdmap.get_pg_pool(tierpool_id); | |
10240 | assert(tp); | |
10241 | ||
10242 | if (!_check_become_tier(tierpool_id, tp, pool_id, p, &err, &ss)) { | |
10243 | goto reply; | |
10244 | } | |
10245 | ||
10246 | // make sure new tier is empty | |
10247 | string force_nonempty; | |
10248 | cmd_getval(g_ceph_context, cmdmap, "force_nonempty", force_nonempty); | |
31f18b77 FG |
10249 | const pool_stat_t *pstats = mon->pgservice->get_pool_stat(tierpool_id); |
10250 | if (pstats && pstats->stats.sum.num_objects != 0 && | |
7c673cae FG |
10251 | force_nonempty != "--force-nonempty") { |
10252 | ss << "tier pool '" << tierpoolstr << "' is not empty; --force-nonempty to force"; | |
10253 | err = -ENOTEMPTY; | |
10254 | goto reply; | |
10255 | } | |
10256 | if (tp->ec_pool()) { | |
10257 | ss << "tier pool '" << tierpoolstr | |
10258 | << "' is an ec pool, which cannot be a tier"; | |
10259 | err = -ENOTSUP; | |
10260 | goto reply; | |
10261 | } | |
10262 | if ((!tp->removed_snaps.empty() || !tp->snaps.empty()) && | |
10263 | ((force_nonempty != "--force-nonempty") || | |
10264 | (!g_conf->mon_debug_unsafe_allow_tier_with_nonempty_snaps))) { | |
10265 | ss << "tier pool '" << tierpoolstr << "' has snapshot state; it cannot be added as a tier without breaking the pool"; | |
10266 | err = -ENOTEMPTY; | |
10267 | goto reply; | |
10268 | } | |
10269 | // go | |
10270 | pg_pool_t *np = pending_inc.get_new_pool(pool_id, p); | |
10271 | pg_pool_t *ntp = pending_inc.get_new_pool(tierpool_id, tp); | |
10272 | if (np->tiers.count(tierpool_id) || ntp->is_tier()) { | |
10273 | wait_for_finished_proposal(op, new C_RetryMessage(this, op)); | |
10274 | return true; | |
10275 | } | |
10276 | np->tiers.insert(tierpool_id); | |
10277 | np->set_snap_epoch(pending_inc.epoch); // tier will update to our snap info | |
10278 | ntp->tier_of = pool_id; | |
10279 | ss << "pool '" << tierpoolstr << "' is now (or already was) a tier of '" << poolstr << "'"; | |
10280 | wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, 0, ss.str(), | |
10281 | get_last_committed() + 1)); | |
10282 | return true; | |
10283 | } else if (prefix == "osd tier remove" || | |
10284 | prefix == "osd tier rm") { | |
10285 | string poolstr; | |
10286 | cmd_getval(g_ceph_context, cmdmap, "pool", poolstr); | |
10287 | int64_t pool_id = osdmap.lookup_pg_pool_name(poolstr); | |
10288 | if (pool_id < 0) { | |
10289 | ss << "unrecognized pool '" << poolstr << "'"; | |
10290 | err = -ENOENT; | |
10291 | goto reply; | |
10292 | } | |
10293 | string tierpoolstr; | |
10294 | cmd_getval(g_ceph_context, cmdmap, "tierpool", tierpoolstr); | |
10295 | int64_t tierpool_id = osdmap.lookup_pg_pool_name(tierpoolstr); | |
10296 | if (tierpool_id < 0) { | |
10297 | ss << "unrecognized pool '" << tierpoolstr << "'"; | |
10298 | err = -ENOENT; | |
10299 | goto reply; | |
10300 | } | |
10301 | const pg_pool_t *p = osdmap.get_pg_pool(pool_id); | |
10302 | assert(p); | |
10303 | const pg_pool_t *tp = osdmap.get_pg_pool(tierpool_id); | |
10304 | assert(tp); | |
10305 | ||
10306 | if (!_check_remove_tier(pool_id, p, tp, &err, &ss)) { | |
10307 | goto reply; | |
10308 | } | |
10309 | ||
10310 | if (p->tiers.count(tierpool_id) == 0) { | |
10311 | ss << "pool '" << tierpoolstr << "' is now (or already was) not a tier of '" << poolstr << "'"; | |
10312 | err = 0; | |
10313 | goto reply; | |
10314 | } | |
10315 | if (tp->tier_of != pool_id) { | |
10316 | ss << "tier pool '" << tierpoolstr << "' is a tier of '" | |
10317 | << osdmap.get_pool_name(tp->tier_of) << "': " | |
10318 | // be scary about it; this is an inconsistency and bells must go off | |
10319 | << "THIS SHOULD NOT HAVE HAPPENED AT ALL"; | |
10320 | err = -EINVAL; | |
10321 | goto reply; | |
10322 | } | |
10323 | if (p->read_tier == tierpool_id) { | |
10324 | ss << "tier pool '" << tierpoolstr << "' is the overlay for '" << poolstr << "'; please remove-overlay first"; | |
10325 | err = -EBUSY; | |
10326 | goto reply; | |
10327 | } | |
10328 | // go | |
10329 | pg_pool_t *np = pending_inc.get_new_pool(pool_id, p); | |
10330 | pg_pool_t *ntp = pending_inc.get_new_pool(tierpool_id, tp); | |
10331 | if (np->tiers.count(tierpool_id) == 0 || | |
10332 | ntp->tier_of != pool_id || | |
10333 | np->read_tier == tierpool_id) { | |
10334 | wait_for_finished_proposal(op, new C_RetryMessage(this, op)); | |
10335 | return true; | |
10336 | } | |
10337 | np->tiers.erase(tierpool_id); | |
10338 | ntp->clear_tier(); | |
10339 | ss << "pool '" << tierpoolstr << "' is now (or already was) not a tier of '" << poolstr << "'"; | |
10340 | wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, 0, ss.str(), | |
10341 | get_last_committed() + 1)); | |
10342 | return true; | |
10343 | } else if (prefix == "osd tier set-overlay") { | |
10344 | err = check_cluster_features(CEPH_FEATURE_OSD_CACHEPOOL, ss); | |
10345 | if (err == -EAGAIN) | |
10346 | goto wait; | |
10347 | if (err) | |
10348 | goto reply; | |
10349 | string poolstr; | |
10350 | cmd_getval(g_ceph_context, cmdmap, "pool", poolstr); | |
10351 | int64_t pool_id = osdmap.lookup_pg_pool_name(poolstr); | |
10352 | if (pool_id < 0) { | |
10353 | ss << "unrecognized pool '" << poolstr << "'"; | |
10354 | err = -ENOENT; | |
10355 | goto reply; | |
10356 | } | |
10357 | string overlaypoolstr; | |
10358 | cmd_getval(g_ceph_context, cmdmap, "overlaypool", overlaypoolstr); | |
10359 | int64_t overlaypool_id = osdmap.lookup_pg_pool_name(overlaypoolstr); | |
10360 | if (overlaypool_id < 0) { | |
10361 | ss << "unrecognized pool '" << overlaypoolstr << "'"; | |
10362 | err = -ENOENT; | |
10363 | goto reply; | |
10364 | } | |
10365 | const pg_pool_t *p = osdmap.get_pg_pool(pool_id); | |
10366 | assert(p); | |
10367 | const pg_pool_t *overlay_p = osdmap.get_pg_pool(overlaypool_id); | |
10368 | assert(overlay_p); | |
10369 | if (p->tiers.count(overlaypool_id) == 0) { | |
10370 | ss << "tier pool '" << overlaypoolstr << "' is not a tier of '" << poolstr << "'"; | |
10371 | err = -EINVAL; | |
10372 | goto reply; | |
10373 | } | |
10374 | if (p->read_tier == overlaypool_id) { | |
10375 | err = 0; | |
10376 | ss << "overlay for '" << poolstr << "' is now (or already was) '" << overlaypoolstr << "'"; | |
10377 | goto reply; | |
10378 | } | |
10379 | if (p->has_read_tier()) { | |
10380 | ss << "pool '" << poolstr << "' has overlay '" | |
10381 | << osdmap.get_pool_name(p->read_tier) | |
10382 | << "'; please remove-overlay first"; | |
10383 | err = -EINVAL; | |
10384 | goto reply; | |
10385 | } | |
10386 | ||
10387 | // go | |
10388 | pg_pool_t *np = pending_inc.get_new_pool(pool_id, p); | |
10389 | np->read_tier = overlaypool_id; | |
10390 | np->write_tier = overlaypool_id; | |
10391 | np->set_last_force_op_resend(pending_inc.epoch); | |
10392 | pg_pool_t *noverlay_p = pending_inc.get_new_pool(overlaypool_id, overlay_p); | |
10393 | noverlay_p->set_last_force_op_resend(pending_inc.epoch); | |
10394 | ss << "overlay for '" << poolstr << "' is now (or already was) '" << overlaypoolstr << "'"; | |
10395 | if (overlay_p->cache_mode == pg_pool_t::CACHEMODE_NONE) | |
10396 | ss <<" (WARNING: overlay pool cache_mode is still NONE)"; | |
10397 | wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, 0, ss.str(), | |
10398 | get_last_committed() + 1)); | |
10399 | return true; | |
10400 | } else if (prefix == "osd tier remove-overlay" || | |
10401 | prefix == "osd tier rm-overlay") { | |
10402 | string poolstr; | |
10403 | cmd_getval(g_ceph_context, cmdmap, "pool", poolstr); | |
10404 | int64_t pool_id = osdmap.lookup_pg_pool_name(poolstr); | |
10405 | if (pool_id < 0) { | |
10406 | ss << "unrecognized pool '" << poolstr << "'"; | |
10407 | err = -ENOENT; | |
10408 | goto reply; | |
10409 | } | |
10410 | const pg_pool_t *p = osdmap.get_pg_pool(pool_id); | |
10411 | assert(p); | |
10412 | if (!p->has_read_tier()) { | |
10413 | err = 0; | |
10414 | ss << "there is now (or already was) no overlay for '" << poolstr << "'"; | |
10415 | goto reply; | |
10416 | } | |
10417 | ||
10418 | if (!_check_remove_tier(pool_id, p, NULL, &err, &ss)) { | |
10419 | goto reply; | |
10420 | } | |
10421 | ||
10422 | // go | |
10423 | pg_pool_t *np = pending_inc.get_new_pool(pool_id, p); | |
10424 | if (np->has_read_tier()) { | |
10425 | const pg_pool_t *op = osdmap.get_pg_pool(np->read_tier); | |
10426 | pg_pool_t *nop = pending_inc.get_new_pool(np->read_tier,op); | |
10427 | nop->set_last_force_op_resend(pending_inc.epoch); | |
10428 | } | |
10429 | if (np->has_write_tier()) { | |
10430 | const pg_pool_t *op = osdmap.get_pg_pool(np->write_tier); | |
10431 | pg_pool_t *nop = pending_inc.get_new_pool(np->write_tier, op); | |
10432 | nop->set_last_force_op_resend(pending_inc.epoch); | |
10433 | } | |
10434 | np->clear_read_tier(); | |
10435 | np->clear_write_tier(); | |
10436 | np->set_last_force_op_resend(pending_inc.epoch); | |
10437 | ss << "there is now (or already was) no overlay for '" << poolstr << "'"; | |
10438 | wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, 0, ss.str(), | |
10439 | get_last_committed() + 1)); | |
10440 | return true; | |
10441 | } else if (prefix == "osd tier cache-mode") { | |
10442 | err = check_cluster_features(CEPH_FEATURE_OSD_CACHEPOOL, ss); | |
10443 | if (err == -EAGAIN) | |
10444 | goto wait; | |
10445 | if (err) | |
10446 | goto reply; | |
10447 | string poolstr; | |
10448 | cmd_getval(g_ceph_context, cmdmap, "pool", poolstr); | |
10449 | int64_t pool_id = osdmap.lookup_pg_pool_name(poolstr); | |
10450 | if (pool_id < 0) { | |
10451 | ss << "unrecognized pool '" << poolstr << "'"; | |
10452 | err = -ENOENT; | |
10453 | goto reply; | |
10454 | } | |
10455 | const pg_pool_t *p = osdmap.get_pg_pool(pool_id); | |
10456 | assert(p); | |
10457 | if (!p->is_tier()) { | |
10458 | ss << "pool '" << poolstr << "' is not a tier"; | |
10459 | err = -EINVAL; | |
10460 | goto reply; | |
10461 | } | |
10462 | string modestr; | |
10463 | cmd_getval(g_ceph_context, cmdmap, "mode", modestr); | |
10464 | pg_pool_t::cache_mode_t mode = pg_pool_t::get_cache_mode_from_str(modestr); | |
10465 | if (mode < 0) { | |
10466 | ss << "'" << modestr << "' is not a valid cache mode"; | |
10467 | err = -EINVAL; | |
10468 | goto reply; | |
10469 | } | |
10470 | ||
10471 | string sure; | |
10472 | cmd_getval(g_ceph_context, cmdmap, "sure", sure); | |
10473 | if ((mode != pg_pool_t::CACHEMODE_WRITEBACK && | |
10474 | mode != pg_pool_t::CACHEMODE_NONE && | |
10475 | mode != pg_pool_t::CACHEMODE_PROXY && | |
10476 | mode != pg_pool_t::CACHEMODE_READPROXY) && | |
10477 | sure != "--yes-i-really-mean-it") { | |
10478 | ss << "'" << modestr << "' is not a well-supported cache mode and may " | |
10479 | << "corrupt your data. pass --yes-i-really-mean-it to force."; | |
10480 | err = -EPERM; | |
10481 | goto reply; | |
10482 | } | |
10483 | ||
10484 | // pool already has this cache-mode set and there are no pending changes | |
10485 | if (p->cache_mode == mode && | |
10486 | (pending_inc.new_pools.count(pool_id) == 0 || | |
10487 | pending_inc.new_pools[pool_id].cache_mode == p->cache_mode)) { | |
10488 | ss << "set cache-mode for pool '" << poolstr << "'" | |
10489 | << " to " << pg_pool_t::get_cache_mode_name(mode); | |
10490 | err = 0; | |
10491 | goto reply; | |
10492 | } | |
10493 | ||
10494 | /* Mode description: | |
10495 | * | |
10496 | * none: No cache-mode defined | |
10497 | * forward: Forward all reads and writes to base pool | |
10498 | * writeback: Cache writes, promote reads from base pool | |
10499 | * readonly: Forward writes to base pool | |
10500 | * readforward: Writes are in writeback mode, Reads are in forward mode | |
10501 | * proxy: Proxy all reads and writes to base pool | |
10502 | * readproxy: Writes are in writeback mode, Reads are in proxy mode | |
10503 | * | |
10504 | * Hence, these are the allowed transitions: | |
10505 | * | |
10506 | * none -> any | |
10507 | * forward -> proxy || readforward || readproxy || writeback || any IF num_objects_dirty == 0 | |
10508 | * proxy -> forward || readforward || readproxy || writeback || any IF num_objects_dirty == 0 | |
10509 | * readforward -> forward || proxy || readproxy || writeback || any IF num_objects_dirty == 0 | |
10510 | * readproxy -> forward || proxy || readforward || writeback || any IF num_objects_dirty == 0 | |
10511 | * writeback -> readforward || readproxy || forward || proxy | |
10512 | * readonly -> any | |
10513 | */ | |
10514 | ||
10515 | // We check if the transition is valid against the current pool mode, as | |
10516 | // it is the only committed state thus far. We will blantly squash | |
10517 | // whatever mode is on the pending state. | |
10518 | ||
10519 | if (p->cache_mode == pg_pool_t::CACHEMODE_WRITEBACK && | |
10520 | (mode != pg_pool_t::CACHEMODE_FORWARD && | |
10521 | mode != pg_pool_t::CACHEMODE_PROXY && | |
10522 | mode != pg_pool_t::CACHEMODE_READFORWARD && | |
10523 | mode != pg_pool_t::CACHEMODE_READPROXY)) { | |
10524 | ss << "unable to set cache-mode '" << pg_pool_t::get_cache_mode_name(mode) | |
10525 | << "' on a '" << pg_pool_t::get_cache_mode_name(p->cache_mode) | |
10526 | << "' pool; only '" | |
10527 | << pg_pool_t::get_cache_mode_name(pg_pool_t::CACHEMODE_FORWARD) | |
10528 | << "','" | |
10529 | << pg_pool_t::get_cache_mode_name(pg_pool_t::CACHEMODE_PROXY) | |
10530 | << "','" | |
10531 | << pg_pool_t::get_cache_mode_name(pg_pool_t::CACHEMODE_READFORWARD) | |
10532 | << "','" | |
10533 | << pg_pool_t::get_cache_mode_name(pg_pool_t::CACHEMODE_READPROXY) | |
10534 | << "' allowed."; | |
10535 | err = -EINVAL; | |
10536 | goto reply; | |
10537 | } | |
10538 | if ((p->cache_mode == pg_pool_t::CACHEMODE_READFORWARD && | |
10539 | (mode != pg_pool_t::CACHEMODE_WRITEBACK && | |
10540 | mode != pg_pool_t::CACHEMODE_FORWARD && | |
10541 | mode != pg_pool_t::CACHEMODE_PROXY && | |
10542 | mode != pg_pool_t::CACHEMODE_READPROXY)) || | |
10543 | ||
10544 | (p->cache_mode == pg_pool_t::CACHEMODE_READPROXY && | |
10545 | (mode != pg_pool_t::CACHEMODE_WRITEBACK && | |
10546 | mode != pg_pool_t::CACHEMODE_FORWARD && | |
10547 | mode != pg_pool_t::CACHEMODE_READFORWARD && | |
10548 | mode != pg_pool_t::CACHEMODE_PROXY)) || | |
10549 | ||
10550 | (p->cache_mode == pg_pool_t::CACHEMODE_PROXY && | |
10551 | (mode != pg_pool_t::CACHEMODE_WRITEBACK && | |
10552 | mode != pg_pool_t::CACHEMODE_FORWARD && | |
10553 | mode != pg_pool_t::CACHEMODE_READFORWARD && | |
10554 | mode != pg_pool_t::CACHEMODE_READPROXY)) || | |
10555 | ||
10556 | (p->cache_mode == pg_pool_t::CACHEMODE_FORWARD && | |
10557 | (mode != pg_pool_t::CACHEMODE_WRITEBACK && | |
10558 | mode != pg_pool_t::CACHEMODE_READFORWARD && | |
10559 | mode != pg_pool_t::CACHEMODE_PROXY && | |
10560 | mode != pg_pool_t::CACHEMODE_READPROXY))) { | |
10561 | ||
31f18b77 FG |
10562 | const pool_stat_t* pstats = |
10563 | mon->pgservice->get_pool_stat(pool_id); | |
7c673cae | 10564 | |
31f18b77 | 10565 | if (pstats && pstats->stats.sum.num_objects_dirty > 0) { |
7c673cae FG |
10566 | ss << "unable to set cache-mode '" |
10567 | << pg_pool_t::get_cache_mode_name(mode) << "' on pool '" << poolstr | |
10568 | << "': dirty objects found"; | |
10569 | err = -EBUSY; | |
10570 | goto reply; | |
10571 | } | |
10572 | } | |
10573 | // go | |
10574 | pg_pool_t *np = pending_inc.get_new_pool(pool_id, p); | |
10575 | np->cache_mode = mode; | |
10576 | // set this both when moving to and from cache_mode NONE. this is to | |
10577 | // capture legacy pools that were set up before this flag existed. | |
10578 | np->flags |= pg_pool_t::FLAG_INCOMPLETE_CLONES; | |
10579 | ss << "set cache-mode for pool '" << poolstr | |
10580 | << "' to " << pg_pool_t::get_cache_mode_name(mode); | |
10581 | if (mode == pg_pool_t::CACHEMODE_NONE) { | |
10582 | const pg_pool_t *base_pool = osdmap.get_pg_pool(np->tier_of); | |
10583 | assert(base_pool); | |
10584 | if (base_pool->read_tier == pool_id || | |
10585 | base_pool->write_tier == pool_id) | |
10586 | ss <<" (WARNING: pool is still configured as read or write tier)"; | |
10587 | } | |
10588 | wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, 0, ss.str(), | |
10589 | get_last_committed() + 1)); | |
10590 | return true; | |
10591 | } else if (prefix == "osd tier add-cache") { | |
10592 | err = check_cluster_features(CEPH_FEATURE_OSD_CACHEPOOL, ss); | |
10593 | if (err == -EAGAIN) | |
10594 | goto wait; | |
10595 | if (err) | |
10596 | goto reply; | |
10597 | string poolstr; | |
10598 | cmd_getval(g_ceph_context, cmdmap, "pool", poolstr); | |
10599 | int64_t pool_id = osdmap.lookup_pg_pool_name(poolstr); | |
10600 | if (pool_id < 0) { | |
10601 | ss << "unrecognized pool '" << poolstr << "'"; | |
10602 | err = -ENOENT; | |
10603 | goto reply; | |
10604 | } | |
10605 | string tierpoolstr; | |
10606 | cmd_getval(g_ceph_context, cmdmap, "tierpool", tierpoolstr); | |
10607 | int64_t tierpool_id = osdmap.lookup_pg_pool_name(tierpoolstr); | |
10608 | if (tierpool_id < 0) { | |
10609 | ss << "unrecognized pool '" << tierpoolstr << "'"; | |
10610 | err = -ENOENT; | |
10611 | goto reply; | |
10612 | } | |
10613 | const pg_pool_t *p = osdmap.get_pg_pool(pool_id); | |
10614 | assert(p); | |
10615 | const pg_pool_t *tp = osdmap.get_pg_pool(tierpool_id); | |
10616 | assert(tp); | |
10617 | ||
10618 | if (!_check_become_tier(tierpool_id, tp, pool_id, p, &err, &ss)) { | |
10619 | goto reply; | |
10620 | } | |
10621 | ||
10622 | int64_t size = 0; | |
10623 | if (!cmd_getval(g_ceph_context, cmdmap, "size", size)) { | |
10624 | ss << "unable to parse 'size' value '" | |
10625 | << cmd_vartype_stringify(cmdmap["size"]) << "'"; | |
10626 | err = -EINVAL; | |
10627 | goto reply; | |
10628 | } | |
10629 | // make sure new tier is empty | |
31f18b77 FG |
10630 | const pool_stat_t *pstats = |
10631 | mon->pgservice->get_pool_stat(tierpool_id); | |
10632 | if (pstats && pstats->stats.sum.num_objects != 0) { | |
7c673cae FG |
10633 | ss << "tier pool '" << tierpoolstr << "' is not empty"; |
10634 | err = -ENOTEMPTY; | |
10635 | goto reply; | |
10636 | } | |
10637 | string modestr = g_conf->osd_tier_default_cache_mode; | |
10638 | pg_pool_t::cache_mode_t mode = pg_pool_t::get_cache_mode_from_str(modestr); | |
10639 | if (mode < 0) { | |
10640 | ss << "osd tier cache default mode '" << modestr << "' is not a valid cache mode"; | |
10641 | err = -EINVAL; | |
10642 | goto reply; | |
10643 | } | |
10644 | HitSet::Params hsp; | |
10645 | if (g_conf->osd_tier_default_cache_hit_set_type == "bloom") { | |
10646 | BloomHitSet::Params *bsp = new BloomHitSet::Params; | |
10647 | bsp->set_fpp(g_conf->osd_pool_default_hit_set_bloom_fpp); | |
10648 | hsp = HitSet::Params(bsp); | |
10649 | } else if (g_conf->osd_tier_default_cache_hit_set_type == "explicit_hash") { | |
10650 | hsp = HitSet::Params(new ExplicitHashHitSet::Params); | |
10651 | } | |
10652 | else if (g_conf->osd_tier_default_cache_hit_set_type == "explicit_object") { | |
10653 | hsp = HitSet::Params(new ExplicitObjectHitSet::Params); | |
10654 | } else { | |
10655 | ss << "osd tier cache default hit set type '" << | |
10656 | g_conf->osd_tier_default_cache_hit_set_type << "' is not a known type"; | |
10657 | err = -EINVAL; | |
10658 | goto reply; | |
10659 | } | |
10660 | // go | |
10661 | pg_pool_t *np = pending_inc.get_new_pool(pool_id, p); | |
10662 | pg_pool_t *ntp = pending_inc.get_new_pool(tierpool_id, tp); | |
10663 | if (np->tiers.count(tierpool_id) || ntp->is_tier()) { | |
10664 | wait_for_finished_proposal(op, new C_RetryMessage(this, op)); | |
10665 | return true; | |
10666 | } | |
10667 | np->tiers.insert(tierpool_id); | |
10668 | np->read_tier = np->write_tier = tierpool_id; | |
10669 | np->set_snap_epoch(pending_inc.epoch); // tier will update to our snap info | |
10670 | np->set_last_force_op_resend(pending_inc.epoch); | |
10671 | ntp->set_last_force_op_resend(pending_inc.epoch); | |
10672 | ntp->tier_of = pool_id; | |
10673 | ntp->cache_mode = mode; | |
10674 | ntp->hit_set_count = g_conf->osd_tier_default_cache_hit_set_count; | |
10675 | ntp->hit_set_period = g_conf->osd_tier_default_cache_hit_set_period; | |
10676 | ntp->min_read_recency_for_promote = g_conf->osd_tier_default_cache_min_read_recency_for_promote; | |
10677 | ntp->min_write_recency_for_promote = g_conf->osd_tier_default_cache_min_write_recency_for_promote; | |
10678 | ntp->hit_set_grade_decay_rate = g_conf->osd_tier_default_cache_hit_set_grade_decay_rate; | |
10679 | ntp->hit_set_search_last_n = g_conf->osd_tier_default_cache_hit_set_search_last_n; | |
10680 | ntp->hit_set_params = hsp; | |
10681 | ntp->target_max_bytes = size; | |
10682 | ss << "pool '" << tierpoolstr << "' is now (or already was) a cache tier of '" << poolstr << "'"; | |
10683 | wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, 0, ss.str(), | |
10684 | get_last_committed() + 1)); | |
10685 | return true; | |
10686 | } else if (prefix == "osd pool set-quota") { | |
10687 | string poolstr; | |
10688 | cmd_getval(g_ceph_context, cmdmap, "pool", poolstr); | |
10689 | int64_t pool_id = osdmap.lookup_pg_pool_name(poolstr); | |
10690 | if (pool_id < 0) { | |
10691 | ss << "unrecognized pool '" << poolstr << "'"; | |
10692 | err = -ENOENT; | |
10693 | goto reply; | |
10694 | } | |
10695 | ||
10696 | string field; | |
10697 | cmd_getval(g_ceph_context, cmdmap, "field", field); | |
10698 | if (field != "max_objects" && field != "max_bytes") { | |
10699 | ss << "unrecognized field '" << field << "'; should be 'max_bytes' or 'max_objects'"; | |
10700 | err = -EINVAL; | |
10701 | goto reply; | |
10702 | } | |
10703 | ||
10704 | // val could contain unit designations, so we treat as a string | |
10705 | string val; | |
10706 | cmd_getval(g_ceph_context, cmdmap, "val", val); | |
10707 | stringstream tss; | |
10708 | int64_t value = unit_to_bytesize(val, &tss); | |
10709 | if (value < 0) { | |
10710 | ss << "error parsing value '" << value << "': " << tss.str(); | |
10711 | err = value; | |
10712 | goto reply; | |
10713 | } | |
10714 | ||
10715 | pg_pool_t *pi = pending_inc.get_new_pool(pool_id, osdmap.get_pg_pool(pool_id)); | |
10716 | if (field == "max_objects") { | |
10717 | pi->quota_max_objects = value; | |
10718 | } else if (field == "max_bytes") { | |
10719 | pi->quota_max_bytes = value; | |
10720 | } else { | |
10721 | assert(0 == "unrecognized option"); | |
10722 | } | |
10723 | ss << "set-quota " << field << " = " << value << " for pool " << poolstr; | |
10724 | rs = ss.str(); | |
10725 | wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, 0, rs, | |
10726 | get_last_committed() + 1)); | |
10727 | return true; | |
c07f9fc5 FG |
10728 | } else if (prefix == "osd pool application enable" || |
10729 | prefix == "osd pool application disable" || | |
10730 | prefix == "osd pool application set" || | |
10731 | prefix == "osd pool application rm") { | |
10732 | err = prepare_command_pool_application(prefix, cmdmap, ss); | |
10733 | if (err == -EAGAIN) | |
10734 | goto wait; | |
10735 | if (err < 0) | |
10736 | goto reply; | |
7c673cae | 10737 | |
c07f9fc5 FG |
10738 | getline(ss, rs); |
10739 | wait_for_finished_proposal( | |
10740 | op, new Monitor::C_Command(mon, op, 0, rs, get_last_committed() + 1)); | |
10741 | return true; | |
7c673cae FG |
10742 | } else if (prefix == "osd reweight-by-pg" || |
10743 | prefix == "osd reweight-by-utilization" || | |
10744 | prefix == "osd test-reweight-by-pg" || | |
10745 | prefix == "osd test-reweight-by-utilization") { | |
10746 | bool by_pg = | |
10747 | prefix == "osd reweight-by-pg" || prefix == "osd test-reweight-by-pg"; | |
10748 | bool dry_run = | |
10749 | prefix == "osd test-reweight-by-pg" || | |
10750 | prefix == "osd test-reweight-by-utilization"; | |
10751 | int64_t oload; | |
10752 | cmd_getval(g_ceph_context, cmdmap, "oload", oload, int64_t(120)); | |
10753 | set<int64_t> pools; | |
10754 | vector<string> poolnamevec; | |
10755 | cmd_getval(g_ceph_context, cmdmap, "pools", poolnamevec); | |
10756 | for (unsigned j = 0; j < poolnamevec.size(); j++) { | |
10757 | int64_t pool = osdmap.lookup_pg_pool_name(poolnamevec[j]); | |
10758 | if (pool < 0) { | |
10759 | ss << "pool '" << poolnamevec[j] << "' does not exist"; | |
10760 | err = -ENOENT; | |
10761 | goto reply; | |
10762 | } | |
10763 | pools.insert(pool); | |
10764 | } | |
10765 | double max_change = g_conf->mon_reweight_max_change; | |
10766 | cmd_getval(g_ceph_context, cmdmap, "max_change", max_change); | |
10767 | if (max_change <= 0.0) { | |
10768 | ss << "max_change " << max_change << " must be positive"; | |
10769 | err = -EINVAL; | |
10770 | goto reply; | |
10771 | } | |
10772 | int64_t max_osds = g_conf->mon_reweight_max_osds; | |
10773 | cmd_getval(g_ceph_context, cmdmap, "max_osds", max_osds); | |
10774 | if (max_osds <= 0) { | |
10775 | ss << "max_osds " << max_osds << " must be positive"; | |
10776 | err = -EINVAL; | |
10777 | goto reply; | |
10778 | } | |
10779 | string no_increasing; | |
10780 | cmd_getval(g_ceph_context, cmdmap, "no_increasing", no_increasing); | |
10781 | string out_str; | |
10782 | mempool::osdmap::map<int32_t, uint32_t> new_weights; | |
31f18b77 FG |
10783 | err = mon->pgservice->reweight_by_utilization(osdmap, |
10784 | oload, | |
10785 | max_change, | |
10786 | max_osds, | |
10787 | by_pg, | |
10788 | pools.empty() ? NULL : &pools, | |
10789 | no_increasing == "--no-increasing", | |
10790 | &new_weights, | |
10791 | &ss, &out_str, f.get()); | |
7c673cae FG |
10792 | if (err >= 0) { |
10793 | dout(10) << "reweight::by_utilization: finished with " << out_str << dendl; | |
10794 | } | |
10795 | if (f) | |
10796 | f->flush(rdata); | |
10797 | else | |
10798 | rdata.append(out_str); | |
10799 | if (err < 0) { | |
10800 | ss << "FAILED reweight-by-pg"; | |
10801 | } else if (err == 0 || dry_run) { | |
10802 | ss << "no change"; | |
10803 | } else { | |
10804 | ss << "SUCCESSFUL reweight-by-pg"; | |
10805 | pending_inc.new_weight = std::move(new_weights); | |
10806 | wait_for_finished_proposal( | |
10807 | op, | |
10808 | new Monitor::C_Command(mon, op, 0, rs, rdata, get_last_committed() + 1)); | |
10809 | return true; | |
10810 | } | |
c07f9fc5 FG |
10811 | } else if (prefix == "osd force-create-pg") { |
10812 | pg_t pgid; | |
10813 | string pgidstr; | |
10814 | cmd_getval(g_ceph_context, cmdmap, "pgid", pgidstr); | |
10815 | if (!pgid.parse(pgidstr.c_str())) { | |
10816 | ss << "invalid pgid '" << pgidstr << "'"; | |
10817 | err = -EINVAL; | |
10818 | goto reply; | |
10819 | } | |
10820 | bool creating_now; | |
10821 | { | |
10822 | std::lock_guard<std::mutex> l(creating_pgs_lock); | |
10823 | auto emplaced = creating_pgs.pgs.emplace(pgid, | |
10824 | make_pair(osdmap.get_epoch(), | |
10825 | ceph_clock_now())); | |
10826 | creating_now = emplaced.second; | |
10827 | } | |
10828 | if (creating_now) { | |
10829 | ss << "pg " << pgidstr << " now creating, ok"; | |
10830 | err = 0; | |
10831 | goto update; | |
10832 | } else { | |
10833 | ss << "pg " << pgid << " already creating"; | |
10834 | err = 0; | |
10835 | goto reply; | |
10836 | } | |
7c673cae FG |
10837 | } else { |
10838 | err = -EINVAL; | |
10839 | } | |
10840 | ||
10841 | reply: | |
10842 | getline(ss, rs); | |
10843 | if (err < 0 && rs.length() == 0) | |
10844 | rs = cpp_strerror(err); | |
10845 | mon->reply_command(op, err, rs, rdata, get_last_committed()); | |
10846 | return ret; | |
10847 | ||
10848 | update: | |
10849 | getline(ss, rs); | |
10850 | wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, 0, rs, | |
10851 | get_last_committed() + 1)); | |
10852 | return true; | |
10853 | ||
10854 | wait: | |
10855 | wait_for_finished_proposal(op, new C_RetryMessage(this, op)); | |
10856 | return true; | |
10857 | } | |
10858 | ||
10859 | bool OSDMonitor::preprocess_pool_op(MonOpRequestRef op) | |
10860 | { | |
10861 | op->mark_osdmon_event(__func__); | |
10862 | MPoolOp *m = static_cast<MPoolOp*>(op->get_req()); | |
10863 | ||
10864 | if (m->fsid != mon->monmap->fsid) { | |
10865 | dout(0) << __func__ << " drop message on fsid " << m->fsid | |
10866 | << " != " << mon->monmap->fsid << " for " << *m << dendl; | |
10867 | _pool_op_reply(op, -EINVAL, osdmap.get_epoch()); | |
10868 | return true; | |
10869 | } | |
10870 | ||
10871 | if (m->op == POOL_OP_CREATE) | |
10872 | return preprocess_pool_op_create(op); | |
10873 | ||
10874 | if (!osdmap.get_pg_pool(m->pool)) { | |
10875 | dout(10) << "attempt to operate on non-existent pool id " << m->pool << dendl; | |
10876 | _pool_op_reply(op, 0, osdmap.get_epoch()); | |
10877 | return true; | |
10878 | } | |
10879 | ||
10880 | // check if the snap and snapname exist | |
10881 | bool snap_exists = false; | |
10882 | const pg_pool_t *p = osdmap.get_pg_pool(m->pool); | |
10883 | if (p->snap_exists(m->name.c_str())) | |
10884 | snap_exists = true; | |
10885 | ||
10886 | switch (m->op) { | |
10887 | case POOL_OP_CREATE_SNAP: | |
10888 | if (p->is_unmanaged_snaps_mode() || p->is_tier()) { | |
10889 | _pool_op_reply(op, -EINVAL, osdmap.get_epoch()); | |
10890 | return true; | |
10891 | } | |
10892 | if (snap_exists) { | |
10893 | _pool_op_reply(op, 0, osdmap.get_epoch()); | |
10894 | return true; | |
10895 | } | |
10896 | return false; | |
10897 | case POOL_OP_CREATE_UNMANAGED_SNAP: | |
10898 | if (p->is_pool_snaps_mode()) { | |
10899 | _pool_op_reply(op, -EINVAL, osdmap.get_epoch()); | |
10900 | return true; | |
10901 | } | |
10902 | return false; | |
10903 | case POOL_OP_DELETE_SNAP: | |
10904 | if (p->is_unmanaged_snaps_mode()) { | |
10905 | _pool_op_reply(op, -EINVAL, osdmap.get_epoch()); | |
10906 | return true; | |
10907 | } | |
10908 | if (!snap_exists) { | |
10909 | _pool_op_reply(op, 0, osdmap.get_epoch()); | |
10910 | return true; | |
10911 | } | |
10912 | return false; | |
10913 | case POOL_OP_DELETE_UNMANAGED_SNAP: | |
10914 | if (p->is_pool_snaps_mode()) { | |
10915 | _pool_op_reply(op, -EINVAL, osdmap.get_epoch()); | |
10916 | return true; | |
10917 | } | |
10918 | if (p->is_removed_snap(m->snapid)) { | |
10919 | _pool_op_reply(op, 0, osdmap.get_epoch()); | |
10920 | return true; | |
10921 | } | |
10922 | return false; | |
10923 | case POOL_OP_DELETE: | |
10924 | if (osdmap.lookup_pg_pool_name(m->name.c_str()) >= 0) { | |
10925 | _pool_op_reply(op, 0, osdmap.get_epoch()); | |
10926 | return true; | |
10927 | } | |
10928 | return false; | |
10929 | case POOL_OP_AUID_CHANGE: | |
10930 | return false; | |
10931 | default: | |
10932 | ceph_abort(); | |
10933 | break; | |
10934 | } | |
10935 | ||
10936 | return false; | |
10937 | } | |
10938 | ||
10939 | bool OSDMonitor::preprocess_pool_op_create(MonOpRequestRef op) | |
10940 | { | |
10941 | op->mark_osdmon_event(__func__); | |
10942 | MPoolOp *m = static_cast<MPoolOp*>(op->get_req()); | |
10943 | MonSession *session = m->get_session(); | |
10944 | if (!session) { | |
10945 | _pool_op_reply(op, -EPERM, osdmap.get_epoch()); | |
10946 | return true; | |
10947 | } | |
10948 | if (!session->is_capable("osd", MON_CAP_W)) { | |
10949 | dout(5) << "attempt to create new pool without sufficient auid privileges!" | |
10950 | << "message: " << *m << std::endl | |
10951 | << "caps: " << session->caps << dendl; | |
10952 | _pool_op_reply(op, -EPERM, osdmap.get_epoch()); | |
10953 | return true; | |
10954 | } | |
10955 | ||
10956 | int64_t pool = osdmap.lookup_pg_pool_name(m->name.c_str()); | |
10957 | if (pool >= 0) { | |
10958 | _pool_op_reply(op, 0, osdmap.get_epoch()); | |
10959 | return true; | |
10960 | } | |
10961 | ||
10962 | return false; | |
10963 | } | |
10964 | ||
10965 | bool OSDMonitor::prepare_pool_op(MonOpRequestRef op) | |
10966 | { | |
10967 | op->mark_osdmon_event(__func__); | |
10968 | MPoolOp *m = static_cast<MPoolOp*>(op->get_req()); | |
10969 | dout(10) << "prepare_pool_op " << *m << dendl; | |
10970 | if (m->op == POOL_OP_CREATE) { | |
10971 | return prepare_pool_op_create(op); | |
10972 | } else if (m->op == POOL_OP_DELETE) { | |
10973 | return prepare_pool_op_delete(op); | |
10974 | } | |
10975 | ||
10976 | int ret = 0; | |
10977 | bool changed = false; | |
10978 | ||
10979 | if (!osdmap.have_pg_pool(m->pool)) { | |
10980 | _pool_op_reply(op, -ENOENT, osdmap.get_epoch()); | |
10981 | return false; | |
10982 | } | |
10983 | ||
10984 | const pg_pool_t *pool = osdmap.get_pg_pool(m->pool); | |
10985 | ||
10986 | switch (m->op) { | |
10987 | case POOL_OP_CREATE_SNAP: | |
10988 | if (pool->is_tier()) { | |
10989 | ret = -EINVAL; | |
10990 | _pool_op_reply(op, ret, osdmap.get_epoch()); | |
10991 | return false; | |
10992 | } // else, fall through | |
10993 | case POOL_OP_DELETE_SNAP: | |
10994 | if (!pool->is_unmanaged_snaps_mode()) { | |
10995 | bool snap_exists = pool->snap_exists(m->name.c_str()); | |
10996 | if ((m->op == POOL_OP_CREATE_SNAP && snap_exists) | |
10997 | || (m->op == POOL_OP_DELETE_SNAP && !snap_exists)) { | |
10998 | ret = 0; | |
10999 | } else { | |
11000 | break; | |
11001 | } | |
11002 | } else { | |
11003 | ret = -EINVAL; | |
11004 | } | |
11005 | _pool_op_reply(op, ret, osdmap.get_epoch()); | |
11006 | return false; | |
11007 | ||
11008 | case POOL_OP_DELETE_UNMANAGED_SNAP: | |
11009 | // we won't allow removal of an unmanaged snapshot from a pool | |
11010 | // not in unmanaged snaps mode. | |
11011 | if (!pool->is_unmanaged_snaps_mode()) { | |
11012 | _pool_op_reply(op, -ENOTSUP, osdmap.get_epoch()); | |
11013 | return false; | |
11014 | } | |
11015 | /* fall-thru */ | |
11016 | case POOL_OP_CREATE_UNMANAGED_SNAP: | |
11017 | // but we will allow creating an unmanaged snapshot on any pool | |
11018 | // as long as it is not in 'pool' snaps mode. | |
11019 | if (pool->is_pool_snaps_mode()) { | |
11020 | _pool_op_reply(op, -EINVAL, osdmap.get_epoch()); | |
11021 | return false; | |
11022 | } | |
11023 | } | |
11024 | ||
11025 | // projected pool info | |
11026 | pg_pool_t pp; | |
11027 | if (pending_inc.new_pools.count(m->pool)) | |
11028 | pp = pending_inc.new_pools[m->pool]; | |
11029 | else | |
11030 | pp = *osdmap.get_pg_pool(m->pool); | |
11031 | ||
11032 | bufferlist reply_data; | |
11033 | ||
11034 | // pool snaps vs unmanaged snaps are mutually exclusive | |
11035 | switch (m->op) { | |
11036 | case POOL_OP_CREATE_SNAP: | |
11037 | case POOL_OP_DELETE_SNAP: | |
11038 | if (pp.is_unmanaged_snaps_mode()) { | |
11039 | ret = -EINVAL; | |
11040 | goto out; | |
11041 | } | |
11042 | break; | |
11043 | ||
11044 | case POOL_OP_CREATE_UNMANAGED_SNAP: | |
11045 | case POOL_OP_DELETE_UNMANAGED_SNAP: | |
11046 | if (pp.is_pool_snaps_mode()) { | |
11047 | ret = -EINVAL; | |
11048 | goto out; | |
11049 | } | |
11050 | } | |
11051 | ||
11052 | switch (m->op) { | |
11053 | case POOL_OP_CREATE_SNAP: | |
11054 | if (!pp.snap_exists(m->name.c_str())) { | |
11055 | pp.add_snap(m->name.c_str(), ceph_clock_now()); | |
11056 | dout(10) << "create snap in pool " << m->pool << " " << m->name << " seq " << pp.get_snap_epoch() << dendl; | |
11057 | changed = true; | |
11058 | } | |
11059 | break; | |
11060 | ||
11061 | case POOL_OP_DELETE_SNAP: | |
11062 | { | |
11063 | snapid_t s = pp.snap_exists(m->name.c_str()); | |
11064 | if (s) { | |
11065 | pp.remove_snap(s); | |
11066 | changed = true; | |
11067 | } | |
11068 | } | |
11069 | break; | |
11070 | ||
11071 | case POOL_OP_CREATE_UNMANAGED_SNAP: | |
11072 | { | |
11073 | uint64_t snapid; | |
11074 | pp.add_unmanaged_snap(snapid); | |
11075 | ::encode(snapid, reply_data); | |
11076 | changed = true; | |
11077 | } | |
11078 | break; | |
11079 | ||
11080 | case POOL_OP_DELETE_UNMANAGED_SNAP: | |
11081 | if (!pp.is_removed_snap(m->snapid)) { | |
11082 | pp.remove_unmanaged_snap(m->snapid); | |
11083 | changed = true; | |
11084 | } | |
11085 | break; | |
11086 | ||
11087 | case POOL_OP_AUID_CHANGE: | |
11088 | if (pp.auid != m->auid) { | |
11089 | pp.auid = m->auid; | |
11090 | changed = true; | |
11091 | } | |
11092 | break; | |
11093 | ||
11094 | default: | |
11095 | ceph_abort(); | |
11096 | break; | |
11097 | } | |
11098 | ||
11099 | if (changed) { | |
11100 | pp.set_snap_epoch(pending_inc.epoch); | |
11101 | pending_inc.new_pools[m->pool] = pp; | |
11102 | } | |
11103 | ||
11104 | out: | |
11105 | wait_for_finished_proposal(op, new OSDMonitor::C_PoolOp(this, op, ret, pending_inc.epoch, &reply_data)); | |
11106 | return true; | |
11107 | } | |
11108 | ||
11109 | bool OSDMonitor::prepare_pool_op_create(MonOpRequestRef op) | |
11110 | { | |
11111 | op->mark_osdmon_event(__func__); | |
11112 | int err = prepare_new_pool(op); | |
11113 | wait_for_finished_proposal(op, new OSDMonitor::C_PoolOp(this, op, err, pending_inc.epoch)); | |
11114 | return true; | |
11115 | } | |
11116 | ||
11117 | int OSDMonitor::_check_remove_pool(int64_t pool_id, const pg_pool_t& pool, | |
11118 | ostream *ss) | |
11119 | { | |
11120 | const string& poolstr = osdmap.get_pool_name(pool_id); | |
11121 | ||
11122 | // If the Pool is in use by CephFS, refuse to delete it | |
11123 | FSMap const &pending_fsmap = mon->mdsmon()->get_pending(); | |
11124 | if (pending_fsmap.pool_in_use(pool_id)) { | |
11125 | *ss << "pool '" << poolstr << "' is in use by CephFS"; | |
11126 | return -EBUSY; | |
11127 | } | |
11128 | ||
11129 | if (pool.tier_of >= 0) { | |
11130 | *ss << "pool '" << poolstr << "' is a tier of '" | |
11131 | << osdmap.get_pool_name(pool.tier_of) << "'"; | |
11132 | return -EBUSY; | |
11133 | } | |
11134 | if (!pool.tiers.empty()) { | |
11135 | *ss << "pool '" << poolstr << "' has tiers"; | |
11136 | for(auto tier : pool.tiers) { | |
11137 | *ss << " " << osdmap.get_pool_name(tier); | |
11138 | } | |
11139 | return -EBUSY; | |
11140 | } | |
11141 | ||
11142 | if (!g_conf->mon_allow_pool_delete) { | |
11143 | *ss << "pool deletion is disabled; you must first set the mon_allow_pool_delete config option to true before you can destroy a pool"; | |
11144 | return -EPERM; | |
11145 | } | |
11146 | ||
11147 | if (pool.has_flag(pg_pool_t::FLAG_NODELETE)) { | |
11148 | *ss << "pool deletion is disabled; you must unset nodelete flag for the pool first"; | |
11149 | return -EPERM; | |
11150 | } | |
11151 | ||
11152 | *ss << "pool '" << poolstr << "' removed"; | |
11153 | return 0; | |
11154 | } | |
11155 | ||
11156 | /** | |
11157 | * Check if it is safe to add a tier to a base pool | |
11158 | * | |
11159 | * @return | |
11160 | * True if the operation should proceed, false if we should abort here | |
11161 | * (abort doesn't necessarily mean error, could be idempotency) | |
11162 | */ | |
11163 | bool OSDMonitor::_check_become_tier( | |
11164 | const int64_t tier_pool_id, const pg_pool_t *tier_pool, | |
11165 | const int64_t base_pool_id, const pg_pool_t *base_pool, | |
11166 | int *err, | |
11167 | ostream *ss) const | |
11168 | { | |
11169 | const std::string &tier_pool_name = osdmap.get_pool_name(tier_pool_id); | |
11170 | const std::string &base_pool_name = osdmap.get_pool_name(base_pool_id); | |
11171 | ||
11172 | const FSMap &pending_fsmap = mon->mdsmon()->get_pending(); | |
11173 | if (pending_fsmap.pool_in_use(tier_pool_id)) { | |
11174 | *ss << "pool '" << tier_pool_name << "' is in use by CephFS"; | |
11175 | *err = -EBUSY; | |
11176 | return false; | |
11177 | } | |
11178 | ||
11179 | if (base_pool->tiers.count(tier_pool_id)) { | |
11180 | assert(tier_pool->tier_of == base_pool_id); | |
11181 | *err = 0; | |
11182 | *ss << "pool '" << tier_pool_name << "' is now (or already was) a tier of '" | |
11183 | << base_pool_name << "'"; | |
11184 | return false; | |
11185 | } | |
11186 | ||
11187 | if (base_pool->is_tier()) { | |
11188 | *ss << "pool '" << base_pool_name << "' is already a tier of '" | |
11189 | << osdmap.get_pool_name(base_pool->tier_of) << "', " | |
11190 | << "multiple tiers are not yet supported."; | |
11191 | *err = -EINVAL; | |
11192 | return false; | |
11193 | } | |
11194 | ||
11195 | if (tier_pool->has_tiers()) { | |
11196 | *ss << "pool '" << tier_pool_name << "' has following tier(s) already:"; | |
11197 | for (set<uint64_t>::iterator it = tier_pool->tiers.begin(); | |
11198 | it != tier_pool->tiers.end(); ++it) | |
11199 | *ss << "'" << osdmap.get_pool_name(*it) << "',"; | |
11200 | *ss << " multiple tiers are not yet supported."; | |
11201 | *err = -EINVAL; | |
11202 | return false; | |
11203 | } | |
11204 | ||
11205 | if (tier_pool->is_tier()) { | |
11206 | *ss << "tier pool '" << tier_pool_name << "' is already a tier of '" | |
11207 | << osdmap.get_pool_name(tier_pool->tier_of) << "'"; | |
11208 | *err = -EINVAL; | |
11209 | return false; | |
11210 | } | |
11211 | ||
11212 | *err = 0; | |
11213 | return true; | |
11214 | } | |
11215 | ||
11216 | ||
11217 | /** | |
11218 | * Check if it is safe to remove a tier from this base pool | |
11219 | * | |
11220 | * @return | |
11221 | * True if the operation should proceed, false if we should abort here | |
11222 | * (abort doesn't necessarily mean error, could be idempotency) | |
11223 | */ | |
11224 | bool OSDMonitor::_check_remove_tier( | |
11225 | const int64_t base_pool_id, const pg_pool_t *base_pool, | |
11226 | const pg_pool_t *tier_pool, | |
11227 | int *err, ostream *ss) const | |
11228 | { | |
11229 | const std::string &base_pool_name = osdmap.get_pool_name(base_pool_id); | |
11230 | ||
11231 | // Apply CephFS-specific checks | |
11232 | const FSMap &pending_fsmap = mon->mdsmon()->get_pending(); | |
11233 | if (pending_fsmap.pool_in_use(base_pool_id)) { | |
11234 | if (base_pool->type != pg_pool_t::TYPE_REPLICATED) { | |
11235 | // If the underlying pool is erasure coded, we can't permit the | |
11236 | // removal of the replicated tier that CephFS relies on to access it | |
11237 | *ss << "pool '" << base_pool_name << "' is in use by CephFS via its tier"; | |
11238 | *err = -EBUSY; | |
11239 | return false; | |
11240 | } | |
11241 | ||
11242 | if (tier_pool && tier_pool->cache_mode == pg_pool_t::CACHEMODE_WRITEBACK) { | |
11243 | *ss << "pool '" << base_pool_name << "' is in use by CephFS, and this " | |
11244 | "tier is still in use as a writeback cache. Change the cache " | |
11245 | "mode and flush the cache before removing it"; | |
11246 | *err = -EBUSY; | |
11247 | return false; | |
11248 | } | |
11249 | } | |
11250 | ||
11251 | *err = 0; | |
11252 | return true; | |
11253 | } | |
11254 | ||
11255 | int OSDMonitor::_prepare_remove_pool( | |
11256 | int64_t pool, ostream *ss, bool no_fake) | |
11257 | { | |
224ce89b | 11258 | dout(10) << __func__ << " " << pool << dendl; |
7c673cae FG |
11259 | const pg_pool_t *p = osdmap.get_pg_pool(pool); |
11260 | int r = _check_remove_pool(pool, *p, ss); | |
11261 | if (r < 0) | |
11262 | return r; | |
11263 | ||
11264 | auto new_pool = pending_inc.new_pools.find(pool); | |
11265 | if (new_pool != pending_inc.new_pools.end()) { | |
11266 | // if there is a problem with the pending info, wait and retry | |
11267 | // this op. | |
11268 | const auto& p = new_pool->second; | |
11269 | int r = _check_remove_pool(pool, p, ss); | |
11270 | if (r < 0) | |
11271 | return -EAGAIN; | |
11272 | } | |
11273 | ||
11274 | if (pending_inc.old_pools.count(pool)) { | |
224ce89b | 11275 | dout(10) << __func__ << " " << pool << " already pending removal" |
7c673cae FG |
11276 | << dendl; |
11277 | return 0; | |
11278 | } | |
11279 | ||
11280 | if (g_conf->mon_fake_pool_delete && !no_fake) { | |
11281 | string old_name = osdmap.get_pool_name(pool); | |
11282 | string new_name = old_name + "." + stringify(pool) + ".DELETED"; | |
11283 | dout(1) << __func__ << " faking pool deletion: renaming " << pool << " " | |
11284 | << old_name << " -> " << new_name << dendl; | |
11285 | pending_inc.new_pool_names[pool] = new_name; | |
11286 | return 0; | |
11287 | } | |
11288 | ||
11289 | // remove | |
11290 | pending_inc.old_pools.insert(pool); | |
11291 | ||
224ce89b | 11292 | // remove any pg_temp mappings for this pool |
7c673cae FG |
11293 | for (auto p = osdmap.pg_temp->begin(); |
11294 | p != osdmap.pg_temp->end(); | |
11295 | ++p) { | |
11296 | if (p->first.pool() == (uint64_t)pool) { | |
224ce89b | 11297 | dout(10) << __func__ << " " << pool << " removing obsolete pg_temp " |
7c673cae FG |
11298 | << p->first << dendl; |
11299 | pending_inc.new_pg_temp[p->first].clear(); | |
11300 | } | |
11301 | } | |
224ce89b | 11302 | // remove any primary_temp mappings for this pool |
7c673cae FG |
11303 | for (auto p = osdmap.primary_temp->begin(); |
11304 | p != osdmap.primary_temp->end(); | |
11305 | ++p) { | |
11306 | if (p->first.pool() == (uint64_t)pool) { | |
224ce89b | 11307 | dout(10) << __func__ << " " << pool |
7c673cae FG |
11308 | << " removing obsolete primary_temp" << p->first << dendl; |
11309 | pending_inc.new_primary_temp[p->first] = -1; | |
11310 | } | |
11311 | } | |
224ce89b WB |
11312 | // remove any pg_upmap mappings for this pool |
11313 | for (auto& p : osdmap.pg_upmap) { | |
11314 | if (p.first.pool() == (uint64_t)pool) { | |
11315 | dout(10) << __func__ << " " << pool | |
11316 | << " removing obsolete pg_upmap " | |
11317 | << p.first << dendl; | |
11318 | pending_inc.old_pg_upmap.insert(p.first); | |
11319 | } | |
11320 | } | |
11321 | // remove any pg_upmap_items mappings for this pool | |
11322 | for (auto& p : osdmap.pg_upmap_items) { | |
11323 | if (p.first.pool() == (uint64_t)pool) { | |
11324 | dout(10) << __func__ << " " << pool | |
11325 | << " removing obsolete pg_upmap_items " << p.first | |
11326 | << dendl; | |
11327 | pending_inc.old_pg_upmap_items.insert(p.first); | |
11328 | } | |
11329 | } | |
7c673cae FG |
11330 | return 0; |
11331 | } | |
11332 | ||
11333 | int OSDMonitor::_prepare_rename_pool(int64_t pool, string newname) | |
11334 | { | |
11335 | dout(10) << "_prepare_rename_pool " << pool << dendl; | |
11336 | if (pending_inc.old_pools.count(pool)) { | |
11337 | dout(10) << "_prepare_rename_pool " << pool << " pending removal" << dendl; | |
11338 | return -ENOENT; | |
11339 | } | |
11340 | for (map<int64_t,string>::iterator p = pending_inc.new_pool_names.begin(); | |
11341 | p != pending_inc.new_pool_names.end(); | |
11342 | ++p) { | |
11343 | if (p->second == newname && p->first != pool) { | |
11344 | return -EEXIST; | |
11345 | } | |
11346 | } | |
11347 | ||
11348 | pending_inc.new_pool_names[pool] = newname; | |
11349 | return 0; | |
11350 | } | |
11351 | ||
11352 | bool OSDMonitor::prepare_pool_op_delete(MonOpRequestRef op) | |
11353 | { | |
11354 | op->mark_osdmon_event(__func__); | |
11355 | MPoolOp *m = static_cast<MPoolOp*>(op->get_req()); | |
11356 | ostringstream ss; | |
11357 | int ret = _prepare_remove_pool(m->pool, &ss, false); | |
11358 | if (ret == -EAGAIN) { | |
11359 | wait_for_finished_proposal(op, new C_RetryMessage(this, op)); | |
11360 | return true; | |
11361 | } | |
11362 | if (ret < 0) | |
11363 | dout(10) << __func__ << " got " << ret << " " << ss.str() << dendl; | |
11364 | wait_for_finished_proposal(op, new OSDMonitor::C_PoolOp(this, op, ret, | |
11365 | pending_inc.epoch)); | |
11366 | return true; | |
11367 | } | |
11368 | ||
11369 | void OSDMonitor::_pool_op_reply(MonOpRequestRef op, | |
11370 | int ret, epoch_t epoch, bufferlist *blp) | |
11371 | { | |
11372 | op->mark_osdmon_event(__func__); | |
11373 | MPoolOp *m = static_cast<MPoolOp*>(op->get_req()); | |
11374 | dout(20) << "_pool_op_reply " << ret << dendl; | |
11375 | MPoolOpReply *reply = new MPoolOpReply(m->fsid, m->get_tid(), | |
11376 | ret, epoch, get_last_committed(), blp); | |
11377 | mon->send_reply(op, reply); | |
11378 | } |