summaryrefslogtreecommitdiffstats
path: root/mdopen.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>
* mdadm/mdopen: fix coverity issue STRING_OVERFLOWXiao Ni2024-08-051-1/+1
| | | | | | | Fix string overflow problems in mdopen.c Signed-off-by: Xiao Ni <xni@redhat.com> Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
* mdadm/mdopen: fix coverity issue CHECKED_RETURNXiao Ni2024-08-051-1/+5
| | | | | | | It needs to check return values when functions return value. Signed-off-by: Xiao Ni <xni@redhat.com> Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
* udev: Move udev_block() and udev_unblock() into udev.cMateusz Grzonka2023-11-211-6/+6
| | | | | | | | Add kernel style comments and better error handling. 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>
* Mdmonitor: Improve udev event handlingMateusz Grzonka2023-11-211-3/+4
| | | | | | | | | | | | | | | | | | | | | | | | 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 unsafe string functionsKinga Tanska2023-09-011-2/+2
| | | | | | | | Add string length limitations where necessary to avoid buffer overflows. Signed-off-by: Kinga Tanska <kinga.tanska@intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
* mdadm: define DEV_NUM_PREFMariusz Tkaczyk2023-05-081-5/+5
| | | | | | | 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-081-3/+3
| | | | | | | | 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>
* 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>
* Mdmonitor: Fix segfaultKinga Tanska2022-06-141-0/+17
| | | | | | | | | | | | Mdadm with "--monitor" parameter requires md device as an argument to be monitored. If given argument is not a md device, error shall be returned. Previously it was not checked and invalid argument caused segmentation fault. This commit adds checking that devices passed to mdmonitor are md devices. Signed-off-by: Kinga Tanska <kinga.tanska@intel.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
* Change warning messageKinga Tanska2020-01-161-1/+2
| | | | | | | | | | | | | | | | In commit 039b7225e6 ("md: allow creation of mdNNN arrays via md_mod/parameters/new_array") support for name like mdNNN was added. Special warning, when kernel is unable to handle request, was added in commit 7105228e19 ("mdadm/mdopen: create new function create_named_array for writing to new_array"), but it was not adequate enough, because in this situation mdadm tries to do it in old way. This commit changes warning to be more relevant when creating RAID container with "/dev/mdNNN" name and mdadm back to old approach. Signed-off-by: Kinga Tanska <kinga.tanska@intel.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
* mdopen: fix gcc 8.1 string overflow errorJes Sorensen2018-05-311-3/+5
| | | | | | | We already cut symlinks longer than 1000, so rely on this calling readlink and error out if we are able to read more than 1000 bytes. Signed-off-by: Jes Sorensen <jsorensen@fb.com>
* mdadm/mdopen: create new function create_named_array for writing to new_arrayZhilong Liu2017-11-011-20/+27
| | | | | | | | | | Split 'write to new_array' out into a function named create_named_array. And fixed a trivial compiling warning 'warn_unused_result' against commit: fdbf7aaa1956 (mdopen: call "modprobe md_mod" if it might be needed.) Suggested-by: NeilBrown <neilb@suse.com> Signed-off-by: Zhilong Liu <zlliu@suse.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
* mdopen: call "modprobe md_mod" if it might be needed.NeilBrown2017-09-271-0/+4
| | | | | | | | | | | | | | | | | | Creating an array by opening a block-device with major number of 9 will transparently load the md module if needed. Creating an array by opening /sys/module/md_mod/parameters/new_array and writing to it won't, it will just fail if md_mod isn't loaded. So when opening that file fails with ENOENT, run "modprobe md_mod" and try again. This fixes a bug whereby if you have "CREATE names=yes" in mdadm.conf, and the md modules isn't loaded, then creating or assembling an array will not honor the "names=yes" configuration. Signed-off-by: NeilBrown <neilb@suse.com> 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>
* util: md_array_valid(): Introduce md_array_valid() helperJes Sorensen2017-05-031-2/+1
| | | | | | | | | | | Using md_get_array_info() to determine if an array is valid is broken during creation, since the ioctl() returns -ENODEV if the device is valid but not active. Where did I leave my stash of brown paper bags? Fixes: ("40b054e mdopen/open_mddev: Use md_get_array_info() to determine valid array") Signed-off-by: Jes Sorensen <jsorensen@fb.com>
* Create: tell udev md device is not ready when first created.NeilBrown2017-05-021-19/+33
| | | | | | | | | | | | | | | | | | | | | 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>
* mdopen: use parameters/new_array to create arrays whenever possible.NeilBrown2017-04-121-0/+12
| | | | | | | | | | | | | | | | | | | | | In a sufficiently recent kernel, an md%d array can be created by writing to .../parameters/new_array. If mdadm does this consistently, then another new feature, disabling create_on_open, can be enabled. This avoids races on shutdown. An added benefit of using new_array (where available) is that it allows md arrays with numbers larger than 511 (e.g. md999) to be created. The old create_on_open mechanism doesn't support such devices since Commit: af5628f05db6 ("md: disable probing for md devices 512 and over.") in Linux 3.17. After a few more mdadm releases it would be good to have mdadm disable create_on_open automatically. Signed-off-by: NeilBrown <neilb@suse.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
* mdopen/open_mddev: Use md_get_array_info() to determine valid arrayJes Sorensen2017-04-051-1/+5
| | | | | | | md_get_array_info() can be used instead of md_get_version() to determine this is in fact a valid array. Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
* mdopen: open md devices O_RDONLYNeilBrown2016-12-051-3/+1
| | | | | | | | | | | | | | | | | | | | | There is no need to request write access when opening the md device, as we never write to it, and none of the ioctls we use require write access. If we do open with write access, then when we close, udev notices that the device was closed after being open for write access, and it generates a CHANGE event. This is generally unwanted, and particularly problematic when mdadm is trying to --stop the array, as the CHANGE event can cause the array to be re-opened before it completely closed, which results in a new mddev being allocated. So just use O_RDONLY instead of O_RDWR. Reported-by: Marc Smith <marc.smith@mcc.edu> Signed-off-by: NeilBrown <neilb@suse.com> Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
* Fix some issues found by clangNeilBrown2016-10-071-1/+1
| | | | | | | | | | | | | | | | | | The clang compiler complained about each of these. The mdmon.h error will only affect 'far' RAID10 arrays using intel or DDF metadata, and there is no such thing. The mdopen.c will cause a problem if there are no free md device numbers in the first 512. That is fairly unlikely. The restripe.c error would only affect the 'test_stripe' command, and probably doesn't change its behaviour. The super-intel.c fix is purely cosmetic. Signed-off-by: NeilBrown <neilb@suse.com> Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
* mdopen: Prevent overrunning the devname buffer when copying devnm into it ↵Robert LeBlanc2016-08-251-1/+1
| | | | | | | | | | | | for long md names. Linux allows for 32 character device names. When using the maximum size device name and also storing "/dev/", devname needs to be 37 character long to store the complete device name. i.e. "/dev/md_abcdefghijklmnopqrstuvwxyz12\0" Signed-off-by: Robert LeBlanc<robert@leblancnet.us> Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
* Change behavior in find_free_devnm when wrapping around.Mike Lovell2016-06-031-1/+1
| | | | | | | | Newer kernels don't allow for specifying an array larger than 511. This makes it so find_free_devnm wraps to 511 instead of 2^20 - 1. Signed-off-by: Mike Lovell <mlovell@bluehost.com> Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
* Use dev_t for devnm2devid and devid2devnmMike Lovell2016-06-031-2/+2
| | | | | | | | | | | | | | | | | | | 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>
* Don't break long strings onto multiple lines.NeilBrown2015-02-121-10/+5
| | | | | | | | | | | | | | | | | 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>
* Release mdadm-3.3mdadm-3.3NeilBrown2013-09-031-1/+1
| | | | | | (and various cosmetic fixes) Signed-off-by: NeilBrown <neilb@suse.de>
* Move find_free_devnum to mdopen.cNeilBrown2013-07-021-0/+33
| | | | | | | | | There is only one called to find_free_devnum and it is in mdopen.c The removes a dependency between util.c and config.c which allows us to now drop config.o from mdmon. Signed-off-by: NeilBrown <neilb@suse.de>
* create_mddev: add support for /dev/md_XXX non-numeric names.NeilBrown2013-05-151-20/+35
| | | | | | | | | | With the 'devnm' infrastructure fixed, it is quite easy to support names like "md_home" for md arrays. The currently defaults to "off" and can be enabled in mdadm.conf with CREATE names=yes This is incase other tools get confused by the new names. Signed-off-by: NeilBrown <neilb@suse.de>
* Discard devnum in favour of devnmNeilBrown2013-02-211-13/+15
| | | | | | | | | | | | | | 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-2/+1
| | | | | | | | | 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>
* Create new md devices consistentlyJustin Maggard2012-10-241-1/+4
| | | | | | | | | | | | | Creating a new MD device with the name 'd-0' results in some unexpected behavior, since mdadm sees that '-0' is a non-negative integer and therefore makes a "partitionable" device (/dev/md_d0). This is not the expected behavior, since the documentation mentions 'dN' several places, and a reboot brings it up as /dev/md/d-0. Make this consistent by ensuring that the character immediately following 'd' is a digit during creation. Signed-off-by: NeilBrown <neilb@suse.de>
* Handles spaces in array names better.NeilBrown2012-10-041-2/+11
| | | | | | | | | | | | 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>
* Minor cosmetic fixes in various files.NeilBrown2012-08-131-14/+10
| | | | Signed-off-by: NeilBrown <neilb@suse.de>
* Remove scattered checks for malloc success.NeilBrown2012-07-091-1/+1
| | | | | | | | | | | | | | 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-13/+13
| | | | | | | 'pr_err("' is a lot shorter than 'fprintf(stderr, Name ": ' cont_err() is also available. Signed-off-by: NeilBrown <neilb@suse.de>
* Update test for "is udev active".NeilBrown2012-05-031-1/+1
| | | | | | | | Newer udev doesn't use /dev/.udev any more. it used /run/udev instead. So test for that as well. Signed-off-by: NeilBrown <neilb@suse.de>
* make_parts(): Fix case of comparing against uninitialized variablesJes Sorensen2011-11-021-9/+12
| | | | | | | | | | | | | | | Silencing gcc's warning of uninitialized variables was hiding a bug where if we have /dev/md64 as a symlink, and /dev/md64p1 was a real device node. In this case major_num and minor_num would not get populated, but we end up comparing against them because the stat for md64p1 succeeds. Instead of using the int foo = foo trick, change the code to set set the variables to invalid values so comparisons will fail. Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com> Signed-off-by: NeilBrown <neilb@suse.de>
* Fix unterminated buffer after readlink() callThomas Jarosch2011-10-171-1/+5
| | | | | Signed-off-by: Thomas Jarosch <thomas.jarosch@intra2net.com> Signed-off-by: NeilBrown <neilb@suse.de>
* open_mddev: open RDONLY if RDWR doesn't work.NeilBrown2011-01-311-0/+2
| | | | | | | If an array is read-only then "mdadm -S" cannot open it to stop it without this fix. Signed-off-by: NeilBrown <neilb@suse.de>
* Free some malloced memory that wasn't being freed.NeilBrown2009-10-221-1/+4
| | | | | | | | | | As mdadm is normally a short-lived program it isn't always necessary to free memory that was allocated, as the 'exit()' call will automatically free everything. But it is more obviously correct if the 'free' is there. So this patch add a few calls to 'free' Signed-off-by: NeilBrown <neilb@suse.de>
* mdopen: only use 'dev' as chosen name if it is a full path.NeilBrown2009-10-191-2/+1
| | | | | | | Otherwise using names like "r0" causes problem. They are handled sufficiently by other paths in the code. Signed-off-by: NeilBrown <neilb@suse.de>
* Update copyright dates and remove references to @cse.unsw.edu.auNeilBrown2009-06-021-7/+2
| | | | | | Also removed 'paper' addresses. Signed-off-by: NeilBrown <neilb@suse.de>
* create_mddev: don't replace /dev/mdX with /dev/md/XNeilBrown2009-05-111-1/+4
| | | | | | | | If someone creates/assemble an array called "/dev/md0", don't force it to be "/dev/md/0". Doing so isn't really necessary and it likely to confuse people. Signed-off-by: NeilBrown <neilb@suse.de>
* create_dev - allow array names like mdX and /dev/mdX to appear 'numeric'NeilBrown2009-05-111-3/+11
| | | | | | | | | | | | | | When choosing the minor number to use with an array, we currently base the number of the 'name' stored in the metadata if that name is numeric. Extend that so that if it looks like a number md device name (/dev/md0 or just md0 or even /dev/md/0), then we use the number at the end to suggest a minor number. The means that if someone creates and array with "--name md0" or even "--name /dev/md0" it will continue to do what they expect. Signed-off-by: NeilBrown <neilb@suse.de>
* mdopen: be more careful when adding digit to names.NeilBrown2009-03-101-1/+1
| | | | | | | | If we need to add digits to a name to make it unique, but don't have to add '_', we need to avoid adding a digit immediately after a digit. So if the last character of the name is a digit, add the '_' anyway. Signed-off-by: NeilBrown <neilb@suse.de>
* some warn_unused_result fixupsDan Williams2008-11-271-5/+9
| | | | Signed-off-by: Dan Williams <dan.j.williams@intel.com>
* mdopen: typo in buffer-length for a sprintf.NeilBrown2008-11-071-1/+1
| | | | | | | That '10000' should have been '1000'. Make it a 'sizeof' to avoid such carelessness. Signed-off-by: NeilBrown <neilb@suse.de>
* mdopen: only let numeric name set minor number if it doesn't cause a conflict.NeilBrown2008-11-041-1/+4
| | | | | | | So if the array with minor number matching the name of a new array already exists, just assemble with a different minor number. Signed-off-by: NeilBrown <neilb@suse.de>
* mdopen: use small sequence number for uniquifying array names.NeilBrown2008-11-041-9/+23
| | | | | | | | | Rather than appending the md minor number, we now append a small sequence number to make sure name in /dev/md/ that aren't LOCAL are unique. As the map file is locked while we do this, we are sure of no losing any races. Signed-off-by: NeilBrown <neilb@suse.de>
* Quiet unitialized variable warningsDan Williams2008-11-041-2/+3
| | | | | Signed-off-by: Dan Williams <dan.j.williams@intel.com> Signed-off-by: NeilBrown <neilb@suse.de>