Commit Graph

3414 Commits

Author SHA1 Message Date
Jes Sorensen 48bc2ade86 Monitor/check_array: Obtain RAID level from syfs
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2017-05-09 16:52:44 -04:00
Jes Sorensen aed5f5c34c Monitor/check_array: Read sysfs entry earlier
This will allow us to pull additional info from sysfs, such as level
and device info.

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2017-05-09 16:51:41 -04:00
Jes Sorensen 826522f0dc Monitor/check_array: Declate mdinfo instance globally
We can pull in more information from sysfs earlier, so move sra to the top.

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2017-05-09 16:41:06 -04:00
Jes Sorensen 13e5d8455c Monitor/check_array: Reduce duplicated error handling
Avoid closing fd in multiple places, and duplicating the error message
for when a device disappeared.

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2017-05-09 16:38:06 -04:00
Jes Sorensen 1830e74b4c Monitor/check_array: Centralize exit path
Improve exit handling to make it easier to share error handling and free
sysfs entries later.

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2017-05-09 16:25:23 -04:00
Alexey Obitotskiy 4b57ecf6ce Add sector size as spare selection criterion
Add sector size as new spare selection criterion. Assume that 0 means
there is no requirement for the sector size in the array. Skip disks
with unsuitable sector size when looking for a spare to move across
containers.

Signed-off-by: Alexey Obitotskiy <aleksey.obitotskiy@intel.com>
Signed-off-by: Tomasz Majchrzak <tomasz.majchrzak@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2017-05-09 14:18:38 -04:00
Alexey Obitotskiy fbfdcb06dc Allow more spare selection criteria
Disks can be moved across containers in order to be used as a spare
drive for reubild. At the moment the only requirement checked for such
disk is its size (if it matches donor expectations). In order to
introduce more criteria rename corresponding superswitch method to more
generic name and move function parameter to a structure. This change is
a big edit but it doesn't introduce any changes in code logic, it just
updates function naming and parameters.

Signed-off-by: Alexey Obitotskiy <aleksey.obitotskiy@intel.com>
Signed-off-by: Tomasz Majchrzak <tomasz.majchrzak@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2017-05-09 14:18:36 -04:00
Alexey Obitotskiy f2cc4f7d82 imsm: don't allow disks with different sector size in one array
As there is no support in IMSM for arrays including disks with different
sector sizes, don't allow to create such configuration. Also skip the
disk with unsuitable sector size when looking for spares in the same
container.

Signed-off-by: Alexey Obitotskiy <aleksey.obitotskiy@intel.com>
Signed-off-by: Tomasz Majchrzak <tomasz.majchrzak@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2017-05-09 14:18:35 -04:00
Alexey Obitotskiy 853375734e imsm: allocate buffer to support maximum sector size
Allocate migration record buffer to support maximum sector size. Disk with
non-matching sector size is not going to be included in the array, however
some preparation/cleanup actions still take place on it and they would
cause a crash. Clear migration record using sector size of the disk (not
array) as they might not match.

Signed-off-by: Alexey Obitotskiy <aleksey.obitotskiy@intel.com>
Signed-off-by: Tomasz Majchrzak <tomasz.majchrzak@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2017-05-09 14:18:33 -04:00
Alexey Obitotskiy 5c5ea85b4d imsm: allow drives in a container regardless of sector size
IMSM doesn't allow to create arrays including drives with different
sector sizes. The initial idea was not to permit to combine drives
with different sector size in the same container. The problem is it
only worked for array creation. On array assemble there are no
calls to metadata handlers to see if drive is suitable for a container
(e.g. as a spare) and it leads to wrong configuration.

Revert the change and allow adding drives with different sector size
to the container.

Signed-off-by: Alexey Obitotskiy <aleksey.obitotskiy@intel.com>
Signed-off-by: Tomasz Majchrzak <tomasz.majchrzak@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2017-05-09 14:17:50 -04:00
Zhilong Liu 17645275ca mdadm/md.4: set page-length as 1000 to avoid warnings from grotty
"nroff" ("man") or ("tbl") needs a long page to avoid warnings
from "grotty", set 'pl' as 1000 to fix the following issue.

This command invokes by Makefile rule.
linux-tjrh:~/mdadm # man -l md.4 > test
grotty:<standard input> (<standard input>):5967:
character above first line discarded
... ...

Signed-off-by: Zhilong Liu <zlliu@suse.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2017-05-09 10:52:38 -04:00
Jes Sorensen f27904a53b Monitor: Code is 80 characters per line
Fix up some lines that are too long for no reason, and some that have
silly line breaks.

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2017-05-08 17:52:10 -04:00
Jes Sorensen b9a0309c7f Monitor: Use md_array_active() instead of manually fiddling in sysfs
This removes a pile of clutter that can easily behandled with a simple
check of array_state.

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2017-05-08 17:41:00 -04:00
NeilBrown 4224685fe9 Mention "endian" in documentation for --update=byte-order
This makes it easier to find as "endian" is a commonly used term.

Reported-by: Trevor Cordes <trevor@tecnopolis.ca>
Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2017-05-08 13:38:04 -04:00
Jes Sorensen 00e56fd953 IncrementalScan: Use md_array_active() instead of md_get_array_info()
This eliminates yet another case where GET_ARRAY_INFO was used to
indicate whether the array was active.

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2017-05-05 12:18:29 -04:00
Jes Sorensen 74d293a253 container_members_max_degradation: Switch to using syfs for disk info
With sysfs now providing the necessary active_disks info, switch to
sysfs and eliminate one more use of md_get_array_info(). We can do
this unconditionally since we wouldn't get here witout sysfs being
available.

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2017-05-05 12:06:57 -04:00
Jes Sorensen 64ec81da7a sysfs/sysfs_read: Count active_disks and failed_disks
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>
2017-05-05 11:51:43 -04:00
Jes Sorensen c2d1a6ec6b Incremental: return is not a function
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2017-05-05 11:39:58 -04:00
NeilBrown dd180cb136 Fix typo in new udev rule.
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: cd6cbb08c4 ("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>
2017-05-05 11:07:00 -04:00
Zhilong Liu 9e04ac1c43 mdadm/util: unify stat checking blkdev into function
declare function stat_is_blkdev() to integrate repeated stat
checking blkdev operations, it returns 'true/1' when it is a
block device, and returns 'false/0' when it isn't.
The devname is necessary parameter, *rdev is optional, parse
the pointer of dev_t *rdev, if valid, assigned device number
to dev_t *rdev, if NULL, ignores.

Signed-off-by: Zhilong Liu <zlliu@suse.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2017-05-05 11:05:32 -04:00
Zhilong Liu 0a6bff09d4 mdadm/util: unify fstat checking blkdev into function
declare function fstat_is_blkdev() to integrate repeated fstat
checking block device operations, it returns true/1 when it is
a block device, and returns false/0 when it isn't.
The fd and devname are necessary parameters, *rdev is optional,
parse the pointer of dev_t *rdev, if valid, assigned the device
number to dev_t *rdev, if NULL, ignores.

Signed-off-by: Zhilong Liu <zlliu@suse.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2017-05-05 11:04:02 -04:00
Jes Sorensen 935795398d mdassemble: Kill off the last remains
Having gotten rid of mdassemble, lets get rid of the man page too

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2017-05-04 11:57:41 -04:00
Jes Sorensen 2b7bddf06c kernel-patch: Remove obsolete kernel patches against 2.6
While we still support some of these kernels, I do not think it makes
sense to carry this patches around at this point.

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2017-05-04 11:39:05 -04:00
Jes Sorensen 9db2ab4e9b util: md_array_valid(): Introduce md_array_valid() helper
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>
2017-05-03 16:15:16 -04:00
Zhilong Liu 99148c19bd change back 0644 permission for Grow.c
Fixes commit:
26714713cd ("mdadm: Change timestamps to unsigned data type.")

Signed-off-by: Zhilong Liu <zlliu@suse.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2017-05-03 10:50:59 -04:00
Jes Sorensen 9e4524df1c Grow: Grow_continue_command: Avoid aliasing array variable
While this would cause a warning since the two are different types,
lets avoid aliasing an existing variable.

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2017-05-02 11:46:49 -04:00
Pawel Baldysiak 2a24dc1b09 IMSM: Initialize my_vol_raid_dev_num during vol creation
This field was not initialized so far. This ID needs to be unique
for every newly created array in container.

Signed-off-by: Pawel Baldysiak <pawel.baldysiak@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2017-05-02 10:48:24 -04:00
Jes Sorensen 80223cb4db Manage: Manage_ro(): Use md_array_active()
One call less to md_get_array_info() for determining whether an array
is active or not.

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2017-05-02 10:41:23 -04:00
Jes Sorensen 6921010d95 Incremental: Use md_array_active() to determine state of array
One less call to md_get_array_info()

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2017-05-02 10:36:51 -04:00
NeilBrown cd6cbb08c4 Create: tell udev md device is not ready when first created.
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>
2017-05-02 09:41:39 -04:00
Jes Sorensen f8c432bfc9 Incremental: Cleanup some if() statement spaghetti
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2017-04-25 15:07:26 -04:00
Jes Sorensen ff4ad24b1c Incremental: Use md_array_active() where applicable
md_get_array_info() == 0 implies an array is active, however this is more
correct.

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2017-04-25 14:57:46 -04:00
Jes Sorensen 0885b942b3 Detail: Reinstate support for not having sysfs
While sysfs support will hopefully go away eventually, lets not break
it unnecessarily for now.

Fixes: 901d5ee ("Detail: Stop bothering about md drivers older than 0.90.00")
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2017-04-25 14:34:31 -04:00
Jes Sorensen 5737086ed7 Detail: Respect code lines are 80 character wide
In addition apply spaces and don'f do 'if () action()' on the same line.

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2017-04-25 12:21:39 -04:00
Jes Sorensen a4dcdb23ea Detail: determine array state from sysfs
This is easily obtained from sysfs as part of the existing call to
sysfs_read() and it simplifies the code a little too.

Another small step in the process of getting rid of the GET_ARRAY_STATE
ioctl.

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2017-04-25 11:40:27 -04:00
Artur Paszkiewicz b75805662e Don't use UnSet with consistency_policy
Use CONSISTENCY_POLICY_UNKNOWN instead. Simplify some checks because
since 5e8e35fb7e ("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>
2017-04-24 17:10:56 -04:00
Jes Sorensen 4a4379b054 maps: Simplify implementation of map_name()
Reported-By: NeilBrown <neilb@suse.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2017-04-21 12:11:21 -04:00
Jes Sorensen 966188e959 maps: Remove incorrect comment about strcmp()
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2017-04-21 12:09:12 -04:00
Jes Sorensen 17d80e6eb6 Makefile: Default to -O2 optimization
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2017-04-21 12:06:35 -04:00
Jes Sorensen 0dfff0f243 Query: Quiet gcc since it cannot know errno != 0 in this case
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2017-04-21 12:04:05 -04:00
NeilBrown b9c9bd9bac Detail: ensure --export names are acceptable as shell variables.
If an array contains a device which has a name that
contains something other than alphnumerics and underscores,
then some values reported by "mdadm --detail --export" will
not be valid as variable assignment of the shell.
This particularly affects dm devices.
e.g.
   MD_DEVICE_dm-4_ROLE=1
   MD_DEVICE_dm-4_DEV=/dev/dm-4

As it is particularly useful to be able to work with these
in a shell script, and as the precise name is not important,
change all non-alphanumerics to '_'.

   MD_DEVICE_dm_4_ROLE=1
   MD_DEVICE_dm_4_DEV=/dev/dm-4

Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2017-04-20 12:59:22 -04:00
NeilBrown 5c4b3b9aa9 systemd/mdadm-last-resort: use ConditionPathExists instead of Conflicts
Commit cec72c071b ("systemd/mdadm-last-resort: add Conflicts to .service file.")

added a 'Conflicts' directive to the mdadm-last-resort@.service file in
the hope that this would make sure the service didn't run after the device
was active, even if the timer managed to get started, which is possible in
race conditions.

This seemed to work is testing, but it isn't clear why, and it is known
to cause problems.
If systemd happens to know that the mentioned device is a dependency of a
mount point, the Conflicts can unmount that mountpoint, which is certainly
not wanted.

So remove the "Conflicts" and instead use
 ConditionPathExists=!/sys/devices/virtual/block/%i/md/sync_action

The "sync_action" file exists for any array which requires last-resort
handling, and only appears when the array is activated.  So it is safe
to rely on it to determine if the last-resort is really needed.

Fixes: cec72c071b ("systemd/mdadm-last-resort: add Conflicts to .service file.")
Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2017-04-20 12:57:27 -04:00
NeilBrown a250ce240f Grow_continue_command: ensure 'content' is properly initialised.
Grow_continue_command() call verify_reshape_position(), which assumes
that info->sys_name is initialised.
'info' in verify_reshape_position() is 'content' in Grow_continue_command().

In the st->ss->external != 0 branch of that function, sysfs_init() is called
to initialize content->sys_name.
In the st->ss->external == 0 branch, ->sys_name is not initialized so
verify_reshape_position() will not do the right thing.

Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2017-04-20 12:56:21 -04:00
Coly Li b63804583e mdadm: retire mdassemble in make everything
make everything reports no rule to make mdassemble, because mdassemble
is removed from mdadm. This patch removes mdassemble from "everything"
in Makefile, now there is no failure when compiling a static mdadm binary.

Signed-off-by: Coly Li <colyli@suse.de>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2017-04-20 12:28:32 -04:00
Jes Sorensen 44356754ec util: Get rid of unused enough_fd()
enough_fd() is no longer used, so lets get rid of it.

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2017-04-20 11:53:30 -04:00
Jes Sorensen 5e8e35fb7e maps: Use keyvalue for null terminator to indicate 'unset' value
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>
2017-04-20 00:27:42 -04:00
Jes Sorensen e47781fcea maps: Terminate 'modes' map correctly.
While we are unlikely to fail here, terminate the modes map correctly
to ensure we don't start running over undefined data.

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2017-04-20 00:13:31 -04:00
Jes Sorensen 3ab8f4bf33 util: Introduce md_array_active() helper
Rather than querying md_get_array_info() to determine whether an array
is valid, do the work in md_array_active() using sysfs, and fall back
on md_get_array_info() if sysfs fails.

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2017-04-20 00:12:34 -04:00
Jes Sorensen 5e4ca8bb82 sysfs: Parse array_state in sysfs_read()
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>
2017-04-20 00:12:27 -04:00
Jes Sorensen f22d6cde7c Query: Use sysfs to obtain data if possible
Use sysfs to obtain leve, raid_disks, and spare_disks. If sysfs fails,
fall back to calling the ioctl via md_get_array_info().

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2017-04-13 12:20:46 -04:00