Commit Graph

232 Commits

Author SHA1 Message Date
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 26bf55874d super1: set RESHAPE_NO_BACKUP based on new_offset.
We need to check for a backup iff the data_offset has changed.
Testing against level==10 was an effective but short-sighted approach.

Signed-off-by: NeilBrown <neilb@suse.de>
2013-05-28 16:58:18 +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 d6e4b44fdb super1: fix some casts of signed superblock fields.
These need to be cast to uint32_t before being cast to 'long', else
sign extension doesn't happen on 64bit hosts.

And bitmap_offset is le32, not le64 !!

Signed-off-by: NeilBrown <neilb@suse.de>
2013-05-28 16:43:03 +10:00
NeilBrown 5e1863d49d Examine/super1 - report Unused space, before and after.
Might be confusing, or might be useful when reshaping.

Signed-off-by: NeilBrown <neilb@suse.de>
2013-05-22 16:37:19 +10:00
NeilBrown f79bbf4f69 super1: don't put the bblog at the end of the free space.
It seems like a nice location, but it means that we cannot
decrease the data_offset during a reshape.

So put it just after the bitmap, leaving 32K.

Signed-off-by: NeilBrown <neilb@suse.de>
2013-05-22 16:00:21 +10:00
NeilBrown c4b26c643d Grow: allow metadata to indicate that changing data_offset not supported.
If space_after and space_before are zero (the default) then assume that
metadata doesn't support changing data_offset.

Signed-off-by: NeilBrown <neilb@suse.de>
2013-05-22 12:26:19 +10:00
NeilBrown cc3130a786 super1: improve calculation of space_before/space_after
1/ these must allow for bad-block-list
2/ they must match the kernel, which has a 32k buffer after the
   superblock.

Signed-off-by: NeilBrown <neilb@suse.de>
2013-05-21 15:38:49 +10:00
NeilBrown 8772113ab2 Examine/super1: don't report "New Offset" when feature not set.
The "new_offset" field may be non-zero, but if the feature flag is not
set, it should be ignored.

Signed-off-by: NeilBrown <neilb@suse.de>
2013-05-21 15:37:20 +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 0cf8322999 Always test return value of posix_memalign.
FORTIFY_SOURCE likes this, and it is good practice.

Signed-off-by: NeilBrown <neilb@suse.de>
2013-05-13 17:09:55 +10:00
NeilBrown 5a23a06ea4 mdassemble - fix new compile-time problems.
Signed-off-by: NeilBrown <neilb@suse.de>
2013-05-13 17:05: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 6d388a8816 MISC: Add --examine-badblocks option
This will list the contents of the bad-blocks log, if one is present.

Signed-off-by: NeilBrown <neilb@suse.de>
2012-12-05 12:56:31 +11:00
NeilBrown 72e7fb13f0 Incremental: support replacement devices.
These need to be counted in the number of 'active' devices.

Signed-off-by: NeilBrown <neilb@suse.de>
2012-10-24 12:06:51 +11:00
NeilBrown aacb2f816a Assemble: add support for replacement devices.
Need to possibly collect 2 devices for each slot, and
original and a replacement.

Signed-off-by: NeilBrown <neilb@suse.de>
2012-10-24 09:48:18 +11:00
NeilBrown 24c7bc8432 Report replacement devices correctly with --detail and --examine
--detail needs to be read to report 2 devices in each slot,
and --examine need to report if the device is the original or
the replacement.

Signed-off-by: NeilBrown <neilb@suse.de>
2012-10-23 17:16:16 +11:00
NeilBrown 5d5002289c Replace a lot of leading spaces with tabs.
Signed-off-by: NeilBrown <neilb@suse.de>
2012-10-10 18:33:26 +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 cb19a251a5 super1: reserve at least 2 chunks for reshape headroom.
sometimes 0.1% isn't enough, though mostly only in testing.

We need one chunk for a successful reshape, so reserve 2.

Signed-off-by: NeilBrown <neilb@suse.de>
2012-10-04 16:34:21 +10:00
NeilBrown 5e88ab2e2f New RESHAPE_NO_BACKUP flag to track when backup action is needed.
Some arrays (raid10) never need a backup file, so during assembly
we can avoid the whole Grow_continue check in that case.
Achieve this using a flag set by the metadata handler.

Also get "mdadm -I" to fail if a backup process would be
needed.  It currently does fail as the kernel rejects things,
but it is nicer to have this explicit.

Signed-off-by: NeilBrown <neilb@suse.de>
2012-10-04 16:34:21 +10:00
NeilBrown 80bf913592 Add space_before/space_after fields to mdinfo
These will be needed to guide changes to data_offset during reshape.
Only set them for super1 for now.

Signed-off-by: NeilBrown <neilb@suse.de>
2012-10-04 16:34:21 +10:00
NeilBrown 8fe1c44f82 super1: add new_offset field.
The 'new_offset' is used for reshaping to avoid the need
for a backup file.

For now we only report the value when it is set.

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 7103b9b88d Handles spaces in array names better.
1/ When printing the "name=" entry for --brief output,
   enclose name in quotes if it contains spaces etc.
   Quotes are already supported for reading mdadm.conf

2/ When a name is used as a device name, translate spaces
   and tabs to '_', as well as the current translation of
   '/' to '-'.

Signed-off-by: NeilBrown <neilb@suse.de>
2012-10-04 16:34:20 +10:00
NeilBrown 88af981fa5 super1: ensure bitmap doesn't overlap bad block log.
If a bad block log already exists when adding a bitmap,
make sure the bitmap stays before the log.

Signed-off-by: NeilBrown <neilb@suse.de>
2012-10-03 17:07:20 +10:00
NeilBrown 688e99a77d Allow --update to add or remove space for a bad block list.
--update=bbl will add a bad block list to each device.
--update=no-bblk will remove the bad block list providing that it
is empty.

Signed-off-by: NeilBrown <neilb@suse.de>
2012-10-03 17:07:13 +10:00
NeilBrown bf95d0f38c Bad block log 2012-10-03 17:07:11 +10:00
Maciej Naruszewicz 80730bae52 Add MD_ARRAY_SIZE for --examine --export
An additional pair of key=value for --examine --export.

Signed-off-by: Maciej Naruszewicz <maciej.naruszewicz@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
2012-10-02 16:42:25 +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
majianpeng 4687f16027 mdadm: Fix Segmentation fault.
In function write_init_super1():
If "rv = store_super1(st, di->fd)" return error and the di is the last.
Then the di = NULL && rv > 0, so exec:
if (rv)
    fprintf(stderr, Name ": Failed to write metadata to%s\n",
     	 di->devname);
will be segmentation fault.

Signed-off-by: majianpeng <majianpeng@gmail.com>
Signed-off-by: NeilBrown <neilb@suse.de>
2012-05-29 09:21:51 +10:00
NeilBrown d9751e06a6 super1: fix choice of data_offset.
While it is nice to set a high data_offset to leave plenty of head
room it is much more important to leave enough space to allow
of the data of the array.
So after we check that sb->size is still available, only reduce the
'reserved', don't increase it.

This fixes a bug where --adding a spare fails because it does not have
enough space in it.

Reported-by: nowhere <nowhere@hakkenden.ath.cx>
Signed-off-by: NeilBrown <neilb@suse.de>
2012-05-15 09:51:03 +10:00
Jes Sorensen 34a13953fa Fix sign extension of bitmap_offset in super1.c
fbdef49811 incorrectly tried to fix sign
extension of the bitmap offset. However mdinfo->bitmap_offset is a u32
and needs to be converted to a 32 bit signed integer before the sign
extension.

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Signed-off-by: NeilBrown <neilb@suse.de>
2012-04-30 09:56:22 +10:00
NeilBrown 508a7f16b2 super1: leave more space in front of data by default.
The kernel is growing the ability to avoid the need for a
backup file during reshape by being able to change the data offset.

For this to be useful we need plenty of free space before the
data so the data offset can be reduced.

So for v1.1 and v1.2 metadata make the default data_offset much
larger.  Aim for 128Meg, but keep a power of 2 and don't use more
than 0.1% of each device.

Don't change v1.0 as that is used when the data_offset is required to
be zero.

Signed-off-by: NeilBrown <neilb@suse.de>
2012-04-04 14:04:28 +10:00
NeilBrown fbdef49811 Bitmap_offset is a signed number
As the bitmap can be before the superblock, bitmap_offset is signed.
But some of the code didn't honour that :-(

Signed-off-by: NeilBrown <neilb@suse.de>
2012-04-04 14:03:45 +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 0a2f189415 super1.c: use ROUND_UP/ROUND_UP_PTR
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Signed-off-by: NeilBrown <neilb@suse.de>
2012-03-21 08:06:35 +11:00
Jes Sorensen 308340aa58 Use struct align_fd to cache fd's block size for aligned reads/writes
This uses a struct to cache the block size for aligned reads/writes,
to avoid repeated ioctl(BLKSSZGET) calls.

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Signed-off-by: NeilBrown <neilb@suse.de>
2012-03-21 08:01:20 +11:00
Jes Sorensen 3c0bcd4609 Use 4K buffer alignment for superblock allocations
To better accommodate 4K sector drives, use 4K buffer alignment for
superblock buffers.

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Signed-off-by: NeilBrown <neilb@suse.de>
2012-03-21 08:01:04 +11:00
Jes Sorensen 2de0b8a2b4 match_metadata_desc1(): 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:00:50 +11:00
Jes Sorensen 1afa9308d2 init_super1() memset full buffer allocated for superblock
Avoid possibly using stale data in bitmap and misc area of superblock.
In addition, remove superfluous memsets already covered by memset of
full superblock.

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Signed-off-by: NeilBrown <neilb@suse.de>
2012-03-21 08:00:26 +11:00
Jes Sorensen 4122675629 Define and use SUPER1_SIZE for allocations
Use a #define rather than calculate the size of the superblock buffer
on every allocation.

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Signed-off-by: NeilBrown <neilb@suse.de>
2012-03-21 08:00:07 +11:00
Jes Sorensen b2bfdfa0fe super1.c don't keep recalculating bitmap pointer
We just calculated the pointer to the bitmap, so use it instead of
recalculating.

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Signed-off-by: NeilBrown <neilb@suse.de>
2012-03-21 07:42:48 +11:00