summaryrefslogtreecommitdiffstats
path: root/src/crimson/osd/main_config_bootstrap_helpers.h
blob: 7c6131d172c08e42509b029fcf7f40dda18546e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:nil -*-
// vim: ts=8 sw=2 smarttab

#pragma once

#include <sys/types.h>
#include <unistd.h>

#include <iostream>
#include <fstream>
#include <random>

#include <seastar/core/future.hh>

#include "common/ceph_argparse.h"
#include "include/expected.hpp"

namespace crimson::osd {

void usage(const char* prog);

inline uint64_t get_nonce()
{
  if (auto pid = getpid(); pid == 1 || std::getenv("CEPH_USE_RANDOM_NONCE")) {
    // we're running in a container; use a random number instead!
    std::random_device rd;
    std::default_random_engine rng{rd()};
    return std::uniform_int_distribution<uint64_t>{}(rng);
  } else {
    return pid;
  }
}

seastar::future<> populate_config_from_mon();

struct early_config_t {
  std::vector<std::string> early_args;
  std::vector<std::string> ceph_args;

  std::string cluster_name{"ceph"};
  std::string conf_file_list;
  CephInitParameters init_params{CEPH_ENTITY_TYPE_OSD};

  /// Returned vector must not outlive in
  auto to_ptr_vector(const std::vector<std::string> &in) {
    std::vector<const char *> ret;
    ret.reserve(in.size());
    std::transform(
      std::begin(in), std::end(in),
      std::back_inserter(ret),
      [](const auto &str) { return str.c_str(); });
    return ret;
  }

  std::vector<const char *> get_early_args() {
    return to_ptr_vector(early_args);
  }

  std::vector<const char *> get_ceph_args() {
    return to_ptr_vector(ceph_args);
  }

  void encode(ceph::buffer::list& bl) const {
    ENCODE_START(1, 1, bl);
    encode(early_args, bl);
    encode(ceph_args, bl);
    encode(cluster_name, bl);
    encode(conf_file_list, bl);
    encode(init_params, bl);
    ENCODE_FINISH(bl);
  }

  void decode(ceph::buffer::list::const_iterator& bl) {
    DECODE_START(1, bl);
    decode(early_args, bl);
    decode(ceph_args, bl);
    decode(cluster_name, bl);
    decode(conf_file_list, bl);
    decode(init_params, bl);
    DECODE_FINISH(bl);
  }
};

/**
 * get_early_config
 *
 * Compile initial configuration information from command line arguments,
 * config files, and monitors.
 *
 * This implementation forks off a worker process to do this work and must
 * therefore be called very early in main().  (See implementation for an
 * explanation).
 */
tl::expected<early_config_t, int>
get_early_config(int argc, const char *argv[]);

}

WRITE_CLASS_ENCODER(crimson::osd::early_config_t)