]> git.ipfire.org Git - thirdparty/mdadm.git/log
thirdparty/mdadm.git
12 months agomdadm/mdopen: fix coverity issue STRING_OVERFLOW
Xiao Ni [Fri, 26 Jul 2024 07:14:10 +0000 (15:14 +0800)] 
mdadm/mdopen: fix coverity issue STRING_OVERFLOW

Fix string overflow problems in mdopen.c

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
12 months agomdadm/mdopen: fix coverity issue CHECKED_RETURN
Xiao Ni [Fri, 26 Jul 2024 07:14:09 +0000 (15:14 +0800)] 
mdadm/mdopen: fix coverity issue CHECKED_RETURN

It needs to check return values when functions return value.

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
12 months agomdadm/mdmon: fix coverity issue RESOURCE_LEAK
Xiao Ni [Fri, 26 Jul 2024 07:14:08 +0000 (15:14 +0800)] 
mdadm/mdmon: fix coverity issue RESOURCE_LEAK

Fix resource leak problem in mdmon.c

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
12 months agomdadm/mdmon: fix coverity issue CHECKED_RETURN
Xiao Ni [Fri, 26 Jul 2024 07:14:07 +0000 (15:14 +0800)] 
mdadm/mdmon: fix coverity issue CHECKED_RETURN

It needs to check return values when functions have return value.

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
12 months agomdadm/Incremental: fix coverity issues.
Xiao Ni [Fri, 26 Jul 2024 07:14:06 +0000 (15:14 +0800)] 
mdadm/Incremental: fix coverity issues.

There are two issues PW.PARAMETER_HIDDEN (declaration hides
parameter 'devname') and INTEGER_OVERFLOW.

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
12 months agomdadm/Grow: fix coverity issue STRING_OVERFLOW
Xiao Ni [Fri, 26 Jul 2024 07:14:05 +0000 (15:14 +0800)] 
mdadm/Grow: fix coverity issue STRING_OVERFLOW

Fix string overflow problems in Grow.c

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
12 months agomdadm/Grow: fix coverity issue RESOURCE_LEAK
Xiao Ni [Fri, 26 Jul 2024 07:14:04 +0000 (15:14 +0800)] 
mdadm/Grow: fix coverity issue RESOURCE_LEAK

Fix some resource leak problems.

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
12 months agomdadm/Grow: fix coverity issue CHECKED_RETURN
Xiao Ni [Fri, 26 Jul 2024 07:14:03 +0000 (15:14 +0800)] 
mdadm/Grow: fix coverity issue CHECKED_RETURN

It needs to check return value when functions have return value.

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
12 months agoimsm: refactor chunk size print
Blazej Kucman [Wed, 24 Jul 2024 20:17:42 +0000 (22:17 +0200)] 
imsm: refactor chunk size print

- add imsm_chunk_ops struct for better code readability,
- move chunk size mapping to string into array,
- add function to print supported chunk sizes by IMSM controller.

Signed-off-by: Blazej Kucman <blazej.kucman@intel.com>
12 months agomdadm: msg.c fix coverity issues
Nigel Croxon [Wed, 24 Jul 2024 13:20:28 +0000 (09:20 -0400)] 
mdadm: msg.c fix coverity issues

Fixing the following coding errors the coverity tools found:

* Event check_return: Calling "fcntl(sfd, 4, fl)" without
checking return value. This library function may fail and
return an error code.

Signed-off-by: Nigel Croxon <ncroxon@redhat.com>
12 months agomdadm: managemon.c fix coverity issues
Nigel Croxon [Wed, 24 Jul 2024 13:04:08 +0000 (09:04 -0400)] 
mdadm: managemon.c fix coverity issues

Fixing the following coding errors the coverity tools found:

* Event check_return: Calling "fcntl(fd, 4, fl)" without checking
return value. This library function may fail and return an error code.

* Event check_after_deref: Null-checking "new" suggests that it may
be null, but it has already been dereferenced on all paths leading
to the check.

Signed-off-by: Nigel Croxon <ncroxon@redhat.com>
12 months agomdstat: Rework mdstat external arrays handling
Mariusz Tkaczyk [Fri, 5 Jul 2024 08:49:27 +0000 (10:49 +0200)] 
mdstat: Rework mdstat external arrays handling

To avoid repeating mdstat_read() in IncrementalRemove(), new function
mdstat_find_by_member_name() has been proposed. With that,
IncrementalRemove() handles own copy of mdstat content and there is no
need to repeat reading for external stop.

Additionally, It proposed few helper to avoid repeating
mdstat_ent->metadata_version checks across code.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
12 months agoreview.yml: fix typo in DEBIAN compiler flag
Kinga Stefaniuk [Thu, 4 Jul 2024 16:41:01 +0000 (18:41 +0200)] 
review.yml: fix typo in DEBIAN compiler flag

Fix typo in -DEBIAN flag in review.yml file.

Signed-off-by: Kinga Stefaniuk <kinga.stefaniuk@intel.com>
12 months agoMakefile: add more compiler flags
Kinga Stefaniuk [Thu, 4 Jul 2024 13:01:06 +0000 (15:01 +0200)] 
Makefile: add more compiler flags

It is essential to avoid vulnerabilities in code as much
as possible using safe compilation flags. It is easier if
they are added to the Makefile and applied during compilation.
Add new gcc flags and make them configurable, because they
may not be supported for some compilers.
Set FORTIFY_SOURCE with the highest supported value for platform.

Signed-off-by: Kinga Stefaniuk <kinga.stefaniuk@intel.com>
12 months agosuper0: use define for char array in examine_super0
Kinga Stefaniuk [Thu, 4 Jul 2024 12:53:35 +0000 (14:53 +0200)] 
super0: use define for char array in examine_super0

Using nb with 11 length may cause format-truncation errors,
because it was possible to use snprintf with 12 length input
and write it to 11 length output. Added new define and use it
to avoid this error.

Signed-off-by: Kinga Stefaniuk <kinga.stefaniuk@intel.com>
12 months agodrive_encryption: Fix ata passthrough12 verify
Blazej Kucman [Tue, 23 Jul 2024 10:45:10 +0000 (12:45 +0200)] 
drive_encryption: Fix ata passthrough12 verify

Based on documentation SCSI Primary Commands - 4 (SPC-4) only first 7 bits
of first byte in sense data are used to store response code. The current
verification uses all 8 bits for comparison of response code.

Incorrect verification may make impossible to use SATA disks with IMSM,
because IMSM requires verification of the encryption state before use.

There was issue in kernel libata [1]. This issue hides bug in mdadm because
last bit was not set.

Example output with affected mdadm:

          Port3 : /dev/sde (BTPR212503EK120LGN)
mdadm: Failed ata passthrough12 ioctl. Device: /dev/sde.
mdadm: Failed to get drive encryption information

The fix is use the first 7 bits of Byte 0, to compare with the expected
values.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/libata/linux.git/commit/?id=38dab832c3f4

Fixes: df38df3052c3 ("Add reading SATA encryption information")
Signed-off-by: Blazej Kucman <blazej.kucman@intel.com>
12 months agoDetail: fix --detail --export for uuid_zero
Kinga Stefaniuk [Tue, 23 Jul 2024 13:38:41 +0000 (15:38 +0200)] 
Detail: fix --detail --export for uuid_zero

Mentioned commit (see Fixes) causes that devices with UUID
equal to uuid_zero was not recognized properly. For few devices
the first one was taken always, and the same information was
printed. It caused regression, when few containers were created,
symlinks were generated only for the first one.

Add checking if uuid is uuid_zero and, if yes, use devname to
differentiate devices.

Fixes: 60c19530dd7c ("Detail: remove duplicated code")
Signed-off-by: Kinga Stefaniuk <kinga.stefaniuk@intel.com>
12 months agoCI: fetch all of the changes in repository
Kinga Stefaniuk [Tue, 23 Jul 2024 13:53:29 +0000 (15:53 +0200)] 
CI: fetch all of the changes in repository

GH action is using checkout plugin, which takes fetch-depth
as a parameter to specify number of commits to fetch. Setting it
to 0 to fetch all of the history of all branches and tags.

Signed-off-by: Kinga Stefaniuk <kinga.stefaniuk@intel.com>
12 months agomdadm: do not allow leading dot in MD device name
Mariusz Tkaczyk [Mon, 15 Jul 2024 10:29:24 +0000 (12:29 +0200)] 
mdadm: do not allow leading dot in MD device name

Do not allow to use '.' on first place for named MD device.
Having leading dot might be confusing, MD device cannot be hidden.
It also removes possibility to create md device with name '.'.

Additionally, code optimalizations are done.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
12 months agomdadm: lib.c fix coverity issues
Nigel Croxon [Tue, 16 Jul 2024 11:20:10 +0000 (07:20 -0400)] 
mdadm: lib.c fix coverity issues

Fixing the following coding errors the coverity tools found:

* Event fixed_size_dest: You might overrun the 32-character fixed-size
string "devnm" by copying "cp + 1" without checking the length.

* Event fixed_size_dest: You might overrun the 32-character fixed-size
string "devnm" by copying "cp" without checking the length.

Signed-off-by: Nigel Croxon <ncroxon@redhat.com>
12 months agomdadm: Query.c fix coverity issues
Nigel Croxon [Tue, 16 Jul 2024 11:19:34 +0000 (07:19 -0400)] 
mdadm: Query.c fix coverity issues

Fixing the following coding errors the coverity tools found:

* Event leaked_storage: Variable "sra" going out of scope leaks the
storage it points to.

* Event uninit_use_in_call: Using uninitialized value "larray_size" when
calling "human_size_brief".

Signed-off-by: Nigel Croxon <ncroxon@redhat.com>
12 months agomdadm: Monitor.c fix coverity issues
Nigel Croxon [Mon, 15 Jul 2024 14:13:46 +0000 (10:13 -0400)] 
mdadm: Monitor.c fix coverity issues

Fixing the following coding errors the coverity tools found:

* Event check_return: Calling "fcntl(fd, 2, 1)" without checking
return value. This library function may fail and return an error code.

* Dereferencing "sl", which is known to be "NULL".

* Event fixed_size_dest: You might overrun the 32-character fixed-size
string "devnm" by copying "tmp" without checking the length.

Signed-off-by: Nigel Croxon <ncroxon@redhat.com>
12 months agoimsm: add indent for encryption details
Mariusz Tkaczyk [Mon, 15 Jul 2024 10:21:19 +0000 (12:21 +0200)] 
imsm: add indent for encryption details

Improve readability of the output.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
12 months agoManage: fix is_remove_safe()
Mariusz Tkaczyk [Tue, 16 Jul 2024 13:37:34 +0000 (15:37 +0200)] 
Manage: fix is_remove_safe()

Fix for to make --set-faulty working.

Fixes: 1b4b73fd535a ("mdadm: Manage.c fix coverity issues")
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
12 months agomdadm: Manage.c fix coverity issues
Nigel Croxon [Wed, 10 Jul 2024 12:55:08 +0000 (08:55 -0400)] 
mdadm: Manage.c fix coverity issues

Fixing the following coding errors the coverity tools found:

* Event parameter_hidden: declaration hides parameter "dv".
* Event leaked_storage: Variable "mdi" going out of scope leaks the storage
it points to.
* Event overwrite_var: Overwriting "mdi" in "mdi = mdi->devs" leaks the
storage that "mdi" points to.
* Event leaked_handle: Handle variable "lfd" going out of scope leaks
the handle.
* Event leaked_handle: Returning without closing handle "fd" leaks it.
* Event fixed_size_dest: You might overrun the 32-character fixed-sizei
string "devnm" by copying the return value of "fd2devnm" without
checking the length.
* Event fixed_size_dest: You might overrun the 32-character fixed-size
string "nm" by copying "nmp" without checking the length.
* Event fixed_size_dest: You might overrun the 32-character fixed-size
string "devnm" by copying the return value of "fd2devnm" without
checking the length.
* Event assigned_value: Assigning value "-1" to "tfd" here, but that
stored value is overwritten before it can be used.

Signed-off-by: Nigel Croxon <ncroxon@redhat.com>
12 months agomapfile.c: Fix STRING_OVERFLOW issue
Anna Sztukowska [Wed, 3 Jul 2024 12:11:58 +0000 (14:11 +0200)] 
mapfile.c: Fix STRING_OVERFLOW issue

Fix STRING_OVERFLOW issue found by SAST analysis in map_add() and
map_update() in mapfile.c.

Signed-off-by: Anna Sztukowska <anna.sztukowska@intel.com>
12 months agomdadm/clustermd_tests: adjust test cases to support md module changes
Heming Zhao [Tue, 9 Jul 2024 12:04:52 +0000 (20:04 +0800)] 
mdadm/clustermd_tests: adjust test cases to support md module changes

Since kernel commit db5e653d7c9f ("md: delay choosing sync action to
md_start_sync()") delays the start of the sync action, clustermd
array sync/resync jobs can happen on any leg of the array. This
commit adjusts the test cases to follow the new kernel layer behavior.

Signed-off-by: Heming Zhao <heming.zhao@suse.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
12 months agomdadm/clustermd_tests: add some APIs in func.sh to support running the tests without...
Heming Zhao [Tue, 9 Jul 2024 12:04:51 +0000 (20:04 +0800)] 
mdadm/clustermd_tests: add some APIs in func.sh to support running the tests without errors

clustermd_tests/func.sh lacks some APIs to run, this patch makes
clustermd_tests runnable from the test suite.

Signed-off-by: Heming Zhao <heming.zhao@suse.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
12 months agomdadm: super-ddf.c fix coverity issues
Nigel Croxon [Tue, 2 Jul 2024 14:11:26 +0000 (10:11 -0400)] 
mdadm: super-ddf.c fix coverity issues

Fixing the following coding errors the coverity tools found:

* Calling "lseek64" without checking return value. This library function may
fail and return an error code.
* Overrunning array "anchor->pad2" of 3 bytes by passing it to a function
which accesses it at byte offset 398 using argument "399UL".
* Event leaked_storage: Variable "sra" going out of scope leaks the storage
it points to.
* Event leaked_storage: Variable "super" going out of scope leaks the storage
it points to.
* Event leaked_handle: Handle variable "dfd" going out of scope leaks the
handle.
* Event leaked_storage: Variable "dl1" going out of scope leaks the storage
it points to
* Event leaked_handle: Handle variable "cfd" going out of scope leaks the
handle.
* Variable "avail" going out of scope leaks the storage it points to.
* Passing unterminated string "super->anchor.revision" to "fprintf", which
expects a null-terminated string.
* You might overrun the 32-character fixed-size string "st->container_devnm"
by copying the return value of "fd2devnm" without checking the length.
* Event fixed_size_dest: You might overrun the 33-character fixed-size string
"dev->name" by copying "(*d).devname" without checking the length.
* Event uninit_use_in_call: Using uninitialized value "info.array.raid_disks"
when calling "getinfo_super_ddf"

V2: clean up validate_geometry_ddf() routine with Mariusz Tkaczyk recommendations.
V3: clean up spaces with Blazej Kucman recommendations.
V4: clean up recommended by Mariusz Tkaczyk.
V5: clean up recommended by Mariusz Tkaczyk.

Signed-off-by: Nigel Croxon <ncroxon@redhat.com>
13 months agomdadm: Create.c fix coverity issues
Nigel Croxon [Fri, 5 Jul 2024 12:45:32 +0000 (08:45 -0400)] 
mdadm: Create.c fix coverity issues

* Event negative_returns: "fd" is passed to a parameter that cannot be negative. Which
is set to -1 to start.

* Event open_fn: Returning handle opened by "open_dev_excl".
* Event var_assign: Assigning: "container_fd" = handle returned from
"open_dev_excl(st->container_devnm)"
* Event leaked_handle: Handle variable "container_fd" going out of scope leaks the handle

Signed-off-by: Nigel Croxon <ncroxon@redhat.com>
13 months agomdadm: Build.c fix coverity issues
Nigel Croxon [Tue, 2 Jul 2024 13:49:13 +0000 (09:49 -0400)] 
mdadm: Build.c fix coverity issues

Event leaked_handle: Handle variable "bitmap_fd" going out of
scope leaks the handle.

Signed-off-by: Nigel Croxon <ncroxon@redhat.com>
13 months agoconfig.c: Fix memory leak in load_containers()
Anna Sztukowska [Fri, 28 Jun 2024 10:32:16 +0000 (12:32 +0200)] 
config.c: Fix memory leak in load_containers()

Fix memory leak in load_containers() in config.c reported by SAST
analysis.

Signed-off-by: Anna Sztukowska <anna.sztukowska@intel.com>
13 months agoCI: use prepared checkpatch.conf file only for GH actions
Kinga Stefaniuk [Mon, 1 Jul 2024 14:31:32 +0000 (16:31 +0200)] 
CI: use prepared checkpatch.conf file only for GH actions

Configuration file .checkpatch.conf is working properly only with
GH actions, because flags from GH plugin are used there. This file
shall not be placed in main repo directory, because it causes errors
while using checkpatch from Linux. Add step to review.yml to copy
this file before checkpatch action is started.

Signed-off-by: Kinga Stefaniuk <kinga.stefaniuk@intel.com>
13 months agomdadm: Fix socket connection failure when mdmon runs in foreground mode.
Shminderjit Singh [Mon, 24 Jun 2024 08:58:51 +0000 (08:58 +0000)] 
mdadm: Fix socket connection failure when mdmon runs in foreground mode.

While creating an IMSM RAID, mdadm will wait for the mdmon main process
to finish if mdmon runs in forking mode. This is because with
"Type=forking" in the mdmon service unit file, "systemctl start service"
will block until the main process of mdmon exits. At that moment, mdmon
has already created the socket, so the subsequent socket connect from
mdadm will succeed.

However, when mdmon runs in foreground mode (without "Type=forking" in
the service unit file), "systemctl start service" will return once the
mdmon process starts. This causes mdadm and mdmon to run in parallel,
which may lead to a socket connection failure since mdmon has not yet
initialized the socket when mdadm tries to connect. If the next
instruction/command is to access this device and try to  write to it, a
permission error will occur since mdmon has not yet set the array to RW
mode.

Signed-off-by: Shminderjit Singh <shminderjit.singh@oracle.com>
13 months agoCI: fix excluded files in checkpatch.conf
Kinga Stefaniuk [Tue, 25 Jun 2024 08:48:33 +0000 (10:48 +0200)] 
CI: fix excluded files in checkpatch.conf

--exclude flag in checkpatch.conf is configured to work on directories
only. When checkpatch.conf contains files, checkpatch scan is not started.
Remove file names and keep only directories which should be excluded.

Signed-off-by: Kinga Stefaniuk <kinga.stefaniuk@intel.com>
13 months agomdadm: Assemble.c fix coverity issues
Nigel Croxon [Tue, 25 Jun 2024 11:57:28 +0000 (07:57 -0400)] 
mdadm: Assemble.c fix coverity issues

Fixing the following coding errors the coverity tools found:

* Event dereference: Dereferencing "pre_exist", which is known to be "NULL".
* Event parameter_hidden: Declaration hides parameter "c".
* Event leaked_storage: Variable "pre_exist" going out of scope leaks the
  storage it points to.
* Event leaked_storage: Variable "avail" going out of scope leaks the
  storage it points to.

Signed-off-by: Nigel Croxon <ncroxon@redhat.com>
13 months agoRevert "mdadm: Fix socket connection failure when mdmon runs in foreground mode."
Mariusz Tkaczyk [Thu, 20 Jun 2024 13:22:50 +0000 (15:22 +0200)] 
Revert "mdadm: Fix socket connection failure when mdmon runs in foreground mode."

This reverts commit 66a54b266f6c579e5f37b6253820903a55c3346c.

connect_monitor() is called from ping_monitor() but this function is often
used as advice, without verification that mdmon is really working. This
produces hangs in many scenarios.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
13 months agomdadm/tests: judge foreign array in test cases
Xiao Ni [Fri, 14 Jun 2024 02:45:01 +0000 (10:45 +0800)] 
mdadm/tests: judge foreign array in test cases

It needs to use array name when judging if one array is foreign or not.
So calling is_raid_foreign in test cases which need it.

Fixes: 41706a915684 ('mdadm/tests: names_template enhance')
Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
13 months agoMakefile: Do not call gcc directly
Gwendal Grignou [Wed, 15 May 2024 21:30:59 +0000 (14:30 -0700)] 
Makefile: Do not call gcc directly

When mdadm is compiled with clang, direct gcc will fail.
Make sure to use $(CC) variable instead.

Note that Clang does not support --help=warnings,
--print-diagnostic-options should be used instead.
So with Clang, the compilation will go through, but the
extra warning flags will never be added.

Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
13 months agomdadm: Fix socket connection failure when mdmon runs in foreground mode.
Shminderjit Singh [Tue, 4 Jun 2024 07:46:03 +0000 (07:46 +0000)] 
mdadm: Fix socket connection failure when mdmon runs in foreground mode.

While creating an IMSM RAID, mdadm will wait for the mdmon main process
to finish if mdmon runs in forking mode. This is because with
"Type=forking" in the mdmon service unit file, "systemctl start service"
will block until the main process of mdmon exits. At that moment, mdmon
has already created the socket, so the subsequent socket connect from
mdadm will succeed.

However, when mdmon runs in foreground mode (without "Type=forking" in
the service unit file), "systemctl start service" will return once the
mdmon process starts. This causes mdadm and mdmon to run in parallel,
which may lead to a socket connection failure since mdmon has not yet
initialized the socket when mdadm tries to connect. If the next
instruction/command is to access this device and try to write to it, a
permission error will occur since mdmon has not yet set the array to RW
mode.

Signed-off-by: Shminderjit Singh <shminderjit.singh@oracle.com>
13 months agotest: pass flags to services
Mateusz Kusiak [Fri, 15 Mar 2024 20:03:09 +0000 (16:03 -0400)] 
test: pass flags to services

Commit 4c12714d1ca0 ("test: run tests on system level mdadm") removed
MDADM_NO_SYSTEMCTL flag from test suite. This causes imsm tests to fail
as mdadm no longer triggers mdmon and flags exists only within session.

Use systemd set/unset-environment to pass necessary flags.

Introduce colors to grab users attention to warnings and key messages.

Make test suite setup systemd environment.
Add setup/clean_systemd_env() functions.
Warn user about altering systemd environment.

Add colors to success/fail messages and warnings.

Signed-off-by: Mateusz Kusiak <mateusz.kusiak@intel.com>
13 months agomdadm: Block SIGCHLD processes before starting children
Logan Gunthorpe [Tue, 4 Jun 2024 16:38:37 +0000 (10:38 -0600)] 
mdadm: Block SIGCHLD processes before starting children

There is a small race condition noticed during code review, but
never actully hit in practice, with the write_zero feature.

If a write zeros fork finishes quickly before wait_for_zero_forks()
gets called, then the SIGCHLD will be delivered before the signalfd
is setup.

While this is only theoretical, fix this by blocking the SIGCHLD
signal before forking any children.

Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
13 months agomdadm: Fix hang race condition in wait_for_zero_forks()
Logan Gunthorpe [Tue, 4 Jun 2024 16:38:36 +0000 (10:38 -0600)] 
mdadm: Fix hang race condition in wait_for_zero_forks()

Running a create operation with --write-zeros can randomly hang
forever waiting for child processes. This happens roughly on in
ten runs with when running with small (20MB) loop devices.

The bug is caused by the fact that signals can be coallesced into
one if they are not read by signalfd quick enough. So if two children
finish at exactly the same time, only one SIGCHLD will be received
by the parent.

To fix this, wait on all processes with WNOHANG every time a SIGCHLD
is received and exit when all processes have been waited on.

Reported-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
13 months agoimsm: make freesize required to volume autolayout
Kinga Stefaniuk [Tue, 11 Jun 2024 05:58:49 +0000 (07:58 +0200)] 
imsm: make freesize required to volume autolayout

Autolayout_imsm() shall be executed when IMSM_NO_PLATFORM=1 is set.
It was fixed by listed commit, checking super->orom was removed, but
also checking freesize. Freesize is not set for operations on RAID
volume with no size update, that's why it is not required to have
this value and always run autolayout_imsm().
Fix it by making autolayout_imsm() dependent on freesize.

Fixes: 46f192 ("imsm: fix first volume autolayout with IMSM_NO_PLATFORM")
Signed-off-by: Kinga Stefaniuk <kinga.stefaniuk@intel.com>
14 months agoimsm: fix first volume autolayout with IMSM_NO_PLATFORM
Mariusz Tkaczyk [Thu, 23 May 2024 10:06:36 +0000 (12:06 +0200)] 
imsm: fix first volume autolayout with IMSM_NO_PLATFORM

Autolayout_imsm() is not executed if IMSM_NO_PLATFORM=1 is set.
This causes that first volume cannot be created. Disk for new volume are
never configured.

Fix it by making autolayout_imsm() independent from super->orom because
NULL there means that IMSM_NO_PLATFORM=1 is set. There are not platform
restrictions to create volume, we just analyze drives. It is safe.

Fixes: 6d4d9ab295de ("imsm: use same slot across container")
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
14 months agomdadm.h: provide basename if GLIBC is not avialable
Mariusz Tkaczyk [Tue, 21 May 2024 14:26:33 +0000 (16:26 +0200)] 
mdadm.h: provide basename if GLIBC is not avialable

If GNU basename is not avilable, define it. It is safer to use that
rather than include libgen.h with XPG basename() definition.

Fixes:#12

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
14 months agomdadm/tests: remove strace test
Xiao Ni [Tue, 28 May 2024 13:51:50 +0000 (21:51 +0800)] 
mdadm/tests: remove strace test

Some tests will fail if the test env doesn't have strace
commands. So remove the dependency.

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
14 months agomdadm/tests: 05r1-re-add-nosuper
Xiao Ni [Tue, 28 May 2024 13:51:49 +0000 (21:51 +0800)] 
mdadm/tests: 05r1-re-add-nosuper

Patch 50b100768a11('mdadm: deprecate bitmap custom file') needs to confirm when
creating raid device with bitmap file.

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
14 months agomdadm/tests: 04update-uuid
Xiao Ni [Tue, 28 May 2024 13:51:48 +0000 (21:51 +0800)] 
mdadm/tests: 04update-uuid

Patch 50b100768a11('mdadm: deprecate bitmap custom file') needs to confirm when
creating raid device with bitmap file.

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
14 months agomdadm/tests: bitmap cases enhance
Xiao Ni [Tue, 28 May 2024 13:51:47 +0000 (21:51 +0800)] 
mdadm/tests: bitmap cases enhance

It fails because bitmap dirty number is smaller than 400 sometimes. It's not
good to compare bitmap dirty bits with a number. It depends on the test
machine, it can flush soon before checking the number. So remove related codes.

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
14 months agomdadm/platform-intel: buffer overflow detected
Xiao Ni [Tue, 28 May 2024 08:44:39 +0000 (16:44 +0800)] 
mdadm/platform-intel: buffer overflow detected

mdadm -CR /dev/md0 -l1 -n2 /dev/nvme0n1 /dev/nvme2n1
*** buffer overflow detected ***: terminated
Aborted (core dumped)

It doesn't happen 100% and it depends on the building environment.
It can be fixed by replacing sprintf with snprintf.

Fixes: d835518b6b53 ('imsm: nvme multipath support')
Reported-by: Guang Wu <guazhang@redhat.com>
Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
14 months agomdadm/tests: disable selinux
Xiao Ni [Wed, 22 May 2024 08:50:56 +0000 (16:50 +0800)] 
mdadm/tests: disable selinux

Sometimes systemd service fails because selinux. Disable selinux
during testing now. We can enable it in future when having a better
method.

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
14 months agomdadm/tests: 07changelevelintr
Xiao Ni [Wed, 22 May 2024 08:50:55 +0000 (16:50 +0800)] 
mdadm/tests: 07changelevelintr

It needs to specify a 2 powered array size when updating array size.
If not, it can't change chunksize.

And sometimes it reports error reshape doesn't happen. In fact the
reshape has finished. It doesn't need to wait before checking
reshape action. Because check function waits itself.

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
14 months agomdadm/tests: 07autodetect.broken can be removed
Xiao Ni [Wed, 22 May 2024 08:50:54 +0000 (16:50 +0800)] 
mdadm/tests: 07autodetect.broken can be removed

07autodetect can run successfully without error in kernel 6.9.0-rc5.

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
14 months agomdadm/tests: 07autoassemble
Xiao Ni [Wed, 22 May 2024 08:50:53 +0000 (16:50 +0800)] 
mdadm/tests: 07autoassemble

This test is used to test stacked array auto assemble.

There are two different cases depends on if array is foreign or not.
If the array is foreign, the stacked array (md0 is on md1 and md2)
can't be assembled with name md0. Because udev rule will run when md1
and md2 are assembled and mdadm -I doesn't specify homehost. So it
will treat stacked array (md0) as foreign array and choose md127 as
the device node name (/dev/md127)

Add the case that stacked array is local.

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
14 months agomdadm/tests: 06name enhance
Xiao Ni [Wed, 22 May 2024 08:50:52 +0000 (16:50 +0800)] 
mdadm/tests: 06name enhance

It needs to check hostname in metadata name if one array is
local. Add the check in this case.

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
14 months agomdadm/tests: 05r5-internalbitmap
Xiao Ni [Wed, 22 May 2024 08:50:50 +0000 (16:50 +0800)] 
mdadm/tests: 05r5-internalbitmap

It's not right to compare bitmap bits with a number after io comes.
Because maybe those bits are already flused. Remove the related
tests.

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
14 months agotests/04update-metadata skip linear
Xiao Ni [Wed, 22 May 2024 08:50:49 +0000 (16:50 +0800)] 
tests/04update-metadata skip linear

Add one check that if kernel doesn't support linear/multipath, it can
skip linear/multipath testing.

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
14 months agomdadm/tests: remove 04r5swap.broken
Xiao Ni [Wed, 22 May 2024 08:50:48 +0000 (16:50 +0800)] 
mdadm/tests: remove 04r5swap.broken

04r5swap can run successfully with kernel 6.9.0-rc4

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
14 months agomdadm/tests: 03r5assemV1
Xiao Ni [Wed, 22 May 2024 08:50:47 +0000 (16:50 +0800)] 
mdadm/tests: 03r5assemV1

dcc22ae74a864 ('super1: remove support for name= in config') already
removes name= support. So remove related test codes in 03r5assemV1.

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
14 months agomdadm/tests: remove 03r5assem-failed
Xiao Ni [Wed, 22 May 2024 08:50:46 +0000 (16:50 +0800)] 
mdadm/tests: remove 03r5assem-failed

03r5assem can run successfully with kernel 6.9.0-rc4

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
14 months agomdadm/tests 03r0assem enhance
Xiao Ni [Wed, 22 May 2024 08:50:45 +0000 (16:50 +0800)] 
mdadm/tests 03r0assem enhance

dcc22ae74a864 ('super1: remove support for name= in config') already
removes name= support. So remove related test codes in 03r0assem.

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
14 months agomdadm/tests: 03assem-incr enhance
Xiao Ni [Wed, 22 May 2024 08:50:44 +0000 (16:50 +0800)] 
mdadm/tests: 03assem-incr enhance

It fails when hostname lenght > 32. Because the super1 metadata name
doesn't include hostname when hostname length > 32. Then mdadm thinks
the array is a foreign array if no device link is specified when
assembling the array. It chooses a minor number from 127.

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
14 months agomdadm/tests: names_template enhance
Xiao Ni [Wed, 22 May 2024 08:50:43 +0000 (16:50 +0800)] 
mdadm/tests: names_template enhance

For super1, if the length of hostname is >= 32, it doesn't add hostname
in metadata name. Fix this problem by checking the length of hostname.
Because other cases may use need to check this, so do the check in
do_setup.

And this patch adds a check if link /dev/md/name exists.

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
14 months agomdadm/tests: test don't fail when systemd reports error
Xiao Ni [Wed, 22 May 2024 08:50:42 +0000 (16:50 +0800)] 
mdadm/tests: test don't fail when systemd reports error

Sometimes systemd reports error in dmesg and test fails. Add
a condition to avoid this failure.

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
14 months agomdadm/tests: test enhance
Xiao Ni [Wed, 22 May 2024 08:50:41 +0000 (16:50 +0800)] 
mdadm/tests: test enhance

There are two changes.
First, if md module is not loaded, it gives error when reading
speed_limit_max. So read the value after loading md module which
is done in do_setup

Second, sometimes the test reports error sync action doesn't
happen. But dmesg shows sync action is done. So limit the sync
speed before test. It doesn't affect the test run time. Because
check wait sets the max speed before waiting sync action. And
recording speed_limit_max/min in do_setup.

Fixes: 4c12714d1ca0 ('test: run tests on system level mdadm')
Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
14 months agoDon't control reshape speed in daemon
Xiao Ni [Wed, 22 May 2024 08:50:40 +0000 (16:50 +0800)] 
Don't control reshape speed in daemon

It tries to set the max sync speed in reshape. This should be done by
administrators by control interfaces /proc/sys/dev/raid/speed_limit_max/min.

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
14 months agomdadm: Start update_opt from 0
Xiao Ni [Wed, 22 May 2024 08:50:39 +0000 (16:50 +0800)] 
mdadm: Start update_opt from 0

Before f2e8393bd722 ('Manage&Incremental: code refactor, string to enum'), it uses
NULL to represent it doesn't need to update. So init UOPT_UNDEFINED to 0. This
problem is found by test case 05r6tor0.

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
14 months agoChange some error messages to info level
Xiao Ni [Wed, 22 May 2024 08:50:38 +0000 (16:50 +0800)] 
Change some error messages to info level

These logs are not error logs. Change them to info level.

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
14 months agoMakefile: fix make -s detection
Valery Ushakov [Wed, 22 May 2024 14:07:38 +0000 (17:07 +0300)] 
Makefile: fix make -s detection

Only check the first word of MAKEFLAGS for 's', that's where all the
single letter options are collected.

MAKEFLAGS contains _all_ make flags, so if any command line argument
contains a letter 's', the silent test will be false positive.  Think
e.g. make 'DESTDIR=.../aports/main/mdadm/pkg/mdadm' install

14 months agomdadm: deprecate bitmap custom file
Mariusz Tkaczyk [Fri, 29 Mar 2024 14:21:54 +0000 (15:21 +0100)] 
mdadm: deprecate bitmap custom file

This option has been deprecated in kernel by Christoph in commit
0ae1c9d38426 ("md: deprecate bitmap file support"). Do the same in
mdadm.

With this change, user must acknowledge it, it is not
skippable. The implementation of custom bitmap file looks like it's
abandoned. It cannot be done by Incremental so it is not respected by
any udev based system and it seems to not be recorded by metadata.
User must assemble such volume manually.

Tests for bitmap custom file are removed because now they will not
pass because interaction with user is mandatory.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
14 months agomdadm: super-intel fix bad shift
Nigel Croxon [Wed, 22 May 2024 20:53:22 +0000 (16:53 -0400)] 
mdadm: super-intel fix bad shift

In the expression "1 << i", left shifting by more than 31 bits has undefined behavior.
The shift amount, "i", is as much as 63. The operand has type "int" (32 bits) and will
be shifted as an "int". The fix is to change to a 64 bit int.

Signed-off-by: Nigel Croxon <ncroxon@redhat.com>
14 months agomdadm: super-intel remove dead code
Nigel Croxon [Wed, 22 May 2024 20:05:25 +0000 (16:05 -0400)] 
mdadm: super-intel remove dead code

Execution cannot reach this statement: "while (devlist) { dv = de...".
Local variable "err" is assigned only once, to a constant value,
making it effectively constant throughout its scope.
Remove dead code.

Signed-off-by: Nigel Croxon <ncroxon@redhat.com>
14 months agosuper-intel: fix typo in error msg
Blazej Kucman [Wed, 22 May 2024 09:13:17 +0000 (11:13 +0200)] 
super-intel: fix typo in error msg

Fix typo in encryption policy error msg.

Signed-off-by: Blazej Kucman <blazej.kucman@intel.com>
14 months agoadd checking of return status on fstat calls
Nigel Croxon [Mon, 20 May 2024 13:36:50 +0000 (09:36 -0400)] 
add checking of return status on fstat calls

There are a few places we don't check the return status when
calling fstat for success. Clean up the calls by adding a
check before continuing.

Signed-off-by: Nigel Croxon <ncroxon@redhat.com>
14 months agomdadm: Fix compilation for 32-bit arch
Blazej Kucman [Wed, 15 May 2024 11:26:28 +0000 (13:26 +0200)] 
mdadm: Fix compilation for 32-bit arch

Casting void pointer to __u64 works for 64-bit arch but fails to compile
on 32-bit arch like i686.

Fail on i686 platform:
drive_encryption.c: In function ‘nvme_security_recv_ioctl’:
drive_encryption.c:236:25: error: cast from pointer to integer of
different size [-Werror=pointer-to-int-cast]
  236 |         nvme_cmd.addr = (__u64)response_buffer;
      |                         ^
drive_encryption.c: In function ‘nvme_identify_ioctl’:
drive_encryption.c:271:25: error: cast from pointer to integer of
different size [-Werror=pointer-to-int-cast]
  271 |         nvme_cmd.addr = (__u64)response_buffer;
      |                         ^
cc1: all warnings being treated as errors
make: *** [Makefile:211: drive_encryption.o] Error 1

This change adds cast void pointer to uintptr_t first to ensure that
proper pointer size is used for casting from pointer type. Then is safe to
cast it to __u64 because it is tracked as u_int, regardless it is 32-bit
or 64-bit arch.

Reported-by: Xiao Ni <xni@redhat.com>
Fixes: cc48406887b3 ("Add reading Opal NVMe encryption information")
Signed-off-by: Blazej Kucman <blazej.kucman@intel.com>
14 months agoCI: create review.yml file
Kinga Stefaniuk [Thu, 11 Apr 2024 08:37:39 +0000 (10:37 +0200)] 
CI: create review.yml file

Introduce review.yml used by GitHub actions. Add make probe, checkpatch
and hardening-check on every pull request.
Add dependabot.yml file which check for updates of actions used in this
repository. This option enables to automatically fill new PR with action
updated to the latest version.

Signed-off-by: Kinga Stefaniuk <kinga.stefaniuk@intel.com>
14 months agomdadm: Change main repository to Github
Mariusz Tkaczyk [Tue, 7 May 2024 15:35:09 +0000 (17:35 +0200)] 
mdadm: Change main repository to Github

Now github will be used for tracking mdadm, adjust README.md.
Daily routines will be automated on Github, there is not need to
decribe them.

Adjust release process, it must be published to both repositories.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
14 months agoWait for mdmon when it is stared via systemd
Kinga Stefaniuk [Tue, 7 May 2024 03:38:56 +0000 (05:38 +0200)] 
Wait for mdmon when it is stared via systemd

When mdmon is being started it may need few seconds to start.
For now, we didn't wait for it. Introduce wait_for_mdmon()
function, which waits up to 5 seconds for mdmon to start completely.

Signed-off-by: Kinga Stefaniuk <kinga.stefaniuk@intel.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
14 months agoutil.c: change devnm to const in mdmon functions
Kinga Stefaniuk [Tue, 7 May 2024 03:38:55 +0000 (05:38 +0200)] 
util.c: change devnm to const in mdmon functions

Devnm shall not be changed inside mdmon_running()
and mdmon_pid() functions, change this parameter to const.

Signed-off-by: Kinga Stefaniuk <kinga.stefaniuk@intel.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
14 months agotests/23rdev-lifetime: fix a typo
Yu Kuai [Thu, 9 May 2024 01:10:59 +0000 (09:10 +0800)] 
tests/23rdev-lifetime: fix a typo

"pill" was wrong, while it should be "kill", test will still pass while
test thread will not be cleaned up.

Signed-off-by: Yu Kuai <yukuai3@huawei.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
14 months agoMakefile: Move -pie to LDFLAGS
Fabrice Fontaine [Tue, 7 May 2024 17:32:16 +0000 (19:32 +0200)] 
Makefile: Move -pie to LDFLAGS

Move -pie from LDLIBS to LDFLAGS and make LDFLAGS configurable to allow
the user to drop it by setting their own LDFLAGS (e.g. PIE could be
enabled or disabled by the buildsystem such as buildroot).

Suggested-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
14 months agotests/01raid6integ.broken can be removed
Xiao Ni [Thu, 18 Apr 2024 10:23:21 +0000 (18:23 +0800)] 
tests/01raid6integ.broken can be removed

01raid6integ can be run successfully with kernel 6.9.0-rc3.
So remove 01raid6integ.broken.

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
14 months agotests/01r5integ.broken
Xiao Ni [Thu, 18 Apr 2024 10:23:20 +0000 (18:23 +0800)] 
tests/01r5integ.broken

01r5integ can be run successfully 152 times without error with
kernel 6.9.0-rc4 and mdadm - v4.3-51-g52bead95. So remove this
one broken case.

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
14 months agotests/01r5fail enhance
Xiao Ni [Thu, 18 Apr 2024 10:23:19 +0000 (18:23 +0800)] 
tests/01r5fail enhance

After removing dev0, the recovery starts because it already has a spare
disk. It's good to check recovery. But it's not right to check recovery
after adding dev3. Because the recovery may finish. It depends on the
recovery performance of the testing machine. If the recovery finishes,
it will fail. But dev3 is only added as a spare disk, we can't expect
there is a recovery happens.

So remove the codes about adding dev3.

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
15 months agoimsm: support RAID 10 with more than 4 drives
Mateusz Kusiak [Mon, 29 Apr 2024 13:07:20 +0000 (15:07 +0200)] 
imsm: support RAID 10 with more than 4 drives

VROC UEFI driver does not support RAID 10 with more than 4 drives.
Add user prompts if such layout is being created and for R0->R10
reshapes.

Refactor ask() function:
- simplify the code,
- remove dialog reattempts,
- do no pass '?' sign on function calls,
- highlight default option on output.

This patch completes adding support for R10D4+ to IMSM.

Signed-off-by: Mateusz Kusiak <mateusz.kusiak@intel.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
15 months agoimsm: simplify imsm_check_attributes()
Mateusz Kusiak [Mon, 29 Apr 2024 13:07:19 +0000 (15:07 +0200)] 
imsm: simplify imsm_check_attributes()

imsm_check_attributes() is too complex for that it really does.

Remove repeating code and simplify the function.
Fix function calls.

Signed-off-by: Mateusz Kusiak <mateusz.kusiak@intel.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
15 months agoimsm: define RAID_10 attribute
Mateusz Kusiak [Mon, 29 Apr 2024 13:07:18 +0000 (15:07 +0200)] 
imsm: define RAID_10 attribute

Add MPB_ATTRIB_RAID10_EXT attribute to support RAID 10
with more than 4 drives.

Allow more than 4 drives in imsm_orom_support_raid_disks_raid10().

This is one of last patches for introducing R10D4+ to imsm.
Only small adjustments in reshape behaviours are needed.

Signed-off-by: Mateusz Kusiak <mateusz.kusiak@intel.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
15 months agoimsm: bump minimal version
Mateusz Kusiak [Mon, 29 Apr 2024 13:07:17 +0000 (15:07 +0200)] 
imsm: bump minimal version

IMSM version 1.3 (called ATTRIBS) brought attributes used to define array
properties which require support in driver. The goal of this change was
to avoid changing version when adding new features.

For some reasons migration has never been completed and currently (after
10 years of implementing) IMSM can use older versions.

It is right time to finally switch it. There is no point in using old
versions, use 1.3.00 as minimal one.

Define JD_VERSION used by Windows driver.

Signed-off-by: Mateusz Kusiak <mateusz.kusiak@intel.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
15 months agoimsm: refactor RAID level handling
Mateusz Kusiak [Mon, 29 Apr 2024 13:07:16 +0000 (15:07 +0200)] 
imsm: refactor RAID level handling

Add imsm_level_ops struct for better handling and unifying raid level
support. Add helper methods and move "orom_has_raid[...]" methods from
header to source file.

RAID 1e is not supported under Linux, remove RAID 1e associated code.

Refactor imsm_analyze_change() and is_raid_level_supported().
Remove hardcoded check for 4 drives and make devNumChange a multiplier
for RAID 10.

Refactor printing supported raid levels.

Signed-off-by: Mateusz Kusiak <mateusz.kusiak@intel.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
15 months agoimsm: add support for literal RAID 10
Mateusz Kusiak [Mon, 29 Apr 2024 13:07:15 +0000 (15:07 +0200)] 
imsm: add support for literal RAID 10

As for now, IMSM supports only 4 drive RAID 1+0. This patch is first in
series to add support for literal RAID 10 (with more than 4 drives) to
imsm.

Allow setting RAID 10 as raid level for imsm arrays.

Add update_imsm_raid_level() to handle raid level updates. Set RAID10 as
default level for imsm R0 to R10 migrations. Replace magic numbers with
defined values for RAID level checks/assigns.

Signed-off-by: Mateusz Kusiak <mateusz.kusiak@intel.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
15 months agomdadm: use struct context in reshape_super()
Mateusz Kusiak [Mon, 29 Apr 2024 13:07:14 +0000 (15:07 +0200)] 
mdadm: use struct context in reshape_super()

reshape_super() takes too many arguments. Change passing params in
favor of single struct.

Add devname pointer and change direction members to struct shape
and use it for reshape_super().

Create reshape_array_size() and reshape_array_non_size() to handle
reshape_super() calls.

Signed-off-by: Mateusz Kusiak <mateusz.kusiak@intel.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
15 months agomdadm: pass struct context for external reshapes
Mateusz Kusiak [Mon, 29 Apr 2024 13:07:13 +0000 (15:07 +0200)] 
mdadm: pass struct context for external reshapes

This patch alters mutiple functions calls so the context is passed to
external reshape functions.

There are two main reasons behind it:
- reduces number of arguments passed and unifies them,
- imsm code will make use of context in incoming patches.

Signed-off-by: Mateusz Kusiak <mateusz.kusiak@intel.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
15 months agoCreate.c: fix uclibc build
Fabrice Fontaine [Fri, 12 Apr 2024 16:45:13 +0000 (18:45 +0200)] 
Create.c: fix uclibc build

Define FALLOC_FL_ZERO_RANGE if needed as FALLOC_FL_ZERO_RANGE is only
defined for aarch64 on uclibc-ng resulting in the following or1k build
failure since commit 577fd10486d8d1472a6b559066f344ac30a3a391:

Create.c: In function 'write_zeroes_fork':
Create.c:155:35: error: 'FALLOC_FL_ZERO_RANGE' undeclared (first use in this function)
  155 |                 if (fallocate(fd, FALLOC_FL_ZERO_RANGE | FALLOC_FL_KEEP_SIZE,
      |                                   ^~~~~~~~~~~~~~~~~~~~

Fixes:
 - http://autobuild.buildroot.org/results/0e04bcdb591ca5642053e1f7e31384f06581e989

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
15 months agomdadm: Add README.md
Mariusz Tkaczyk [Tue, 26 Mar 2024 12:21:12 +0000 (13:21 +0100)] 
mdadm: Add README.md

Describe supported metadata types, add step-by-step patch sending
instruction, mention minimally supported kernel version and licensing.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
15 months agomdadm: Add MAINTAINERS.md
Mariusz Tkaczyk [Tue, 26 Mar 2024 12:21:11 +0000 (13:21 +0100)] 
mdadm: Add MAINTAINERS.md

Describe rules maintainer should follow.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
15 months agomdadm: add CHANGELOG.md
Mariusz Tkaczyk [Tue, 26 Mar 2024 12:21:10 +0000 (13:21 +0100)] 
mdadm: add CHANGELOG.md

Bring changelog back to life. Remove ANNOUCEs. It will use markdown
format, to have one style. All releases are migrated to new
changelog. It was a exercise I have taken, to familiarize with the
mdadm history.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
16 months agoimsm: drive encryption policy implementation
Blazej Kucman [Fri, 22 Mar 2024 11:51:20 +0000 (12:51 +0100)] 
imsm: drive encryption policy implementation

IMSM cares about drive encryption state. It is not allowed to mix disks
with different encryption state within one md device. This policy will
verify that attempt to use disks with different encryption states will
fail. Verification is performed for devices NVMe/SATA Opal and SATA.

There is one exception, Opal SATA drives encryption is not checked when
ENCRYPTION_NO_VERIFY key with "sata_opal" value is set in conf, for this
reason such drives are treated as without encryption support.

Signed-off-by: Blazej Kucman <blazej.kucman@intel.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
16 months agoimsm: print disk encryption information
Blazej Kucman [Fri, 22 Mar 2024 11:51:19 +0000 (12:51 +0100)] 
imsm: print disk encryption information

Print SATA/NVMe disk encryption information in --detail-platform.
Encryption Ability and Status will be printed for each disk.

There is one exception, Opal SATA drives encryption is not checked when
ENCRYPTION_NO_VERIFY key with "sata_opal" value is set in conf, for this
reason such drives are treated as without encryption support.

To test this feature, drives SATA/NVMe with Opal support or SATA drives
with encryption support have to be used.

Example outputs of --detail-platform:

Non Opal, encryption enabled, SATA drive:
Port0 : /dev/sdc (CVPR050600G3120LGN)
        Encryption(Ability|Status): Other|Unlocked

NVMe drive without Opal support:
NVMe under VMD : /dev/nvme2n1 (PHLF737302GB1P0GGN)
        Encryption(Ability|Status): None|Unencrypted

Unencrypted SATA drive with OPAL support:

- default allow_tpm, we will get an error from mdadm:
          Port6 : /dev/sdi (CVTS4246015V180IGN)
mdadm: Detected SATA drive /dev/sdi with Trusted Computing support.
mdadm: Cannot verify encryption state. Requires libata.tpm_enabled=1.
mdadm: Failed to get drive encrytpion information.

-  default "allow_tpm" and config entry "ENCRYPTION_NO_VERIFY sata_opal":
Port6 : /dev/sdi (CVTS4246015V180IGN)
        Encryption(Ability|Status): None|Unencrypted

- added "libata.allow_tpm=1" to boot parameters(requires reboot),
the status will be read correctly:
Port6 : /dev/sdi (CVTS4246015V180IGN)
        Encryption(Ability|Status): SED|Unencrypted

Signed-off-by: Blazej Kucman <blazej.kucman@intel.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
16 months agoAdd key ENCRYPTION_NO_VERIFY to conf
Blazej Kucman [Fri, 22 Mar 2024 11:51:18 +0000 (12:51 +0100)] 
Add key ENCRYPTION_NO_VERIFY to conf

Add ENCRYPTION_NO_VERIFY config key and allow to disable checking
encryption status for given type of drives.

The key is introduced because of SATA Opal disks for which TPM commands
must be enabled in libata kernel module, (libata.allow_tpm=1), otherwise
it is impossible to verify encryption status. TPM commands are disabled by
default.

Currently the key only supports the "sata_opal" value, if necessary,
the functionality is ready to support more types of disks. This
functionality will be used in the next patches.

Signed-off-by: Blazej Kucman <blazej.kucman@intel.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>