]> git.ipfire.org Git - thirdparty/mdadm.git/log
thirdparty/mdadm.git
3 years agoMake target to install binaries only
Kinga Tanska [Thu, 22 Oct 2020 12:22:29 +0000 (14:22 +0200)] 
Make target to install binaries only

Make install causes installation of binaries, udev and man.
This commit contains new target make install-bin, which
results in installation of binaries only.

Signed-off-by: Kinga Tanska <kinga.tanska@intel.com>
3 years agomdadm/Detail: show correct state for clustered array
Zhao Heming [Sat, 24 Oct 2020 09:43:12 +0000 (17:43 +0800)] 
mdadm/Detail: show correct state for clustered array

After kernel md module commit 480523feae581, in clustered env,
mddev->in_sync always zero, it will make array.state never set
up MD_SB_CLEAN. it causes "mdadm -D /dev/mdX" show state 'active'
all the time.

bitmap.c: add a new API IsBitmapDirty() to support inquiry bitmap
dirty or clean.

Signed-off-by: Zhao Heming <heming.zhao@suse.com>
3 years agomdadm: Unify forks behaviour
Mariusz Tkaczyk [Wed, 4 Nov 2020 09:02:36 +0000 (10:02 +0100)] 
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>
3 years agoimsm: limit support to first NVMe namespace
Mariusz Tkaczyk [Wed, 4 Nov 2020 09:01:28 +0000 (10:01 +0100)] 
imsm: limit support to first NVMe namespace

Due to metadata limitations NVMe multinamespace support has to be removed.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@intel.com>
3 years agoMonitor: don't use default modes when creating a file
Mariusz Tkaczyk [Tue, 24 Nov 2020 15:41:01 +0000 (16:41 +0100)] 
Monitor: don't use default modes when creating a file

Replace fopen() calls by open() with creation mode directly specified.
This fixes the potential security issue. Use octal values instead masks.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
3 years agoimsm: remove redundant calls to imsm_get_map
Mariusz Tkaczyk [Tue, 24 Nov 2020 14:58:53 +0000 (15:58 +0100)] 
imsm: remove redundant calls to imsm_get_map

MAP_0 is gotten and the beginning, there is no need to get it again.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
3 years agoimsm: update num_data_stripes according to dev_size
Mariusz Tkaczyk [Tue, 24 Nov 2020 13:15:15 +0000 (14:15 +0100)] 
imsm: update num_data_stripes according to dev_size

If array was created in UEFI there is possibility that
member size is not rounded to 1MB. After any size reconfiguration
it will be rounded down to 1MB per each member but the old
component size will remain in metadata.
During reshape old array size is calculated from component size because
dev_size is not a part of map and is bumped to new value quickly.
It may result in size mismatch if array is assembled during reshape.

If difference in calculated size and dev_size is observed try to fix it.
num_data_stripes value can be safety updated to smaller value if array
doesn't occuppy whole reserved component space.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
3 years agoCreate.c: close mdfd and generate uevent
Mariusz Tkaczyk [Tue, 24 Nov 2020 12:39:49 +0000 (13:39 +0100)] 
Create.c: close mdfd and generate uevent

During mdfd closing change event is not generated because open() is
called before start watching mddevice by udev.
Device is ready at this stage. Unblock device, close fd and
generate event to give a chance next layers to work.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
3 years agoDetail: fix segfault during IMSM raid creation
Lidong Zhong [Sun, 22 Nov 2020 15:12:29 +0000 (23:12 +0800)] 
Detail: fix segfault during IMSM raid creation

It can be reproduced with non IMSM hardware and IMSM_NO_PLATFORM
environmental variable set. The array state is inactive when creating
an IMSM container. And the structure info is NULL because load_super()
always fails since no intel HBA information could be obtained.

Signed-off-by: Lidong Zhong <lidong.zhong@suse.com>
Reported-by: Tkaczyk Mariusz <mariusz.tkaczyk@intel.com>
Fixes: 64bf4dff3430 (Detail: show correct raid level when the array is inactive)
3 years agoSuper1: allow RAID0 layout setting to be removed.
NeilBrown [Wed, 14 Oct 2020 02:12:48 +0000 (13:12 +1100)] 
Super1: allow RAID0 layout setting to be removed.

Once the RAID0 layout has been set, the RAID0 array cannot be assembled
on an older kernel which doesn't understand layouts.
This is an intentional safety feature, but sometimes people need the
ability to roll-back to a previously working configuration.

So add "--update=layout-unspecified" to remove RAID0 layout information
from the superblock.
Running "--assemble --update=layout-unspecified" will cause the assembly
the fail when run on a newer kernel, but will allow it to work on
an older kernel.

Signed-off-by: NeilBrown <neilb@suse.de>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agoCheck if other Monitor instance running before fork.
Blazej Kucman [Wed, 9 Sep 2020 08:31:20 +0000 (10:31 +0200)] 
Check if other Monitor instance running before fork.

Make error message visible to the user.

Signed-off-by: Blazej Kucman <blazej.kucman@intel.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agomdmonitor: set small delay once
Blazej Kucman [Wed, 9 Sep 2020 08:31:19 +0000 (10:31 +0200)] 
mdmonitor: set small delay once

If mdmonitor is awakened by event, set small delay once
to deal with udev and mdadm.

Signed-off-by: Blazej Kucman <blazej.kucman@intel.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agoMonitor: stop notifing about containers.
Mariusz Tkaczyk [Wed, 9 Sep 2020 08:31:18 +0000 (10:31 +0200)] 
Monitor: stop notifing about containers.

Stop reporting any events from container but still track them,
it is important for spare migration.
Stop mdmonitor if no redundant array is presented in mdstat.
There is nothing to follow.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agoMonitor: refresh mdstat fd after select
Mariusz Tkaczyk [Wed, 9 Sep 2020 08:31:17 +0000 (10:31 +0200)] 
Monitor: refresh mdstat fd after select

After 52209d6ee118 ("Monitor: release /proc/mdstat fd when no arrays
present") mdstat fd is closed if mdstat is empty or cannot be opened.
It causes that monitor is not able to select on mdstat. Select
doesn't fail because it gets valid descriptor to a different resource.
As a result any new event will be unnoticed until timeout (delay).

Refresh mdstat after wake up, don't poll on wrong resource.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agoDon't create bitmap for raid5 with journal disk
Xiao Ni [Tue, 15 Sep 2020 07:44:42 +0000 (15:44 +0800)] 
Don't create bitmap for raid5 with journal disk

Journal disk and bitmap can't exist at the same time. It needs to check if the raid
has a journal disk when creating bitmap.

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agoDetail: show correct raid level when the array is inactive
Lidong Zhong [Mon, 14 Sep 2020 02:52:18 +0000 (10:52 +0800)] 
Detail: show correct raid level when the array is inactive

Sometimes the raid level in the output of `mdadm -D /dev/mdX` is
misleading when the array is in inactive state. Here is a testcase for
introduction.
1\ creating a raid1 device with two disks. Specify a different hostname
rather than the real one for later verfication.

node1:~ # mdadm --create /dev/md0 --homehost TESTARRAY -o -l 1 -n 2 /dev/sdb
/dev/sdc
2\ remove one of the devices and reboot
3\ show the detail of raid1 device

node1:~ # mdadm -D /dev/md127
/dev/md127:
        Version : 1.2
     Raid Level : raid0
  Total Devices : 1
    Persistence : Superblock is persistent
          State : inactive
Working Devices : 1

You can see that the "Raid Level" in /dev/md127 is raid0 now.
After step 2\ is done, the degraded raid1 device is recognized
as a "foreign" array in 64-md-raid-assembly.rules. And thus the
timer to activate the raid1 device is not triggered. The array
level returned from GET_ARRAY_INFO ioctl is 0. And the string
shown for "Raid Level" is
str = map_num(pers, array.level);
And the definition of pers is
mapping_t pers[] = {
{ "linear", LEVEL_LINEAR},
{ "raid0", 0},
{ "0", 0}
...
So the misleading "raid0" is shown in this testcase.

Changelog:
v1: don't show "Raid Level" when array is inactive
Signed-off-by: Lidong Zhong <lidong.zhong@suse.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agomanual: update --examine-badblocks
Mariusz Tkaczyk [Thu, 6 Aug 2020 11:57:50 +0000 (13:57 +0200)] 
manual: update --examine-badblocks

IMSM also supports it.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agomdadm/md.4: update path to in-kernel-tree documentation
Winston Weinert [Wed, 22 Jul 2020 13:33:22 +0000 (08:33 -0500)] 
mdadm/md.4: update path to in-kernel-tree documentation

Documentation/md.txt was renamed to Documentation/admin-guide/md.rst
in linux commit 9d85025b0418163fae079c9ba8f8445212de8568 (Oct 26,
2016).

Signed-off-by: Winston Weinert <winston@ml1.net>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agoSpecify nodes number when updating cluster nodes
Xiao Ni [Mon, 27 Jul 2020 01:14:20 +0000 (09:14 +0800)] 
Specify nodes number when updating cluster nodes

Now it allows updating cluster nodes without specify --nodes. It can write superblock
with zero nodes. It can break the current cluster. Add this check to avoid this problem.

v2: It needs check c.update first to avoid NULL pointer reference
v3: Wol points the typo error

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agomdadm/Grow: prevent md's fd from being occupied during delayed time
allenpeng [Fri, 12 Jun 2020 09:00:39 +0000 (17:00 +0800)] 
mdadm/Grow: prevent md's fd from being occupied during delayed time

If we start reshaping on md which shares sub-devices with another
resyncing md, it may be forced to wait for others to complete. mdadm
occupies the md's fd during this time, which causes the md can not be
stopped and the filesystem can not be mounted on the md. We can close
md's fd earlier to solve this problem.

Reproducible Steps:

1. create two partitions on sda, sdb, sdc, sdd
2. create raid1 with sda1, sdb1
mdadm -C /dev/md1 --assume-clean -l1 -n2 /dev/sda1 /dev/sdb1
3. create raid5 with sda2, sdb2, sdc2
mdadm -C /dev/md2 --assume-clean -l5 -n3 /dev/sda2 /dev/sdb2 /dev/sdc2
4. start resync at md1
echo repair > /sys/block/md1/md/sync_action
5. reshape raid5 to raid6
mdadm -a /dev/md2 /dev/sdd2
mdadm --grow /dev/md2 -n4 -l6 --backup-file=/root/md2-backup

Now mdadm is occupying the fd of md2, causing md2 unable to be stopped

6.Try to stop md2, an error message shows
mdadm -S /dev/md2
mdadm: Cannot get exclusive access to /dev/md3:Perhaps a running process,
mounted filesystem or active volume group?

Reviewed-by: Alex Wu <alexwu@synology.com>
Reviewed-by: BingJing Chang <bingjingc@synology.com>
Reviewed-by: Danny Shih <dannyshih@synology.com>
Signed-off-by: ChangSyun Peng <allenpeng@synology.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agoUpdate link to Intel page for IMSM
Jes Sorensen [Fri, 12 Jun 2020 14:49:11 +0000 (10:49 -0400)] 
Update link to Intel page for IMSM

The old design page is gone, so update to the current overview page.

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agoUse more secure HTTPS URLs
Paul Menzel [Thu, 28 May 2020 14:52:24 +0000 (16:52 +0200)] 
Use more secure HTTPS URLs

All URLs in the source are available over HTTPS, so convert all URLs to
HTTPS with the command below.

    git grep -l 'http://' | xargs sed -i 's,http://,https://,g'

Revert the changes to announcement files `ANNOUNCE-*` as requested by
the maintainer.

Cc: linux-raid@vger.kernel.org
Signed-off-by: Paul Menzel <pmenzel@molgen.mpg.de>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agoDetect too-small device: error rather than underflow/crash
David Favro [Sat, 23 May 2020 12:24:59 +0000 (08:24 -0400)] 
Detect too-small device: error rather than underflow/crash

For 1.x metadata, when the user requested creation of an array on
component devices that were too small even to hold the superblock,
an undetected integer wraparound (underflow) resulted in an enormous
computed size which resulted in various follow-on errors such as
floating-point exception.

This patch detects this condition, prints a reasonable diagnostic
message, and refuses to continue.

Signed-off-by: David Favro <dfavro@meta-dynamic.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agoBlock overwriting existing links while manual assembly
Kinga Tanska [Fri, 29 May 2020 06:31:36 +0000 (08:31 +0200)] 
Block overwriting existing links while manual assembly

Manual assembly with existing link caused overwriting
this link. Add checking link and block this situation.

Signed-off-by: Kinga Tanska <kinga.tanska@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agorestripe: fix ignoring return value of ‘read’ and lseek
Guoqing Jiang [Mon, 18 May 2020 21:53:36 +0000 (23:53 +0200)] 
restripe: fix ignoring return value of ‘read’ and lseek

Got below error when run "make everything".

restripe.c: In function ‘test_stripes’:
restripe.c:870:4: error: ignoring return value of ‘read’, declared with attribute warn_unused_result [-Werror=unused-result]
    read(source[i], stripes[i], chunk_size);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Fix it by check the return value of ‘read’, and free memory
in the failure case.

And check the return value of lseek as well per Jes's comment.

Signed-off-by: Guoqing Jiang <guoqing.jiang@cloud.ionos.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agoInclude count for \0 character when using strncpy to implement strdup.
Jes Sorensen [Tue, 19 May 2020 00:19:53 +0000 (20:19 -0400)] 
Include count for \0 character when using strncpy to implement strdup.

We have to include the \0 character in the length when copying a
string with strncpy() for which length was found with strlen().
Otherwise the destination will not get null terminated - except that
we explicitly zeroed it out earlier.

This quiets down the compiler's warnings.

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agouuid.c: split uuid stuffs from util.c
Guoqing Jiang [Mon, 18 May 2020 21:53:35 +0000 (23:53 +0200)] 
uuid.c: split uuid stuffs from util.c

Currently, 'make raid6check' is build broken since commit b06815989
("mdadm: load default sysfs attributes after assemblation").

/usr/bin/ld: sysfs.o: in function `sysfsline':
sysfs.c:(.text+0x2707): undefined reference to `parse_uuid'
/usr/bin/ld: sysfs.c:(.text+0x271a): undefined reference to `uuid_zero'
/usr/bin/ld: sysfs.c:(.text+0x2721): undefined reference to `uuid_zero'

Apparently, the compile of mdadm or raid6check are coupled with uuid
functions inside util.c. However, we can't just add util.o to CHECK_OBJS
which raid6check is needed, because it caused other worse problems.

So, let's introduce a uuid.c file which is indenpended file to fix the
problem, all the contents are splitted from util.c.

Signed-off-by: Guoqing Jiang <guoqing.jiang@cloud.ionos.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agoMakefile: add EXTRAVERSION support
Tkaczyk Mariusz [Fri, 15 May 2020 09:23:14 +0000 (11:23 +0200)] 
Makefile: add EXTRAVERSION support

Add optional EXTRAVERSION parameter to Makefile and allow to mark version
by user friendly label. It might be useful when creating custom
spins of mdadm, or labeling some instance in between major releases.

Signed-off-by: Tkaczyk Mariusz <mariusz.tkaczyk@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agomdcheck: Log when done
Donald Buczek [Wed, 13 May 2020 13:16:46 +0000 (15:16 +0200)] 
mdcheck: Log when done

Currently mdcheck (when called with `--duration`) logs only the
beginning of the check, the pausing and the continuation but not the
completion.

So, log the completion, too, so that it can be determined how long the
raid check took.

    2020-05-08T18:00:02+02:00 deadpool root: mdcheck start checking /dev/md0
    2020-05-08T18:00:02+02:00 deadpool root: mdcheck start checking /dev/md1
    2020-05-09T15:32:04+02:00 deadpool root: mdcheck finished checking /dev/md1
    2020-05-09T17:38:04+02:00 deadpool root: mdcheck finished checking /dev/md0

Cc: linux-raid@vger.kernel.org
Signed-off-by: Paul Menzel <pmenzel@molgen.mpg.de>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agoAssemble.c: respect force flag.
Mariusz Tkaczyk [Tue, 5 May 2020 10:17:17 +0000 (12:17 +0200)] 
Assemble.c: respect force flag.

If the array is dirty handler will set resync_start to 0 to inform kernel
that resync is needed. RWH affects only raid456 module, for other
levels array will be started even array is degraded and resync cannot be
performed.

Force is really meaningful for raid456. If array is degraded and resync
is requested, kernel will reject an attempt to start the array. To
respect force, it has to be marked as clean (this will be done for each
array without PPL) and remove the resync request (only for raid 456).
Data corruption may occur so proper warning is added.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agoclean up meaning of small typo
Nigel Croxon [Mon, 4 May 2020 16:27:45 +0000 (12:27 -0400)] 
clean up meaning of small typo

Clean up the typo which leads to wrong understanding.

Signed-off-by: Nigel Croxon <ncroxon@redhat.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
4 years agoAssemble: print error message if mdadm fails assembling with --uuid option
Gioh Kim [Tue, 16 Apr 2019 16:08:17 +0000 (18:08 +0200)] 
Assemble: print error message if mdadm fails assembling with --uuid option

When mdadm tries to assemble one working device and one zeroed-out device,
it failed but print successful message because there is --uuid option.

Following script always reproduce it.

dd if=/dev/zero of=/dev/ram0 oflag=direct
dd if=/dev/zero of=/dev/ram1 oflag=direct
./mdadm -C /dev/md111 -e 1.2 --uuid="12345678:12345678:12345678:12345678" \
    -l1 -n2 /dev/ram0 /dev/ram1
./mdadm -S /dev/md111
dd if=/dev/zero of=/dev/ram1 oflag=direct
./mdadm -A /dev/md111 --uuid="12345678:12345678:12345678:12345678" \
    /dev/ram0 /dev/ram1

Following is message from mdadm.

mdadm: No super block found on /dev/ram1 (Expected magic a92b4efc, got 00000000)
mdadm: no RAID superblock on /dev/ram1
mdadm: /dev/md111 assembled from 1 drive - need all 2 to start it (use --run to insist).

The mdadm say that it assembled but mdadm does not create /dev/md111.
The message is wrong.

After applying this patch, mdadm reports error correctly as following.

mdadm: No super block found on /dev/ram1 (Expected magic a92b4efc, got 00000000)
mdadm: no RAID superblock on /dev/ram1
mdadm: /dev/ram1 has no superblock - assembly aborted

Signed-off-by: Gioh Kim <gi-oh.kim@cloud.ionos.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
4 years agoManage, imsm: Write metadata before add
Tkaczyk Mariusz [Fri, 17 Apr 2020 11:55:55 +0000 (13:55 +0200)] 
Manage, imsm: Write metadata before add

New drive in container always appears as spare. Manager is able to
handle that, and queues appropriative update to monitor.
No update from mdadm side has to be processed, just insert the drive and
ping the mdmon. Metadata has to be written if no mdmon is running (case
for Raid0 or container without arrays).

If bare drive is added very early on startup (by custom bare rule),
there is possiblity that mdmon was not restarted after switch root. Old
one is not able to handle new drive. New one fails because there is
drive without metadata in container and metadata cannot be loaded.

To prevent this, write spare metadata before adding device
to container. Mdmon will overwrite it (same case as spare migration,
if drive appears it writes the most recent metadata).
Metadata has to be written only on new drive before sysfs_add_disk(),
don't race with mdmon if running.

Signed-off-by: Tkaczyk Mariusz <mariusz.tkaczyk@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
4 years agoDetail: adding sync status for cluster device
Lidong Zhong [Tue, 14 Apr 2020 08:19:41 +0000 (16:19 +0800)] 
Detail: adding sync status for cluster device

On the node with /proc/mdstat is

Personalities : [raid1]
md0 : active raid1 sdb[4] sdc[3] sdd[2]
      1046528 blocks super 1.2 [3/2] [UU_]
        recover=REMOTE
      bitmap: 1/1 pages [4KB], 65536KB chunk

Let's change the 'State' of 'mdadm -Q -D' accordingly
State : clean, degraded
With this patch, it will be
State : clean, degraded, recovering (REMOTE)

Signed-off-by: Lidong Zhong <lidong.zhong@suse.com>
Acked-by: Guoqing Jiang <guoqing.jiang@cloud.ionos.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
4 years agoMonitor: improve check_one_sharer() for checking duplicated process
Coly Li [Fri, 10 Apr 2020 16:24:46 +0000 (00:24 +0800)] 
Monitor: improve check_one_sharer() for checking duplicated process

When running mdadm monitor with scan mode, only one autorebuild process
is allowed. check_one_sharer() checks duplicated process by following
steps,
1) Read autorebuild.pid file,
   - if file does not exist, no duplicated process, go to 3).
   - if file exists, continue to next step.
2) Read pid number from autorebuild.pid file, then check procfs pid
   directory /proc/<PID>,
   - if the directory does not exist, no duplicated process, go to 3)
   - if the directory exists, print error message for duplicated process
     and exit this mdadm.
3) Write current pid into autorebuild.pid file, continue to monitor in
   scan mode.

The problem for the above step 2) is, if after system reboots and
another different process happens to have exact same pid number which
autorebuild.pid file records, check_one_sharer() will treat it as a
duplicated mdadm process and returns error with message "Only one
autorebuild process allowed in scan mode, aborting".

This patch tries to fix the above same-pid-but-different-process issue
by one more step to check the process command name,
1) Read autorebuild.pid file
   - if file does not exist, no duplicated process, go to 4).
   - if file exists, continue to next step.
2) Read pid number from autorebuild.pid file, then check procfs file
   comm with the specific pid directory /proc/<PID>/comm
   - if the file does not exit, it means the directory /proc/<PID> does
     not exist, go to 4)
   - if the file exits, continue next step
3) Read process command name from /proc/<PIC>/comm, compare the command
   name with "mdadm" process name,
   - if not equal, no duplicated process, goto 4)
   - if strings are equal, print error message for duplicated process
     and exit this mdadm.
4) Write current pid into autorebuild.pid file, continue to monitor in
   scan mode.

Now check_one_sharer() returns error for duplicated process only when
the recorded pid from autorebuild.pid exists, and the process has exact
same command name as "mdadm".

Reported-by: Shinkichi Yamazaki <shinkichi.yamazaki@suse.com>
Signed-off-by: Coly Li <colyli@suse.de>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
4 years agoudev: Ignore change event for imsm
Mariusz Tkaczyk [Wed, 8 Apr 2020 14:44:52 +0000 (16:44 +0200)] 
udev: Ignore change event for imsm

When adding a device to a container mdadm has to close its file
descriptor before sysfs_add_disk(). This generates change event.
There is race possibility because metadata is already written and other
-I process can place drive differently. As a result device can be added
to two containers simultaneously.
From IMSM perspective there is no need to react for change event. IMSM
doesn't support stacked devices.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
4 years agoimsm: show Subarray and Volume ID in --examine output
Artur Paszkiewicz [Tue, 17 Mar 2020 09:21:03 +0000 (10:21 +0100)] 
imsm: show Subarray and Volume ID in --examine output

Show the index of the subarray as 'Subarray' and the value of the
my_vol_raid_dev_num field as 'Volume ID'.

Signed-off-by: Artur Paszkiewicz <artur.paszkiewicz@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
4 years agoimsm: support the Array Creation Time field in metadata
Artur Paszkiewicz [Tue, 17 Mar 2020 09:20:12 +0000 (10:20 +0100)] 
imsm: support the Array Creation Time field in metadata

Also present its value in --examine and --examine --export.

Signed-off-by: Artur Paszkiewicz <artur.paszkiewicz@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
4 years agoDetail: show correct bitmap info for cluster raid device
Lidong Zhong [Mon, 16 Mar 2020 02:16:49 +0000 (10:16 +0800)] 
Detail: show correct bitmap info for cluster raid device

Signed-off-by: Lidong Zhong <lidong.zhong@suse.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
4 years agoimsm: Correct minimal device size.
Blazej Kucman [Wed, 11 Mar 2020 14:40:13 +0000 (15:40 +0100)] 
imsm: Correct minimal device size.

Check if given size of member drive is not less than 1 MibiByte.

Signed-off-by: Blazej Kucman <blazej.kucman@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
4 years agoimsm: Remove --dump/--restore implementation
Blazej Kucman [Wed, 19 Feb 2020 10:13:17 +0000 (11:13 +0100)] 
imsm: Remove --dump/--restore implementation

Functionalities --dump and --restore are not supported.
Remove dead code from imsm.

Signed-off-by: Blazej Kucman <blazej.kucman@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
4 years agoimsm: pass subarray id to kill_subarray function
Blazej Kucman [Wed, 19 Feb 2020 09:54:49 +0000 (10:54 +0100)] 
imsm: pass subarray id to kill_subarray function

After patch b6180160f ("imsm: save current_vol number")
current_vol for imsm is not set and kill_subarray()
cannot determine which volume has to be deleted.
Volume has to be passed as "subarray_id".
The parameter affects only IMSM metadata.

Signed-off-by: Blazej Kucman <blazej.kucman@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
4 years agoRemove the legacy whitespace
Xiao Ni [Tue, 11 Feb 2020 13:44:15 +0000 (21:44 +0800)] 
Remove the legacy whitespace

The whitespace between Environment= and the true value causes confusion.
To avoid confusing other people in future, remove the whitespace to keep
it a simple, unambiguous syntax

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
4 years agomdadm.8: add note information for raid0 growing operation
Coly Li [Mon, 24 Feb 2020 11:34:09 +0000 (12:34 +0100)] 
mdadm.8: add note information for raid0 growing operation

When growing a raid0 device, if the new component disk size is not
big enough, the grow operation may fail due to lack of backup space.

The minimum backup space should be larger than:
 LCM(old, new) * chunk-size * 2

where LCM() is the least common multiple of the old and new count of
component disks, and "* 2" comes from the fact that mdadm refuses to
use more than half of a spare device for backup space.

There are users reporting such failure when they grew a raid0 array
with small component disk. Neil Brown points out this is not a bug
and how the failure comes. This patch adds note information into
mdadm(8) man page in the Notes part of GROW MODE section to explain
the minimum size requirement of new component disk size or external
backup size.

Reviewed-by: Petr Vorel <pvorel@suse.cz>
Cc: NeilBrown <neilb@suse.de>
Cc: Jes Sorensen <jsorensen@fb.com>
Cc: Paul Menzel <pmenzel@molgen.mpg.de>
Cc: Wols Lists <antlists@youngman.org.uk>
Cc: Nix <nix@esperi.org.uk>
Signed-off-by: Coly Li <colyli@suse.de>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
4 years agoimsm: fill working_disks according to metadata.
Blazej Kucman [Fri, 17 Jan 2020 14:24:04 +0000 (15:24 +0100)] 
imsm: fill working_disks according to metadata.

Imsm tracks as "working_disk" each visible drive.
Assemble routine expects that the value will return count
of active member drives recorded in metadata.
As a side effect "--no-degraded" doesn't work correctly for imsm.
Align this field to others.
Added check, if the option --no-degraded is called with --scan.

Signed-off-by: Blazej Kucman <blazej.kucman@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
4 years agoAdd support for Tebibytes
Kinga Tanska [Tue, 21 Jan 2020 09:38:52 +0000 (10:38 +0100)] 
Add support for Tebibytes

Adding support for Tebibytes enables display size of
volumes in Tebibytes and Terabytes when they are
bigger than 2048 GiB (or GB).

Signed-off-by: Kinga Tanska <kinga.tanska@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
4 years agoimsm: Update grow manual.
Blazej Kucman [Thu, 16 Jan 2020 08:34:44 +0000 (09:34 +0100)] 
imsm: Update grow manual.

Update --grow option description in manual, according to
the supported grow operations by IMSM.

Signed-off-by: Blazej Kucman <blazej.kucman@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
4 years agomdcheck service can't start succesfully because of syntax error
Xiao Ni [Wed, 18 Dec 2019 06:46:21 +0000 (14:46 +0800)] 
mdcheck service can't start succesfully because of syntax error

It reports error when starting mdcheck_start and mdcheck_continue service.
Invalid environment assignment, ignoring: MDADM_CHECK_DURATION="6 hours"

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
4 years agoChange warning message
Kinga Tanska [Tue, 10 Dec 2019 11:21:21 +0000 (12:21 +0100)] 
Change warning message

In commit 039b7225e6 ("md: allow creation of mdNNN arrays via
md_mod/parameters/new_array") support for name like mdNNN
was added. Special warning, when kernel is unable to handle
request, was added in commit 7105228e19
("mdadm/mdopen: create new function create_named_array for
writing to new_array"), but it was not adequate enough,
because in this situation mdadm tries to do it in old way.
This commit changes warning to be more relevant when
creating RAID container with "/dev/mdNNN" name and mdadm
back to old approach.

Signed-off-by: Kinga Tanska <kinga.tanska@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
4 years agoRespect $(CROSS_COMPILE) when $(CC) is the default
dann frazier [Mon, 9 Dec 2019 20:54:13 +0000 (13:54 -0700)] 
Respect $(CROSS_COMPILE) when $(CC) is the default

Commit 1180ed5 told make to only respect $(CROSS_COMPILE) when $(CC)
was unset. But that will never be the case, as make provides
a default value for $(CC). Change this logic to respect $(CROSS_COMPILE)
when $(CC) is the default. Patch originally by Helmet Grohne.

Fixes: 1180ed5 ("Makefile: make the CC definition conditional")
Signed-off-by: dann frazier <dann.frazier@canonical.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
4 years agoAssemble: add support for RAID0 layouts.
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>
4 years 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>
4 years 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>
4 years 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>
4 years 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>
4 years 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>
4 years 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>
4 years 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 years 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 years 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 years 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 years 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 years 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>
4 years 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>
4 years 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>
4 years 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>
4 years 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>
4 years 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>
4 years 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>
4 years 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>
4 years 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 years 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 years 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 years 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 years 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>
4 years 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>
4 years 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>
4 years 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>
4 years 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>
4 years 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>
4 years 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>
5 years 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>
5 years 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>
5 years 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>
5 years 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>
5 years 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>
5 years 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>
5 years 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>
5 years 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>
5 years 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>
5 years 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>
5 years 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>
5 years 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>
5 years 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>
5 years 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>
5 years 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>
5 years 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>
5 years 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>
5 years 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>
5 years 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>