summaryrefslogtreecommitdiffstats
path: root/policy.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* 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>
* policy.c: Fix check_return issue in Write_rules()Anna Sztukowska2024-08-051-16/+9
| | | | | | | | Refactor Write_rules() in policy.c to eliminate check_return issue found by SAST analysis. Create udev rules file directly using rule_name instead of creating temporary file and renaming it. Signed-off-by: Anna Sztukowska <anna.sztukowska@intel.com>
* Revert "policy.c: Avoid to take spare without defined domain by imsm"Mariusz Tkaczyk2024-03-111-4/+0
| | | | | | | | | | This reverts commit 3bf9495270d7 ("policy.c: Avoid to take spare without defined domain by imsm"). IMSM does not require to be special now because it doesn't create disk controller domain. Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
* mdadm: drop get_disk_controller_domain()Mariusz Tkaczyk2024-03-111-13/+0
| | | | | | | | This function is unused now. Drop it. Controller for IMSM is a device policy and is separated from user defined domains. Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
* mdadm: test_and_add device policies implementationMariusz Tkaczyk2024-03-111-0/+93
| | | | | | | | | | | | Add support for three scenarios: - obtaining array wide policies via fd, - obtaining array wide policies via struct mdinfo, - getting policies for particular drive from the request. Add proper functions and make them extern. These functions are used in next patches. Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
* Fix 2 dc stream bufferNigel Croxon2021-10-191-2/+2
| | | | | | | | | | | | | | | | | | 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>
* policy.c: Fix for compiler errorMariusz Tkaczyk2018-12-111-1/+1
| | | | | | | | | | | After cd72f9d(policy: support devices with multiple paths.) compilation on old compilers fails because "ā€˜pā€™ may be used uninitialized in this function". Initialize it with NULL to prevent this. Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@intel.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
* policy.c: prevent NULL pointer referencingGioh Kim2018-12-111-1/+1
| | | | | | | | | paths could be NULL and paths[0] should be followed by NULL pointer checking. Reviewed-by: NeilBrown <neilb@suse.com> Signed-off-by: Gioh Kim <gi-oh.kim@cloud.ionos.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
* policy: support devices with multiple paths.NeilBrown2018-12-061-73/+90
| | | | | | | | | | | | | | | As new releases of Linux some time change the name of a path, some distros keep "legacy" names as well. This is useful, but confuses mdadm which assumes each device has precisely one path. So change this assumption: allow a disk to have several paths, and allow any to match when looking for a policy which matches a disk. Reported-and-tested-by: Mariusz Tkaczyk <mariusz.tkaczyk@intel.com> Signed-off-by: NeilBrown <neilb@suse.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
* Document PART-POLICY linesNeilBrown2018-12-061-1/+1
| | | | | | | | | | | | PART-POLICY has been accepted in mdadm.conf since the same time that POLICY was accepted, but it was never documented. So add the missing documentation. Also fix a bug which would have stopped it from working if anyone had ever tried to use it. Signed-off-by: NeilBrown <neilb@suse.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
* policy.c: Avoid to take spare without defined domain by imsmMariusz Tkaczyk2018-01-211-0/+4
| | | | | | | | | | | | Only Imsm get_disk_controller_domain returns disk controller domain for each disk. It causes that mdadm automatically creates disk controller domain policy for imsm metadata, and imsm containers in the same disk controller domain can take spare for recovery. Ignore spares if only one imsm domain is matched. Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@intel.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
* mdadm: Fixup != broken formattingJes Sorensen2017-05-161-3/+2
| | | | Signed-off-by: Jes Sorensen <jsorensen@fb.com>
* Don't break long strings onto multiple lines.NeilBrown2015-02-121-6/+3
| | | | | | | | | | | | | | | | | It is best to keep strings all together so that they are easier to search for in the source code. If a string is so long that it looks ugly one line, them maybe it should be broken into multiple lines for display too. Only strings which contain a newline can be broken into multiple lines: "It is OK to\n" "break this string\n" Signed-off-by: NeilBrown <neilb@suse.de>
* install: use BINDIR consistently to locate mdadm and mdmonNeilBrown2014-05-221-2/+2
| | | | | | | | Every place where the paths for mdadm or mdmon is explicit, it should use the BINDIR setting, not "/sbin/". Reported-by: member graysky <graysky@archlinux.us> (https://bugs.archlinux.org/task/37330) Signed-off-by: NeilBrown <neilb@suse.de>
* policy: NULL path isn't really acceptable - use the devnameLukasz Dorau2014-01-061-18/+17
| | | | | | | | | | | According to: commit b451aa4846c5ccca5447a6b6d45e5623b8c8e961 Fix handling for "auto" line in mdadm.conf a NULL path isn't really acceptable and the devname should be used instead. Signed-off-by: Lukasz Dorau <lukasz.dorau@intel.com> Signed-off-by: NeilBrown <neilb@suse.de>
* Remove lots of unnecessary white space.NeilBrown2013-06-191-3/+0
| | | | | | | Now that I am using white-space mode in Emacs I can see all of this, and I don't like it :-) Signed-off-by: NeilBrown <neilb@suse.de>
* Discard devnum in favour of devnmNeilBrown2013-02-211-3/+3
| | | | | | | | | | | | | | We widely use a "devnum" which is 0 or +ve for md%d devices and -ve for md_d%d devices. But I want to be able to use md_%s device names. So get rid of devnum (a number) and use devnm (a 32char string). eg. md0 md_d2 md_home Signed-off-by: NeilBrown <neilb@suse.de>
* Replace a lot of leading spaces with tabs.NeilBrown2012-10-101-79/+79
| | | | Signed-off-by: NeilBrown <neilb@suse.de>
* Remove scattered checks for malloc success.NeilBrown2012-07-091-11/+11
| | | | | | | | | | | | | | malloc should never fail, and if it does it is unlikely that anything else useful can be done. Best approach is to abort and let some super-daemon restart. So define xmalloc, xcalloc, xrealloc, xstrdup which don't fail but just print a message and exit. Then use those removing all the tests for failure. Also replace all "malloc;memset" sequences with 'xcalloc'. Signed-off-by: NeilBrown <neilb@suse.de>
* Introduce pr_err for printing error messages.NeilBrown2012-07-091-6/+6
| | | | | | | 'pr_err("' is a lot shorter than 'fprintf(stderr, Name ": ' cont_err() is also available. Signed-off-by: NeilBrown <neilb@suse.de>
* Write_rules(): Avoid stack corruption if using extremely long udev pathnameJes Sorensen2011-11-011-1/+2
| | | | | Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com> Signed-off-by: NeilBrown <neilb@suse.de>
* policy_add(): Add missing va_end()Jes Sorensen2011-11-011-0/+1
| | | | | Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com> Signed-off-by: NeilBrown <neilb@suse.de>
* Fix off-by-one in readlink() buffer size handlingThomas Jarosch2011-10-171-1/+1
| | | | | | | | | | | | | | readlink() returns the number of bytes in the buffer. If we do something like len = readlink(path, buf, sizeof(buf)); buf[len] = '\0'; we might write one byte past the end of the buffer. Signed-off-by: Thomas Jarosch <thomas.jarosch@intra2net.com> Signed-off-by: NeilBrown <neilb@suse.de>
* Fix handling for "auto" line in mdadm.confNeilBrown2011-10-061-13/+22
| | | | | | | | | | | | | Two problems. 1/ pol_merge was ignoring the pol_auto tag so any 'auto' information was lost 2/ If a device had not path (e.g. loop devices) or if there were no path-based policies, we didn't bother looking for policy at all. So path-independant policies were ignored. Reported-by: Christian Boltz <suse-beta@cboltz.de> Signed-off-by: NeilBrown <neilb@suse.de>
* Fix small memory leakThomas Jarosch2011-10-021-1/+4
| | | | | | | Credit goes to cppcheck. Signed-off-by: Thomas Jarosch <thomas.jarosch@intra2net.com> Signed-off-by: NeilBrown <neilb@suse.de>
* FIX: Prevent using null list pointerNeilBrown2011-09-071-0/+2
| | | | | | | | | When not all attributes are supported (attributes incompatibility) function container_content_imsm returns NULL pointer. We need to cope with a NULL list better. Reported-by: Lukasz Dorau <lukasz.dorau@intel.com> Signed-off-by: NeilBrown <neilb@suse.de>
* fix: generated udev rules does not work due to incorrect line formatHawrylewicz Czarnowski, Przemyslaw2011-03-071-4/+4
| | | | | | | | | Problem consists of missing =sign in comparison with SUBSYSTEM and missing new line character at the end of line. As a result incremental for hot-plugs of bare disks does not work. Signed-off-by: Przemyslaw Czarnowski <przemyslaw.hawrylewicz.czarnowski@intel.com> Signed-off-by: NeilBrown <neilb@suse.de>
* Allow domain_test to report that no domains were found.NeilBrown2011-02-011-2/+5
| | | | | | | | | Sometime we will need to know the difference between no domains found and domains didn't match. So allow domain_test to return different values and fix up all callers to maintain current behaviour. Signed-off-by: NeilBrown <neilb@suse.de>
* Dynamic hot-plug udev rules for policiesLabun, Marcin2011-01-271-0/+133
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Neil, Please consider this patch that once was discussed and I think agreed with in general direction. It was sent a while ago but somehow did not merged into your devel3-2. This patch enables hot-plug of so called bare devices (as understand by domain policies rules in mdadm.conf). Without this patch we do NOT serve hot-plug of bare devices at all. Thanks, Marcin Labun Subject was: FW: Autorebuild, new dynamic udev rules for hot-plugs >>From c0aecd4dd96691e8bfa6f2dc187261ec8bb2c5a2 Mon Sep 17 00:00:00 2001 From: Przemyslaw Czarnowski <przemyslaw.hawrylewicz.czarnowski@intel.com> Date: Thu, 23 Dec 2010 16:35:01 +0100 Subject: [PATCH] Dynamic hot-plug udev rules for policies Cc: linux-raid@vger.kernel.org, Williams, Dan J <dan.j.williams@intel.com>, Ciechanowski, Ed <ed.ciechanowski@intel.com> When introducing policies, new hot-plug rules were added to support bare disks. Mdadm was started for each hot plugged block device to determine if it could be used as spare or as a replacement member for degraded array. This patch introduces limitation of range of devices that are handled by mdadm. It limits them to the ones specified in domains associated with the actions: spare-same-port, spare and spare-force. In order to enable hot-plug for bare disks one must update udev rules with command mdadm --activate-domains[=filename] Above command writes udev rule configuration to stdout. If 'filename' is given output is written to the file provided as parameter. It is up to system administrator what should be done later. To make such rule permanent (i.e. remain after reboot) rule should be writen to /lib/udev/rules.d directory. Other cases will just need to write it to /dev/.udev/rules.d directory where temporary rules lies. One should be aware of the meaning of names/priorities of the udev rules. After mdadm.conf is changed one is obliged to re-run "mdadm --activate-domains" command in order to bring the system configuration up to date. All hot-plugged disks containing metadata are still handled by existing rules. Signed-off-by: Przemyslaw Czarnowski <przemyslaw.hawrylewicz.czarnowski@intel.com> Signed-off-by: NeilBrown <neilb@suse.de>
* Policy is aware of metadata disk's controller domains.Marcin Labun2010-11-221-4/+33
| | | | | | | | | | | | | | | | | Platform (metadata) domain let the metadata handlers differentiate disk domains based on controllers that the disk belongs to. Platform domain is sub-domain inside user specified domain in mdadm.conf configuration files inheriting all parameters from it. The metadata domain name is used disk domain matching functions. The disk with the same metadata domain name belong to the same metadata domain. New metadata handler is added that retrieves platform domain string based on disk path: const char *(*get_disk_controller_domain)(const char *path); Signed-off-by: Marcin Labun <marcin.labun@intel.com> Signed-off-by: NeilBrown <neilb@suse.de>
* Monitor: policy based spare migration.NeilBrown2010-11-221-7/+29
| | | | | | | | | | | Rather than only migrating between arrays with the same spare_group, we now migrate based on domains set in the policy. In order for spare_group to continue to work, we treat it as a domain of the destination array, and a domain of any device we might remove from a source array. Signed-off-by: NeilBrown <neilb@suse.de>
* Add action=spare-same-slot policy.NeilBrown2010-11-221-0/+2
| | | | | | | | | | | | | | | | | | | | | | When "mdadm -I" is given a device with no metadata, mdadm tries to add it as a 'spare' somewhere based on policy. This patch changes the behaviour in two ways: 1/ If the device is at a 'path' where a previous device was removed from an array or container, then we preferentially add the spare to that array or container. 2/ Previously only 'bare' devices were considered for adding as spares. Now if action=spare-same-slot is active, we will add non-bare devices, but *only* if the path was previously in use for some array, and the device will only be added to that array. Based on code From: Przemyslaw Czarnowski <przemyslaw.hawrylewicz.czarnowski@intel.com> Signed-off-by: Przemyslaw Czarnowski <przemyslaw.hawrylewicz.czarnowski@intel.com> Signed-off-by: NeilBrown <neilb@suse.de>
* extension of IncrementalRemove to store location (path-id) of removed devicePrzemyslaw Czarnowski2010-11-221-0/+67
| | | | | | | | | | | | | | | | If the disk is taken out from its port this port information is lost. Only udev rule can provide us with this information, and then we have to store it somehow. This patch adds writing 'cookie' file in /dev/.mdadm/failed-slots directory in form of file named with value of f<path-id> containing the metadata type and uuid of the array (or container) that the device was a member of. The uuid is in exactly the same format as in the mapfile. FAILED_SLOTS_DIR constant has been added to hold the location of cookie files. Signed-off-by: Przemyslaw Czarnowski <przemyslaw.hawrylewicz.czarnowski@intel.com> Signed-off-by: NeilBrown <neilb@suse.de>
* policy: don't try to get policy when path == NULL.NeilBrown2010-11-221-4/+3
| | | | | | | config_rules_has_path, we fail if path==NULL, so we should when config_rules doesn't has_path too. Signed-Off-By: NeilBrown <neilb@suse.de>
* Fix error in pol_sort.NeilBrown2010-11-221-2/+2
| | | | | | | | | pol_sort could go into an infinite loop. The proof of this patch is left as a exercise for the reader :-) Reported-by: "Hawrylewicz Czarnowski, Przemyslaw" <przemyslaw.hawrylewicz.czarnowski@intel.com> Signed-off-by: NeilBrown <neilb@suse.de>
* Convert 'auto' config line to policy statementsNeilBrown2010-09-061-3/+39
|
* Factor out path_policy functon.NeilBrown2010-09-061-10/+26
| | | | | | | | Allow disk-policy to be computed given the path and disk type explicitly. This can be used when hunting through /dev/disk/by-path for something interesting. Signed-off-by: NeilBrown <neilb@suse.de>
* Add domain policy support.NeilBrown2010-09-061-0/+89
| | | | | | | | | | | A device can be in a number of domains. The domains of an array is the union of the domains of all devices. A device is allowed to join an array when its set of domains is a subset of the array's domains. Signed-off-by: NeilBrown <neilb@suse.de>
* Add policy_action supportNeilBrown2010-09-061-0/+45
| | | | | | Add code for easy working 'action' policies. Signed-off-by: NeilBrown <neilb@suse.de>
* Add policy framework.NeilBrown2010-09-061-0/+461
Policy can be stated as lines in mdadm.conf like: POLICY type=disk path=pci-0000:00:1f.2-* action=ignore domain=onboard This defines two distinct policies which apply to any disk (but not partition) device reached through the pci device 0000:00:1f.2. The policies are "action=ignore" which means certain actions will ignore the device, and "domain=onboard" which means all such devices as treated as being united under the name 'onboard'. This patch just adds data structures and code to read and manipulate them. Future patches will actually use them. Signed-off-by: NeilBrown <neilb@suse.de>