|
Packit Service |
a2ae7a |
(******************************************************************************
|
|
Packit Service |
a2ae7a |
Mdadm_conf module for Augeas
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
Author: Matthew Booth <mbooth@redhat.com>
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
Copyright (C):
|
|
Packit Service |
a2ae7a |
2011 Red Hat Inc.
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
Reference:
|
|
Packit Service |
a2ae7a |
mdadm(5)
|
|
Packit Service |
a2ae7a |
config.c and policy.c from mdadm-3.2.2
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
License:
|
|
Packit Service |
a2ae7a |
This file is licensed under the LGPL v2+.
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
This is a lens for /etc/mdadm.conf. It aims to parse every valid configuration
|
|
Packit Service |
a2ae7a |
file as of version 3.2.2, and many invalid ones too. This last point is a
|
|
Packit Service |
a2ae7a |
feature, not a bug! madm will generate warnings for invalid configuration which
|
|
Packit Service |
a2ae7a |
do not prevent correct operation of the tool. Wherever possible, we try to
|
|
Packit Service |
a2ae7a |
allow for this behaviour.
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
Keywords in mdadm.conf are matched with a case-insensitive prefix match of at
|
|
Packit Service |
a2ae7a |
least 3 characters. Keys in key/value pairs are also matched case-insensitively,
|
|
Packit Service |
a2ae7a |
but require a full match. The exception is POLICY and PART-POLICY, where keys
|
|
Packit Service |
a2ae7a |
are matched case-sensitively.
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
N.B. We can't use case-insensitive regular expressions in most places due to bug
|
|
Packit Service |
a2ae7a |
#147.
|
|
Packit Service |
a2ae7a |
*******************************************************************************)
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
module Mdadm_conf =
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
autoload xfm
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(******************************************************************************
|
|
Packit Service |
a2ae7a |
* PRIMITIVES
|
|
Packit Service |
a2ae7a |
******************************************************************************)
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let eol = Util.comment_or_eol
|
|
Packit Service |
a2ae7a |
let comment = Util.comment
|
|
Packit Service |
a2ae7a |
let empty = Util.empty
|
|
Packit Service |
a2ae7a |
let value = /[^ \t\n#]+/
|
|
Packit Service |
a2ae7a |
let value_no_eq = /[^ \t\n#=]+/
|
|
Packit Service |
a2ae7a |
let value_no_eq_sl = /[^ \t\n#=\/]+/
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let continuation = /\n[ \t]+/
|
|
Packit Service |
a2ae7a |
let space = /[ \t]+/
|
|
Packit Service |
a2ae7a |
let value_sep = ( del ( continuation | space . continuation? ) " "
|
|
Packit Service |
a2ae7a |
| comment . del space " " )
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* We parse specific keys rather than having a catch-all owing to the varying
|
|
Packit Service |
a2ae7a |
case of the syntax. This means the user can rely on 'array/uuid' rather than
|
|
Packit Service |
a2ae7a |
additionally testing for 'array/UUID'.
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
It would be good to have an additional catchall, but I haven't been able to make
|
|
Packit Service |
a2ae7a |
that work.
|
|
Packit Service |
a2ae7a |
*)
|
|
Packit Service |
a2ae7a |
let keyvalue (r:regexp) (lc:string) (uc:string) =
|
|
Packit Service |
a2ae7a |
[ del ( r . /=/ ) ( uc . "=" ) . label lc . store value ]
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let simplevalue (r:regexp) (lc:string) (uc:string) =
|
|
Packit Service |
a2ae7a |
[ del r uc . label lc
|
|
Packit Service |
a2ae7a |
. ( value_sep . [ label "value" . store value ] )* . eol ]
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(******************************************************************************
|
|
Packit Service |
a2ae7a |
* DEVICES
|
|
Packit Service |
a2ae7a |
******************************************************************************)
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let dev_re = /dev(i(ce?)?)?/i
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let dev_containers_re = /containers/i
|
|
Packit Service |
a2ae7a |
let dev_partitions_re = /partitions/i
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let dev_containers = [ del dev_containers_re "containers" . label "containers" ]
|
|
Packit Service |
a2ae7a |
let dev_partitions = [ del dev_partitions_re "partitions" . label "partitions" ]
|
|
Packit Service |
a2ae7a |
let dev_device = [ label "name". store ( value - (dev_containers_re | dev_partitions_re)) ]
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* Strictly there must be at least 1 device, but we err on the side of parsing
|
|
Packit Service |
a2ae7a |
*)
|
|
Packit Service |
a2ae7a |
let dev_devices = ( value_sep . ( dev_containers
|
|
Packit Service |
a2ae7a |
| dev_partitions
|
|
Packit Service |
a2ae7a |
| dev_device ) )*
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let device = [ del dev_re "DEVICE" . label "device" . dev_devices . eol ]
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(******************************************************************************
|
|
Packit Service |
a2ae7a |
* ARRAY
|
|
Packit Service |
a2ae7a |
******************************************************************************)
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let array_re = /arr(ay?)?/i
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let arr_auto_re = /auto/i
|
|
Packit Service |
a2ae7a |
let arr_bitmap_re = /bitmap/i
|
|
Packit Service |
a2ae7a |
let arr_container_re = /container/i
|
|
Packit Service |
a2ae7a |
let arr_devices_re = /devices/i
|
|
Packit Service |
a2ae7a |
let arr_disks_re = /disks/i (* Undocumented *)
|
|
Packit Service |
a2ae7a |
let arr_level_re = /level/i
|
|
Packit Service |
a2ae7a |
let arr_member_re = /member/i
|
|
Packit Service |
a2ae7a |
let arr_metadata_re = /metadata/i
|
|
Packit Service |
a2ae7a |
let arr_name_re = /name/i
|
|
Packit Service |
a2ae7a |
let arr_num_devices_re = /num-devices/i
|
|
Packit Service |
a2ae7a |
let arr_spare_group_re = /spare-group/i
|
|
Packit Service |
a2ae7a |
let arr_spares_re = /spares/i
|
|
Packit Service |
a2ae7a |
let arr_super_minor_re = /super-minor/i
|
|
Packit Service |
a2ae7a |
let arr_uuid_re = /uuid/i
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let arr_devicename = [ store value_no_eq . label "devicename" ]
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let arr_auto = keyvalue arr_auto_re "auto" "AUTO"
|
|
Packit Service |
a2ae7a |
let arr_bitmap = keyvalue arr_bitmap_re "bitmap" "BITMAP"
|
|
Packit Service |
a2ae7a |
let arr_container = keyvalue arr_container_re "container" "CONTAINER"
|
|
Packit Service |
a2ae7a |
let arr_devices = keyvalue arr_devices_re "devices" "DEVICES"
|
|
Packit Service |
a2ae7a |
let arr_disks = keyvalue arr_disks_re "disks" "DISKS"
|
|
Packit Service |
a2ae7a |
let arr_level = keyvalue arr_level_re "level" "LEVEL"
|
|
Packit Service |
a2ae7a |
let arr_member = keyvalue arr_member_re "member" "MEMBER"
|
|
Packit Service |
a2ae7a |
let arr_metadata = keyvalue arr_metadata_re "metadata" "METADATA"
|
|
Packit Service |
a2ae7a |
let arr_name = keyvalue arr_name_re "name" "NAME"
|
|
Packit Service |
a2ae7a |
let arr_num_devices = keyvalue arr_num_devices_re "num-devices" "NUM-DEVICES"
|
|
Packit Service |
a2ae7a |
let arr_spare_group = keyvalue arr_spare_group_re "spare-group" "SPARE-GROUP"
|
|
Packit Service |
a2ae7a |
let arr_spares = keyvalue arr_spares_re "spares" "SPARES"
|
|
Packit Service |
a2ae7a |
let arr_super_minor = keyvalue arr_super_minor_re "super-minor" "SUPER-MINOR"
|
|
Packit Service |
a2ae7a |
let arr_uuid = keyvalue arr_uuid_re "uuid" "UUID"
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let arr_options = ( value_sep . ( arr_devicename
|
|
Packit Service |
a2ae7a |
| arr_auto
|
|
Packit Service |
a2ae7a |
| arr_bitmap
|
|
Packit Service |
a2ae7a |
| arr_container
|
|
Packit Service |
a2ae7a |
| arr_devices
|
|
Packit Service |
a2ae7a |
| arr_disks
|
|
Packit Service |
a2ae7a |
| arr_level
|
|
Packit Service |
a2ae7a |
| arr_member
|
|
Packit Service |
a2ae7a |
| arr_metadata
|
|
Packit Service |
a2ae7a |
| arr_name
|
|
Packit Service |
a2ae7a |
| arr_num_devices
|
|
Packit Service |
a2ae7a |
| arr_spare_group
|
|
Packit Service |
a2ae7a |
| arr_spares
|
|
Packit Service |
a2ae7a |
| arr_super_minor
|
|
Packit Service |
a2ae7a |
| arr_uuid ) )*
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let array = [ del array_re "ARRAY" . label "array" . arr_options . eol ]
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(******************************************************************************
|
|
Packit Service |
a2ae7a |
* MAILADDR
|
|
Packit Service |
a2ae7a |
******************************************************************************)
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let mailaddr_re = /mai(l(a(d(dr?)?)?)?)?/i
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* We intentionally allow multiple mailaddr values here, even though this is
|
|
Packit Service |
a2ae7a |
invalid and would produce a warning. This is better than not parsing the file.
|
|
Packit Service |
a2ae7a |
*)
|
|
Packit Service |
a2ae7a |
let mailaddr = simplevalue mailaddr_re "mailaddr" "MAILADDR"
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(******************************************************************************
|
|
Packit Service |
a2ae7a |
* MAILFROM
|
|
Packit Service |
a2ae7a |
******************************************************************************)
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* N.B. MAILFROM can only be abbreviated to 5 characters *)
|
|
Packit Service |
a2ae7a |
let mailfrom_re = /mailf(r(om?)?)?/i
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let mailfrom = [ del mailfrom_re "MAILFROM" . label "mailfrom"
|
|
Packit Service |
a2ae7a |
. ( value_sep . [ label "value" . store value ] )* . eol ]
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(******************************************************************************
|
|
Packit Service |
a2ae7a |
* PROGRAM
|
|
Packit Service |
a2ae7a |
******************************************************************************)
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let program_re = /pro(g(r(am?)?)?)?/i
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let program = simplevalue program_re "program" "PROGRAM"
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(******************************************************************************
|
|
Packit Service |
a2ae7a |
* CREATE
|
|
Packit Service |
a2ae7a |
******************************************************************************)
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let create_re = /cre(a(te?)?)?/i
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let cre_auto_re = /auto/i
|
|
Packit Service |
a2ae7a |
let cre_owner_re = /owner/i
|
|
Packit Service |
a2ae7a |
let cre_group_re = /group/i
|
|
Packit Service |
a2ae7a |
let cre_mode_re = /mode/i
|
|
Packit Service |
a2ae7a |
let cre_metadata_re = /metadata/i
|
|
Packit Service |
a2ae7a |
let cre_symlinks_re = /symlinks/i
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let cre_auto = keyvalue cre_auto_re "auto" "AUTO"
|
|
Packit Service |
a2ae7a |
let cre_group = keyvalue cre_group_re "group" "GROUP"
|
|
Packit Service |
a2ae7a |
let cre_metadata = keyvalue cre_metadata_re "metadata" "METADATA"
|
|
Packit Service |
a2ae7a |
let cre_mode = keyvalue cre_mode_re "mode" "MODE"
|
|
Packit Service |
a2ae7a |
let cre_owner = keyvalue cre_owner_re "owner" "OWNER"
|
|
Packit Service |
a2ae7a |
let cre_symlinks = keyvalue cre_symlinks_re "symlinks" "SYMLINKS"
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let cre_options = ( value_sep . ( arr_auto
|
|
Packit Service |
a2ae7a |
| cre_owner
|
|
Packit Service |
a2ae7a |
| cre_group
|
|
Packit Service |
a2ae7a |
| cre_mode
|
|
Packit Service |
a2ae7a |
| cre_metadata
|
|
Packit Service |
a2ae7a |
| cre_symlinks) )*
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let create = [ del create_re "CREATE" . label "create" . cre_options . eol ]
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(******************************************************************************
|
|
Packit Service |
a2ae7a |
* HOMEHOST
|
|
Packit Service |
a2ae7a |
******************************************************************************)
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let homehost_re = /hom(e(h(o(st?)?)?)?)?/i
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let homehost = simplevalue homehost_re "homehost" "HOMEHOST"
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(******************************************************************************
|
|
Packit Service |
a2ae7a |
* AUTO
|
|
Packit Service |
a2ae7a |
******************************************************************************)
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let auto_re = /auto?/i
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let aut_plus = [ key "+" . store value ]
|
|
Packit Service |
a2ae7a |
let aut_minus = [ key "-" . store value ]
|
|
Packit Service |
a2ae7a |
let aut_homehost = [ del /homehost/i "homehost" . label "homehost" ]
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let aut_list = ( value_sep . ( aut_plus | aut_minus | aut_homehost ) )*
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let auto = [ del auto_re "AUTO" . label "auto" . aut_list . eol ]
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(******************************************************************************
|
|
Packit Service |
a2ae7a |
* POLICY and PART-POLICY
|
|
Packit Service |
a2ae7a |
******************************************************************************)
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* PART-POLICY is undocumented. A cursory inspection of the parsing code
|
|
Packit Service |
a2ae7a |
suggests it's parsed the same way as POLICY, but treated slightly differently
|
|
Packit Service |
a2ae7a |
thereafter. *)
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let policy_re = /pol(i(cy?)?)?/i
|
|
Packit Service |
a2ae7a |
let part_policy_re = /par(t(-(p(o(l(i(cy?)?)?)?)?)?)?)?/i
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* Unlike everything else, policy keys are matched case sensitive. This means we
|
|
Packit Service |
a2ae7a |
don't have to mess around with explicit option matching, as the match string is
|
|
Packit Service |
a2ae7a |
fixed for a working configuration. *)
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let pol_option (act:string) =
|
|
Packit Service |
a2ae7a |
[ del ( act . "=" ) ( act . "=" ) . label act . store value ]
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let pol_options = ( value_sep . [ key value_no_eq_sl . del "=" "="
|
|
Packit Service |
a2ae7a |
. store value ] )*
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let policy = [ del policy_re "POLICY" . label "policy"
|
|
Packit Service |
a2ae7a |
. pol_options . eol ]
|
|
Packit Service |
a2ae7a |
let part_policy = [ del part_policy_re "PART-POLICY" . label "part-policy"
|
|
Packit Service |
a2ae7a |
. pol_options . eol ]
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(******************************************************************************
|
|
Packit Service |
a2ae7a |
* LENS
|
|
Packit Service |
a2ae7a |
******************************************************************************)
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let lns = (comment
|
|
Packit Service |
a2ae7a |
| empty
|
|
Packit Service |
a2ae7a |
| device
|
|
Packit Service |
a2ae7a |
| array
|
|
Packit Service |
a2ae7a |
| mailaddr
|
|
Packit Service |
a2ae7a |
| mailfrom
|
|
Packit Service |
a2ae7a |
| program
|
|
Packit Service |
a2ae7a |
| create
|
|
Packit Service |
a2ae7a |
| homehost
|
|
Packit Service |
a2ae7a |
| auto
|
|
Packit Service |
a2ae7a |
| policy
|
|
Packit Service |
a2ae7a |
| part_policy )*
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let filter = incl "/etc/mdadm.conf"
|
|
Packit Service |
a2ae7a |
. incl "/etc/mdadm/mdadm.conf"
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let xfm = transform lns filter
|