Go to file
Dan Williams 836759d561 mdmon: ignore inactive arrays and other manage_new() cleanups
While mdadm is constructing an array mdmon may see an intermediate state
(some disks not yet added / redundancy attributes like sync_action not
available).  Waiting for mdstat->active == true ensures that the array
is ready to be handled.  This fixes a bug in create array via mdmon
update whereby failures are not detected in the new array.

Introduce aa_ready() to catch cases where the active_array is not
correctly initialized.  Barring a kernel bug this should never trigger,
nonetheless it precludes a class of bugs like the one mentioned above
from triggering.

Cleanup the exit paths and only call replace_array when the new array is
ready to be inserted into container->arrays.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2008-08-04 16:48:27 -07:00
misc mdadm-1.8.0 2004-11-01 04:49:34 +00:00
tests Fix autoassemble for stack arrays. 2008-05-20 16:28:48 +10:00
.gitignore Add a .gitignore file. 2008-04-29 17:14:01 +10:00
ANNOUNCE-2.0 Release!! 2005-08-26 06:37:33 +00:00
ANNOUNCE-2.1 Release 2-0 2005-09-12 07:12:07 +00:00
ANNOUNCE-2.2 Release 2.2 2005-12-09 04:55:02 +00:00
ANNOUNCE-2.3 Update ChangeLog and release 2.3 2006-02-02 05:17:24 +00:00
ANNOUNCE-2.3.1 Add ANNOUNCE-2.3.1 2006-02-06 04:11:49 +00:00
ANNOUNCE-2.4 Add ANNOUNCE-2.4 2006-03-30 04:24:09 +00:00
ANNOUNCE-2.4-pre1 Add ANNOUNCE-2.4-pre1 2006-03-20 03:34:49 +00:00
ANNOUNCE-2.4.1 Release 2.4.1 2006-04-17 12:49:28 +00:00
ANNOUNCE-2.5 Release 2.5 2006-05-26 07:12:48 +00:00
ANNOUNCE-2.5.1 Release 2.5.1 2006-06-16 10:54:14 +10:00
ANNOUNCE-2.5.2 Release 2.5.2 2006-06-27 21:31:58 +10:00
ANNOUNCE-2.5.3 Release 2.5.3 2006-08-07 12:00:30 +10:00
ANNOUNCE-2.5.4 Release 2-5-4 2006-10-13 10:12:47 +10:00
ANNOUNCE-2.5.5 Release 2-5-5 2006-11-03 14:52:28 +11:00
ANNOUNCE-2.5.6 Release 2.5.6 2006-11-09 10:00:32 +11:00
ANNOUNCE-2.6 Release 2.6 2006-12-21 17:24:38 +11:00
ANNOUNCE-2.6.1 Add ANNOUNCE-2.6.1 to git 2007-09-24 14:40:23 +10:00
ANNOUNCE-2.6.2 Release 2.6.2 2007-05-21 14:25:53 +10:00
ANNOUNCE-2.6.3 Release 2.6.3 2007-08-20 14:22:15 +10:00
ANNOUNCE-2.6.4 Release 2.6.4 2007-10-19 14:13:04 +10:00
ANNOUNCE-2.6.5 Release 2.6.5 2008-05-15 15:50:59 +10:00
ANNOUNCE-2.6.6 Release 2.6.6 2008-05-19 12:07:54 +10:00
ANNOUNCE-2.6.7 Release 2.6.7 2008-06-06 16:07:11 +10:00
Assemble.c Remove getinfo_super_n and do some other cleaning up. 2008-07-12 20:27:39 +10:00
bitmap.c Use O_DIRECT for all IO to devices. 2008-07-12 20:28:33 +10:00
bitmap.h Remove spaces/tabs from ends of lines. 2007-12-14 20:13:43 +11:00
Build.c Remove spaces/tabs from ends of lines. 2007-12-14 20:13:43 +11:00
ChangeLog Release 2.6.7 2008-06-06 16:07:11 +10:00
config.c Fix for segfault when reading /proc/mdstat 2008-04-28 16:29:12 +10:00
COPYING mdctl-0.6 2002-03-06 23:17:40 +00:00
crc32.c Add crc32 files. 2008-05-15 16:48:10 +10:00
crc32.h Add crc32 files. 2008-05-15 16:48:10 +10:00
Create.c Factor common code into new "start_mdmon". 2008-07-18 16:37:11 +10:00
Detail.c add --export option to --examine 2008-05-06 10:02:38 +10:00
dlink.c mdadm-1.5.0 2004-01-22 02:10:29 +00:00
dlink.h This is to avoid gcc warnings when building with strict-aliasing optimization 2006-05-29 02:06:32 +00:00
Examine.c add --export option to --examine 2008-05-06 10:02:38 +10:00
Grow.c Use O_DIRECT for all IO to devices. 2008-07-12 20:28:33 +10:00
Incremental.c Factor common code into new "start_mdmon". 2008-07-18 16:37:11 +10:00
INSTALL mdadm-0.8.1 2002-04-05 22:00:28 +00:00
inventory Release 2.6.7 2008-06-06 16:07:11 +10:00
kernel-patch-2.6.18 Add new mode: --incremental 2006-12-21 17:10:52 +11:00
kernel-patch-2.6.18.6 Add new mode: --incremental 2006-12-21 17:10:52 +11:00
kernel-patch-2.6.19 Add new mode: --incremental 2006-12-21 17:10:52 +11:00
kernel-patch-2.6.25 Fix kernel patch 2008-07-12 20:27:39 +10:00
Kill.c Use O_DIRECT for all IO to devices. 2008-07-12 20:28:33 +10:00
makedist Release 2.5.1 2006-06-16 10:54:14 +10:00
Makefile install mdmon to the same location as mdadm 2008-07-21 17:42:12 -07:00
Manage.c Manage: sync with mdmon before stopping containers. 2008-07-18 16:37:25 +10:00
managemon.c mdmon: ignore inactive arrays and other manage_new() cleanups 2008-08-04 16:48:27 -07:00
mapfile.c Use text_version in map_file rather than major.minor. 2008-07-12 20:27:37 +10:00
md_p.h Remove spaces/tabs from ends of lines. 2007-12-14 20:13:43 +11:00
md_u.h Remove spaces/tabs from ends of lines. 2007-12-14 20:13:43 +11:00
md.4 Documentation fixup for stripe_cache_size 2008-07-18 17:47:13 -07:00
md5.h Make homehost information appear in superblock. 2006-05-19 06:56:06 +00:00
mdadm.8 Document MDADM_NO_MDMON 2008-07-18 17:47:34 -07:00
mdadm.c Stop managed arrays more carefully. 2008-07-18 16:37:09 +10:00
mdadm.conf-example Fix silly example 2005-06-14 06:33:45 +00:00
mdadm.conf.5 Fix possible bug with bitmap space allocation with v1.0 metadata 2008-04-29 17:13:53 +10:00
mdadm.h sysfs: deprecate sysfs_disk_to_sg 2008-07-24 17:26:24 -07:00
mdadm.spec Release 2.6.7 2008-06-06 16:07:11 +10:00
mdassemble.8 Release 2.6.7 2008-06-06 16:07:11 +10:00
mdassemble.c Mdassemble improvements 2006-10-16 15:26:53 +10:00
mdmon.c mdmon: don't fork if DEBUG 2008-07-24 17:26:24 -07:00
mdmon.h mdmon: ping will wait for manage_mon to catch up. 2008-07-18 16:37:06 +10:00
mdopen.c Make device-special files for partitions when using --incremental 2008-05-05 21:55:39 +10:00
mdstat.c Introduce devname2devnum 2008-07-12 20:28:38 +10:00
mkinitramfs Guides on how to use mdadm with initramfs 2005-12-05 05:56:42 +00:00
monitor.c imsm: handle degraded->normal transitions in set_disk 2008-07-24 17:26:23 -07:00
Monitor.c Fix for segfault when reading /proc/mdstat 2008-04-28 16:29:12 +10:00
msg.c msg: add a timeout to ping_monitor 2008-07-18 16:37:28 +10:00
msg.h Revise message passing code. 2008-07-12 20:27:40 +10:00
pwgr.c Improve compiling for static binaries. 2006-05-29 04:09:21 +00:00
Query.c Remove 'major' from superswitch. 2008-07-12 20:27:37 +10:00
raid5extend.c Remove spaces/tabs from ends of lines. 2007-12-14 20:13:43 +11:00
ReadMe.c Merge branch 'master' into devel-3.0 2008-06-19 16:38:37 +10:00
README.initramfs Guides on how to use mdadm with initramfs 2005-12-05 05:56:42 +00:00
restripe.c Teach restripe to calculate Q syndrome for raid6. 2007-02-22 14:59:19 +11:00
sg_io.c imsm: initial Intel(R) Matrix Storage Manager support 2008-05-15 16:48:22 +10:00
sha1.c Make homehost information appear in superblock. 2006-05-19 06:56:06 +00:00
sha1.h Make homehost information appear in superblock. 2006-05-19 06:56:06 +00:00
super-ddf.c Make sure resync_start is initialised properly and maintained properly 2008-07-18 16:37:04 +10:00
super-intel.c imsm: trim some memory wastage 2008-07-25 17:45:13 -07:00
super1.c Pass 'verbose' flag to validate_geometry 2008-07-12 20:28:38 +10:00
super0.c Pass 'verbose' flag to validate_geometry 2008-07-12 20:28:38 +10:00
swap_super.c Getting ready for 2.0 release... 2005-08-26 02:26:37 +00:00
sysfs.c sysfs: deprecate sysfs_disk_to_sg 2008-07-24 17:26:24 -07:00
test Stop all arrays before running each test in regression test driver. 2008-07-12 20:27:42 +10:00
TODO Initial DDF support code. 2008-05-15 16:48:14 +10:00
util.c mdmon: fork and run as a daemon. 2008-07-18 16:37:20 +10:00

Assembling md arrays at boot time.
---------------------------------
December 2005

These notes apply to 2.6 kernels only and, in some cases,
to 2.6.15 or later.

Md arrays can be assembled at boot time using the 'autodetect' functionality
which is triggered by storing components of an array in partitions of type
'fd' - Linux Raid Autodetect.
They can also be assembled by specifying the component devices in a
kernel parameter such as
  md=0,/dev/sda,/dev/sdb
In this case, /dev/md0 will be assembled (because of the 0) from the listed
devices.

These mechanisms, while useful, do not provide complete functionality
and are unlikely to be extended.  The preferred way to assemble md
arrays at boot time is using 'mdadm' or 'mdassemble' (which is a
trimmed-down mdadm).  To assemble an array which contains the root
filesystem, mdadm needs to be run before that filesystem is mounted,
and so needs to be run from an initial-ram-fs.  It is how this can
work that is the primary focus of this document.

It should be noted up front that only the array containing the root
filesystem should be assembled from the initramfs.  Any other arrays
should be assembled under the control of files on the main filesystem
as this enhanced flexibility and maintainability.

A minimal initramfs for assembling md arrays can be created using 3
files and one directory.  These are:

/bin           Directory
/bin/mdadm     statically linked mdadm binary
/bin/busybox   statically linked busybox binary
/bin/sh        hard link to /bin/busybox
/init          a shell script which call mdadm appropriately.

An example init script is:

==============================================
#!/bin/sh

echo 'Auto-assembling boot md array'
mkdir /proc
mount -t proc proc /proc
if [ -n "$rootuuid" ]
then arg=--uuid=$rootuuid
elif [ -n "$mdminor" ]
then arg=--super-minor=$mdminor
else arg=--super-minor=0
fi
echo "Using $arg"
mdadm -Acpartitions $arg --auto=part /dev/mda
cd /
mount /dev/mda1 /root ||  mount /dev/mda /root
umount /proc
cd /root
exec chroot . /sbin/init < /dev/console > /dev/console 2>&1
=============================================

This could certainly be extended, or merged into a larger init script.
Though tested and in production use, it is not presented here as
"The Right Way" to do it, but as a useful example.
Some key points are:

  /proc needs to be mounted so that /proc/partitions can be accessed
  by mdadm, and so that /proc/filesystems can be accessed by mount.

  The uuid of the array can be passed in as a kernel parameter
  (rootuuid).  As the kernel doesn't use this value, it is made available
  in the environment for /init

  If no uuid is given, we default to md0, (--super-minor=0) which is a
  commonly used to store the root filesystem.  This may not work in
  all situations.

  We assemble the array as a partitionable array (/dev/mda) even if we
  end up using the whole array.  There is no cost in using the partitionable
  interface, and in this context it is simpler.

  We try mounting both /dev/mda1 and /dev/mda as they are the most like
  part of the array to contain the root filesystem.

  The --auto flag is given to mdadm so that it will create /dev/md*
  files automatically.  This is needed as /dev will not contain
  and md files, and udev will not create them (as udev only created device
  files after the device exists, and mdadm need the device file to create
  the device).  Note that the created md files may not exist in /dev
  of the mounted root filesystem.  This needs to be deal with separately
  from mdadm - possibly using udev.

  We do not need to create device files for the components which will
  be assembled into /dev/mda.  mdadm finds the major/minor numbers from
  /proc/partitions and creates a temporary /dev file if one doesn't already
  exist.

The script "mkinitramfs" which is included with the mdadm distribution
can be used to create a minimal initramfs.  It creates a file called
'init.cpio.gz' which can be specified as an 'initrd' to lilo or grub
(or whatever boot loader is being used).




Resume from an md array
-----------------------

If you want to make use of the suspend-to-disk/resume functionality in Linux,
and want to have swap on an md array, you will need to assemble the array
before resume is possible.
However, because the array is active in the resumed image, you do not want
anything written to any drives during the resume process, such as superblock
updates or array resync.

This can be achieved in 2.6.15-rc1 and later kernels using the
'start_readonly' module parameter.
Simply include the command
  echo 1 > /sys/module/md_mod/parameters/start_ro
before assembling the array with 'mdadm'.
You can then echo
  9:0
or whatever is appropriate to /sys/power/resume to trigger the resume.