From 40e0c7bbd30e56970c18c78e9b7df795eabf7cac Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 20 Mar 2008 13:44:36 -0700 Subject: [PATCH] crushtool: grammar? --- src/crush/grammar.h | 89 ++++++++++++++++++++++++++++++--- src/crush/old_sample.txt | 37 ++++++++++++++ src/crush/sample.txt | 105 +++++++++++---------------------------- 3 files changed, 148 insertions(+), 83 deletions(-) create mode 100644 src/crush/old_sample.txt diff --git a/src/crush/grammar.h b/src/crush/grammar.h index eaa7ecf808846..3ec4b30134b35 100644 --- a/src/crush/grammar.h +++ b/src/crush/grammar.h @@ -24,16 +24,96 @@ struct crush_grammar : public grammar static const int termID = 3; static const int expressionID = 4; + static const int _posint = 10; + static const int _name = 11; + static const int _device = 12; + static const int _bucket_type = 13; + static const int _bucket_id = 14; + static const int _bucket_alg = 15; + static const int _bucket_item = 16; + static const int _bucket = 17; + + static const int _step_take = 18; + static const int _step_choose_firstn = 19; + static const int _step_choose_indep = 20; + static const int _step_emit = 21; + static const int _step = 22; + static const int _crushrule = 23; + + static const int _crushmap = 23; + template struct definition { + rule, parser_tag > expression; + rule, parser_tag > term; + rule, parser_tag > factor; + rule, parser_tag > integer; + + rule, parser_tag<_posint> > posint; + rule, parser_tag<_name> > name; + + rule, parser_tag<_device> > device; + + rule, parser_tag<_bucket_type> > bucket_type; + + rule, parser_tag<_bucket_id> > bucket_id; + rule, parser_tag<_bucket_alg> > bucket_alg; + rule, parser_tag<_bucket_item> > bucket_item; + rule, parser_tag<_bucket> > bucket; + + rule, parser_tag<_step_take> > step_take; + rule, parser_tag<_step_choose_firstn> > step_choose_firstn; + rule, parser_tag<_step_choose_indep> > step_choose_indep; + rule, parser_tag<_step_emit> > step_emit; + rule, parser_tag<_step> > step; + rule, parser_tag<_crushrule> > crushrule; + + rule, parser_tag<_crushmap> > crushmap; + definition(crush_grammar const& /*self*/) { - // Start grammar definition + // base types integer = leaf_node_d[ lexeme_d[ (!ch_p('-') >> +digit_p) ] ]; + posint = leaf_node_d[ lexeme_d[ +digit_p ] ]; + name = +alnum_p; + + // devices + device = str_p("device") >> posint >> name >> *(str_p("overload") >> real_p); + + // bucket types + bucket_type = str_p("buckettype") >> posint >> name; + + // buckets + bucket_id = str_p("id") >> ch_p('-') >> posint; + bucket_alg = str_p("alg") >> ( str_p("uniform") | str_p("list") | str_p("tree") | str_p("straw") ); + bucket_item = str_p("item") >> name + >> !( str_p("weight") >> real_p ) + >> !( str_p("pos") >> posint ); + bucket = name >> name >> '{' >> !bucket_id >> bucket_alg >> *bucket_item >> '}'; + // rules + step_take = str_p("take") >> str_p("root"); + step_choose_indep = str_p("choose_indep") >> integer >> name; + step_choose_firstn = str_p("choose_firstn") >> integer >> name; + step_emit = str_p("emit"); + step = str_p("step") >> ( step_take | step_choose_indep | step_choose_firstn | step_emit ); + crushrule = str_p("rule") >> name >> '{' + >> str_p("pool") >> posint + >> str_p("type") >> ( str_p("replicated") | str_p("raid4") ) + >> str_p("min_size") >> posint + >> str_p("max_size") >> posint + >> +step + >> '}'; + + // the whole crush map + crushmap = *(device | bucket_type) >> *bucket >> *crushrule; + + + + // Start grammar definition factor = integer | inner_node_d[ch_p('(') >> expression >> ch_p(')')] | (root_node_d[ch_p('-')] >> factor); @@ -56,12 +136,7 @@ struct crush_grammar : public grammar BOOST_SPIRIT_DEBUG_RULE(expression); } - rule, parser_tag > expression; - rule, parser_tag > term; - rule, parser_tag > factor; - rule, parser_tag > integer; - - rule, parser_tag > const& + rule, parser_tag > const& start() const { return expression; } }; }; diff --git a/src/crush/old_sample.txt b/src/crush/old_sample.txt new file mode 100644 index 0000000000000..e138428982af4 --- /dev/null +++ b/src/crush/old_sample.txt @@ -0,0 +1,37 @@ + +# types +type osd 0 +type cab 2 +type row 3 +type pool 10 + +# devices +device osd001 { + id 1; + weight 500; # optional +} +device cosd002 { id 2; weight 300; } +device cosd003 { id 3; } +device cosd004 { id 4; } +device cosd005 { id 5; } + +# hierarchy +bucket cab-d2 type cab { + id -1; # optional + alg straw; + item osd001; + item osd002 weight 600; + item osd003 weight 600; + item osd004 weight 600; + item osd005 weight 600; +} + +rule normal { + pool 0; + type replicated; + min_size 1; + max_size 4; + step take(root); + step choose_indep(0, osd); + step emit; +} diff --git a/src/crush/sample.txt b/src/crush/sample.txt index 54cf06a7bc4dd..d74ec2b8e6fda 100644 --- a/src/crush/sample.txt +++ b/src/crush/sample.txt @@ -1,82 +1,35 @@ -# first define our types - - - type_id = 0 - - - type_id = 2 - - - type_id = 3 - - - type_id = 10 - - +# devices +device 1 osd001 +device 2 osd002 +device 3 osd003 +device 4 osd004 overload 0 # 0.0 -> normal, 1.0 -> failed +device 5 osd005 overload .1 # hierarchy - - - id 1 - weight 500 - - - id 2 - weight 500 - - - id 3 - weight 500 - - - id 4 - weight 500 - - - id 5 - weight 500 - - +buckettype 2 cab +buckettype 3 row +buckettype 10 pool - - - alg straw - id -12 - - - - - weight 600 - - - -# -# -# weight 1.0 -# -# -# weight 3.0 -# -# - - - - - id 5 - weight 500 - - +cab cab-d2 { + id -1 # optional + alg straw # required + item osd001 + item osd002 weight 600 pos 1 + item osd003 weight 600 pos 2 + item osd004 weight 600 pos 3 + item osd005 pos 4 weight 600 +} # rules - - - pool 0 - type replicated - min_size 1 - mix_size 4 - step take root - step choose_indep 0 osd - step emit - - +rule normal { + # these are required. + pool 0 + type replicated + min_size 1 + max_size 4 + # need 1 or more of these. + step take root + step choose_indep 0 osd + step emit +} -- 2.39.5