]> git.proxmox.com Git - ceph.git/blame - ceph/src/crush/grammar.h
import quincy beta 17.1.0
[ceph.git] / ceph / src / crush / grammar.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 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2004-2008 Sage Weil <sage@newdream.net>
7 *
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
12 *
13 */
14
15#ifndef CEPH_CRUSH_GRAMMAR_H
16#define CEPH_CRUSH_GRAMMAR_H
17
18//#define BOOST_SPIRIT_DEBUG
19
20#ifdef USE_BOOST_SPIRIT_OLD_HDR
21#include <boost/spirit/core.hpp>
22#include <boost/spirit/tree/ast.hpp>
23#include <boost/spirit/tree/tree_to_xml.hpp>
24#else
25#define BOOST_SPIRIT_USE_OLD_NAMESPACE
26#include <boost/spirit/include/classic_core.hpp>
27#include <boost/spirit/include/classic_ast.hpp>
28#include <boost/spirit/include/classic_tree_to_xml.hpp>
29#endif
30using namespace boost::spirit;
31
9f95a23c 32struct crush_grammar : public boost::spirit::grammar<crush_grammar>
7c673cae
FG
33{
34 enum {
35 _int = 1,
36 _posint,
37 _negint,
38 _name,
39 _device,
40 _bucket_type,
41 _bucket_id,
42 _bucket_alg,
43 _bucket_hash,
44 _bucket_item,
45 _bucket,
46 _step_take,
47 _step_set_chooseleaf_tries,
48 _step_set_chooseleaf_vary_r,
49 _step_set_chooseleaf_stable,
50 _step_set_choose_tries,
51 _step_set_choose_local_tries,
52 _step_set_choose_local_fallback_tries,
53 _step_choose,
54 _step_chooseleaf,
55 _step_emit,
56 _step,
57 _crushrule,
58 _weight_set_weights,
59 _weight_set,
60 _choose_arg_ids,
61 _choose_arg,
62 _choose_args,
63 _crushmap,
64 _tunable,
65 };
66
67 template <typename ScannerT>
68 struct definition
69 {
9f95a23c
TL
70 boost::spirit::rule<ScannerT, boost::spirit::parser_context<>,boost::spirit::parser_tag<_int> > integer;
71 boost::spirit::rule<ScannerT, boost::spirit::parser_context<>, boost::spirit::parser_tag<_posint> > posint;
72 boost::spirit::rule<ScannerT, boost::spirit::parser_context<>, boost::spirit::parser_tag<_negint> > negint;
73 boost::spirit::rule<ScannerT, boost::spirit::parser_context<>, boost::spirit::parser_tag<_name> > name;
74
75 boost::spirit::rule<ScannerT, boost::spirit::parser_context<>, boost::spirit::parser_tag<_tunable> > tunable;
76
77 boost::spirit::rule<ScannerT, boost::spirit::parser_context<>, boost::spirit::parser_tag<_device> > device;
78
79 boost::spirit::rule<ScannerT, boost::spirit::parser_context<>, boost::spirit::parser_tag<_bucket_type> > bucket_type;
80
81 boost::spirit::rule<ScannerT, boost::spirit::parser_context<>, boost::spirit::parser_tag<_bucket_id> > bucket_id;
82 boost::spirit::rule<ScannerT, boost::spirit::parser_context<>, boost::spirit::parser_tag<_bucket_alg> > bucket_alg;
83 boost::spirit::rule<ScannerT, boost::spirit::parser_context<>, boost::spirit::parser_tag<_bucket_hash> > bucket_hash;
84 boost::spirit::rule<ScannerT, boost::spirit::parser_context<>, boost::spirit::parser_tag<_bucket_item> > bucket_item;
85 boost::spirit::rule<ScannerT, boost::spirit::parser_context<>, boost::spirit::parser_tag<_bucket> > bucket;
86
87 boost::spirit::rule<ScannerT, boost::spirit::parser_context<>, boost::spirit::parser_tag<_step_take> > step_take;
88 boost::spirit::rule<ScannerT, boost::spirit::parser_context<>, boost::spirit::parser_tag<_step_set_choose_tries> > step_set_choose_tries;
89 boost::spirit::rule<ScannerT, boost::spirit::parser_context<>, boost::spirit::parser_tag<_step_set_choose_local_tries> > step_set_choose_local_tries;
90 boost::spirit::rule<ScannerT, boost::spirit::parser_context<>, boost::spirit::parser_tag<_step_set_choose_local_fallback_tries> > step_set_choose_local_fallback_tries;
91 boost::spirit::rule<ScannerT, boost::spirit::parser_context<>, boost::spirit::parser_tag<_step_set_chooseleaf_tries> > step_set_chooseleaf_tries;
92 boost::spirit::rule<ScannerT, boost::spirit::parser_context<>, boost::spirit::parser_tag<_step_set_chooseleaf_vary_r> > step_set_chooseleaf_vary_r;
93 boost::spirit::rule<ScannerT, boost::spirit::parser_context<>, boost::spirit::parser_tag<_step_set_chooseleaf_stable> > step_set_chooseleaf_stable;
94 boost::spirit::rule<ScannerT, boost::spirit::parser_context<>, boost::spirit::parser_tag<_step_choose> > step_choose;
95 boost::spirit::rule<ScannerT, boost::spirit::parser_context<>, boost::spirit::parser_tag<_step_chooseleaf> > step_chooseleaf;
96 boost::spirit::rule<ScannerT, boost::spirit::parser_context<>, boost::spirit::parser_tag<_step_emit> > step_emit;
97 boost::spirit::rule<ScannerT, boost::spirit::parser_context<>, boost::spirit::parser_tag<_step> > step;
98 boost::spirit::rule<ScannerT, boost::spirit::parser_context<>, boost::spirit::parser_tag<_crushrule> > crushrule;
99 boost::spirit::rule<ScannerT, boost::spirit::parser_context<>, boost::spirit::parser_tag<_weight_set_weights> > weight_set_weights;
100 boost::spirit::rule<ScannerT, boost::spirit::parser_context<>, boost::spirit::parser_tag<_weight_set> > weight_set;
101 boost::spirit::rule<ScannerT, boost::spirit::parser_context<>, boost::spirit::parser_tag<_choose_arg_ids> > choose_arg_ids;
102 boost::spirit::rule<ScannerT, boost::spirit::parser_context<>, boost::spirit::parser_tag<_choose_arg> > choose_arg;
103 boost::spirit::rule<ScannerT, boost::spirit::parser_context<>, boost::spirit::parser_tag<_choose_args> > choose_args;
104
105 boost::spirit::rule<ScannerT, boost::spirit::parser_context<>, boost::spirit::parser_tag<_crushmap> > crushmap;
7c673cae
FG
106
107 definition(crush_grammar const& /*self*/)
108 {
9f95a23c
TL
109 using boost::spirit::leaf_node_d;
110 using boost::spirit::lexeme_d;
111 using boost::spirit::str_p;
112 using boost::spirit::ch_p;
113 using boost::spirit::digit_p;
114 using boost::spirit::alnum_p;
115 using boost::spirit::real_p;
116
7c673cae
FG
117 // base types
118 integer = leaf_node_d[ lexeme_d[
119 (!ch_p('-') >> +digit_p)
120 ] ];
121 posint = leaf_node_d[ lexeme_d[ +digit_p ] ];
122 negint = leaf_node_d[ lexeme_d[ ch_p('-') >> +digit_p ] ];
123 name = leaf_node_d[ lexeme_d[ +( alnum_p || ch_p('-') || ch_p('_') || ch_p('.')) ] ];
124
125 // tunables
126 tunable = str_p("tunable") >> name >> posint;
127
128 // devices
129 device = str_p("device") >> posint >> name >> !( str_p("class") >> name );
130
131 // bucket types
132 bucket_type = str_p("type") >> posint >> name;
133
134 // buckets
135 bucket_id = str_p("id") >> negint >> !( str_p("class") >> name );
136 bucket_alg = str_p("alg") >> name;
137 bucket_hash = str_p("hash") >> ( integer |
138 str_p("rjenkins1") );
139 bucket_item = str_p("item") >> name
140 >> !( str_p("weight") >> real_p )
141 >> !( str_p("pos") >> posint );
142 bucket = name >> name >> '{' >> *bucket_id >> bucket_alg >> *bucket_hash >> *bucket_item >> '}';
143
144 // rules
145 step_take = str_p("take") >> name >> !( str_p("class") >> name );
146 step_set_choose_tries = str_p("set_choose_tries") >> posint;
147 step_set_choose_local_tries = str_p("set_choose_local_tries") >> posint;
148 step_set_choose_local_fallback_tries = str_p("set_choose_local_fallback_tries") >> posint;
149 step_set_chooseleaf_tries = str_p("set_chooseleaf_tries") >> posint;
150 step_set_chooseleaf_vary_r = str_p("set_chooseleaf_vary_r") >> posint;
151 step_set_chooseleaf_stable = str_p("set_chooseleaf_stable") >> posint;
152 step_choose = str_p("choose")
153 >> ( str_p("indep") | str_p("firstn") )
154 >> integer
155 >> str_p("type") >> name;
156 step_chooseleaf = str_p("chooseleaf")
157 >> ( str_p("indep") | str_p("firstn") )
158 >> integer
159 >> str_p("type") >> name;
160 step_emit = str_p("emit");
161 step = str_p("step") >> ( step_take |
162 step_set_choose_tries |
163 step_set_choose_local_tries |
164 step_set_choose_local_fallback_tries |
165 step_set_chooseleaf_tries |
166 step_set_chooseleaf_vary_r |
167 step_set_chooseleaf_stable |
168 step_choose |
169 step_chooseleaf |
170 step_emit );
171 crushrule = str_p("rule") >> !name >> '{'
c07f9fc5 172 >> (str_p("id") | str_p("ruleset")) >> posint
20effc67
TL
173 >> str_p("type") >> ( str_p("replicated") | str_p("erasure") )
174 >> !(str_p("min_size") >> posint)
175 >> !(str_p("max_size") >> posint)
7c673cae
FG
176 >> +step
177 >> '}';
178
179 weight_set_weights = str_p("[") >> *real_p >> str_p("]");
180 weight_set = str_p("weight_set") >> str_p("[")
181 >> *weight_set_weights
182 >> str_p("]");
183 choose_arg_ids = str_p("ids") >> str_p("[") >> *integer >> str_p("]");
184 choose_arg = str_p("{") >> str_p("bucket_id") >> negint
185 >> !weight_set
186 >> !choose_arg_ids
187 >> str_p("}");
188 choose_args = str_p("choose_args") >> posint >> str_p("{") >> *choose_arg >> str_p("}");
189
190 // the whole crush map
191 crushmap = *(tunable | device | bucket_type) >> *(bucket | crushrule) >> *choose_args;
192 }
193
9f95a23c
TL
194 boost::spirit::rule<ScannerT, boost::spirit::parser_context<>,
195 boost::spirit::parser_tag<_crushmap> > const&
7c673cae
FG
196 start() const { return crushmap; }
197 };
198};
199
200#endif