]> git.ipfire.org Git - thirdparty/mdadm.git/blame - Examine.c
Stuff like..
[thirdparty/mdadm.git] / Examine.c
CommitLineData
64c4757e 1/*
9a9dab36 2 * mdadm - manage Linux "md" devices aka RAID arrays.
64c4757e 3 *
cd29a5c8 4 * Copyright (C) 2001-2002 Neil Brown <neilb@cse.unsw.edu.au>
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"
82d9eba6 38int Examine(mddev_dev_t devlist, int brief, int scan, int SparcAdjust, struct supertype *forcest)
64c4757e
NB
39{
40
41 /* Read the raid superblock from a device and
42 * display important content.
43 *
44 * If cannot be found, print reason: too small, bad magic
45 *
46 * Print:
47 * version, ctime, level, size, raid+spare+
48 * prefered minor
49 * uuid
50 *
51 * utime, state etc
52 *
9a9dab36 53 * If (brief) gather devices for same array and just print a mdadm.conf line including devices=
8b0dabea 54 * if devlist==NULL, use conf_get_devs()
64c4757e 55 */
cd29a5c8 56 int fd;
4b1ac34b 57 void *super = NULL;
cd29a5c8 58 int rv = 0;
6baf9a87 59 int err = 0;
64c4757e 60
cd29a5c8 61 struct array {
4b1ac34b 62 void *super;
82d9eba6 63 struct supertype *st;
4b1ac34b 64 struct mdinfo info;
947fd4dd 65 struct mddev_ident_s ident;
cd29a5c8
NB
66 void *devs;
67 struct array *next;
4b1ac34b 68 int spares;
cd29a5c8
NB
69 } *arrays = NULL;
70
cd29a5c8 71 for (; devlist ; devlist=devlist->next) {
82d9eba6 72 struct supertype *st = forcest;
f9ce90ba 73
8b0dabea 74 fd = dev_open(devlist->devname, O_RDONLY);
cd29a5c8
NB
75 if (fd < 0) {
76 if (!scan)
77 fprintf(stderr,Name ": cannot open %s: %s\n",
78 devlist->devname, strerror(errno));
79 err = 1;
80 }
81 else {
82d9eba6
NB
82 if (!st)
83 st = guess_super(fd);
84 if (st)
85 err = st->ss->load_super(st, fd, &super, (brief||scan)?NULL:devlist->devname);
6baf9a87
NB
86 else {
87 if (!brief)
88 fprintf(stderr, Name ": No md superblock detected on %s.\n", devlist->devname);
f9ce90ba 89 err = 1;
6baf9a87 90 }
cd29a5c8
NB
91 close(fd);
92 }
6baf9a87
NB
93 if (err) {
94 rv = 1;
cd29a5c8 95 continue;
6baf9a87 96 }
4b1ac34b
NB
97
98 if (SparcAdjust)
dab6685f 99 st->ss->update_super(NULL, super, "sparc2.2", devlist->devname, 0);
cd29a5c8
NB
100 /* Ok, its good enough to try, though the checksum could be wrong */
101 if (brief) {
102 struct array *ap;
103 char *d;
104 for (ap=arrays; ap; ap=ap->next) {
82d9eba6 105 if (st->ss == ap->st->ss && st->ss->compare_super(&ap->super, super)==0)
cd29a5c8
NB
106 break;
107 }
108 if (!ap) {
109 ap = malloc(sizeof(*ap));
110 ap->super = super;
111 ap->devs = dl_head();
112 ap->next = arrays;
4b1ac34b 113 ap->spares = 0;
82d9eba6 114 ap->st = st;
cd29a5c8 115 arrays = ap;
947fd4dd 116 st->ss->getinfo_super(&ap->info, &ap->ident, super);
4b1ac34b 117 } else {
947fd4dd 118 st->ss->getinfo_super(&ap->info, &ap->ident, super);
4b1ac34b 119 free(super);
cd29a5c8 120 }
4b1ac34b
NB
121 if (!(ap->info.disk.state & MD_DISK_SYNC))
122 ap->spares++;
cd29a5c8
NB
123 d = dl_strdup(devlist->devname);
124 dl_add(ap->devs, d);
125 } else {
126 printf("%s:\n",devlist->devname);
82d9eba6 127 st->ss->examine_super(super);
4b1ac34b 128 free(super);
bd526cee 129 }
82b27616 130 }
cd29a5c8
NB
131 if (brief) {
132 struct array *ap;
133 for (ap=arrays; ap; ap=ap->next) {
134 char sep='=';
cd29a5c8 135 char *d;
82d9eba6 136 ap->st->ss->brief_examine_super(ap->super);
4b1ac34b 137 if (ap->spares) printf(" spares=%d", ap->spares);
22892d56
NB
138 if (brief > 1) {
139 printf(" devices");
140 for (d=dl_next(ap->devs); d!= ap->devs; d=dl_next(d)) {
141 printf("%c%s", sep, d);
142 sep=',';
143 }
cd29a5c8 144 }
4b1ac34b
NB
145 free(ap->super);
146 /* FIXME free ap */
d9d4e469
NB
147 if (ap->spares || brief > 1)
148 printf("\n");
cd29a5c8 149 }
64c4757e 150 }
cd29a5c8 151 return rv;
64c4757e 152}