Commit Graph

112 Commits

Author SHA1 Message Date
oshchirs 0663137c77 Add monitor delay parameter to mdadm.conf
Add possibility to configure delay for mdadm in monitoring mode
using mdadm.conf.
--delay command line argument takes precedence over config file.

Signed-off-by: Oleksandr Shchirskyi <oleksandr.shchirskyi@intel.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2021-08-02 10:24:20 -04:00
Mariusz Dabrowski b068159891 mdadm: load default sysfs attributes after assemblation
Added new type of line to mdadm.conf which allows to specify values of
sysfs attributes for MD devices that should be loaded after the array is
assembled. Each line is interpreted as list of structures containing
sysname of MD device (md126 etc.) and list of sysfs attributes and their
values.

Signed-off-by: Mariusz Dabrowski <mariusz.dabrowski@intel.com>
Signed-off-by: Krzysztof Smolinski <krzysztof.smolinski@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2019-07-10 16:12:09 -04:00
Guoqing Jiang 898bd1ecef Free map to avoid resource leak issues
1. There are some places which didn't free map as
discovered by coverity.

CID 289661 (#1 of 1): Resource leak (RESOURCE_LEAK)12. leaked_storage: Variable mapl going out of scope leaks the storage it points to.
CID 289619 (#3 of 3): Resource leak (RESOURCE_LEAK)63. leaked_storage: Variable map going out of scope leaks the storage it points to.
CID 289618 (#1 of 1): Resource leak (RESOURCE_LEAK)26. leaked_storage: Variable map going out of scope leaks the storage it points to.
CID 289607 (#1 of 1): Resource leak (RESOURCE_LEAK)41. leaked_storage: Variable map going out of scope leaks the storage it points to.

2. If we call map_by_* inside a loop, then map_free
should be called in the same loop, and it is better
to set map to NULL after free.

3. And map_unlock is always called with map_lock,
if we don't call map_remove before map_unlock,
then the memory (allocated by  map_lock -> map_read
-> map_add -> xmalloc) could be leaked. So we
need to free it in map_unlock as well.

Signed-off-by: Guoqing Jiang <gqjiang@suse.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2018-06-11 06:35:41 -04:00
Jes Sorensen b831b299e8 mdadm: Fix '==' broken formatting
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2017-05-16 14:04:22 -04:00
Jes Sorensen 421c6c047e config: Various stylistic cleanups
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
2016-08-11 15:48:09 -04:00
Jes Sorensen 6a674388f8 config: Use xcalloc() rather than xmalloc()+memset()
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
2016-08-11 15:32:34 -04:00
Khem Raj cf80bce8df Define _POSIX_C_SOURCE if undefined
config.c uses _POSIX_C_SOURCE which is defined in features.h when
glibc/uclibc is used, but isn't defined when musl is used.
So provide a reasonable default.

Signed-off-by: Khem Raj <raj.khem@gmail.com>
Signed-off-by: NeilBrown <neilb@suse.com>
2016-01-15 08:36:19 +11:00
NeilBrown 653299b699 Merge branch 'cluster'
Now that 3.3.3 is out, it is time to include the cluster-support code.

Signed-off-by: NeilBrown <neilb@suse.com>
2015-07-27 11:01:08 +10:00
NeilBrown 9581efb1ae mdstat: discard 'dev' field, just use 'devnm'
These both have the same value, and have done since the
'devnm' concept was introduced.
So discard the pointless duplicate.

Signed-off-by: NeilBrown <neilb@suse.de>
2015-07-02 08:15:10 +10:00
Guoqing Jiang 7716570e6d Set home-cluster while creating an array
The home-cluster is stored in the bitmap super block of the
array. The device can be assembled on a cluster with the
cluster name same as the one recorded in the bitmap.

If home-cluster is not specified, this is auto-detected using
dlopen corosync cmap library.

neilb: allow code to compile when corosync-devel is not installed.

Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
Signed-off-by: Guoqing Jiang <gqjiang@suse.com>
Signed-off-by: NeilBrown <neilb@suse.de>
2015-06-17 09:06:30 +10:00
NeilBrown 7a862a020f Don't break long strings onto multiple lines.
It is best to keep strings all together so that they
are easier to search for in the source code.
If a string is so long that it looks ugly one line,
them maybe it should be broken into multiple lines
for display too.

Only strings which contain a newline can be broken
into multiple lines:

 "It is OK to\n"
 "break this string\n"


Signed-off-by: NeilBrown <neilb@suse.de>
2015-02-12 13:46:53 +11:00
NeilBrown e2efe9e7bc config: new option to suppress adding bad block lists.
CREATE bbl=no

in mdadm.conf will cause any devices added to an array
to not have a bad block list.  By default they do for 1.x
metadata.

This is useful if you are suspicious of the bad-block-list
implementation.

Reported-by: Ethan Wilson <ethan.wilson@shiftmail.org>
Signed-off-by: NeilBrown <neilb@suse.de>
2014-08-07 12:23:45 +10:00
NeilBrown dbdf3f15e7 config: set "auto_seen" after processing the auto line.
Otherwise when we process an empty autoline (to be sure to
capture the MDADM_CONF_AUTO environment variable) we can end up
setting everything to 'yes' which over-rides 'no'.

Signed-off-by: NeilBrown <neilb@suse.de>
2013-09-10 17:10:10 +10:00
NeilBrown 2dfb675b94 config: support MDADM_CONF_AUTO= env var.
If a distribution allows the choice between using mdadm and
dmraid for DDF and IMSM to be made by some config file
(/etc/defaults/ /sys/sysconfig/ etc) which is queried by
/etc/init.d scripts, then the fact that mdadm implements this
choce through the config file is not very helpful.

So allow the "AUTO" line to be specified in part using MDADM_CONF_AUTO
in environment.

Signed-off-by: NeilBrown <neilb@suse.de>
2013-09-03 13:25:02 +10:00
NeilBrown 824e57276a config: refactor load_conffile() to have a single exit.
This will make next patch cleaner.
No functional change.

Signed-off-by: NeilBrown <neilb@suse.de>
2013-09-03 10:26:06 +10:00
NeilBrown 3c6e95c1aa Config: multiple occurences of lines is not an error.
As we now support config directories it is helpful if
lines are allowed to occur multiple times with one
over-riding the other.
So stop giving warnings when later lines are ignored.

Signed-off-by: NeilBrown <neilb@suse.de>
2013-09-03 10:05:59 +10:00
NeilBrown 9dc70cbc54 config: read /etc/mdadm.conf.d as well as /etc/mdadm.conf
If a configfile is explicitly given, just that file or directory
is read. Otherwise we now read both a file
  /etc/mdadm.conf
and a directory
  /etc/mdadm.conf.d

This allows a transition to directory based config, which in turn
allows easy control from scripts.

Signed-off-by: NeilBrown  <neilb@suse.de>
2013-09-03 09:29:52 +10:00
NeilBrown 343b7e75e8 Conf: allow conf file to be a directory.
If config file is a directory, process each file within with a name
ending in ".conf" that doesn't start with ".".
Files are processed in lexical order.

Signed-off-by: NeilBrown <neilb@suse.de>
2013-09-03 09:16:33 +10:00
NeilBrown 15af969283 Config: factor reading of file out into separate function.
This will make it easier to read multiple files in a conf.d/

Signed-off-by: NeilBrown <neilb@suse.de>
2013-09-03 08:47:57 +10:00
NeilBrown b4924f46c0 Don't set 'hold' option for mdstat_read if not needed.
We only need 'hold' if we want to mdstat_wait for a change.
These two callers don't care about a change, so they shouldn't
use the 'hold' flag.

Signed-off-by: NeilBrown <neilb@suse.de>
2013-07-10 11:02:10 +10:00
NeilBrown eb2306f841 Config: use better device names for "DEVICES container"
When "containers" appears on the "DEVICES" line (which is does by
default), use names from the mdadm map file instead of kernel names,
when possible.
This mean that the name will be more likely to appear in mdadm.conf
and so more likely to match "container=" tags.

Signed-off-by: NeilBrown <neilb@suse.de>
2013-07-02 10:46:43 +10:00
NeilBrown d0c017a663 Move conf_line and free_line from conf.c to lib.c
As they are uses for mdstat as well as mdadm.conf, they don't really
belong in conf.c

This removes a dependency between mdmon and conf.c

Signed-off-by: NeilBrown <neilb@suse.de>
2013-07-02 10:17:51 +10:00
NeilBrown 1011e8344a Remove lots of unnecessary white space.
Now that I am using white-space mode in Emacs I can see all of this,
and I don't like it :-)

Signed-off-by: NeilBrown <neilb@suse.de>
2013-06-19 12:31:45 +10:00
NeilBrown eca944fa9c create_mddev: add support for /dev/md_XXX non-numeric names.
With the 'devnm' infrastructure fixed, it is quite easy to support
names like "md_home" for md arrays.
The currently defaults to "off" and can be enabled in mdadm.conf with
  CREATE names=yes
This is incase other tools get confused by the new names.

Signed-off-by: NeilBrown <neilb@suse.de>
2013-05-15 11:03:25 +10:00
NeilBrown 5e73b02409 Ensure mddev_dev struct always zeroed on allocation.
There are a number of fields which should not
be left uninitialised.  e.g. attempt_re_add can get
confused if ->writemostly is not set correctly.

Signed-off-by: NeilBrown <neilb@suse.de>
2013-03-05 11:53:51 +11:00
NeilBrown 4dd2df0966 Discard devnum in favour of devnm
We widely use a "devnum" which is 0 or +ve for md%d devices
and -ve for md_d%d devices.
But I want to be able to use md_%s device names.

So get rid of devnum (a number) and use devnm (a 32char string).
eg.
  md0
  md_d2
  md_home

Signed-off-by: NeilBrown <neilb@suse.de>
2013-02-21 17:05:23 +11:00
NeilBrown 13f2dd6be5 conf: allow multiple arrays to be <ignore>d
We currently complain if mdadm.conf contains multiple
definitions for the same name.  Unfortunately this stops
multiple arrays  from being <ignored>d.

So exclude "<ignore>" from the duplicate-names test.

Reported-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: NeilBrown <neilb@suse.de>
2012-11-22 16:28:00 +11:00
NeilBrown 5d5002289c Replace a lot of leading spaces with tabs.
Signed-off-by: NeilBrown <neilb@suse.de>
2012-10-10 18:33:26 +11:00
NeilBrown 503975b9d5 Remove scattered checks for malloc success.
malloc should never fail, and if it does it is unlikely
that anything else useful can be done.  Best approach is to
abort and let some super-daemon restart.

So define xmalloc, xcalloc, xrealloc, xstrdup which don't
fail but just print a message and exit.  Then use those
removing all the tests for failure.

Also replace all "malloc;memset" sequences with 'xcalloc'.

Signed-off-by: NeilBrown <neilb@suse.de>
2012-07-09 17:14:16 +10:00
NeilBrown e7b84f9d50 Introduce pr_err for printing error messages.
'pr_err("' is a lot shorter than 'fprintf(stderr, Name ": '
cont_err() is also available.

Signed-off-by: NeilBrown <neilb@suse.de>
2012-07-09 17:14:16 +10:00
NeilBrown 9f1b0f0f1e config: conf_match should ignore devname when not set.
mapfile:RebuildMap calls conf_match with no devname, so we must be
careful not to use it.

Reported-by: Arkadiusz Miśkiewicz <arekm@maven.pl>
Signed-off-by: NeilBrown <neilb@suse.de>
2012-02-16 14:11:57 +11:00
NeilBrown b10c663ea9 config: fix handing of 'homehost' in AUTO line.
We should be looking for the policy "auto=homehost", not
"auto=auto".

Signed-off-by: NeilBrown <neilb@suse.de>
2012-02-09 11:44:38 +11:00
Lukasz Orlowski 7c3367585e fix: Allowed to assemble 2 volumes with the same names from config file.
mdadm allowes to assemble 2 volumes with the same names based on the
config file. The issue is fixed by iterating over the list of md device
identifiers and comparing the names of md devices against each other,
detecting identical names and blocking the assembly should the same names
be found.
Now having detected duplicate names, mdadm terminates without assembling
the container, displaying appropriate prompt.

Signed-off-by: Lukasz Orlowski <lukasz.orlowski@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
2011-11-07 12:20:34 +11:00
NeilBrown 2244d1a987 Remove duplicated code: search_mdstat and conf_match
search_mdstat and conf_match are almost identical.

Put all the functionality in conf_match, and remove search_mdstat.

Reported-by: Jes.Sorensen@redhat.com
Signed-off-by: NeilBrown <neilb@suse.de>
2011-11-01 13:30:41 +11:00
Thomas Jarosch 42de2ac27d Fix small memory leak
Found by cppcheck

Signed-off-by: Thomas Jarosch <thomas.jarosch@intra2net.com>
Signed-off-by: NeilBrown <neilb@suse.de>
2011-09-07 18:10:33 +10:00
NeilBrown 0f23aa88f8 config: restore the possibility of a NULL homehost
As homehost defaults to the system name it is not possible to specify
a NULL homehost.

This patch restored this ability with either --homehost="" or
--homehost="<none>".

This allows the creation of v1.x arrays without a "hostname:"
prefix in the name.

Signed-off-by: NeilBrown <neilb@suse.de>
2011-05-10 16:17:12 +10:00
NeilBrown 78c0a3b17f Split some of util.c into a new lib.c
Some of util.c is dependent on lots of other code, some of it
is stand-alone.
Move some of the stand-alone stuff into a new lib.c so it can be used
by smaller utilities.

Signed-off-by: NeilBrown <neilb@suse.de>
2011-04-05 08:44:54 +10:00
NeilBrown 2b594614a1 Remove content from mddev_dev
Now that the next_member loop is much smaller it is easy to
just use 'content' rather than stashing it in 'tmpdev->content'.
So we can remove the 'content' field from 'struct mddev_dev'.

Signed-off-by: NeilBrown <neilb@suse.de>
2010-11-22 20:58:05 +11:00
NeilBrown a655e55064 Improve type names for mddev_dev
Remove the _t pointer typedef and remove the _s suffix for the
structure,

These things do not help readability.

Signed-off-by: NeilBrown <neilb@suse.de>
2010-11-22 20:58:05 +11:00
NeilBrown fa56eddbd1 Improve mddev_ident type definitions.
Remove the _t typedef and remove the _s suffix from the struct name.

These things do not help readability.

Signed-off-by: NeilBrown <neilb@suse.de>
2010-11-22 20:58:05 +11:00
NeilBrown 4e8d9f0a16 Convert 'auto' config line to policy statements 2010-09-06 11:26:28 +10:00
NeilBrown 5527fc7462 Add policy framework.
Policy can be stated as lines in mdadm.conf like:

POLICY  type=disk path=pci-0000:00:1f.2-* action=ignore domain=onboard

This defines two distinct policies which apply to any disk (but not
partition) device reached through the pci device 0000:00:1f.2.
The policies are "action=ignore" which means certain actions will
ignore the device, and "domain=onboard" which means all such devices
as treated as being united under the name 'onboard'.

This patch just adds data structures and code to read and
manipulate them.  Future patches will actually use them.

Signed-off-by: NeilBrown <neilb@suse.de>
2010-09-06 11:03:43 +10:00
NeilBrown f21e18ca89 Compile with -Wextra by default
This produced lots of warning, some of which pointed to actual bugs.

Signed-off-by: NeilBrown <neilb@suse.de>
2010-08-05 13:13:02 +10:00
NeilBrown d1d3482b56 config: add 'homehost' option to 'AUTO' line.
This allows basing auto-assembly decisions on whether
the array is recorded as belonging to this host or not.

Signed-off-by: NeilBrown <neilb@suse.de>
2010-03-03 14:33:55 +11:00
Doug Ledford 4d0b563b5b Fix segfault when the AUTO keyword is used in the config file
Signed-off-by: Doug Ledford <dledford@redhat.com>
Signed-off-by: NeilBrown <neilb@suse.de>
2010-01-19 10:50:26 +13:00
NeilBrown e736b62389 Update copyright dates and remove references to @cse.unsw.edu.au
Also removed 'paper' addresses.

Signed-off-by: NeilBrown <neilb@suse.de>
2009-06-02 14:35:45 +10:00
NeilBrown 360b463696 mapfile - when rebuilding, choose an appropriate name is none is found.
When rebuilding the mapfile (mdadm -Ir), if not appropriate name is
found in /dev/md/, try to find an appropriate name, either by looking
in mdadm.conf or by using the name in the metadata.

Signed-off-by: NeilBrown <neilb@suse.de>
2009-05-11 15:58:42 +10:00
NeilBrown 5c4c9ab16d config: enhance name matching in conf_get_ident.
Use when searching mdadm.conf for a device, use more flexible
matching that e.g. ignores leading /dev/md/ or /dev/

As mdadm now accepts both "/dev/md/foo" and "foo" is many places as
equivalent, they should compare as the same.

Signed-off-by: NeilBrown <neilb@suse.de>
2009-05-11 15:47:10 +10:00
NeilBrown 0ac91628b9 Allow homehost to be largely ignored when assembling arrays.
If mdadm.conf contains
   HOMEHOST <ignore>
or commandline contains
   --homehost=<ignore>

then the check that array metadata mentions the given homehost is
replace by a check that the name recorded in the metadata is not
already used by some other array mentioned in mdadm.conf.

This allows more arrays to use their native name rather than having
an _NN suffix added.

This should only be used during boot time if all arrays required for
normal boot are listed in mdadm.conf.

If auto-assembly is used to find all array during boot, then the
HOMEHOST feature should be used to ensure there is no room for
confusion in choosing array names, and so it should not be set
to <ignore>.

Signed-off-by: NeilBrown <neilb@suse.de>
2009-05-11 15:46:46 +10:00
NeilBrown db2d001cee config: allow Array line to contain array name without /dev/md/ prefix.
For consistency with --create and --assemble, allow the array name
given in mdadm.conf to exclude the "/dev/md/" prefix.  So e.g.

  ARRAY home uuid=whatever

is treated like

  ARRAY /dev/md/home uuid=whatever

Also exclude names which create_mddev will reject.

Signed-off-by: NeilBrown <neilb@suse.de>
2009-05-11 15:18:35 +10:00