]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Incremental: add --export handling.
authorNeilBrown <neilb@suse.de>
Thu, 28 Nov 2013 04:15:30 +0000 (15:15 +1100)
committerNeilBrown <neilb@suse.de>
Thu, 28 Nov 2013 04:15:30 +0000 (15:15 +1100)
If --export is given with --incremental, then
  MD_DEVNAME
is output which gives the name of the device (in /dev/md) that
is the array (or container) that the device would be added to.
Also
  MD_STARTED
is set to one of
  no
  unsafe
  yes
  nothing

to indicate if the array was started.  IF MD_STARTED=unsafe
then it may be appropriate to run
  mdadm -R /dev/md/$MD_DEVNAME
after a timeout to ensure newly degraded array are started.

If
  MD_FOREIGN=yes
it might be appropriate to suppress this as the array is
probably not critical.

Signed-off-by: NeilBrown <neilb@suse.de>
Assemble.c
Incremental.c
mdadm.8.in
mdadm.h

index 11b77c288608f17c6f419fba0e7d33af1613de05..44e905bb8667a8dbbdce1d9a256efc1c62c50046 100644 (file)
@@ -1419,7 +1419,7 @@ try_again:
                /* This is a member of a container.  Try starting the array. */
                int err;
                err = assemble_container_content(st, mdfd, content, c,
-                                                chosen_name);
+                                                chosen_name, NULL);
                close(mdfd);
                return err;
        }
@@ -1771,7 +1771,7 @@ try_again:
 #ifndef MDASSEMBLE
 int assemble_container_content(struct supertype *st, int mdfd,
                               struct mdinfo *content, struct context *c,
-                              char *chosen_name)
+                              char *chosen_name, int *result)
 {
        struct mdinfo *dev, *sra;
        int working = 0, preexist = 0;
@@ -1838,7 +1838,9 @@ int assemble_container_content(struct supertype *st, int mdfd,
 
        if (enough(content->array.level, content->array.raid_disks,
                   content->array.layout, content->array.state & 1, avail) == 0) {
-               if (c->verbose >= 0) {
+               if (c->export && result)
+                       *result |= INCR_NO;
+               else if (c->verbose >= 0) {
                        pr_err("%s assembled with %d device%s",
                               chosen_name, preexist + working,
                               preexist + working == 1 ? "":"s");
@@ -1854,7 +1856,9 @@ int assemble_container_content(struct supertype *st, int mdfd,
        if (c->runstop <= 0 &&
            (working + preexist + expansion) <
            content->array.working_disks) {
-               if (c->verbose >= 0) {
+               if (c->export && result)
+                       *result |= INCR_UNSAFE;
+               else if (c->verbose >= 0) {
                        pr_err("%s assembled with %d device%s",
                               chosen_name, preexist + working,
                               preexist + working == 1 ? "":"s");
@@ -1918,7 +1922,12 @@ int assemble_container_content(struct supertype *st, int mdfd,
            !start_reshape)
                block_subarray(content);
 
-       if (c->verbose >= 0) {
+       if (c->export && result) {
+               if (err)
+                       *result |= INCR_NO;
+               else
+                       *result |= INCR_YES;
+       } else if (c->verbose >= 0) {
                if (err)
                        pr_err("array %s now has %d device%s",
                               chosen_name, working + preexist,
index d082e61d66e37d1072ae90988b854c285664c30e..0703deae187811c9e903b0cf50e141d6855dc9c1 100644 (file)
@@ -91,6 +91,7 @@ int Incremental(char *devname, struct context *c,
        struct mdinfo *sra = NULL, *d;
        struct mddev_ident *match;
        char chosen_name[1024];
+       char *md_devname;
        int rv = 1;
        struct map_ent *mp, *map = NULL;
        int dfd = -1, mdfd = -1;
@@ -138,6 +139,8 @@ int Incremental(char *devname, struct context *c,
                        if (map_lock(&map))
                                pr_err("failed to get "
                                       "exclusive lock on mapfile\n");
+                       if (c->export)
+                               printf("MD_DEVNAME=%s\n", devname);
                        rv = Incremental_container(st, devname, c, NULL);
                        map_unlock(&map);
                        return rv;
@@ -459,6 +462,15 @@ int Incremental(char *devname, struct context *c,
                        info.array.working_disks ++;
 
        }
+       if (strncmp(chosen_name, "/dev/md/", 8) == 0)
+               md_devname = chosen_name+8;
+       else
+               md_devname = chosen_name;
+       if (c->export) {
+               printf("MD_DEVICE=%s\n", fd2devnm(mdfd));
+               printf("MD_DEVNAME=%s\n", md_devname);
+               printf("MD_FOREIGN=%s\n", trustworthy == FOREIGN ? "yes" : "no");
+       }
 
        /* 7/ Is there enough devices to possibly start the array? */
        /* 7a/ if not, finish with success. */
@@ -466,7 +478,7 @@ int Incremental(char *devname, struct context *c,
                char devnm[32];
                /* Try to assemble within the container */
                sysfs_uevent(sra, "change");
-               if (c->verbose >= 0)
+               if (!c->export && c->verbose >= 0)
                        pr_err("container %s now has %d device%s\n",
                               chosen_name, info.array.working_disks,
                               info.array.working_disks == 1?"":"s");
@@ -498,7 +510,9 @@ int Incremental(char *devname, struct context *c,
        if (enough(info.array.level, info.array.raid_disks,
                   info.array.layout, info.array.state & 1,
                   avail) == 0) {
-               if (c->verbose >= 0)
+               if (c->export) {
+                       printf("MD_STARTED=no\n");
+               } else if (c->verbose >= 0)
                        pr_err("%s attached to %s, not enough to start (%d).\n",
                               devname, chosen_name, active_disks);
                rv = 0;
@@ -512,7 +526,9 @@ int Incremental(char *devname, struct context *c,
        /*   + start the array (auto-readonly). */
 
        if (ioctl(mdfd, GET_ARRAY_INFO, &ainf) == 0) {
-               if (c->verbose >= 0)
+               if (c->export) {
+                       printf("MD_STARTED=already\n");
+               } else if (c->verbose >= 0)
                        pr_err("%s attached to %s which is already active.\n",
                               devname, chosen_name);
                rv = 0;
@@ -559,7 +575,9 @@ int Incremental(char *devname, struct context *c,
                        rv = sysfs_set_str(sra, NULL,
                                           "array_state", "read-auto");
                if (rv == 0) {
-                       if (c->verbose >= 0)
+               if (c->export) {
+                       printf("MD_STARTED=yes\n");
+               } else if (c->verbose >= 0)
                                pr_err("%s attached to %s, which has been started.\n",
                                       devname, chosen_name);
                        rv = 0;
@@ -582,7 +600,9 @@ int Incremental(char *devname, struct context *c,
                        rv = 1;
                }
        } else {
-               if (c->verbose >= 0)
+               if (c->export) {
+                       printf("MD_STARTED=unsafe\n");
+               } else if (c->verbose >= 0)
                        pr_err("%s attached to %s, not enough to start safely.\n",
                               devname, chosen_name);
                rv = 0;
@@ -1436,6 +1456,7 @@ static int Incremental_container(struct supertype *st, char *devname,
        int sfd;
        int ra_blocked = 0;
        int ra_all = 0;
+       int result = 0;
 
        st->ss->getinfo_super(st, &info, NULL);
 
@@ -1443,7 +1464,9 @@ static int Incremental_container(struct supertype *st, char *devname,
            info.container_enough > 0)
                /* pass */;
        else {
-               if (c->verbose)
+               if (c->export) {
+                       printf("MD_STARTED=no\n");
+               } else if (c->verbose)
                        pr_err("not enough devices to start the container\n");
                return 0;
        }
@@ -1464,8 +1487,12 @@ static int Incremental_container(struct supertype *st, char *devname,
 
        list = st->ss->container_content(st, NULL);
        /* when nothing to activate - quit */
-       if (list == NULL)
+       if (list == NULL) {
+               if (c->export) {
+                       printf("MD_STARTED=nothing\n");
+               }
                return 0;
+       }
        for (ra = list ; ra ; ra = ra->next) {
                int mdfd;
                char chosen_name[1024];
@@ -1555,9 +1582,30 @@ static int Incremental_container(struct supertype *st, char *devname,
                }
 
                assemble_container_content(st, mdfd, ra, c,
-                                          chosen_name);
+                                          chosen_name, &result);
                close(mdfd);
        }
+       if (c->export && result) {
+               char sep = '=';
+               printf("MD_STARTED");
+               if (result & INCR_NO) {
+                       printf("%cno", sep);
+                       sep = ',';
+               }
+               if (result & INCR_UNSAFE) {
+                       printf("%cunsafe", sep);
+                       sep = ',';
+               }
+               if (result & INCR_ALREADY) {
+                       printf("%calready", sep);
+                       sep = ',';
+               }
+               if (result & INCR_YES) {
+                       printf("%cyes", sep);
+                       sep = ',';
+               }
+               printf("\n");
+       }
 
        /* don't move spares to container with volume being activated
           when all volumes are blocked */
index 61cb4f7100dc9c7616bcc245b3d0f0247061d0fb..f49822eccfaebf77a58dc50b5da8d4f330fc03ff 100644 (file)
@@ -1440,13 +1440,30 @@ absolute filepath or a link, e.g.
 .TP
 .BR \-Y ", " \-\-export
 When used with
-.B \-\-detail , \-\-detail-platform
-or
+.BR \-\-detail ,
+.BR \-\-detail-platform ,
 .BR \-\-examine ,
+or
+.B \-\-incremental
 output will be formatted as
 .B key=value
 pairs for easy import into the environment.
 
+With
+.B \-\-incremental
+The value
+.B MD_STARTED
+indicates whether an array was started
+.RB ( yes )
+or not, which may include a reason
+.RB ( unsafe ", " nothing ", " no ).
+Also the value
+.B MD_FOREIGN
+indicates if the array is expected on this host
+.RB ( no ),
+or seems to be from elsewhere
+.RB ( yes ).
+
 .TP
 .BR \-E ", " \-\-examine
 Print contents of the metadata stored on the named device(s).
diff --git a/mdadm.h b/mdadm.h
index 7cfdd8fd1cf9b97bacc263c355bb2eef03779052..c38fdfb935735ab12c4f21d61131b1e272f622b1 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -1331,7 +1331,11 @@ extern void append_metadata_update(struct supertype *st, void *buf, int len);
 extern int assemble_container_content(struct supertype *st, int mdfd,
                                      struct mdinfo *content,
                                      struct context *c,
-                                     char *chosen_name);
+                                     char *chosen_name, int *result);
+#define        INCR_NO         1
+#define        INCR_UNSAFE     2
+#define        INCR_ALREADY    4
+#define        INCR_YES        8
 extern struct mdinfo *container_choose_spares(struct supertype *st,
                                              unsigned long long min_size,
                                              struct domainlist *domlist,