]>
Commit | Line | Data |
---|---|---|
1e59de90 TL |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:nil -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | ||
4 | #pragma once | |
5 | ||
6 | #include <sys/types.h> | |
7 | #include <unistd.h> | |
8 | ||
9 | #include <iostream> | |
10 | #include <fstream> | |
11 | #include <random> | |
12 | ||
13 | #include <seastar/core/future.hh> | |
14 | ||
15 | #include "common/ceph_argparse.h" | |
16 | #include "include/expected.hpp" | |
17 | ||
18 | namespace crimson::osd { | |
19 | ||
20 | void usage(const char* prog); | |
21 | ||
22 | inline uint64_t get_nonce() | |
23 | { | |
24 | if (auto pid = getpid(); pid == 1 || std::getenv("CEPH_USE_RANDOM_NONCE")) { | |
25 | // we're running in a container; use a random number instead! | |
26 | std::random_device rd; | |
27 | std::default_random_engine rng{rd()}; | |
28 | return std::uniform_int_distribution<uint64_t>{}(rng); | |
29 | } else { | |
30 | return pid; | |
31 | } | |
32 | } | |
33 | ||
34 | seastar::future<> populate_config_from_mon(); | |
35 | ||
36 | struct early_config_t { | |
37 | std::vector<std::string> early_args; | |
38 | std::vector<std::string> ceph_args; | |
39 | ||
40 | std::string cluster_name{"ceph"}; | |
41 | std::string conf_file_list; | |
42 | CephInitParameters init_params{CEPH_ENTITY_TYPE_OSD}; | |
43 | ||
44 | /// Returned vector must not outlive in | |
45 | auto to_ptr_vector(const std::vector<std::string> &in) { | |
46 | std::vector<const char *> ret; | |
47 | ret.reserve(in.size()); | |
48 | std::transform( | |
49 | std::begin(in), std::end(in), | |
50 | std::back_inserter(ret), | |
51 | [](const auto &str) { return str.c_str(); }); | |
52 | return ret; | |
53 | } | |
54 | ||
55 | std::vector<const char *> get_early_args() { | |
56 | return to_ptr_vector(early_args); | |
57 | } | |
58 | ||
59 | std::vector<const char *> get_ceph_args() { | |
60 | return to_ptr_vector(ceph_args); | |
61 | } | |
62 | ||
63 | void encode(ceph::buffer::list& bl) const { | |
64 | ENCODE_START(1, 1, bl); | |
65 | encode(early_args, bl); | |
66 | encode(ceph_args, bl); | |
67 | encode(cluster_name, bl); | |
68 | encode(conf_file_list, bl); | |
69 | encode(init_params, bl); | |
70 | ENCODE_FINISH(bl); | |
71 | } | |
72 | ||
73 | void decode(ceph::buffer::list::const_iterator& bl) { | |
74 | DECODE_START(1, bl); | |
75 | decode(early_args, bl); | |
76 | decode(ceph_args, bl); | |
77 | decode(cluster_name, bl); | |
78 | decode(conf_file_list, bl); | |
79 | decode(init_params, bl); | |
80 | DECODE_FINISH(bl); | |
81 | } | |
82 | }; | |
83 | ||
84 | /** | |
85 | * get_early_config | |
86 | * | |
87 | * Compile initial configuration information from command line arguments, | |
88 | * config files, and monitors. | |
89 | * | |
90 | * This implementation forks off a worker process to do this work and must | |
91 | * therefore be called very early in main(). (See implementation for an | |
92 | * explanation). | |
93 | */ | |
94 | tl::expected<early_config_t, int> | |
95 | get_early_config(int argc, const char *argv[]); | |
96 | ||
97 | } | |
98 | ||
99 | WRITE_CLASS_ENCODER(crimson::osd::early_config_t) |