summaryrefslogtreecommitdiff
path: root/sysfs.c
Commit message (Collapse)AuthorAgeFilesLines
* mdadm: define DEV_MD_DIRMariusz Tkaczyk2023-05-081-1/+1
| | | | | | | | 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>
* mdadm: replace container level checking with inlineKinga Tanska2022-09-291-1/+1
| | | | | | | | | 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>
* mdadm: add map_num_s()Mariusz Tkaczyk2022-04-041-4/+5
| | | | | | | | | | | | | | 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>
* mdadm: check value returned by snprintf against errorsKrzysztof Smolinski2019-08-161-2/+10
| | | | | | | | | GCC 8 checks possible truncation during snprintf more strictly than GCC 7 which result in compilation errors. To fix this problem checking result of snprintf against errors has been added. Signed-off-by: Krzysztof Smolinski <krzysztof.smolinski@intel.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
* mdadm: load default sysfs attributes after assemblationMariusz Dabrowski2019-07-101-0/+158
| | | | | | | | | | | | Added new type of line to mdadm.conf which allows to specify values of sysfs attributes for MD devices that should be loaded after the array is assembled. Each line is interpreted as list of structures containing sysname of MD device (md126 etc.) and list of sysfs attributes and their values. Signed-off-by: Mariusz Dabrowski <mariusz.dabrowski@intel.com> Signed-off-by: Krzysztof Smolinski <krzysztof.smolinski@intel.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
* mdmon: fix wrong array state when disk fails during mdmon startupArtur Paszkiewicz2019-05-201-9/+14
| | | | | | | | | | | | | | | | | | | | | | If a member drive disappears and is set faulty by the kernel during mdmon startup, after ss->load_container() but before manage_new(), mdmon will try to readd the faulty drive to the array and start rebuilding. Metadata on the active drive is updated, but the faulty drive is not removed from the array and is left in a "blocked" state and any write request to the array will block. If the faulty drive reappears in the system e.g. after a reboot, the array will not assemble because metadata on the drives will be incompatible (at least on imsm). Fix this by adding a new option for sysfs_read(): "GET_DEVS_ALL". This is an extension for the "GET_DEVS" option and causes all member devices to be returned, even if the associated block device has been removed. Use this option in manage_new() to include the faulty device on the active_array's devices list. Mdmon will then properly remove the faulty device from the array and update the metadata to reflect the degraded state. Signed-off-by: Artur Paszkiewicz <artur.paszkiewicz@intel.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
* sysfs: include faulty drive in disk countMariusz Tkaczyk2017-11-091-1/+1
| | | | | | | | | | | | | | When the disk fails, it goes into faulty state first and it is removed from the array in a while. It gives mdadm monitor a chance to see the disk has failed and notify an event (e.g. FailSpare). It doesn't work when sysfs is used to get a number of disks in the array as it skips faulty disk. ioctl implementation doesn't differentiate between active and faulty disk. Do the same for sysfs then. It should not matter that number of disks reported is greater than list of disk structures returned by the call because the same approach already takes place for offline disks. Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@intel.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
* Don't abort starting the array if kernel does not support pplArtur Paszkiewicz2017-10-021-3/+3
| | | | | | | | | | | | | | | | | | | Change the behavior of assemble and create for consistency-policy=ppl for external metadata arrays. If the kernel does not support ppl, don't abort but print a warning and start the array without ppl (consistency-policy=resync). No change for native md arrays because the kernel will not allow starting the array if it finds an unsupported feature bit in the superblock. In sysfs_add_disk() check consistency_policy in the mdinfo structure that represents the array, not the disk and read the current consistency policy from sysfs in mdmon's manage_member(). This is necessary to make sysfs_add_disk() honor the actual consistency policy and not what is in the metadata. Also remove all the places where consistency_policy is set for a disk's mdinfo - it is a property of the array, not the disk. Signed-off-by: Artur Paszkiewicz <artur.paszkiewicz@intel.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
* sysfs_init_dev - take a dev_t argumentJes Sorensen2017-09-291-1/+1
| | | | | | Be consistent and use the correct type. Signed-off-by: Jes Sorensen <jsorensen@fb.com>
* Get failed disk count from array stateTomasz Majchrzak2017-06-051-10/+8
| | | | | | | | | | | | | | | | | | | | Recent commit has changed the way failed disks are counted. It breaks recovery for external metadata arrays as failed disks are not part of the array and have no corresponding entries is sysfs (they are only reported for containers) so degraded arrays show no failed disks. Recent commit overwrites GET_DEGRADED result prior to GET_STATE and it is not set again if GET_STATE has not been requested. As GET_STATE provides the same information as GET_DEGRADED, the latter is not needed anymore. Remove GET_DEGRADED option and replace it with GET_STATE option. Don't count number of failed disks looking at sysfs entries but calculate it at the end. Do it only for arrays as containers report no disks, just spares. Signed-off-by: Tomasz Majchrzak <tomasz.majchrzak@intel.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
* sysfs/sysfs_read: Count working_disksJes Sorensen2017-05-091-6/+9
| | | | | | | This counts working_disks the same way as get_array_info counts it in the kernel. Signed-off-by: Jes Sorensen <jsorensen@fb.com>
* sysfs/sysfs_read: Count active_disks and failed_disksJes Sorensen2017-05-051-2/+8
| | | | | | | Cound active_disks as drives mark 'in_sync' and failed_disks as disks marked 'faulty', in the same way ioctl(GET_ARRAY_INFO) does. Signed-off-by: Jes Sorensen <jsorensen@fb.com>
* Don't use UnSet with consistency_policyArtur Paszkiewicz2017-04-241-6/+4
| | | | | | | | | Use CONSISTENCY_POLICY_UNKNOWN instead. Simplify some checks because since 5e8e35fb7e17 ("maps: Use keyvalue for null terminator to indicate 'unset' value") map_name() can return this default directly. Suggested-by: Jes Sorensen <Jes.Sorensen@gmail.com> Signed-off-by: Artur Paszkiewicz <artur.paszkiewicz@intel.com>
* maps: Use keyvalue for null terminator to indicate 'unset' valueJes Sorensen2017-04-201-2/+0
| | | | | | | This simplifies the code calling map_name() so it no longer has to manually check for UnSet and convert the value manually. Signed-off-by: Jes Sorensen <jsorensen@fb.com>
* sysfs: Parse array_state in sysfs_read()Jes Sorensen2017-04-201-4/+5
| | | | | | | 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>
* sysfs: Make sysfs_init() return an error codeJes Sorensen2017-03-301-6/+10
| | | | | | | | 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>
* sysfs: Use the presence of /sys/block/<dev>/md as indicator of valid deviceJes Sorensen2017-03-301-5/+12
| | | | | | | | | Rather than calling ioctl(RAID_VERSION), use the presence of /sys/block/<dev>/md as indicator of the device being valid and sysfs being active for it. The ioctl could return valid data, but sysfs not mounted, which renders sysfs_init() useless anyway. Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
* imsm: PPL supportArtur Paszkiewicz2017-03-291-0/+14
| | | | | | | | | | | | | | | | | | | Enable creating and assembling IMSM raid5 arrays with PPL. Update the IMSM metadata format to include new fields used for PPL. Add structures for PPL metadata. They are used also by super1 and shared with the kernel, so put them in md_p.h. Write the initial empty PPL header when creating an array. When assembling an array with PPL, validate the PPL header and in case it is not correct allow to overwrite it if --force was provided. Write the PPL location and size for a device to the new rdev sysfs attributes 'ppl_sector' and 'ppl_size'. Enable PPL in the kernel by writing to 'consistency_policy' before the array is activated. Signed-off-by: Artur Paszkiewicz <artur.paszkiewicz@intel.com> Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
* Generic support for --consistency-policy and PPLArtur Paszkiewicz2017-03-291-0/+11
| | | | | | | | | | | | | Add a new parameter to mdadm: --consistency-policy=. It determines how the array maintains consistency in case of unexpected shutdown. This maps to the md sysfs attribute 'consistency_policy'. It can be used to create a raid5 array using PPL. Add the necessary plumbing to pass this option to metadata handlers. The write journal and bitmap functionalities are treated as different policies, which are implicitly selected when using --write-journal or --bitmap options. Signed-off-by: Artur Paszkiewicz <artur.paszkiewicz@intel.com> Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
* Make get_component_size() work with named array.NeilBrown2016-12-221-8/+2
| | | | | | | | | | | | | | | | | get_component_size() still assumes that all array are /sys/block/md%d or /sys/block/md_d%d and so doesn't work with e.g. /sys/block/md_foo. This cause "mdadm --detail" to report Used Dev Size : unknown and causes problems when added spares and in other circumstances. So change it to use stat2devnm() which does the right thing with all types of array names. Reported-and-tested-by: Robert LeBlanc <robert@leblancnet.us> Signed-off-by: NeilBrown <neilb@suse.com> Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
* mdadm: bad block support for external metadata - initializationTomasz Majchrzak2016-11-281-1/+26
| | | | | | | | | | | If metadata handler provides support for bad blocks, tell md by writing 'external_bbl' to rdev state file (both on create and assemble), followed by a list of known bad blocks written via sysfs 'bad_blocks' file. Signed-off-by: Tomasz Majchrzak <tomasz.majchrzak@intel.com> Reviewed-by: Artur Paszkiewicz <artur.paszkiewicz@intel.com> Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
* Increase buffer for sysfs pathTomasz Majchrzak2016-11-171-16/+20
| | | | | | | | | 'unacknowledged_bad_blocks' is a long name for sysfs property and it makes sysfs path over 50 characters long. Increase buffer to the double length of the longest path available in sysfs at the moment. Signed-off-by: Tomasz Majchrzak <tomasz.majchrzak@intel.com> Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
* sysfs: Avoid if and return on the same lineJes Sorensen2016-08-111-1/+2
| | | | Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
* load_sys(): Add a buffer size argumentJes Sorensen2016-03-091-23/+24
| | | | | | | | | | | | | This adds a buffer size argument to load_sys(), rather than relying on a hard coded buffer size. The old behavior was safe because we knew the kernel would never return strings overrunning the buffers, however it was ugly, and would cause code checking tools to spit out warnings. This caused a Coverity warning over the read into sra->sysfs_array_state which is only 20 bytes. Reviewed-by: NeilBrown <neilb@suse.com> Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
* add sysfs_array_state to struct mdinfoSong Liu2015-12-161-0/+7
| | | | | | | | | Add sysfs_array_state to struct mdinfo, and add GET_ARRAY_STATE to options of sysfs_read. Signed-off-by: Song Liu <songliubraving@fb.com> Signed-off-by: Shaohua Li <shli@fb.com> Signed-off-by: NeilBrown <neilb@suse.com>
* re-add: make re-add try to write sysfs node firstGuoqing Jiang2015-10-081-0/+6
| | | | | | | If sysfs node existed, we should try to write "re-add" to it. Signed-off-by: Guoqing Jiang <gqjiang@suse.com> Signed-off-by: NeilBrown <neilb@suse.com>
* sysfs: reject reads that use the whole buffer.NeilBrown2015-07-061-5/+5
| | | | | | | | | If a read fills the whole buffer, then we possibly missed something of the end, and we definitely shouldn't put a '\0' beyond the end, so just return an error. This should never happen anyway. Signed-off-by: NeilBrown <neilb@suse.com>
* Don't break long strings onto multiple lines.NeilBrown2015-02-121-5/+2
| | | | | | | | | | | | | | | | | 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>
* Consistently print program Name and __func__ in debug messages.NeilBrown2015-02-121-4/+4
| | | | | | | | | | | | make dprintf() print program name and __func__, so that this messaging is consistent. Also remove all __func__ messages from pr_err(). We shouldn't leak that internal data in error message. If we really want function name there, we new pr_XXX might be wanted. Signed-off-by: NeilBrown <neilb@suse.de>
* Change way of printing name of a processPawel Baldysiak2015-02-121-4/+4
| | | | | | | | | | | | | Sometimes mdadm prints messages with wrong name "mdmon", and vice versa. This patch solves this problem by changing method of determining process name. Now "Name" will be set in const at start of a program, previously was hardcoded as #define. Signed-off-by: Pawel Baldysiak <pawel.baldysiak@intel.com> Signed-off-by: Artur Paszkiewicz <artur.paszkiewicz@intel.com> Signed-off-by: NeilBrown <neilb@suse.de>
* Introduce devid2kname - slightly different to devid2devnm.NeilBrown2013-08-011-1/+1
| | | | | | | | | | | | | 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>
* sysfs: fix bugs in new sysfs_wait function.NeilBrown2013-07-021-3/+6
| | | | | | | - 'tv' isn't initialised properly. - 100? I'm sure I fixed that already! Seems not. Signed-off-by: NeilBrown <neilb@suse.de>
* Manage: check alignment when stopping an array undergoing reshape.NeilBrown2013-07-011-0/+43
| | | | | | | | | | | | | 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>
* New function: sysfs_waitNeilBrown2013-07-011-0/+29
| | | | | | | We have several places that wait for activity on a sysfs file. Combine most of these into a single 'sysfs_wait' function. Signed-off-by: NeilBrown <neilb@suse.de>
* Grow: fix bug in raid0 -> raid5 conversion.NeilBrown2013-06-251-1/+1
| | | | | | | | | | The moment we change a RAID0 to a RAID5 it will try to recovery. This will abort quite quickly as there are not spare devices, but it could confuse the attempt to freeze the array. So allow 'freeze' to work even on a recovering array. Signed-off-by: NeilBrown <neilb@suse.de>
* Remove lots of unnecessary white space.NeilBrown2013-06-191-3/+1
| | | | | | | 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>
* sysfs_read: return devices in same order as in filesystem.NeilBrown2013-06-191-4/+7
| | | | | | | | When we read devices from sysfs (../md/dev-*), store them in the same order that they appear. That makes more sense when exposed to a human (as the next patch will). Signed-off-by: NeilBrown <neilb@suse.de>
* Detail: report on inactive arrays.NeilBrown2013-05-131-0/+1
| | | | | | | | Array can be inactive when e.g. -I is in the process of assembling them. This change allows --detail to report limited information about these arrays. Signed-off-by: NeilBrown <neilb@suse.de>
* Discard devnum in favour of devnmNeilBrown2013-02-211-41/+20
| | | | | | | | | | | | | | 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>
* Grow: fix reshape from RAID5 to RAID1.NeilBrown2012-11-201-2/+4
| | | | | | | | | | | Commit 5da9ab9874cb5896023afae1462550d83a869831 Grow_reshape re-factor in mdadm-3.2 broke conversion from RAID5 and RAID1 - and we never noticed. This fixes it. Signed-off-by: NeilBrown <neilb@suse.de>
* Grow: set new_data_offset if appropriateNeilBrown2012-10-041-0/+5
|
* Manage: fix checks for removal from a container.NeilBrown2012-09-241-18/+16
| | | | | | | | | | | | | | | | | | We must only remove from a container if the device isn't a member of any member array. To check we look at the 'holders' directory in sysfs. We currently skip that check if ->devname is "detached", however that can never be true since the change that introduced add_detached(). Also sysfs_unique_holder returns status in 'errno' which isn't entirely safe as e.g. closedir() is probably allowed to clear it. So make sysfs_unique_holder return an unambigious value, and us it to decide what to report. Signed-off-by: NeilBrown <neilb@suse.de>
* Remove scattered checks for malloc success.NeilBrown2012-07-091-7/+2
| | | | | | | | | | | | | | 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-2/+2
| | | | | | | 'pr_err("' is a lot shorter than 'fprintf(stderr, Name ": ' cont_err() is also available. Signed-off-by: NeilBrown <neilb@suse.de>
* Introduce sysfs_set_num_signed() and use it to set bitmap/offsetJes Sorensen2012-04-301-0/+8
| | | | | | | | | | mdinfo->bitmap_offset is a signed long and needs to be treated as such when passed to the kernel. This resolves the problem with adding internal bitmaps to a 1.0 array. Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com> Signed-off-by: NeilBrown <neilb@suse.de>
* Bitmap_offset is a signed numberNeilBrown2012-04-041-1/+1
| | | | | | | As the bitmap can be before the superblock, bitmap_offset is signed. But some of the code didn't honour that :-( Signed-off-by: NeilBrown <neilb@suse.de>
* sysfs: fixed sysfs_freeze_array array to work properly with Manage_subdevs.NeilBrown2012-03-281-3/+4
| | | | | | | | | | | | | If the array is already frozen when Manage_subdevs is called we don't want it to unfreeze the array. This is because Grow calls Manage_subdevs to add devices to an array being reshaped, and the array must stay frozen over this call. So if sysfs_freeze_array find the array to be frozen it returns '0', meaning that it didn't and cannot freeze it. Then the caller will not try to unfreeze, which is good. Signed-off-by: NeilBrown <neilb@suse.de>
* Grow/bitmap: support adding bitmap via sysfs.NeilBrown2011-12-231-0/+13
| | | | | | | | | | Adding a bitmap via ioctl can only add it at a fixed location. That location is not suitable for 4K-block devices. So allow setting the bitmap location via sysfs if kernel supports it and aim to always use 4K alignments. Signed-off-by: NeilBrown <neilb@suse.de>
* get_component_size(): Check read() return value for error before using itJes Sorensen2011-11-031-1/+1
| | | | | Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com> Signed-off-by: NeilBrown <neilb@suse.de>
* sysfs_unique_holder(): Check read() return value before using as buffer indexJes Sorensen2011-11-021-0/+2
| | | | | Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com> Signed-off-by: NeilBrown <neilb@suse.de>