summaryrefslogtreecommitdiffstats
AgeCommit message (Collapse)AuthorFilesLines
2023-05-08enable RAID for SATA under VMDHEADmasterKevin Friedberg3-13/+37
Detect when a SATA controller has been mapped under Intel Alderlake RST VMD, so that it can use the VMD controller's RAID capabilities. Create new device type SYS_DEV_SATA_VMD and list separate controller to prevent mixing with the NVMe SYS_DEV_VMD devices on the same VMD domain. Signed-off-by: Kevin Friedberg <kev.friedberg@gmail.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-05-08mdadm: numbered names verificationMariusz Tkaczyk4-17/+50
New functions added to remove literals and make the code reusable. Use parse_num() instead of is_numer(). Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-05-08mdadm: define is_devname_ignore()Mariusz Tkaczyk5-10/+20
Use function instead of direct checks across code. Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-05-08mdadm: define DEV_NUM_PREFMariusz Tkaczyk3-7/+15
Use define instead of inlines. Add _LEN define. Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-05-08mdadm: define DEV_MD_DIRMariusz Tkaczyk13-45/+54
It is used many times. Additionally define _LEN to avoid repeated strlen() calls when length is needed. Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-04-10Remove the config files in mdcheck_start|continue serviceXiao Ni2-4/+0
We set MDADM_CHECK_DURATION in the mdcheck_start|continue.service files. And mdcheck doesn't use any configs from the config file. So we can remove the dependencies. Signed-off-by: Xiao Ni <xni@redhat.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-04-10Bump minimum kernel version to 2.6.32Jes Sorensen5-45/+2
Summary: At this point it probably is reasonable to drop support for anything prior to 3.10. Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-04-10Fix some cases eyesore formattingJes Sorensen1-57/+60
Summary: No functional change .... just make it more readable. Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-04-10super1: fix truncation check for journal deviceHristo Venev1-2/+3
The journal device can be smaller than the component devices. Fixes: 171e9743881e ("super1: report truncated device") Signed-off-by: Hristo Venev <hristo@venev.name> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-04-10Fix null pointer for incremental in mdadmmiaoguanqin1-0/+3
when we excute mdadm --assemble, udev-md-raid-assembly.rules is triggered. Then we stop array, we found an coredump for mdadm --incremental.func stack are as follows: #0 enough (level=10, raid_disks=4, layout=258, clean=1, avail=avail@entry=0x0) at util.c:555 #1 0x0000562170c26965 in Incremental (devlist=<optimized out>, c=<optimized out>, st=0x5621729b6dc0) at Incremental.c:514 #2 0x0000562170bfb6ff in main (argc=<optimized out>, argv=<optimized out>) at mdadm.c:1762 func enough() use array avail,avail allocate space in func count_active, it may not alloc space, causing a coredump.We fix this coredump. Signed-off-by: Guanqin Miao <miaoguanqin@huawei.com> Signed-off-by: lixiaokeng <lixiaokeng@huawei.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-03-23Create: Fix checking for container in update_metadataMateusz Grzonka1-1/+1
The commit 8a4ce2c05386 ("Create: Factor out add_disks() helpers") introduced a regression that caused timeouts and udev failing to create links. Steps to reproduce the issue were as following: $ mdadm -CR imsm -e imsm -n4 /dev/nvme[0-3]n1 $ mdadm -CR vol -l5 -n4 /dev/nvme[0-3]n1 --assume-clean I found the check for container was wrong because negation was missing. Fixes: 8a4ce2c05386 ("Create: Factor out add_disks() helpers") Signed-off-by: Mateusz Grzonka <mateusz.grzonka@intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-03-23Revert "Revert "mdadm/systemd: remove KillMode=none from service file""Mariusz Tkaczyk1-1/+0
This reverts commit 28a083955c6f58f8e582734c8c82aff909a7d461. Resolved by commit 723d1df4946e ("mdmon: Improve switchroot interactions.") We are ready to drop it. Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-03-20Improvements for IMSM_NO_PLATFORM testing.NeilBrown5-6/+55
Factor out IMSM_NO_PLATFORM testing into a single function that caches the result. Allow mdmon to explicitly set the result to "1" so that we don't need the ENV var in the unit file Check if the kernel command line contains "mdadm.imsm.test=1" and in that case assert NO_PLATFORM. This simplifies testing in a virtual machine. Signed-off-by: NeilBrown <neilb@suse.de> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-03-19mdopen: always try create_named_array()NeilBrown1-0/+1
mdopen() will use create_named_array() to ask the kernel to create the given md array, but only if it is given a number or name. If it is NOT given a name and is required to choose one itself using find_free_devnm() it does NOT use create_named_array(). On kernels with CONFIG_BLOCK_LEGACY_AUTOLOAD not set, this can result in failure to assemble an array. This can particularly seen when the "name" of the array begins with a host name different to the name of the host running the command. So add the missing call to create_named_array(). Link: https://bugzilla.kernel.org/show_bug.cgi?id=217074 Signed-off-by: NeilBrown <neilb@suse.de> Acked-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-03-19mdmon: Improve switchroot interactions.NeilBrown6-9/+16
We need a new mdmon@mdfoo instance to run in the root filesystem after switch root, as /sys and /dev are removed from the initrd. systemd will not start a new unit with the same name running while the old unit is still active, and we want the two mdmon processes to overlap in time to avoid any risk of deadlock, which can happen when a write is attempted with no mdmon running. So we need a different unit name in the initrd than in the root. Apart from the name, everything else should be the same. This is easily achieved using a different instance name as the mdmon@.service unit file already supports multiple instances (for different arrays). So start "mdmon@mdfoo.service" from root, but "mdmon@initrd-mdfoo.service" from the initrd. udev can tell which circumstance is the case by looking for /etc/initrd-release. continue_from_systemd() is enhanced so that the "initrd-" prefix can be requested. Teach mdmon that a container name like "initrd/foo" should be treated just like "foo". Note that systemd passes the instance name "initrd-foo" as "initrd/foo". We don't need a similar mechanism at shutdown because dracut runs "mdmon --takeover --all" when appropriate. Signed-off-by: NeilBrown <neilb@suse.de> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-03-19mdmon: Remove need for KillMode=noneNeilBrown1-1/+6
mdmon needs to keep running during the switchroot out of (at boot) and then back into (at shutdown) the initrd. It runs until a new mdmon takes over. Killmode=none is used to achieve this, with the help of --offroot which sets argv[0][0] to '@' which systemd understands. This is needed because mdmon is currently run in system-mdmon.slice which conflicts with shutdown.target so without Killmode=none mdmon would get killed early in shutdown when system.mdmon.slice is removed. As described in systemd.service(5), this conflict with shutdown can be resolved by explicitly requesting system.slice, which is a natural counterpart to DefaultDependencies=no. So add that, and also add IgnoreOnIsolate=true to avoid another possible source of an early death. With these we no longer need KillMode=none which the systemd developers have marked as "deprecated". Signed-off-by: NeilBrown <neilb@suse.de> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-03-19mdmon: change systemd unit file to use --foregroundNeilBrown1-2/+1
There is no value in mdmon forking when it is running under systemd - systemd can still track it anyway. So add --foreground option, and remove "Type=forking". Signed-off-by: NeilBrown <neilb@suse.de> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-03-19mdmon: don't test both 'all' and 'container_name'.NeilBrown1-7/+4
If 'all' is not set, then container_name must be NULL, as nothing else can set it. So simplify the test to ignore container_name. This makes the purpose of the code more obvious. Signed-off-by: NeilBrown <neilb@suse.de> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-03-19Use existence of /etc/initrd-release to detect initrd.NeilBrown1-9/+1
Since v183, systemd has used the existence of /etc/initrd-release to detect if it is running in an initrd, rather than looking at the magic number of the root filesystem's device. It is time for mdadm to do the same. Signed-off-by: NeilBrown <neilb@suse.de> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-03-19Define alignof using _Alignof when using C11 or newerKhem Raj1-1/+11
WG14 N2350 made very clear that it is an UB having type definitions within "offsetof" [1]. This patch enhances the implementation of macro alignof_slot to use builtin "_Alignof" to avoid undefined behavior on when using std=c11 or newer clang 16+ has started to flag this [2] Fixes build when using -std >= gnu11 and using clang16+ Older compilers gcc < 4.9 or clang < 8 has buggy _Alignof even though it may support C11, exclude those compilers too [1] https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2350.htm [2] https://reviews.llvm.org/D133574 Upstream-Status: Pending Signed-off-by: Khem Raj <raj.khem@gmail.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-03-13manpage: Add --write-zeroes option to manpageLogan Gunthorpe1-1/+17
Document the new --write-zeroes option in the manpage. Signed-off-by: Logan Gunthorpe <logang@deltatee.com> Acked-by: Kinga Tanska <kinga.tanska@linux.intel.com> Reviewed-by: Xiao Ni <xni@redhat.com> Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com> Acked-by: Coly Li <colyli@suse.de> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-03-13tests/00raid5-zero: Introduce test to exercise --write-zeros.Logan Gunthorpe1-0/+12
Attempt to create a raid5 array with --write-zeros. If it is successful check the array to ensure it is in sync. If it is unsuccessful and an unsupported error is printed, skip the test. Signed-off-by: Logan Gunthorpe <logang@deltatee.com> Acked-by: Kinga Tanska <kinga.tanska@linux.intel.com> Reviewed-by: Xiao Ni <xni@redhat.com> Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com> Acked-by: Coly Li <colyli@suse.de> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-03-13mdadm: Add --write-zeros option for CreateLogan Gunthorpe4-2/+190
Add the --write-zeros option for Create which will send a write zeros request to all the disks before assembling the array. After zeroing the array, the disks will be in a known clean state and the initial sync may be skipped. Writing zeroes is best used when there is a hardware offload method to zero the data. But even still, zeroing can take several minutes on a large device. Because of this, all disks are zeroed in parallel using their own forked process and a message is printed to the user. The main process will proceed only after all the zeroing processes have completed successfully. Signed-off-by: Logan Gunthorpe <logang@deltatee.com> Acked-by: Kinga Tanska <kinga.tanska@linux.intel.com> Reviewed-by: Xiao Ni <xni@redhat.com> Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com> Acked-by: Coly Li <colyli@suse.de> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-03-13mdadm: Introduce pr_info()Logan Gunthorpe2-3/+6
Feedback was given to avoid informational pr_err() calls that print to stderr, even though that's done all through out the code. Using printf() directly doesn't maintain the same format (an "mdadm" prefix on every line. So introduce pr_info() which prints to stdout with the same format and use it for a couple informational pr_err() calls in Create(). Future work can make this call used in more cases. Signed-off-by: Logan Gunthorpe <logang@deltatee.com> Acked-by: Kinga Tanska <kinga.tanska@linux.intel.com> Reviewed-by: Xiao Ni <xni@redhat.com> Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com> Acked-by: Coly Li <colyli@suse.de> Acked-by: Paul Menzel <pmenzel@molgen.mpg.de> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-03-13Create: Factor out add_disks() helpersLogan Gunthorpe1-169/+213
The Create function is massive with a very large number of variables. Reading and understanding the function is almost impossible. To help with this, factor out the two pass loop that adds the disks to the array. This moves about 160 lines into three new helper functions and removes a bunch of local variables from the main Create function. The main new helper function add_disks() does the two pass loop and calls into add_disk_to_super() and update_metadata(). Factoring out the latter two helpers also helps to reduce a ton of indentation. No functional changes intended. Signed-off-by: Logan Gunthorpe <logang@deltatee.com> Acked-by: Kinga Tanska <kinga.tanska@linux.intel.com> Reviewed-by: Xiao Ni <xni@redhat.com> Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com> Acked-by: Coly Li <colyli@suse.de> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-03-13Create: remove safe_mode_delay local variableLogan Gunthorpe1-3/+1
All .getinfo_super() call sets the info.safe_mode_delay variables to a constant value, so no matter what the current state is that function will always set it to the same value. Create() calls .getinfo_super() multiple times while creating the array. The value is stored in a local variable for every disk in the loop to add disks (so the last disc call takes precedence). The local variable is then used in the call to sysfs_set_safemode(). This can be simplified by using info.safe_mode_delay directly. The info variable had .getinfo_super() called on it early in the function so, by the reasoning above, it will have the same value as the local variable which can thus be removed. Doing this allows for factoring out code from Create() in a subsequent patch. Signed-off-by: Logan Gunthorpe <logang@deltatee.com> Acked-by: Kinga Tanska <kinga.tanska@linux.intel.com> Reviewed-by: Xiao Ni <xni@redhat.com> Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com> Acked-by: Coly Li <colyli@suse.de> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-03-13Create: goto abort_locked instead of return 1 in error pathLogan Gunthorpe1-1/+1
The return 1 after the fstat_is_blkdev() check should be replaced with an error return that goes through the error path to unlock resources locked by this function. Signed-off-by: Logan Gunthorpe <logang@deltatee.com> Acked-by: Kinga Tanska <kinga.tanska@linux.intel.com> Reviewed-by: Xiao Ni <xni@redhat.com> Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com> Acked-by: Coly Li <colyli@suse.de> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-03-08super-ddf.c: fix memleak in get_vd_num_of_subarray()Wu Guanghao1-2/+7
sra = sysfs_read() should be free before return in get_vd_num_of_subarray() Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com> Acked-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> Acked-by: Coly Li <colyli@suse.de> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-03-08super-intel.c: fix memleak in find_disk_attached_hba()Wu Guanghao1-2/+2
If disk_path = diskfd_to_devpath(), we need free(disk_path) before return, otherwise there will be a memory leak Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com> Reviewed-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> Acked-by: Coly Li <colyli@suse.de> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-03-08isuper-intel.c: fix double free in load_imsm_mpb()Wu Guanghao1-0/+1
In load_imsm_mpb() there is potential double free issue on super->buf. The first location to free super->buf is from get_super_block() <== load_and_parse_mpb() <== load_imsm_mpb(): 4514 if (posix_memalign(&super->migr_rec_buf, MAX_SECTOR_SIZE, 4515 MIGR_REC_BUF_SECTORS*MAX_SECTOR_SIZE) != 0) { 4516 pr_err("could not allocate migr_rec buffer\n"); 4517 free(super->buf); 4518 return 2; 4519 } If the above error condition happens, super->buf is freed and value 2 is returned to get_super_block() eventually. Then in the following code block inside load_imsm_mpb(), 5289 error: 5290 if (!err) { 5291 s->next = *super_list; 5292 *super_list = s; 5293 } else { 5294 if (s) 5295 free_imsm(s); 5296 close_fd(&dfd); 5297 } at line 5295 when free_imsm() is called, super->buf is freed again from the call chain free_imsm() <== __free_imsm(), in following code block, 4651 if (super->buf) { 4652 free(super->buf); 4653 super->buf = NULL; 4654 } This patch sets super->buf as NULL after line 4517 in load_imsm_mpb() to avoid the potential double free(). (Coly Li helps to re-compose the commit log) Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com> Reviewed-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> Acked-by: Coly Li <colyli@suse.de> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-03-08Detail.c: fix memleak in Detail()Wu Guanghao1-0/+1
char *sysdev = xstrdup() but not free() in for loop, will cause memory leak Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com> Acked-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> Acked-by: Coly Li <colyli@suse.de> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-03-08util.c: fix memleak in parse_layout_faulty()Wu Guanghao1-0/+2
char *m is allocated by xstrdup but not free() before return, will cause a memory leak Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com> Acked-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> Acked-by: Coly Li <colyli@suse.de> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-03-08util.c: reorder code lines in parse_layout_faulty()Coly Li1-3/+6
Resort the code lines in parse_layout_faulty() to make it more comfortable, no logic change. Signed-off-by: Coly Li <colyli@suse.de> Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-03-02Mdmonitor: Refactor check_one_sharer() for better error handlingMateusz Grzonka1-27/+62
Also check if autorebuild.pid is a symlink, which we shouldn't accept. Signed-off-by: Mateusz Grzonka <mateusz.grzonka@intel.com> Acked-by: Coly Li <colyli@suse.de> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-03-02Mdmonitor: Refactor write_autorebuild_pid()Mateusz Grzonka1-19/+36
Add better error handling and check for symlinks when opening MDMON_DIR. Signed-off-by: Mateusz Grzonka <mateusz.grzonka@intel.com> Acked-by: Coly Li <colyli@suse.de> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-03-02Add helpers to determine whether directories or files are soft linksMateusz Grzonka2-0/+47
Signed-off-by: Mateusz Grzonka <mateusz.grzonka@intel.com> Acked-by: Coly Li <colyli@suse.de> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-03-02Mdmonitor: Add helper functionsMateusz Grzonka1-70/+158
Add functions: - is_email_event(), - get_syslog_event_priority(), - sprint_event_message(), with kernel style comments containing more detailed descriptions. Also update event syslog priorities to be consistent with man. MoveSpare event was described in man as priority info, while implemented as warning. Move event data into a struct, so that it is passed between different functions if needed. Sort function declarations alphabetically and remove redundant alert() declaration. Signed-off-by: Mateusz Grzonka <mateusz.grzonka@intel.com> Acked-by: Coly Li <colyli@suse.de> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-03-02Mdmonitor: Pass events to alert() using enums instead of stringsMateusz Grzonka1-53/+83
Add events enum, and mapping_t struct, that maps them to strings, so that enums are passed around instead of strings. Signed-off-by: Mateusz Grzonka <mateusz.grzonka@intel.com> Acked-by: Coly Li <colyli@suse.de> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-03-02Mdmonitor: Make alert_info globalMateusz Grzonka1-63/+61
Move information about --test flag and hostname into alert_info. Signed-off-by: Mateusz Grzonka <mateusz.grzonka@intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-02-28Fix NULL dereference in super_by_fdLi Xiao Keng2-1/+10
When we create 100 partitions (major is 259 not 254) in a raid device, mdadm may coredump: Core was generated by `/usr/sbin/mdadm --detail --export /dev/md1p7'. Program terminated with signal SIGSEGV, Segmentation fault. #0 __strlen_avx2_rtm () at ../sysdeps/x86_64/multiarch/strlen-avx2.S:74 74 VPCMPEQ (%rdi), %ymm0, %ymm1 (gdb) bt #0 __strlen_avx2_rtm () at ../sysdeps/x86_64/multiarch/strlen-avx2.S:74 #1 0x00007fbb9a7e4139 in __strcpy_chk (dest=dest@entry=0x55d55d6a13ac "", src=0x0, destlen=destlen@entry=32) at strcpy_chk.c:28 #2 0x000055d55ba1766d in strcpy (__src=<optimized out>, __dest=0x55d55d6a13ac "") at /usr/include/bits/string_fortified.h:79 #3 super_by_fd (fd=fd@entry=3, subarrayp=subarrayp@entry=0x7fff44dfcc48) at util.c:1289 #4 0x000055d55ba273a6 in Detail (dev=0x7fff44dfef0b "/dev/md1p7", c=0x7fff44dfe440) at Detail.c:101 #5 0x000055d55ba0de61 in misc_list (c=<optimized out>, ss=<optimized out>, dump_directory=<optimized out>, ident=<optimized out>, devlist=<optimized out>) at mdadm.c:1959 #6 main (argc=<optimized out>, argv=<optimized out>) at mdadm.c:1629 The direct cause is fd2devnm returning NULL, so add a check. Signed-off-by: Li Xiao Keng <lixiaokeng@huawei.com> Signed-off-by: Wu Guang Hao <wuguanghao3@huawei.com> Acked-by: Coly Li <colyli@suse.de> Acked-by: Coly Li <colyli@suse.de <mailto:colyli@suse.de>> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-02-23Grow: fix can't change bitmap type from none to clustered.Heming Zhao1-1/+1
Commit a042210648ed ("disallow create or grow clustered bitmap with writemostly set") introduced this bug. We should use 'true' logic not '== 0' to deny setting up clustered array under WRITEMOSTLY condition. How to trigger ``` ~/mdadm # ./mdadm -Ss && ./mdadm --zero-superblock /dev/sd{a,b} ~/mdadm # ./mdadm -C /dev/md0 -l mirror -b clustered -e 1.2 -n 2 \ /dev/sda /dev/sdb --assume-clean mdadm: array /dev/md0 started. ~/mdadm # ./mdadm --grow /dev/md0 --bitmap=none ~/mdadm # ./mdadm --grow /dev/md0 --bitmap=clustered mdadm: /dev/md0 disks marked write-mostly are not supported with clustered bitmap ``` Signed-off-by: Heming Zhao <heming.zhao@suse.com> Acked-by: Coly Li <colyli@suse.de> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-02-02Revert "mdadm/systemd: remove KillMode=none from service file"Mariusz Tkaczyk2-0/+2
This reverts commit 52c67fcdd6dadc4138ecad73e65599551804d445. The functionality is marked as deprecated but we don't have alternative solution yet. Shutdown hangs if OS is installed on external array: task:umount state:D stack: 0 pid: 6285 ppid: flags:0x00004084 Call Trace: __schedule+0x2d1/0x830 ? finish_wait+0x80/0x80 schedule+0x35/0xa0 md_write_start+0x14b/0x220 ? finish_wait+0x80/0x80 raid1_make_request+0x3c/0x90 [raid1] md_handle_request+0x128/0x1b0 md_make_request+0x5b/0xb0 generic_make_request_no_check+0x202/0x330 submit_bio+0x3c/0x160 Use it until new solution is implemented. Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-01-05manage: move comment with function descriptionKinga Tanska1-28/+44
Move the function description from the function body to outside to obey kernel coding style. Signed-off-by: Kinga Tanska <kinga.tanska@intel.com> Acked-by: Coly Li <colyli@suse.de> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-01-04super-intel: make freesize not required for chunk size migrationKinga Tanska1-5/+5
Freesize is needed to be set for migrations where size of RAID could be changed - expand. It tells how many free space is determined for members. In chunk size migartion freesize is not needed to be set, pointer shouldn't be checked if exists. This commit moves check to condition which contains size calculations, instead of checking it always at the first step. Fix return value when superblock is not set. Signed-off-by: Kinga Tanska <kinga.tanska@intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-01-04incremental, manage: do not verify if remove is safeKinga Tanska2-4/+5
Function is_remove_safe() was introduced to verify if removing member device won't cause failed state of the array. This verification should be used only with set-faulty command. Add special mode indicating that Incremental removal was executed. If this mode is used do not execute is_remove_safe() routine. Signed-off-by: Kinga Tanska <kinga.tanska@intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-01-04Manage: do not check array state when drive is removedKinga Tanska1-2/+1
Array state doesn't need to be checked when drive is removed, but until now clean state was required. Result of the is_remove_safe() function will be independent from array state. Signed-off-by: Kinga Tanska <kinga.tanska@intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-01-04mdadm/udev: Don't handle change event on raw devicesXiao Ni1-0/+8
The raw devices are ready when add event happpens and the raid can be assembled. So there is no need to handle change events. And it can cause some inconvenient problems. For example, the OS is installed on md0(/root) and md1(/home). md0 and md1 are created on partitions. When it wants to re-install OS, anaconda can't clear the storage configure. It deletes one partition and does some jobs. The change event happens. Now the raid device is assembled again. It can't delete the other partitions. So in this patch, we don't handle change event on raw devices anymore. Signed-off-by: Xiao Ni <xni@redhat.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-01-04util: remove obsolete code from get_md_nameMateusz Kusiak2-39/+20
get_md_name() is used only with mdstat entries. Remove dead code and simplyfy function. Remove redundadnt checks from mdmon.c Signed-off-by: Mateusz Kusiak <mateusz.kusiak@intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-01-04mdmon: fix segfaultMateusz Kusiak2-15/+13
Mdmon crashes if stat2devnm returns null. Use open_mddev to check if device is mddevice and get name using fd2devnm. Refactor container name handling. Signed-off-by: Mateusz Kusiak <mateusz.kusiak@intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-01-04Change char* to enum in context->update & refactor codeMateusz Kusiak3-57/+37
Storing update option in string is bad for frequent comparisons and error prone. Replace char array with enum so already existing enum is passed around instead of string. Adapt code to changes. Signed-off-by: Mateusz Kusiak <mateusz.kusiak@intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-01-04Manage&Incremental: code refactor, string to enumMateusz Kusiak5-33/+45
Prepare Manage and Incremental for later changing context->update to enum. Change update from string to enum in multiple functions and pass enum where already possible. Signed-off-by: Mateusz Kusiak <mateusz.kusiak@intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-01-04Change update to enum in update_super and update_subarrayMateusz Kusiak9-62/+52
Use already existing enum, change update_super and update_subarray update to enum globally. Refactor function references also. Remove code specific options from update_options. Signed-off-by: Mateusz Kusiak <mateusz.kusiak@intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-01-04super-intel: refactor the code for enumMateusz Kusiak1-12/+25
It prepares super-intel for change context->update to enum. Signed-off-by: Mateusz Kusiak <mateusz.kusiak@intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-01-04super1: refactor the code for enumMateusz Kusiak1-61/+91
It prepares update_super1 for change context->update to enum. Change if else statements into switch. Signed-off-by: Mateusz Kusiak <mateusz.kusiak@intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-01-04super0: refactor the code for enumMateusz Kusiak1-39/+63
It prepares update_super0 for change context->update to enum. Change if else statements to switch. Signed-off-by: Mateusz Kusiak <mateusz.kusiak@intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-01-04super-ddf: Remove update_super_ddf.Mateusz Kusiak1-70/+0
This is not supported by ddf. It hides errors by returning success status for some updates. Remove update_super_dff(). Signed-off-by: Mateusz Kusiak <mateusz.kusiak@intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-01-04Add code specific update options to enum.Mateusz Kusiak2-0/+36
Some of update options aren't taken from user input, but are hard-coded as strings. Include those options in enum. Signed-off-by: Mateusz Kusiak <mateusz.kusiak@intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-01-04Fix --update-subarray on active volumeMateusz Kusiak2-5/+7
Options: bitmap, ppl and name should not be updated when array is active. Those features are mutually exclusive and share the same data area in IMSM (danger of overwriting by kernel). Remove check for active subarrays from super-intel. Since ddf is not supported, apply it globally for all options. Signed-off-by: Mateusz Kusiak <mateusz.kusiak@intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2023-01-04mdadm: Add option validation for --update-subarrayMateusz Kusiak4-74/+124
Subset of options available for "--update" is not same as for "--update-subarray". Define maps and enum for update options and use them instead of direct comparisons. Add proper error message. Signed-off-by: Mateusz Kusiak <mateusz.kusiak@intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2022-12-28mdadm: create ident_init()Mariusz Tkaczyk3-32/+36
Add a wrapper for repeated initializations in mdadm.c and config.c. Move includes up. Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2022-12-28Grow: fix possible memory leak.Blazej Kucman1-1/+4
Signed-off-by: Blazej Kucman <blazej.kucman@intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2022-12-28Update mdadm Monitor manual.Blazej Kucman1-21/+50
- describe monitor work modes, - clarify the turning off condition, - describe the mdmonitor.service as a prefered management way. Signed-off-by: Blazej Kucman <blazej.kucman@intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2022-12-28Monitor: block if monitor modes are combined.Blazej Kucman1-1/+6
Block monitoring start if --scan mode and MD devices list are combined. Signed-off-by: Blazej Kucman <blazej.kucman@intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2022-12-28Mdmonitor: Split alert() into separate functionsMateusz Grzonka1-91/+95
Signed-off-by: Mateusz Grzonka <mateusz.grzonka@intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2022-09-29Mdmonitor: Omit non-md devicesLukasz Florczak1-8/+4
Fix segfault commit [1] introduced check whether given device is mddevice, but it happend to terminate Mdmonitor if at least one of given devices didn't fulfill that condition. In result Mdmonitor service was no longer started on boot (with --scan option) when config contained some non-existent array entry. This commit introduces ommiting non-md devices so scan option can still be used when config is wrong and allow Mdmonitor service to run on boot. Giving a list of devices to monitor containing non-existing or non-md devices will result in monitoring only confirmed mddevices. [1] https://git.kernel.org/pub/scm/utils/mdadm/mdadm.git/commit/?id=e702f392959d1c2ad2089e595b52235ed97b4e18 Signed-off-by: Lukasz Florczak <lukasz.florczak@linux.intel.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2022-09-29mdadm: replace container level checking with inlineKinga Tanska10-20/+33
To unify all containers checks in code, is_container() function is added and propagated. Signed-off-by: Kinga Tanska <kinga.tanska@intel.com> Acked-by: Coly Li <colyli@suse.de> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2022-09-16ReadMe: fix command-line helpMariusz Tkaczyk1-1/+1
Make command-line help consistent with manual page. Copied from Debian. Cc: Felix Lechner <felix.lechner@lease-up.com> Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> Acked-by: Coly Li <colyli@suse.de> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2022-09-16mdadm: Add Documentation entries to systemd servicesMariusz Tkaczyk7-1/+8
Add documentation section. Copied from Debian. Cc: Felix Lechner <felix.lechner@lease-up.com> Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> Acked-by: Coly Li <colyli@suse.de> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2022-09-14mdadm: added support for Intel Alderlake RST on VMD platformOldřich Jedlička1-5/+13
Alderlake RST on VMD uses RstVmdV UEFI variable name, so detect it. Signed-off-by: Oldřich Jedlička <oldium.pro@gmail.com> Reviewed-by: Kinga Tanska <kinga.tanska@linux.intel.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2022-09-08Monitor: Fix statelist memory leaksPawel Baldysiak1-9/+31
Free statelist in error path in Monitor initialization. Signed-off-by: Pawel Baldysiak <pawel.baldysiak@intel.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2022-09-08Manage: Block unsafe member failingMateusz Kusiak1-1/+52
Kernel may or may not block mdadm from removing member device if it will cause arrays failed state. It depends on raid personality implementation in kernel. Add verification on requested removal path (#mdadm --set-faulty command). Signed-off-by: Mateusz Kusiak <mateusz.kusiak@intel.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2022-09-08mdadm: Correct typos, punctuation and grammar in manMateusz Grzonka1-90/+88
Signed-off-by: Mateusz Grzonka <mateusz.grzonka@intel.com> Reviewed-by: Wol <anthony@youngman.org.uk> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2022-08-29super1: report truncated deviceNeilBrown1-7/+28
When the metadata is at the start of the device, it is possible that it describes a device large than the one it is actually stored on. When this happens, report it loudly in --examine. .... Unused Space : before=1968 sectors, after=-2047 sectors DEVICE TOO SMALL State : clean TRUNCATED DEVICE .... Also report in --assemble so that the failure which the kernel will report will be explained. mdadm: Device /dev/sdb is not large enough for data described in superblock mdadm: no RAID superblock on /dev/sdb mdadm: /dev/sdb has no superblock - assembly aborted Scenario can be demonstrated as follows: mdadm: Note: this array has metadata at the start and may not be suitable as a boot device. If you plan to store '/boot' on this device please ensure that your boot-loader understands md/v1.x metadata, or use --metadata=0.90 mdadm: Defaulting to version 1.2 metadata mdadm: array /dev/md/test started. mdadm: stopped /dev/md/test Unused Space : before=1968 sectors, after=-2047 sectors DEVICE TOO SMALL State : clean TRUNCATED DEVICE Unused Space : before=1968 sectors, after=-2047 sectors DEVICE TOO SMALL State : clean TRUNCATED DEVICE Signed-off-by: NeilBrown <neilb@suse.de> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2022-08-24Assemble: check if device is container before scheduling force-clean updateKinga Tanska1-3/+2
Up to now using assemble with force flag making each array as clean. Force-clean should not be done for the container. This commit add check if device is different than container before cleaning. Signed-off-by: Kinga Tanska <kinga.tanska@intel.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2022-08-24Grow: Split Grow_reshape into helper functionMateusz Kusiak3-59/+81
Grow_reshape should be split into helper functions given its size. - Add helper function for preparing reshape on external metadata. - Close cfd file descriptor. Signed-off-by: Mateusz Kusiak <mateusz.kusiak@intel.com> Acked-by: Coly Li <colyli@suse.de> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2022-08-23mdadm: Don't open md device for CREATE and ASSEMBLELogan Gunthorpe3-20/+33
The mdadm command tries to open the md device for most modes, first thing, no matter what. When running to create or assemble an array, in most cases, the md device will not exist, the open call will fail and everything will proceed correctly. However, when running tests, a create or assembly command may be run shortly after stopping an array and the old md device file may still be around. Then, if create_on_open is set in the kernel, a new md device will be created when mdadm does its initial open. When mdadm gets around to creating the new device with the new_array parameter it issues this error: mdadm: Fail to create md0 when using /sys/module/md_mod/parameters/new_array, fallback to creation via node This is because an mddev was already created by the kernel with the earlier open() call and thus the new one being created will fail with EEXIST. The mdadm command will still successfully be created due to falling back to the node creation method. However, the error message itself will fail any test that's running it. This issue is a race condition that is very rare, but a recent change in the kernel caused this to happen more frequently: about 1 in 50 times. To fix this, don't bother trying to open the md device for CREATE, ASSEMBLE and BUILD commands, as the file descriptor will never be used anyway even if it is successfully openned. The mdfd has not been used for these commands since: 7f91af49ad09 ("Delay creation of array devices for assemble/build/create") The checks that were done on the open device can be changed to being done with stat. Side note: it would be nice to disable create_on_open as well to help solve this, but it seems the work for this was never finished. By default, mdadm will create using the old node interface when a name is specified unless the user specifically puts names=yes in a config file, which doesn't seem to be common or desirable to require this.. Signed-off-by: Logan Gunthorpe <logang@deltatee.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2022-08-23mdadm: move data_offset to struct shapeMariusz Tkaczyk4-26/+22
Data offset is a shape property so move it there to remove additional parameter from some functions. Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2022-08-23mdadm: remove symlink optionMariusz Tkaczyk6-53/+1
The option is not used. Remove it from code. Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2022-08-23tests: add test for namesMariusz Tkaczyk1-0/+93
Current behavior is not documented and tested. This test is a base for future improvements. It is enough to test it only with native metadata, because it is generic code. Generated properties are passed to metadata handler. Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2022-08-23tests/00readonly: Run udevadm settle before setting roLogan Gunthorpe1-0/+1
In some recent kernel versions, 00readonly fails with: mdadm: failed to set readonly for /dev/md0: Device or resource busy ERROR: array is not read-only! This was traced down to a race condition with udev holding a reference to the block device at the same time as trying to set it read only. To fix this, call udevadm settle before setting the array read only. Signed-off-by: Logan Gunthorpe <logang@deltatee.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2022-08-22mdadm: Replace obsolete usleep with nanosleepMateusz Grzonka8-26/+54
According to POSIX.1-2001, usleep is considered obsolete. Replace it with a wrapper that uses nanosleep, as recommended in man. Add handy macros for conversions between msec, usec and nsec. Signed-off-by: Mateusz Grzonka <mateusz.grzonka@intel.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2022-08-07tests: Add broken files for all broken testsLogan Gunthorpe24-0/+226
Each broken file contains the rough frequency of brokeness as well as a brief explanation of what happens when it breaks. Estimates of failure rates are not statistically significant and can vary run to run. This is really just a view from my window. Tests were done on a small VM with the default loop devices, not real hardware. We've seen different kernel configurations can cause bugs to appear as well (ie. different block schedulers). It may also be that different race conditions will be seen on machines with different performance characteristics. These annotations were done with the kernel currently in md/md-next: facef3b96c5b ("md: Notify sysfs sync_completed in md_reap_sync_thread()") Signed-off-by: Logan Gunthorpe <logang@deltatee.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2022-08-07mdadm/test: Mark and ignore broken test failuresLogan Gunthorpe1-2/+35
Add functionality to continue if a test marked as broken fails. To mark a test as broken, a file with the same name but with the suffix '.broken' should exist. The first line in the file will be printed with a KNOWN BROKEN message; the rest of the file can describe the how the test is broken. Also adds --skip-broken and --skip-always-broken to skip all the tests that have a .broken file or to skip all tests whose .broken file's first line contains the keyword always. Signed-off-by: Logan Gunthorpe <logang@deltatee.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2022-08-07mdadm/test: Add a mode to repeat specified testsLogan Gunthorpe1-12/+24
Many tests fail infrequently or rarely. To help find these, add an option to run the tests multiple times by specifying --loop=N. If --loop=0 is specified, the test will be looped forever. Signed-off-by: Logan Gunthorpe <logang@deltatee.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2022-08-07tests/02lineargrow: clear the superblock at every iterationSudhakar Panneerselvam1-0/+2
This fixes 02lineargrow test as prior metadata causes --add operation to misbehave. Signed-off-by: Sudhakar Panneerselvam <sudhakar.panneerselvam@oracle.com> Signed-off-by: Himanshu Madhani <himanshu.madhani@oracle.com> Signed-off-by: Logan Gunthorpe <logang@deltatee.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2022-08-07tests/04update-metadata: avoid passing chunk size to raid1Sudhakar Panneerselvam1-1/+5
'04update-metadata' test fails with error, "specifying chunk size is forbidden for this level" added by commit, 5b30a34aa4b5e. Hence, correcting the test to ignore passing chunk size to raid1. Signed-off-by: Sudhakar Panneerselvam <sudhakar.panneerselvam@oracle.com> Signed-off-by: Himanshu Madhani <himanshu.madhani@oracle.com> [logang@deltatee.com: fix if/then style and dropped unrelated hunk] Signed-off-by: Logan Gunthorpe <logang@deltatee.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2022-08-07tests: fix raid0 tests for 0.90 metadataSudhakar Panneerselvam5-8/+12
Some of the test cases fail because raid0 creation fails with the error, "0.90 metadata does not support layouts for RAID0" added by commit, 329dfc28debb. Fix some of the test cases by switching from raid0 to linear level for 0.9 metadata where possible. Signed-off-by: Sudhakar Panneerselvam <sudhakar.panneerselvam@oracle.com> Signed-off-by: Himanshu Madhani <himanshu.madhani@oracle.com> Signed-off-by: Logan Gunthorpe <logang@deltatee.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2022-08-07tests/00raid0: add a test that validates raid0 with layout fails for 0.9Sudhakar Panneerselvam1-4/+2
329dfc28debb disallows the creation of raid0 with layouts for 0.9 metadata. This test confirms the new behavior. Signed-off-by: Sudhakar Panneerselvam <sudhakar.panneerselvam@oracle.com> Signed-off-by: Himanshu Madhani <himanshu.madhani@oracle.com> Signed-off-by: Logan Gunthorpe <logang@deltatee.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2022-08-07mdadm: Fix optional --write-behind parameterLogan Gunthorpe1-2/+3
The commit noted below changed the behaviour of --write-behind to require an argument. This broke the 06wrmostly test with the error: mdadm: Invalid value for maximum outstanding write-behind writes: (null). Must be between 0 and 16383. To fix this, check if optarg is NULL before parising it, as the origial code did. Fixes: 60815698c0ac ("Refactor parse_num and use it to parse optarg.") Cc: Mateusz Grzonka <mateusz.grzonka@intel.com> Signed-off-by: Logan Gunthorpe <logang@deltatee.com> Acked-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2022-08-07mdadm: Fix mdadm -r remove option regressionLogan Gunthorpe3-0/+3
The commit noted below globally adds a parameter to the -r option but missed the fact that -r is used for another purpose: --remove. After that commit, a command such as: mdadm /dev/md0 -r /dev/loop0 will do nothing seeing the device parameter will be consumed as a argument to the -r option; thus, there will only be one device seen one the command line, devs_found will only be 1 and nothing will happen. This caused the 01r5integ and 01raid6integ tests to hang indefinitely as mdadm did not remove the failed device. With the device not removed, it would not be readded. Then the loop waiting for the array status to change would loop forever. This commit was recently reverted, but the legitimate fix for the monitor operations was still not fixed. So add specific monitor short ops to re-fix the --monitor -r option. Fixes: 546047688e1c ("mdadm: fix coredump of mdadm --monitor -r") Fixes: 190dc029b141 ("Revert "mdadm: fix coredump of mdadm --monitor -r"") Cc: Wu Guanghao <wuguanghao3@huawei.com> Cc: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> Signed-off-by: Logan Gunthorpe <logang@deltatee.com> Acked-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2022-08-07monitor: Avoid segfault when calling NULL get_bad_blocksLogan Gunthorpe1-0/+3
Not all struct superswitch implement a get_bad_blocks() function, yet mdmon seems to call it without checking for NULL and thus occasionally segfaults in the test 10ddf-geometry. Fix this by checking for NULL before calling it. Signed-off-by: Logan Gunthorpe <logang@deltatee.com> Acked-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2022-08-07mdadm/Grow: Fix use after close bug by closing after forkLogan Gunthorpe1-1/+3
The test 07reshape-grow fails most of the time. But it succeeds around 1 in 5 times. When it does succeed, it causes the tests to die because mdadm has segfaulted. The segfault was caused by mdadm attempting to repoen a file descriptor that was already closed. The backtrace of the segfault was: #0 __strncmp_avx2 () at ../sysdeps/x86_64/multiarch/strcmp-avx2.S:101 #1 0x000056146e31d44b in devnm2devid (devnm=0x0) at util.c:956 #2 0x000056146e31dab4 in open_dev_flags (devnm=0x0, flags=0) at util.c:1072 #3 0x000056146e31db22 in open_dev (devnm=0x0) at util.c:1079 #4 0x000056146e3202e8 in reopen_mddev (mdfd=4) at util.c:2244 #5 0x000056146e329f36 in start_array (mdfd=4, mddev=0x7ffc55342450 "/dev/md0", content=0x7ffc55342860, st=0x56146fc78660, ident=0x7ffc55342f70, best=0x56146fc6f5d0, bestcnt=10, chosen_drive=0, devices=0x56146fc706b0, okcnt=5, sparecnt=0, rebuilding_cnt=0, journalcnt=0, c=0x7ffc55342e90, clean=1, avail=0x56146fc78720 "\001\001\001\001\001", start_partial_ok=0, err_ok=0, was_forced=0) at Assemble.c:1206 #6 0x000056146e32c36e in Assemble (st=0x56146fc78660, mddev=0x7ffc55342450 "/dev/md0", ident=0x7ffc55342f70, devlist=0x56146fc6e2d0, c=0x7ffc55342e90) at Assemble.c:1914 #7 0x000056146e312ac9 in main (argc=11, argv=0x7ffc55343238) at mdadm.c:1510 The file descriptor was closed early in Grow_continue(). The noted commit moved the close() call to close the fd above the fork which caused the parent process to return with a closed fd. This meant reshape_array() and Grow_continue() would return in the parent with the fd forked. The fd would eventually be passed to reopen_mddev() which returned an unhandled NULL from fd2devnm() which would then be dereferenced in devnm2devid. Fix this by moving the close() call below the fork. This appears to fix the 07revert-grow test. While we're at it, switch to using close_fd() to invalidate the file descriptor. Fixes: 77b72fa82813 ("mdadm/Grow: prevent md's fd from being occupied during delayed time") Cc: Alex Wu <alexwu@synology.com> Cc: BingJing Chang <bingjingc@synology.com> Cc: Danny Shih <dannyshih@synology.com> Cc: ChangSyun Peng <allenpeng@synology.com> Signed-off-by: Logan Gunthorpe <logang@deltatee.com> Acked-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2022-08-07DDF: Fix NULL pointer dereference in validate_geometry_ddf()Logan Gunthorpe1-3/+3
A relatively recent patch added a call to validate_geometry() in Manage_add() that has level=LEVEL_CONTAINER and chunk=NULL. This causes some ddf tests to segfault which aborts the test suite. To fix this, avoid dereferencing chunk when the level is LEVEL_CONTAINER or LEVEL_NONE. Fixes: 1f5d54a06df0 ("Manage: Call validate_geometry when adding drive to external container") Signed-off-by: Logan Gunthorpe <logang@deltatee.com> Acked-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2022-08-07DDF: Cleanup validate_geometry_ddf_container()Logan Gunthorpe1-49/+39
Move the function up so that the function declaration is not necessary and remove the unused arguments to the function. No functional changes are intended but will help with a bug fix in the next patch. Signed-off-by: Logan Gunthorpe <logang@deltatee.com> Acked-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2022-08-07Makefile: Don't build static build with everything and everything-testLogan Gunthorpe1-2/+2
Running the test suite requires building everything, but it seems to be difficult to build the static version of mdadm now seeing there is no readily available static udev library. The test suite doesn't need the static binary so just don't build it with the everything or everything-test targets. Leave the mdadm.static and install-static targets in place in case someone still has a use case for the static binary. Signed-off-by: Logan Gunthorpe <logang@deltatee.com> Acked-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
2022-07-28Monitor: use snprintf to fill device nameKinga Tanska1-23/+14
Safe string functions are propagated in Monitor.c. Signed-off-by: Kinga Tanska <kinga.tanska@intel.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2022-07-28Monitor: use devname as char array instead of pointerKinga Tanska1-3/+5
Device name wasn't filled properly due to incorrect use of strcpy. Strcpy was used twice. Firstly to fill devname with "/dev/md/" and then to add chosen name. First strcpy result was overwritten by second one (as a result <device_name> instead of "/dev/md/<device_name>" was assigned). This commit changes this implementation to use snprintf and devname with fixed size. Signed-off-by: Kinga Tanska <kinga.tanska@intel.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2022-07-28mdadm: Remove dead code in imsm_fix_size_mismatchLukasz Florczak1-4/+0
imsm_create_metadata_update_for_size_change() that returns u_size value could return 0 in the past. As its behavior changed, and returned value is always the size of imsm_update_size_change structure, check for u_size is no longer needed. Signed-off-by: Lukasz Florczak <lukasz.florczak@linux.intel.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2022-07-28mdadm: Fix array size mismatch after growLukasz Florczak1-1/+1
imsm_fix_size_mismatch() is invoked to fix the problem, but it couldn't proceed due to migration check. This patch allows for intended behavior. Signed-off-by: Lukasz Florczak <lukasz.florczak@linux.intel.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2022-06-24mdadm: block update=ppl for non raid456 levelsLukasz Florczak6-12/+31
Option ppl should be used only for raid levels 4, 5 and 6. Cancel update for other levels. Applied globally for imsm and ddf format. Additionally introduce is_level456() helper function. Signed-off-by: Lukasz Florczak <lukasz.florczak@linux.intel.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2022-06-24imsm: block changing slots during creationMariusz Tkaczyk2-39/+22
If user specifies drives for array creation, then slot order across volumes is not preserved. Ideally, it should be checked in validate_geometry() but it is not possible in current implementation (order is determined later). Add verification in add_to_super_imsm_volume() and throw error if mismatch is detected. IMSM allows to use only same members within container. This is not hardware dependency but metadata limitation. Therefore, 09-imsm-overlap test is removed. Testing it is pointless. After this patch, creation in this scenario is blocked. Offset verification is covered in other tests. Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> Acked-by: Coly Li <colyli@suse.de> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2022-06-24imsm: use same slot across containerMariusz Tkaczyk1-61/+108
Autolayout relies on drives order on super->disks list, but it is not quaranted by readdir() in sysfs_read(). As a result drive could be put in different slot in second volume. Make it consistent by reffering to first volume, if exists. Use enum imsm_status to unify error handling. Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> Acked-by: Coly Li <colyli@suse.de> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2022-06-24imsm: introduce get_disk_slot_in_dev()Mariusz Tkaczyk1-11/+36
The routine was added to remove unnecessary get_imsm_dev() and get_imsm_map() calls, used only to determine disk slot. Additionally, enum for IMSM return statues was added for further usage. Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> Acked-by: Coly Li <colyli@suse.de> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2022-06-24mdadm/super1: restore commit 45a87c2f31335 to fix clustered slot issueHeming Zhao1-1/+11
Commit 9d67f6496c71 ("mdadm:check the nodes when operate clustered array") modified assignment logic for st->nodes in write_bitmap1(), which introduced bitmap slot issue: load_super1 didn't set up supertype.nodes, which made spare disk only have one slot info. Then it triggered kernel md_bitmap_load_sb to get wrong bitmap slot data. For fixing this issue, there are two methods: 1> revert the related code of commit 9d67f6496c71. and restore the code from former commit 45a87c2f31335 ("super1: add more checks for NodeNumUpdate option"). st->nodes value would be 0 & 1 under current code logic. i.e. When adding a spare disk, there is no place to init st->nodes, and the value is ZERO. 2> keep 9d67f6496c71, add additional ->nodes handling in load_super1(), let load_super1 to set st->nodes when bitmap is BITMAP_MAJOR_CLUSTERED. Under current mdadm code logic, load_super1 will be called many times, any new code in load_super1 will cost mdadm running more time. And more reason is I prefer as much as possible to limit clustered code spreading in every corner. So I used method <1> to fix this issue. How to trigger: dd if=/dev/zero bs=1M count=1 oflag=direct of=/dev/sda dd if=/dev/zero bs=1M count=1 oflag=direct of=/dev/sdb dd if=/dev/zero bs=1M count=1 oflag=direct of=/dev/sdc mdadm -C /dev/md0 -b clustered -e 1.2 -n 2 -l mirror /dev/sda /dev/sdb mdadm -a /dev/md0 /dev/sdc mdadm /dev/md0 --fail /dev/sda mdadm /dev/md0 --remove /dev/sda mdadm -Ss mdadm -A /dev/md0 /dev/sdb /dev/sdc the output of current "mdadm -X /dev/sdc": (there should be (by default) 4 slot info for correct output) ``` Filename : /dev/sdc Magic : 6d746962 Version : 5 UUID : a74642f8:a6b1fba8:58e1f8db:cfe7b082 Events : 29 Events Cleared : 0 State : OK Chunksize : 64 MB Daemon : 5s flush period Write Mode : Normal Sync Size : 306176 (299.00 MiB 313.52 MB) Bitmap : 5 bits (chunks), 5 dirty (100.0%) ``` And mdadm later operations will trigger kernel output error message: (triggered by "mdadm -A /dev/md0 /dev/sdb /dev/sdc") ``` kernel: md0: invalid bitmap file superblock: bad magic kernel: md_bitmap_copy_from_slot can't get bitmap from slot 1 kernel: md-cluster: Could not gather bitmaps from slot 1 kernel: md0: invalid bitmap file superblock: bad magic kernel: md_bitmap_copy_from_slot can't get bitmap from slot 2 kernel: md-cluster: Could not gather bitmaps from slot 2 kernel: md0: invalid bitmap file superblock: bad magic kernel: md_bitmap_copy_from_slot can't get bitmap from slot 3 kernel: md-cluster: Could not gather bitmaps from slot 3 kernel: md-cluster: failed to gather all resyn infos kernel: md0: detected capacity change from 0 to 612352 ``` Acked-by: Coly Li <colyli@suse.de> Signed-off-by: Heming Zhao <heming.zhao@suse.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2022-06-24util: replace ioctl use with functionKinga Tanska1-1/+1
Replace using of ioctl calling to get md array info with special function prepared to it. Signed-off-by: Kinga Tanska <kinga.tanska@intel.com> Acked-by: Coly Li <colyli@suse.de> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2022-06-17Revert "mdadm: fix coredump of mdadm --monitor -r"Nigel Croxon1-3/+3
This reverts commit 546047688e1c64638f462147c755b58119cabdc8. The change from commit mdadm: fix coredump of mdadm --monitor -r broke the printing of the return message when passing -r to mdadm --manage, the removal of a device from an array. If the current code reverts this commit, both issues are still fixed. The original problem reported that the fix tried to address was: The --monitor -r option requires a parameter, otherwise a null pointer will be manipulated when converting to integer data, and a core dump will appear. The original problem was really fixed with: 60815698c0a Refactor parse_num and use it to parse optarg. Which added a check for NULL in 'optarg' before moving it to the 'increments' variable. New issue: When trying to remove a device using the short argument -r, instead of the long argument --remove, the output is empty. The problem started when commit 546047688e1c was added. Steps to Reproduce: 1. create/assemble /dev/md0 device 2. mdadm --manage /dev/md0 -r /dev/vdxx Actual results: Nothing, empty output, nothing happens, the device is still connected to the array. The output should have stated "mdadm: hot remove failed for /dev/vdxx: Device or resource busy", if the device was still active. Or it should remove the device and print a message: mdadm: set /dev/vdd faulty in /dev/md0 mdadm: hot removed /dev/vdd from /dev/md0 The following commit should be reverted as it breaks mdadm --manage -r. commit 546047688e1c64638f462147c755b58119cabdc8 Author: Wu Guanghao <wuguanghao3@huawei.com> Date: Mon Aug 16 15:24:51 2021 +0800 mdadm: fix coredump of mdadm --monitor -r -Nigel Signed-off-by: Nigel Croxon <ncroxon@redhat.com> Acked-by: Coly Li <colyli@suse.de> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2022-06-14imsm: Remove possibility for get_imsm_dev to return NULLMateusz Grzonka1-75/+78
Returning NULL from get_imsm_dev or __get_imsm_dev will cause segfault. Guarantee that it never happens. Signed-off-by: Mateusz Grzonka <mateusz.grzonka@intel.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2022-06-14Fix possible NULL ptr dereferences and memory leaksMateusz Grzonka2-3/+13
In Assemble there was a NULL check for sra variable, which effectively didn't stop the execution in every case. That might have resulted in a NULL pointer dereference. Also in super-ddf, mu variable was set to NULL for some condition, and then immidiately dereferenced. Additionally some memory wasn't freed as well. Signed-off-by: Mateusz Grzonka <mateusz.grzonka@intel.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2022-06-14Mdmonitor: Improve logging methodKinga Tanska1-11/+14
Change logging, and as a result, mdmonitor in verbose mode will report its configuration. Signed-off-by: Kinga Tanska <kinga.tanska@intel.com> Signed-off-by: Oleksandr Shchirskyi <oleksandr.shchirskyi@intel.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2022-06-14Mdmonitor: Fix segfaultKinga Tanska3-1/+27
Mdadm with "--monitor" parameter requires md device as an argument to be monitored. If given argument is not a md device, error shall be returned. Previously it was not checked and invalid argument caused segmentation fault. This commit adds checking that devices passed to mdmonitor are md devices. Signed-off-by: Kinga Tanska <kinga.tanska@intel.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2022-06-14Incremental: Fix possible memory and resource leaksMateusz Grzonka1-9/+23
map allocated through map_by_uuid() is not freed if mdfd is invalid. In addition mdfd is not closed, and mdinfo list is not freed too. Signed-off-by: Mateusz Grzonka <mateusz.grzonka@intel.com> Change-Id: I25e726f0e2502cf7e8ce80c2bd7944b3b1e2b9dc Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2022-06-09Grow: block -n on external volumes.Mateusz Kusiak1-0/+8
Performing --raid-devices on external metadata volume should be blocked as it causes unwanted behaviour. Eg. Performing mdadm -G /dev/md/volume -l10 -n4 on r0_d2 inside 4 disk container, returns mdadm: Need 2 spares to avoid degraded array, only have 0. Signed-off-by: Mateusz Kusiak <mateusz.kusiak@intel.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2022-06-09mdmon: Stop parsing duplicate optionsLukasz Florczak1-9/+35
Introduce new function is_duplicate_opt() to check if given option was already used and prevent setting it again along with an error message. Move parsing above in_initrd() check to be able to detect --offroot option duplicates. Now help option is executed after parsing to prevent executing commands like: 'mdmon --help --ndlksnlksajndfjksndafasj'. Signed-off-by: Lukasz Florczak <lukasz.florczak@linux.intel.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2022-04-06mdadm/systemd: remove KillMode=none from service fileColy Li2-2/+0
For mdadm's systemd configuration, current systemd KillMode is "none" in following service files, - mdadm-grow-continue@.service - mdmon@.service This "none" mode is strongly againsted by systemd developers (see man 5 systemd.kill for "KillMode=" section), and is considering to remove in future systemd version. As systemd developer explained in disuccsion, the systemd kill process is, 1. send the signal specified by KillSignal= to the list of processes (if any), TERM is the default 2. wait until either the target of process(es) exit or a timeout expires 3. if the timeout expires send the signal specified by FinalKillSignal=, KILL is the default For "control-group", all remaining processes will receive the SIGTERM signal (by default) and if there are still processes after a period f time, they will get the SIGKILL signal. For "mixed", only the main process will receive the SIGTERM signal, and if there are still processes after a period of time, all remaining processes (including the main one) will receive the SIGKILL signal. From the above comment, currently KillMode=control-group is a proper kill mode. Since control-gropu is the default kill mode, the fix can be simply removing KillMode=none line from the service file, then the default mode will take effect. Signed-off-by: Coly Li <colyli@suse.de> Cc: Benjamin Brunner <bbrunner@suse.com> Cc: Franck Bui <fbui@suse.de> Cc: Jes Sorensen <jes@trained-monkey.org> Cc: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> Cc: Neil Brown <neilb@suse.de> Cc: Xiao Ni <xni@redhat.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2022-04-04mdadm: add map_num_s()Mariusz Tkaczyk13-38/+61
map_num() returns NULL if key is not defined. This patch adds alternative, non NULL version for cases where NULL is not expected. There are many printf() calls where map_num() is called on variable without NULL verification. It works, even if NULL is passed because gcc is able to ignore NULL argument quietly but the behavior is undefined. For safety reasons such usages will use map_num_s() now. It is a potential point of regression. Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2022-04-04Create, Build: use default_layout()Mariusz Tkaczyk3-48/+43
This code is duplicated for Build mode so make default_layout() extern and use it. Simplify the function structure. It introduced change for Build mode, now for raid0 RAID0_ORIG_LAYOUT will be returned same as for Create. Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2022-04-04mdadm: Update config manualLukasz Florczak1-0/+17
Add missing HOMECLUSTER keyword description. Signed-off-by: Lukasz Florczak <lukasz.florczak@linux.intel.com> Acked-by: Coly Li <colyli@suse.de> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2022-04-04mdadm: Update config man regarding default files and multi-keyword behaviorLukasz Florczak2-24/+71
Simplify default and alternative config file and directory location references from mdadm(8) as references to mdadm.conf(5). Add FILE section in config man and explain order and conditions in which default and alternative config files and directories are used. Update config man behavior regarding parsing order when multiple keywords/config files are involved. Signed-off-by: Lukasz Florczak <lukasz.florczak@linux.intel.com> Acked-by: Coly Li <colyli@suse.de> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2022-04-04mdadm: Update ReadMeLukasz Florczak1-5/+6
Instead of hardcoded config file path give reference to config manual. Add missing monitordelay and homecluster parameters. Signed-off-by: Lukasz Florczak <lukasz.florczak@linux.intel.com> Acked-by: Coly Li <colyli@suse.de> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2022-04-04mdadm: Respect config file location in manLukasz Florczak4-10/+16
Default config file location could differ depending on OS (e.g. Debian family). This patch takes default config file into consideration when creating mdadm.man file as well as mdadm.conf.man. Rename mdadm.conf.5 to mdadm.conf.5.in. Now mdadm.conf.5 is generated automatically. Signed-off-by: Lukasz Florczak <lukasz.florczak@linux.intel.com> Acked-by: Coly Li <colyli@suse.de> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2022-04-04Replace error prone signal() with sigaction()Lukasz Florczak9-21/+45
Up to this date signal() was used which implementation could vary [1]. Sigaction() call is preferred. This commit introduces replacement from signal() to sigaction() by the use of signal_s() wrapper. Also remove redundant signal.h header includes. [1] https://man7.org/linux/man-pages/man2/signal.2.html Signed-off-by: Lukasz Florczak <lukasz.florczak@linux.intel.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2022-03-31udev: adapt rules to systemd v247Mariusz Tkaczyk3-4/+5
New events have been added in kernel 4.14 ("bind" and "unbind"). Systemd maintainer suggests to modify "add|change" branches. This patches implements their suggestions. There is no issue yet because new event types are not used in md. Please see systemd announcement for details[1]. [1] https://lists.freedesktop.org/archives/systemd-devel/2020-November/045646.html Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2022-03-31Grow_reshape: Add r0 grow size error message and update manMateusz Kusiak2-7/+18
Grow size on r0 is not supported for imsm and native metadata. Add proper error message. Update man for proper use of --size. Signed-off-by: Mateusz Kusiak <mateusz.kusiak@intel.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2022-03-31mdadm: Fix double freeLukasz Florczak1-2/+1
If there was a size mismatch after creation it would get fixed on grow in imsm_fix_size_mismatch(), but due to double free "double free or corruption (fasttop)" error occurs and grow cannot proceed. Signed-off-by: Lukasz Florczak <lukasz.florczak@linux.intel.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2022-03-15Unify error message.Lukasz Florczak2-4/+4
Provide the same error message for the same error that can occur in Grow.c and super-intel.c. Signed-off-by: Lukasz Florczak <lukasz.florczak@linux.intel.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2021-12-30Release mdadm-4.2mdadm-4.2Jes Sorensen7-23/+25
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2021-12-08Monitor: print message before quit for no array to monitorColy Li1-0/+1
If there is no array device to monitor, Monitor() will stop monitoring at line 261 from the following code block, 257 if (!new_found) { 258 if (oneshot) 259 break; 260 else if (!anyredundant) { 261 break; 262 } This change was introduced by commit 007087d0898a ("Monitor: stop notifing about containers"). Before this commit, Monitor() will continue and won't quit even there is no array to monitor. It is fine to quit without any array device to monitor, but users may wonder whether there is something wrong with mdadm program or their configuration to make mdadm quit monitoring. This patch adds a simple error message to indicate Monitor() quits for array device to monitor, which makes users have hint to understand why mdadm stops monitoring. Reported-by: George Gkioulis <ggkioulis@suse.com> Suggested-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> Signed-off-by: Coly Li <colyli@suse.de> Cc: Jes Sorensen <jsorensen@fb.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2021-12-08mdadm: block creation with long namesBlazej Kucman3-1/+18
This fixes buffer overflows in create_mddev(). It prohibits creation with not supported names for DDF and native. For IMSM, mdadm will do silent cut to 16 later. Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> Signed-off-by: Blazej Kucman <blazej.kucman@intel.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2021-11-24Correct checking if file descriptors are validMateusz Grzonka5-11/+6
In some cases file descriptors equal to 0 are treated as invalid. Fix it. Signed-off-by: Mateusz Grzonka <mateusz.grzonka@intel.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2021-11-24Incremental: Close unclosed mdfd in IncrementalScan()Mateusz Grzonka1-5/+6
In addition to closing mdfd, propagate helpers to manage file descriptors across IncrementalScan(). Signed-off-by: Mateusz Grzonka <mateusz.grzonka@intel.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2021-11-09imsm: assert if there is migration but prev_map doesn't existPawel Piatkowski1-14/+15
Verify that prev_map in not null during volume migration. Practically this case is not possible, device prev_map is being added if it is in the middle of migration. Add verification to silence static code analyze errors. Change error handling for function is_gen_migration() (as well as values compared with return value from this function) to use boolean types provided by stdbool.h. Signed-off-by: Pawel Piatkowski <pawel.piatkowski@intel.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2021-11-09imsm: free allocated memory in imsm_fix_size_mismatchPawel Piatkowski1-0/+2
Free allocated memory stored in variable named update Signed-off-by: Pawel Piatkowski <pawel.piatkowski@intel.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2021-11-03Release mdadm-4.2-rc3mdadm-4.2-rc3Jes Sorensen6-10/+11
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2021-11-02imsm: introduce helpers to manage file descriptorsMariusz Tkaczyk2-92/+100
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>
2021-11-02mdadm/Detail: Can't show container name correctly when unpluging disksXiao Ni1-8/+8
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>
2021-11-02mdadm/lib: Define a new helper function is_dev_alivedXiao Ni2-0/+13
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>
2021-10-19Fix 2 dc stream bufferNigel Croxon2-3/+3
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>
2021-10-19Assemble: apply sysfs rulesKinga Tanska1-3/+2
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>
2021-10-08Fix potential overlap dest bufferNigel Croxon1-1/+1
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>
2021-10-08disallow create or grow clustered bitmap with writemostly setNigel Croxon2-2/+12
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>
2021-10-08Fix buffer size warning for strcpyNigel Croxon1-3/+5
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>
2021-10-08Refactor parse_num and use it to parse optarg.Mateusz Grzonka7-71/+83
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>
2021-10-08Fix error message when creating raid 4, 5 and 10Mateusz Grzonka1-1/+1
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>
2021-10-08mdadm: fix coredump of mdadm --monitor -rWu Guanghao1-3/+3
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>
2021-08-13Utils: Change sprintf to snprintfMateusz Kusiak1-2/+2
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>
2021-08-02Release mdadm-4.2-rc2mdadm-4.2-rc2Jes Sorensen6-9/+10
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2021-08-02Assemble: skip devices that don't match uuid instead of aborting the assembly.Sudhakar Panneerselvam1-0/+5
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>
2021-08-02Add monitor delay parameter to mdadm.confoshchirs4-8/+46
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>
2021-08-02tests: Avoid passing chunk size when creating RAID 1Mateusz Grzonka5-9/+14
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>
2021-08-02Fix memory leak after "mdadm --detail"Mateusz Grzonka1-11/+9
Signed-off-by: Mateusz Grzonka <mateusz.grzonka@intel.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2021-07-27Assemble: start dirty and degraded array.Mariusz Tkaczyk3-80/+103
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>
2021-07-27imsm: fix num_data_stripes after raid0 takeoverMariusz Tkaczyk1-62/+77
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>
2021-07-16Add error handling for chunk size in RAID1Mateusz Grzonka1-3/+2
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>
2021-07-16imsm: Fix possible memory leaks and refactor freeing struct dlMateusz Grzonka1-20/+19
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>
2021-07-16mdadm: Fix building errorsXiao Ni2-2/+2
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>
2021-07-16Don't associate spares with other arrays during RAID ExamineOleksandr Shchirskyi2-56/+20
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>
2021-07-16Remove Spare drives line from details for external metadataOleksandr Shchirskyi1-1/+2
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>
2021-07-16imsm: correct offset for 4k disks in --examine outputOleksandr Shchirskyi1-1/+1
"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>
2021-07-16Use dev_open in validate geometry containerBlazej Kucman2-2/+2
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>
2021-07-16mdadm/super1: It needs to specify int32 for bitmap_offsetXiao Ni1-1/+1
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>
2021-05-26Manage: Call validate_geometry when adding drive to external containerMariusz Tkaczyk3-16/+19
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>
2021-05-26imsm: Limit support to the lowest namespaceMariusz Tkaczyk3-84/+123
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>
2021-05-26imsm: add devpath_to_char methodMariusz Tkaczyk3-18/+40
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>
2021-05-26imsm: add generic method to resolve "device" linksMariusz Tkaczyk3-65/+77
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>
2021-05-06Prevent user from using --stop with ambiguous argsNorbert Szulc1-0/+5
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>
2021-05-06Fix some building errorsXiao Ni1-3/+3
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>
2021-05-06imsm: change wrong size verificationMariusz Tkaczyk1-5/+5
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>
2021-04-14Release mdadm-4.2-rc1mdadm-4.2-rc1Jes Sorensen6-5/+29
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2021-04-14super-intel.c: Handle errors from calls to get_dev_sector_size()Jes Sorensen1-4/+10
The compiler gets rather upset if we do not take care of this. Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2021-04-06mdadm: fix growing containersNigel Croxon1-8/+11
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>
2021-03-19Monitor: make libudev dependency optionalMariusz Tkaczyk2-6/+29
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>
2021-03-18imsm: support for third Sata controllerMariusz Tkaczyk1-27/+31
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>
2021-03-16imsm: nvme multipath supportBlazej Kucman3-15/+104
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>
2021-03-16imsm: extend curr_migr_unit to u64Mariusz Tkaczyk1-41/+51
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>
2021-03-09Grow: Block reshape when external metadata and write-intent bitmapJakub Radtke1-9/+15
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>
2021-03-09Create: Block automatic enabling bitmap for external metadataJakub Radtke1-0/+1
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>
2021-03-09imsm: Update-subarray for write-intent bitmapJakub Radtke1-6/+17
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>
2021-03-09Add "bitmap" to allowed command-line valuesJakub Radtke2-3/+14
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>
2021-03-09imsm: Adding a spare to an existing array with bitmapJakub Radtke1-1/+36
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>
2021-03-09imsm: Write-intent bitmap supportJakub Radtke1-2/+617
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>
2021-03-09Enable bitmap support for external metadataJakub Radtke3-0/+22
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>
2021-03-09Modify mdstat parsing for volumes with the bitmapJakub Radtke1-0/+6
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>
2021-03-08It should be FAILED when raid has not enough active disksXiao Ni1-4/+10
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>
2021-03-08imsm: add verbose flag to compare_superMariusz Tkaczyk8-16/+23
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>
2021-03-08mdmonitor: check if udev has finished events processingOleksandr Shchirskyi2-12/+65
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>
2021-03-08Document PPL in man mdOleksandr Shchirskyi1-15/+29
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>
2021-03-08imsm: use saved fds during migrationMariusz Tkaczyk1-154/+54
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>
2021-03-03super1.c: avoid useless sync when bitmap switches from clustered to noneZhao Heming1-0/+2
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>
2021-03-03super1: fix Floating point exceptionZhao Heming1-1/+4
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>
2021-03-03Grow: be careful of corrupt dev_roles listNeilBrown2-13/+50
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>
2021-03-03mdadm: fix reshape from RAID5 to RAID6 with backup fileNigel Croxon1-2/+5
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>
2021-03-03mdadm/bitmap: locate bitmap calcuate bitmap position wronglyXiao Ni1-3/+9
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>
2020-12-20Dump: get stat from a wrong metadata file when restoring metadataLidong Zhong1-0/+5
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>
2020-12-20Incremental: Remove redundant spare movement logicMariusz Tkaczyk1-62/+0
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>
2020-11-25udev: start grow service automaticallyTkaczyk Mariusz1-0/+2
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>
2020-11-25Make target to install binaries onlyKinga Tanska1-3/+5
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>
2020-11-25mdadm/Detail: show correct state for clustered arrayZhao Heming3-10/+86
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>
2020-11-25mdadm: Unify forks behaviourMariusz Tkaczyk6-101/+100
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>
2020-11-25imsm: limit support to first NVMe namespaceMariusz Tkaczyk3-1/+42
Due to metadata limitations NVMe multinamespace support has to be removed. Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@intel.com>
2020-11-25Monitor: don't use default modes when creating a fileMariusz Tkaczyk1-5/+12
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>