config: add 'homehost' option to 'AUTO' line.

This allows basing auto-assembly decisions on whether
the array is recorded as belonging to this host or not.

Signed-off-by: NeilBrown <neilb@suse.de>
This commit is contained in:
NeilBrown 2010-03-03 14:33:55 +11:00
parent 5a9de8db04
commit d1d3482b56
7 changed files with 70 additions and 24 deletions

View File

@ -261,7 +261,8 @@ int Assemble(struct supertype *st, char *mddev,
devname);
tmpdev->used = 2;
} else if (auto_assem && st == NULL &&
!conf_test_metadata(tst->ss->name)) {
!conf_test_metadata(tst->ss->name,
tst->ss->match_home(tst, homehost) == 1)) {
if (report_missmatch)
fprintf(stderr, Name ": %s has metadata type %s for which "
"auto-assembly is disabled\n",

View File

@ -221,7 +221,22 @@ int Incremental(char *devname, int verbose, int runstop,
return 1;
}
if (!match && !conf_test_metadata(st->ss->name)) {
/* 3a/ if not, check for homehost match. If no match, continue
* but don't trust the 'name' in the array. Thus a 'random' minor
* number will be assigned, and the device name will be based
* on that. */
if (match)
trustworthy = LOCAL;
else if (st->ss->match_home(st, homehost) == 1)
trustworthy = LOCAL;
else if (st->ss->match_home(st, "any") == 1)
trustworthy = LOCAL_ANY;
else
trustworthy = FOREIGN;
if (!match && !conf_test_metadata(st->ss->name,
(trustworthy == LOCAL))) {
if (verbose >= 1)
fprintf(stderr, Name
": %s has metadata type %s for which "
@ -229,18 +244,7 @@ int Incremental(char *devname, int verbose, int runstop,
devname, st->ss->name);
return 1;
}
/* 3a/ if not, check for homehost match. If no match, continue
* but don't trust the 'name' in the array. Thus a 'random' minor
* number will be assigned, and the device name will be based
* on that. */
if (match)
trustworthy = LOCAL;
else if ((homehost == NULL ||
st->ss->match_home(st, homehost) != 1) &&
st->ss->match_home(st, "any") != 1)
trustworthy = FOREIGN;
else
if (trustworthy == LOCAL_ANY)
trustworthy = LOCAL;
/* There are three possible sources for 'autof': command line,

View File

@ -891,18 +891,26 @@ int conf_test_dev(char *devname)
return 0;
}
int conf_test_metadata(const char *version)
int conf_test_metadata(const char *version, int is_homehost)
{
/* Check if the given metadata version is allowed
* to be auto-assembled.
* The default is 'yes' but the 'auto' line might over-ride that.
* Word in auto_options are processed in order with the first
* Words in auto_options are processed in order with the first
* match winning.
* word can be:
* +version - that version can be assembled
* -version - that version cannot be auto-assembled
* yes or +all - any other version can be assembled
* no or -all - no other version can be assembled.
* homehost - any array associated by 'homehost' to this
* host can be assembled.
*
* Thus:
* +ddf -0.90 homehost -all
* will auto-assemble any ddf array, no 0.90 array, and
* any other array (imsm, 1.x) if and only if it is identified
* as belonging to this host.
*/
char *w;
load_conffile();
@ -914,6 +922,12 @@ int conf_test_metadata(const char *version)
return 1;
if (strcasecmp(w, "no") == 0)
return 0;
if (strcasecmp(w, "homehost") == 0) {
if (is_homehost)
return 1;
else
continue;
}
if (w[0] == '+')
rv = 1;
else if (w[0] == '-')

View File

@ -27,6 +27,14 @@
#DEVICE /dev/discs/*/*
#
#
# The AUTO line can control which arrays get assembled by auto-assembly,
# meaing either "mdadm -As" when there are no 'ARRAY' lines in this file,
# or "mdadm --incremental" when the array found is not listed in this file.
# By default, all arrays that are found are assembled.
# If you want to ignore all DDF arrays (maybe they are managed by dmraid),
# and only assemble 1.x arrays if which are marked for 'this' homehost,
# but assemble all others, then use
#AUTH -ddf hosthost -1.x +all
#
# ARRAY lines specify an array to assemble and a method of identification.
# Arrays can currently be identified by using a UUID, superblock minor number,

View File

@ -336,7 +336,7 @@ to suppress this symlink creation.
The
.B homehost
line gives a default value for the
.B --homehost=
.B \-\-homehost=
option to mdadm. There should normally be only one other word on the line.
It should either be a host name, or one of the special words
.B <system>
@ -375,15 +375,19 @@ or
.B AUTO
A list of names of metadata format can be given, each preceded by a
plus or minus sign. Also the word
.I homehost
is allowed as is
.I all
preceded by plus or minus is allowed and is usually last.
preceded by plus or minus sign.
.I all
is usually last.
When
.I mdadm
is auto-assembling an array, either via
.I --assemble
.I \-\-assemble
or
.I --incremental
.I \-\-incremental
and it finds metadata of a given type, it checks that metadata type
against those listed in this line. The first match wins, where
.I all
@ -393,10 +397,20 @@ assembly is allowed. If the match was preceded by a minus sign, the
auto assembly is disallowed. If no match is found, the auto assembly
is allowed.
If the metadata indicates that the array was created for
.I this
host, and the word
.I homehost
appears before any other match, then the array is treated as a valid
candidate for auto-assembly.
This can be used to disable all auto-assembly (so that only arrays
explicitly listed in mdadm.conf or on the command line are assembled),
or to disable assembly of certain metadata types which might be
handled by other software.
handled by other software. It can also be used to disable assembly of
all foreign arrays - normally such arrays are assembled but given a
non-deterministic name in
.BR /dev/md/ .
The known metadata types are
.BR 0.90 ,
@ -451,7 +465,7 @@ CREATE group=system mode=0640 auto=part\-8
.br
HOMEHOST <system>
.br
AUTO +1.x -all
AUTO +1.x homehost -all
.SH SEE ALSO
.BR mdadm (8),

View File

@ -844,7 +844,7 @@ extern int parse_auto(char *str, char *msg, int config);
extern mddev_ident_t conf_get_ident(char *dev);
extern mddev_dev_t conf_get_devs(void);
extern int conf_test_dev(char *devname);
extern int conf_test_metadata(const char *version);
extern int conf_test_metadata(const char *version, int is_homehost);
extern struct createinfo *conf_get_create_info(void);
extern void set_conffile(char *file);
extern char *conf_get_mailaddr(void);
@ -901,6 +901,7 @@ extern int create_mddev(char *dev, char *name, int autof, int trustworthy,
char *chosen);
/* values for 'trustworthy' */
#define LOCAL 1
#define LOCAL_ANY 10
#define FOREIGN 2
#define METADATA 3
extern int open_mddev(char *dev, int report_errors);

View File

@ -1260,7 +1260,11 @@ static int match_home_ddf(struct supertype *st, char *homehost)
* the hostname
*/
struct ddf_super *ddf = st->sb;
int len = strlen(homehost);
int len;
if (!homehost)
return 0;
len = strlen(homehost);
return (memcmp(ddf->controller.guid, T10, 8) == 0 &&
len < sizeof(ddf->controller.vendor_data) &&