]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
config: add 'homehost' option to 'AUTO' line.
authorNeilBrown <neilb@suse.de>
Wed, 3 Mar 2010 03:33:55 +0000 (14:33 +1100)
committerNeilBrown <neilb@suse.de>
Wed, 3 Mar 2010 03:33:55 +0000 (14:33 +1100)
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>
Assemble.c
Incremental.c
config.c
mdadm.conf-example
mdadm.conf.5
mdadm.h
super-ddf.c

index 1f73a5be05f5339ee6811860f269e0556bc684d5..b3052ac37f65d4ba863992254a382ed84801a6d2 100644 (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",
index 8c686f7e8e6bde1d426d8731f3bdeca8a9d5c1d3..7ad648a336d8de576afda3e83226037649fa2a71 100644 (file)
@@ -221,26 +221,30 @@ int Incremental(char *devname, int verbose, int runstop,
                return 1;
        }
 
-       if (!match && !conf_test_metadata(st->ss->name)) {
-               if (verbose >= 1)
-                       fprintf(stderr, Name
-                               ": %s has metadata type %s for which "
-                               "auto-assembly is disabled\n",
-                               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 (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 "
+                               "auto-assembly is disabled\n",
+                               devname, st->ss->name);
+               return 1;
+       }
+       if (trustworthy == LOCAL_ANY)
                trustworthy = LOCAL;
 
        /* There are three possible sources for 'autof':  command line,
index 07a12dcb3ff6f98d358c964378a6a3a6f4445879..20c46e9eb1fc058cb5290b1502f63d735defdc73 100644 (file)
--- a/config.c
+++ b/config.c
@@ -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] == '-')
index 2d83fc0b5317168b0979cf5d07595a9c3acfa806..9250f233fa0986e59c27a641788b7f5854ec7056 100644 (file)
 #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,
index 1c2ae58f093b604f1321f30dbd84bcc4d66d1dcb..e677ba9ec4ddd65c0b2377f7455875407a35f79d 100644 (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 sign.
 .I all
-preceded by plus or minus is allowed and is usually last.
+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),
diff --git a/mdadm.h b/mdadm.h
index 3628ea0220b0b41822f3745e93a1f8ade4b9348d..362b66b1a874c12a78f04dfd0a2d4236911c0984 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -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);
index 870efd8296063633253214c82974d83af09829c8..c2c562f1ec19d37cae50016cc612a03b02ad55bf 100644 (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) &&