Commit Graph

62 Commits

Author SHA1 Message Date
Zhao Heming 9c030dadba mdadm/Detail: show correct state for clustered array
After kernel md module commit 480523feae581, in clustered env,
mddev->in_sync always zero, it will make array.state never set
up MD_SB_CLEAN. it causes "mdadm -D /dev/mdX" show state 'active'
all the time.

bitmap.c: add a new API IsBitmapDirty() to support inquiry bitmap
dirty or clean.

Signed-off-by: Zhao Heming <heming.zhao@suse.com>
2020-11-25 18:19:49 -05:00
Zhilong Liu 8cc56e8b32 mdadm/bitmap: examine-bitmap failed when bitmap is external mode
--examine-bitmap: the bitmap_file_open() shouldn't omit the
regular file descriptor when the bitmap is external mode.
Such as: ./mdadm -X /mnt/3

This commit is partial revert of commit 0a6bff09d4
(mdadm/util: unify fstat checking blkdev into function)

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

Signed-off-by: Zhilong Liu <zlliu@suse.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2017-05-05 11:04:02 -04:00
Jes Sorensen 5d89b18da8 bitmap: Remove use of md_get_version()
Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
2017-04-05 15:38:48 -04:00
Artur Paszkiewicz 561ad5597b super1: make internal bitmap size calculations more consistent
Determining internal bitmap size is performed using two different
functions (bitmap_sectors() and calc_bitmap_size()) and in
getinfo_super1() it is calculated in yet another way. Each of these
methods give slightly different results. The most accurate is
calc_bitmap_size() but it also has a rounding issue. So:

- fix the rounding issue in calc_bitmap_size() using bitmap_bits()
- replace usages of bitmap_sectors() and open-coded calculations with
  calc_bitmap_size()
- remove bitmap_sectors()
- move bitmap_bits() to mdadm.h as inline - otherwise mdassemble won't
  compile (it does not use bitmap.c)

Signed-off-by: Artur Paszkiewicz <artur.paszkiewicz@intel.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
2016-11-16 09:56:39 -05:00
Jes Sorensen 6e88b3b3e5 bitmap: Mark a number of local functions static
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
2016-08-15 16:35:28 -04:00
Jes Sorensen 34996a5f89 bitmap: Handle errors when reading bitmap info for cluster nodes
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
2016-08-15 16:21:33 -04:00
Jes Sorensen 9ca0de6241 bitmap: Simplify code for bitmap_file_open()
By switching to open+fstat rather than stat+open the code can be
simplified and avoid duplicating the open handling.

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
2016-08-15 16:16:05 -04:00
Jes Sorensen de12cdc7eb bitmap: Fix resource leak in bitmap_file_open()
The code would leak 'fd' if locate_bitmap() failed.

Reviewed-by: NeilBrown <neilb@suse.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
2016-03-09 11:35:34 -05: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
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
Goldwyn Rodrigues 6d9c7c2551 Increment version for clustered bitmaps
Add BITMAP_MAJOR_CLUSTERED as 5, in order to prevent older kernels
to assemble a clustered device.

In order to maximize compatibility, the major version is set to
BITMAP_MAJOR_CLUSTERED *only* if the bitmap is clustered.

Also, added MD_FEATURE_CLUSTERED in order to return error
for older kernels which would assemble MD in case bitmap is
corrupted.

Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
Signed-off-by: NeilBrown <neilb@suse.com>
2015-09-28 11:47:04 +10:00
Guoqing Jiang 2cf42394f0 md-cluster: use %-64s to print cluster_name
Left align is better for cluster with name less than 64. Also
make the output of cluster name is aligned with others.

Signed-off-by: Guoqing Jiang <gqjiang@suse.com>
Signed-off-by: NeilBrown <neilb@suse.com>
2015-07-29 17:26:12 +10:00
NeilBrown 653299b699 Merge branch 'cluster'
Now that 3.3.3 is out, it is time to include the cluster-support code.

Signed-off-by: NeilBrown <neilb@suse.com>
2015-07-27 11:01:08 +10:00
NeilBrown d8f82d1d88 bitmap: convert "inline" to "static inline"
Otherwise new gcc ignores them with some compile options.

Signed-off-by: NeilBrown <neilb@suse.com>
2015-07-24 16:10:44 +10:00
Guoqing Jiang b98043a2f8 Show all bitmaps while examining bitmap
This adds capability of exmining bitmaps corresponding to all
nodes/slots on the device.

Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
Signed-off-by: Guoqing Jiang <gqjiang@suse.com>
Signed-off-by: NeilBrown <neilb@suse.de>
2015-06-17 09:19:25 +10:00
Guoqing Jiang 95a05b37e8 Create n bitmaps for clustered mode
For a clustered MD, create bitmaps equal to number of nodes so
each node has an independent bitmap.

Only the first bitmap is has the bits set so that the first node
that assembles the device also performs the sync.

The bitmaps are aligned to 4k boundaries.

On-disk format:

0                    4k                     8k                    12k
-------------------------------------------------------------------
| idle                | md super            | bm super [0] + bits |
| bm bits[0, contd]   | bm super[1] + bits  | bm bits[1, contd]   |
| bm super[2] + bits  | bm bits [2, contd]  | bm super[3] + bits  |
| bm bits [3, contd]  |                     |                     |

Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
Signed-off-by: Guoqing Jiang <gqjiang@suse.com>
Signed-off-by: NeilBrown <neilb@suse.de>
2015-06-17 07:54:03 +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 1e781e07ab --examine-bitmap: give useful message if no bitmap found on md array.
The bitmap is stored on member devices, not on the array, so
--examine-bitmap should be given the member device.
If --examine-bitmap is given an array, and it doesn't have a bitmap
on it (i.e. it isn't a member of some other array), then that
is probably a usage error, so print a helpful message.

Signed-off-by: NeilBrown <neilb@suse.de>
2014-05-22 15:22:39 +10: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 ca3b669603 Minor cosmetic fixes in various files.
Signed-off-by: NeilBrown <neilb@suse.de>
2012-08-13 08:00:21 +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 a7322ae12f Subject: bitmap: used 4K aligned buffers when reading the bitmap.
This is needed on 4K block devices such as DASD as we do O_DIRECT
reads.

Do the same alignment for gpt just to be safe.

Signed-off-by: NeilBrown <neilb@suse.de>
2011-12-23 14:09:29 +11:00
NeilBrown 6c9a5fa103 bitmap: print correct percentage of bitmap in use.
We were adding 1, presumably to avoid div-by-zero possibilities.
It is better to only substitute '1' if the value actually is zero,
else for small numbers of bits the difference is visible.

Signed-off-by: NeilBrown <neilb@suse.de>
2011-12-23 09:07:14 +11:00
Jes Sorensen 39c74d5e25 bitmap_fd_read(): fix memory leak
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Signed-off-by: NeilBrown <neilb@suse.de>
2011-11-02 10:48:53 +11:00
NeilBrown f21e18ca89 Compile with -Wextra by default
This produced lots of warning, some of which pointed to actual bugs.

Signed-off-by: NeilBrown <neilb@suse.de>
2010-08-05 13:13:02 +10:00
NeilBrown 3e4165619b Cast to long long before left-shifting too much.
When left-shifting we must be sure that the value being
shifted is large enough to not lose bits.
The 'chunkssize' in CreateBitmap is only 'long' so it
can overflow.  So cast to 'long long' first.

Also fix a similar issue in Detail even though it isn't currently
being compiled.

Signed-off-by: NeilBrown <neilb@suse.de>
Reported-by: Tomasz Chmielewski <mangoo@wpkg.org>
2010-07-22 15:35:54 +10:00
NeilBrown ebeb366382 Don't attempt to create or read bitmaps where the metadata doesn't support it.
In particular, if the relevant bitmap method is NULL, don't try to
call it, print an error instead.

Signed-off-by: NeilBrown <neilb@suse.de>
2010-04-07 09:18:01 +10:00
Dan Williams 1e5c69836d imsm: add support for checkpointing via 'curr_migr_unit'
Unlike native md checkpointing some data about the geometry and type of
the migration process is coded into curr_migr_unit.  Provide logic to
convert between md/{resync_start|recovery_start} and imsm/curr_migr_unit.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2009-12-21 17:54:32 -07:00
NeilBrown 8320878543 Merge branch 'master' into devel-3.0
Conflicts:
	Build.c
	mdadm.c
	mdadm.h
	super1.c
2009-05-11 16:05:41 +10:00
NeilBrown caa0f6c623 Fix gcc-4.4 compiler warning.
Apparently the dereferencing of a type-punned pointer breaks strict
aliasing rules.   And we wouldn't want to do that.
So just make a different array of the appropriate type and use memcpy.

Resolves-Debian-bug: 505375
Signed-off-by: NeilBrown <neilb@suse.de>
2009-04-29 11:44:02 +10:00
NeilBrown 6c40598f59 Merge branch 'master' into devel-3.0 2009-02-02 11:09:09 +11:00
NeilBrown b47dff6675 Fix possible crash if bitmap metadata is bad.
We really should never divide by 0.

Thanks to "Jon Nelson" <jnelson-linux-raid@jamponi.net>
for finding the problem.

Signed-off-by: NeilBrown <neilb@suse.de>
2009-02-02 11:06:38 +11:00
NeilBrown 492350045c Merge branch 'master' into devel-3.0
Conflicts:

	Manage.c
2008-10-17 12:46:23 +11:00
Dan Williams 3d2c4fc7b6 trivial warn_unused_result squashing
Made the mistake of recompiling the F9 mdadm rpm which has a patch to
remove -Werror and add "-Wp,-D_FORTIFY_SOURCE -O2" which turns on lots
of errors:

config.c:568: warning: ignoring return value of asprintf
Assemble.c:411: warning: ignoring return value of asprintf
Assemble.c:413: warning: ignoring return value of asprintf
super0.c:549: warning: ignoring return value of posix_memalign
super0.c:742: warning: ignoring return value of posix_memalign
super0.c:812: warning: ignoring return value of posix_memalign
super1.c:692: warning: ignoring return value of posix_memalign
super1.c:1039: warning: ignoring return value of posix_memalign
super1.c:1155: warning: ignoring return value of posix_memalign
super-ddf.c:508: warning: ignoring return value of posix_memalign
super-ddf.c:645: warning: ignoring return value of posix_memalign
super-ddf.c:696: warning: ignoring return value of posix_memalign
super-ddf.c:715: warning: ignoring return value of posix_memalign
super-ddf.c:1476: warning: ignoring return value of posix_memalign
super-ddf.c:1603: warning: ignoring return value of posix_memalign
super-ddf.c:1614: warning: ignoring return value of posix_memalign
super-ddf.c:1842: warning: ignoring return value of posix_memalign
super-ddf.c:2013: warning: ignoring return value of posix_memalign
super-ddf.c:2140: warning: ignoring return value of write
super-ddf.c:2143: warning: ignoring return value of write
super-ddf.c:2147: warning: ignoring return value of write
super-ddf.c:2150: warning: ignoring return value of write
super-ddf.c:2162: warning: ignoring return value of write
super-ddf.c:2169: warning: ignoring return value of write
super-ddf.c:2172: warning: ignoring return value of write
super-ddf.c:2176: warning: ignoring return value of write
super-ddf.c:2181: warning: ignoring return value of write
super-ddf.c:2686: warning: ignoring return value of posix_memalign
super-ddf.c:2690: warning: ignoring return value of write
super-ddf.c:3070: warning: ignoring return value of posix_memalign
super-ddf.c:3254: warning: ignoring return value of posix_memalign
bitmap.c:128: warning: ignoring return value of posix_memalign
mdmon.c:94: warning: ignoring return value of write
mdmon.c:221: warning: ignoring return value of pipe
mdmon.c:327: warning: ignoring return value of write
mdmon.c:330: warning: ignoring return value of chdir
mdmon.c:335: warning: ignoring return value of dup
monitor.c:415: warning: rv may be used uninitialized in this function

...some of these like the write() ones are not so trivial so save those
fixes for the next patch.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2008-10-15 14:15:52 -07:00
NeilBrown 2a528478c7 Manage: allow adding device that is just large enough to v1.x array.
When adding a device to an array, we check that it is large enough.

Currently the check makes sure there is also room for a reasonably
sized bitmap.  But if the array doesn't have a bitmap, then this test
might be too restrictive.
So when adding, only insist there is enough space for the current
bitmap.
When Creating, still require room for the standard sized bitmap.

This resolved Debian Bug 500309
2008-10-13 16:15:16 +11:00
Neil Brown 6416d5275d Use O_DIRECT for all IO to devices.
Using buffered IO risks non-atomic updates to parts of the
device that we don't actually want to write to.  This isn't in
general safe.
So switch to O_DIRECT for all that IO and make sure we have
properly aligned buffers.
2008-07-12 20:28:33 +10:00
Neil Brown 3da92f272d Drop the superblock arg from all metadata methods.
It is now in the 'supertype'
2007-12-14 20:14:33 +11:00
Neil Brown aba69144fd Remove spaces/tabs from ends of lines. 2007-12-14 20:13:43 +11:00
Neil Brown 350f29f90d Centralise code for copying uuid
Rather than opencoding the byteswap all the time.
2006-12-14 17:33:14 +11:00
Neil Brown bf4fb153a4 Fix and test --update=uuid
A number of odd bugs here, but now we have a regression test as well.
2006-12-14 17:31:29 +11:00
Neil Brown b39827de21 Reduce max bitmap size when bitmap is in a file.
To ensure kernel never needs to allocate more than 1 page contiguously.
2006-10-16 15:26:43 +10:00
Neil Brown 97a6748ce2 Flush bitmap file before truncate.
Otheriwse the last write happens on fclose which is after ftruncate,
to the truncate has no effect.
2006-10-16 14:39:06 +10:00
Paul Clements 10ae45c12c Fixed endian problem with bitmap metdata
From: Paul Clements <paul.clements@steeleye.com>
2006-10-09 11:17:22 +10:00
Neil Brown 9fca7d6236 check return status of all write/fwrite functions as required by glibc 2.4
From: Luca Berra <bluca@vodka.it>

glibc 2.4 is pedantic on ignoring return values from fprintf, fwrite and
write, so now we check the rval and actually do something with it.
in the Grow.c case i only print a warning, since i don't think we can do
anything in case we fail invalidating those superblocks (is should never
happen, but then...)

Signed-off-by: Neil Brown <neilb@suse.de>
2006-05-29 02:06:32 +00:00
Neil Brown 8131b493df When updating uuid, update the bitmap as well - external bitmaps
Signed-off-by: Neil Brown <neilb@suse.de>
2006-05-16 06:05:27 +00:00
Neil Brown 1bfdbe01ff Limit size of bitmap to 2million chunks.
When creating a file bitmap, choose a default size that
results in fewer than 2^21 chunks.  Without this kmalloc
failure in the kernel becomes likely.

Signed-off-by: Neil Brown <neilb@suse.de>
2006-05-15 04:21:33 +00:00
Neil Brown 4ccdb95600 Use O_DIRECT to read bitmap files.
A pending patch to the kernel causes bitmap file updates
to not go through the page cache, so O_DIRECT is needed to
ensure that we read current data.

Signed-off-by: Neil Brown <neilb@suse.de>
2006-05-15 00:56:02 +00:00
Neil Brown 1e0d770c0f Release some compile fixes.
Signed-off-by: Neil Brown <neilb@suse.de>
2006-02-06 04:18:12 +00:00