summaryrefslogtreecommitdiffstats
Commit message (Collapse)AuthorAgeFilesLines
* imsm: fix free space calculationsMariusz Tkaczyk2023-09-011-20/+30
| | | | | | | | | | | | | | | | | | | | | | | Between two volumes or between last volume and metadata at least IMSM_RESERVED_SECTORS gap must exist. Currently the gap can be doubled because metadata reservation contains IMSM_RESERVED_SECTORS too. Divide reserve variable into pre_reservation and post_reservation to be more flexible and decide separately if each reservation is needed. Pre_reservation is needed only when a volume is created and it is not a real first volume in a container (we can check that by extent_idx). This type of reservation is not needed for expand. Post_reservation is not needed only if real last volume is created or expanded because reservation is done with the metadata. The volume index in metadata cannot be trusted, because the real volume order can be reversed. It is safer to use extent table, it is sorted by start position. Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
* imsm: return free space after volume for expandMariusz Tkaczyk2023-09-011-34/+37
| | | | | | | | | | | | | | | | merge_extends() routine searches for the biggest free space. For expand, it works only in standard cases where the last volume is expanded and the free space is determined after the last volume. Add volume index to extent struct and use that do determine size after super->current_vol during expand. Limitation to last volume is no longer needed. It unblocks scenarios where kill-subarray is used to remove first volume and later it is recreated (now it is the second volume, even if it is placed before existing one). Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
* imsm: move expand verification code into new functionMariusz Tkaczyk2023-09-011-86/+101
| | | | | | | | The code here is too complex. Move it to separate function and simplify it. Add more error messages. Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
* imsm: introduce round_member_size_to_mb()Mariusz Tkaczyk2023-09-011-10/+21
| | | | | | | Extract rounding logic to separate function. Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
* imsm: imsm_get_free_size() refactor.Mariusz Tkaczyk2023-09-011-13/+14
| | | | | | | Move minsize calculations up. Add error message if free size is too small. Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
* imsm: move sum_extents calculations to merge_extents()Mariusz Tkaczyk2023-09-011-18/+19
| | | | | | | | This logic is only used by merge_extents() code, there is no need to pass it as parameter. Move it up. Add proper description. Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
* imsm: Fix possible segfault in check_no_platform()Mateusz Grzonka2023-08-071-0/+5
| | | | | | | | conf_line() may return NULL, which is not handled and might cause segfault. Signed-off-by: Mateusz Grzonka <mateusz.grzonka@intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
* enable RAID for SATA under VMDKevin Friedberg2023-05-083-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>
* mdadm: numbered names verificationMariusz Tkaczyk2023-05-084-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>
* mdadm: define is_devname_ignore()Mariusz Tkaczyk2023-05-085-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>
* mdadm: define DEV_NUM_PREFMariusz Tkaczyk2023-05-083-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>
* mdadm: define DEV_MD_DIRMariusz Tkaczyk2023-05-0813-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>
* Remove the config files in mdcheck_start|continue serviceXiao Ni2023-04-102-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>
* Bump minimum kernel version to 2.6.32Jes Sorensen2023-04-105-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>
* Fix some cases eyesore formattingJes Sorensen2023-04-101-57/+60
| | | | | | Summary: No functional change .... just make it more readable. Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
* super1: fix truncation check for journal deviceHristo Venev2023-04-101-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>
* Fix null pointer for incremental in mdadmmiaoguanqin2023-04-101-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>
* Create: Fix checking for container in update_metadataMateusz Grzonka2023-03-231-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>
* Revert "Revert "mdadm/systemd: remove KillMode=none from service file""Mariusz Tkaczyk2023-03-231-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>
* Improvements for IMSM_NO_PLATFORM testing.NeilBrown2023-03-205-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>
* mdopen: always try create_named_array()NeilBrown2023-03-191-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>
* mdmon: Improve switchroot interactions.NeilBrown2023-03-196-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>
* mdmon: Remove need for KillMode=noneNeilBrown2023-03-191-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>
* mdmon: change systemd unit file to use --foregroundNeilBrown2023-03-191-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>
* mdmon: don't test both 'all' and 'container_name'.NeilBrown2023-03-191-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>
* Use existence of /etc/initrd-release to detect initrd.NeilBrown2023-03-191-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>
* Define alignof using _Alignof when using C11 or newerKhem Raj2023-03-191-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>
* manpage: Add --write-zeroes option to manpageLogan Gunthorpe2023-03-131-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>
* tests/00raid5-zero: Introduce test to exercise --write-zeros.Logan Gunthorpe2023-03-131-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>
* mdadm: Add --write-zeros option for CreateLogan Gunthorpe2023-03-134-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>
* mdadm: Introduce pr_info()Logan Gunthorpe2023-03-132-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>
* Create: Factor out add_disks() helpersLogan Gunthorpe2023-03-131-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>
* Create: remove safe_mode_delay local variableLogan Gunthorpe2023-03-131-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>
* Create: goto abort_locked instead of return 1 in error pathLogan Gunthorpe2023-03-131-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>
* super-ddf.c: fix memleak in get_vd_num_of_subarray()Wu Guanghao2023-03-081-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>
* super-intel.c: fix memleak in find_disk_attached_hba()Wu Guanghao2023-03-081-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>
* isuper-intel.c: fix double free in load_imsm_mpb()Wu Guanghao2023-03-081-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>
* Detail.c: fix memleak in Detail()Wu Guanghao2023-03-081-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>
* util.c: fix memleak in parse_layout_faulty()Wu Guanghao2023-03-081-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>
* util.c: reorder code lines in parse_layout_faulty()Coly Li2023-03-081-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>
* Mdmonitor: Refactor check_one_sharer() for better error handlingMateusz Grzonka2023-03-021-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>
* Mdmonitor: Refactor write_autorebuild_pid()Mateusz Grzonka2023-03-021-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>
* Add helpers to determine whether directories or files are soft linksMateusz Grzonka2023-03-022-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>
* Mdmonitor: Add helper functionsMateusz Grzonka2023-03-021-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>
* Mdmonitor: Pass events to alert() using enums instead of stringsMateusz Grzonka2023-03-021-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>
* Mdmonitor: Make alert_info globalMateusz Grzonka2023-03-021-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>
* Fix NULL dereference in super_by_fdLi Xiao Keng2023-02-282-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>
* Grow: fix can't change bitmap type from none to clustered.Heming Zhao2023-02-231-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>
* Revert "mdadm/systemd: remove KillMode=none from service file"Mariusz Tkaczyk2023-02-022-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>
* manage: move comment with function descriptionKinga Tanska2023-01-051-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>