]> git.ipfire.org Git - thirdparty/mdadm.git/log
thirdparty/mdadm.git
2 years agoRelease mdadm-4.2-rc3 mdadm-4.2-rc3
Jes Sorensen [Thu, 4 Nov 2021 01:49:36 +0000 (21:49 -0400)] 
Release mdadm-4.2-rc3

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2 years agoimsm: introduce helpers to manage file descriptors
Mariusz Tkaczyk [Tue, 19 Oct 2021 10:07:43 +0000 (12:07 +0200)] 
imsm: introduce helpers to manage file descriptors

To avoid direct comparisions define dedicated inlines.
This patch propagates them in super-intel.c. They are declared globally
for future usage outside IMSM.

Additionally, it adds fd check in save_backup_imsm() to remove
code vulnerability and simplifies targets array implementation.

It also propagates pr_vrb() macro instead if (verbose) condidtion.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2 years agomdadm/Detail: Can't show container name correctly when unpluging disks
Xiao Ni [Wed, 27 Oct 2021 12:23:14 +0000 (20:23 +0800)] 
mdadm/Detail: Can't show container name correctly when unpluging disks

The test case is:
1. create one imsm container
2. create a raid5 device from the container
3. unplug two disks
4. mdadm --detail /dev/md126
[root@rhel85 ~]# mdadm -D /dev/md126
/dev/md126:
         Container : ��, member 0

The Detail function first gets container name by function
map_dev_preferred. Then it tries to find which disks are
available. In patch db5377883fef(It should be FAILED..)
uses map_dev_preferred to find which disks are under /dev.

But now, the major/minor information comes from kernel space.
map_dev_preferred malloc memory and init a device list when
first be called by Detail. It can't find the device in the
list by the major/minor. It free the memory and reinit the
list.

The container name now points to an area tha has been freed.
So the containt is a mess.

This patch replaces map_dev_preferred with access.

Fixes: db5377883fef (It should be FAILED when raid has)
Signed-off-by: Xiao Ni <xni@redhat.com>
Reported-by: Fine Fan <ffan@redhat.com>
Acked-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2 years agomdadm/lib: Define a new helper function is_dev_alived
Xiao Ni [Wed, 27 Oct 2021 12:23:13 +0000 (20:23 +0800)] 
mdadm/lib: Define a new helper function is_dev_alived

The function is used to check if one member disk is alive.

Signed-off-by: Xiao Ni <xni@redhat.com>
Acked-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2 years agoFix 2 dc stream buffer
Nigel Croxon [Thu, 14 Oct 2021 16:02:00 +0000 (12:02 -0400)] 
Fix 2 dc stream buffer

To meet requirements of Common Criteria certification vulnerablility
assessment. Static code analysis has been run and found the following
Error: DC.STREAM_BUFFER (CWE-120): [#def46]
mdadm-4.2: dont_call: "fscanf" assumes an arbitrarily
long string, so callers must use correct precision specifiers or
never use "fscanf".

The change is to define a value for string %s.

V2: Tighten the value in policy.c to match the limit of the metadata.
Add a change to policy_save_path() to use correct precision on the
fscanf call.

Signed-off-by: Nigel Croxon <ncroxon@redhat.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2 years agoAssemble: apply sysfs rules
Kinga Tanska [Tue, 12 Oct 2021 10:16:16 +0000 (12:16 +0200)] 
Assemble: apply sysfs rules

During assemblation container with quiet flag, sysfs rules are not applied.
This commit makes sysfs_rules_apply() independent from verbose condition.

Signed-off-by: Kinga Tanska <kinga.tanska@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2 years agoFix potential overlap dest buffer
Nigel Croxon [Tue, 17 Aug 2021 13:14:48 +0000 (09:14 -0400)] 
Fix potential overlap dest buffer

To meet requirements of Common Criteria certification vulnerablility
assessment. Static code analysis has been run and found the following
error.  Overlapping_buffer: The source buffer potentially overlaps
with the destination buffer, which results in undefined
behavior for "memcpy".

The change is to use memmove instead of memcpy.

Signed-off-by: Nigel Croxon <ncroxon@redhat.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2 years agodisallow create or grow clustered bitmap with writemostly set
Nigel Croxon [Mon, 23 Aug 2021 12:48:35 +0000 (08:48 -0400)] 
disallow create or grow clustered bitmap with writemostly set

Do not support creating an MD array on a clustered system
(--bitmap=clustered) and disks with the write mostly
(--write-mostly) flag set.

Or do not grow an MD array on a non-clustered bitmap to a
clustered bitmap with disks having the write mostly flag set.

The actual results is the MD array is created successfully.
But the expected results should be a failure with an
error message stating:
Can not set --write-mostly with a clustered bitmap.
and disks marked write-mostly are not supported with clustered bitmap.

V2:
Added the device name in the error message during creation:
mdadm -CR /dev/md0 -l1 --raid-devices=2 /dev/sda --write-mostly /dev/sdb --bitmap=clustered
mdadm: Can not set /dev/sdb --write-mostly with a clustered bitmap.

Added the array name in the error message when growing:
mdadm --grow /dev/md0 --bitmap=clustered
mdadm: /dev/md0 disks marked write-mostly are not supported with clustered bitmap

Signed-off-by: Nigel Croxon <ncroxon@redhat.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2 years agoFix buffer size warning for strcpy
Nigel Croxon [Wed, 25 Aug 2021 15:30:14 +0000 (11:30 -0400)] 
Fix buffer size warning for strcpy

To meet requirements of Common Criteria certification vulnerability
assessment. Static code analysis has been run and found the following
error:
buffer_size_warning: Calling "strncpy" with a maximum size
argument of 16 bytes on destination array "ve->name" of
size 16 bytes might leave the destination string unterminated.
https://people.redhat.com/ncroxon/mdadm-4.2-rc2-scan-results.html

The change is to make the destination size to fit the allocated size.

V5:
Simplify the the strnlen call.

V4:
Code cleanup of the interim "if" statement.

V3: Doc change only:
The code change from filling ve->name with spaces to filling it with
null-terminated is to comform to the SNIA - Common RAID Disk Data
Format Specification. The format for VD_Name (ve->name) specifies
the field to be either ASCII or UNICODE. Bit 2 of the VD_Type field
MUST be used to determine the Unicode or ASCII format of this field.
If this field is not used, all bytes MUST be set to zero.

V2: Change from zero-terminated to zero-padded on memset and
change from using strncpy to memcpy, feedback from Neil Brown.

Tested-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Signed-off-by: Nigel Croxon <ncroxon@redhat.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2 years agoRefactor parse_num and use it to parse optarg.
Mateusz Grzonka [Thu, 2 Sep 2021 09:48:12 +0000 (11:48 +0200)] 
Refactor parse_num and use it to parse optarg.

Use parse_num instead of atoi to parse optarg. Replace atoi by strtol.
Move inst to int conversion into manage_new. Add better error handling.

Signed-off-by: Mateusz Grzonka <mateusz.grzonka@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2 years agoFix error message when creating raid 4, 5 and 10
Mateusz Grzonka [Mon, 30 Aug 2021 08:25:17 +0000 (10:25 +0200)] 
Fix error message when creating raid 4, 5 and 10

Change inappropriate error message "at least 2 raid-devices needed for
level 4 or 5" to only mention relevant raid level.

Signed-off-by: Mateusz Grzonka <mateusz.grzonka@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2 years agomdadm: fix coredump of mdadm --monitor -r
Wu Guanghao [Mon, 16 Aug 2021 07:24:51 +0000 (15:24 +0800)] 
mdadm: fix coredump of mdadm --monitor -r

The --monitor -r option requires a parameter, otherwise a null pointer will be manipulated
when converting to integer data, and a coredump will appear.

Segmentation fault (core dumped)

Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
Acked-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2 years agoUtils: Change sprintf to snprintf
Mateusz Kusiak [Thu, 12 Aug 2021 11:48:48 +0000 (13:48 +0200)] 
Utils: Change sprintf to snprintf

Using sprintf can cause segmentation fault by exceeding the size of buffer array.

Signed-off-by: Mateusz Kusiak <mateusz.kusiak@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2 years agoRelease mdadm-4.2-rc2 mdadm-4.2-rc2
Jes Sorensen [Mon, 2 Aug 2021 17:07:32 +0000 (13:07 -0400)] 
Release mdadm-4.2-rc2

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2 years agoAssemble: skip devices that don't match uuid instead of aborting the assembly.
Sudhakar Panneerselvam [Thu, 22 Jul 2021 18:28:34 +0000 (18:28 +0000)] 
Assemble: skip devices that don't match uuid instead of aborting the assembly.

This fixes '03r0assem' test as assembly fails when looking for specific
uuid among the device list.

Signed-off-by: Sudhakar Panneerselvam <sudhakar.panneerselvam@oracle.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2 years agoAdd monitor delay parameter to mdadm.conf
oshchirs [Fri, 30 Jul 2021 09:16:00 +0000 (11:16 +0200)] 
Add monitor delay parameter to mdadm.conf

Add possibility to configure delay for mdadm in monitoring mode
using mdadm.conf.
--delay command line argument takes precedence over config file.

Signed-off-by: Oleksandr Shchirskyi <oleksandr.shchirskyi@intel.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2 years agotests: Avoid passing chunk size when creating RAID 1
Mateusz Grzonka [Wed, 28 Jul 2021 14:31:11 +0000 (16:31 +0200)] 
tests: Avoid passing chunk size when creating RAID 1

Tests fail because passing chunk size for RAID 1 is now forbidden.
Failing tests:
- 14imsm-r1_2d-grow-r1_3d
- 14imsm-r1_2d-takeover-r0_2d
- 18imsm-1d-takeover-r1_2d
- 18imsm-r1_2d-takeover-r0_1d

Correct tests to not pass chunk size when RAID level is 1.

Signed-off-by: Mateusz Grzonka <mateusz.grzonka@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2 years agoFix memory leak after "mdadm --detail"
Mateusz Grzonka [Tue, 27 Jul 2021 08:25:18 +0000 (10:25 +0200)] 
Fix memory leak after "mdadm --detail"

Signed-off-by: Mateusz Grzonka <mateusz.grzonka@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2 years agoAssemble: start dirty and degraded array.
Mariusz Tkaczyk [Wed, 21 Jul 2021 15:47:54 +0000 (17:47 +0200)] 
Assemble: start dirty and degraded array.

The case when array is already degraded has been omitted
by commit 7b99edab2834 ("Assemble.c: respect force flag.").
Appropriative support has been added now.

Handlers for "run" and "force" have been divided into independent
routines. Especially force has to be as meaningless as possible.
It respects following rules:
    - user agrees to start array as degraded (by --run) or is already
      degraded
    - raid456 module is in use
    - some drives are missing (to limit potential abuses)

It doesn't allow to skip resync on dirty, but not degraded array.

This patch cleans up message generation for external array and makes it
consistent. Following code could be reused also for native.

In current implementation assemble_container_content is called once, in
both Incremental or Assembly mode. Thus makes that partial assembly is
not likely to happen. It is possible, but requires user input.
Partial assembly during reshape fails (sysfs_set_array
error - not yet investigated). For now I put FIXME to mark current
logic as known to be buggy because preexist_cnt contains both exp_cnt
and new_cnt which may produce an incorrect message.

Check for new disks and runstop is unnecessary, so has been removed.
This allows to print assemble status in every case, even if nothing new
happens.

Reported-by: Devon Beets <devon@sigmalabsinc.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2 years agoimsm: fix num_data_stripes after raid0 takeover
Mariusz Tkaczyk [Wed, 21 Jul 2021 11:42:20 +0000 (13:42 +0200)] 
imsm: fix num_data_stripes after raid0 takeover

After raid1 to raid0 migration num_data_stripes value is
incorrect because was additionally divided by 2.

Create dedicated setters for num_data_stripes and num_domains
and propagate it across the code to unify alghoritms and
eliminate similar mistakes.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2 years agoAdd error handling for chunk size in RAID1
Mateusz Grzonka [Thu, 15 Jul 2021 10:25:23 +0000 (12:25 +0200)] 
Add error handling for chunk size in RAID1

Print error if chunk size is set as it is not supported.

Signed-off-by: Mateusz Grzonka <mateusz.grzonka@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2 years agoimsm: Fix possible memory leaks and refactor freeing struct dl
Mateusz Grzonka [Mon, 28 Jun 2021 12:15:04 +0000 (14:15 +0200)] 
imsm: Fix possible memory leaks and refactor freeing struct dl

Free memory allocated by structs dl and intel_super.
Allow __free_imsm_disk to decide if fd has to be closed and propagate it
across code instead of direct struct dl freeing.

Signed-off-by: Mateusz Grzonka <mateusz.grzonka@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2 years agomdadm: Fix building errors
Xiao Ni [Tue, 22 Jun 2021 15:15:55 +0000 (23:15 +0800)] 
mdadm: Fix building errors

In util.c, there is a building error:
'/md/metadata_version' directive writing 20 bytes into a
region of size between 0 and 255 [-Werror=format-overflow=]

In mapfile.c
It declares the fouth argument as 'int *' in map_update,
but in mdadm.h it's previously declared as an array 'int[4]'

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2 years agoDon't associate spares with other arrays during RAID Examine
Oleksandr Shchirskyi [Fri, 18 Jun 2021 13:53:32 +0000 (15:53 +0200)] 
Don't associate spares with other arrays during RAID Examine

Spares in imsm belong to containers, not volumes, and must go into
a separate container when assembling the RAID.
Remove association spares with other arrays and make Examine print
separate containers for spares.
Auto assemble without config file already works like this. So make
creating a config file and assembling from it consistent with auto
assemble.
With this change, mdadm -Es will add this line to output if spares
are found:
ARRAY metadata=imsm UUID=00000000:00000000:00000000:00000000

Signed-off-by: Oleksandr Shchirskyi <oleksandr.shchirskyi@linux.intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2 years agoRemove Spare drives line from details for external metadata
Oleksandr Shchirskyi [Fri, 18 Jun 2021 13:53:31 +0000 (15:53 +0200)] 
Remove Spare drives line from details for external metadata

Arrays with external metadata do not have spare disks directly
assigned to volumes; spare disks belong to containers and are
moved to arrays when the array is degraded/reshaping.
Thus, the display of zero spare disks in volume details is
incorrect and can be confusing.

Signed-off-by: Oleksandr Shchirskyi <oleksandr.shchirskyi@linux.intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2 years agoimsm: correct offset for 4k disks in --examine output
Oleksandr Shchirskyi [Fri, 18 Jun 2021 13:53:30 +0000 (15:53 +0200)] 
imsm: correct offset for 4k disks in --examine output

"Sector Offset" field in Examine output was always printed in 512
byte sectors. Update it to support 4096 sector size.

Signed-off-by: Oleksandr Shchirskyi <oleksandr.shchirskyi@linux.intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2 years agoUse dev_open in validate geometry container
Blazej Kucman [Tue, 15 Jun 2021 14:45:39 +0000 (16:45 +0200)] 
Use dev_open in validate geometry container

Fix regression caused by the patch 1f5d54a06
("Manage: Call validate_geometry when adding drive to external container")
- mdmonitor passes to Manage() routine dev name as min:mjr.
The open() used in validate_geometry_container()
in both ddf and imsm requires path, replace open calls by dev_open,
which allows to use dev path and min:mjr.

Signed-off-by: Blazej Kucman <blazej.kucman@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2 years agomdadm/super1: It needs to specify int32 for bitmap_offset
Xiao Ni [Wed, 2 Jun 2021 01:17:19 +0000 (09:17 +0800)] 
mdadm/super1: It needs to specify int32 for bitmap_offset

For super1.0 bitmap offset is -16. So it needs to use int type for bitmap offset.

Fixes: 1fe2e1007310 (mdadm/bitmap: locate bitmap calcuate bitmap position wrongly)
Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2 years agoManage: Call validate_geometry when adding drive to external container
Mariusz Tkaczyk [Mon, 17 May 2021 14:39:03 +0000 (16:39 +0200)] 
Manage: Call validate_geometry when adding drive to external container

When adding drive to container call validate_geometry to verify whether
drive is supported and can be addded to container.

Remove unused parameters from validate_geometry_imsm_container().
There is no need to pass them.
Don't calculate freesize if it is not mandatory. Make it configurable.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2 years agoimsm: Limit support to the lowest namespace
Mariusz Tkaczyk [Mon, 17 May 2021 14:39:02 +0000 (16:39 +0200)] 
imsm: Limit support to the lowest namespace

First namespace existence is not quaranted by NVMe specification.
Instead first the smallest one shall be chosen.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2 years agoimsm: add devpath_to_char method
Mariusz Tkaczyk [Mon, 17 May 2021 14:39:01 +0000 (16:39 +0200)] 
imsm: add devpath_to_char method

Add method for reading sysfs attributes and propagate it across IMSM code.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2 years agoimsm: add generic method to resolve "device" links
Mariusz Tkaczyk [Mon, 17 May 2021 14:39:00 +0000 (16:39 +0200)] 
imsm: add generic method to resolve "device" links

Each virtual device is linked with parent by "device". This patch adds
possibility to get previous device in sysfs tree.

Depending on device type, there is a different amount of virutal
layers. The best we can do is allow to directly specify how many
"device" links need to be resolved. This approach also allows to get
previous virtual device, which may contain some attributes.

Simplify fd2devname, this function doesn't require new functionality and
shall use generic fd2kname.

For nvme drives represented via nvme-subystem when path to block
device if requested, then return it without translation.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agoPrevent user from using --stop with ambiguous args
Norbert Szulc [Wed, 5 May 2021 11:01:02 +0000 (13:01 +0200)] 
Prevent user from using --stop with ambiguous args

When both --scan and device name is passed to --stop action,
then is executed only for given device. Scan is ignored.

Block the operation when both --scan and device name are passed.

Signed-off-by: Norbert Szulc <norbert.szulc@intel.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agoFix some building errors
Xiao Ni [Fri, 23 Apr 2021 06:01:30 +0000 (14:01 +0800)] 
Fix some building errors

There are some building errors if treating warning as errors.
Fix them in this patch.

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agoimsm: change wrong size verification
Mariusz Tkaczyk [Wed, 21 Apr 2021 14:50:08 +0000 (16:50 +0200)] 
imsm: change wrong size verification

Expectation that size is always rounded is incorrect.
Just confirm that size is smaller to be certain that update is safe.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agoRelease mdadm-4.2-rc1 mdadm-4.2-rc1
Jes Sorensen [Wed, 14 Apr 2021 15:02:53 +0000 (11:02 -0400)] 
Release mdadm-4.2-rc1

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agosuper-intel.c: Handle errors from calls to get_dev_sector_size()
Jes Sorensen [Wed, 14 Apr 2021 15:15:07 +0000 (11:15 -0400)] 
super-intel.c: Handle errors from calls to get_dev_sector_size()

The compiler gets rather upset if we do not take care of this.

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agomdadm: fix growing containers
Nigel Croxon [Fri, 26 Mar 2021 11:56:10 +0000 (07:56 -0400)] 
mdadm: fix growing containers

This fixes growing containers which was broken with
commit 4ae96c802203ec3c (mdadm: fix reshape from RAID5 to RAID6 with
backup file)

The issue being that containers use the function
wait_for_reshape_isms and expect a number value and not a
string value of "max".  The change is to test for external
before setting the correct value.

Signed-off-by: Nigel Croxon <ncroxon@redhat.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agoMonitor: make libudev dependency optional
Mariusz Tkaczyk [Thu, 18 Mar 2021 16:12:35 +0000 (17:12 +0100)] 
Monitor: make libudev dependency optional

Make -ludev configurable, enabled by default.
To disable it, -DNO_LIBUDEV has to be set explicitly in CXFALGS.

This patch restores commit cab9c67d461c ("mdmonitor: set small delay
once") for configuration without libudev to bring minimal support in
such case.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agoimsm: support for third Sata controller
Mariusz Tkaczyk [Wed, 17 Mar 2021 12:01:54 +0000 (13:01 +0100)] 
imsm: support for third Sata controller

Add new UEFI TSata variable. Remove CSata variable.
This variable has been never exposed by UEFI.
Remove vulnerability to match different hbas with SATA variable.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agoimsm: nvme multipath support
Blazej Kucman [Fri, 12 Mar 2021 09:30:16 +0000 (10:30 +0100)] 
imsm: nvme multipath support

Add support for nvme devices which are represented
via nvme-subsystem.
Print warning when multi-path disk is added to RAID.

Signed-off-by: Oleksandr Shchirskyi <oleksandr.shchirskyi@intel.com>
Signed-off-by: Blazej Kucman <blazej.kucman@intel.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agoimsm: extend curr_migr_unit to u64
Mariusz Tkaczyk [Thu, 11 Mar 2021 12:52:45 +0000 (13:52 +0100)] 
imsm: extend curr_migr_unit to u64

Make it u64 to align it with curr_migr_init field from migration_area.

Name helpers as vol_curr_migr_unit for differentiation between those
fields. Add ommited fillers in struct migr_record.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agoGrow: Block reshape when external metadata and write-intent bitmap
Jakub Radtke [Fri, 15 Jan 2021 05:47:01 +0000 (00:47 -0500)] 
Grow: Block reshape when external metadata and write-intent bitmap

Current kernel sysfs interface for the bitmap is limited. It allows
the applying of the bitmap on non-active volumes only.
The reshape operation for a volume with a bitmap should be blocked.

Signed-off-by: Jakub Radtke <jakub.radtke@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agoCreate: Block automatic enabling bitmap for external metadata
Jakub Radtke [Fri, 15 Jan 2021 05:47:00 +0000 (00:47 -0500)] 
Create: Block automatic enabling bitmap for external metadata

For external metadata, bitmap should be added only when
explicitly set by the administrator.
They could be additional requirements to consider before
enabling the external metadata's functionality
(e.g., kernel support).

Signed-off-by: Jakub Radtke <jakub.radtke@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agoimsm: Update-subarray for write-intent bitmap
Jakub Radtke [Fri, 15 Jan 2021 05:46:59 +0000 (00:46 -0500)] 
imsm: Update-subarray for write-intent bitmap

The patch updates the current bitmap functionality to handle adding
the bitmap on existing volumes.

Signed-off-by: Jakub Radtke <jakub.radtke@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agoAdd "bitmap" to allowed command-line values
Jakub Radtke [Fri, 15 Jan 2021 05:46:58 +0000 (00:46 -0500)] 
Add "bitmap" to allowed command-line values

Currently, the sysfs interface allows bitmap setup only when volume
is in an inactive state.
For external metadata to add bitmap to existing volume instead of
GROW, the UPDATE operation can be done.
The patch adds a "bitmap" argument to the allowed values for UPDATE.

Signed-off-by: Jakub Radtke <jakub.radtke@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agoimsm: Adding a spare to an existing array with bitmap
Jakub Radtke [Fri, 15 Jan 2021 05:46:57 +0000 (00:46 -0500)] 
imsm: Adding a spare to an existing array with bitmap

When adding a spare to an existing array with bitmap, an additional
initialization (adding bitmap header and preparing the bitmap area)
is required.

Signed-off-by: Jakub Radtke <jakub.radtke@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agoimsm: Write-intent bitmap support
Jakub Radtke [Fri, 15 Jan 2021 05:46:56 +0000 (00:46 -0500)] 
imsm: Write-intent bitmap support

This patch enables the bitmap functionality with the IMSM metadata format.
The functionality covers "internal" bitmap.

There are the following limitation to "internal" metadata:
- creating the bitmap using --grow is not supported
- parameter --bitmap-chunk is ignored (default value 64MiB is used)

Signed-off-by: Jakub Radtke <jakub.radtke@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agoEnable bitmap support for external metadata
Jakub Radtke [Fri, 15 Jan 2021 05:46:55 +0000 (00:46 -0500)] 
Enable bitmap support for external metadata

The patch enables the implementation of a write-intent bitmap for external
metadata.
Configuration of the internal bitmaps for non-native metadata requires the
extension in superswitch to perform an additional sysfs setup before the
array is activated.

Signed-off-by: Jakub Radtke <jakub.radtke@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agoModify mdstat parsing for volumes with the bitmap
Jakub Radtke [Fri, 15 Jan 2021 05:46:54 +0000 (00:46 -0500)] 
Modify mdstat parsing for volumes with the bitmap

Current mdstat read functionality is not working correctly
for the volumes with the write-intent bitmap.
It affects rebuild and reshape use cases.

Signed-off-by: Jakub Radtke <jakub.radtke@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agoIt should be FAILED when raid has not enough active disks
Xiao Ni [Tue, 9 Feb 2021 09:39:51 +0000 (17:39 +0800)] 
It should be FAILED when raid has not enough active disks

It can't remove the disk if there are not enough disks. For example, raid5 can't remove the
second disk. If the second disk is unplug from machine, it's better show missing and the raid
should be FAILED. It's better for administrator to monitor the raid.

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agoimsm: add verbose flag to compare_super
Mariusz Tkaczyk [Fri, 5 Feb 2021 13:29:58 +0000 (14:29 +0100)] 
imsm: add verbose flag to compare_super

IMSM does more than comparing metadata and errors reported directly
from compare_super_imsm can be useful.

Add verbose flag to compare_super method and make all not critical
error printing configurable.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agomdmonitor: check if udev has finished events processing
Oleksandr Shchirskyi [Thu, 14 Jan 2021 14:14:16 +0000 (15:14 +0100)] 
mdmonitor: check if udev has finished events processing

If mdmonitor is awaken by event, wait for udev to finish
events processing, to eliminate the race between udev and mdadm
when spare has been added and need to be moved by mdmonitor

Signed-off-by: Oleksandr Shchirskyi <oleksandr.shchirskyi@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agoDocument PPL in man md
Oleksandr Shchirskyi [Thu, 14 Jan 2021 12:59:20 +0000 (13:59 +0100)] 
Document PPL in man md

Partial Parity Log (PPL) was not documented in the man md.
Added brief info about PPL.

Signed-off-by: Oleksandr Shchirskyi <oleksandr.shchirskyi@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agoimsm: use saved fds during migration
Mariusz Tkaczyk [Wed, 13 Jan 2021 08:58:45 +0000 (09:58 +0100)] 
imsm: use saved fds during migration

IMSM super keeps open descriptors in super->disks structure, they are
reliable and should be chosen if possible. The repeatedly called open
and close during reshape generates redundant udev change events on
each member drive.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agosuper1.c: avoid useless sync when bitmap switches from clustered to none
Zhao Heming [Wed, 3 Feb 2021 00:22:51 +0000 (08:22 +0800)] 
super1.c: avoid useless sync when bitmap switches from clustered to none

With kernel commit 480523feae58 ("md: only call set_in_sync() when it
is expected to succeed."), mddev->in_sync in clustered array is always
zero. It makes metadata resync_offset to always zero.
When assembling a clusterd array with "-U no-bitmap" option, kernel
md layer "mddev->resync_offset == 0" and "mddev->bitmap == NULL" will
trigger raid1 do sync on every bitmap chunk. the sync action is useless,
we should avoid it.

Related kernel flow:
```
md_do_sync
 mddev->pers->sync_request
  raid1_sync_request
   md_bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, 1)
    __bitmap_start_sync(bitmap, offset,&blocks1, degraded)
      if (bitmap == NULL) {/* FIXME or bitmap set as 'failed' */
        *blocks = 1024;
        return 1; /* always resync if no bitmap */
      }
```

Reprodusible steps:
```
node1 # mdadm -C /dev/md0 -b clustered -e 1.2 -n 2 -l mirror /dev/sd{a,b}
node1 # mdadm -Ss
(in another shell, executing & watching: watch -n 1 'cat /proc/mdstat')
node1 # mdadm -A -U no-bitmap /dev/md0 /dev/sd{a,b}
```

Signed-off-by: Zhao Heming <heming.zhao@suse.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agosuper1: fix Floating point exception
Zhao Heming [Sat, 30 Jan 2021 09:49:54 +0000 (17:49 +0800)] 
super1: fix Floating point exception

write_bitmap1 didn't check return value of locate_bitmap1, which will
operate bitmap area under invalid bitmap info.

mdadm core dumped when doing below steps:
```
node1 # mdadm -C /dev/md0 -b none -e 1.2 -n 2 -l mirror /dev/sda /dev/sdb
node1 # mdadm -Ss
node1 # mdadm -A -U home-cluster --home-cluster=abc /dev/md0 /dev/sda /dev/sdb
Floating point exception (core dumped)
```

Signed-off-by: Zhao Heming <heming.zhao@suse.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agoGrow: be careful of corrupt dev_roles list
NeilBrown [Fri, 26 Feb 2021 01:02:36 +0000 (12:02 +1100)] 
Grow: be careful of corrupt dev_roles list

I've seen a case where the dev_roles list of a linear array
was corrupt.  ->max_dev was > 128 and > raid_disks, and the
extra slots were '0', not 0xFFFE or 0xFFFF.

This caused problems when a 128th device was added.

So:
 1/ make Grow_Add_device more robust so that if numbers
   look wrong, it fails-safe.

 2/ make examine_super1() report details if the dev_roles
   array is corrupt.

Signed-off-by: NeilBrown <neilb@suse.de>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agomdadm: fix reshape from RAID5 to RAID6 with backup file
Nigel Croxon [Wed, 20 Jan 2021 20:05:42 +0000 (15:05 -0500)] 
mdadm: fix reshape from RAID5 to RAID6 with backup file

Reshaping a 3-disk RAID5 to 4-disk RAID6 will cause a hang of
the resync after the grow.

Adding a spare disk to avoid degrading the array when growing
is successful, but not successful when supplying a backup file
on the command line. If the reshape job is not already running,
set the sync_max value to max.

Signed-off-by: Nigel Croxon <ncroxon@redhat.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agomdadm/bitmap: locate bitmap calcuate bitmap position wrongly
Xiao Ni [Wed, 28 Oct 2020 06:04:24 +0000 (14:04 +0800)] 
mdadm/bitmap: locate bitmap calcuate bitmap position wrongly

Now it only adds bitmap offset based on cluster nodes. It's not right. It needs to
add per node bitmap space to find next node bitmap position.

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agoDump: get stat from a wrong metadata file when restoring metadata
Lidong Zhong [Mon, 14 Dec 2020 14:51:33 +0000 (22:51 +0800)] 
Dump: get stat from a wrong metadata file when restoring metadata

The dumped metadata files are shown as below
localhost:~ # ll -ih test/
total 16K
34565564 -rw-r--r-- 2 root root 1.0G Dec 14 21:15
scsi-0QEMU_QEMU_HARDDISK_drive-scsi0-0-0-3
34565563 -rw-r--r-- 2 root root 1.0G Dec 14 21:15
scsi-0QEMU_QEMU_HARDDISK_drive-scsi0-0-0-4
34565563 -rw-r--r-- 2 root root 1.0G Dec 14 21:15 sda
34565564 -rw-r--r-- 2 root root 1.0G Dec 14 21:15 sdb

It reports such error when trying to restore metadata for /dev/sda
localhost:~ # mdadm --restore=test /dev/sda
mdadm: test/scsi-0QEMU_QEMU_HARDDISK_drive-scsi0-0-0-4 is not the same
size as /dev/sda - cannot restore.
It's because the stb value has been changed to other metadata file in
the while statement.

Signed-off-by: Lidong Zhong <lidong.zhong@suse.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agoIncremental: Remove redundant spare movement logic
Mariusz Tkaczyk [Fri, 11 Dec 2020 11:28:38 +0000 (12:28 +0100)] 
Incremental: Remove redundant spare movement logic

If policy is set then mdmonitor is responsible for moving spares.
This logic is reduntant and potentialy dangerus, spare could be moved at
initrd stage depending on drives appearance order.

Remove it.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3 years agoudev: start grow service automatically
Tkaczyk Mariusz [Thu, 15 Oct 2020 08:45:29 +0000 (10:45 +0200)] 
udev: start grow service automatically

Grow continue via service or fork is started during raid assembly.
If raid was assembled in initrd it will be newer restarted after
switch root.
Add udev support for starting mdadm-grow-continue service.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@intel.com>
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>
4 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>