]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crushtool: grammar?
authorSage Weil <sage@newdream.net>
Thu, 20 Mar 2008 20:44:36 +0000 (13:44 -0700)
committerSage Weil <sage@newdream.net>
Thu, 20 Mar 2008 20:44:36 +0000 (13:44 -0700)
src/crush/grammar.h
src/crush/old_sample.txt [new file with mode: 0644]
src/crush/sample.txt

index eaa7ecf808846e2db5d3e7d4aa25641582aefc32..3ec4b30134b35fd08b750b496620db186d8d0787 100644 (file)
@@ -24,16 +24,96 @@ struct crush_grammar : public grammar<crush_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 <typename ScannerT>
   struct definition
   {
+    rule<ScannerT, parser_context<>, parser_tag<expressionID> >   expression;
+    rule<ScannerT, parser_context<>, parser_tag<termID> >         term;
+    rule<ScannerT, parser_context<>, parser_tag<factorID> >       factor;
+    rule<ScannerT, parser_context<>, parser_tag<integerID> >      integer;
+
+    rule<ScannerT, parser_context<>, parser_tag<_posint> >      posint;
+    rule<ScannerT, parser_context<>, parser_tag<_name> >      name;
+
+    rule<ScannerT, parser_context<>, parser_tag<_device> >      device;
+
+    rule<ScannerT, parser_context<>, parser_tag<_bucket_type> >      bucket_type;
+
+    rule<ScannerT, parser_context<>, parser_tag<_bucket_id> >      bucket_id;
+    rule<ScannerT, parser_context<>, parser_tag<_bucket_alg> >      bucket_alg;
+    rule<ScannerT, parser_context<>, parser_tag<_bucket_item> >      bucket_item;
+    rule<ScannerT, parser_context<>, parser_tag<_bucket> >      bucket;
+
+    rule<ScannerT, parser_context<>, parser_tag<_step_take> >      step_take;
+    rule<ScannerT, parser_context<>, parser_tag<_step_choose_firstn> >      step_choose_firstn;
+    rule<ScannerT, parser_context<>, parser_tag<_step_choose_indep> >      step_choose_indep;
+    rule<ScannerT, parser_context<>, parser_tag<_step_emit> >      step_emit;
+    rule<ScannerT, parser_context<>, parser_tag<_step> >      step;
+    rule<ScannerT, parser_context<>, parser_tag<_crushrule> >      crushrule;
+
+    rule<ScannerT, parser_context<>, 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<crush_grammar>
       BOOST_SPIRIT_DEBUG_RULE(expression);
     }
     
-    rule<ScannerT, parser_context<>, parser_tag<expressionID> >   expression;
-    rule<ScannerT, parser_context<>, parser_tag<termID> >         term;
-    rule<ScannerT, parser_context<>, parser_tag<factorID> >       factor;
-    rule<ScannerT, parser_context<>, parser_tag<integerID> >      integer;
-    
-    rule<ScannerT, parser_context<>, parser_tag<expressionID> > const&
+    rule<ScannerT, parser_context<>, parser_tag<expressionID> > const& 
     start() const { return expression; }
   };
 };
diff --git a/src/crush/old_sample.txt b/src/crush/old_sample.txt
new file mode 100644 (file)
index 0000000..e138428
--- /dev/null
@@ -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;
+}
index 54cf06a7bc4ddbfde171ab52a1642c26bded9703..d74ec2b8e6fda8592775add4952d4ca8523bd8f9 100644 (file)
@@ -1,82 +1,35 @@
 
-# first define our types
-<types>
-       <type osd>
-          type_id = 0
-       </type>
-       <type cab>
-          type_id = 2
-       </type>
-       <type row>
-          type_id = 3
-       </type>
-       <type pool>
-          type_id = 10
-       </type>
-</types>
+# 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
-<devices>
-       <osd osd001>
-               id 1
-               weight 500
-       </osd>
-       <osd osd002>
-               id 2
-               weight 500
-       </osd>
-       <osd osd003>
-               id 3
-               weight 500
-       </osd>
-       <osd osd004>
-               id 4
-               weight 500
-       </osd>
-       <osd osd005>
-               id 5
-               weight 500
-       </osd>
-</devices>
+buckettype 2 cab
+buckettype 3 row
+buckettype 10 pool
 
-<buckets>
-       <cab cab-d2>
-               alg straw
-               id   -12
-               <item osd001/>
-               <item osd002/>
-               <item osd003/>
-               <item osd004>
-                     weight 600
-               </item>
-       </cab>
-       
-#      <pool newlayout>
-#              <item satapool>
-#                      weight 1.0
-#              </item>
-#              <item fcpool>
-#                      weight 3.0
-#              </item>
-#      </pool>
-</buckets>
-
-<devices>
-       <osd osd006>
-               id 5
-               weight 500
-       </osd>
-</devices>
+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
-<rules>
-       <rule normal>
-               pool 0
-               type replicated
-               min_size 1
-               mix_size 4
-               step take root
-               step choose_indep 0 osd
-               step emit
-       </rule>
-</rules>
+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
+}