]>
Commit | Line | Data |
---|---|---|
64c4757e | 1 | /* |
9a9dab36 | 2 | * mdadm - manage Linux "md" devices aka RAID arrays. |
64c4757e | 3 | * |
6f02172d | 4 | * Copyright (C) 2001-2013 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 | |
e736b623 | 22 | * Email: <neilb@suse.de> |
64c4757e NB |
23 | */ |
24 | ||
9a9dab36 | 25 | #include "mdadm.h" |
cd29a5c8 | 26 | #include "dlink.h" |
64c4757e | 27 | |
82b27616 NB |
28 | #if ! defined(__BIG_ENDIAN) && ! defined(__LITTLE_ENDIAN) |
29 | #error no endian defined | |
30 | #endif | |
64c4757e NB |
31 | #include "md_u.h" |
32 | #include "md_p.h" | |
eec3f887 N |
33 | int Examine(struct mddev_dev *devlist, |
34 | struct context *c, | |
35 | struct supertype *forcest) | |
64c4757e NB |
36 | { |
37 | ||
38 | /* Read the raid superblock from a device and | |
39 | * display important content. | |
40 | * | |
41 | * If cannot be found, print reason: too small, bad magic | |
42 | * | |
43 | * Print: | |
44 | * version, ctime, level, size, raid+spare+ | |
45 | * prefered minor | |
46 | * uuid | |
47 | * | |
48 | * utime, state etc | |
49 | * | |
ca3b6696 N |
50 | * If (brief) gather devices for same array and just print a mdadm.conf |
51 | * line including devices= | |
8b0dabea | 52 | * if devlist==NULL, use conf_get_devs() |
64c4757e | 53 | */ |
aba69144 | 54 | int fd; |
cd29a5c8 | 55 | int rv = 0; |
64c4757e | 56 | |
cd29a5c8 | 57 | struct array { |
82d9eba6 | 58 | struct supertype *st; |
4b1ac34b | 59 | struct mdinfo info; |
cd29a5c8 NB |
60 | void *devs; |
61 | struct array *next; | |
4b1ac34b | 62 | int spares; |
cd29a5c8 NB |
63 | } *arrays = NULL; |
64 | ||
ca3b6696 | 65 | for (; devlist ; devlist = devlist->next) { |
0ea2b5ef | 66 | struct supertype *st; |
1f49fb3a | 67 | int have_container = 0; |
36352fc9 N |
68 | int err = 0; |
69 | int container = 0; | |
f9ce90ba | 70 | |
8b0dabea | 71 | fd = dev_open(devlist->devname, O_RDONLY); |
cd29a5c8 | 72 | if (fd < 0) { |
eec3f887 | 73 | if (!c->scan) { |
e7b84f9d N |
74 | pr_err("cannot open %s: %s\n", |
75 | devlist->devname, strerror(errno)); | |
e52f8e25 | 76 | rv = 1; |
751406f3 | 77 | } |
36352fc9 | 78 | continue; |
cd29a5c8 | 79 | } |
36352fc9 N |
80 | |
81 | if (forcest) | |
82 | st = dup_super(forcest); | |
83 | else if (must_be_container(fd)) { | |
84 | /* might be a container */ | |
85 | st = super_by_fd(fd, NULL); | |
86 | container = 1; | |
87 | } else | |
88 | st = guess_super(fd); | |
89 | if (st) { | |
90 | err = 1; | |
91 | st->ignore_hw_compat = 1; | |
92 | if (!container) | |
93 | err = st->ss->load_super(st, fd, | |
94 | (c->brief||c->scan) ? NULL | |
95 | :devlist->devname); | |
96 | if (err && st->ss->load_container) { | |
97 | err = st->ss->load_container(st, fd, | |
98 | (c->brief||c->scan) ? NULL | |
99 | :devlist->devname); | |
100 | if (!err) | |
101 | have_container = 1; | |
6baf9a87 | 102 | } |
36352fc9 N |
103 | st->ignore_hw_compat = 0; |
104 | } else { | |
105 | if (!c->brief) { | |
106 | pr_err("No md superblock detected on %s.\n", devlist->devname); | |
107 | rv = 1; | |
108 | } | |
109 | err = 1; | |
cd29a5c8 | 110 | } |
36352fc9 N |
111 | close(fd); |
112 | ||
113 | if (err) { | |
114 | if (st) | |
115 | st->ss->free_super(st); | |
cd29a5c8 | 116 | continue; |
36352fc9 | 117 | } |
4b1ac34b | 118 | |
eec3f887 | 119 | if (c->SparcAdjust) |
3da92f27 | 120 | st->ss->update_super(st, NULL, "sparc2.2", |
68c7d6d7 | 121 | devlist->devname, 0, 0, NULL); |
cd29a5c8 | 122 | /* Ok, its good enough to try, though the checksum could be wrong */ |
0d726f17 | 123 | |
eec3f887 N |
124 | if (c->brief && st->ss->brief_examine_super == NULL) { |
125 | if (!c->scan) | |
e7b84f9d | 126 | pr_err("No brief listing for %s on %s\n", |
36352fc9 | 127 | st->ss->name, devlist->devname); |
eec3f887 | 128 | } else if (c->brief) { |
cd29a5c8 NB |
129 | struct array *ap; |
130 | char *d; | |
ca3b6696 | 131 | for (ap = arrays; ap; ap = ap->next) { |
68c7d6d7 | 132 | if (st->ss == ap->st->ss && |
c7b8547c | 133 | st->ss->compare_super(ap->st, st, 0) == 0) |
cd29a5c8 NB |
134 | break; |
135 | } | |
136 | if (!ap) { | |
503975b9 | 137 | ap = xmalloc(sizeof(*ap)); |
cd29a5c8 NB |
138 | ap->devs = dl_head(); |
139 | ap->next = arrays; | |
4b1ac34b | 140 | ap->spares = 0; |
82d9eba6 | 141 | ap->st = st; |
cd29a5c8 | 142 | arrays = ap; |
a5d85af7 | 143 | st->ss->getinfo_super(st, &ap->info, NULL); |
37424f13 | 144 | } else |
a5d85af7 | 145 | st->ss->getinfo_super(st, &ap->info, NULL); |
1f49fb3a | 146 | if (!have_container && |
ed57a7e8 | 147 | !(ap->info.disk.state & (1<<MD_DISK_SYNC))) |
4b1ac34b | 148 | ap->spares++; |
cd29a5c8 NB |
149 | d = dl_strdup(devlist->devname); |
150 | dl_add(ap->devs, d); | |
eec3f887 | 151 | } else if (c->export) { |
bceedeec N |
152 | if (st->ss->export_examine_super) |
153 | st->ss->export_examine_super(st); | |
1cc7f4fe | 154 | st->ss->free_super(st); |
cd29a5c8 NB |
155 | } else { |
156 | printf("%s:\n",devlist->devname); | |
eec3f887 | 157 | st->ss->examine_super(st, c->homehost); |
3da92f27 | 158 | st->ss->free_super(st); |
bd526cee | 159 | } |
82b27616 | 160 | } |
eec3f887 | 161 | if (c->brief) { |
cd29a5c8 | 162 | struct array *ap; |
ca3b6696 | 163 | for (ap = arrays; ap; ap = ap->next) { |
cd29a5c8 | 164 | char sep='='; |
cd29a5c8 | 165 | char *d; |
ee836c39 DW |
166 | int newline = 0; |
167 | ||
eec3f887 | 168 | ap->st->ss->brief_examine_super(ap->st, c->verbose > 0); |
ee836c39 DW |
169 | if (ap->spares) |
170 | newline += printf(" spares=%d", ap->spares); | |
eec3f887 | 171 | if (c->verbose > 0) { |
ee836c39 | 172 | newline += printf(" devices"); |
ca3b6696 N |
173 | for (d = dl_next(ap->devs); |
174 | d != ap->devs; | |
175 | d=dl_next(d)) { | |
22892d56 NB |
176 | printf("%c%s", sep, d); |
177 | sep=','; | |
178 | } | |
cd29a5c8 | 179 | } |
ee836c39 DW |
180 | if (ap->st->ss->brief_examine_subarrays) { |
181 | if (newline) | |
182 | printf("\n"); | |
eec3f887 | 183 | ap->st->ss->brief_examine_subarrays(ap->st, c->verbose); |
ee836c39 | 184 | } |
3da92f27 | 185 | ap->st->ss->free_super(ap->st); |
4b1ac34b | 186 | /* FIXME free ap */ |
eec3f887 | 187 | if (ap->spares || c->verbose > 0) |
d9d4e469 | 188 | printf("\n"); |
cd29a5c8 | 189 | } |
64c4757e | 190 | } |
cd29a5c8 | 191 | return rv; |
64c4757e | 192 | } |
6d388a88 N |
193 | |
194 | int ExamineBadblocks(char *devname, int brief, struct supertype *forcest) | |
195 | { | |
196 | int fd = dev_open(devname, O_RDONLY); | |
197 | struct supertype *st = forcest; | |
198 | int err = 1; | |
199 | ||
200 | if (fd < 0) { | |
201 | pr_err("cannot open %s: %s\n", devname, strerror(errno)); | |
202 | return 1; | |
203 | } | |
204 | if (!st) | |
205 | st = guess_super(fd); | |
206 | if (!st) { | |
207 | if (!brief) | |
208 | pr_err("No md superblock detected on %s\n", devname); | |
209 | goto out; | |
210 | } | |
211 | if (!st->ss->examine_badblocks) { | |
212 | pr_err("%s metadata does not support badblocks\n", st->ss->name); | |
213 | goto out; | |
214 | } | |
215 | err = st->ss->load_super(st, fd, brief ? NULL : devname); | |
216 | if (err) | |
217 | goto out; | |
218 | err = st->ss->examine_badblocks(st, fd, devname); | |
219 | ||
220 | out: | |
221 | if (fd >= 0) | |
222 | close(fd); | |
223 | if (st) { | |
224 | st->ss->free_super(st); | |
225 | free(st); | |
226 | } | |
227 | return err; | |
228 | } |