Add 'supertype' arg to almost all metadata methods.
[thirdparty/mdadm.git] / Examine.c
CommitLineData
64c4757e 1/*
9a9dab36 2 * mdadm - manage Linux "md" devices aka RAID arrays.
64c4757e 3 *
4f589ad0 4 * Copyright (C) 2001-2006 Neil Brown <neilb@suse.de>
64c4757e
NB
5 *
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 * Author: Neil Brown
22 * Email: <neilb@cse.unsw.edu.au>
23 * Paper: Neil Brown
24 * School of Computer Science and Engineering
25 * The University of New South Wales
26 * Sydney, 2052
27 * Australia
28 */
29
9a9dab36 30#include "mdadm.h"
cd29a5c8 31#include "dlink.h"
64c4757e 32
82b27616
NB
33#if ! defined(__BIG_ENDIAN) && ! defined(__LITTLE_ENDIAN)
34#error no endian defined
35#endif
64c4757e
NB
36#include "md_u.h"
37#include "md_p.h"
a1cbd7d0
NB
38int Examine(mddev_dev_t devlist, int brief, int scan,
39 int SparcAdjust, struct supertype *forcest,
40 char *homehost)
64c4757e
NB
41{
42
43 /* Read the raid superblock from a device and
44 * display important content.
45 *
46 * If cannot be found, print reason: too small, bad magic
47 *
48 * Print:
49 * version, ctime, level, size, raid+spare+
50 * prefered minor
51 * uuid
52 *
53 * utime, state etc
54 *
9a9dab36 55 * If (brief) gather devices for same array and just print a mdadm.conf line including devices=
8b0dabea 56 * if devlist==NULL, use conf_get_devs()
64c4757e 57 */
aba69144 58 int fd;
4b1ac34b 59 void *super = NULL;
cd29a5c8 60 int rv = 0;
6baf9a87 61 int err = 0;
64c4757e 62
cd29a5c8 63 struct array {
4b1ac34b 64 void *super;
82d9eba6 65 struct supertype *st;
4b1ac34b 66 struct mdinfo info;
cd29a5c8
NB
67 void *devs;
68 struct array *next;
4b1ac34b 69 int spares;
cd29a5c8
NB
70 } *arrays = NULL;
71
cd29a5c8 72 for (; devlist ; devlist=devlist->next) {
82d9eba6 73 struct supertype *st = forcest;
f9ce90ba 74
8b0dabea 75 fd = dev_open(devlist->devname, O_RDONLY);
cd29a5c8 76 if (fd < 0) {
751406f3 77 if (!scan) {
cd29a5c8
NB
78 fprintf(stderr,Name ": cannot open %s: %s\n",
79 devlist->devname, strerror(errno));
e52f8e25 80 rv = 1;
751406f3 81 }
e52f8e25 82 err = 1;
cd29a5c8
NB
83 }
84 else {
82d9eba6
NB
85 if (!st)
86 st = guess_super(fd);
87 if (st)
88 err = st->ss->load_super(st, fd, &super, (brief||scan)?NULL:devlist->devname);
6baf9a87 89 else {
e52f8e25 90 if (!brief) {
6baf9a87 91 fprintf(stderr, Name ": No md superblock detected on %s.\n", devlist->devname);
e52f8e25
NB
92 rv = 1;
93 }
f9ce90ba 94 err = 1;
6baf9a87 95 }
cd29a5c8
NB
96 close(fd);
97 }
e52f8e25 98 if (err)
cd29a5c8 99 continue;
4b1ac34b
NB
100
101 if (SparcAdjust)
68c7d6d7
NB
102 st->ss->update_super(st, NULL, super, "sparc2.2",
103 devlist->devname, 0, 0, NULL);
cd29a5c8
NB
104 /* Ok, its good enough to try, though the checksum could be wrong */
105 if (brief) {
106 struct array *ap;
107 char *d;
108 for (ap=arrays; ap; ap=ap->next) {
68c7d6d7
NB
109 if (st->ss == ap->st->ss &&
110 st->ss->compare_super(&ap->super, super)==0)
cd29a5c8
NB
111 break;
112 }
113 if (!ap) {
114 ap = malloc(sizeof(*ap));
115 ap->super = super;
116 ap->devs = dl_head();
117 ap->next = arrays;
4b1ac34b 118 ap->spares = 0;
82d9eba6 119 ap->st = st;
cd29a5c8 120 arrays = ap;
68c7d6d7 121 st->ss->getinfo_super(st, &ap->info, super);
4b1ac34b 122 } else {
68c7d6d7
NB
123 st->ss->getinfo_super(st, &ap->info, super);
124 st->ss->free_super(st, super);
cd29a5c8 125 }
4b1ac34b
NB
126 if (!(ap->info.disk.state & MD_DISK_SYNC))
127 ap->spares++;
cd29a5c8
NB
128 d = dl_strdup(devlist->devname);
129 dl_add(ap->devs, d);
130 } else {
131 printf("%s:\n",devlist->devname);
68c7d6d7
NB
132 st->ss->examine_super(st, super, homehost);
133 st->ss->free_super(st, super);
bd526cee 134 }
82b27616 135 }
cd29a5c8
NB
136 if (brief) {
137 struct array *ap;
138 for (ap=arrays; ap; ap=ap->next) {
139 char sep='=';
cd29a5c8 140 char *d;
68c7d6d7 141 ap->st->ss->brief_examine_super(ap->st, ap->super);
4b1ac34b 142 if (ap->spares) printf(" spares=%d", ap->spares);
22892d56
NB
143 if (brief > 1) {
144 printf(" devices");
145 for (d=dl_next(ap->devs); d!= ap->devs; d=dl_next(d)) {
146 printf("%c%s", sep, d);
147 sep=',';
148 }
cd29a5c8 149 }
68c7d6d7 150 ap->st->ss->free_super(ap->st, ap->super);
4b1ac34b 151 /* FIXME free ap */
d9d4e469
NB
152 if (ap->spares || brief > 1)
153 printf("\n");
cd29a5c8 154 }
64c4757e 155 }
cd29a5c8 156 return rv;
64c4757e 157}