summaryrefslogtreecommitdiffstats
path: root/Manage.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* Incremental: Simplify remove logicMariusz Tkaczyk2024-12-161-6/+4
| | | | | | Incremental_remove() does not execute Manage_subdevs() now. Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
* sysfs: functions for writing md/<memb>/stateMariusz Tkaczyk2024-12-161-3/+1
| | | | | | | Add dedicated enum to reflect possible values for mentioned file. Not all values are mapped. Add map to present sysfs keywords. Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
* Manage: forbid re-add to the array without metadataYu Kuai2024-12-031-0/+12
| | | | | | | | | | | For the build mode or external metadata, re-add is not supported, because it will not trigger full disk recovery, user should add a new disk to the array instead. Also update test/05r1-re-add-nosuper to reflect this. Signed-off-by: Yu Kuai <yukuai3@huawei.com> Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
* sysfs: add sysfs_open_memb_attr()Mariusz Tkaczyk2024-11-041-78/+44
| | | | | | | | | | Function is added to not repeat defining "dev-%s", disk_name. Related code branches are updated. Ioctl way for setting disk faulty/remove is removed, sysfs is always used now. Some non functional style issues are fixed in Manage_subdevs(). Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
* mdadm/Manage: Clear superblock if adding new device failsXiao Ni2024-10-181-0/+4
| | | | | | | | The superblock is kept if adding new device fails. It should clear the superblock if it fails to add a new disk. Signed-off-by: Xiao Ni <xni@redhat.com> Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
* mdadm: add xmalloc.hMariusz Tkaczyk2024-09-271-0/+2
| | | | | | | | | | Move memory declaration helpers outside mdadm.h. They seems to be useful so keep them but include separatelly. Rework them to not reffer to Name[] declared internally in mdadm/mdmon. This is first step to start decomplexing mdadm.h. Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
* sysfs: add function for writing to sysfs fdMariusz Tkaczyk2024-09-271-19/+26
| | | | | | | | | | Proposed function sysfs_wrte_descriptor() unifies error handling for write() done to sysfs files. Main purpose is to use it with MD sysfs file but it can be used elsewhere. No functional changes. Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
* mdadm/Manage: record errnoXiao Ni2024-09-231-3/+5
| | | | | | | | | Sometimes it reports: mdadm: failed to stop array /dev/md0: Success It's the reason the errno is reset. So record errno during the loop. Signed-off-by: Xiao Ni <xni@redhat.com> Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
* mdstat: Rework mdstat external arrays handlingMariusz Tkaczyk2024-07-301-4/+2
| | | | | | | | | | | | To avoid repeating mdstat_read() in IncrementalRemove(), new function mdstat_find_by_member_name() has been proposed. With that, IncrementalRemove() handles own copy of mdstat content and there is no need to repeat reading for external stop. Additionally, It proposed few helper to avoid repeating mdstat_ent->metadata_version checks across code. Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
* Manage: fix is_remove_safe()Mariusz Tkaczyk2024-07-161-1/+1
| | | | | | | Fix for to make --set-faulty working. Fixes: 1b4b73fd535a ("mdadm: Manage.c fix coverity issues") Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
* mdadm: Manage.c fix coverity issuesNigel Croxon2024-07-101-78/+71
| | | | | | | | | | | | | | | | | | | | | | | | | Fixing the following coding errors the coverity tools found: * Event parameter_hidden: declaration hides parameter "dv". * Event leaked_storage: Variable "mdi" going out of scope leaks the storage it points to. * Event overwrite_var: Overwriting "mdi" in "mdi = mdi->devs" leaks the storage that "mdi" points to. * Event leaked_handle: Handle variable "lfd" going out of scope leaks the handle. * Event leaked_handle: Returning without closing handle "fd" leaks it. * Event fixed_size_dest: You might overrun the 32-character fixed-sizei string "devnm" by copying the return value of "fd2devnm" without checking the length. * Event fixed_size_dest: You might overrun the 32-character fixed-size string "nm" by copying "nmp" without checking the length. * Event fixed_size_dest: You might overrun the 32-character fixed-size string "devnm" by copying the return value of "fd2devnm" without checking the length. * Event assigned_value: Assigning value "-1" to "tfd" here, but that stored value is overwritten before it can be used. Signed-off-by: Nigel Croxon <ncroxon@redhat.com>
* Change some error messages to info levelXiao Ni2024-05-241-1/+1
| | | | | | | These logs are not error logs. Change them to info level. Signed-off-by: Xiao Ni <xni@redhat.com> Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
* Manage: check device policies in manage_add_external()Mariusz Tkaczyk2024-03-111-0/+8
| | | | | | | | | | | Only IMSM is going to use device policies so it is added to manage_add_external(). Test policies before adding the drive to container. The change blocks adding new device to the container which already contains not matching devices Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
* mdadm: introduce sysfs_get_container_devnm()Mariusz Tkaczyk2024-03-111-10/+4
| | | | | | | | There at least two places where it is done directly, so replace them with function. Print message about creating external array, add "/dev/" prefix to refer directly to devnode. Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
* Manage: implement manage_add_external()Mariusz Tkaczyk2024-03-111-61/+86
| | | | | | | | | Move external add code to separate function. It is easier to control error path now. Error messages are adjusted. No functional changes. Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
* Manage: fix check after dereference issueMariusz Tkaczyk2024-03-111-14/+12
| | | | | | | | | | | | | The code dereferences dev_st earlier without checking, it gives SAST problem. dev_st is needed for attempt_re_add(), but it is executed only if dv->disposition != 'S', so move disposition check up. tst is a must to reach this place, dup_super() have to return valid pointer, all it needs to check is if load_super() returns superblock. Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
* Replace "none" with macroMateusz Kusiak2024-01-241-1/+1
| | | | | | | | | | | String "none" is used many times throughout the code. Replace "none" strings with predefined macro. Add str_is_none() for comparing strings with "none". Replace str(n)cmp calls with function. Signed-off-by: Mateusz Kusiak <mateusz.kusiak@intel.com> Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
* Define sysfs max buffer sizeMateusz Kusiak2024-01-241-4/+4
| | | | | | | | | | | sysfs_get_str() usages have inconsistant buffer size. This results in wild buffer declarations and redundant memory usage. Define maximum buffer size for sysfs strings. Replace wild sysfs string buffer sizes for globaly defined value. Signed-off-by: Mateusz Kusiak <mateusz.kusiak@intel.com> Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
* manage: adjust checking subarray state in update_subarrayPawel Piatkowski2024-01-051-1/+2
| | | | | | | | | | | | Only changing bitmap related consistency_policy requires subarray to be inactive. consistency_policy with PPL or NO_PPL value can be changed on active subarray. It fixes regression introduced in commit db10eab68e652f141169 ("Fix --update-subarray on active volume") Signed-off-by: Pawel Piatkowski <pawel.piatkowski@intel.com> Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
* Mdmonitor: Improve udev event handlingMateusz Grzonka2023-11-211-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | Mdmonitor is waiting for udev queue to become empty. Even if the queue becomes empty, udev might still be processing last event. However we want to wait and wake up mdmonitor when udev finished processing events.. Also, the udev queue interface is considered legacy and should not be used outside of udev. Use udev monitor instead, and wake up mdmonitor on every event triggered by udev for md block device. We need to generate more change events from kernel, because they are missing in some situations, for example, when rebuild started. This will be addressed in a separate patch. Move udev specific code into separate functions, and place them in udev.c file. Also move use_udev() logic from lib.c into newly created file. Signed-off-by: Mateusz Grzonka <mateusz.grzonka@intel.com> Signed-off-by: Kinga Tanska <kinga.tanska@intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
* Fix race of "mdadm --add" and "mdadm --incremental"Li Xiao Keng2023-10-261-8/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There is a raid1 with sda and sdb. And we add sdc to this raid, it may return -EBUSY. The main process of --add: 1. dev_open(sdc) in Manage_add 2. store_super1(st, di->fd) in write_init_super1 3. fsync(fd) in store_super1 4. close(di->fd) in write_init_super1 5. ioctl(ADD_NEW_DISK) Step 2 and 3 will add sdc to metadata of raid1. There will be udev(change of sdc) event after step4. Then "/usr/sbin/mdadm --incremental --export $devnode --offroot $env{DEVLINKS}" will be run, and the sdc will be added to the raid1. Then step 5 will return -EBUSY because it checks if device isn't claimed in md_import_device()->lock_rdev()->blkdev_get_by_dev() ->blkdev_get(). It will be confusing for users because sdc is added first time. The "incremental" will get map_lock before add sdc to raid1. So we add map_lock before write_init_super in "mdadm --add" to fix the race of "add" and "incremental". Signed-off-by: Li Xiao Keng <lixiaokeng@huawei.com> Signed-off-by: Guanqin Miao <miaoguanqin@huawei.com> Reviewed-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
* Fix memory leak in file ManageGuanqin Miao2023-09-011-2/+11
| | | | | | | | | | | | When we test mdadm with asan, we found some memory leaks in Manage.c We fix these memory leaks based on code logic. v2: Fix free() of uninitialized 'tst' in abort path. Signed-off-by: Guanqin Miao <miaoguanqin@huawei.com> Signed-off-by: Li Xiao Keng <lixiaokeng@huawei.com> Acked-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
* Bump minimum kernel version to 2.6.32Jes Sorensen2023-04-101-17/+0
| | | | | | | 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>
* 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>
* incremental, manage: do not verify if remove is safeKinga Tanska2023-01-051-3/+4
| | | | | | | | | | | 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>
* Manage: do not check array state when drive is removedKinga Tanska2023-01-051-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>
* Manage&Incremental: code refactor, string to enumMateusz Kusiak2023-01-041-18/+17
| | | | | | | | | 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>
* Change update to enum in update_super and update_subarrayMateusz Kusiak2023-01-041-6/+8
| | | | | | | | | | 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>
* Fix --update-subarray on active volumeMateusz Kusiak2023-01-041-0/+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>
* Manage: Block unsafe member failingMateusz Kusiak2022-09-081-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>
* mdadm: Replace obsolete usleep with nanosleepMateusz Grzonka2022-08-221-5/+5
| | | | | | | | | 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>
* mdadm: block update=ppl for non raid456 levelsLukasz Florczak2022-06-241-2/+12
| | | | | | | | | | | | 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>
* Manage: Call validate_geometry when adding drive to external containerMariusz Tkaczyk2021-05-261-0/+7
| | | | | | | | | | | | 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>
* Manage, imsm: Write metadata before addTkaczyk Mariusz2020-04-271-5/+1
| | | | | | | | | | | | | | | | | | | | | | New drive in container always appears as spare. Manager is able to handle that, and queues appropriative update to monitor. No update from mdadm side has to be processed, just insert the drive and ping the mdmon. Metadata has to be written if no mdmon is running (case for Raid0 or container without arrays). If bare drive is added very early on startup (by custom bare rule), there is possiblity that mdmon was not restarted after switch root. Old one is not able to handle new drive. New one fails because there is drive without metadata in container and metadata cannot be loaded. To prevent this, write spare metadata before adding device to container. Mdmon will overwrite it (same case as spare migration, if drive appears it writes the most recent metadata). Metadata has to be written only on new drive before sysfs_add_disk(), don't race with mdmon if running. Signed-off-by: Tkaczyk Mariusz <mariusz.tkaczyk@intel.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
* Fix up a few formatting issuesJes Sorensen2019-11-271-4/+9
| | | | Signed-off-by: Jes Sorensen <jsorensen@fb.com>
* Remove last traces of HOT_ADD_DISKJes Sorensen2019-11-271-2/+0
| | | | | | This ioctl is no longer used, so remove all references to it. Signed-off-by: Jes Sorensen <jsorensen@fb.com>
* Manage: Remove the legacy code for md driver prior to 0.90.03Xiao Yang2019-11-271-12/+0
| | | | | | | | | | | | | | | | | | | Previous re-add operation only calls ioctl(HOT_ADD_DISK) for array without metadata(e.g. mdadm -B/--build) when md driver is less than 0.90.02, but commit 091e8e6 breaks the logic and current re-add operation can call ioctl(HOT_ADD_DISK) even if md driver is 0.90.03. This issue is reproduced by 05r1-re-add-nosuper: ------------------------------------------------ ++ die 'resync or recovery is happening!' ++ echo -e '\n\tERROR: resync or recovery is happening! \n' ERROR: resync or recovery is happening! ------------------------------------------------ Fixes: 091e8e6("Manage: Remove all references to md_get_version()") Reported-by: kernel test robot <lkp@intel.com> Signed-off-by: Xiao Yang <ice_yangxiao@163.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
* Manage_subdevs(): Use a dev_tJes Sorensen2017-09-301-1/+1
| | | | | | Use the correct type for rdev Signed-off-by: Jes Sorensen <jsorensen@fb.com>
* Error messages should end with a newline character.NeilBrown2017-08-161-1/+1
| | | | | | | | Add "\n" to the end of error messages which don't already have one. Also spell "opened" correctly. Signed-off-by: NeilBrown <neilb@suse.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
* mdadm/r5cache: allow adding journal to array without journalSong Liu2017-08-021-6/+0
| | | | | | | | | | | | Currently, --add-journal can be only used to recreate broken journal for arrays with journal since creation. As the kernel code getting more mature, this constraint is no longer necessary. This patch allows --add-journal to add journal to array without journal. Signed-off-by: Song Liu <songliubraving@fb.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
* mdadm: Fixup more broken logical operator formattingJes Sorensen2017-05-161-2/+2
| | | | Signed-off-by: Jes Sorensen <jsorensen@fb.com>
* mdadm: Fixup a large number of bad formatting of logical operatorsJes Sorensen2017-05-161-16/+13
| | | | | | Logical oprators never belong at the beginning of a line. Signed-off-by: Jes Sorensen <jsorensen@fb.com>
* retire the APIs that driver no longer supportsZhilong Liu2017-05-111-4/+0
| | | | | | | | | | refer to commit: e6e5f8f1267d ("Build: Stop bothering about supporting md driver ...") continue to retire the APIs that md driver wasn't supported for very long period of time. Signed-off-by: Zhilong Liu <zlliu@suse.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
* mdadm/util: unify stat checking blkdev into functionZhilong Liu2017-05-051-10/+1
| | | | | | | | | | | | declare function stat_is_blkdev() to integrate repeated stat checking blkdev operations, it returns 'true/1' when it is a block device, and returns 'false/0' when it isn't. The devname is necessary parameter, *rdev is optional, parse the pointer of dev_t *rdev, if valid, assigned device number to dev_t *rdev, if NULL, ignores. Signed-off-by: Zhilong Liu <zlliu@suse.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
* mdadm/util: unify fstat checking blkdev into functionZhilong Liu2017-05-051-1/+1
| | | | | | | | | | | | declare function fstat_is_blkdev() to integrate repeated fstat checking block device operations, it returns true/1 when it is a block device, and returns false/0 when it isn't. The fd and devname are necessary parameters, *rdev is optional, parse the pointer of dev_t *rdev, if valid, assigned the device number to dev_t *rdev, if NULL, ignores. Signed-off-by: Zhilong Liu <zlliu@suse.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
* Manage: Manage_ro(): Use md_array_active()Jes Sorensen2017-05-021-4/+2
| | | | | | | One call less to md_get_array_info() for determining whether an array is active or not. Signed-off-by: Jes Sorensen <jsorensen@fb.com>
* sysfs: Parse array_state in sysfs_read()Jes Sorensen2017-04-201-1/+1
| | | | | | | Rather than copying in the array_state string, parse it and use an enum to indicate the state. Signed-off-by: Jes Sorensen <jsorensen@fb.com>
* Retire mdassembleJes Sorensen2017-04-111-9/+1
| | | | | | | | mdassemble doesn't handle container based arrays, no support for sysfs, etc. It has not been actively maintained for years, so time to send it off to retirement. Signed-off-by: Jes Sorensen <jsorensen@fb.com>
* Manage: Remove all references to md_get_version()Jes Sorensen2017-04-051-19/+1
| | | | | | | At this point, support for md driver prior to 0.90.03 is going to disappear. Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
* sysfs: Make sysfs_init() return an error codeJes Sorensen2017-03-301-2/+5
| | | | | | | | Rather than have the caller inspect the returned content, return an error code from sysfs_init(). In addition make all callers actually check it. Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>