Commit Graph

3344 Commits

Author SHA1 Message Date
Jes Sorensen 091e8e6e06 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>
2017-04-05 15:34:44 -04:00
Jes Sorensen 5f4cc23926 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>
2017-04-05 15:32:40 -04:00
Jes Sorensen 901d5ee6da 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>
2017-04-05 15:29:29 -04:00
Jes Sorensen 6ae8b2b314 Grow: Stop bothering about md driver versions older than 0.90.00
Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
2017-04-05 15:29:29 -04:00
Jes Sorensen e6e5f8f126 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>
2017-04-05 15:29:22 -04:00
Jes Sorensen 6142741d14 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>
2017-04-05 15:09:18 -04:00
Jes Sorensen 700483a223 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>
2017-04-05 15:06:24 -04:00
Jes Sorensen f5c924f441 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>
2017-04-05 14:01:30 -04:00
Jes Sorensen 98dbf73cba Create: Fixup various whitespace issues
Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
2017-04-05 11:57:30 -04:00
Jes Sorensen cf622ec1d8 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>
2017-04-05 11:53:12 -04:00
Zhilong Liu 230a0dde09 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>
2017-04-05 11:47:04 -04:00
Jes Sorensen dae131379f 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>
2017-03-30 16:52:37 -04:00
Jes Sorensen 67a02d5200 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>
2017-03-30 16:02:36 -04:00
Gioh Kim 13428e2e76 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>
2017-03-30 13:46:14 -04:00
Tomasz Majchrzak b53bfba611 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>
2017-03-30 11:54:53 -04:00
Zhilong Liu 5b2846684e 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>
2017-03-30 11:49:44 -04:00
Jes Sorensen 49948a3561 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>
2017-03-30 10:46:01 -04:00
Jes Sorensen 758b327cf5 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 65a9798b58

Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
2017-03-30 10:44:36 -04:00
Jes Sorensen b0ba6a1dee 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>
2017-03-29 15:48:24 -04:00
Jes Sorensen 018a488238 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>
2017-03-29 15:43:53 -04:00
Jes Sorensen d97572f5a5 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>
2017-03-29 15:23:50 -04:00
Jes Sorensen 5b13d2e1fb 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>
2017-03-29 14:40:36 -04:00
Jes Sorensen 9cd39f0155 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>
2017-03-29 14:35:41 -04:00
Jes Sorensen 6ebf34e6bd Grow: Fixup a pile of cosmetic issues
No code change, simply cleanup ugliness.

Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
2017-03-29 12:15:20 -04:00
Jes Sorensen efa295309f util: Cosmetic changes
Fixup a number of indentation and whitespace issues

Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
2017-03-29 12:05:12 -04:00
Jes Sorensen 8ea982179a 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>
2017-03-29 12:02:14 -04:00
Jes Sorensen ed18099698 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>
2017-03-29 11:55:19 -04:00
Gioh Kim aa31311836 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>
2017-03-29 11:40:40 -04:00
Jes Sorensen a86b1c8d15 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>
2017-03-29 11:37:27 -04:00
Artur Paszkiewicz 860f11ed4d 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>
2017-03-29 11:35:16 -04:00
Artur Paszkiewicz e6e9dd3f1b 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>
2017-03-29 11:35:07 -04:00
Artur Paszkiewicz e97a7cd011 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>
2017-03-29 11:33:52 -04:00
Artur Paszkiewicz 2432ce9b32 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>
2017-03-29 11:32:49 -04:00
Artur Paszkiewicz 65884368cd 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>
2017-03-29 11:32:27 -04:00
Artur Paszkiewicz 5308f11727 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>
2017-03-29 11:32:15 -04:00
NeilBrown b4decd517d 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>
2017-03-28 14:33:48 -04:00
NeilBrown 1ab9ed2afb Add 'force' flag to *hot_remove_disk().
In rare circumstances, the short period that *hot_remove_disk()
waits isn't long enough to IO to complete.  This particularly happens
when a device is failing and many retries are still happening.

We don't want to increase the normal wait time for "mdadm --remove"
as that might be use just to test if a device is active or not, and a
delay would be problematic.
So allow "--force" to mean that mdadm should try extra hard for a
--remove to complete, waiting up to 5 seconds.

Note that this patch fixes a comment which claim the previous
wait time was half a second, where it was really 50msec.

Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
2017-03-28 14:32:35 -04:00
NeilBrown fdd015696c Introduce sys_hot_remove_disk()
The new hot_remove_disk() will retry HOT_REMOVE_DISK
several times in the face of EBUSY.
However we sometimes remove a device by writing "remove" to the
"state" attributed.  This should be retried as well.
So introduce sys_hot_remove_disk() to repeat this action a few times.

Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
2017-03-28 14:30:49 -04:00
Zhilong Liu 1b4944f3a1 mdadm/Build:check the level parameter when build new array
check if user forgets to specify the --level
when build a new array. such as:
./mdadm -B /dev/md0 -n2 /dev/loop[0-1]

Signed-off-by: Zhilong Liu <zlliu@suse.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
2017-03-28 14:26:47 -04:00
NeilBrown 2dd271fe70 Retry HOT_REMOVE_DISK a few times.
HOT_REMOVE_DISK can fail with EBUSY if there are outstanding
IO request that have not completed yet.  It can sometimes
be helpful to wait a little while for these to complete.

We already do this in impose_level() when reshaping a device,
but not in Manage.c in response to an explicit --remove request.

So create hot_remove_disk() to central this code, and call it
where-ever it makes sense to wait for a HOT_REMOVE_DISK to succeed.

Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
2017-03-28 14:25:23 -04:00
Hannes Reinecke 3a77acd717 udev-md-raid-assembly.rules: Skip non-ready devices
If a device isn't fully initialized (e.g if it should be
handled by multipathing) it should not be considered for
md/RAID auto-assembly.  Doing so can cause incorrect results
such as causing multipath to fail during startup.

There is a convention that the udev environment variable
SYSTEMD_READY be set to zero for such devices.  So change
the mdadm rules to ignore devices with SYSTEMD_READY==0.

Signed-off-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
2017-03-28 14:22:32 -04:00
Zhilong Liu 4c829c2252 mdadm/bitmap:fixed typos in comments of bitmap.h
bitmap.h: fixed trivial typos in comments

Signed-off-by: Zhilong Liu <zlliu@suse.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
2017-03-28 14:08:04 -04:00
Gioh Kim e23c2663da super1: ignore failfast flag for setting device role
There is corner case for setting device role,
if new device has failfast flag.
The failfast flag should be ignored.

Signed-off-by: Gioh Kim <gi-oh.kim@profitbricks.com>
Signed-off-by: Jack Wang <jinpu.wang@profitbricks.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
2017-03-28 13:59:03 -04:00
Xiao Ni 5b97512954 mdadm: Forced type conversion to avoid truncation
Gcc reports it needs 19 bytes to right to disk->serial. Because the
type of argument i is int. But the meaning of i is failed disk
number. So it doesn't need to use 19 bytes.  Just add a type
conversion to avoid this building error

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
2017-03-28 13:56:43 -04:00
Xiao Ni 618f4e6d63 Replace snprintf with strncpy at some places to avoid truncation
In gcc7 there are some building errors like:
directive output may be truncated writing up to 31 bytes into a region of size 24
snprintf(str, MPB_SIG_LEN, %s, mpb->sig);

It just need to copy one string to target. So use strncpy to replace it.

For this line code: snprintf(str, MPB_SIG_LEN, %s, mpb->sig);
Because mpb->sig has the content of version after magic, so
it's better to use strncpy to replace snprintf too.

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
2017-03-28 13:54:43 -04:00
Zhilong Liu 75dd32a185 mdadm/Monitor: Fix NULL pointer dereference when stat2devnm return NULL
Wait(): stat2devnm() returns NULL for non block devices. Check the
pointer is valid derefencing it. This can happen when using --wait,
such as the 'f' and 'd' file type, causing a core dump.
such as: ./mdadm --wait /dev/md/

Reviewed-by: NeilBrown <neilb@suse.com>
Signed-off-by: Zhilong Liu <zlliu@suse.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
2017-03-27 18:24:19 -04:00
Zhilong Liu e81070a69b mdadm/mdmon:deleted the abort_reshape never invoked
mdmon.c: abort_reshape() has implemented in Grow.c,
this function doesn't make a lot of sense here.

Signed-off-by: Zhilong Liu <zlliu@suse.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
2017-03-27 18:16:19 -04:00
Zhilong Liu 27c48b375d mdadm:it doesn't make sense to set --bitmap twice
mdadm.c: it doesn't make sense to set --bitmap twice.

Signed-off-by: Zhilong Liu <zlliu@suse.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
2017-03-27 18:14:09 -04:00
Zhilong Liu 7054da69c7 mdadm:fixed some trivial typos in comments of mdadm.h
mdadm.h: fixed some trivial typos in comments

Signed-off-by: Zhilong Liu <zlliu@suse.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
2017-03-27 18:00:25 -04:00
Xiao Ni ff9239ee31 mdadm: Specify enough length when write to buffer
In Detail.c the buffer path in function Detail is defined as path[200],
in fact the max lenth of content which needs to write to the buffer is
287. Because the length of dname of struct dirent is 255.
During building it reports error:
error: ‘%s’ directive writing up to 255 bytes into a region of size 189
[-Werror=format-overflow=]

In function examine_super0 there is a buffer nb with length 5.
But it need to show a int type argument. The lenght of max
number of int is 10. So the buffer length should be 11.

In human_size function the length of buf is 30. During building
there is a error:
output between 20 and 47 bytes into a destination of size 30.
Change the length to 47.

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
2017-03-17 15:58:16 -04:00