thirdparty/mdadm.git
11 days agoAssemble: add support for RAID0 layouts. master
NeilBrown [Mon, 4 Nov 2019 03:27:49 +0000 (14:27 +1100)] 
Assemble: add support for RAID0 layouts.

If you have a RAID0 array with varying sized devices
on a kernel before 5.4, you cannot assembling it on
5.4 or later without explicitly setting the layout.
This is now possible with
  --update=layout-original (For 3.13 and earlier kernels)
or
  --update=layout-alternate (for 3.14 and later kernels)

Signed-off-by: NeilBrown <neilb@suse.de>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
11 days agoCreate: add support for RAID0 layouts.
NeilBrown [Mon, 4 Nov 2019 03:27:49 +0000 (14:27 +1100)] 
Create: add support for RAID0 layouts.

Since Linux 5.4 a layout is needed for RAID0 arrays with
varying device sizes.
This patch makes the layout of an array visible (via --examine)
and sets the layout on newly created arrays.
--layout=dangerous
can be used to avoid setting a layout so that they array
can be used on older kernels.

Tested-by: dann frazier <dann.frazier@canonical.com>
Signed-off-by: NeilBrown <neilb@suse.de>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
11 days agoimsm: Change the way of printing nvme drives in detail-platform.
Blazej Kucman [Mon, 2 Dec 2019 09:52:05 +0000 (10:52 +0100)] 
imsm: Change the way of printing nvme drives in detail-platform.

Change NVMe controller path to device node path
in mdadm --detail-platform and print serial number.
The method imsm_read_serial always trimes serial to
MAX_RAID_SERIAL_LEN, added parameter 'serial_buf_len'
will be used to check the serial fit
to passed buffor, if not, will be trimed.

Signed-off-by: Blazej Kucman <blazej.kucman@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
11 days agoimsm: return correct uuid for volume in detail
Blazej Kucman [Fri, 29 Nov 2019 14:21:08 +0000 (15:21 +0100)] 
imsm: return correct uuid for volume in detail

Fixes the side effect of the patch b6180160f ("imsm: save current_vol number")
- wrong UUID is printed in detail for each volume.
New parameter "subarray" is added to determine what info should be extracted
from metadata (subarray or container).
The parameter affects only IMSM metadata.

Signed-off-by: Blazej Kucman <blazej.kucman@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
11 days agoRemove unused code
Xiao Ni [Fri, 29 Nov 2019 09:14:47 +0000 (17:14 +0800)] 
Remove unused code

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2 weeks agoFix up a few formatting issues
Jes Sorensen [Wed, 27 Nov 2019 16:33:15 +0000 (11:33 -0500)] 
Fix up a few formatting issues

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2 weeks agoRemove last traces of HOT_ADD_DISK
Jes Sorensen [Wed, 27 Nov 2019 15:19:54 +0000 (10:19 -0500)] 
Remove last traces of HOT_ADD_DISK

This ioctl is no longer used, so remove all references to it.

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2 weeks agoManage: Remove the legacy code for md driver prior to 0.90.03
Xiao Yang [Wed, 27 Nov 2019 03:59:24 +0000 (11:59 +0800)] 
Manage: Remove the legacy code for md driver prior to 0.90.03

Previous re-add operation only calls ioctl(HOT_ADD_DISK) for array without
metadata(e.g. mdadm -B/--build) when md driver is less than 0.90.02, but
commit 091e8e6 breaks the logic and current re-add operation can call
ioctl(HOT_ADD_DISK) even if md driver is 0.90.03.

This issue is reproduced by 05r1-re-add-nosuper:
------------------------------------------------
++ die 'resync or recovery is happening!'
++ echo -e '\n\tERROR: resync or recovery is happening! \n'
ERROR: resync or recovery is happening!
------------------------------------------------

Fixes: 091e8e6("Manage: Remove all references to md_get_version()")
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Xiao Yang <ice_yangxiao@163.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
4 weeks agosuper-intel: don't mark structs 'packed' unnecessarily
NeilBrown [Thu, 31 Oct 2019 04:15:38 +0000 (15:15 +1100)] 
super-intel: don't mark structs 'packed' unnecessarily

super-intel marks a number of structures 'packed', but this
doesn't change the layout - they are already well organized.

This is a problem a gcc warns when code takes the address
of a field in a packet struct - as super-intel sometimes does.

So remove the marking where isn't needed.
Do ensure this does introduce a regression, add a compile-time
assertion that the size of the structure is exactly the value
it had before the 'packed' notation was removed.

Note that a couple of structure do need to be packed.
As the address of fields is never taken, that is safe.

Signed-off-by: NeilBrown <neilb@suse.de>
Acked-by: Artur Paszkiewicz <artur.paszkiewicz@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
4 weeks agoSUSE-mdadm_env.sh: handle MDADM_CHECK_DURATION
NeilBrown [Tue, 29 Oct 2019 23:32:41 +0000 (10:32 +1100)] 
SUSE-mdadm_env.sh: handle MDADM_CHECK_DURATION

The suse sysconfig/mdadm allows MDADM_CHECK_DURATION
to be set, but it is currently ignored.

Signed-off-by: NeilBrown <neilb@suse.de>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
4 weeks agomdcheck: use ${} to pass variable to mdcheck
NeilBrown [Tue, 29 Oct 2019 23:32:41 +0000 (10:32 +1100)] 
mdcheck: use ${} to pass variable to mdcheck

$MDADM_CHECK_DURATION allows the value to be split on spaces.
${MDADM_CHECK_DURATION} avoids such splitting.

Making this change removes the need for double quoting when setting
the default Environment, and means that double quoting isn't needed
in the EnvironmentFile.

Signed-off-by: NeilBrown <neilb@suse.de>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
4 weeks agomdcheck: when mdcheck_start is enabled, enable mdcheck_continue too.
NeilBrown [Tue, 29 Oct 2019 23:32:41 +0000 (10:32 +1100)] 
mdcheck: when mdcheck_start is enabled, enable mdcheck_continue too.

mdcheck_continue continues a regular array scan that was started by
mdcheck_start.
mdcheck_start will ensure that mdcheck_continue is active.
Howver if you reboot after a check has started, but before it finishes,
then mdcheck_continue won't cause it to continue, because nothing
starts it on boot.

So add an install option for mdcheck_contine, and make sure it
gets enabled when mdcheck_start is enabled.

Signed-off-by: NeilBrown <neilb@suse.de>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
4 weeks agoimsm: allow to specify second volume size
Krzysztof Smolinski [Fri, 8 Nov 2019 10:59:11 +0000 (11:59 +0100)] 
imsm: allow to specify second volume size

Removed checks which limited second volume size only to max value (the
largest size that fits on all current drives). It is now permitted
to create second volume with size lower then maximum possible.

Signed-off-by: Krzysztof Smolinski <krzysztof.smolinski@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2 months agoimsm: save current_vol number
Mariusz Tkaczyk [Fri, 4 Oct 2019 10:07:28 +0000 (12:07 +0200)] 
imsm: save current_vol number

The imsm container_content routine will set curr_volume index in super
for getting volume information. This flag has never been restored to
original value, later other function may rely on it.

Restore this flag to original value.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2 months agoudev: allow for udev attribute reading bug.
NeilBrown [Wed, 18 Sep 2019 05:12:55 +0000 (15:12 +1000)] 
udev: allow for udev attribute reading bug.

There is a bug in udev (which will hopefully get fixed, but
we should allow for it anways).
When reading a sysfs attribute, it first reads the whole
value of the attribute, then reads again expecting to get
a read of 0 bytes, like you would with an ordinary file.
If the sysfs attribute changed between these two reads, it can
get a mixture of two values.

In particular, if it reads when 'array_state' is changing from
'clear' to 'inactive', it can find the value as "clear\nve".

This causes the test for "|clear|active" to fail, so systemd is allowed
to think that the array is ready - when it isn't.

So change the pattern to allow for this but adding a wildcard at
the end.
Also don't allow for an empty string - reading array_state will
never return an empty string - if it exists at all, it will be
non-empty.

Signed-off-by: NeilBrown <neilb@suse.de>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2 months agoDon't need to check recovery after re-add when no I/O writes to raid
Xiao Ni [Mon, 30 Sep 2019 11:48:00 +0000 (19:48 +0800)] 
Don't need to check recovery after re-add when no I/O writes to raid

If there is no write I/O between removing member disk and re-add it, there is no
recovery after re-adding member disk.

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2 months agoInit devlist as an array
Xiao Ni [Mon, 30 Sep 2019 11:47:59 +0000 (19:47 +0800)] 
Init devlist as an array

devlist is an string. It will change to an array if there is disk that
is sbd disk. If one device is sbd, it runs devlist=().
This line code changes devlist from a string to an array. If there is
no sbd device, it can't run this line code. So it will still be a string.
The later codes need an array, rather than an string. So init devlist
as an array to fix this problem.

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2 months agomdadm/md.4: add the descriptions for bitmap sysfs nodes
Guoqing Jiang [Fri, 31 May 2019 02:10:00 +0000 (10:10 +0800)] 
mdadm/md.4: add the descriptions for bitmap sysfs nodes

The sysfs nodes under bitmap are not recorded in md.4,
add them based on md.rst and kernel source code.

Cc: NeilBrown <neilb@suse.com>
Signed-off-by: Guoqing Jiang <gqjiang@suse.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2 months agomdadm: force a uuid swap on big endian
Nigel Croxon [Tue, 24 Sep 2019 15:39:24 +0000 (11:39 -0400)] 
mdadm: force a uuid swap on big endian

The code path for metadata 0.90 calls a common routine
fname_from_uuid that uses metadata 1.2. The code expects member
swapuuid to be setup and usable. But it is only setup when using
metadata 1.2. Since the metadata 0.90 did not create swapuuid
and set it. The test (st->ss == &super1) ? 1 : st->ss->swapuuid
fails. The swapuuid is set at compile time based on byte order.
Any call based on metadata 0.90 and on big endian processors,
the --export uuid will be incorrect.

Signed-Off-by: Nigel Croxon <ncroxon@redhat.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2 months agomdadm: Introduce new array state 'broken' for raid0/linear
Guilherme G. Piccoli [Tue, 3 Sep 2019 19:49:01 +0000 (16:49 -0300)] 
mdadm: Introduce new array state 'broken' for raid0/linear

Currently if a md raid0/linear array gets one or more members removed while
being mounted, kernel keeps showing state 'clean' in the 'array_state'
sysfs attribute. Despite udev signaling the member device is gone, 'mdadm'
cannot issue the STOP_ARRAY ioctl successfully, given the array is mounted.

Nothing else hints that something is wrong (except that the removed devices
don't show properly in the output of mdadm 'detail' command). There is no
other property to be checked, and if user is not performing reads/writes
to the array, even kernel log is quiet and doesn't give a clue about the
missing member.

This patch is the mdadm counterpart of kernel new array state 'broken'.
The 'broken' state mimics the state 'clean' in every aspect, being useful
only to distinguish if an array has some member missing. All necessary
paths in mdadm were changed to deal with 'broken' state, and in case the
tool runs in a kernel that is not updated, it'll work normally, i.e., it
doesn't require the 'broken' state in order to work.
Also, this patch changes the way the array state is showed in the 'detail'
command (for raid0/linear only) - now it takes the 'array_state' sysfs
attribute into account instead of only rely in the MD_SB_CLEAN flag.

Cc: Jes Sorensen <jes.sorensen@gmail.com>
Cc: NeilBrown <neilb@suse.de>
Cc: Song Liu <songliubraving@fb.com>
Signed-off-by: Guilherme G. Piccoli <gpiccoli@canonical.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 months agomdadm: check value returned by snprintf against errors
Krzysztof Smolinski [Fri, 16 Aug 2019 09:06:17 +0000 (11:06 +0200)] 
mdadm: check value returned by snprintf against errors

GCC 8 checks possible truncation during snprintf more strictly
than GCC 7 which result in compilation errors. To fix this
problem checking result of snprintf against errors has been added.

Signed-off-by: Krzysztof Smolinski <krzysztof.smolinski@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
4 months agoimsm: close removed drive fd.
Mariusz Tkaczyk [Mon, 15 Jul 2019 07:25:35 +0000 (09:25 +0200)] 
imsm: close removed drive fd.

When member drive fails, managemon prepares metadata update and adds
the drive to disk_mgmt_list with DISK_REMOVE flag. It fills only
minor and major. It is enough to recognize the device later.

Monitor thread while processing this update will remove the drive from
super only if it is a spare. It never removes failed member from
disks list. As a result, it still keeps opened descriptor to
non-existing device.

If removed drive is not a spare fill fd in disk_cfg structure
(prepared by managemon), monitor will close fd during freeing it.

Also set this drive fd to -1 in super to avoid double closing because
monitor will close the fd (if needed) while replacing removed drive
in array.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
4 months agoudev: add --no-devices option for calling 'mdadm --detail'
Coly Li [Wed, 31 Jul 2019 05:29:30 +0000 (13:29 +0800)] 
udev: add --no-devices option for calling 'mdadm --detail'

When creating symlink of a md raid device, the detailed information of
component disks are unnecessary for rule udev-md-raid-arrays.rules. For
md raid devices with huge number of component disks (e.g. 1500 DASD
disks), the detail information of component devices can be very large
and exceed udev monitor's on-stack message buffer.

This patch adds '--no-devices' option when calling mdadm by,
IMPORT{program}="BINDIR/mdadm --detail --no-devices --export $devnode"

Now the detailed output won't include component disks information,
and the error message "invalid message length" reported by systemd can
be removed.

Signed-off-by: Coly Li <colyli@suse.de>
Reviewed-by: NeilBrown <neilb@suse.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
4 months agomdadm: add --no-devices to avoid component devices detail information
Coly Li [Wed, 31 Jul 2019 05:29:29 +0000 (13:29 +0800)] 
mdadm: add --no-devices to avoid component devices detail information

When people assemble a md raid device with a large number of
component deivces (e.g. 1500 DASD disks), the raid device detail
information generated by 'mdadm --detail --export $devnode' is very
large. It is because the detail information contains information of
all the component disks (even the missing/failed ones).

In such condition, when udev-md-raid-arrays.rules is triggered and
internally calls "mdadm --detail --no-devices --export $devnode",
user may observe systemd error message ""invalid message length". It
is because the following on-stack raw message buffer in systemd code
is not big enough,
        systemd/src/libudev/libudev-monitor.c
        _public_ struct udev_device *udev_monito ...
                struct ucred *cred;
                union {
                        struct udev_monitor_netlink_header nlh;
                        char raw[8192];
                } buf;
Even change size of raw[] from 8KB to larger size, it may still be not
enough for detail message of a md raid device with much larger number of
component devices.

To fix this problem, an extra option '--no-devices' is added (the
original idea is proposed by Neil Brown). When printing detailed
information of a md raid device, if '--no-devices' is specified, then
all component devices information will not be printed, then the output
message size can be restricted to a small number, even with the systemd
only has 8KB on-disk raw buffer, the md raid array udev rules can work
correctly without failure message.

Signed-off-by: Coly Li <colyli@suse.de>
Reviewed-by: NeilBrown <neilb@suse.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
4 months agomdadm.h: include sysmacros.h unconditionally
Baruch Siach [Tue, 6 Aug 2019 13:05:23 +0000 (16:05 +0300)] 
mdadm.h: include sysmacros.h unconditionally

musl libc now also requires sys/sysmacros.h for the major/minor macros.
All supported libc implementations carry sys/sysmacros.h, including
diet-libc, klibc, and uclibc-ng.

Cc: Hauke Mehrtens <hauke@hauke-m.de>
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
5 months agomdadm: load default sysfs attributes after assemblation
Mariusz Dabrowski [Wed, 10 Jul 2019 11:38:53 +0000 (13:38 +0200)] 
mdadm: load default sysfs attributes after assemblation

Added new type of line to mdadm.conf which allows to specify values of
sysfs attributes for MD devices that should be loaded after the array is
assembled. Each line is interpreted as list of structures containing
sysname of MD device (md126 etc.) and list of sysfs attributes and their
values.

Signed-off-by: Mariusz Dabrowski <mariusz.dabrowski@intel.com>
Signed-off-by: Krzysztof Smolinski <krzysztof.smolinski@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
5 months agosuper-intel: Use put_unaligned in split_ull
Jes Sorensen [Tue, 9 Jul 2019 18:49:22 +0000 (14:49 -0400)] 
super-intel: Use put_unaligned in split_ull

Shut up some gcc9 errors by using put_unaligned() accessors. Not pretty,
but better than it was.

Also correct to the correct swap macros.

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
5 months agomdadm.h: Introduced unaligned {get,put}_unaligned{16,32}()
Jes Sorensen [Tue, 9 Jul 2019 18:15:38 +0000 (14:15 -0400)] 
mdadm.h: Introduced unaligned {get,put}_unaligned{16,32}()

We need these to avoid gcc9 going all crazy on us.

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
5 months agosuper-intel: Fix issue with abs() being irrelevant
Jes Sorensen [Tue, 9 Jul 2019 17:26:08 +0000 (13:26 -0400)] 
super-intel: Fix issue with abs() being irrelevant

gcc9 complains about subtracting unsigned from unsigned and code
assuming the result can be negative.

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
5 months agoEnable probe_roms to scan more than 6 roms.
Roman Sobanski [Tue, 2 Jul 2019 11:29:27 +0000 (13:29 +0200)] 
Enable probe_roms to scan more than 6 roms.

In some cases if more than 6 oroms exist, resource for particular
controller may not be found. Change method for storing
adapter_rom_resources from array to list.

Signed-off-by: Roman Sobanski <roman.sobanski@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
6 months agomdmon: fix wrong array state when disk fails during mdmon startup
Artur Paszkiewicz [Tue, 7 May 2019 14:08:47 +0000 (16:08 +0200)] 
mdmon: fix wrong array state when disk fails during mdmon startup

If a member drive disappears and is set faulty by the kernel during
mdmon startup, after ss->load_container() but before manage_new(), mdmon
will try to readd the faulty drive to the array and start rebuilding.
Metadata on the active drive is updated, but the faulty drive is not
removed from the array and is left in a "blocked" state and any write
request to the array will block. If the faulty drive reappears in the
system e.g. after a reboot, the array will not assemble because metadata
on the drives will be incompatible (at least on imsm).

Fix this by adding a new option for sysfs_read(): "GET_DEVS_ALL". This
is an extension for the "GET_DEVS" option and causes all member devices
to be returned, even if the associated block device has been removed.
Use this option in manage_new() to include the faulty device on the
active_array's devices list. Mdmon will then properly remove the faulty
device from the array and update the metadata to reflect the degraded
state.

Signed-off-by: Artur Paszkiewicz <artur.paszkiewicz@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
7 months agoudev: Add udev rules to create by-partuuid for md device
Liwei Song [Wed, 20 Mar 2019 03:51:05 +0000 (23:51 -0400)] 
udev: Add udev rules to create by-partuuid for md device

This rules will create link under /dev/disk/by-partuuid/ for
MD devices partition, with which will support specify
root=PARTUUID=XXX to boot rootfs.

Signed-off-by: Liwei Song <liwei.song@windriver.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
8 months agoCreate: Block rounding size to max
Mariusz Tkaczyk [Mon, 1 Apr 2019 14:53:41 +0000 (16:53 +0200)] 
Create: Block rounding size to max

When passed size is smaller than chunk, mdadm rounds it to 0 but 0 there
means max available space.
Block it for every metadata. Remove the same check from imsm routine.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
8 months agoimsm: fix spare activation for old matrix arrays
Pawel Baldysiak [Fri, 8 Mar 2019 11:19:11 +0000 (12:19 +0100)] 
imsm: fix spare activation for old matrix arrays

During spare activation get_extents() calculates metadata reserved space based
on smallest active RAID member or it will take the defaults. Since patch
611d9529("imsm: change reserved space to 4MB") default is extended.  If array
was created prior that patch, reserved space is smaller. In case of matrix
RAID - spare is activated in each array one-by-one, so it is spare for first
activation, but treated as "active" during second one.

In case of adding spare drive to old matrix RAID with the size the same as
already existing member drive the routine will take the defaults during second
run and mdmon will refuse to rebuild second volume, claiming that the drive
does not have enough free space.

Add parameter to get_extents(), so the during spare activation reserved space
is always based on smallest active drive - even if given drive is already
active in some other array of matrix RAID.

Signed-off-by: Pawel Baldysiak <pawel.baldysiak@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
9 months agoadd missing units to --examine
Corey Hickey [Tue, 12 Feb 2019 01:42:27 +0000 (17:42 -0800)] 
add missing units to --examine

Within the output of "mdadm --examine", there are three sizes reported
on adjacent lines. For example:

$ sudo mdadm --examine /dev/md3
[...]
 Avail Dev Size : 17580545024 (8383.06 GiB 9001.24 GB)
     Array Size : 17580417024 (16765.99 GiB 18002.35 GB)
  Used Dev Size : 11720278016 (5588.66 GiB 6000.78 GB)
[...]

This can be confusing, since the first and third line are in 512-byte
sectors, and the second is in KiB.

Add units to avoid ambiguity.

(I don't particularly like the "KiB" notation, but it is at least
unambiguous.)

Signed-off-by: Corey Hickey <bugfood-c@fatooh.org>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
9 months agoAssemble: Fix starting array with initial reshape checkpoint
Pawel Baldysiak [Fri, 22 Feb 2019 11:56:27 +0000 (12:56 +0100)] 
Assemble: Fix starting array with initial reshape checkpoint

If array was stopped during reshape initialization,
there might be a "0" checkpoint recorded in metadata.
If array with such condition (reshape with position 0)
is passed to kernel - it will refuse to start such array.

Treat such array as normal during assemble, Grow_continue() will
reinitialize and start the reshape.

Signed-off-by: Pawel Baldysiak <pawel.baldysiak@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
9 months agomdmon: wait for previous mdmon to exit during takeover
Pawel Baldysiak [Fri, 22 Feb 2019 12:30:27 +0000 (13:30 +0100)] 
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>
9 months agomdmon: don't attempt to manage new arrays when terminating
Artur Paszkiewicz [Fri, 22 Feb 2019 09:15:45 +0000 (10:15 +0100)] 
mdmon: don't attempt to manage new arrays when terminating

When mdmon gets a SIGTERM, it stops managing arrays that are clean. If
there is more that one array in the container and one of them is dirty
and the clean one is still present in mdstat, mdmon will treat it as a
new array and start managing it again. This leads to a cycle of
remove_old() / manage_new() calls for the clean array, until the other
one also becomes clean.

Prevent this by not calling manage_new() if sigterm is set. Also, remove
a check for sigterm in manage_new() because the condition will never be
true.

Signed-off-by: Artur Paszkiewicz <artur.paszkiewicz@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
9 months agomdadm/tests: add one test case for failfast of raid1
Gioh Kim [Fri, 7 Dec 2018 13:30:09 +0000 (14:30 +0100)] 
mdadm/tests: add one test case for failfast of raid1

This creates raid1 device with the failfast option and check all
slaves have the failfast flag. And it does assembling and growing
the raid1 device and check the failfast works fine.

Signed-off-by: Gioh Kim <gi-oh.kim@cloud.ionos.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
9 months agoFix reshape for decreasing data offset
Corey Hickey [Tue, 12 Feb 2019 01:18:38 +0000 (17:18 -0800)] 
Fix reshape for decreasing data offset

...when not changing the number of disks.

This patch needs context to explain. These are the relevant parts of
the original code (condensed and annotated):

if (dir > 0) {
    /* Increase data offset (reshape backwards) */
    if (data_offset < sd->data_offset + min) {
        pr_err("--data-offset too small on %s\n",
               dn);
        goto release;
    }
} else {
    /* Decrease data offset (reshape forwards) */
    if (data_offset < sd->data_offset - min) {
        pr_err("--data-offset too small on %s\n",
               dn);
        goto release;
    }
}

When this code is reached, mdadm has already decided on a reshape
direction. When increasing the data offset, the reshape runs backwards
(dir==1); when decreasing the data offset, the reshape runs forwards
(dir==-1).

The conditional within the backwards reshape is correct: the requested
offset must be larger than the old offset plus a minimum delta; thus the
reshape has room to work.

For the forwards reshape, the requested offset needs to be smaller than
the old offset minus a minimum delta; to do this correctly, the
comparison must be reversed.

Also update the error message.

Note: I have tested this change on a RAID 5 on Linux 4.18.0 and verified
that there were no errors from the kernel and that the device data
remained intact. I do not know if there are considerations for different
RAID levels.

Signed-off-by: Corey Hickey <bugfood-c@fatooh.org>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
9 months agoDetail.c: do not skip first character when calling xstrdup in Detail()
Coly Li [Tue, 12 Feb 2019 04:53:18 +0000 (12:53 +0800)] 
Detail.c: do not skip first character when calling xstrdup in Detail()

'Commit b9c9bd9bacaa ("Detail: ensure --export names are acceptable as
shell variables")' duplicates mdi->sys_name to sysdev string by,
char *sysdev = xstrdup(mdi->sys_name + 1);
which skips the first character of mdi->sys_name. Then when running
mdadm --detail <md device> --export, the output looks like,
MD_DEVICE_ev_sda2_ROLE=1
MD_DEVICE_ev_sda2_DEV=/dev/sda2
The first character of md device (between MD_DEVICE and _ROLE/_DEV)
is dropped. The expected output should be,
MD_DEVICE_dev_sda2_ROLE=1
MD_DEVICE_dev_sda2_DEV=/dev/sda2

This patch removes the '+ 1' from calling xstrdup() in Detail(), which
gets the dropped first character back.

Reported-by: Arvin Schnell <aschnell@suse.com>
Fixes: b9c9bd9bacaa ("Detail: ensure --export names are acceptable as 4 shell variables")
Signed-off-by: Coly Li <colyli@suse.de>
Cc: NeilBrown <neilb@suse.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
10 months agoFix spelling typos.
Dimitri John Ledkov [Tue, 15 Jan 2019 19:08:37 +0000 (19:08 +0000)] 
Fix spelling typos.

Signed-off-by: Dimitri John Ledkov <xnox@ubuntu.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
10 months agoimsm: fix reshape for >2TB drives
Pawel Baldysiak [Mon, 28 Jan 2019 16:10:41 +0000 (17:10 +0100)] 
imsm: fix reshape for >2TB drives

If reshape is performed on drives larger then 2 TB,
migration checkpoint area that is calculated exeeds 32-bit value.
This checkpoint area is a reserved space threated as backup
during reshape - at the end of the drive, right before metadata.
As a result - wrong space is used and the data that may exists there
is overwritten.

Adding additional field to migration record to track high order 32-bits
of pba of this area. Three other fields that may exceed 32-bit value
for large drives are added as well.

Signed-off-by: Pawel Baldysiak <pawel.baldysiak@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
10 months agoimsm: finish recovery when drive with rebuild fails
Mariusz Tkaczyk [Fri, 8 Feb 2019 10:07:10 +0000 (11:07 +0100)] 
imsm: finish recovery when drive with rebuild fails

Commit d7a1fda2769b ("imsm: update metadata correctly while raid10 double
degradation") resolves main Imsm double degradation problems but it
omits one case. Now metadata hangs in the rebuilding state if the drive
under rebuild is removed during recovery from double degradation.

The root cause of this problem is comparing new map_state with current
and if they both are degraded assuming that nothing new happens.

Don't rely on map states, just check if device is failed. If the drive
under rebuild fails then finish migration, in other cases update map
state only (second fail means that destination map state can't be normal).

To avoid problems with reassembling move end_migration (called after
double degradation successful recovery) after check if recovery really
finished, for details see (7ce057018 "imsm: fix: rebuild does not
continue after reboot").
Remove redundant code responsible for finishing rebuild process. Function
end_migration do exactly the same. Set last_checkpoint to 0, to prepare
it for the next rebuild.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
12 months agopolicy.c: Fix for compiler error
Mariusz Tkaczyk [Tue, 11 Dec 2018 14:04:07 +0000 (15:04 +0100)] 
policy.c: Fix for compiler error

After cd72f9d(policy: support devices with multiple paths.) compilation
on old compilers fails because "ā€˜pā€™ may be used uninitialized
in this function".

Initialize it with NULL to prevent this.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
12 months agopolicy.c: prevent NULL pointer referencing
Gioh Kim [Fri, 7 Dec 2018 11:04:44 +0000 (12:04 +0100)] 
policy.c: prevent NULL pointer referencing

paths could be NULL and paths[0] should be followed by NULL pointer
checking.

Reviewed-by: NeilBrown <neilb@suse.com>
Signed-off-by: Gioh Kim <gi-oh.kim@cloud.ionos.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
12 months agoGrow: report correct new chunk size.
NeilBrown [Wed, 5 Dec 2018 23:36:28 +0000 (10:36 +1100)] 
Grow: report correct new chunk size.

When using "--grow --chunk=" to change chunk
size, the old chunksize is reported instead of the new.

Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
12 months agoGrow: avoid overflow in compute_backup_blocks()
NeilBrown [Wed, 5 Dec 2018 23:35:41 +0000 (10:35 +1100)] 
Grow: avoid overflow in compute_backup_blocks()

With a chunk size of 16Meg and data drive count of 8,
this calculate can easily overflow the 'int' type that
is used for the multiplications.
So force it to use "long" instead.

Reported-and-tested-by: Ed Spiridonov <edo.rus@gmail.com>
Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
12 months agoAssemble: mask FAILFAST and WRITEMOSTLY flags when finding the most recent device
Gioh Kim [Tue, 6 Nov 2018 15:20:17 +0000 (16:20 +0100)] 
Assemble: mask FAILFAST and WRITEMOSTLY flags when finding the most recent device

If devices[].i.disk.state has MD_DISK_FAILFAST or MD_DISK_WRITEMOSTLY
flag, it cannot be the most recent device. Both flags should be masked
before checking the state.

Reviewed-by: NeilBrown <neilb@suse.com>
Signed-off-by: Gioh Kim <gi-oh.kim@cloud.ionos.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
12 months agoimsm: update metadata correctly while raid10 double degradation
Mariusz Tkaczyk [Wed, 17 Oct 2018 10:11:41 +0000 (12:11 +0200)] 
imsm: update metadata correctly while raid10 double degradation

Mdmon calls end_migration() when map state changes from normal to
degraded. It is not valid because in raid 10 double degradation case
mdmon breaks checkpointing but array is still rebuilding.
In this case mdmon has to mark map as degraded and continues marking
recovery checkpoint in metadata. Migration can be finished only if newly
failed device is a rebuilding device.

Add catching double degraded to degraded transition. Migration is
finished but map state doesn't change, array is still degraded.

Update failed_disk_num correctly. If double degradation
happens rebuild will start on the lowest slot, but this variable points
to the first failed slot. If second fail happens while rebuild this
variable shouldn't be updated until rebuild is not finished.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
12 months agoMonitor: add system timer to run --oneshot periodically
NeilBrown [Wed, 5 Dec 2018 05:35:00 +0000 (16:35 +1100)] 
Monitor: add system timer to run --oneshot periodically

"mdadm --monitor --oneshot" can be used to get a warning
if there are any degraded arrays.  It can be helpful to get
this warning periodically while the condition persists.

This patch add a systemd service and timer which can
be enabled with
   systemctl enable mdmonitor-oneshot.service

and will then provide daily warnings.

Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
12 months agomdcheck: add systemd unit files to run mdcheck.
NeilBrown [Wed, 5 Dec 2018 05:35:00 +0000 (16:35 +1100)] 
mdcheck: add systemd unit files to run mdcheck.

Having the mdcheck script is not use if is never run.
This patch adds systemd unit files so that it can easily
be run on the first Sunday of each month for 6 hours,
then on every subsequent morning until the check is
finished.

The units still need to be enabled with
  systemctl enable mdcheck_start.timer

The timer will only actually be started when an array
which might need it becomes active.

Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
12 months agopolicy: support devices with multiple paths.
NeilBrown [Fri, 9 Nov 2018 06:12:33 +0000 (17:12 +1100)] 
policy: support devices with multiple paths.

As new releases of Linux some time change the name of
a path, some distros keep "legacy" names as well.  This
is useful, but confuses mdadm which assumes each device has
precisely one path.

So change this assumption:  allow a disk to have several
paths, and allow any to match when looking for a policy
which matches a disk.

Reported-and-tested-by: Mariusz Tkaczyk <mariusz.tkaczyk@intel.com>
Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
12 months agoDocument PART-POLICY lines
NeilBrown [Fri, 9 Nov 2018 06:12:33 +0000 (17:12 +1100)] 
Document PART-POLICY lines

PART-POLICY has been accepted in mdadm.conf since the same
time that POLICY was accepted, but it was never documented.
So add the missing documentation.

Also fix a bug which would have stopped it from working if
anyone had ever tried to use it.

Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
12 months agoAssemble: keep MD_DISK_FAILFAST and MD_DISK_WRITEMOSTLY flag
Gioh Kim [Tue, 6 Nov 2018 14:27:42 +0000 (15:27 +0100)] 
Assemble: keep MD_DISK_FAILFAST and MD_DISK_WRITEMOSTLY flag

Before updating superblock of slave disks, desired_state value
is set for the target state of the slave disks. But it forgets
to check MD_DISK_FAILFAST and MD_DISK_WRITEMOSTLY flags. Then
start_arrays() calls ADD_NEW_DISK ioctl-call and pass the state
without MD_DISK_FAILFAST and MD_DISK_WRITEMOSTLY.

Currenlty it does not generate any problem because kernel does not
care MD_DISK_FAILFAST or MD_DISK_WRITEMOSTLY flags.

Reviewed-by: NeilBrown <neilb@suse.com>
Signed-off-by: Gioh Kim <gi-oh.kim@profitbricks.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
14 months agoRelease mdadm-4.1 mdadm-4.1
Jes Sorensen [Mon, 1 Oct 2018 18:26:06 +0000 (14:26 -0400)] 
Release mdadm-4.1

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
14 months agoimsm: block using partition
Mariusz Tkaczyk [Fri, 28 Sep 2018 07:48:53 +0000 (09:48 +0200)] 
imsm: block using partition

When IMSM_NO_PLATFORM is exported mdadm allows to create array with
partitions or add partition to existing array but there is no
possibilty to assemble it after stopping, see commit 691c6ee1b6bb
("IMSM/DDF: don't recognised these metadata on partitions.").

When searching for hba capabilities first test device and print
corresponding error if it is a partition.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
14 months agoAssemble: set devices to NULL when load_devices can't load device
Guoqing Jiang [Mon, 27 Aug 2018 03:10:52 +0000 (11:10 +0800)] 
Assemble: set devices to NULL when load_devices can't load device

Since load_devices frees "devices" when it can't find any
device, we should set it to NULL to avoid double free issue
which can be reproduced by below steps:

mdadm -CR /dev/md/vol -l0 -e 1.2 -n2 /dev/sd[b-c] --assume-clean
mdadm -Ss
mdadm -A /dev/md127 /dev/sd[b-c] --update metadata

Reported-by: Tkaczyk Mariusz <mariusz.tkaczyk@intel.com>
Tested-by: Tkaczyk Mariusz <mariusz.tkaczyk@intel.com>
Signed-off-by: Guoqing Jiang <gqjiang@suse.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
14 months agoAssemble: free resources in load_devices
Guoqing Jiang [Mon, 27 Aug 2018 03:10:51 +0000 (11:10 +0800)] 
Assemble: free resources in load_devices

Like other failure cases in load_devices, we need
to free those resources as well.

Signed-off-by: Guoqing Jiang <gqjiang@suse.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
14 months agoimsm: Avoid duplicate entries in --detail-platform
Roman Sobanski [Mon, 13 Aug 2018 05:52:53 +0000 (07:52 +0200)] 
imsm: Avoid duplicate entries in --detail-platform

In some scenarios mdadm --detail-platform shows duplicated info about one
of controllers. Block it.

Signed-off-by: Roman Sobanski <roman.sobanski@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
14 months agoimsm: Block volume creation with empty name
Roman Sobanski [Fri, 10 Aug 2018 12:20:35 +0000 (14:20 +0200)] 
imsm: Block volume creation with empty name

There is a possibility to create a RAID with empty name. Block it. Also
remove trailing and leading whitespaces from given name.

Signed-off-by: Roman Sobanski <roman.sobanski@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
14 months agomdadm.c: Fix error handling for --zero-superblock
Mariusz Tkaczyk [Mon, 3 Sep 2018 11:52:55 +0000 (13:52 +0200)] 
mdadm.c: Fix error handling for --zero-superblock

When Kill() cannot open device or find superblock it return the same
error and mdadm ignores it.
Change error handling in Kill() function. Return error if device is
busy, ignore it only when superblock doesn't exist- assume that metadata
is zeroed.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
16 months agoRelease mdadm-4.1-rc2
Jes Sorensen [Fri, 3 Aug 2018 15:30:31 +0000 (11:30 -0400)] 
Release mdadm-4.1-rc2

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
16 months agoIncremental: remove external arrays and devices correctly
Mariusz Tkaczyk [Fri, 3 Aug 2018 07:41:50 +0000 (09:41 +0200)] 
Incremental: remove external arrays and devices correctly

Kernel returns EBUSY when device fail invokes array fail.
In external metadata if kernel returns it, mdadm doesn't stop member
arrays but it will try to stop container directly. It fails because
container still has working arrays, so udev remove is triggered.

Try to set faulty state on device in member arrays first. If kernel
returns EBUSY, stop this array. After that remove the device from
container.

In external metadata mdmon has to remove faulty devices from degraded
arrays, just remove device from container.

Raid5 array doesn't return EBUSY, it allows to remove every device.
Mdadm shouldn't block it.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
16 months agoGrow: Frozen array can't be idle
Mariusz Tkaczyk [Wed, 1 Aug 2018 13:29:31 +0000 (15:29 +0200)] 
Grow: Frozen array can't be idle

When array is frozen but there is no recovery/reshape in mdstat,
check_idle() will not return error but grow countinue can still working.

Check is array frozen. Do not use sysfs sync_action parameter because it
doesn't exist for Raid0, simply check metadata_version in mdstat.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
16 months agoudev.rules: make safe timeouts compatible with split-usr systems.
Dimitri John Ledkov [Mon, 23 Jul 2018 10:46:03 +0000 (11:46 +0100)] 
udev.rules: make safe timeouts compatible with split-usr systems.

Instead of /usr/bin/sh, and /usr/bin/echo, use /bin/sh and shell
built-in echo respectively. This makes
udev-md-raid-safe-timeouts.rules to be compatible with both usr-merged
and split-usr systems alike.

Signed-off-by: Dimitri John Ledkov <xnox@ubuntu.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
16 months agoAssemble: remove the protection when clustered raid do assemble
Guoqing Jiang [Fri, 20 Jul 2018 08:05:14 +0000 (16:05 +0800)] 
Assemble: remove the protection when clustered raid do assemble

For HA product, RA (resource agent) assembles cluster raid
through call below cmd:

$MDADM --assemble $mddev --config=$RAIDCONF $MDADM_HOMEHOST

Sometimes node can't assemble array because all the nodes
need to contend dlm lock, which causes node fence in automatic
test.

And in fact, we don't need the protection since the assemble
cmd called by RA doesn't change superblock, so revert the
commit 76781701a487090172d32befae07671a10ea88ad ("Assemble:
provide protection when clustered raid do assemble") to remove
unneccessary protection.

Signed-off-by: Guoqing Jiang <gqjiang@suse.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
16 months agomapfile: set *mapp to NULL after map_free
Guoqing Jiang [Thu, 19 Jul 2018 01:40:42 +0000 (09:40 +0800)] 
mapfile: set *mapp to NULL after map_free

We can see "double free or corruption" with below steps
as reported by Mariusz:

export IMSM_NO_PLATFORM=1
export IMSM_DEVNAME_AS_SERIAL=1
mdadm --zero-super /dev/sd*
mdadm -C /dev/md/imsm -n2 -eimsm /dev/sdb /dev/sdc --run
mdadm -C /dev/md/r1 -n2 -z15G -eimsm /dev/sdb /dev/sdc -l1 --run --assume-clean
mdadm -f /dev/md126 /dev/sdb
mdadm -Ss

It is caused by Manage_stop calls map_remove and map_unlock,
but *mapp is not set to NULL after map_remove -> map_free,
so map_unlock will call map_free again.

Reported-by: Tkaczyk Mariusz <mariusz.tkaczyk@intel.com>
Tested-by: Tkaczyk Mariusz <mariusz.tkaczyk@intel.com>
Signed-off-by: Guoqing Jiang <gqjiang@suse.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
17 months agotests, imsm: Calculate expected array_size in proper way
Michal Zylowski [Fri, 22 Jun 2018 14:34:12 +0000 (16:34 +0200)] 
tests, imsm: Calculate expected array_size in proper way

Tests should calucalte expected array_size accordingly to raid level. Also
tests should take care about runding to neares MB introduced from b53bfba6
"imsm: use rounded size for metadata initialization".

Expect proper size in tests. Simplify 09imsm-overlap test by creating array
with size which has not been rounded. Main purpose of this test is checking
something else.

Signed-off-by: Michal Zylowski <michal.zylowski@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
17 months agotests, imsm: Migration from RAID5 to RAID0 is not supported for IMSM metadata
Michal Zylowski [Fri, 22 Jun 2018 14:34:11 +0000 (16:34 +0200)] 
tests, imsm: Migration from RAID5 to RAID0 is not supported for IMSM metadata

When test tries to change RAID level from RAID5 to RAID0 mdadm respond with
error about unsporrted operation.

Make 16imsm-r5_3d-migrate-r0_3d and 16imsm-r5_5d-migrate-r0_5d test
negative.

Signed-off-by: Michal Zylowski <michal.zylowski@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
17 months agotests, imsm: Test shouldn't call grow with chunk and level in one command
Michal Zylowski [Fri, 22 Jun 2018 14:34:10 +0000 (16:34 +0200)] 
tests, imsm: Test shouldn't call grow with chunk and level in one command

Since a3b831c9 "Grow.c: Block any level migration with chunk size change"
there is no possibility to perform migration between level and chunk in
one operation. When any test tries to do this error message is printed
and tests finishes with fail.

Signed-off-by: Michal Zylowski <michal.zylowski@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
17 months agotests, imsm: Set new_num_disks value corectly to perform expected size calculations
Michal Zylowski [Fri, 22 Jun 2018 14:34:09 +0000 (16:34 +0200)] 
tests, imsm: Set new_num_disks value corectly to perform expected size calculations

In some migration tests, variable new_num_disks should be set to expected
number of disks after migration. This is required for proper expected size
calculation.

Pass new_num_disks variable during test execution for:
- 16imsm-r0_3d-migrate-r5_4d
- 18imsm-r1_2d-takeover-r0_1d
- 16imsm-r0_5d-migrate-r5_6d

Signed-off-by: Michal Zylowski <michal.zylowski@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
17 months agotests, imsm: Fix unit inconsistency in tests error messages
Michal Zylowski [Fri, 22 Jun 2018 14:34:08 +0000 (16:34 +0200)] 
tests, imsm: Fix unit inconsistency in tests error messages

Chunk size copied from sysfs should be divied by 1024 to compare with
expected chunk size.

Signed-off-by: Michal Zylowski <michal.zylowski@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
17 months agotests, imsm: Set correct expected offset between volumes
Michal Zylowski [Fri, 22 Jun 2018 14:34:07 +0000 (16:34 +0200)] 
tests, imsm: Set correct expected offset between volumes

Since 611d9529 (imsm: change reserved space to 4MB) gap between RAID
volumes has changed. Tests should expect correct offset in size
calulations.

Fix expected offset for tests.

Signed-off-by: Michal Zylowski <michal.zylowski@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
17 months agoCoverity: Resource leak: close fd before return
Anthony Youngman [Fri, 15 Jun 2018 21:36:42 +0000 (22:36 +0100)] 
Coverity: Resource leak: close fd before return

Anthony Youngman <anthony@youngman.org.uk>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
17 months agoCoverity: Resource leak: close fds and free array before return
Anthony Youngman [Sat, 16 Jun 2018 19:48:46 +0000 (20:48 +0100)] 
Coverity: Resource leak: close fds and free array before return

Signed-off-by: Anthony Youngman <anthony@youngman.org.uk>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
17 months agoCoverity: Resource leak: fix return without free
Anthony Youngman [Fri, 15 Jun 2018 21:18:14 +0000 (22:18 +0100)] 
Coverity: Resource leak: fix return without free

Signed-off-by: Anthony Youngman <anthony@youngman.org.uk>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
18 months agoFree map to avoid resource leak issues
Guoqing Jiang [Mon, 11 Jun 2018 09:03:44 +0000 (17:03 +0800)] 
Free map to avoid resource leak issues

1. There are some places which didn't free map as
discovered by coverity.

CID 289661 (#1 of 1): Resource leak (RESOURCE_LEAK)12. leaked_storage: Variable mapl going out of scope leaks the storage it points to.
CID 289619 (#3 of 3): Resource leak (RESOURCE_LEAK)63. leaked_storage: Variable map going out of scope leaks the storage it points to.
CID 289618 (#1 of 1): Resource leak (RESOURCE_LEAK)26. leaked_storage: Variable map going out of scope leaks the storage it points to.
CID 289607 (#1 of 1): Resource leak (RESOURCE_LEAK)41. leaked_storage: Variable map going out of scope leaks the storage it points to.

2. If we call map_by_* inside a loop, then map_free
should be called in the same loop, and it is better
to set map to NULL after free.

3. And map_unlock is always called with map_lock,
if we don't call map_remove before map_unlock,
then the memory (allocated by  map_lock -> map_read
-> map_add -> xmalloc) could be leaked. So we
need to free it in map_unlock as well.

Signed-off-by: Guoqing Jiang <gqjiang@suse.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
18 months agoimsm: correct num_data_stripes in metadata map for migration
Roman Sobanski [Fri, 8 Jun 2018 10:34:18 +0000 (12:34 +0200)] 
imsm: correct num_data_stripes in metadata map for migration

When migrating an array from R0 to R10 num_data_stripes in metadata map
will not be updated. Update it to allow correct migration process.
Changes in R10 to R0 migration for clarity of code.

Signed-off-by: Roman Sobanski <roman.sobanski@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
18 months agoAssemble.c Don't ignore faulty disk when array is auto assembled.
Mariusz Tkaczyk [Thu, 7 Jun 2018 12:47:47 +0000 (14:47 +0200)] 
Assemble.c Don't ignore faulty disk when array is auto assembled.

Since commit 20dc76d15b40 ("imsm: Set disk slot number") mdadm
sets slot number for each disk in imsm array. Now auto-assemble determines
devices using slot number and ignores devices on the same slot that have
older generation number.
It causes infinit loop if failed device is still visible in system
(it has metadata, but it is not merged with exisiting array).

To avoid it, out-of-sync device should be added to the best[]. Later
mdadm adds it as spare to the container.

Imsm doesn't support disk replacement feature, so it can use rooms for
replacements.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
18 months agogcc-8 coverity hack
Jes Sorensen [Mon, 4 Jun 2018 18:49:59 +0000 (14:49 -0400)] 
gcc-8 coverity hack

Coverity still has issues with gcc-7, not to mention gcc-8. Hack around
it, until they fix it.

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
18 months agomdadm/test: correct tests/testdev as testdev in 02r5grow
Zhilong Liu [Wed, 30 May 2018 07:04:41 +0000 (15:04 +0800)] 
mdadm/test: correct tests/testdev as testdev in 02r5grow

Fixes: a6994ccc230b ("mdadm/test: get rid of the tests/testdev")

Signed-off-by: Zhilong Liu <zlliu@suse.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
18 months agomdadm/test: mdadm needn't make install on the system
Zhilong Liu [Wed, 30 May 2018 07:04:05 +0000 (15:04 +0800)] 
mdadm/test: mdadm needn't make install on the system

Fixes: beb71de04d31 ("mdadm/test: enable clustermd testing under clustermd_tests/")
clustermd_tests/func.sh:
remove unnecessary 'make install', just ensure 'make everything' has done.
the original idea is to make the /sbin/mdadm version same as ./mdadm, and
this breakage has pointed out by commit:
59416da78fc6 ("tests/func.sh: Fix some total breakage in the test scripts")

Signed-off-by: Zhilong Liu <zlliu@suse.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
18 months agoCheck major number of block device when querying md device
Xiao Ni [Wed, 30 May 2018 05:49:41 +0000 (13:49 +0800)] 
Check major number of block device when querying md device

It give error message when query a non md device.
mdadm /dev/null
/dev/null: is an md device, but gives "Inappropriate ioctl for device" when queried

It's introduced by commit 5cb8599 and 8d0cd09
At first it checks whether a block is md device by function md_get_version.
In this function it does mainly two jobs:
1. send request by ioctl. (now it can be replace by argument ioctlerr)
2. check the block device major number which we don't do this.

We add the second judgement in this patch.

Fixes: 5cb8599 and 8d0cd09
Reported-by: Karsten Weiss <karsten.weiss@atos.net>
Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
18 months agosuper-ddf: Fix gcc-8.1 overflow warnings
Jes Sorensen [Thu, 31 May 2018 20:07:33 +0000 (16:07 -0400)] 
super-ddf: Fix gcc-8.1 overflow warnings

Cast to types that are big enough to hold the values, but also guarantee
no overflow of the buffer keepts gcc happy.

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
18 months agosuper1: Fix cases triggering gcc-8.1 strncpy truncate warning
Jes Sorensen [Thu, 31 May 2018 17:38:08 +0000 (13:38 -0400)] 
super1: Fix cases triggering gcc-8.1 strncpy truncate warning

Find the string length, copy it, and zero out the rest, instead of
relying on strncpy cleaning up for us.

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
18 months agosuper0: Use memmove() when adjusting sparc2.2 superblock data
Jes Sorensen [Thu, 31 May 2018 17:17:46 +0000 (13:17 -0400)] 
super0: Use memmove() when adjusting sparc2.2 superblock data

memcpy() does not allow overlapping copies, switch to memmove()

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
18 months agomdopen: fix gcc 8.1 string overflow error
Jes Sorensen [Thu, 31 May 2018 17:11:21 +0000 (13:11 -0400)] 
mdopen: fix gcc 8.1 string overflow error

We already cut symlinks longer than 1000, so rely on this calling
readlink and error out if we are able to read more than 1000 bytes.

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
18 months agoMonitor: Increase size of percentalert to avoid gcc warning
Jes Sorensen [Thu, 31 May 2018 15:45:21 +0000 (11:45 -0400)] 
Monitor: Increase size of percentalert to avoid gcc warning

gcc-8.1 complains about truncated string operations. While we know
percent will never grow larger than 100, it doesn't cost us anything
to increase the size of 'percentalert' on the stack like this.

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
18 months agoimsm: Do not require MDADM_EXPERIMENTAL flag anymore
Michal Zylowski [Tue, 29 May 2018 13:47:25 +0000 (15:47 +0200)] 
imsm: Do not require MDADM_EXPERIMENTAL flag anymore

Grow feature for IMSM metadata is currently fully supported and tested.
Reshape operation is not in experimental state anymore, so usage of this
flag is unnecessary.

Do not require MDADM_EXPERIMENTAL flag and remove obsolete information
from manual.

Signed-off-by: Michal Zylowski <michal.zylowski@intel.com>
Acked-by: Mariusz Dabrowski <mariusz.dabrowski@intel.com>
Acked-by: Roman Sobanski <roman.sobanski@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
18 months agoimsm: Do not block volume creation when container has disks with mixed sector size
Michal Zylowski [Tue, 29 May 2018 13:47:09 +0000 (15:47 +0200)] 
imsm: Do not block volume creation when container has disks with mixed sector size

Currently when created container keeps disks with mixed sector size (few
4K disks and some 512 disks) there is no possibility to create volume from
disks with one sector size.
Allow volume creation when given disks are related with mixed container.

Signed-off-by: Michal Zylowski <michal.zylowski@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
18 months agosuper-intel: Do not truncate last character of volume name
Jes Sorensen [Wed, 30 May 2018 16:10:13 +0000 (12:10 -0400)] 
super-intel: Do not truncate last character of volume name

Clear up strncpy abuse to avoid gcc-8.1 complaining about truncating
the string.

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
18 months agosuper-intel: Avoid gcc-8.1 complaining about truncating snprintf()
Jes Sorensen [Wed, 30 May 2018 15:56:37 +0000 (11:56 -0400)] 
super-intel: Avoid gcc-8.1 complaining about truncating snprintf()

We know the max size of the volume name, so no need to play the
snprintf() game.

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
18 months agosuper-intel: Get rid of unnused string
Jes Sorensen [Tue, 29 May 2018 20:55:41 +0000 (16:55 -0400)] 
super-intel: Get rid of unnused string

No need to snprintf() into the string when we don't use it afterards

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
18 months agosuper-intel: Use memcpy() to avoid confusing gcc
Jes Sorensen [Tue, 29 May 2018 20:09:47 +0000 (16:09 -0400)] 
super-intel: Use memcpy() to avoid confusing gcc

When added :0 to serial number and copying it back, use memcpy()
instead of strncpy() as we know the actual length. This stops gcc
from complaining with -Werror=stringop-truncation enabled

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
18 months agoDo not confuse gcc
Jes Sorensen [Tue, 29 May 2018 19:52:48 +0000 (15:52 -0400)] 
Do not confuse gcc

gcc-8.1's -Werror=stringop-truncation is easily confused. Rather than
disabling the check, make it explicit we are OK truncating here.

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
18 months agoFix misspelling of 'alignment' and 'geometry'
Michal Zylowski [Tue, 29 May 2018 13:46:40 +0000 (15:46 +0200)] 
Fix misspelling of 'alignment' and 'geometry'

Set gemetry to geometry in error message about geometry validation failed.
Fix misspelled 'alignment' word in imsm_component_size_alignment_check
function.

Signed-off-by: Michal Zylowski <michal.zylowski@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
19 months agomdadm/grow: correct size and chunk_size casting
Roman Sobanski [Fri, 27 Apr 2018 10:12:21 +0000 (12:12 +0200)] 
mdadm/grow: correct size and chunk_size casting

With commit 4b74a905a67e
("mdadm/grow: Component size must be larger than chunk size") mdadm returns
incorrect message if size given to grow was greater than 2 147 483 647 K.
Cast chunk_size to "unsigned long long" instead of casting size to "int".

Signed-off-by: Roman Sobanski <roman.sobanski@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
19 months agoPrevent create IMSM volume with size smaller than 1M or chunk
Roman Sobanski [Wed, 25 Apr 2018 09:25:06 +0000 (11:25 +0200)] 
Prevent create IMSM volume with size smaller than 1M or chunk

Block creation of the imsm volume when given size is smaller than 1M and
print appropriate message.

Commit b53bfba6119d3f6f56eb9e10e5a59da6901af159
(imsm: use rounded size for metadata initialization) introduces issue with
rounding volume sizes smaller than 1M to 0. There is an inconsistency when
size smaller than 1M was given depends of what we give as target device:
1) When block devices was given created volume has maximum available size.
2) When container symlink was given created volume has size 0. Additionally
it causes below call trace:

[69587.891556] WARNING: CPU: 28 PID: 22485 at ../drivers/md/md.c:7582 md_seq_show+0x764/0x770 [md_mod]
[69588.066405] Call Trace:
[69588.066409]  seq_read+0x336/0x430
[69588.066411]  proc_reg_read+0x40/0x70
[69588.066412]  __vfs_read+0x26/0x140
[69588.066414]  vfs_read+0x89/0x130
[69588.066415]  SyS_read+0x42/0x90
[69588.066417]  do_syscall_64+0x74/0x140
[69588.066419]  entry_SYSCALL_64_after_hwframe+0x3d/0xa2

Signed-off-by: Roman Sobanski <roman.sobanski@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
20 months agoimsm: do not use blocks_per_member in array size calculations
Mariusz Dabrowski [Thu, 5 Apr 2018 11:38:38 +0000 (13:38 +0200)] 
imsm: do not use blocks_per_member in array size calculations

mdadm assumes that blocks_per_member value is equal to num_data_stripes *
blocks_per_stripe but it is not true. For IMSM arrays created in OROM
NUM_BLOCKS_DIRTY_STRIPE_REGION sectors are added up to this value. Because
of this mdadm shows invalid size of arrays created in OROM and to fix this
we need to use array size calculation based on num data stripes and blocks
per stripe.

Signed-off-by: Mariusz Dabrowski <mariusz.dabrowski@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>