Commit Graph

81 Commits

Author SHA1 Message Date
Kinga Tanska 1a87493014 Change warning message
In commit 039b7225e6 ("md: allow creation of mdNNN arrays via
md_mod/parameters/new_array") support for name like mdNNN
was added. Special warning, when kernel is unable to handle
request, was added in commit 7105228e19
("mdadm/mdopen: create new function create_named_array for
writing to new_array"), but it was not adequate enough,
because in this situation mdadm tries to do it in old way.
This commit changes warning to be more relevant when
creating RAID container with "/dev/mdNNN" name and mdadm
back to old approach.

Signed-off-by: Kinga Tanska <kinga.tanska@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2020-01-16 13:48:13 -05:00
Jes Sorensen c1b78589cf mdopen: fix gcc 8.1 string overflow error
We already cut symlinks longer than 1000, so rely on this calling
readlink and error out if we are able to read more than 1000 bytes.

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2018-05-31 13:11:21 -04:00
Zhilong Liu 7105228e19 mdadm/mdopen: create new function create_named_array for writing to new_array
Split 'write to new_array' out into a function named create_named_array.
And fixed a trivial compiling warning 'warn_unused_result' against commit:
fdbf7aaa19 (mdopen: call "modprobe md_mod" if it might be needed.)

Suggested-by: NeilBrown <neilb@suse.com>
Signed-off-by: Zhilong Liu <zlliu@suse.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2017-11-01 17:23:28 -04:00
NeilBrown fdbf7aaa19 mdopen: call "modprobe md_mod" if it might be needed.
Creating an array by opening a block-device with major number of 9
will transparently load the md module if needed.
Creating an array by opening
   /sys/module/md_mod/parameters/new_array
and writing to it won't, it will just fail if md_mod isn't loaded.

So when opening that file fails with ENOENT, run "modprobe md_mod" and
try again.

This fixes a bug whereby if you have "CREATE names=yes" in mdadm.conf,
and the md modules isn't loaded, then creating or assembling an
array will not honor the "names=yes" configuration.

Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2017-09-27 17:30:27 -04:00
NeilBrown 8e5b52cdda Error messages should end with a newline character.
Add "\n" to the end of error messages which don't already
have one.  Also spell "opened" correctly.

Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2017-08-16 08:25:07 -04:00
Jes Sorensen 9db2ab4e9b 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>
2017-05-03 16:15:16 -04:00
NeilBrown cd6cbb08c4 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>
2017-05-02 09:41:39 -04:00
NeilBrown 039df36231 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>
2017-04-12 13:34:44 -04:00
Jes Sorensen 40b054e1dc 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>
2017-04-05 15:44:20 -04:00
NeilBrown f71d2b8f4b mdopen: open md devices O_RDONLY
There is no need to request write access when opening
the md device, as we never write to it, and none of the
ioctls we use require write access.

If we do open with write access, then when we close, udev notices that
the device was closed after being open for write access, and it
generates a CHANGE event.

This is generally unwanted, and particularly problematic when mdadm is
trying to --stop the array, as the CHANGE event can cause the array to
be re-opened before it completely closed, which results in a new mddev
being allocated.

So just use O_RDONLY instead of O_RDWR.

Reported-by: Marc Smith <marc.smith@mcc.edu>
Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
2016-12-05 09:26:22 -05:00
NeilBrown 681b7ae245 Fix some issues found by clang
The clang compiler complained about each of these.

The mdmon.h error will only affect 'far' RAID10 arrays using intel or DDF
metadata, and there is no such thing.

The mdopen.c will cause a problem if there are no free md device
numbers in the first 512.  That is fairly unlikely.

The restripe.c error would only affect the 'test_stripe' command, and
probably doesn't change its behaviour.

The super-intel.c fix is purely cosmetic.

Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
2016-10-07 11:47:48 -04:00
Robert LeBlanc bd1fd72e13 mdopen: Prevent overrunning the devname buffer when copying devnm into it for long md names.
Linux allows for 32 character device names. When using the maximum
size device name and also storing "/dev/", devname needs to be 37
character long to store the complete device name.
i.e. "/dev/md_abcdefghijklmnopqrstuvwxyz12\0"

Signed-off-by: Robert LeBlanc<robert@leblancnet.us>
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
2016-08-25 13:43:31 -04:00
Mike Lovell 2e466cce45 Change behavior in find_free_devnm when wrapping around.
Newer kernels don't allow for specifying an array larger than 511. This
makes it so find_free_devnm wraps to 511 instead of 2^20 - 1.

Signed-off-by: Mike Lovell <mlovell@bluehost.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
2016-06-03 15:36:11 -04:00
Mike Lovell 13db17bd1f Use dev_t for devnm2devid and devid2devnm
Commit 4dd2df0966 added a trip through makedev(), major(), and minor() for
device major and minor numbers. This would cause mdadm to fail in operating
on a device with a minor number bigger than (2^19)-1 due to it changing
from dev_t to a signed int and back.

Where this was found as a problem was when a array was created with a device
specified as a name like /dev/md/raidname and there were already 128 arrays
on the system. In this case, mdadm would chose 1048575 ((2^20)-1) for the
array and minor number. This would cause the major and minor number to become
negative when generated from devnm2devid() and passed to major() and minor()
in open_dev_excl(). open_dev_excl() would then call dev_open() which would
detect the negative minor number and call open() on the *char containing the
major:minor pair which isn't a valid file.

Signed-off-by: Mike Lovell <mlovell@bluehost.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
2016-06-03 15:35:26 -04: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 6f02172d2e Release mdadm-3.3
(and  various cosmetic fixes)

Signed-off-by: NeilBrown <neilb@suse.de>
2013-09-03 14:47:47 +10:00
NeilBrown 289c74f8d7 Move find_free_devnum to mdopen.c
There is only one called to find_free_devnum and it is in mdopen.c

The removes a dependency between util.c and config.c which allows
us to now drop config.o from mdmon.

Signed-off-by: NeilBrown <neilb@suse.de>
2013-07-02 10:24:50 +10:00
NeilBrown eca944fa9c create_mddev: add support for /dev/md_XXX non-numeric names.
With the 'devnm' infrastructure fixed, it is quite easy to support
names like "md_home" for md arrays.
The currently defaults to "off" and can be enabled in mdadm.conf with
  CREATE names=yes
This is incase other tools get confused by the new names.

Signed-off-by: NeilBrown <neilb@suse.de>
2013-05-15 11:03:25 +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 06d2ffc3e2 conditionally remove map_dev from find_free_devnum
map_dev can be slow so it is best to not call it when
not necessary.
The final test in "find_free_devnum" is not relevant when
udev is being used, so remove the test in that case.

Signed-off-by: NeilBrown <neilb@suse.de>
2013-01-07 10:17:04 +11:00
Justin Maggard 4cda8682c6 Create new md devices consistently
Creating a new MD device with the name 'd-0' results in some
 unexpected behavior, since mdadm sees that '-0' is a
 non-negative integer and therefore makes a "partitionable"
 device (/dev/md_d0).  This is not the expected behavior,
 since the documentation mentions 'dN' several places, and a
 reboot brings it up as /dev/md/d-0.  Make this consistent
 by ensuring that the character immediately following 'd' is
 a digit during creation.

Signed-off-by: NeilBrown <neilb@suse.de>
2012-10-24 12:07:32 +11: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 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 5ffdc2dd44 Update test for "is udev active".
Newer udev doesn't use /dev/.udev any more. it used
/run/udev instead.
So test for that as well.

Signed-off-by: NeilBrown <neilb@suse.de>
2012-05-03 14:16:51 +10:00
Jes Sorensen 96ae5973dd make_parts(): Fix case of comparing against uninitialized variables
Silencing gcc's warning of uninitialized variables was hiding a bug
where if we have /dev/md64 as a symlink, and /dev/md64p1 was a real
device node.

In this case major_num and minor_num would not get populated, but we
end up comparing against them because the stat for md64p1 succeeds.

Instead of using the int foo = foo trick, change the code to set
set the variables to invalid values so comparisons will fail.

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Signed-off-by: NeilBrown <neilb@suse.de>
2011-11-02 11:18:53 +11:00
Thomas Jarosch fca13185fc Fix unterminated buffer after readlink() call
Signed-off-by: Thomas Jarosch <thomas.jarosch@intra2net.com>
Signed-off-by: NeilBrown <neilb@suse.de>
2011-10-17 11:15:05 +11:00
NeilBrown c3f26510c6 open_mddev: open RDONLY if RDWR doesn't work.
If an array is read-only then "mdadm -S"
cannot open it to stop it without this fix.

Signed-off-by: NeilBrown <neilb@suse.de>
2011-01-31 14:49:39 +11:00
NeilBrown 0eb26465c0 Free some malloced memory that wasn't being freed.
As mdadm is normally a short-lived program it isn't always necessary
to free memory that was allocated, as the 'exit()' call will
automatically free everything.  But it is more obviously correct if
the 'free' is there.
So this patch add a few calls to 'free'

Signed-off-by: NeilBrown <neilb@suse.de>
2009-10-22 11:00:56 +11:00
NeilBrown 5ac6db12f9 mdopen: only use 'dev' as chosen name if it is a full path.
Otherwise using names like "r0" causes problem.  They are
handled sufficiently by other paths in the code.

Signed-off-by: NeilBrown <neilb@suse.de>
2009-10-19 17:11:15 +11:00
NeilBrown e736b62389 Update copyright dates and remove references to @cse.unsw.edu.au
Also removed 'paper' addresses.

Signed-off-by: NeilBrown <neilb@suse.de>
2009-06-02 14:35:45 +10:00
NeilBrown 9a40c32728 create_mddev: don't replace /dev/mdX with /dev/md/X
If someone creates/assemble an array called "/dev/md0", don't force
it to be "/dev/md/0".  Doing so isn't really necessary and it
likely to confuse people.

Signed-off-by: NeilBrown <neilb@suse.de>
2009-05-11 15:58:44 +10:00
NeilBrown d7ba0c55f0 create_dev - allow array names like mdX and /dev/mdX to appear 'numeric'
When choosing the minor number to use with an array, we currently base
the number of the 'name' stored in the metadata if that name is
numeric.
Extend that so that if it looks like a number md device name (/dev/md0
or just md0 or even /dev/md/0), then we use the number at the end to
suggest a minor number.

The means that if someone creates and array with "--name md0" or even
"--name /dev/md0" it will continue to do what they expect.

Signed-off-by: NeilBrown <neilb@suse.de>
2009-05-11 15:16:47 +10:00
NeilBrown add394f39e mdopen: be more careful when adding digit to names.
If we need to add digits to a name to make it unique, but don't have
to add '_', we need to avoid adding a digit immediately after a digit.
So if the last character of the name is a digit, add the '_' anyway.

Signed-off-by: NeilBrown <neilb@suse.de>
2009-03-10 16:28:22 +11:00
Dan Williams 614825ea82 some warn_unused_result fixups
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2008-11-27 15:29:54 +11:00
NeilBrown e10a79c344 mdopen: typo in buffer-length for a sprintf.
That '10000' should have been '1000'.  Make it a 'sizeof' to avoid
such carelessness.

Signed-off-by: NeilBrown <neilb@suse.de>
2008-11-07 14:46:51 +11:00
NeilBrown bde2c6e287 mdopen: only let numeric name set minor number if it doesn't cause a conflict.
So if the array with minor number matching the name of a new array
already exists, just assemble with a different minor number.

Signed-off-by: NeilBrown <neilb@suse.de>
2008-11-04 20:54:50 +11:00
NeilBrown f2e55eccfb mdopen: use small sequence number for uniquifying array names.
Rather than appending the md minor number, we now append a small
sequence number to make sure name in /dev/md/ that aren't LOCAL are
unique.  As the map file is locked while we do this, we are sure
of no losing any races.

Signed-off-by: NeilBrown <neilb@suse.de>
2008-11-04 20:51:12 +11:00
Dan Williams 197e3eb690 Quiet unitialized variable warnings
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
2008-11-04 20:50:39 +11:00
NeilBrown 11fb4c054f mdopen: fix up name parsing.
I think this is closer to what I want.  Fewer surprises anyway.
2008-11-04 20:50:39 +11:00
NeilBrown 215bb3f776 Incremental: adjust to the new naming scheme.
--incremental now uses exactly the same create_mddev that
other code uses.
2008-11-04 20:50:38 +11:00
NeilBrown c4fe2d4f56 mdopen: Restore creation of partition devices and symlink.
Using the 'new' name scheme we restore the creation of partition
links (in the case the udev isn't used).
2008-11-04 20:50:38 +11:00
NeilBrown 69207ff6ac mdopen: Introduce new rules for creating device name.
MORE CONTENT HERE
2008-11-04 20:50:21 +11:00
NeilBrown 6be1d39d1d Introduce new open_mddev which just does an open.
Some cases we aren't interested in creating the mddev, just opening
it.  Make those more explicit.

Signed-off-by: NeilBrown <neilb@suse.de>
2008-11-04 10:35:31 +11:00
NeilBrown 2399204ddd Rename open_mddev to create_mddev
This reflect that fact that more often than not it is creating things
in /dev, and allows for a new open_mddev which does just that.

Signed-off-by: NeilBrown <neilb@suse.de>
2008-11-04 10:35:10 +11:00
NeilBrown 6c766cf101 Merge branch 'master' into devel-3.0
Conflicts:

	Incremental.c
	super0.c
	super1.c
2008-10-30 13:59:11 +11:00
NeilBrown 7b403fef7e Incremental: allow assembly of foreign array.
If a foreign (i.e. not known to be local) array is discovered
by --incremental assembly, we now assemble it.  However we ignore
any name information in the array so as not to potentially create
a name that conflict with a 'local' array.
Also, foreign arrays are always assembled 'read-auto' to avoid writing
anything until the array is actually used.

Signed-off-by: NeilBrown <neilb@suse.de>
2008-10-30 09:48:18 +11:00
NeilBrown c5afc314e2 Lots of fixes to make incremental assembly of containers work.
So:
  mdadm -I /dev/whatever

will (if appropriate) add whatever to a container, then start
any arrays inside the container.
2008-09-18 16:03:05 +10:00
Doug Ledford fb97b4d691 Clean up usage of open()
Fix on call that passed an invalid mode to open
	Don't pass a third arg unless we also pass O_CREAT
	Use symbolic args for 2nd and 3rd args

Signed-off-by: Doug Ledford <dledford@redhat.com>
2008-07-24 18:35:11 -04:00