Commit Graph

97 Commits

Author SHA1 Message Date
Lukasz Florczak 83a379cfbd Replace error prone signal() with sigaction()
Up to this date signal() was used which implementation could vary [1].
Sigaction() call is preferred. This commit introduces replacement
from signal() to sigaction() by the use of signal_s() wrapper.
Also remove redundant signal.h header includes.

[1] https://man7.org/linux/man-pages/man2/signal.2.html

Signed-off-by: Lukasz Florczak <lukasz.florczak@linux.intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2022-04-04 11:13:02 -04:00
Mariusz Tkaczyk ff6bb131a4 mdadm: Unify forks behaviour
If mdadm is run by udev or systemd, it gets a pipe as each stream.
Forks in the background may run after an event or service has been
processed when udev is detached from pipe. As a result process
fails quietly if any message is written.
To prevent from it, each fork has to close all parent streams. Leave
stderr and stdout opened only for debug purposes.
Unify it across all forks. Introduce other descriptors detection by
scanning /proc/self/fd directory. Add generic method for
managing systemd services.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@intel.com>
2020-11-25 18:15:55 -05:00
Pawel Baldysiak d2e11da4b7 mdmon: wait for previous mdmon to exit during takeover
Since the patch c76242c5("mdmon: get safe mode delay file descriptor
early"), safe_mode_dalay is set properly by initrd mdmon.  But in some
cases with filesystem traffic since the very start of the system, it
might take a while to transit to clean state.  Due to fact that new
mdmon does not wait for the old one to exit - it might happen that the
new one switches safe_mode_delay back to seconds, before old one exits.
As the result two mdmons are running concurrently on same array.

Wait for the old mdmon to exit by pinging it with SIGUSR1 signal, just
in case it is sleeping.

Signed-off-by: Pawel Baldysiak <pawel.baldysiak@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2019-02-28 15:47:01 -05:00
Jes Sorensen 15d924d363 mdmon: Stop bothering about md_get_version()
If anyone has a kernel with md driver older than 0.90.03 they will
also know where to find older versions of mdadm.

Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
2017-04-05 15:39:51 -04:00
Zhilong Liu e81070a69b mdadm/mdmon:deleted the abort_reshape never invoked
mdmon.c: abort_reshape() has implemented in Grow.c,
this function doesn't make a lot of sense here.

Signed-off-by: Zhilong Liu <zlliu@suse.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
2017-03-27 18:16:19 -04:00
Khem Raj 50d72ed429 Add casts for the addr arg of connect and bind
glibc allows the addr arg to connect and socket to be any of a number
of 'sockaddr_*' types, but musl requires 'const struct sockaddr *'
which is in line with open group specs.  So add casts to allow
compilation with musl.

Signed-off-by: Khem Raj <raj.khem@gmail.com>
Signed-off-by: NeilBrown <neilb@suse.com>
2016-01-15 08:36:45 +11:00
Pawel Baldysiak d56dd607ba Change way of printing name of a process
Sometimes mdadm prints messages with wrong name "mdmon",
and vice versa.
This patch solves this problem by changing method of determining
process name.
Now "Name" will be set in const at start of a program,
previously was hardcoded as #define.

Signed-off-by: Pawel Baldysiak <pawel.baldysiak@intel.com>
Signed-off-by: Artur Paszkiewicz <artur.paszkiewicz@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
2015-02-12 12:11:01 +11:00
NeilBrown 935a32543e mdmon: don't include super0 and super1 in mdmon
They are no needed, and future patch will add a dependency
yo super1 which mdmon doesn't have.

Signed-off-by: NeilBrown <neilb@suse.de>
2014-08-07 12:14:49 +10:00
NeilBrown 120ec6f7b9 mdmon: ensure Unix domain socket is created with safe permissions.
In the unlikely case that mdmon is started with an overly
permissive umask, we don't want to risk giving away world acccess.

All other "mkdir" and  "O_CREAT" calls in mdmon and mdadm set
a suitably restrictive permission mask.  'bind' don't take an
explicit mask so it needs an implicit one.

Reported-by: Vincent Berg <vberg@ioactive.com>
Signed-off-by: NeilBrown <neilb@suse.de>
2014-07-03 17:06:45 +10:00
NeilBrown 5e57245e3f mdmon: don't complain about notifying parent when there is no need
When run with --foreground mdmon has no need to notify any
parent, so it shouldn't even try, let alone complain when it fails.

Also close an end of a pipe which is no longer used.

Signed-off-by: NeilBrown <neilb@suse.de>
2014-01-21 09:43:31 +11:00
mwilck@arcor.de 5d79c72e16 mdmon: honour --offroot, again
commit 3e32ba9d removed support for --offroot, and a9c15847 made
mdmon use @ in argv[0] only when started from initrd.

This breaks mdadm in OpenSUSE 12.3, which starts mdmon from the
root file system and relies on --offroot to work as documented earlier.

Reintroducing --offroot as an undocumented option, as its use is going to
go away soon anyway.

If this can't be applied, it should probably be included as distro-specific
patch if mdadm 3.3 is built for OpenSUSE 12.3. I haven't checked if the
patch is necesary for OpenSUSE Factory, too.

Signed-off-by: Martin Wilck <mwilck@arcor.de>
Signed-off-by: NeilBrown <neilb@suse.de>
2013-09-12 15:41:45 +10:00
NeilBrown a9c1584757 mdmon: don't lie to systemd.
Now that mdmon responds fairly well to SIGTERM, stop lying to
systemd about being started on the initrd.

Note that if mdmon is rerun (--takeover) for some reason, and systemd
chooses to kill processes before remounting / readonly, then the
unmount will hang.

If systemd ever lets us tell it that we don't want to be killed until
root is readonly, then we should do that.

Signed-off-by: NeilBrown <neilb@suse.de>
2013-08-01 15:59:24 +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 a88e119f6f pr_err for mdmon.
Signed-off-by: NeilBrown <neilb@suse.de>
2013-05-21 12:58:02 +10:00
Jes Sorensen bf3a33b35c mdmon: Add missing option documentation to --help output
Document that -a is equivalent to --all, as well as --foreground / -F

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Signed-off-by: NeilBrown <neilb@suse.de>
2013-04-26 08:45:05 +10: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 030419821f mdmon: add --foreground option
While not strictly necessary for systemd, it is cleaner to avoid
forking when running from a management daemon.  So add a --foreground
option to mdmon.

Signed-off-by: NeilBrown <neilb@suse.de>
2013-02-05 15:57:09 +11:00
Jes Sorensen 3e23ba9d7b Remove --offroot argument and default to always setting argv[0] to @
We still allow --offroot to be given - for compatibility with scripts
- but ignore it.

The whole point of --offroot is to get systemd to not auto-kill mdmon,
and we always want that.

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Signed-off-by: NeilBrown <neilb@suse.de>
2013-02-05 15:06:47 +11:00
NeilBrown a99d346971 mdmon: allow --takeover when original was started with --offroot
As --offroot causes ARGV[0] to be changed, we need to be more
lenient when checking that the mdmon we are about to kill really
is mdmon.  i.e. allow name to be "@dmon" instead.

Signed-off-by: NeilBrown <neilb@suse.de>
2012-08-20 10:37:21 +10:00
NeilBrown bcd2b4485a mdmon: fix arg processing for -a
'-a' was not being recognised as an abbreviation for '--all'.

Signed-off-by: NeilBrown <neilb@suse.de>
2012-08-20 10:33:50 +10: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 7a0bfa2d55 mdmon: fix arg parsing.
-t aka --takeover should not be setting container_name.
It sets it to NULL which causes failure when you try
  mdmon --all --takeover

Signed-off-by: NeilBrown <neilb@suse.de>
2012-07-09 16:50:22 +10:00
Jes Sorensen da827518c1 Add --offroot argument to mdmon
Acked-by: Doug Ledford <dledford@redhat.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Signed-off-by: NeilBrown <neilb@suse.de>
2012-01-30 12:11:21 +11:00
Jes Sorensen eb155f6de0 mdmon: Use getopt_long() to parse command line options
This changes mdmon over to use getopt_long() for option parsing,
making it easier to add new options. In addition this patch introduces
a short version -t for --takeover and adds -h/--help.

Acked-by: Doug Ledford <dledford@redhat.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Signed-off-by: NeilBrown <neilb@suse.de>
2012-01-30 12:11:07 +11:00
NeilBrown 88e5516ea9 mdmon: avoid using victim_sock when it is -1.
It possible that we try to use victim_sock even when we couldn't open
it.  This is never actually harmful but it looks wrong and it is best
to fix it.

Signed-off-by: NeilBrown <neilb@suse.de>
2011-11-07 11:44:21 +11:00
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