summaryrefslogtreecommitdiffstats
path: root/lib.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* lib: devid2kname() should take a dev_tJes Sorensen2017-09-291-3/+2
| | | | | | Make devid2kname() and devid2devnm() consistent in their APIs Signed-off-by: Jes Sorensen <jsorensen@fb.com>
* Fix typo in new udev rule.NeilBrown2017-05-051-1/+1
| | | | | | | | | | | | As pointed out by Peter Rajnoha, the correct usage in udev is TEST=="file", not TEST="file". Also improve a related comment which was a bit informal. Reported-by: Peter Rajnoha <prajnoha@redhat.com> Fixes: cd6cbb08c458 ("Create: tell udev md device is not ready when first created.") Signed-off-by: NeilBrown <neilb@suse.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
* Create: tell udev md device is not ready when first created.NeilBrown2017-05-021-0/+29
| | | | | | | | | | | | | | | | | | | | | When an array is created the content is not initialized, so it could have remnants of an old filesystem or md array etc on it. udev will see this and might try to activate it, which is almost certainly not what is wanted. So create a mechanism for mdadm to communicate with udev to tell it that the device isn't ready. This mechanism is the existance of a file /run/mdadm/created-mdXXX where mdXXX is the md device name. When creating an array, mdadm will create the file. A new udev rule file, 01-md-raid-creating.rules, will detect the precense of thst file and set ENV{SYSTEMD_READY}="0". This is fairly uniformly used to suppress actions based on the contents of the device. Signed-off-by: NeilBrown <neilb@suse.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
* Lib.c: Fix geting devname for devices with long pathPawel Baldysiak2016-10-261-1/+1
| | | | | | | | | | | In scenario where VMD is enabled, and "x8" type of NVMe drive is plugged into PCIe switch - the path will be longer than 200 chars (additional VMD domain + 2 level of PCIe switches). This patch makes the buffer big enough to handle this kind of configurations. Signed-off-by: Pawel Baldysiak <pawel.baldysiak@intel.com> Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
* lib: Various coding style cleanupsJes Sorensen2016-08-111-34/+51
| | | | Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
* lib: Avoid if and return on the same lineJes Sorensen2016-08-111-2/+3
| | | | Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
* Use dev_t for devnm2devid and devid2devnmMike Lovell2016-06-031-1/+1
| | | | | | | | | | | | | | | | | | | Commit 4dd2df0966ec added a trip through makedev(), major(), and minor() for device major and minor numbers. This would cause mdadm to fail in operating on a device with a minor number bigger than (2^19)-1 due to it changing from dev_t to a signed int and back. Where this was found as a problem was when a array was created with a device specified as a name like /dev/md/raidname and there were already 128 arrays on the system. In this case, mdadm would chose 1048575 ((2^20)-1) for the array and minor number. This would cause the major and minor number to become negative when generated from devnm2devid() and passed to major() and minor() in open_dev_excl(). open_dev_excl() would then call dev_open() which would detect the negative minor number and call open() on the *char containing the major:minor pair which isn't a valid file. Signed-off-by: Mike Lovell <mlovell@bluehost.com> Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
* Introduce stat2kname() and fd2kname()Artur Paszkiewicz2016-03-301-0/+15
| | | | | | | | | | | | These are similar to stat2devnm() and fd2devnm() but not limited to md devices. If the device is a partition they will return its kernel name, not the whole device's name. For more information see commit: 8d83493 ("Introduce devid2kname - slightly different to devid2devnm.") Also remove unsued declaration for fmt_devname(). Signed-off-by: Artur Paszkiewicz <artur.paszkiewicz@intel.com> Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
* Introduce devid2kname - slightly different to devid2devnm.NeilBrown2013-08-011-0/+26
| | | | | | | | | | | | | The purpose od devid2devnm is to return a kernel name of an md device, whether that device is a whole device or a partition, we want the whole device. md4, never md4p2. In one place I was using devid2devnm where I really wanted the partition if there was one ... and wasn't really interested in it being an md device. So introduce a new 'devid2kname' for that case. Signed-off-by: NeilBrown <neilb@suse.de>
* Move conf_line and free_line from conf.c to lib.cNeilBrown2013-07-021-0/+40
| | | | | | | | | As they are uses for mdstat as well as mdadm.conf, they don't really belong in conf.c This removes a dependency between mdmon and conf.c Signed-off-by: NeilBrown <neilb@suse.de>
* Manage: check alignment when stopping an array undergoing reshape.NeilBrown2013-07-011-0/+11
| | | | | | | | | | | | | To be able to revert-reshape of raid4/5/6 which is changing the number of devices, the reshape must has been stopped on a multiple of the old and new stripe sizes. The kernel only enforces the new stripe size multiple. So we enforce the old-stripe-size multiple by careful use of "sync_max" and monitoring "reshape_position". Signed-off-by: NeilBrown <neilb@suse.de>
* Remove lots of unnecessary white space.NeilBrown2013-06-191-4/+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>
* raid6check: Fix build of raid6checkBernd Schubert2013-06-191-0/+10
| | | | | | | | | | | | | After recent git pull 'make raid6check' did not work anymore, as sysfs_read() was called with a wrong argument and as check_env() was used by use_udev(), but not defined. Replace sysfs_read(..., -1, ...) by sysfs_read(..., NULL, ...) Move check_env() from util.c to lib.c Signed-off-by: Bernd Schubert <bernd.schubert@itwm.fraunhofer.de> Signed-off-by: NeilBrown <neilb@suse.de>
* Discard devnum in favour of devnmNeilBrown2013-02-211-53/+40
| | | | | | | | | | | | | | 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>
* conditionally remove map_dev from find_free_devnumNeilBrown2013-01-071-0/+13
| | | | | | | | | map_dev can be slow so it is best to not call it when not necessary. The final test in "find_free_devnum" is not relevant when udev is being used, so remove the test in that case. Signed-off-by: NeilBrown <neilb@suse.de>
* Replace a lot of leading spaces with tabs.NeilBrown2012-10-101-3/+3
| | | | Signed-off-by: NeilBrown <neilb@suse.de>
* Handles spaces in array names better.NeilBrown2012-10-041-0/+68
| | | | | | | | | | | | 1/ When printing the "name=" entry for --brief output, enclose name in quotes if it contains spaces etc. Quotes are already supported for reading mdadm.conf 2/ When a name is used as a device name, translate spaces and tabs to '_', as well as the current translation of '/' to '-'. Signed-off-by: NeilBrown <neilb@suse.de>
* Remove scattered checks for malloc success.NeilBrown2012-07-091-8/+5
| | | | | | | | | | | | | | 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>
* Add --prefer option for --detail and --monitorNeilBrown2012-04-181-2/+7
| | | | | | | | | | | | | | | | | Both --detail and --monitor can report the names of member devices on an array, and do so by searching /dev and finding the shortest name that matches. If --prefer=foo is given, they will instead prefer a name that contain /foo/. So mdadm --detail /dev/md0 --prefer=by-path will list the component devices via their /dev/disk/by-path/xxx names. Signed-off-by: NeilBrown <neilb@suse.de>
* Split some of util.c into a new lib.cNeilBrown2011-04-051-0/+322
Some of util.c is dependent on lots of other code, some of it is stand-alone. Move some of the stand-alone stuff into a new lib.c so it can be used by smaller utilities. Signed-off-by: NeilBrown <neilb@suse.de>