]> git.proxmox.com Git - ceph.git/blame - ceph/src/crush/CrushCompiler.h
update sources to v12.1.4
[ceph.git] / ceph / src / crush / CrushCompiler.h
CommitLineData
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#ifndef CEPH_CRUSH_COMPILER_H
5#define CEPH_CRUSH_COMPILER_H
6
7#include "crush/CrushWrapper.h"
8#include "crush/grammar.h"
9
10#include <map>
31f18b77 11#include <iostream>
7c673cae
FG
12
13class CrushCompiler {
14 CrushWrapper& crush;
15 ostream& err;
16 int verbose;
17 bool unsafe_tunables;
18
19 // decompile
20 enum dcb_state_t {
21 DCB_STATE_IN_PROGRESS = 0,
22 DCB_STATE_DONE
23 };
24
25 int decompile_weight_set_weights(crush_weight_set weight_set,
26 ostream &out);
27 int decompile_weight_set(crush_weight_set *weight_set,
28 __u32 size,
29 ostream &out);
30 int decompile_choose_arg(crush_choose_arg *arg,
31 int bucket_id,
32 ostream &out);
33 int decompile_ids(int *ids,
34 __u32 size,
35 ostream &out);
36 int decompile_choose_arg_map(crush_choose_arg_map arg_map,
37 ostream &out);
38 int decompile_choose_args(const std::pair<const long unsigned int, crush_choose_arg_map> &i,
39 ostream &out);
40 int decompile_bucket_impl(int i, ostream &out);
41 int decompile_bucket(int cur,
42 std::map<int, dcb_state_t>& dcb_states,
43 ostream &out);
44
45 // compile
46 typedef char const* iterator_t;
47 typedef tree_match<iterator_t> parse_tree_match_t;
48 typedef parse_tree_match_t::tree_iterator iter_t;
49 typedef parse_tree_match_t::node_t node_t;
50
51 map<string, int> item_id;
52 map<int, string> id_item;
53 map<int, unsigned> item_weight;
54 map<string, int> type_id;
55 map<string, int> rule_id;
d2e6a577 56 std::map<int32_t, map<int32_t, int32_t> > class_bucket; // bucket id -> class id -> shadow bucket id
7c673cae
FG
57
58 string string_node(node_t &node);
59 int int_node(node_t &node);
60 float float_node(node_t &node);
61
62 int parse_tunable(iter_t const& i);
63 int parse_device(iter_t const& i);
64 int parse_bucket_type(iter_t const& i);
65 int parse_bucket(iter_t const& i);
66 int parse_rule(iter_t const& i);
67 int parse_weight_set_weights(iter_t const& i, int bucket_id, crush_weight_set *weight_set);
68 int parse_weight_set(iter_t const& i, int bucket_id, crush_choose_arg *arg);
69 int parse_choose_arg_ids(iter_t const& i, int bucket_id, crush_choose_arg *args);
70 int parse_choose_arg(iter_t const& i, crush_choose_arg *args);
71 int parse_choose_args(iter_t const& i);
72 void find_used_bucket_ids(iter_t const& i);
73 int parse_crush(iter_t const& i);
74 void dump(iter_t const& i, int ind=1);
75 string consolidate_whitespace(string in);
76 int adjust_bucket_item_place(iter_t const &i);
77
78public:
79 CrushCompiler(CrushWrapper& c, ostream& eo, int verbosity=0)
80 : crush(c), err(eo), verbose(verbosity),
81 unsafe_tunables(false) {}
82 ~CrushCompiler() {}
83
84 void enable_unsafe_tunables() {
85 unsafe_tunables = true;
86 }
87
88 int decompile(ostream& out);
89 int compile(istream& in, const char *infn=0);
90};
91
92#endif