Commit Graph

243 Commits

Author SHA1 Message Date
NeilBrown 6f02172d2e Release mdadm-3.3
(and  various cosmetic fixes)

Signed-off-by: NeilBrown <neilb@suse.de>
2013-09-03 14:47:47 +10:00
NeilBrown 2f1bcf43d9 Make sure "mdmon" doesn't get called "@dmon".
The Anaconda installer (via its "loader" program) will try to kill
many processes at shutdown, but not "mdmon".

However when mdadm runs mdmon in the Anaconda environment, mdmon
sets argv[0][0] to '@' resulting in "@dmon" which confuses
"loader".

So change mdadm to set argv[0] to a path so that mdmon becomes e.g.
  "@usr/sbin/mdmon"
which "loader" will recognise as being "mdmon".

Reported-by: Martin Wilck <mwilck@arcor.de>
Signed-off-by: NeilBrown <neilb@suse.de>
2013-09-02 11:02:09 +10:00
mwilck@arcor.de 7ac5d47e8a in_initrd: fix gcc compiler error
On some systems, this code caused a "comparison between signed
and unsigned" error.

Signed-off-by: Martin Wilck <mwilck@arcor.de>
Signed-off-by: NeilBrown <neilb@suse.de>
2013-08-28 14:58:56 +10:00
NeilBrown 2538ba2abf Create: fix warning about pre-existing filesystems.
An ext[234] filesystem larger than 2TB was beign reported with
a negative size - which looks odd.

So fix it to use suitably large and unsigned values.

Reported-by: Jan Engelhardt <jengelh@inai.de>
Signed-off-by: NeilBrown <neilb@suse.de>
2013-08-08 09:16:43 +10:00
NeilBrown 9540cc244d test: ensure testing uses correct mdmon
When testing we want to run mdmon directly, not use
systemctl to get systemd to run it.

So allow an environment variable to make that choice.

Signed-off-by: NeilBrown <neilb@suse.de>
2013-08-05 14:55:13 +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 23bf42cc79 super1: simplify setting of array size.
Currently the extra space to leave before the data in the array
is calculated in two separate places, and they can be inconsistent.

Instead, do it all in validate_geometry.  This records the
'data_offset' chosen which all other devices then use.

'write_init_super' now just uses the value rather than doing all the
calculations again.

This results in more consistent numbers.

Also, load_super sets st->data_offset so that it is used by "--add",
so the new device has a data offset matching a pre-existing device.

Signed-off-by: NeilBrown <neilb@suse.de>
2013-07-30 17:05:47 +10:00
NeilBrown 289c74f8d7 Move find_free_devnum to mdopen.c
There is only one called to find_free_devnum and it is in mdopen.c

The removes a dependency between util.c and config.c which allows
us to now drop config.o from mdmon.

Signed-off-by: NeilBrown <neilb@suse.de>
2013-07-02 10:24:50 +10:00
NeilBrown 399e0b9709 Subject: Make wait_for and open_dev_excl faster
When we crete or assemble an array, we wait for udev to create the
device file in /dev so that as soon as mdadm complete, the device can
be used.

This waiting is performed in multiples of 200ms, which can sometimes
be too long to wait.

So change to an exponential backoff.  Wait 1, then 2, then 4 msec etc.
Once we get to 256msec, stop backing off and continue waiting 256ms at
a time until we reach the limit which is now 4.608sec rather than 5sec
which it was before.

Ditto for open_dev_excl.

Signed-off-by: NeilBrown <neilb@suse.de>
2013-06-25 15:56:22 +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
Bernd Schubert f8fcf7a1c5 raid6check: Fix build of raid6check
After recent git pull 'make raid6check' did not work anymore, as
sysfs_read() was called with a wrong argument and as check_env()
was used by use_udev(), but not defined.

Replace sysfs_read(..., -1, ...) by sysfs_read(..., NULL, ...)

Move check_env() from util.c to lib.c

Signed-off-by: Bernd Schubert <bernd.schubert@itwm.fraunhofer.de>
Signed-off-by: NeilBrown <neilb@suse.de>
2013-06-19 10:03:12 +10:00
NeilBrown a7dec3fd92 Make sure NOFILE resource limit is big enough.
Some people want to create truely enormous arrays.
As we sometimes need to hold one file descriptor for each
device, this can hit  the NOFILE limit.

So raise the limit if it ever looks like it might be a problem.

Signed-off-by: NeilBrown <neilb@suse.de>
2013-05-30 14:31:09 +10:00
NeilBrown d33f151842 Change some fprintf(stderrs to cont_err()
Signed-off-by: NeilBrown <neilb@suse.de>
2013-05-21 12:51:33 +10:00
NeilBrown 701d5b4ab5 Suppress error messages from systemctl.
We call systemctl to see if systemd will run mdmon for us.
If it cannot, we run mdmon directly, so we aren't interested
in the error message.
So redirect stderr to /dev/null.

Signed-off-by: NeilBrown <neilb@suse.de>
2013-05-15 11:10:54 +10:00
NeilBrown 5a23a06ea4 mdassemble - fix new compile-time problems.
Signed-off-by: NeilBrown <neilb@suse.de>
2013-05-13 17:05:16 +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
Jes Sorensen 15c10423aa In case launching mdmon fails, print an error message before exiting
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Signed-off-by: NeilBrown <neilb@suse.de>
2013-02-05 15:51:48 +11:00
Jes Sorensen 0f7bdf8946 Add support for launching mdmon via systemctl instead of fork/exec
If launching mdmon via systemctl fails, we fall back to the old method
of fork/exec. This allows for having mdmon launched via systemctl
which avoids problems with it getting killed by systemd due to it
ending up in the parent's cgroup (udev).

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Signed-off-by: NeilBrown <neilb@suse.de>
2013-02-05 15:40:38 +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 9dc7d3576a dev_open - don't bother trying map_dev
map_dev can be slow, and doesn't really provide a better result
than just creating a temporary device.
So discard it and use mknod/open/unlink to open a major:minor device.

Signed-off-by: NeilBrown <neilb@suse.de>
2013-01-10 14:04:54 +11:00
NeilBrown 06d2ffc3e2 conditionally remove map_dev from find_free_devnum
map_dev can be slow so it is best to not call it when
not necessary.
The final test in "find_free_devnum" is not relevant when
udev is being used, so remove the test in that case.

Signed-off-by: NeilBrown <neilb@suse.de>
2013-01-07 10:17:04 +11:00
NeilBrown cb8f6859d1 IMSM - allow assembling any imsm array even without OROM.
It is important to check for compatibility with 'platform' or
Option ROM when creating or changing and array.  However there is no
real need when simply assembling the array.

On some systems there are situations where the platform information is
not available.  e.g. on some UEFI systems, UEFI is not available
during 'kdump' handling.  This makes it impossible to assemble
an IMSM array to receive the dump.

So remove the requirements that the platform be visible to assemble
an IMSM array.

Signed-off-by: NeilBrown <neilb@suse.de>
2012-11-20 12:07:30 +11:00
NeilBrown 4ec2cbe96d Remove get_one_disk
It has never been used, and there isn't really any place that
could usefully use it.

Signed-off-by: NeilBrown <neilb@suse.de>
2012-10-22 17:23:15 +11:00
NeilBrown a994592d75 Fix open_container
open_container should open a container which contains the device,
but sometimes it would open another volume which contains the
device.  Be more careful in 'holder' selection.

Signed-off-by: NeilBrown <neilb@suse.de>
2012-10-11 17:15:55 +11:00
NeilBrown 5d5002289c Replace a lot of leading spaces with tabs.
Signed-off-by: NeilBrown <neilb@suse.de>
2012-10-10 18:33:26 +11:00
NeilBrown 72ca9bcff3 Allow data-offset to be specified per-device for create
mdadm --create /dev/md0 .... /dev/sda1:1024 /dev/sdb1:2048 ...

The size is in K unless a suffix: K M G is given.
The suffix 's' means sectors.

Signed-off-by: NeilBrown <neilb@suse.de>
2012-10-04 16:34:21 +10:00
NeilBrown 822e393a05 Allow parse_size to return 0.
We will shortly introduce --data-offset= which is allowed to
be zero.  We will want to use parse_size() so it needs to be
able to return '0' without it being an error.

So define INVALID_SECTORS to be an impossible value (currently '1')
and return and test for it consistently.

Signed-off-by: NeilBrown <neilb@suse.de>
2012-10-04 16:34:20 +10:00
Maciej Naruszewicz 9eafa1de73 imsm: Allow to specify controller for --detail-platform.
Usually, 'mdadm --detail-platform -e imsm' scans all the controllers
looking for IMSM capabilities. This patch provides the possibility
to specify a controller to scan, enabling custom usage by other
processes - especially with the --export switch.

$ mdadm --detail-platform
       Platform : Intel(R) Matrix Storage Manager
        Version : 9.5.0.1037
    RAID Levels : raid0 raid1 raid10 raid5
    Chunk Sizes : 4k 8k 16k 32k 64k 128k
    2TB volumes : supported
      2TB disks : not supported
      Max Disks : 7
    Max Volumes : 2 per array, 4 per controller
 I/O Controller : /sys/devices/pci0000:00/0000:00:1f.2 (SATA)

$ mdadm --detail-platform /sys/devices/pci0000:00/0000:00:1f.2
       Platform : Intel(R) Matrix Storage Manager
        Version : 9.5.0.1037
    RAID Levels : raid0 raid1 raid10 raid5
    Chunk Sizes : 4k 8k 16k 32k 64k 128k
    2TB volumes : supported
      2TB disks : not supported
      Max Disks : 7
    Max Volumes : 2 per array, 4 per controller
 I/O Controller : /sys/devices/pci0000:00/0000:00:1f.2 (SATA)

$ mdadm --detail-platform /sys/devices/pci0000:00/0000:00:1f.2 --export
MD_FIRMWARE_TYPE=imsm
IMSM_VERSION=9.5.0.1037
IMSM_SUPPORTED_RAID_LEVELS=raid0 raid1 raid10 raid5
IMSM_SUPPORTED_CHUNK_SIZES=4k 8k 16k 32k 64k 128k
IMSM_2TB_VOLUMES=yes
IMSM_2TB_DISKS=no
IMSM_MAX_DISKS=7
IMSM_MAX_VOLUMES_PER_ARRAY=2
IMSM_MAX_VOLUMES_PER_CONTROLLER=4

$ mdadm --detail-platform /sys/devices/pci0000:00/0000:00:1f.0 # This isn't an IMSM-capable controller
mdadm: no active Intel(R) RAID controller found under /sys/devices/pci0000:00/0000:00:1f.0

Signed-off-by: Maciej Naruszewicz <maciej.naruszewicz@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
2012-10-04 16:34:11 +10:00
NeilBrown b3ec716d00 Fix 'enough' function for RAID10.
The 'enough' function is written to work with 'near' arrays only
in that is implicitly assumes that the offset from one 'group' of
devices to the next is the same as the number of copies.
In reality it is the number of 'near' copies.

So change it to make this number explicit.

Reported-by: Jakub Husák <jakub@gooseman.cz>
Signed-off-by: NeilBrown <neilb@suse.de>
2012-10-03 13:53:46 +10:00
Maciej Naruszewicz f0ec67106c Display size with human_size_brief with a chosen prefix
When using human_size_brief, only IEC prefixes were supported. Now
it's possible to specify which format we want to see - either IEC
(kibi, mibi, gibi) or JEDEC (kilo, mega, giga).

Signed-off-by: Maciej Naruszewicz <maciej.naruszewicz@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
2012-10-02 16:41:13 +10:00
Maciej Naruszewicz 570abc6f38 Synchronize size calculation in human_size and human_size_brief
It would be better if two size-calculating methods had the same
calculating algorithm. The human_size way of calculation seems
more readable, so let's use it for both methods.

Signed-off-by: Maciej Naruszewicz <maciej.naruszewicz@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
2012-10-02 16:40:11 +10:00
Lukasz Dorau 51d4261ca9 fix: adjust parse_size() to the unsigned size variable
An error in parse_size() should be reported by 0, not -1,
because -1 is changed to the max value of unsigned long long
during calculations of size (e.g. at mdadm.c:412).

A negative value of size should be reported as error
(e.g. size equal -1 has been changed to the max value of
unsigned long long so far).

Signed-off-by: Lukasz Dorau <lukasz.dorau@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
2012-09-20 12:27:17 +10:00
Robert Buchholz 1cc101f3f8 Move xmalloc et al into their own file
This avoid code duplication for utilities that do not link to
util.c and everything that comes with it, such as test_restripe and
raid6check

Signed-off-by: NeilBrown <neilb@suse.de>
2012-09-10 17:23:59 +10:00
NeilBrown fb52f2457a find_free_devnum: avoid auto-using names in /etc/mdadm.conf
high-number names like "/dev/md126" shouldn't be in /etc/mdadm.conf,
but if they are they should be ignored when choosing an
unused number.

Signed-off-by: NeilBrown <neilb@suse.de>
2012-08-20 10:50:42 +10:00
NeilBrown ca3b669603 Minor cosmetic fixes in various files.
Signed-off-by: NeilBrown <neilb@suse.de>
2012-08-13 08:00:21 +10:00
NeilBrown 7986889004 Create parse_num() function.
Instead of open-coding this several times, just do it once.

The frees up the name 'c' which I'm about to use.

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

Signed-off-by: NeilBrown <neilb@suse.de>
2012-07-09 17:14:16 +10:00
NeilBrown 480f356641 Raid limit of 1024 when scanning for devices.
When we can for devices using GET_DISK_INFO we currently
limit to 1024.  But some arrays can have more than this.
So raise it to 4096 and make the constant a #define.

Signed-off-by: NeilBrown <neilb@suse.de>
2012-04-18 09:06:02 +10:00
NeilBrown 15632a96f4 parse_size: distinguish between 0 and error.
It isn't sufficient to use '0' for 'error' as well will
later have fields that can validly be '0'.

So return "-1" on error.

Also fix parsing of --bitmap_check so that '0' is treated
as an error: we don't support 512B anyway.

Signed-off-by: NeilBrown <neilb@suse.de>
2012-04-04 14:03:13 +10:00
Czarnowska, Anna e03640bda5 simplify calculating array_blocks
no point calling info_to_blocks_per_member when it just returns size*2 for level==1
calc_array_size can be used for all levels

Signed-off-by: Anna Czarnowska <anna.czarnowska@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
2012-04-02 10:16:04 +10:00
Adam Kwolek 92d49ecfaa FIX: NULL pointer to strdup() can be passed
When result from strchr() is NULL and it is assigned to subarray,
NULL pointer can be passed to strdup() function and coredump file
is generated.

Subarray is checked for NULL pointer, so it is assumed that it can
be NULL at this moment.

Signed-off-by: Adam Kwolek <adam.kwolek@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
2012-02-09 12:20:51 +11:00
NeilBrown de5a472ea3 Remove avail_disks arg from 'enough'.
It can easily be calculated from 'avail' and  'raid_disks', and we
will soon have a case where we don't have it easily available to pass
in.

Signed-off-by: NeilBrown <neilb@suse.de>
2012-02-07 14:04:47 +11:00
Jes Sorensen a0963a86e1 Spawn mdmon with --offroot if mdadm was launched with --offroot
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:29 +11:00
Jes Sorensen aabe020dd2 enough_fd(): remember to free buffer for avail array
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Signed-off-by: NeilBrown <neilb@suse.de>
2011-11-02 10:48:53 +11:00
Jes Sorensen db7fdfe422 Avoid stack overflow if GPT partition entries on disk are > 128 bytes
Per [1] GPT partition table entries are not guaranteed to be 128
bytes, in which case read() straight into a struct GPT_part_entry
would result in a buffer overflow corrupting the stack.

[1] http://en.wikipedia.org/wiki/GUID_Partition_Table

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Signed-off-by: NeilBrown <neilb@suse.de>
2011-10-31 10:24:55 +11:00
Lukasz Dorau 65c83a8023 util.c: two typos fixed
Two typos fixed.

Signed-off-by: Lukasz Dorau <lukasz.dorau@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
2011-10-26 08:48:31 +11:00
Thomas Jarosch 9cf014ec40 Fix off-by-one in readlink() buffer size handling
readlink() returns the number of bytes in the buffer.

If we do something like

len = readlink(path, buf, sizeof(buf));
buf[len] = '\0';

we might write one byte past the end of the buffer.

Signed-off-by: Thomas Jarosch <thomas.jarosch@intra2net.com>
Signed-off-by: NeilBrown <neilb@suse.de>
2011-10-17 11:15:04 +11:00
Adam Kwolek 577e8448e9 Move code to get_data_disks() function
Move code to function for code reuse.

Signed-off-by: Adam Kwolek <adam.kwolek@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
2011-10-03 09:57:12 +11:00
NeilBrown 01619b4818 Fix component size checks in validate_super0.
A 0.90 array can use at most 4TB of each device - 2TB between
2.6.39 and 3.1 due to a kernel bug.

The test for this in validate_super0 is very wrong.  'size' is sectors
and the number it is compared against is just confusing.

So fix it all up and correct the spelling of terabytes and remove
a second redundant test on 'size'.

Signed-off-by: NeilBrown <neilb@suse.de>
2011-09-08 12:20:36 +10:00