]> git.ipfire.org Git - thirdparty/mdadm.git/log
thirdparty/mdadm.git
6 years agoAllow more spare selection criteria
Alexey Obitotskiy [Tue, 9 May 2017 10:25:46 +0000 (12:25 +0200)] 
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>
6 years agoimsm: don't allow disks with different sector size in one array
Alexey Obitotskiy [Tue, 9 May 2017 10:25:45 +0000 (12:25 +0200)] 
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>
6 years agoimsm: allocate buffer to support maximum sector size
Alexey Obitotskiy [Tue, 9 May 2017 10:25:44 +0000 (12:25 +0200)] 
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>
6 years agoimsm: allow drives in a container regardless of sector size
Alexey Obitotskiy [Tue, 9 May 2017 10:25:43 +0000 (12:25 +0200)] 
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>
6 years agomdadm/md.4: set page-length as 1000 to avoid warnings from grotty
Zhilong Liu [Tue, 9 May 2017 06:25:17 +0000 (14:25 +0800)] 
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>
6 years agoMonitor: Code is 80 characters per line
Jes Sorensen [Mon, 8 May 2017 21:52:10 +0000 (17:52 -0400)] 
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>
6 years agoMonitor: Use md_array_active() instead of manually fiddling in sysfs
Jes Sorensen [Mon, 8 May 2017 21:34:08 +0000 (17:34 -0400)] 
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>
6 years agoMention "endian" in documentation for --update=byte-order
NeilBrown [Sun, 7 May 2017 23:40:09 +0000 (09:40 +1000)] 
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>
6 years agoIncrementalScan: Use md_array_active() instead of md_get_array_info()
Jes Sorensen [Fri, 5 May 2017 16:18:29 +0000 (12:18 -0400)] 
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>
6 years agocontainer_members_max_degradation: Switch to using syfs for disk info
Jes Sorensen [Fri, 5 May 2017 16:06:57 +0000 (12:06 -0400)] 
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>
6 years agosysfs/sysfs_read: Count active_disks and failed_disks
Jes Sorensen [Fri, 5 May 2017 15:51:43 +0000 (11:51 -0400)] 
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>
6 years agoIncremental: return is not a function
Jes Sorensen [Fri, 5 May 2017 15:39:58 +0000 (11:39 -0400)] 
Incremental: return is not a function

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
6 years agoFix typo in new udev rule.
NeilBrown [Fri, 5 May 2017 05:16:15 +0000 (15:16 +1000)] 
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: 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>
6 years agomdadm/util: unify stat checking blkdev into function
Zhilong Liu [Fri, 5 May 2017 03:09:41 +0000 (11:09 +0800)] 
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>
6 years agomdadm/util: unify fstat checking blkdev into function
Zhilong Liu [Thu, 4 May 2017 12:16:21 +0000 (20:16 +0800)] 
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>
6 years agomdassemble: Kill off the last remains
Jes Sorensen [Thu, 4 May 2017 15:57:41 +0000 (11:57 -0400)] 
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>
6 years agokernel-patch: Remove obsolete kernel patches against 2.6
Jes Sorensen [Thu, 4 May 2017 15:39:05 +0000 (11:39 -0400)] 
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>
6 years agoutil: md_array_valid(): Introduce md_array_valid() helper
Jes Sorensen [Wed, 3 May 2017 18:25:57 +0000 (14:25 -0400)] 
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>
6 years agochange back 0644 permission for Grow.c
Zhilong Liu [Tue, 2 May 2017 09:27:13 +0000 (17:27 +0800)] 
change back 0644 permission for Grow.c

Fixes commit:
26714713cd2b ("mdadm: Change timestamps to unsigned data type.")

Signed-off-by: Zhilong Liu <zlliu@suse.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
6 years agoGrow: Grow_continue_command: Avoid aliasing array variable
Jes Sorensen [Tue, 2 May 2017 15:46:49 +0000 (11:46 -0400)] 
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>
6 years agoIMSM: Initialize my_vol_raid_dev_num during vol creation
Pawel Baldysiak [Wed, 26 Apr 2017 09:08:07 +0000 (11:08 +0200)] 
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>
6 years agoManage: Manage_ro(): Use md_array_active()
Jes Sorensen [Tue, 2 May 2017 14:40:07 +0000 (10:40 -0400)] 
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>
6 years agoIncremental: Use md_array_active() to determine state of array
Jes Sorensen [Tue, 2 May 2017 14:36:51 +0000 (10:36 -0400)] 
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>
6 years agoCreate: tell udev md device is not ready when first created.
NeilBrown [Fri, 28 Apr 2017 05:05:50 +0000 (15:05 +1000)] 
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>
7 years agoIncremental: Cleanup some if() statement spaghetti
Jes Sorensen [Tue, 25 Apr 2017 19:01:43 +0000 (15:01 -0400)] 
Incremental: Cleanup some if() statement spaghetti

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
7 years agoIncremental: Use md_array_active() where applicable
Jes Sorensen [Tue, 25 Apr 2017 18:57:46 +0000 (14:57 -0400)] 
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>
7 years agoDetail: Reinstate support for not having sysfs
Jes Sorensen [Tue, 25 Apr 2017 18:34:31 +0000 (14:34 -0400)] 
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>
7 years agoDetail: Respect code lines are 80 character wide
Jes Sorensen [Tue, 25 Apr 2017 16:21:39 +0000 (12:21 -0400)] 
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>
7 years agoDetail: determine array state from sysfs
Jes Sorensen [Tue, 25 Apr 2017 15:40:27 +0000 (11:40 -0400)] 
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>
7 years agoDon't use UnSet with consistency_policy
Artur Paszkiewicz [Mon, 24 Apr 2017 14:03:26 +0000 (16:03 +0200)] 
Don't use UnSet with consistency_policy

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>
7 years agomaps: Simplify implementation of map_name()
Jes Sorensen [Fri, 21 Apr 2017 16:11:21 +0000 (12:11 -0400)] 
maps: Simplify implementation of map_name()

Reported-By: NeilBrown <neilb@suse.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
7 years agomaps: Remove incorrect comment about strcmp()
Jes Sorensen [Fri, 21 Apr 2017 16:09:12 +0000 (12:09 -0400)] 
maps: Remove incorrect comment about strcmp()

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
7 years agoMakefile: Default to -O2 optimization
Jes Sorensen [Fri, 21 Apr 2017 16:06:35 +0000 (12:06 -0400)] 
Makefile: Default to -O2 optimization

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
7 years agoQuery: Quiet gcc since it cannot know errno != 0 in this case
Jes Sorensen [Fri, 21 Apr 2017 16:04:05 +0000 (12:04 -0400)] 
Query: Quiet gcc since it cannot know errno != 0 in this case

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
7 years agoDetail: ensure --export names are acceptable as shell variables.
NeilBrown [Thu, 20 Apr 2017 02:40:06 +0000 (12:40 +1000)] 
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>
7 years agosystemd/mdadm-last-resort: use ConditionPathExists instead of Conflicts
NeilBrown [Thu, 20 Apr 2017 02:40:05 +0000 (12:40 +1000)] 
systemd/mdadm-last-resort: use ConditionPathExists instead of Conflicts

Commit cec72c071bbe ("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: cec72c071bbe ("systemd/mdadm-last-resort: add Conflicts to .service file.")
Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
7 years agoGrow_continue_command: ensure 'content' is properly initialised.
NeilBrown [Thu, 20 Apr 2017 02:40:05 +0000 (12:40 +1000)] 
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>
7 years agomdadm: retire mdassemble in make everything
Coly Li [Sun, 16 Apr 2017 07:01:29 +0000 (15:01 +0800)] 
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>
7 years agoutil: Get rid of unused enough_fd()
Jes Sorensen [Thu, 20 Apr 2017 15:53:30 +0000 (11:53 -0400)] 
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>
7 years agomaps: Use keyvalue for null terminator to indicate 'unset' value
Jes Sorensen [Thu, 20 Apr 2017 04:19:44 +0000 (00:19 -0400)] 
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>
7 years agomaps: Terminate 'modes' map correctly.
Jes Sorensen [Thu, 20 Apr 2017 04:13:31 +0000 (00:13 -0400)] 
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>
7 years agoutil: Introduce md_array_active() helper
Jes Sorensen [Thu, 13 Apr 2017 17:30:17 +0000 (13:30 -0400)] 
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>
7 years agosysfs: Parse array_state in sysfs_read()
Jes Sorensen [Thu, 20 Apr 2017 03:27:58 +0000 (23:27 -0400)] 
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>
7 years agoQuery: Use sysfs to obtain data if possible
Jes Sorensen [Thu, 13 Apr 2017 16:20:46 +0000 (12:20 -0400)] 
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>
7 years agoQuery: Handle error returned by fstat()
Jes Sorensen [Thu, 13 Apr 2017 15:53:21 +0000 (11:53 -0400)] 
Query: Handle error returned by fstat()

We shouldn't ignore any error returned by fstat() even if open() didn't
fail.

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
7 years agoDetail: Fixup ugly if () foo() abuse
Jes Sorensen [Wed, 12 Apr 2017 21:05:55 +0000 (17:05 -0400)] 
Detail: Fixup ugly if () foo() abuse

Cosmetic change only

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
7 years agoAssemble: Remove obsolete test for kernels older than 2.4
Jes Sorensen [Wed, 12 Apr 2017 18:50:02 +0000 (14:50 -0400)] 
Assemble: Remove obsolete test for kernels older than 2.4

We only support 2.6.15+ at this point

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
7 years agoDetail: Remove pre-2.6 code for printing info on rebuilding
Jes Sorensen [Wed, 12 Apr 2017 18:48:10 +0000 (14:48 -0400)] 
Detail: Remove pre-2.6 code for printing info on rebuilding

Since we no longer support anything pre-2.6.15, there is no point in
keeping this around.

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
7 years agoAssemble: Clean up start_array()
Jes Sorensen [Wed, 12 Apr 2017 18:23:45 +0000 (14:23 -0400)] 
Assemble: Clean up start_array()

This is purely cosmetic, no codeflow changes.

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
7 years agomdadm/manpage:clustered arrays don't support array-size yet
Zhilong Liu [Wed, 12 Apr 2017 08:37:27 +0000 (16:37 +0800)] 
mdadm/manpage:clustered arrays don't support array-size yet

Update manpage for array-size section:
Clustered arrays don't support the --array-size yet.

Signed-off-by: Zhilong Liu <zlliu@suse.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
7 years agomdadm/manpage:update manpage for readonly parameter
Zhilong Liu [Wed, 12 Apr 2017 08:36:38 +0000 (16:36 +0800)] 
mdadm/manpage:update manpage for readonly parameter

update readonly in manpage:
Currently both the readwrite and readonly are worked well,
update the readonly section.
One commit in linux/driver/md. Cleared "MD_CLOSING bit" to
Fixes: af8d8e6f0315 ("md: changes for MD_STILL_CLOSED flag")
Signed-off-by: Zhilong Liu <zlliu@suse.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
7 years agomdopen: use parameters/new_array to create arrays whenever possible.
NeilBrown [Wed, 12 Apr 2017 06:29:04 +0000 (16:29 +1000)] 
mdopen: use parameters/new_array to create arrays whenever possible.

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>
7 years agosuper1: Clean up various style abuses
Jes Sorensen [Tue, 11 Apr 2017 18:25:24 +0000 (14:25 -0400)] 
super1: Clean up various style abuses

Code is 80 characters wide, so lets try to respect that. In addition, we
should never have one-line 'if () action()' statements. Fixup various
whitespace abuse.

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
7 years agoRetire mdassemble
Jes Sorensen [Tue, 11 Apr 2017 16:54:26 +0000 (12:54 -0400)] 
Retire mdassemble

mdassemble doesn't handle container based arrays, no support for sysfs,
etc. It has not been actively maintained for years, so time to send it
off to retirement.

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
7 years agoRevert "mdadm/grow: reshape would be stuck from raid1 to raid5"
Jes Sorensen [Tue, 11 Apr 2017 15:30:23 +0000 (11:30 -0400)] 
Revert "mdadm/grow: reshape would be stuck from raid1 to raid5"

This reverts commit 5b2846684ef5172eccc432e3520b79efbc2abba5.

This was a red herring and shouldn't have been applied in the first
place.

Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
7 years agomdadm.c:fix compile warning "mdfd is uninitialized"
Zhilong Liu [Mon, 10 Apr 2017 04:49:52 +0000 (12:49 +0800)] 
mdadm.c:fix compile warning "mdfd is uninitialized"

Initialized the mdfd as -1 to prevent compile error
of some compilers.
For example, gcc version 4.8.5(SUSE Linux).

Signed-off-by: Zhilong Liu <zlliu@suse.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
7 years agomdadm: Fail for kernels older than 2.6.15
Jes Sorensen [Thu, 6 Apr 2017 19:46:31 +0000 (15:46 -0400)] 
mdadm: Fail for kernels older than 2.6.15

With the removal of old kernel API support, mdadm will no longer run
on kernels older than 2.6.15.

Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
7 years agoutil: Finally kill off md_get_version()
Jes Sorensen [Wed, 5 Apr 2017 19:49:18 +0000 (15:49 -0400)] 
util: Finally kill off md_get_version()

Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
7 years agoAssemble/Assemble: Get rid of last use of md_get_version()
Jes Sorensen [Wed, 5 Apr 2017 19:47:37 +0000 (15:47 -0400)] 
Assemble/Assemble: Get rid of last use of md_get_version()

At this point in the code, we know we have a valid array, and any
recent kernel will return 9003, so no point in querying the kernel for
this.

Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
7 years agomdassemble: Use md_get_array_info() to check for valid array
Jes Sorensen [Wed, 5 Apr 2017 19:46:35 +0000 (15:46 -0400)] 
mdassemble: Use md_get_array_info() to check for valid array

Get rid of another use of md_get_version()

Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
7 years agomdopen/open_mddev: Use md_get_array_info() to determine valid array
Jes Sorensen [Wed, 5 Apr 2017 19:44:20 +0000 (15:44 -0400)] 
mdopen/open_mddev: Use md_get_array_info() to determine valid array

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>
7 years agomdmon: Stop bothering about md_get_version()
Jes Sorensen [Wed, 5 Apr 2017 19:39:51 +0000 (15:39 -0400)] 
mdmon: Stop bothering about md_get_version()

If anyone has a kernel with md driver older than 0.90.03 they will
also know where to find older versions of mdadm.

Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
7 years agobitmap: Remove use of md_get_version()
Jes Sorensen [Wed, 5 Apr 2017 19:38:48 +0000 (15:38 -0400)] 
bitmap: Remove use of md_get_version()

Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
7 years agoQuery: Remove all references to md_get_version()
Jes Sorensen [Wed, 5 Apr 2017 19:37:38 +0000 (15:37 -0400)] 
Query: Remove all references to md_get_version()

More legacy code removed

Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
7 years agoManage: Remove all references to md_get_version()
Jes Sorensen [Wed, 5 Apr 2017 19:34:44 +0000 (15:34 -0400)] 
Manage: Remove all references to md_get_version()

At this point, support for md driver prior to 0.90.03 is going to
disappear.

Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
7 years agoCreate: Remove all attemps to handle md driver older than 0.90.03
Jes Sorensen [Wed, 5 Apr 2017 19:32:40 +0000 (15:32 -0400)] 
Create: Remove all attemps to handle md driver older than 0.90.03

More legacy code moved to the bit-bucket.

Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
7 years agoDetail: Stop bothering about md drivers older than 0.90.00
Jes Sorensen [Wed, 5 Apr 2017 19:26:53 +0000 (15:26 -0400)] 
Detail: Stop bothering about md drivers older than 0.90.00

Remove further handling of md driver version older than 0.90.00

Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
7 years agoGrow: Stop bothering about md driver versions older than 0.90.00
Jes Sorensen [Wed, 5 Apr 2017 19:22:36 +0000 (15:22 -0400)] 
Grow: Stop bothering about md driver versions older than 0.90.00

Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
7 years agoBuild: Stop bothering about supporting md driver older than 0.90.00
Jes Sorensen [Wed, 5 Apr 2017 19:20:52 +0000 (15:20 -0400)] 
Build: Stop bothering about supporting md driver older than 0.90.00

The kernel has been stuck at md driver version 0.90.03 for at least  a
decade. No point in continuing to support the older API.

Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
7 years agoAssemble/Assemble: Stop checking kernel md driver version
Jes Sorensen [Wed, 5 Apr 2017 19:09:18 +0000 (15:09 -0400)] 
Assemble/Assemble: Stop checking kernel md driver version

Any kernel released during the last decade will return 9003 from
md_get_version() so no point in checking that.

Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
7 years agoutil/set_array_info: Simplify code since md_get_version returns a constant
Jes Sorensen [Wed, 5 Apr 2017 19:06:24 +0000 (15:06 -0400)] 
util/set_array_info: Simplify code since md_get_version returns a constant

md_get_version() always returns (0 * 1000) + (90 * 100) + 3, so no
point in calling it.

Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
7 years agoutil/must_be_container: Use sysfs_read(GET_VERSION) to determine valid array
Jes Sorensen [Wed, 5 Apr 2017 18:01:30 +0000 (14:01 -0400)] 
util/must_be_container: Use sysfs_read(GET_VERSION) to determine valid array

Use sysfs_read() instead of ioctl(RAID_VERSION) to determine this is
in fact a valid raid array fd.

Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
7 years agoCreate: Fixup various whitespace issues
Jes Sorensen [Wed, 5 Apr 2017 15:57:30 +0000 (11:57 -0400)] 
Create: Fixup various whitespace issues

Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
7 years agoCreate: Fixup bad placement of logical || && in multi-line if statements
Jes Sorensen [Wed, 5 Apr 2017 15:53:12 +0000 (11:53 -0400)] 
Create: Fixup bad placement of logical || && in multi-line if statements

These always go at the end of the line, never at the front

Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
7 years agomdadm/Create: declaring an existing struct within same function
Zhilong Liu [Sat, 1 Apr 2017 12:51:44 +0000 (20:51 +0800)] 
mdadm/Create: declaring an existing struct within same function

Create:declaring 'struct stat stb' twice within the same
function, rename stb as stb2 when declares 'struct stat'
at the second time.

Signed-off-by: Zhilong Liu <zlliu@suse.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
7 years agosysfs: Make sysfs_init() return an error code
Jes Sorensen [Thu, 30 Mar 2017 20:52:37 +0000 (16:52 -0400)] 
sysfs: Make sysfs_init() return an error code

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>
7 years agosysfs: Use the presence of /sys/block/<dev>/md as indicator of valid device
Jes Sorensen [Thu, 30 Mar 2017 20:02:36 +0000 (16:02 -0400)] 
sysfs: Use the presence of /sys/block/<dev>/md as indicator of valid device

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>
7 years agomdadm.c: fix compile error "switch condition has boolean value"
Gioh Kim [Thu, 30 Mar 2017 16:58:13 +0000 (18:58 +0200)] 
mdadm.c: fix compile error "switch condition has boolean value"

Remove a boolean expression in switch condition
to prevent compile error of some compilers,
for example, gcc version 5.2.1 20151010 (Ubuntu 5.2.1-22ubuntu2).

Signed-off-by: Gioh Kim <gi-oh.kim@profitbricks.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
7 years agoimsm: use rounded size for metadata initialization
Tomasz Majchrzak [Thu, 30 Mar 2017 14:25:41 +0000 (16:25 +0200)] 
imsm: use rounded size for metadata initialization

Array size is rounded to the nearest MB, however number of data stripes
and blocks per disk are calculated using size passed by the user. If
given size is not aligned, there is a mismatch. It's not possible to
assemble raid0 migrated to raid5 since raid5 arrays use number of data
stripes to calculate array size.

Signed-off-by: Tomasz Majchrzak <tomasz.majchrzak@intel.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
7 years agomdadm/grow: reshape would be stuck from raid1 to raid5
Zhilong Liu [Thu, 30 Mar 2017 07:38:08 +0000 (15:38 +0800)] 
mdadm/grow: reshape would be stuck from raid1 to raid5

systemctl doesn't interpret mdadm-grow-continue@.service
correctly due to the wrong argument provided in [service],
it should be corrected %I as %i. Otherwise, if the service
cannot start by systemctl and the reshap progress would be
stuck all time when grows array from raid1 to raid5.

reproduce steps:
./mdadm -CR /dev/md0 -l1 -b internal -n2 /dev/loop[0-1]
./mdadm --grow /dev/md0 -l5 -n3 -a /dev/loop2

Signed-off-by: Zhilong Liu <zlliu@suse.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
7 years agoGrow: Do not shadow an existing variable
Jes Sorensen [Thu, 30 Mar 2017 14:46:01 +0000 (10:46 -0400)] 
Grow: Do not shadow an existing variable

Declaring 'int rv' twice within the same function is asking for
trouble.

Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
7 years agoGrow: Remove unnecessary optimization
Jes Sorensen [Thu, 30 Mar 2017 14:39:29 +0000 (10:39 -0400)] 
Grow: Remove unnecessary optimization

Per explanation by Neil, this optimization of writing "size" to the
attribute of each device, however when reducing the size of devices,
the size change isn't permitted until the array has been shrunk, so
this will fail anyway.

This effectively reverts 65a9798b58b4e4de0157043e2b30a738c27eff43

Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
7 years agomd_u: Remove some unused ioctl declarations
Jes Sorensen [Wed, 29 Mar 2017 19:48:24 +0000 (15:48 -0400)] 
md_u: Remove some unused ioctl declarations

These were no longer used in the code, so get rid of them.

Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
7 years agoutil: Introduce md_set_array_info()
Jes Sorensen [Wed, 29 Mar 2017 19:43:53 +0000 (15:43 -0400)] 
util: Introduce md_set_array_info()

Switch from using ioctl(SET_ARRAY_INFO) to using md_set_array_info()

Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
7 years agoutil: Introduce md_get_disk_info()
Jes Sorensen [Wed, 29 Mar 2017 19:23:50 +0000 (15:23 -0400)] 
util: Introduce md_get_disk_info()

This removes all the inline ioctl calls for GET_DISK_INFO, allowing us
to switch to sysfs in one place, and improves type checking.

Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
7 years agoIncremental: Remove redundant call for GET_ARRAY_INFO
Jes Sorensen [Wed, 29 Mar 2017 18:40:36 +0000 (14:40 -0400)] 
Incremental: Remove redundant call for GET_ARRAY_INFO

The code above just called md_get_array_info() and only reached this
point if it returned an error that isn't ENODEV, so it's pointless to
check this again here.

In addition it was incorrectly retrieving ioctl data into a
mdu_bitmap_file_t instead of mdu_array_info_t.

Fixes: ("8382f19 Add new mode: --incremental")
Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
7 years agoutil: Introduce md_get_array_info()
Jes Sorensen [Wed, 29 Mar 2017 18:35:41 +0000 (14:35 -0400)] 
util: Introduce md_get_array_info()

Remove most direct ioctl calls for GET_ARRAY_INFO, except for one,
which will be addressed in the next patch.

This is the start of the effort to clean up the use of ioctl calls and
introduce a more structured API, which will use sysfs and fall back to
ioctl for backup.

Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
7 years agoGrow: Fixup a pile of cosmetic issues
Jes Sorensen [Wed, 29 Mar 2017 16:15:20 +0000 (12:15 -0400)] 
Grow: Fixup a pile of cosmetic issues

No code change, simply cleanup ugliness.

Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
7 years agoutil: Cosmetic changes
Jes Sorensen [Wed, 29 Mar 2017 16:05:12 +0000 (12:05 -0400)] 
util: Cosmetic changes

Fixup a number of indentation and whitespace issues

Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
7 years agomdadm: Fixup a number of whitespace inconsistency cases
Jes Sorensen [Wed, 29 Mar 2017 16:02:14 +0000 (12:02 -0400)] 
mdadm: Fixup a number of whitespace inconsistency cases

Lots of code lacked whitespaces in assignments, and in other places
had them in the wrong place.

Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
7 years agomdadm: Clean up some ugly multiple actions on single line
Jes Sorensen [Wed, 29 Mar 2017 15:55:19 +0000 (11:55 -0400)] 
mdadm: Clean up some ugly multiple actions on single line

'foo(); continue;' on the same line within a switch statement is
always wrong. Get rid of some of it.

Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
7 years agosuper1: replace hard-coded values with bit definitions
Gioh Kim [Wed, 29 Mar 2017 09:40:33 +0000 (11:40 +0200)] 
super1: replace hard-coded values with bit definitions

Some hard-coded values for disk status are replaced
with bit definitions.

Signed-off-by: Gioh Kim <gi-oh.kim@profitbricks.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
7 years agomdadm.h: struct mdinfo: reorganize ppl elements for better struct packing
Jes Sorensen [Wed, 29 Mar 2017 15:37:27 +0000 (11:37 -0400)] 
mdadm.h: struct mdinfo: reorganize ppl elements for better struct packing

Minor optimization putting ints next to ints for better data
alignment.

Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
7 years agoGrow: support consistency policy change
Artur Paszkiewicz [Wed, 29 Mar 2017 09:54:20 +0000 (11:54 +0200)] 
Grow: support consistency policy change

Extend the --consistency-policy parameter to work also in Grow mode.
Using it changes the currently active consistency policy in the kernel
driver and updates the metadata to make this change permanent. Currently
this supports only changing between "ppl" and "resync" policies, that is
enabling or disabling PPL at runtime.

Signed-off-by: Artur Paszkiewicz <artur.paszkiewicz@intel.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
7 years agoAdd 'ppl' and 'no-ppl' options for --update=
Artur Paszkiewicz [Wed, 29 Mar 2017 09:54:19 +0000 (11:54 +0200)] 
Add 'ppl' and 'no-ppl' options for --update=

This can be used with --assemble for super1 and with --update-subarray
for imsm to enable or disable PPL in the metadata.

Signed-off-by: Artur Paszkiewicz <artur.paszkiewicz@intel.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
7 years agosuper1: PPL support
Artur Paszkiewicz [Wed, 29 Mar 2017 09:54:18 +0000 (11:54 +0200)] 
super1: PPL support

Enable creating and assembling raid5 arrays with PPL for 1.x metadata.

When creating, reserve enough space for PPL and store its size and
location in the superblock and set MD_FEATURE_PPL bit. Write an initial
empty header in the PPL area on each device. PPL is stored in the
metadata region reserved for internal write-intent bitmap, so don't
allow using bitmap and PPL together.

While at it, fix two endianness issues in write_empty_r5l_meta_block()
and write_init_super1().

Signed-off-by: Artur Paszkiewicz <artur.paszkiewicz@intel.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
7 years agoimsm: PPL support
Artur Paszkiewicz [Wed, 29 Mar 2017 09:54:17 +0000 (11:54 +0200)] 
imsm: PPL support

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>
7 years agoDetail: show consistency policy
Artur Paszkiewicz [Wed, 29 Mar 2017 09:54:16 +0000 (11:54 +0200)] 
Detail: show consistency policy

Show the currently enabled consistency policy in the output from
--detail. Add 3 spaces to all existing items in Detail output to align
with "Consistency Policy : ".

Signed-off-by: Artur Paszkiewicz <artur.paszkiewicz@intel.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
7 years agoGeneric support for --consistency-policy and PPL
Artur Paszkiewicz [Wed, 29 Mar 2017 09:54:15 +0000 (11:54 +0200)] 
Generic support for --consistency-policy and PPL

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>
7 years agoDetail: handle non-existent arrays better.
NeilBrown [Mon, 27 Mar 2017 03:36:56 +0000 (14:36 +1100)] 
Detail: handle non-existent arrays better.

If you call "mdadm --detail" with a device file for an array which
doesn't exist, such as by
  mknod /dev/md57 b 9 57
  mdadm --detail /dev/md57

you get an unhelpful message about and inactive RAID0, and return
status is '0'.  This is confusing.

So catch this possibility and print a more useful message, and
return a non-zero status.

Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>