Commit Graph

188 Commits

Author SHA1 Message Date
Mariusz Tkaczyk 5f21d67472 mdadm: add map_num_s()
map_num() returns NULL if key is not defined. This patch adds
alternative, non NULL version for cases where NULL is not expected.

There are many printf() calls where map_num() is called on variable
without NULL verification. It works, even if NULL is passed because
gcc is able to ignore NULL argument quietly but the behavior is
undefined. For safety reasons such usages will use map_num_s() now.
It is a potential point of regression.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2022-04-04 21:29:43 -04:00
Mariusz Tkaczyk c7b8547c70 imsm: add verbose flag to compare_super
IMSM does more than comparing metadata and errors reported directly
from compare_super_imsm can be useful.

Add verbose flag to compare_super method and make all not critical
error printing configurable.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2021-03-08 10:43:29 -05:00
NeilBrown 329dfc28de Create: add support for RAID0 layouts.
Since Linux 5.4 a layout is needed for RAID0 arrays with
varying device sizes.
This patch makes the layout of an array visible (via --examine)
and sets the layout on newly created arrays.
--layout=dangerous
can be used to avoid setting a layout so that they array
can be used on older kernels.

Tested-by: dann frazier <dann.frazier@canonical.com>
Signed-off-by: NeilBrown <neilb@suse.de>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2019-12-02 16:14:49 -05:00
Blazej Kucman b771faef93 imsm: return correct uuid for volume in detail
Fixes the side effect of the patch b6180160f ("imsm: save current_vol number")
- wrong UUID is printed in detail for each volume.
New parameter "subarray" is added to determine what info should be extracted
from metadata (subarray or container).
The parameter affects only IMSM metadata.

Signed-off-by: Blazej Kucman <blazej.kucman@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2019-12-02 16:01:16 -05:00
Jes Sorensen 2dcd649271 super0: Use memmove() when adjusting sparc2.2 superblock data
memcpy() does not allow overlapping copies, switch to memmove()

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2018-05-31 13:19:57 -04:00
Jes Sorensen d16a749444 mdadm: Fixup != broken formatting
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2017-05-16 14:09:57 -04:00
Jes Sorensen 32141c1765 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>
2017-04-11 12:54:26 -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
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
NeilBrown 71574efb07 Add failfast support.
Allow per-device "failfast" flag to be set when creating an
array or adding devices to an array.

When re-adding a device which had the failfast flag, it can be removed
using --nofailfast.

failfast status is printed in --detail and --examine output.

Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
2016-11-28 08:50:36 -05:00
Jes Sorensen 00fab7459a super0: Clean up formatting in examine_super0()
No funcionality change - should be purely cosmetic

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
2016-08-15 15:56:23 -04:00
Jes Sorensen a8cb6604b6 super0: Fix spelling of 'version' in comment and fix formatting
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
2016-08-15 15:49:59 -04:00
Jes Sorensen 055b766b1c super0: Use random_uuid() in init_super0()
This shaves another 80 bytes off the mdadm binary.

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
2016-08-15 15:48:56 -04:00
Jes Sorensen 2ec2b7e9d5 mdadm: Make add_internal_bitmap() return 0 on success
add_internal_bitmap() returned 1 on success and 0 on error which is
inconsistent. This changes it to return 0 on success and use more
reasonable error codes on error.

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
2016-05-12 15:19:16 -04:00
Guoqing Jiang b138214fac Fix wrong bitmap output for cluster raid
For cluster raid, we need to displays bitmap related
contents from different bitmaps which are based on node
num. So bitmap_file_open and locate_bitmap are changed a
little bit for the purpose.

Reported-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Fixes: b98043a2f8 ("Show all bitmaps while examining bitmap")
Signed-off-by: Guoqing Jiang <gqjiang@suse.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
2016-03-07 15:21:02 -05:00
NeilBrown 9f7f28ee50 super0: Fix reporting of devices between 2GB and 4GB
v0.90 metadata can handle devices between 2GB and 4GB, but we need
to treat the 'size' and unsigned.  In a couple of places we don't.

URL: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=809447
Signed-off-by: NeilBrown <neilb@suse.com>
2016-01-28 11:57:54 +11:00
Guoqing Jiang 53e76b1def mdadm: do not display bitmap info if it is cleared
"mdadm -X DISK" is used to report information about a bitmap
file, it is better to not display all the related infos if
bitmap is cleared with "--bitmap=none" under grow mode.

To do that, the locate_bitmap is changed a little to have a
return value based on MD_FEATURE_BITMAP_OFFSET.

Signed-off-by: Guoqing Jiang <gqjiang@suse.com>
Signed-off-by: NeilBrown <neilb@suse.com>
2015-12-16 13:24:04 +11:00
Guoqing Jiang 0aa2f15b20 mdadm: add the ability to change cluster name
To support change the cluster name, the commit do the followings:

1. extend original write_bitmap function for new scenario.
2. add the scenarion to handle the modification of cluster's name
   in write_bitmap1.
3. let the cluster name also show in examine_super1 and detail_super1

Signed-off-by: Guoqing Jiang <gqjiang@suse.com>
Signed-off-by: NeilBrown <neilb@suse.de>
2015-06-17 09:33:39 +10:00
NeilBrown 7a862a020f Don't break long strings onto multiple lines.
It is best to keep strings all together so that they
are easier to search for in the source code.
If a string is so long that it looks ugly one line,
them maybe it should be broken into multiple lines
for display too.

Only strings which contain a newline can be broken
into multiple lines:

 "It is OK to\n"
 "break this string\n"


Signed-off-by: NeilBrown <neilb@suse.de>
2015-02-12 13:46:53 +11:00
NeilBrown 1ade5cc15a Consistently print program Name and __func__ in debug messages.
make dprintf() print program name and __func__, so that
this messaging is consistent.

Also remove all __func__ messages from pr_err(). We shouldn't
leak that internal data in error message.
If we really want function name there, we new pr_XXX might
be wanted.

Signed-off-by: NeilBrown <neilb@suse.de>
2015-02-12 13:21:17 +11:00
NeilBrown f4dc5e9b7f super: make sure to ignore disk state flags that we don't understand.
This make it easier to add new flags that some super-types
don't understand.

Signed-off-by: NeilBrown <neilb@suse.de>
2014-08-07 11:34:50 +10:00
NeilBrown 7ccc4cc4fc Manage: remove call to validate_geometry.
This call to validate_geometry is really rather gratuitous.
It is purely about the fact that super0 cannot use more than 4TB.
So just make it an explicit test - less confusing that way.

With this, validate_geometry is only called from Create, which
makes it easier to reason about.

Also validate_geometry is now never passed NULL for the 'chunk'
parameter, so we can remove those annoying tests for NULL.

Signed-off-by: NeilBrown <neilb@suse.de>
2013-07-30 13:45:22 +10:00
NeilBrown 2bf62891c1 super0/1: fix typo in error messages.
Signed-off-by: NeilBrown <neilb@suse.de>
2013-07-24 12:22:58 +10:00
NeilBrown efb3994e48 revert-reshape: only impose reshape_position tests on raid[456]
This test is irrelevant for RAID10, so restrict it to those
levels in which it is meaningful.

Signed-off-by: NeilBrown <neilb@suse.de>
2013-07-02 16:10:27 +10:00
NeilBrown a2836f12c4 revert-reshape: make sure reshape_position is acceptable.
We can only revert a reshape if the reshape_position aligns
properly for the old geometry.
If it doesn't we just fail for now.

Also fix a +/- error with updating raid_disks for super1.c

Signed-off-by: NeilBrown <neilb@suse.de>
2013-06-27 16:38:53 +10:00
NeilBrown 1011e8344a Remove lots of unnecessary white space.
Now that I am using white-space mode in Emacs I can see all of this,
and I don't like it :-)

Signed-off-by: NeilBrown <neilb@suse.de>
2013-06-19 12:31:45 +10:00
NeilBrown f69bb60857 super0: set uninitialized variable.
Reported by -O3

Signed-off-by: NeilBrown  <neilb@suse.de>
2013-06-19 09:51:01 +10:00
NeilBrown 199f1a1fad Assemble: allow --update=revert-reshape
This will cause a reshape to start going backwards.
2013-05-28 16:44:23 +10:00
NeilBrown afa368f49a Assemble: --update=metadata converts v0.90 to v1.0
This allows the smooth conversion of legacy 0.90 arrays
to 1.0 metadata.
Old metadata is likely to remain but will be ignored.
It can be removed with
  mdadm --zero-superblock --metadata=0.90 /dev/whatever

Signed-off-by: NeilBrown <neilb@suse.de>
2013-05-28 16:44:22 +10:00
NeilBrown ed503f89e4 Change some "fprintf(stderr,"s to pr_err.
They just keep slipping in..

Signed-off-by: NeilBrown <neilb@suse.de>
2013-05-21 12:42:57 +10:00
NeilBrown 74db60b00a Add --dump / --restore functionality.
This allows the metadata on a device to be saved and later restored.
This can be useful before experimenting on an array that is misbehaving.

Suggested-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
2013-05-16 15:07:16 +10:00
NeilBrown 4dd2df0966 Discard devnum in favour of devnm
We widely use a "devnum" which is 0 or +ve for md%d devices
and -ve for md_d%d devices.
But I want to be able to use md_%s device names.

So get rid of devnum (a number) and use devnm (a 32char string).
eg.
  md0
  md_d2
  md_home

Signed-off-by: NeilBrown <neilb@suse.de>
2013-02-21 17:05:23 +11:00
NeilBrown def1133297 make --update=homehost work again
Commit 1e2b276535 (Report error in --update
string is not recognised) broke homehost updating functionality because it
depended on each string comparison being done even after we already found
a match.  Make it work again by restructuring code.

Reported-by: (and original version by) Justin Maggard <jmaggard10@gmail.com>
Signed-off-by: NeilBrown <neilb@suse.de>
2013-02-10 15:40:42 +11:00
NeilBrown 9698df15d9 Avoid using BLKFLSBUF.
Now that we use O_DIRECT for all device IO, BLKFLSBUF is not needed to
ensure we get current data, and it can impose a cost if any flush-out
is needed.  So remove it.

To be safe, add O_DIRECT to one place where it isn't currently used:
when reading a bitmap.

Signed-off-by: NeilBrown <neilb@suse.de>
2013-02-05 16:00:55 +11:00
NeilBrown 63ebe78fae super0: allow creation of array on 2TB+ devices.
As 'info->size' is signed, it cannot even hold values above
2TB.
But it isn't used much.  sb->size is the important value and it
is unsigned.
So use that to check for overflow of size.

Reported-by: Eugene San <eugenesan@gmail.com>
2012-10-23 08:48:00 +11:00
Michael Tokarev dae45415a9 Trivial bugfix and spelling fixes.
And here's another trivial bugfix, now for spelling mistakes in various
places, authred by Sergey Kirpichev (Cc'ed) and carried in debian mdadm
package.


Signed-off-by: NeilBrown <neilb@suse.de>
2012-10-22 08:55:27 +11:00
Michael Tokarev 30d4815971 mdadm: super0: do not override uuid with homehost
When --uuid is specified in the command line, even for v0.90
superblock we override last portion of uuid with data from
--homehost, which is wrong (and disagrees with the manpage).
Only use homehost in super0 if no uuid is specified.

Signed-off-By: Michael Tokarev <mjt@tls.msk.ru>
Signed-off-by: NeilBrown <neilb@suse.de>
2012-10-22 08:48:18 +11:00
NeilBrown 72ca9bcff3 Allow data-offset to be specified per-device for create
mdadm --create /dev/md0 .... /dev/sda1:1024 /dev/sdb1:2048 ...

The size is in K unless a suffix: K M G is given.
The suffix 's' means sectors.

Signed-off-by: NeilBrown <neilb@suse.de>
2012-10-04 16:34:21 +10:00
NeilBrown 83cd1e97cb Add data_offset arg to ->init_super and use it in super1.c
So if ->data_offset is already set, use that rather than
computing one.

Signed-off-by: NeilBrown <neilb@suse.de>
2012-10-04 16:34:20 +10:00
NeilBrown af4348ddd1 Add data_offset arg to ->validate_geometry.
This is needed to return correct available size.  It isn't
really used yet.

Signed-off-by: NeilBrown <neilb@suse.de>
2012-10-04 16:34:20 +10:00
NeilBrown 387fcd593c Add data_offset arg to ->avail_size
This is currently only useful for 1.x metadata and will allow an
explicit --data-offset request on command line.

Signed-off-by: NeilBrown <neilb@suse.de>
2012-10-04 16:34:20 +10:00
NeilBrown ba728be72f Convert 'quiet' to 'not verbose' in various places.
If we change some functions to accept 'verbose', where <0 means to be
quiet, in place of 'quiet', then we will be able to merge
'quiet' and 'verbose' together for simplicity.

Signed-off-by: NeilBrown <neilb@suse.de>
2012-07-09 17:18:09 +10:00
NeilBrown 503975b9d5 Remove scattered checks for malloc success.
malloc should never fail, and if it does it is unlikely
that anything else useful can be done.  Best approach is to
abort and let some super-daemon restart.

So define xmalloc, xcalloc, xrealloc, xstrdup which don't
fail but just print a message and exit.  Then use those
removing all the tests for failure.

Also replace all "malloc;memset" sequences with 'xcalloc'.

Signed-off-by: NeilBrown <neilb@suse.de>
2012-07-09 17:14:16 +10:00
NeilBrown e7b84f9d50 Introduce pr_err for printing error messages.
'pr_err("' is a lot shorter than 'fprintf(stderr, Name ": '
cont_err() is also available.

Signed-off-by: NeilBrown <neilb@suse.de>
2012-07-09 17:14:16 +10:00
NeilBrown d4633e06df Examine: fix array size calculation for RAID10.
RAID10 arrays with an odd number of devices had the arraysize
reported wrongly by --examine due to a rounding error.

Reported-by: Chris Francy <zoredache@gmail.com>
Signed-off-by: NeilBrown <neilb@suse.de>
2012-03-22 14:43:09 +11:00
Jes Sorensen 65ed615155 match_metadata_desc0(): Use calloc instead of malloc+memset
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Signed-off-by: NeilBrown <neilb@suse.de>
2012-03-21 08:04:14 +11:00
Jes Sorensen d669228f29 Use posix_memalign() for memory used to write bitmaps
This makes super[01].c properly align buffers used for the bitmap
using posix_memalign() to make sure the writes don't fail in case the
bitmap is opened using O_DIRECT.

This is based on https://bugzilla.redhat.com/show_bug.cgi?id=789898
and an initial patch by Alexander Murashkin.

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Signed-off-by: NeilBrown <neilb@suse.de>
2012-02-16 14:16:03 +11:00
NeilBrown c0c1acd691 Grow/bitmap: support adding bitmap via sysfs.
Adding a bitmap via ioctl can only add it at a fixed location.
That location is not suitable for 4K-block devices.

So allow setting the bitmap location via sysfs if kernel supports it
and aim to always use 4K alignments.

Signed-off-by: NeilBrown <neilb@suse.de>
2011-12-23 14:10:41 +11:00
NeilBrown 9c8c121881 super0: fix overflow when checking max size.
We need to force multiplication to use ULL before they
get to big, else it overflows.  So move the "2ULL" to the start.

Signed-off-by: NeilBrown <neilb@suse.de>
2011-10-20 13:14:26 +11:00