summaryrefslogtreecommitdiff
path: root/util.c
Commit message (Collapse)AuthorAge
* Improvements to GPT reading code.Luca Berra2011-06-17
| | | | | | | | | | | | | looking at the gpt code in util.c i found i did not like it at all, a gpt partition entry is currently 128 bytes, but the spec does not say it is a fixed value, so the code that reads into a buffer with 512bytes chunk expecting this to be a multiplier of part_size is imho incorrect. my fix was to read each partition entry directly into a struct GPT_part_entry, the advantage is that the code is very simple to read, the disadvantage it is 128 reads of 128 bytes each, which is sub-optimal, but i believe readahead will mitigate this a lot. Signed-off-by: NeilBrown <neilb@suse.de>
* Check all member devices in enough_fdNeilBrown2011-05-23
| | | | | | | | | | | | | | The loop over all member devices in enough_fd could easily stop before it had found all devices. This would cause --re-add to fail incorrectly. So change the loop to be based on the reported number of devices in the device - with a safe-guard limit of 1024. Change some other loops to be more careful too. Reported-by: "Schmidt, Annemarie" <Annemarie.Schmidt@stratus.com> Signed-off-by: NeilBrown <neilb@suse.de>
* Split some of util.c into a new lib.cNeilBrown2011-04-05
| | | | | | | | | 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>
* split name/number maps into separate file.NeilBrown2011-04-05
| | | | | | This reduced some interdependencies between files. Signed-off-by: NeilBrown <neilb@suse.de>
* open_dev_excl: allow device to be read-only.NeilBrown2011-03-24
| | | | | | | | | | For many operations we don't need a writable device. So if opening O_RDWR fails in open_dev_excl, then try again O_RDONLY. If we really needed write, a subsequent operation will failed. But if we didn't, we succeed when otherwise we wouldn't have. Signed-off-by: NeilBrown <neilb@suse.de>
* examine: allows to examine a disk metadata on non-metadata compliant systemsLabun, Marcin2011-03-23
| | | | | | | | | | | | | Allow for loading metadata from disk attached to non-metadata compliant system. Affects mdadm --examine and guess_super. Added ignore_hw_compat in supertype to pass information to load_super handler. If ignore_hw_compat is set the handler should load metadata also from disks that do not comply with metadata requirements (i.e. disk is not attached to native controller, etc). Signed-off-by: Marcin Labun <marcin.labun@intel.com> Signed-off-by: NeilBrown <neilb@suse.de>
* mdmon: don't wait for O_EXCL when shutting down.NeilBrown2011-03-22
| | | | | | | | | | If mdmon is shutting down because there are no devices left to look at, then don't wait 5 seconds for an O_EXCL open, and that can block progress of --grow. Only wait for O_EXCL if we received a signal. Signed-off-by: NeilBrown <neilb@suse.de>
* Warn the user about too small array sizeKrzysztof Wojcik2011-03-14
| | | | | | | | | | | | If single-disk RAID0 or RAID1 array is created, user may preserve data on disk. If array given size covers all partitions on disk, all data will be available on created array. If array size is too small (not covers all partitions), data will be not accessible. This patch introduces warning message during array creation if given size is too small. User may interrupt creation process to avoid data loss. Signed-off-by: Krzysztof Wojcik <krzysztof.wojcik@intel.com> Signed-off-by: NeilBrown <neilb@suse.de>
* dev_open should always open read-only.NeilBrown2011-03-10
| | | | | | | | | | When opening an array to manipulate it we never need to write to the array and sometimes it might be read-only so the open for write will fail. So always open read-only. Reported-by: Adam Kwolek <adam.kwolek@intel.com> Signed-off-by: NeilBrown <neilb@suse.de>
* Various compile fixes.NeilBrown2011-02-01
| | | | | | | Make "make everything" succeed. This fixed some real bugs. Signed-off-by: NeilBrown <neilb@suse.de>
* Allow domain_test to report that no domains were found.NeilBrown2011-02-01
| | | | | | | | | 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>
* Incr: don't exclude 'active' devices from auto inclusion in a container.NeilBrown2011-02-01
| | | | | | | | For containers, it is always appropriate to include a device in the container. Whether it should then be included in an array is a separate question. Signed-off-by: NeilBrown <neilb@suse.de>
* Monitor: do not move partitions to external containerCzarnowska, Anna2011-02-01
| | | | | | | | Arrays on partitions are not supported for external metadata so do not take such spare from native array. Signed-off-by: Anna Czarnowska <anna.czarnowska@intel.com> Signed-off-by: NeilBrown <neilb@suse.de>
* fix extended partition detectionDan Williams2011-01-27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | # mdadm --detail --export /dev/md127p1 Before: MD_LEVEL=raid5 MD_DEVICES=4 MD_METADATA=0.90 After: MD_LEVEL=raid5 MD_DEVICES=4 MD_CONTAINER=/dev/md0 MD_MEMBER=0 MD_UUID=55746a20:925d24a7:4f9bd7e2:9c9a411f We parse the symlink target with a format: ../../block/mdXXX/mdXXXpYY ...and need the second '/' from the end of the string to read detect a 'md' device. Reported-by: Krzysztof Wasilewski <krzysztof.wasilewski@intel.com> Cc: Przemyslaw Czarnowski <przemyslaw.hawrylewicz.czarnowski@intel.com> Signed-off-by: Dan Williams <dan.j.williams@intel.com> Signed-off-by: NeilBrown <neilb@suse.de>
* Use one function chosing spares from containerAnna Czarnowska2011-01-05
| | | | | | | | | | | | | | | | | container_chose_spares in Monitor.c and get_spares_for_grow in super-intel.c do the same thing: search for spares in a container. Another version will also be needed for Incremental so a more general solution is presented here and applied in two previous contexts. Normally domlist==NULL would lead an empty list but this is typically checked earlier so here it is interpreted as "do not test domains". Signed-off-by: Anna Czarnowska <anna.czarnowska@intel.com> Signed-off-by: NeilBrown <neilb@suse.de>
* imsm: set imsm spare uuid to 0Anna Czarnowska2010-12-26
| | | | | | | | | | uuid_match_any is replaced by uuid_zero for imsm spares. Function fixup_container_spare_uuid not needed as it gives unwanted uuid to spares. Signed-off-by: Anna Czarnowska <anna.czarnowska@intel.com> Signed-off-by: NeilBrown <neilb@suse.de>
* Allow a metadata update to have a linked list of allocated spaces.NeilBrown2010-12-16
| | | | | | | | | | | | Sometimes one metadata update will require allocating several larger data structures. As 'monitor' cannot allocate, 'manager' must, so it must be able to attach a list of allocates to the update, and importantly it must be able to easily free them. So add a 'space_list' element to metadata updates where each element on the list starts with a pointer to the next. Signed-off-by: NeilBrown <neilb@suse.de>
* Split fmt_devnum out from devnum2devnameNeilBrown2010-12-16
| | | | | | | Sometimes we want to convert a devnum to a devname without allocating memory. So provide function to do the formatting without allocation. Signed-off-by: NeilBrown <neilb@suse.de>
* Treat feature as experimentalAdam Kwolek2010-11-29
| | | | | | | | | Due to fact that IMSM Windows compatibility was not tested yet, feature has to be treated as experimental until compatibility verification will be performed. Signed-off-by: Adam Kwolek <adam.kwolek@intel.com> Signed-off-by: NeilBrown <neilb@suse.de>
* Monitor: devid should be dev_tAnna Czarnowska2010-11-29
| | | | | | | | For consistency with makedev(). int is not sufficient. Signed-off-by: Anna Czarnowska <anna.czarnowska@intel.com> Signed-off-by: NeilBrown <neilb@suse.de>
* Incremental - avoid including wayward devices.NeilBrown2010-11-29
| | | | | | | | | | | | | | | | | | | If a devices - typically in a mirrored set - is assembled independently of the other devices, and then attempted to be brought back into the set, it could contain inconsistent data. It should not be included. So detect this situation by ensuring that the 'most recent' device is believed to be active by every other device. If a device is wayward, it will only consider fellow wayward devices to be active and will think all others are failed or missing. This patches fixes --incremental, --assemble was done in an earlier patch. Signed-off-by: NeilBrown <neilb@suse.de>
* Initialize st->devnum and st->container_dev in super_by_fdDan Williams2010-11-23
| | | | | | | | Precludes needing to deduce this information later, like in Detail.c and soon in Grow.c. Signed-off-by: Dan Williams <dan.j.williams@intel.com> Signed-off-by: NeilBrown <neilb@suse.de>
* block monitor: freeze spare assignment for external arraysDan Williams2010-11-23
| | | | | | | | | | | | | | | | | | | | | | | In order to support reshape and atomic removal of spares from containers we need to prevent mdmon from activating spares. In the reshape case we additionally need to freeze sync_action while the reshape transaction is initiated with the kernel and recorded in the metadata. When reshaping a raid0 array we need to freeze the array *before* it is transitioned to a redundant raid level. Since sync_action does not exist at this point we extend the '-' prefix of a subarray string to flag mdmon not to activate spares. Mdadm needs to be reasonably certain that the version of mdmon in the system honors this 'freeze' indication. If mdmon is not already active then we assume the version that gets started is the same as the mdadm version. Otherwise, we check the version of mdmon as returned by the extended ping_monitor() operation. This is to catch cases where mdadm is upgraded in the filesystem, but mdmon started in the initramfs is from a previous release. Signed-off-by: Dan Williams <dan.j.williams@intel.com> Signed-off-by: NeilBrown <neilb@suse.de>
* Provide a mdstat_ent to subarray helperDan Williams2010-11-23
| | | | | | | ...before introducing another open coded instace of this conversion. Signed-off-by: Dan Williams <dan.j.williams@intel.com> Signed-off-by: NeilBrown <neilb@suse.de>
* Util: get device size from idAnna Czarnowska2010-11-22
| | | | | Signed-off-by: Anna Czarnowska <anna.czarnowska@intel.com> Signed-off-by: NeilBrown <neilb@suse.de>
* Add must_be_container helper.NeilBrown2010-11-22
| | | | | | | This checks a block device to see if it could be a container, and in particular cannot be a member device. Signed-off-by: NeilBrown <neilb@suse.de>
* Switch open_subarray to use the new load_containerNeilBrown2010-11-22
| | | | | | This removes another user of loaded_container Signed-off-by: NeilBrown <neilb@suse.de>
* Use new load_container in ExamineNeilBrown2010-11-22
| | | | | | | This makes explicit the two different ways to use Examine And removes a user of container_loaded. Signed-off-by: NeilBrown <neilb@suse.de>
* Remove subarray field in supertype.NeilBrown2010-11-22
| | | | | | | This is now only ever set, never used. So remove it. Signed-off-by: NeilBrown <neilb@suse.de>
* Create: user container_dev rather than subarray for some tests.NeilBrown2010-11-22
| | | | | | | | | It makes more sense to test for container_dev than for subarray for several places in Create where it then uses container_dev. This allows us to subsequently remove subarray. Signed-off-by: NeilBrown <neilb@suse.de>
* Pass subarray arg explicitly to ->update_subarray.NeilBrown2010-11-22
| | | | | | | This is better than hiding it in the supertype structure where we are never quite sure who needs it. Signed-off-by: NeilBrown <neilb@suse.de>
* super_by_fd: return subarray info explicitly.NeilBrown2010-11-22
| | | | | | | | | Rather than hiding this in the 'st', return it explicitly. In the one case we still need it, copy it into st where needed. This will disappear in a future patch. Signed-off-by: NeilBrown <neilb@suse.de>
* open_subarray: pass subarray name as explicit arg.NeilBrown2010-11-22
| | | | | | | | | | | Rather than hiding this arg in the 'st' structure, pass it explicitly. This is a first step to getting rid of 'subarray' from 'supertype'. The strcpy in open_subarray should have better error checking, but it will disappear soon so there is little point. Signed-off-by: NeilBrown <neilb@suse.de.
* get_info_super: report which other devices are thought to be working/failed.NeilBrown2010-11-22
| | | | | | | | | | | | | | To accurately detect when an array has been split and is now being recombined, we need to track which other devices each thinks is working. We should never include a device in an array if it thinks that the primary device has failed. This patch just allows get_info_super to return a list of devices and whether they are thought to be working or not. Signed-off-by: NeilBrown <neilb@suse.de>
* Manage: be more careful about --add attempts.NeilBrown2010-11-22
| | | | | | | | | If an --add is requested and a re-add looks promising but fails or cannot possibly succeed, then don't try the add. This avoids inadvertently turning devices into spares when an array is failed but the devices seem to actually work. Signed-off-by: NeilBrown <neilb@suse.de>
* Add guess_super_typeNeilBrown2010-09-06
| | | | | | | This can select to only guess array types, or only guess partition types. Signed-off-by: NeilBrown <neilb@suse.de>
* Add gpt pseudo-metadataNeilBrown2010-09-06
| | | | | | This allows mdadm to work with gpt metadata to a limited extent. Signed-off-by: NeilBrown <neilb@suse.de>
* Add mbr pseudo metadata handler.NeilBrown2010-09-06
| | | | | | | | | | | | To support incorpating a new bare device into a collection of arrays - one partition each - mdadm needs a modest understanding of partition tables. The main needs to be able to recognise a partition table on one device and copy it onto another. This will be done using pseudo metadata types 'mbr' and 'gpt'. Signed-off-by: NeilBrown <neilb@suse.de>
* Allow dev_open to work on read-only /devNeilBrown2010-08-30
| | | | | | | | | | /dev could be read-only in which case we cannot make devices there. So dev_open should first try to use an existing device name, and if that doesn't work try creating a node in /dev or /tmp. Reported-by: Paweł Sikora <pluto@agmk.net> Signed-off-by: NeilBrown <neilb@suse.de>
* Compile with -Wextra by defaultNeilBrown2010-08-05
| | | | | | This produced lots of warning, some of which pointed to actual bugs. Signed-off-by: NeilBrown <neilb@suse.de>
* Fix all the confusion over directories once and for all.Doug Ledford2010-07-22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | We now have 3 directory definitions: mdmon directory for its pid and sock files (compile time define, not changable at run time), mdmonitor directory which is for the mdadm monitor mode pid file (can only be passed in via command line at the time mdadm is invoked in monitor mode), and the directory for the mdadm incremental assembly map file (compile time define, not changable at run time). Only the mdadm map file still hunts multiple locations, and the number of locations has been reduced to /var/run and the compile time specified location. Re-use of similar sounding defines that actually didn't denote their actual usage at compile time made it more difficult for a person to know what affect changing the compile time defines would have on the resulting programs. This patch renames the various defines to clearly identify which item the define affects. It also reduces the number of various directories which will be searched for these files as this has lead to confusion in mdadm and mdmon in terms of which files should take precedence when files exist in multiple locations, etc. It's best if the person compiling the program intentionally and with planning selects the right directories to be used for the various purposes. Which directory is right depends on which items you are talking about and what boot loader your system uses and what initramfs generation program your system uses. Because of the inter-dependency of all these items it would typically be up to the distribution that mdadm is being integrated into to select the correct values for these defines. Signed-off-by: Doug Ledford <dledford@redhat.com>
* Incremental: restore assembly for inactive containers, block activeDan Williams2010-07-19
| | | | | | | GET_ARRAY_INFO always succeeds on an inactive container, so we need to be a bit more diligent about adding a disk to an active container. Signed-off-by: Dan Williams <dan.j.williams@intel.com>
* Merge branch 'fixes' into for-neilDan Williams2010-07-01
|\
| * fix: memory leak in mdmon_pid()Przemyslaw Hawrylewicz Czarnowski2010-05-17
| | | | | | | | | | | | | | | | devnum2devname() returns pointer to memory allocated with strdup. It must be released to prevent memory leak. Signed-off-by: Przemyslaw Czarnowski <przemyslaw.hawrylewicz.czarnowski@intel.com> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
* | Kill subarray v2Dan Williams2010-06-15
|/ | | | | | | | | | | | | | | | | | | | | | | | | Support for deleting a subarray out of a container. When all subarrays are deleted the component devices are converted back into spares, a --zero-superblock is still needed to kill the remaining metadata at this point. This operation is blocked when the subarray is active and may also be blocked by the metadata handler when deleting the subarray might change the uuid of other active subarrays. For example, with imsm, deleting subarray 'n' may change the uuid of subarrays with indexes > n. Deleting a subarray needs to be a container wide event to ensure disks that record the modified subarray list perceive other disks that did not receive this change as out of date. Notes: The st->subarray parsing in super-intel.c and super-ddf.c is updated to be more strict now that we are reading user supplied subarray values. Offline container modification shares actions that mdmon typically handles so promote is_container_member() and version_to_superswitch() (formerly find_metadata_methods()) to generic utility functions for the cases where mdadm performs the operation. Signed-off-by: Dan Williams <dan.j.williams@intel.com>
* IMSM/DDF: don't recognised these metadata on partitions.NeilBrown2010-04-29
| | | | | | | | | | | These metadata are not expected on partitions, and they have no way of differentiation whether which is correct if they are found both on the device and on the last partition. So if the device is a partition, refuse to read the metadata. Signed-off-by: NeilBrown <neilb@suse.de>
* (no commit message)NeilBrown2010-03-24
|
* Improve partition table code.NeilBrown2010-03-09
| | | | | | | | | | Code to check partition tables used some needless casts and was broken, using a u8 when a u32 was wanted. So create structure describing the tables rather than using offset, and read into those tables instead. Signed-off-by: NeilBrown <neilb@suse.de>
* fix mdmon takeoverLuca Berra2010-03-03
| | | | | | | | | | | - when we waited for the old mdmon to exit, we didn't look for the socket in the right place - when we failed to find a pid file, we returned the wrong value (code expected <0, but got ==0). Signed-off-by: Luca Berra <bluca@comedia.it> Signed-off-by: NeilBrown <neilb@suse.de>
* fix gcc warnings about strict-aliasing rulesNeilBrown2010-03-03
| | | | | Original-by: Luca Berra <bluca@comedia.it> Signed-off-by: NeilBrown <neilb@suse.de>