Upload Tizen:Main source
[external/augeas.git] / lenses / multipath.aug
1 (* Process /etc/multipath.conf                             *)
2 (* The lens is based on the multipath.conf(5) man page     *)
3 module Multipath =
4
5 autoload xfm
6
7 let comment = Util.comment
8 let empty = Util.empty
9 let dels = Util.del_str
10 let eol = Util.eol
11
12 let ws = del /[ \t]+/ " "
13 let indent = del /[ \t]*/ ""
14 (* We require that braces are always followed by a newline *)
15 let obr = del /\{([ \t]*)\n/ "{\n"
16 let cbr = del /[ \t]*}[ \t]*\n/ "}\n"
17
18 let ikey (k:regexp) = indent . key k
19
20 let section (n:regexp) (b:lens) =
21   [ ikey n . ws . obr . (b|empty|comment)* . cbr ]
22
23 let kv (k:regexp) (v:regexp) =
24   [ ikey k . ws . store v . eol ]
25
26 (* FIXME: it would be much more concise to write                       *)
27 (* [ key k . ws . (bare | quoted) ]                                    *)
28 (* but the typechecker trips over that                                 *)
29 let qstr (k:regexp) =
30   let delq = del /['"]/ "\"" in
31   let bare = del /["']?/ "" . store /[^"' \t\n]+/ . del /["']?/ "" in
32   let quoted = delq . store /.*[ \t].*/ . delq in
33   [ ikey k . ws . bare . eol ]
34  |[ ikey k . ws . quoted . eol ]
35
36 let wwid = kv "wwid" (Rx.word|"*")
37
38 (* Settings that can be changed in various places *)
39 let common_setting =
40   kv "path_grouping_policy"
41     /failover|multibus|group_by_(serial|prio|node_name)/
42  |qstr /(getuid|prio)_callout/
43  |qstr /path_(selector|checker)|features/
44  |kv "failback" (Rx.integer | /immediate|manual/)
45  |kv "rr_weight" /priorities|uniform/
46  |kv "no_path_retry" (Rx.integer | /fail|queue/)
47  |kv "rr_min_io" Rx.integer
48
49 (* A device subsection *)
50 let device =
51   let setting =
52     qstr /vendor|product|product_blacklist|hardware_handler/
53    |common_setting in
54   section "device" setting
55
56 (* The defaults section *)
57 let defaults =
58   let setting =
59     common_setting
60    |kv "polling_interval" Rx.integer
61    |kv "udev_dir" Rx.fspath
62    |qstr "selector"
63    |kv "user_friendly_names" /yes|no/
64    (* These are not in the manpage but in the example multipath.conf *)
65    |kv "prio" Rx.word
66    |kv "max_fds" Rx.integer in
67   section "defaults" setting
68
69 (* The blacklist and blacklist_exceptions sections *)
70 let blacklist =
71   let setting =
72     wwid
73    |qstr "devnode"
74    |device in
75   section /blacklist(_exceptions)?/ setting
76
77 (* A multipath subsection *)
78 let multipath =
79   let setting =
80     wwid
81    |qstr "alias"
82    |common_setting in
83   section "multipath" setting
84
85 (* The multipaths section *)
86 let multipaths =
87   section "multipaths" multipath
88
89 (* The devices section *)
90 let devices =
91   section "devices" device
92
93 let lns = (comment|empty|defaults|blacklist|devices|multipaths)*
94
95 let xfm = transform lns (incl "/etc/multipath.conf")