]> git.ipfire.org Git - thirdparty/mdadm.git/blob - Examine.c
Allow autoassembly to choose it's own name for the array.
[thirdparty/mdadm.git] / Examine.c
1 /*
2 * mdadm - manage Linux "md" devices aka RAID arrays.
3 *
4 * Copyright (C) 2001-2006 Neil Brown <neilb@suse.de>
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
30 #include "mdadm.h"
31 #include "dlink.h"
32
33 #if ! defined(__BIG_ENDIAN) && ! defined(__LITTLE_ENDIAN)
34 #error no endian defined
35 #endif
36 #include "md_u.h"
37 #include "md_p.h"
38 int Examine(mddev_dev_t devlist, int brief, int scan,
39 int SparcAdjust, struct supertype *forcest,
40 char *homehost)
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 *
55 * If (brief) gather devices for same array and just print a mdadm.conf line including devices=
56 * if devlist==NULL, use conf_get_devs()
57 */
58 int fd;
59 void *super = NULL;
60 int rv = 0;
61 int err = 0;
62
63 struct array {
64 void *super;
65 struct supertype *st;
66 struct mdinfo info;
67 void *devs;
68 struct array *next;
69 int spares;
70 } *arrays = NULL;
71
72 for (; devlist ; devlist=devlist->next) {
73 struct supertype *st = forcest;
74
75 fd = dev_open(devlist->devname, O_RDONLY);
76 if (fd < 0) {
77 if (!scan) {
78 fprintf(stderr,Name ": cannot open %s: %s\n",
79 devlist->devname, strerror(errno));
80 err = 1;
81 }
82 }
83 else {
84 if (!st)
85 st = guess_super(fd);
86 if (st)
87 err = st->ss->load_super(st, fd, &super, (brief||scan)?NULL:devlist->devname);
88 else {
89 if (!brief)
90 fprintf(stderr, Name ": No md superblock detected on %s.\n", devlist->devname);
91 err = 1;
92 }
93 close(fd);
94 }
95 if (err) {
96 rv = 1;
97 continue;
98 }
99
100 if (SparcAdjust)
101 st->ss->update_super(NULL, super, "sparc2.2", devlist->devname, 0, 0, NULL);
102 /* Ok, its good enough to try, though the checksum could be wrong */
103 if (brief) {
104 struct array *ap;
105 char *d;
106 for (ap=arrays; ap; ap=ap->next) {
107 if (st->ss == ap->st->ss && st->ss->compare_super(&ap->super, super)==0)
108 break;
109 }
110 if (!ap) {
111 ap = malloc(sizeof(*ap));
112 ap->super = super;
113 ap->devs = dl_head();
114 ap->next = arrays;
115 ap->spares = 0;
116 ap->st = st;
117 arrays = ap;
118 st->ss->getinfo_super(&ap->info, super);
119 } else {
120 st->ss->getinfo_super(&ap->info, super);
121 free(super);
122 }
123 if (!(ap->info.disk.state & MD_DISK_SYNC))
124 ap->spares++;
125 d = dl_strdup(devlist->devname);
126 dl_add(ap->devs, d);
127 } else {
128 printf("%s:\n",devlist->devname);
129 st->ss->examine_super(super, homehost);
130 free(super);
131 }
132 }
133 if (brief) {
134 struct array *ap;
135 for (ap=arrays; ap; ap=ap->next) {
136 char sep='=';
137 char *d;
138 ap->st->ss->brief_examine_super(ap->super);
139 if (ap->spares) printf(" spares=%d", ap->spares);
140 if (brief > 1) {
141 printf(" devices");
142 for (d=dl_next(ap->devs); d!= ap->devs; d=dl_next(d)) {
143 printf("%c%s", sep, d);
144 sep=',';
145 }
146 }
147 free(ap->super);
148 /* FIXME free ap */
149 if (ap->spares || brief > 1)
150 printf("\n");
151 }
152 }
153 return rv;
154 }