]> git.ipfire.org Git - thirdparty/mdadm.git/log
thirdparty/mdadm.git
13 years agoAllow a metadata update to have a linked list of allocated spaces.
NeilBrown [Thu, 16 Dec 2010 01:10:01 +0000 (12:10 +1100)] 
Allow a metadata update to have a linked list of allocated spaces.

Sometimes one metadata update will require allocating several
larger data structures.  As 'monitor' cannot allocate, 'manager'
must, so it must be able to attach a list of allocates to the
update, and importantly it must be able to easily free them.

So add a 'space_list' element to metadata updates where each
element on the list starts with a pointer to the next.

Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoimsm: Prepare reshape_update in mdadm
NeilBrown [Thu, 16 Dec 2010 00:45:21 +0000 (11:45 +1100)] 
imsm: Prepare reshape_update in mdadm

During Online Capacity Expansion metadata has to be updated to show
array changes and allow for future assembly of array.  To do this
mdadm prepares and sends reshape_update metadata update to mdmon.
The update contains the old and new number of raid disks, and the
indices of the spare disks that will be used to fill the spaces.

This works as follows:
1. reshape_super() prepares metadata update.
2. mdadm discovers the spares and adds them to the array
3. mdadm sends the update to mdmon
4. managemon in prepare_update() allocates required memory for bigger
   device object
5. monitor in process_update() updates the metadata to record the
   new sizes and the newly assigned devices.
6. mdadm initiates the reshape

Based on code From: Adam Kwolek <adam.kwolek@intel.com>

Signed-off-by: Krzysztof Wojcik <krzysztof.wojcik@intel.com>
Signed-off-by: Adam Kwolek <adam.kwolek@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoimsm: add spares to --examine output.
NeilBrown [Thu, 16 Dec 2010 00:33:23 +0000 (11:33 +1100)] 
imsm: add spares to --examine output.

When we examine a container, list the spare devices as well as
the active devices.

Signed-off-by: NeilBrown <neilb@suse.de>
13 years agomdmon: when a reshape is detected, add any newly added devices to the array.
NeilBrown [Wed, 15 Dec 2010 22:07:52 +0000 (09:07 +1100)] 
mdmon: when a reshape is detected, add any newly added devices to the array.

When mdadm starts a reshape, it might add some devices to the array
first.  mdmon needs to notice the reshape starting and check for any
new devices.  If there are any they need to be provided to be
monitored.

Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoGrow: add disks chosen by metadata handler to array for growth.
NeilBrown [Wed, 15 Dec 2010 22:07:52 +0000 (09:07 +1100)] 
Grow: add disks chosen by metadata handler to array for growth.

With externally managed container based metadata, the ->reshape_super
method must choose any spares that are to be added to the array.
They should be prepared so that ->container_content will find them
as spares (disk.state == 0) which are assigned to a slot
(raid_disk >= 0).
We need to take those and add them to the array(s).

Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoGrow: call start/abort_reshape as appropriate when reshaping a container.
NeilBrown [Wed, 15 Dec 2010 22:07:52 +0000 (09:07 +1100)] 
Grow: call start/abort_reshape as appropriate when reshaping a container.

This means that ->manage_reshape will be called with reshape ready to
roll.

Also move the current start_reshape call earlier so that it is before
the other ->manage_reshape call.

Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoGrow: make sure rv is set correctly in reshape_container_raid_disks
NeilBrown [Wed, 15 Dec 2010 22:07:52 +0000 (09:07 +1100)] 
Grow: make sure rv is set correctly in reshape_container_raid_disks

Whenever there is an error, rv must be -1.

Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoGrow: split out start_reshape for initiating reshape via sysfs.
NeilBrown [Wed, 15 Dec 2010 22:07:52 +0000 (09:07 +1100)] 
Grow: split out start_reshape for initiating reshape via sysfs.

Rather than sprinkling various sysfs setting around, put them all
in one place.  This will make implementing ->manage_reshape easier.

This changes behaviour slightly.
Previously we would not set 'sync_action' to 'reshape' until we were
ready for the process to start.  Now we set sync_max to zero and set
sync_action to 'reshape' at that time.  When we want reshape to
actually start we advance sync_max.

Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoGrow: fix calculation of stripe_cache_size when reshaping.
NeilBrown [Wed, 15 Dec 2010 22:07:52 +0000 (09:07 +1100)] 
Grow: fix calculation of stripe_cache_size when reshaping.

The two places that this was done were different.  The original was
most correct, thought it used odisks rather than odata.

So fix that and make them both use the same calculation.

Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoGrow: be more careful about metadata updates.
NeilBrown [Wed, 15 Dec 2010 22:07:51 +0000 (09:07 +1100)] 
Grow: be more careful about metadata updates.

1/ When we sunc_metadata, we must reset ->update_tail else
   future metadata updates might go direct to the device bypassing
   mdmon.

2/ When converting to an array with redundancy so we can add disks
   it is neater to sync_metadata before starting mdmon rather that
   artificially setting update_tail early.

Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoGrow: be extra careful about races when freezing an array
NeilBrown [Wed, 15 Dec 2010 22:07:51 +0000 (09:07 +1100)] 
Grow: be extra careful about races when freezing an array

If any subarray has any spare devices, then something raced,
and we should abort the reshape.

Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoGrow: check container is idle before freezing it.
NeilBrown [Wed, 15 Dec 2010 22:07:51 +0000 (09:07 +1100)] 
Grow: check container is idle before freezing it.

Before we freeze a container in preparation for growing a subarray, we
need to be sure all the subarrays are idle.

This test is racy as recovery could start at any moment following a
failure.  However it is still useful as it stops us from even trying
to start a reshape while a reshape or recovery is active.

Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoSplit fmt_devnum out from devnum2devname
NeilBrown [Wed, 15 Dec 2010 22:07:51 +0000 (09:07 +1100)] 
Split fmt_devnum out from devnum2devname

Sometimes we want to convert a devnum to a devname without allocating
memory.  So provide function to do the formatting without allocation.

Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoUpdate external reshape documentation.
NeilBrown [Wed, 15 Dec 2010 22:07:51 +0000 (09:07 +1100)] 
Update external reshape documentation.

Revise documentation for external reshape, correcting some problems,
and clarifying some issues.

Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoimsm: FIX: imsm_add_spare() wrongly tests spares list
Adam Kwolek [Wed, 15 Dec 2010 09:38:15 +0000 (10:38 +0100)] 
imsm: FIX: imsm_add_spare() wrongly tests spares list

For more than one disk tested additional_test_list was searched from last
point, not from begin.

This bug causes that more than 2 disks cannot be added to imsm array,
when imsm_add_spare() is used for this.

Signed-off-by: Adam Kwolek <adam.kwolek@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agofix: Monitor doesn't return after starting daemon
Anna Czarnowska [Wed, 15 Dec 2010 04:51:53 +0000 (15:51 +1100)] 
fix: Monitor doesn't return after starting daemon

Signed-off-by: Anna Czarnowska <anna.czarnowska@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoIMSM: do not rebuild the array if a non-redundant sub-array with failed disks is...
Labun, Marcin [Wed, 15 Dec 2010 04:51:53 +0000 (15:51 +1100)] 
IMSM: do not rebuild the array if a non-redundant sub-array with failed disks is present

Before looking for a spare to rebuild a degraded array, check if there
are any failed disks in container.  Block rebuild if another sub-array
is failed until failed disks are removed from container.

Currently, Intel metadata handler rebuilds all sub-arrays even if one
of them is non-redundant. In case of failed sub-array, failed disks
are just replaced with new ones in the metadata mapping. The data for
failed disk is not restored even the disk is present in the system.

With this fix, we require the removal of the failed disk from
container to start the process of rebuilding the array with failed
member. If the disk is physically pulled out of the system, the disk
is removed from container automatically by exiting udev rules.

Signed-off-by: Marcin Labun <marcin.labun@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoIMSM: Fix problem in mdmon monitor of using removed disk in imsm container.
Labun, Marcin [Wed, 15 Dec 2010 04:51:51 +0000 (15:51 +1100)] 
IMSM: Fix problem in mdmon monitor of using removed disk in imsm container.

Manager thread shall pass the information to monitor thread (mdmon)
that some devices are removed from container.  Otherwise, monitor
(mdmon) might use such devices (spares) to rebuild the array that has
gone degraded.

This problem happens for imsm containers, since a list of the
container disks is maintained in intel_super structure. When array
goes degraded, the list is searched to find a spare disks to start
rebuild.  Without this fix the rebuild could be stared on the spare
device that was a member of the container, but has been removed from
it.

New super type function handler has been introduced to prepare
metadata format specific information about removed devices.

int (*remove_from_super)(struct supertype *st, mdu_disk_info_t *dinfo)

The message prepared in remove_from_super is later processed by
process_update handler in monitor thread.

Signed-off-by: Marcin Labun <marcin.labun@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoMerge branch 'master' into devel-3.2
NeilBrown [Mon, 13 Dec 2010 03:00:05 +0000 (14:00 +1100)] 
Merge branch 'master' into devel-3.2

Conflicts:
super-intel.c

13 years agosegfault in imsm create with wrong arguments
Luca Berra [Sun, 12 Dec 2010 10:33:55 +0000 (11:33 +0100)] 
segfault in imsm create with wrong arguments

When calling mdadm -C --metadata=imsm -l 1 /dev/sd..
mdadm segfaults in default_chunk_imsm()
above syntax is incorrect, but mdadm should error instead of segfaulting

Signed-off-by: Luca Berra <bluca@comedia.it>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoAllow --update=devicesize with --re-add
NeilBrown [Thu, 9 Dec 2010 02:06:29 +0000 (13:06 +1100)] 
Allow --update=devicesize with --re-add

This is useful with 1.1 and 1.2 metadata to update the metadata if
the device size has changed.
The same functionality can be achieved by writing to the device size
in sysfs after re-adding normally, but in some cases this might be
easier.

Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoGrow: warn if growing an array will make it degraded.
NeilBrown [Thu, 9 Dec 2010 00:51:13 +0000 (11:51 +1100)] 
Grow: warn if growing an array will make it degraded.

Growing an array when there aren't enough spares can make the array
degraded.  This works but might not be what is wanted.
So warn the user in this case and require a --force to go ahead
with the reshape.

Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoMerge branch 'master' into devel-3.2
NeilBrown [Thu, 9 Dec 2010 00:16:42 +0000 (11:16 +1100)] 
Merge branch 'master' into devel-3.2

Conflicts:
mdadm.8.in

Same conceptual change was written with different words in each version.
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agofix: mdstat_read() incorrectly translates value of mdstat_ent->reshape for recovering
Hawrylewicz Czarnowski, Przemyslaw [Wed, 8 Dec 2010 11:30:28 +0000 (11:30 +0000)] 
fix: mdstat_read() incorrectly translates value of mdstat_ent->reshape for recovering

it results in wrong output of mdadm --detail (shows reshaping instead
of recovering)

Signed-off-by: Przemyslaw Czarnowski <przemyslaw.hawrylewicz.czarnowski@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agofix: mdadm -Ss for external metadata don't stop container
Hawrylewicz Czarnowski, Przemyslaw [Tue, 7 Dec 2010 06:44:21 +0000 (06:44 +0000)] 
fix: mdadm -Ss for external metadata don't stop container

Sometimes (~50%) mdadm -Ss cannot stop container as mdmon opens its device
and do not close it before exit(). The period between open and release of
handle is too long and md is not able stop device. Releasing handle before
exit does not block md.

Signed-off-by: Przemyslaw Czarnowski <przemyslaw.hawrylewicz.czarnowski@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agofix: incremental on invalid container causes segfault
Hawrylewicz Czarnowski, Przemyslaw [Mon, 6 Dec 2010 06:40:40 +0000 (06:40 +0000)] 
fix: incremental on invalid container causes segfault

counterpart of 417f346ee0 for incremental.
If md device has metadata_version="none" super_by_fd() matches
supertype=super0.
Call of load_container() dereferences null, so we have to forbid it.

Signed-off-by: Przemyslaw Czarnowski <przemyslaw.hawrylewicz.czarnowski@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoFIX: wait_backup() sometimes hungs
Adam Kwolek [Fri, 3 Dec 2010 10:33:55 +0000 (21:33 +1100)] 
FIX: wait_backup() sometimes hungs

Sometimes wait_backup() omits transition from reshape to idle state
and mdadm seams to be hung.  So check the 'complete' count
*before* waiting rather than only after.

Signed-off-by: Adam Kwolek <adam.kwolek@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoFIX: Honor !reshape state on wait_reshape() entry
Adam Kwolek [Fri, 3 Dec 2010 04:10:20 +0000 (15:10 +1100)] 
FIX: Honor !reshape state on wait_reshape() entry

When wait_reshape() function starts it can occurs that reshape is
finished already, before wait_reshape() start. This can lead to wait
for change state inside this function for a long time.  To avoid this
before wait we should test if finish conditions are not reached
already.

Signed-off-by: Adam Kwolek <adam.kwolek@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoFIX: sync_completed_fd handler has to be closed
Adam Kwolek [Fri, 3 Dec 2010 04:07:04 +0000 (15:07 +1100)] 
FIX: sync_completed_fd handler has to be closed

sync_completed_fd handler has to be closed when array is closing.
This is in pair to open handler code.

Signed-off-by: Adam Kwolek <adam.kwolek@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoFIX: Do not use layout for raid4 and raid0 while geo map computing
Adam Kwolek [Fri, 3 Dec 2010 04:03:25 +0000 (15:03 +1100)] 
FIX: Do not use layout for raid4 and raid0 while geo map computing

After takeover, layout has no meaning for computing geo map for raid0
and raid4.  Set layout to 0 for such cases.  It can happen after
takeover operation when not all array information is reread.

Signed-off-by: Adam Kwolek <adam.kwolek@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoGrow: open backup file for reshape as function
Adam Kwolek [Fri, 3 Dec 2010 04:00:16 +0000 (15:00 +1100)] 
Grow: open backup file for reshape as function

Move opening backup file to the function for future reuse during
container reshape.

Signed-off-by: Adam Kwolek <adam.kwolek@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoAdd support to skip slot configuration
Adam Kwolek [Thu, 2 Dec 2010 08:19:12 +0000 (09:19 +0100)] 
Add support to skip slot configuration

When disk is added, set valid slot numbers (positive) only.

Signed-off-by: Adam Kwolek <adam.kwolek@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoFIX: Cannot exit monitor after takeover
Adam Kwolek [Thu, 2 Dec 2010 08:18:49 +0000 (09:18 +0100)] 
FIX: Cannot exit monitor after takeover

When performing backward takeover to raid0 monitor cannot exit
for single raid0 array configuration.
Monitor is locked by communication (ping_manager()) after unfreeze()

Do not ping manager for raid0 array as they shouldn't be monitored.

Signed-off-by: Adam Kwolek <adam.kwolek@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoMonitor: don't add more spares than needed
Anna Czarnowska [Fri, 3 Dec 2010 03:11:29 +0000 (14:11 +1100)] 
Monitor: don't add more spares than needed

When we add a spare to a container it takes a while
before it is noticed by mdmon and recovery starts.
During this time the array remains degraded but we don't want to add
any more spares to this container. Therefore we must check container
with degraded array if it doesn't already have a suitable spare.
container_choose_spare is reused with from=to
Domain check is not needed in this situation.

Ping_manager after moving disk is needed to be able to see
newly added disk in container after coming back through the loop.

Signed-off-by: Anna Czarnowska <anna.czarnowska@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoMonitor: only get min_size once
Anna Czarnowska [Fri, 3 Dec 2010 03:05:11 +0000 (14:05 +1100)] 
Monitor: only get min_size once

We may call chose_spare several times before we find a suitable one
so it is better to get the size beforehand.

Signed-off-by: Anna Czarnowska <anna.czarnowska@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoMonitor: pass statelist reference when adding new arrays
Anna Czarnowska [Tue, 30 Nov 2010 12:44:45 +0000 (13:44 +0100)] 
Monitor: pass statelist reference when adding new arrays

Otherwise it will not get updated.

Signed-off-by: Anna Czarnowska <anna.czarnowska@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoCreate/grow: improve checks on number of devices.
NeilBrown [Wed, 1 Dec 2010 03:51:27 +0000 (14:51 +1100)] 
Create/grow: improve checks on number of devices.

Check on upper limit of number of devices was in the wrong place.
Result was could not create array with more than 27 devices without
explicitly setting metadata, even though default metadata allows more.

Fixed, and also perform check when growing an array.

Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoGrow: disallow placing backup file on array being reshaped.
NeilBrown [Wed, 1 Dec 2010 00:58:32 +0000 (11:58 +1100)] 
Grow: disallow placing backup file on array being reshaped.

the tests here aren't perfect, but they could catch some cases.

Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoAssemble: allow an array undergoing reshape to be started without backup file
NeilBrown [Wed, 1 Dec 2010 00:47:32 +0000 (11:47 +1100)] 
Assemble: allow an array undergoing reshape to be started without backup file

Though not having the proper backup file can cause data corruption, it
is not enough to justify not being able to start the array at all.
So allow "--invalid-backup" to be specified which says "just continue
even if a backup cannot be restored".

Signed-off-by: NeilBrown <neilb@suse.de>
13 years agofix: assemble for external metadata generates segfault if invalid device found
Hawrylewicz Czarnowski, Przemyslaw [Wed, 1 Dec 2010 00:06:09 +0000 (11:06 +1100)] 
fix: assemble for external metadata generates segfault if invalid device found

An attempt to invoke super_by_fd() on device that has
metadata_version="none" always matches super0 (as test_version is "").
In Assemble() it results in segfault when load_container is invoked
(=null for super0).
As of now load_container is only started if it points to valid pointer.

Signed-off-by: Przemyslaw Czarnowski <przemyslaw.hawrylewicz.czarnowski@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoCreate: report failure if array cannot be started.
NeilBrown [Wed, 1 Dec 2010 00:03:28 +0000 (11:03 +1100)] 
Create: report failure if array cannot be started.

We weren't checking the result of writing 'active' to array_state

Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoddf: fail creation of new subarray with same name as old.
NeilBrown [Tue, 30 Nov 2010 22:55:35 +0000 (09:55 +1100)] 
ddf: fail creation of new subarray with same name as old.

Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoddf: don't print warning on assemble
NeilBrown [Tue, 30 Nov 2010 22:47:21 +0000 (09:47 +1100)] 
ddf: don't print warning on assemble

Now that we check the error return of 'update_super' better, we
much make sure that ddf doesn't incorrectly report that the
superblocks are wrong during assemble.

Signed-off-by: NeilBrown <neilb@suse.de>
13 years agomdmon: don't copy an invalid chunk_size
NeilBrown [Tue, 30 Nov 2010 07:35:36 +0000 (18:35 +1100)] 
mdmon: don't copy an invalid chunk_size

As chunk_size in mdstat_ent is never set, we shouldn't copy
it into a->info.array.
In fact, it is safest to get rid of the field altogether.

Reported-by: "Kwolek, Adam" <adam.kwolek@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoAssemble: call remove_partitions later.
NeilBrown [Tue, 30 Nov 2010 05:56:01 +0000 (16:56 +1100)] 
Assemble: call remove_partitions later.

We shouldn't call remove_partitions until we have made a really firm
decision to include the device into the array.

Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoAssemble: add --update=no-bitmap
NeilBrown [Tue, 30 Nov 2010 05:46:01 +0000 (16:46 +1100)] 
Assemble: add --update=no-bitmap

This allows an array with a corrupt internal bitmap to be assembled
without the bitmap.

Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoGrow: give useful message when adding bitmap gives EBUSY.
NeilBrown [Tue, 30 Nov 2010 05:34:25 +0000 (16:34 +1100)] 
Grow: give useful message when adding bitmap gives EBUSY.

If adding a bitmap fails with EBUSY, then it is because the array is
currently resyncing/recovering/reshaping.
As this is non-obvious, give a message explaining the fact.

Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoFix warning about host-endian bitmaps.
NeilBrown [Tue, 30 Nov 2010 05:25:26 +0000 (16:25 +1100)] 
Fix warning about host-endian bitmaps.

Hostendian bitmaps should be warned about on all arch's.
And fix a speeling mistake.

Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoAllow K,M,G suffix on chunk sizes as well as device/array sizes.
NeilBrown [Tue, 30 Nov 2010 05:23:02 +0000 (16:23 +1100)] 
Allow K,M,G suffix on chunk sizes as well as device/array sizes.

We already allow K,M,G suffixes for --size and --array-size.
Allow it for --chunk and --bitmap-chunk as well.

Also add this info to man page, and remove the duplication of info
about --array-size.

Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoCompute backup blocks in function.
Adam Kwolek [Tue, 30 Nov 2010 02:30:22 +0000 (13:30 +1100)] 
Compute backup blocks in function.

number of backup blocks evaluation is put in to function for code reuse.

Signed-off-by: Adam Kwolek <adam.kwolek@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoPrepare and free fdlist in functions
Adam Kwolek [Tue, 30 Nov 2010 02:27:08 +0000 (13:27 +1100)] 
Prepare and free fdlist in functions

fd handles table creation is put in to function for code reuse.

In manage_reshape(), child_grow() function from Grow.c will be reused.
To prepare parameters for this function, code from Grow.c can be
reused also.

Signed-off-by: Adam Kwolek <adam.kwolek@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoimsm: Allow multiple spares to be collected.
Adam Kwolek [Fri, 26 Nov 2010 07:08:01 +0000 (08:08 +0100)] 
imsm: Allow multiple spares to be collected.

Assumption for spares searching was that after picking new device, it
has to be added to array before next search.  This causes returning
different disk on each call.

When creating a spare list during Online Capacity Expansion, we will
first collect the devices list and then all devices are added to md.
Picked device from spares pool has to be checked against picked
devices so far. If not, the same disk will be returned all the time.
Already picked devices are stored in the list and this list is used
for new devices verification also.

So add an extra arg to imsm_add_spare to hold a list of known
spares to ignore.

Signed-off-by: Adam Kwolek <adam.kwolek@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoimsm: FIX: core dump during imsm metadata writing
Adam Kwolek [Mon, 29 Nov 2010 01:53:16 +0000 (12:53 +1100)] 
imsm: FIX: core dump during imsm metadata writing

Wrong number of disks during metadata update causes core dump.  New
disks number based on internal mdmon information has to used for
calculation (not previously read from metadata).

Signed-off-by: Adam Kwolek <adam.kwolek@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoimsm: Add support for general migration
Adam Kwolek [Mon, 29 Nov 2010 01:28:01 +0000 (12:28 +1100)] 
imsm: Add support for general migration

Internal IMSM procedures need to support the General Migration.
It is used during operations like:
- Online Capacity Expansion,
- migration initialization,
- finishing migration,
- apply changes to raid disks etc.

Signed-off-by: Adam Kwolek <adam.kwolek@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoTreat feature as experimental
Adam Kwolek [Mon, 29 Nov 2010 01:11:09 +0000 (12:11 +1100)] 
Treat feature as experimental

Due to fact that IMSM Windows compatibility was not tested yet,
feature has to be treated as experimental until compatibility
verification will be performed.

Signed-off-by: Adam Kwolek <adam.kwolek@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoDisk removal support for Raid10->Raid0 takeover
Adam Kwolek [Mon, 29 Nov 2010 00:57:51 +0000 (11:57 +1100)] 
Disk removal support for Raid10->Raid0 takeover

Until now Raid10->Raid0 takeover was possible only if all the mirrors
where removed before md starts the takeover.  Now mdadm, when
performing Raid10->raid0 takeover, will remove all unwanted mirrors
from the array before actual md takeover is called.

Signed-off-by: Maciej Trela <maciej.trela@intel.com>
Signed-off-by: Adam Kwolek <adam.kwolek@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoImprove comments for block_monitor.
NeilBrown [Sun, 28 Nov 2010 23:32:15 +0000 (10:32 +1100)] 
Improve comments for block_monitor.

Also not that the leading '-' on the metadata names now
simply means that mdmon must not reconfiure the array.

Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoMonitor: array that has disappeared doesn't need spares
Anna Czarnowska [Fri, 26 Nov 2010 13:31:15 +0000 (14:31 +0100)] 
Monitor: array that has disappeared doesn't need spares

If a degraded array disappears we still have it in statelist
with active<raid but it is pointless to look for spares for it.

Signed-off-by: Anna Czarnowska <anna.czarnowska@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoMonitor: fix writing autorebuild.pid
Anna Czarnowska [Fri, 26 Nov 2010 13:29:53 +0000 (14:29 +0100)] 
Monitor: fix writing autorebuild.pid

If /var/run/mdadm doesn't exist we can never succeed writing
so we should try to create it first. When we make sure it is there we
write pid file as before.

Signed-off-by: Anna Czarnowska <anna.czarnowska@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoMonitor: reset dev when size too small
Anna Czarnowska [Fri, 26 Nov 2010 10:51:59 +0000 (11:51 +0100)] 
Monitor: reset dev when size too small

Cc: linux-raid@vger.kernel.org, Williams, Dan J <dan.j.williams@intel.com>, Ciechanowski, Ed <ed.ciechanowski@intel.com>
Otherwise spare will be considered good anyway.

Signed-off-by: Anna Czarnowska <anna.czarnowska@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoMonitor: devid should be dev_t
Anna Czarnowska [Fri, 26 Nov 2010 10:49:33 +0000 (11:49 +0100)] 
Monitor: devid should be dev_t

For consistency with makedev().
int is not sufficient.

Signed-off-by: Anna Czarnowska <anna.czarnowska@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoMonitor: few bug fixes for spare migration
Anna Czarnowska [Sun, 28 Nov 2010 22:51:27 +0000 (09:51 +1100)] 
Monitor: few bug fixes for spare migration

1. If array not changed we should still report any degraded
    - another array may have a new spare that we can move.
2. Array with err=1 can't give a spare.
3. We look for spares in "from" not "st" which is supertype
   and has devname=NULL.

Signed-off-by: Anna Czarnowska <anna.czarnowska@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoSpare migration tests
Anna Czarnowska [Sun, 28 Nov 2010 22:43:29 +0000 (09:43 +1100)] 
Spare migration tests

This is a series of tests checking if mdadm Monitor migrates spares
according to rules in /etc/mdadm.conf defined by POLICY lines.

Signed-off-by: Anna Czarnowska <anna.czarnowska@intel.com>
Signed-off-by: Marcin Labun <marcin.labun@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoIncremental - avoid including wayward devices.
NeilBrown [Sun, 28 Nov 2010 22:40:15 +0000 (09:40 +1100)] 
Incremental - avoid including wayward devices.

If a devices - typically in a mirrored set - is assembled
independently of the other devices, and then attempted to be brought
back into the set, it could contain inconsistent data.  It should not
be included.

So detect this situation by ensuring that the 'most recent' device is
believed to be active by every other device.  If a device is wayward,
it will only consider fellow wayward devices to be active and will
think all others are failed or missing.

This patches fixes --incremental, --assemble was done in an earlier
patch.

Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoImprove opt parsing, and distinguish long from short.
NeilBrown [Thu, 25 Nov 2010 07:58:45 +0000 (18:58 +1100)] 
Improve opt parsing, and distinguish long from short.

In several cases, two different long options map to the same short
option.  So e.g. you could give '--brief' and it would be interpreted
as '--bitmap'.  That isn't really good.

So for every shared short option, define an option number and return
that for the long option instead.  Then always check for both the
short and long options.

Also give some bugs like " mode == 'G'" which should be '== GROW'.

Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoIncr: reduce the number of times we load data from sysfs.
NeilBrown [Thu, 25 Nov 2010 07:58:44 +0000 (18:58 +1100)] 
Incr: reduce the number of times we load data from sysfs.

Rather than calling sysfs_read whenever we want data from sysfs, call
it once at the start will all the requests of interest, then just use
that,

Make sure we free it properly too.

Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoMonitor: choose spare correctly for external metadata.
NeilBrown [Thu, 25 Nov 2010 07:58:27 +0000 (18:58 +1100)] 
Monitor: choose spare correctly for external metadata.

When metadata is managed externally - probably as a container - we
need to examine that metadata to see which devices are spares.

So use the getinfo_super_disk message and use the info returned.

Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoMonitor: separate 'choose_spare' out from 'move_spare'
NeilBrown [Thu, 25 Nov 2010 07:37:23 +0000 (18:37 +1100)] 
Monitor: separate 'choose_spare' out from 'move_spare'

choosing a spare from a container is more complicated that
from a native array.  So separate out choose_spare to make it easier
to use an alternate implementation

Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoExternal reshape (step 2): Freeze container
Dan Williams [Tue, 23 Nov 2010 05:39:58 +0000 (16:39 +1100)] 
External reshape (step 2): Freeze container

When growing the number of raid disks the reshape process will promote
container-spares to subarray-spares (later the kernel promotes them to
subarray-members in raid5_start_reshape()).  The automatic spare
promotion that mdmon performs upon seeing a degraded array must be
disabled until the reshape process has been initiated.  Otherwise, mdmon
may start a rebuild before the reshape parameters can be specified.

In the external case we arrange for the monitor to be blocked, and
turn off the safemode delay.
Mdmon is updated to check sync_action is not frozen before initiating
recovery.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoExternal reshape (step 1): container reshape and ->reshape_super()
Dan Williams [Thu, 18 Nov 2010 09:22:59 +0000 (10:22 +0100)] 
External reshape (step 1): container reshape and ->reshape_super()

In the native metadata case Grow_reshape() and the kernel validate what
reshapes are possible / supported and the kernel handles all the metadata
updates.  In the external case the metadata format may have specific
constraints above this baseline.  External formats also introduce the
constraint of only permitting some reshapes at container scope versus subarray
scope.  For exmaple imsm changes to 'raiddisks' must be applied to all arrays
in the container.

This operation assumes that its 'st' parameter has been obtained from
super_by_fd() (such that st->subarray is up to date), and that a snapshot of
the metadata has been loaded from the container.

Why a new method, versus extending an existing one?
->validate_geometry: this routine assumes it is being called from Create(),
adding reshape complicates the cases that this routine needs to handle.  Where
we find that checks can be shared between the two cases those routines
refactored into common code internal to the metadata handler, i.e. no need to
provide a unified external interface.  ->validate_geometry() also does not
expect to update the metadata.

->update_super: this is meant to update single fields at Assembly() and only at
the container scope.  Reshape potentially wants to update multiple fields at
either container or subarray scope.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoDocument the external reshape implementation
Dan Williams [Tue, 23 Nov 2010 04:53:00 +0000 (15:53 +1100)] 
Document the external reshape implementation

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoInitialize st->devnum and st->container_dev in super_by_fd
Dan Williams [Tue, 23 Nov 2010 04:31:18 +0000 (15:31 +1100)] 
Initialize st->devnum and st->container_dev in super_by_fd

Precludes needing to deduce this information later, like in Detail.c and
soon in Grow.c.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoCreate: cleanup/unify default geometry handling
Dan Williams [Thu, 18 Nov 2010 09:22:33 +0000 (10:22 +0100)] 
Create: cleanup/unify default geometry handling

Support metadata specific level, layout and chunksize defaults.  Kill an
uneeded superswitch methods ahead of adding more for the reshape case.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agofix a get_linux_version() comparison typo
Dan Williams [Thu, 18 Nov 2010 09:22:25 +0000 (10:22 +0100)] 
fix a get_linux_version() comparison typo

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoGrow: fix check for raid6 layout normalization
Dan Williams [Thu, 18 Nov 2010 09:22:09 +0000 (10:22 +0100)] 
Grow: fix check for raid6 layout normalization

If the user does not specify a layout, don't skip asking about retaining
the non-standard raid6 layout which may be implicitly changed.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoAssemble: fix assembly in the delta_disks > max_degraded case
Dan Williams [Thu, 18 Nov 2010 09:22:01 +0000 (10:22 +0100)] 
Assemble: fix assembly in the delta_disks > max_degraded case

Incremental assembly works on such an array because the kernel sees the
disk as in-sync and that the array is reshaping.  Teach Assemble() the
same assumptions.

This is only needed on kernels that do not initialize ->recovery_offset
when activating spares for reshape.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoGrow: mark some functions static
Dan Williams [Thu, 18 Nov 2010 09:21:53 +0000 (10:21 +0100)] 
Grow: mark some functions static

Going through the Grow api found some local routines that could be
marked static.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoManage: allow manual control of external raid0 readonly flag
Dan Williams [Tue, 23 Nov 2010 04:08:19 +0000 (15:08 +1100)] 
Manage: allow manual control of external raid0 readonly flag

mdadm --readwrite <subarray> will clear the external readonly flag ('-'
to '/'), but only for redudant arrays.  Allow raid0 arrays as well so
the user has a simple helper to control this flag.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoblock monitor: freeze spare assignment for external arrays
Dan Williams [Tue, 23 Nov 2010 04:00:54 +0000 (15:00 +1100)] 
block monitor: freeze spare assignment for external arrays

In order to support reshape and atomic removal of spares from containers
we need to prevent mdmon from activating spares.  In the reshape case we
additionally need to freeze sync_action while the reshape transaction is
initiated with the kernel and recorded in the metadata.

When reshaping a raid0 array we need to freeze the array *before* it is
transitioned to a redundant raid level.  Since sync_action does not exist
at this point we extend the '-' prefix of a subarray string to flag
mdmon not to activate spares.

Mdadm needs to be reasonably certain that the version of mdmon in the
system honors this 'freeze' indication.  If mdmon is not already active
then we assume the version that gets started is the same as the mdadm
version.  Otherwise, we check the version of mdmon as returned by the
extended ping_monitor() operation.  This is to catch cases where mdadm
is upgraded in the filesystem, but mdmon started in the initramfs is
from a previous release.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoProvide a mdstat_ent to subarray helper
Dan Williams [Thu, 18 Nov 2010 09:21:29 +0000 (10:21 +0100)] 
Provide a mdstat_ent to subarray helper

...before introducing another open coded instace of this conversion.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoAssemble: get content before testing it.
NeilBrown [Tue, 23 Nov 2010 00:34:36 +0000 (11:34 +1100)] 
Assemble: get content before testing it.

When checking that a container matches the required uuid,
we need to call 'getinfo_super' before we have a 'content'
to test.

Reported-by: "Czarnowska, Anna" <anna.czarnowska@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoMonitor: check spare group is non-NULL before adding to domain list
NeilBrown [Tue, 23 Nov 2010 00:11:45 +0000 (11:11 +1100)] 
Monitor: check spare group is non-NULL before adding to domain list

... otherwise we crash.

Reported-by: "Labun, Marcin" <Marcin.Labun@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoPolicy is aware of metadata disk's controller domains.
Marcin Labun [Mon, 22 Nov 2010 09:58:07 +0000 (20:58 +1100)] 
Policy is aware of metadata disk's controller domains.

Platform (metadata) domain let the metadata handlers differentiate
disk domains based on controllers that the disk belongs to.
Platform domain is sub-domain inside user specified domain
in mdadm.conf configuration files inheriting all parameters from it.
The metadata domain name is used disk domain matching functions.
The disk with the same metadata domain name belong to the same metadata
domain.

New metadata handler is added that retrieves platform domain string based
on disk path:
const char *(*get_disk_controller_domain)(const char *path);

Signed-off-by: Marcin Labun <marcin.labun@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoMonitor: Allow metadata to set minimum size for spare to migrate in.
Anna Czarnowska [Mon, 22 Nov 2010 09:58:07 +0000 (20:58 +1100)] 
Monitor: Allow metadata to set minimum size for spare to migrate in.

Signed-off-by: Anna Czarnowska <anna.czarnowska@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoMonitor: teach spare migration about containers
NeilBrown [Mon, 22 Nov 2010 09:58:07 +0000 (20:58 +1100)] 
Monitor: teach spare migration about containers

When trying to move a spare, move to the container of a degraded
array, not to the array itself.
And don't try to move from a subarray, only from a native or container
array.
And don't move from a container which contains degraded subarrays.

Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoMonitor: policy based spare migration.
NeilBrown [Mon, 22 Nov 2010 09:58:07 +0000 (20:58 +1100)] 
Monitor: policy based spare migration.

Rather than only migrating between arrays with the same spare_group,
we now migrate based on domains set in the policy.

In order for spare_group to continue to work, we treat it as a domain
of the destination array, and a domain of any device we might remove
from a source array.

Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoMonitor: split out check_donor
NeilBrown [Mon, 22 Nov 2010 09:58:07 +0000 (20:58 +1100)] 
Monitor: split out check_donor

Checking compatibility between arrays for spare migration is going to
become a little more complicated, so split it out into a separate
function.

Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoMonitor: split out move_spare in spare migration.
NeilBrown [Mon, 22 Nov 2010 09:58:07 +0000 (20:58 +1100)] 
Monitor: split out move_spare in spare migration.

This is a simple refactoring with no functionality change.

Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoMonior: create struct for holding alert info.
NeilBrown [Mon, 22 Nov 2010 09:58:07 +0000 (20:58 +1100)] 
Monior: create struct for holding alert info.

Rather than passing mailaddr, mailfrom, cmd, dosyslog around in
argument lists, create a structure to hold them all.

Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoMonitor: use calloc rather than malloc
NeilBrown [Mon, 22 Nov 2010 09:58:07 +0000 (20:58 +1100)] 
Monitor: use calloc rather than malloc

calloc zeros the memory allocated, which is safer, particularly as
we add more things to struct state.

Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoMonitor: minor optimisation to spare migration.
NeilBrown [Mon, 22 Nov 2010 09:58:07 +0000 (20:58 +1100)] 
Monitor: minor optimisation to spare migration.

Only try spare migration if we know that at least one array is
degraded.

Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoimsm: create mdinfo list of disks in a container from supertype
Anna Czarnowska [Mon, 22 Nov 2010 09:58:07 +0000 (20:58 +1100)] 
imsm: create mdinfo list of disks in a container from supertype

If getinfo_super is called on a container supertype we only get information
on first disk. As a parameter it uses reference to preallocated
mdinfo structure. Amending getinfo_super to return full list of disks
would require ammending all previous calls and subsequently freeing memory
allocated for mdinfo list.
Function container_content that returns a mdinfo list is written
specifically for assembly, performing actions not needed to just fill
mdinfo. It also does not include spares so is unsuitable.
As an alternative a new function getinfo_super_disks is created
to obtain information about all disks states in array.
Existing function sysfs_free is used to free memory
allocated by getinfo_super_disks.

Signed-off-by: Anna Czarnowska <anna.czarnowska@intel.com>
Signed-off-by: Marcin Labun <marcin.labun@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoMonitor: link containers with subarrays in statelist
Marcin Labun [Mon, 22 Nov 2010 09:58:07 +0000 (20:58 +1100)] 
Monitor: link containers with subarrays in statelist

Each containers has list of its subarrays. Each subarray
has back link to its parent container.

Signed-off-by: Marcin Labun <marcin.labun@intel.com>
Signed-off-by: Anna Czarnowska <anna.czarnowska@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoBreak Monitor into smaller functions.
NeilBrown [Mon, 22 Nov 2010 09:58:07 +0000 (20:58 +1100)] 
Break Monitor into smaller functions.

Monitor() has become way too big.  Break it up into multiple smaller
functions that are all called from the main loop.

Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoMonitor: track metadata type or parent/container of arrays.
NeilBrown [Mon, 22 Nov 2010 09:58:07 +0000 (20:58 +1100)] 
Monitor: track metadata type or parent/container of arrays.

For subarrays, record the devid of the parent.
For others arrays, record the metadata type.

This will be used in a subsequent patch to link related arrays
together and allow spare migration between containers.

Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoMonitor: include containers in scan mode
Anna Czarnowska [Mon, 22 Nov 2010 09:58:07 +0000 (20:58 +1100)] 
Monitor: include containers in scan mode

Signed-off-by: Marcin Labun <marcin.labun@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoMonitor: avoid skipping checks on external arrays
NeilBrown [Mon, 22 Nov 2010 09:58:06 +0000 (20:58 +1100)] 
Monitor: avoid skipping checks on external arrays

utime is not correct for external metadata so we must
not risk the observed time ever matching the old time.

Reported-by: Anna Czarnowska <anna.czarnowska@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agomdadm: added --no-sharing option for Monitor mode
Anna Czarnowska [Mon, 22 Nov 2010 09:58:06 +0000 (20:58 +1100)] 
mdadm: added --no-sharing option for Monitor mode

--no-sharing option disables moving spares between arrays/containers.
Without the option spares are moved if needed according to config rules.
We only allow one process moving spares started with --scan option.
If there is such process running and another instance of Monitor
is starting without --scan, then we issue a warning but allow it
to continue.

Signed-off-by: Anna Czarnowska <anna.czarnowska@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoMonitor: set err on arrays not in mdstat
Anna Czarnowska [Mon, 22 Nov 2010 09:58:06 +0000 (20:58 +1100)] 
Monitor: set err on arrays not in mdstat

mse can be NULL when the array was not in mdstat when we read it
but existed in statelist and was recreated after reading mdstat.
In this case we set err as we can't get full update on this array
this time.
If the same array is given twice in command line it appears twice
in statelist. The first one will mark mse->devnum=INT_MAX
so the second one can't find mse. We set err on the second one as
it's not needed. Also if it becomes degraded we would look for spares
twice for the same array.

Signed-off-by: Anna Czarnowska <anna.czarnowska@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
13 years agoUtil: get device size from id
Anna Czarnowska [Mon, 22 Nov 2010 09:58:06 +0000 (20:58 +1100)] 
Util: get device size from id

Signed-off-by: Anna Czarnowska <anna.czarnowska@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>