Commit Graph

72 Commits

Author SHA1 Message Date
NeilBrown 84a230d993 Revert "mdmon(): Error out if failing to connect to victim monitor"
This reverts commit 819c158866.

Adam Kwolek reports that with this patch, mdmon sometimes doesn't start:

    When array is not clean dismounted directory /dev/.mdadm is not cleaned up.
    On array re-assembly read pid is not valid and it is not possible
    to connect to monitor. This causes mdmon to exit and array remains
    not monitored.
    Problem is introduced by fix:
       mdmon(): Error out if failing to connect to victim monitor
       819c158866

    This is critical for container reshape when mdmon is should finish reshape.
    when reshape is not finished, array is reshaped again by mdadm.

As victim_sock is subsequently tested, we don't really need to test-and-fail here.

Reported-by: Adam Kwolek <adam.kwolek@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
2011-11-07 11:37:12 +11:00
Jes Sorensen 819c158866 mdmon(): Error out if failing to connect to victim monitor
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Signed-off-by: NeilBrown <neilb@suse.de>
2011-11-01 14:56:28 +11:00
Luca Berra e4c72d1dc6 Fix some compiler warnings.
Original by Luca, with various changes by Neil

Signed-off-by: NeilBrown <neilb@suse.de>
2011-06-17 14:35:06 +10:00
Adam Kwolek afbbf073ed Define dummy functions to mdmon.c
Definitions are necessary to compile mdmon.
Metadata specific source code is compiled to mdmon.
Functions used for reshape check pointing:
- restore_stripes()
- save_stripes
- abort_reshape
are not used in mdmon, but they are compiled in it.
To enable mdmon compilation, dummy functions are used.

Signed-off-by: Adam Kwolek <adam.kwolek@intel.com>
Signed-off-by: Krzysztof Wojcik <krzysztof.wojcik@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
2011-06-08 16:28:40 +10:00
Michal Marek f4db7a6f3c mdmon: Fix crash if /proc/mdstat lists 0.9 superblocks
Signed-off-by: Michal Marek <mmarek@suse.cz>
2011-05-17 11:08:16 +10:00
NeilBrown 999b497251 Make child_monitor a candidate for ->manage_reshape
Child_monitor was design to perform 'manage_reshape' for native
arrays.  So change the signature for ->manage_reshape to match
child_monitor and move the all to the same place that child_monitor
is called from.

Also give super-intel a manage_reshape handler which simple calls
child_monitor.

Signed-off-by: NeilBrown <neilb@suse.de>
2011-01-12 14:46:17 +11:00
NeilBrown 0fb69d1dae Replace various load_super calls with load_container
When we call load_super expecting to find a container, we now
just call load_container directly.

Signed-off-by: NeilBrown <neilb@suse.de>
2010-11-22 20:58:06 +11:00
NeilBrown 69b2fcc5bb Remove subarray field in supertype.
This is now only ever set, never used.
So remove it.

Signed-off-by: NeilBrown <neilb@suse.de>
2010-11-22 20:24:50 +11: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
Doug Ledford 753cf90512 Fix all the confusion over directories once and for all.
We now have 3 directory definitions: mdmon directory for its pid and
sock files (compile time define, not changable at run time), mdmonitor
directory which is for the mdadm monitor mode pid file (can only be
passed in via command line at the time mdadm is invoked in monitor mode),
and the directory for the mdadm incremental assembly map file (compile
time define, not changable at run time).  Only the mdadm map file still
hunts multiple locations, and the number of locations has been reduced
to /var/run and the compile time specified location.  Re-use of similar
sounding defines that actually didn't denote their actual usage at
compile time made it more difficult for a person to know what affect
changing the compile time defines would have on the resulting programs.

This patch renames the various defines to clearly identify which item
the define affects.  It also reduces the number of various directories
which will be searched for these files as this has lead to confusion
in mdadm and mdmon in terms of which files should take precedence when
files exist in multiple locations, etc.  It's best if the person
compiling the program intentionally and with planning selects the
right directories to be used for the various purposes.  Which directory
is right depends on which items you are talking about and what boot
loader your system uses and what initramfs generation program your
system uses.  Because of the inter-dependency of all these items it
would typically be up to the distribution that mdadm is being integrated
into to select the correct values for these defines.

Signed-off-by: Doug Ledford <dledford@redhat.com>
2010-07-22 10:16:30 -04:00
Dan Williams f4190c2f12 mdmon: satisfy glibc tls abi requirements with pthreads
Setting up a proper tls descriptor is required to conform to the abi
[1].  Until it can be implemented in mdmon use pthreads instead of
clone(2) to let glibc handle the details.  The old behaviour can be had
by un-defining USE_PTHREADS.

Note, the "O2" builds need LDFLAGS now to pick up the '-pthread' option.

[1]: http://people.redhat.com/drepper/tls.pdf

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2010-07-06 12:48:56 -07:00
Dan Williams d19e3cfb66 Merge branch 'fixes' into for-neil 2010-07-01 17:36:11 -07:00
Dan Williams b526e52dc7 Always assume SKIP_GONE_DEVS behaviour and kill the flag
...i.e. GET_DEVS == (GET_DEVS|SKIP_GONE_DEVS)

A null pointer dereference in Incremental.c can be triggered by
replugging a disk while the old name is in use.  When mdadm -I is called
on the new disk we fail the call to sysfs_read().  I audited all the
locations that use GET_DEVS and it appears they can tolerate missing a
drive.  So just make SKIP_GONE_DEVS the default behaviour.

Also fix up remaining unchecked usages of the sysfs_read() return value.

Reported-by: Dave Jiang <dave.jiang@intel.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2010-06-16 17:26:04 -07:00
Dan Williams 33414a0182 Kill subarray v2
Support for deleting a subarray out of a container.  When all subarrays
are deleted the component devices are converted back into spares, a
--zero-superblock is still needed to kill the remaining metadata at this
point.  This operation is blocked when the subarray is active and may
also be blocked by the metadata handler when deleting the subarray might
change the uuid of other active subarrays.  For example, with imsm,
deleting subarray 'n' may change the uuid of subarrays with indexes > n.

Deleting a subarray needs to be a container wide event to ensure
disks that record the modified subarray list perceive other disks that
did not receive this change as out of date.

Notes:
The st->subarray parsing in super-intel.c and super-ddf.c is updated to
be more strict now that we are reading user supplied subarray values.

Offline container modification shares actions that mdmon typically
handles so promote is_container_member() and version_to_superswitch()
(formerly find_metadata_methods()) to generic utility functions for the
cases where mdadm performs the operation.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2010-06-15 17:55:41 -07:00
Doug Ledford 435b90e7d4 Create directory to contain mapfile (Assuming parent exists and
filesystem is writable).
This particularly keeps udev happy if VAR_RUN is set to /dev/md.

Signed-off-by: Doug Ledford <dledford@redhat.com>
Signed-off-by: NeilBrown <neilb@suse.de>
2010-03-24 09:07:03 +11:00
NeilBrown 32f217017f mdmon: Check both RUN directories to find running mdmon
If mdmon is run without "--takeover", it should still
check both *_RUN directories for a valid 'pid' file
to guard against having two mdmons running at the same time.


Suggested-by: Luca Berra <bluca@comedia.it>
Signed-off-by: NeilBrown <neilb@suse.de>
2010-03-03 12:07:18 +11:00
Luca Berra ed8fa52f31 mdmon: check select a writable pid_dir
Check that either VAR_DIR or ALT_DIR is actually writable before
selecting it.

Signed-off-by: Luca Berra <bluca@comedia.it>
Signed-off-by: NeilBrown <neilb@suse.de>
2010-03-03 11:54:47 +11:00
Luca Berra eb49460b74 fix mdmon option parsing
running mdmon --takeover --all resulted in a segfault.

Also allow "--all" to be longer so that e.g. md_d127 can
successfully over-write it in the argument list visible
to 'ps'.

Signed-off-by: Luca Berra <bluca@comedia.it>
Signed-off-by: NeilBrown <neilb@suse.de>
2010-03-03 11:06:08 +11:00
NeilBrown fcf5762500 Add _FORTIFY_SOURCE to mdadm.O2 build.
When building mdadm.O2, set _FORTIFY_SOURCE to get more
warnings, and also build mdmon.O2 to find warnings in that
code too.
Then fix the warnings.

Suggested-by: Luca Berra <bluca@comedia.it>
Signed-off-by: NeilBrown <neilb@suse.de>
2010-03-03 10:54:17 +11:00
NeilBrown fa716c83c5 mdmon: insist on creating .pid file at startup.
Now that we don't "mdadm --takeover" until /var/run is writable
there is no need to continually try to create files in there.

So only create these files at startup and fail if they cannot be
made.  This means that to start an array with externally managed
metadata, either /var/run or ALT_RUN (e.g. /lib/init/rw) must be
writable.  To 'takeover' from a previous mdmon instance, /var/run
must be writable.

This means we don't need to worry about SIGHUP (which was once used to
tell us it was time to create .pid) and SIGALRM.

Signed-off-by: NeilBrown <neilb@suse.de>
2010-02-08 17:26:18 +11:00
NeilBrown b5c727dc1a mdmon: remove switch-root functionality.
Using switch-root and then creating files in /var/run once
that location is writable is racing as most distro clean out
/var/run shortly after it is mounted.
This can cause the .pid and .sock files to be deleted shortly
after they are created.

This option doesn't seem to be used at all any, and the alternative
of communicating the pid etc in some preserved directory and then
restarting mdmon once all is settled seems simpler.

So remove the code for supporting switchroot and update man page
accordingly.

Signed-off-by: NeilBrown <neilb@suse.de>
2010-02-08 14:08:13 +11:00
NeilBrown a9596b79a3 mdmon: recognise --all in place of /proc/mdstat
It seems more meaningful.
Keep the old option as well for back compatibility.

Signed-off-by: NeilBrown <neilb@suse.de>
2010-02-04 17:34:06 +11:00
NeilBrown 5d4d1b26d3 mdmon: allow pid to be stored in different directory.
/var/run probably doesn't persist from early boot.
So if necessary, store in in /lib/init/rw or somewhere else
that does persist.

Signed-off-by: NeilBrown <neilb@suse.de>
2010-02-04 16:47:28 +11:00
NeilBrown 24f6f99b36 Having single function to read mdmon pid file.
We don't need three.
One (signal_mdmon) wasn't even being used.

Signed-off-by: NeilBrown <neilb@suse.de>
2010-02-04 16:47:21 +11:00
NeilBrown 24cfdbc5c0 mdmon: discard test_pidfile()
devname2mdmon() can be used just as easily and doing so saves us from
some duplicate code.
Also tidy up some related logic.

Signed-off-by: NeilBrown <neilb@suse.de>
2010-02-04 16:37:21 +11:00
NeilBrown e98ef22509 mdmon: improve switchroot handling.
The change to get mdmon to re-exec itself from the switchroot
filesystem broken switchroot in various ways.  This fixes it.

If the switchroot path is not '/', mdmon will find the pid and
socket for the monitor, chroot to the new root, and exec mdmon
passing the pid in argv[2] and the socket in stdin.

If the switchroot path is actually a number, mdmon will not chroot,
but will kill that pid before taking over the array.

Signed-off-by: NeilBrown <neilb@suse.de>
2010-02-04 12:04:18 +11:00
NeilBrown af7ca33487 mdmon: simplify try_kill_monitor
After we SIGTERM the monitor we need to wait for it to finish up.
Rather than the complexity of waiting for every md array to be clean,
we can simply read from the sock connected to the monitor.
When the monitor dies, we will get EOF.  Before then we will block.

Signed-off-by: NeilBrown <neilb@suse.de>
2010-02-04 12:04:16 +11:00
NeilBrown 3e7312a96c mdmon: remove scan variable from mdmon()
It is redundant as each place that it is used, it can only
have one possible value.
Also change the related arg to mdmon() to have a more meaningful
name.
And make mdmon() static.

Signed-off-by: NeilBrown <neilb@suse.de>
2010-02-04 12:04:15 +11:00
NeilBrown 417a4b046d mdmon: fix fd leak and possible buffer overrun.
We normally wouldn't close 'fd', and as 'buf' might not have
had a nul, strstr could have overrun it.

Signed-off-by: NeilBrown <neilb@suse.de>
2010-01-29 10:15:15 +11:00
NeilBrown 1373b07d75 mdmon: lock current memory as well as future memory.
mlockall(MCL_FUTURE) only locks mappings that have not yet
been created.  To lock all memory used by the process, we need
 MCL_CURRENT | MCL_FUTURE

Signed-off-by: NeilBrown <neilb@suse.de>
2009-10-19 13:04:16 +11:00
Dan Williams 9f1da82421 mdmon: preserve socket over chroot
Connect to the monitor in the old namespace and use that connection for
WaitClean requests when stopping the victim mdmon instance.  This allows
ping_monitor() to work post chroot().

Cc: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2009-10-13 17:41:58 -07:00
Dan Williams b928b5a038 mdmon: exec(2) when the switchroot argument is not "/"
Try to execute mdmon from the target namespace.  When used for initramfs
handovers we need to drop all references to the initramfs filesystem for
that memory to be freed.

Cc: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2009-10-13 17:41:58 -07:00
Dan Williams 96a8270d46 mdmon: avoid writes in the startup path for mdmon on root arrays
When killing a previous monitor be careful not to cause writes to the
filesystem until the reads necessary to get the monitor operational have
completed.

The code is already prepared for errors creating the pid and socket
files, so simply defer creation of these files until after the first
call to manage().

Cc: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2009-10-13 17:41:57 -07:00
Hans de Goede f5df5d69a7 mdmon: fix freeing unallocated memory
mdmon was creating a supertype struct with malloc, and thus not
necessarily getting zero-d memory.

This was causing it to segfault when called like this from the initrd:
/sbin/mdmon /proc/mdstat /sysroot

The problem was that  load_super_imsm would get called on the non-zero'd
super struct, whcih in turn calls free_super_imsm, which checks st->sb,
which should be zero but isn't and then starts freeing bogus memory.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2009-09-24 06:52:06 -07: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
Dan Williams 1b34f51997 mdmon: update cmdline when scanning
Allows ps -ax | grep mdmon to show:
	mdmon md127
	mdmon md126
...rather than:
	mdmon /proc/mdstat
	mdmon /proc/mdstat

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2009-02-24 18:45:57 -07:00
Dan Williams 7da80e6faa mdmon: fix removed disk handling
Use SKIP_GONE_DEVS when reading the container, and correct some confused
logic in manage_new().

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2009-02-24 18:45:57 -07:00
Dan Williams 5746141e3f mdmon: make switchroot an undecorated option
Simplify the usage from:
	mdmon [--switch-root dir] /device/name/for/container
to...
	mdmon /device/name/for/container [target_dir]

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2009-01-20 01:36:50 -07:00
Dan Williams 1ffd2840df mdmon: support scanning for containers
When the given container is '/proc/mdstat' then launch an mdmon instance
per container found in /proc/mdstat.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2009-01-20 01:36:50 -07:00
Dan Williams 6f4098a6fd mdmon: expand permissible container device names
Allow any path that dereferences to an md device to be used in addition
to the current symbolic md device names.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2009-01-20 01:36:50 -07:00
Dan Williams c1363b408f mdmon: fix missing ->subarray initialization
This can cause mdmon to fail at startup.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2009-01-13 15:46:05 -07:00
NeilBrown e8a70c8958 mdmon: pass symbolic name to mdmon instead of device name.
Now that names in /dev are usually created (eventually) by udev,
it isn't really safe to rely in finding a name in /dev to pass to
mdmon to identify which array to monitor.
And it isn't really necessary to have a name in /dev.
So just pass the symbolic name, e.g. md127 or md123.

Change util.c to pass that name, and change mdmon to process the
name sensibly.

Signed-off-by: NeilBrown <neilb@suse.de>
2008-11-20 14:51:42 +11:00
NeilBrown 97f734fde2 A couple of bugfixes found by suse autobuilding:
1/ ia64 appear to have __clone2, not clone.
2/ Including "++" in the arg to a macro is a bad thing to do.

Signed-off-by: NeilBrown <neilb@suse.de>
2008-11-07 14:46:30 +11:00
Dan Williams ce744c97bc Assemble: revert preliminary -As support
I have seen the light.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2008-11-04 20:51:11 +11:00
NeilBrown 40ebbb9cfe util: make env checking more generic
Change the "env_check_mdmon" function to be more generic, accepting
and environment variable name, as soon we will have a new use for it.

Signed-off-by: NeilBrown <neilb@suse.de>
2008-11-04 10:35:43 +11:00
Dan Williams 71d60c480a Preliminary -As support for container member arrays
Given an mdadm.conf like the following allow /dev/imsm and /dev/md/r1 to be
created by "mdadm -As".

DEVICES partitions 
ARRAY /dev/imsm metadata=imsm auto=md UUID=b98f5dbe-aa859e7b-0e369b89-a80986d4 
ARRAY /dev/md/r1 container=/dev/imsm member=0 auto=mdp UUID=3538e39c-b397c2e9-1aa031f9-2bc0eca4 
   spares=1

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2008-10-28 10:55:31 -07:00
Dan Williams a54d52625a update copyright headers
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2008-10-28 10:55:29 -07:00
Dan Williams 8aae4219a2 mdmon: suicide prevention
mdmon cannot remove the pidfile at shutdown becuase it needs to stay
running across the "mount -o remount,ro /" event.  When it relaunches
after a reboot there is a good chance that the pid will match what was
there previously.  The result is that the "take over for unresponsive
mdmon" logic results in self termination.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2008-10-15 14:43:57 -07:00
Dan Williams 27dec8fae3 quiet WaitClean()
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2008-10-15 14:43:57 -07:00
Dan Williams 13047e4c07 mdmon: --switch-root
For raid rootfs we cannot run the array unmonitored for any length of
time.  At least XFS will not mount/replay the journal if the underlying
block device is readonly (FIXME it also seems that XFS does not always
honor the ro status of the backing device as I was able to hit the
BUG_ON(mddev->ro == 1) in md_write_start... but I digress).

So we need to start mdmon in the initramfs before '/' is mounted and
then restart it after the real rootfs is available.  Upon seeing the
--switch-root option, mdmon will kill any victims in the current
/var/run/mdadm directory and then chroot(2) before continuing.

The option is deliberately called 'switch-root' instead of 'chroot' to
hopefully indicate that this is different than doing "chroot mdmon
/dev/imsm".

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2008-10-15 14:43:57 -07:00