]>
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" |
64c4757e NB |
26 | #include "md_p.h" |
27 | #include "md_u.h" | |
b9c9bd9b | 28 | #include <ctype.h> |
c69b251b | 29 | #include <dirent.h> |
64c4757e | 30 | |
41a663b2 | 31 | static int cmpstringp(const void *p1, const void *p2) |
32 | { | |
33 | return strcmp(* (char * const *) p1, * (char * const *) p2); | |
34 | } | |
35 | ||
b76dc299 MW |
36 | static int add_device(const char *dev, char ***p_devices, |
37 | int *p_max_devices, int n_devices) | |
38 | { | |
39 | if (n_devices + 1 >= *p_max_devices) { | |
40 | *p_max_devices += 16; | |
41 | *p_devices = xrealloc(*p_devices, *p_max_devices * | |
42 | sizeof(**p_devices)); | |
43 | if (!*p_devices) { | |
44 | *p_max_devices = 0; | |
45 | return 0; | |
46 | } | |
47 | }; | |
48 | (*p_devices)[n_devices] = xstrdup(dev); | |
49 | return n_devices + 1; | |
50 | } | |
51 | ||
ef898ce6 | 52 | int Detail(char *dev, struct context *c) |
64c4757e NB |
53 | { |
54 | /* | |
d97572f5 | 55 | * Print out details for an md array |
64c4757e | 56 | */ |
fb97b4d6 | 57 | int fd = open(dev, O_RDONLY); |
64c4757e | 58 | mdu_array_info_t array; |
b0c63f32 NB |
59 | mdu_disk_info_t *disks; |
60 | int next; | |
64c4757e NB |
61 | int d; |
62 | time_t atime; | |
4df01ff5 | 63 | char *str; |
41a663b2 | 64 | char **devices = NULL; |
65 | int max_devices = 0, n_devices = 0; | |
feb716e9 | 66 | int spares = 0; |
dd0781e5 | 67 | struct stat stb; |
e5329c37 | 68 | int failed = 0; |
9aaada05 | 69 | struct supertype *st; |
4725bc31 | 70 | char *subarray = NULL; |
e27d562b | 71 | int max_disks = MD_SB_DISKS; /* just a default */ |
a1f976a0 | 72 | struct mdinfo *info = NULL; |
142cb9e1 | 73 | struct mdinfo *sra; |
e6fc80a8 | 74 | struct mdinfo *subdev; |
c69b251b N |
75 | char *member = NULL; |
76 | char *container = NULL; | |
64c4757e | 77 | |
ef898ce6 | 78 | int rv = c->test ? 4 : 1; |
a77be586 | 79 | int avail_disks = 0; |
d0673517 | 80 | char *avail = NULL; |
e6fc80a8 N |
81 | int external; |
82 | int inactive; | |
82b27616 | 83 | |
64c4757e | 84 | if (fd < 0) { |
e7b84f9d | 85 | pr_err("cannot open %s: %s\n", |
64c4757e | 86 | dev, strerror(errno)); |
feb716e9 | 87 | return rv; |
64c4757e | 88 | } |
a4dcdb23 | 89 | sra = sysfs_read(fd, NULL, GET_VERSION | GET_DEVS | GET_ARRAY_STATE); |
901d5ee6 JS |
90 | if (!sra) { |
91 | pr_err("%s does not appear to be an md device\n", dev); | |
64c4757e | 92 | close(fd); |
feb716e9 | 93 | return rv; |
64c4757e | 94 | } |
901d5ee6 JS |
95 | external = (sra != NULL && sra->array.major_version == -1 && |
96 | sra->array.minor_version == -2); | |
a4dcdb23 JS |
97 | inactive = (sra->array_state == ARRAY_ACTIVE || |
98 | sra->array_state == ARRAY_CLEAR); | |
e6fc80a8 | 99 | st = super_by_fd(fd, &subarray); |
a4dcdb23 | 100 | if (md_get_array_info(fd, &array) && errno == ENODEV) { |
b4decd51 N |
101 | if (sra->array.major_version == -1 && |
102 | sra->array.minor_version == -1 && | |
103 | sra->devs == NULL) { | |
104 | pr_err("Array associated with md device %s does not exist.\n", dev); | |
105 | close(fd); | |
106 | sysfs_free(sra); | |
107 | return rv; | |
108 | } | |
e6fc80a8 | 109 | array = sra->array; |
e6fc80a8 N |
110 | } else { |
111 | pr_err("cannot get array detail for %s: %s\n", | |
112 | dev, strerror(errno)); | |
64c4757e | 113 | close(fd); |
feb716e9 | 114 | return rv; |
64c4757e | 115 | } |
f9ce90ba | 116 | |
dd0781e5 NB |
117 | if (fstat(fd, &stb) != 0 && !S_ISBLK(stb.st_mode)) |
118 | stb.st_rdev = 0; | |
feb716e9 | 119 | rv = 0; |
e5329c37 | 120 | |
c69b251b N |
121 | if (st) |
122 | max_disks = st->max_devs; | |
123 | ||
5f7e44b2 | 124 | if (subarray) { |
c69b251b N |
125 | /* This is a subarray of some container. |
126 | * We want the name of the container, and the member | |
127 | */ | |
13db17bd | 128 | dev_t devid = devnm2devid(st->container_devnm); |
c1ea5a98 | 129 | int cfd, err; |
5f7e44b2 DW |
130 | |
131 | member = subarray; | |
4dd2df09 N |
132 | container = map_dev_preferred(major(devid), minor(devid), |
133 | 1, c->prefer); | |
c1ea5a98 | 134 | cfd = open_dev(st->container_devnm); |
135 | if (cfd >= 0) { | |
136 | err = st->ss->load_container(st, cfd, NULL); | |
137 | close(cfd); | |
138 | if (err == 0) | |
139 | info = st->ss->container_content(st, subarray); | |
140 | } | |
c69b251b | 141 | } |
ea329559 | 142 | |
e6fc80a8 | 143 | /* try to load a superblock. Try sra->devs first, then try ioctl */ |
776b199e JS |
144 | if (st && !info) |
145 | for (d = 0, subdev = sra ? sra->devs : NULL; | |
146 | d < max_disks || subdev; | |
147 | subdev ? (void)(subdev = subdev->next) : (void)(d++)){ | |
e5329c37 NB |
148 | mdu_disk_info_t disk; |
149 | char *dv; | |
9aaada05 N |
150 | int fd2; |
151 | int err; | |
776b199e | 152 | |
e6fc80a8 N |
153 | if (subdev) |
154 | disk = subdev->disk; | |
155 | else { | |
156 | disk.number = d; | |
d97572f5 | 157 | if (md_get_disk_info(fd, &disk) < 0) |
e6fc80a8 N |
158 | continue; |
159 | if (d >= array.raid_disks && | |
5737086e | 160 | disk.major == 0 && disk.minor == 0) |
e6fc80a8 N |
161 | continue; |
162 | } | |
9aaada05 N |
163 | |
164 | if (array.raid_disks > 0 && | |
165 | (disk.state & (1 << MD_DISK_ACTIVE)) == 0) | |
166 | continue; | |
167 | ||
168 | dv = map_dev(disk.major, disk.minor, 1); | |
169 | if (!dv) | |
170 | continue; | |
171 | ||
172 | fd2 = dev_open(dv, O_RDONLY); | |
173 | if (fd2 < 0) | |
174 | continue; | |
175 | ||
176 | if (st->sb) | |
177 | st->ss->free_super(st); | |
178 | ||
179 | err = st->ss->load_super(st, fd2, NULL); | |
180 | close(fd2); | |
181 | if (err) | |
182 | continue; | |
a1f976a0 N |
183 | if (info) |
184 | free(info); | |
185 | if (subarray) | |
186 | info = st->ss->container_content(st, subarray); | |
187 | else { | |
503975b9 | 188 | info = xmalloc(sizeof(*info)); |
a1f976a0 N |
189 | st->ss->getinfo_super(st, info, NULL); |
190 | } | |
191 | if (!info) | |
192 | continue; | |
9aaada05 N |
193 | |
194 | if (array.raid_disks != 0 && /* container */ | |
a1f976a0 N |
195 | (info->array.ctime != array.ctime || |
196 | info->array.level != array.level)) { | |
9aaada05 N |
197 | st->ss->free_super(st); |
198 | continue; | |
e5329c37 | 199 | } |
9aaada05 | 200 | /* some formats (imsm) have free-floating-spares |
22e263f6 | 201 | * with a uuid of uuid_zero, they don't |
9aaada05 N |
202 | * have very good info about the rest of the |
203 | * container, so keep searching when | |
204 | * encountering such a device. Otherwise, stop | |
205 | * after the first successful call to | |
206 | * ->load_super. | |
207 | */ | |
22e263f6 | 208 | if (memcmp(uuid_zero, |
a1f976a0 | 209 | info->uuid, |
22e263f6 | 210 | sizeof(uuid_zero)) == 0) { |
9aaada05 N |
211 | st->ss->free_super(st); |
212 | continue; | |
213 | } | |
214 | break; | |
e5329c37 NB |
215 | } |
216 | ||
64c4757e | 217 | /* Ok, we have some info to print... */ |
4df01ff5 | 218 | str = map_num(pers, array.level); |
54bad364 | 219 | |
ef898ce6 | 220 | if (c->export) { |
c69b251b | 221 | if (array.raid_disks) { |
4df01ff5 N |
222 | if (str) |
223 | printf("MD_LEVEL=%s\n", str); | |
c69b251b N |
224 | printf("MD_DEVICES=%d\n", array.raid_disks); |
225 | } else { | |
e6fc80a8 N |
226 | if (!inactive) |
227 | printf("MD_LEVEL=container\n"); | |
c69b251b N |
228 | printf("MD_DEVICES=%d\n", array.nr_disks); |
229 | } | |
230 | if (container) { | |
231 | printf("MD_CONTAINER=%s\n", container); | |
232 | printf("MD_MEMBER=%s\n", member); | |
233 | } else { | |
234 | if (sra && sra->array.major_version < 0) | |
235 | printf("MD_METADATA=%s\n", sra->text_version); | |
236 | else | |
6e48d593 | 237 | printf("MD_METADATA=%d.%d\n", |
5737086e JS |
238 | array.major_version, |
239 | array.minor_version); | |
c69b251b | 240 | } |
ca3b6696 | 241 | |
a1f976a0 | 242 | if (st && st->sb && info) { |
35ddc76d | 243 | char nbuf[64]; |
f069dd29 | 244 | struct map_ent *mp, *map = NULL; |
9aaada05 | 245 | |
a1f976a0 | 246 | fname_from_uuid(st, info, nbuf, ':'); |
5737086e | 247 | printf("MD_UUID=%s\n", nbuf + 5); |
a1f976a0 | 248 | mp = map_by_uuid(&map, info->uuid); |
f069dd29 | 249 | if (mp && mp->path && |
7103b9b8 N |
250 | strncmp(mp->path, "/dev/md/", 8) == 0) { |
251 | printf("MD_DEVNAME="); | |
5737086e | 252 | print_escape(mp->path + 8); |
7103b9b8 N |
253 | putchar('\n'); |
254 | } | |
142cb9e1 | 255 | |
35ddc76d N |
256 | if (st->ss->export_detail_super) |
257 | st->ss->export_detail_super(st); | |
7e6c6cb2 N |
258 | } else { |
259 | struct map_ent *mp, *map = NULL; | |
aae5a112 | 260 | char nbuf[64]; |
4dd2df09 | 261 | mp = map_by_devnm(&map, fd2devnm(fd)); |
aae5a112 DW |
262 | if (mp) { |
263 | __fname_from_uuid(mp->uuid, 0, nbuf, ':'); | |
264 | printf("MD_UUID=%s\n", nbuf+5); | |
265 | } | |
7e6c6cb2 | 266 | if (mp && mp->path && |
7103b9b8 N |
267 | strncmp(mp->path, "/dev/md/", 8) == 0) { |
268 | printf("MD_DEVNAME="); | |
269 | print_escape(mp->path+8); | |
270 | putchar('\n'); | |
271 | } | |
35ddc76d | 272 | } |
54def20f N |
273 | if (sra) { |
274 | struct mdinfo *mdi; | |
275 | for (mdi = sra->devs; mdi; mdi = mdi->next) { | |
5737086e | 276 | char *path; |
b9c9bd9b N |
277 | char *sysdev = xstrdup(mdi->sys_name + 1); |
278 | char *cp; | |
5737086e JS |
279 | |
280 | path = map_dev(mdi->disk.major, | |
281 | mdi->disk.minor, 0); | |
b9c9bd9b N |
282 | for (cp = sysdev; *cp; cp++) |
283 | if (!isalnum(*cp)) | |
284 | *cp = '_'; | |
54def20f N |
285 | |
286 | if (mdi->disk.raid_disk >= 0) | |
287 | printf("MD_DEVICE_%s_ROLE=%d\n", | |
b9c9bd9b | 288 | sysdev, |
54def20f N |
289 | mdi->disk.raid_disk); |
290 | else | |
291 | printf("MD_DEVICE_%s_ROLE=spare\n", | |
b9c9bd9b | 292 | sysdev); |
54def20f N |
293 | if (path) |
294 | printf("MD_DEVICE_%s_DEV=%s\n", | |
b9c9bd9b | 295 | sysdev, path); |
54def20f N |
296 | } |
297 | } | |
54bad364 KS |
298 | goto out; |
299 | } | |
300 | ||
8057db46 N |
301 | disks = xmalloc(max_disks * 2 * sizeof(mdu_disk_info_t)); |
302 | for (d = 0; d < max_disks * 2; d++) { | |
5737086e | 303 | disks[d].state = (1 << MD_DISK_REMOVED); |
d998adc3 | 304 | disks[d].major = disks[d].minor = 0; |
78a5dc03 | 305 | disks[d].number = -1; |
5737086e | 306 | disks[d].raid_disk = d / 2; |
d998adc3 N |
307 | } |
308 | ||
5737086e | 309 | next = array.raid_disks * 2; |
e6fc80a8 N |
310 | if (inactive) { |
311 | struct mdinfo *mdi; | |
312 | if (sra != NULL) | |
313 | for (mdi = sra->devs; mdi; mdi = mdi->next) { | |
314 | disks[next++] = mdi->disk; | |
5737086e | 315 | disks[next - 1].number = -1; |
e6fc80a8 N |
316 | } |
317 | } else for (d = 0; d < max_disks; d++) { | |
d998adc3 N |
318 | mdu_disk_info_t disk; |
319 | disk.number = d; | |
d97572f5 | 320 | if (md_get_disk_info(fd, &disk) < 0) { |
d998adc3 | 321 | if (d < array.raid_disks) |
e7b84f9d | 322 | pr_err("cannot get device detail for device %d: %s\n", |
d998adc3 N |
323 | d, strerror(errno)); |
324 | continue; | |
325 | } | |
326 | if (disk.major == 0 && disk.minor == 0) | |
327 | continue; | |
5737086e JS |
328 | if (disk.raid_disk >= 0 && disk.raid_disk < array.raid_disks && |
329 | disks[disk.raid_disk * 2].state == (1 << MD_DISK_REMOVED) && | |
330 | ((disk.state & (1 << MD_DISK_JOURNAL)) == 0)) | |
331 | disks[disk.raid_disk * 2] = disk; | |
332 | else if (disk.raid_disk >= 0 && | |
333 | disk.raid_disk < array.raid_disks && | |
334 | disks[disk.raid_disk * 2 + 1].state == | |
335 | (1 << MD_DISK_REMOVED) && | |
336 | !(disk.state & (1 << MD_DISK_JOURNAL))) | |
337 | disks[disk.raid_disk * 2 + 1] = disk; | |
338 | else if (next < max_disks * 2) | |
d998adc3 N |
339 | disks[next++] = disk; |
340 | } | |
341 | ||
503975b9 | 342 | avail = xcalloc(array.raid_disks, 1); |
d998adc3 | 343 | |
5737086e | 344 | for (d = 0; d < array.raid_disks; d++) { |
d998adc3 | 345 | |
24c7bc84 N |
346 | if ((disks[d*2].state & (1<<MD_DISK_SYNC)) || |
347 | (disks[d*2+1].state & (1<<MD_DISK_SYNC))) { | |
d998adc3 N |
348 | avail_disks ++; |
349 | avail[d] = 1; | |
cd04f562 CS |
350 | } else |
351 | rv |= !! c->test; | |
d998adc3 N |
352 | } |
353 | ||
ef898ce6 | 354 | if (c->brief) { |
e8eb8763 | 355 | mdu_bitmap_file_t bmf; |
e6fc80a8 | 356 | printf("%sARRAY %s", inactive ? "INACTIVE-":"", dev); |
b3908491 | 357 | if (c->verbose > 0) { |
061f2c6a | 358 | if (array.raid_disks) |
0e90271e | 359 | printf(" level=%s num-devices=%d", |
5737086e JS |
360 | str ? str : "-unknown-", |
361 | array.raid_disks); | |
e6fc80a8 | 362 | else if (!inactive) |
0e90271e | 363 | printf(" level=container num-devices=%d", |
061f2c6a | 364 | array.nr_disks); |
e6fc80a8 N |
365 | else |
366 | printf(" num-devices=%d", array.nr_disks); | |
061f2c6a | 367 | } |
c69b251b N |
368 | if (container) { |
369 | printf(" container=%s", container); | |
370 | printf(" member=%s", member); | |
371 | } else { | |
372 | if (sra && sra->array.major_version < 0) | |
373 | printf(" metadata=%s", sra->text_version); | |
374 | else | |
5737086e JS |
375 | printf(" metadata=%d.%d", array.major_version, |
376 | array.minor_version); | |
c69b251b | 377 | } |
e8eb8763 NB |
378 | |
379 | /* Only try GET_BITMAP_FILE for 0.90.01 and later */ | |
901d5ee6 | 380 | if (ioctl(fd, GET_BITMAP_FILE, &bmf) == 0 && bmf.pathname[0]) { |
e8eb8763 NB |
381 | printf(" bitmap=%s", bmf.pathname); |
382 | } | |
142cb9e1 | 383 | } else { |
8fac0577 | 384 | mdu_bitmap_file_t bmf; |
e0d19036 | 385 | unsigned long long larray_size; |
22a88995 | 386 | struct mdstat_ent *ms = mdstat_read(0, 0); |
dd0781e5 | 387 | struct mdstat_ent *e; |
4dd2df09 | 388 | char *devnm; |
dd0781e5 | 389 | |
4dd2df09 | 390 | devnm = stat2devnm(&stb); |
5737086e | 391 | for (e = ms; e; e = e->next) |
4dd2df09 | 392 | if (strcmp(e->devnm, devnm) == 0) |
dd0781e5 | 393 | break; |
beae1dfe NB |
394 | if (!get_dev_size(fd, NULL, &larray_size)) |
395 | larray_size = 0; | |
56eb10c0 | 396 | |
cd29a5c8 | 397 | printf("%s:\n", dev); |
142cb9e1 | 398 | |
c69b251b | 399 | if (container) |
5737086e JS |
400 | printf(" Container : %s, member %s\n", |
401 | container, member); | |
c69b251b | 402 | else { |
5737086e JS |
403 | if (sra && sra->array.major_version < 0) |
404 | printf(" Version : %s\n", | |
405 | sra->text_version); | |
406 | else | |
407 | printf(" Version : %d.%d\n", | |
408 | array.major_version, | |
409 | array.minor_version); | |
c69b251b | 410 | } |
142cb9e1 | 411 | |
cd29a5c8 | 412 | atime = array.ctime; |
c69b251b | 413 | if (atime) |
65884368 | 414 | printf(" Creation Time : %.24s\n", ctime(&atime)); |
e6fc80a8 | 415 | if (array.raid_disks == 0 && external) |
4df01ff5 | 416 | str = "container"; |
e6fc80a8 | 417 | if (str) |
65884368 | 418 | printf(" Raid Level : %s\n", str); |
56eb10c0 | 419 | if (larray_size) |
5737086e JS |
420 | printf(" Array Size : %llu%s\n", |
421 | (larray_size >> 10), | |
ca3b6696 | 422 | human_size(larray_size)); |
3d4064cc | 423 | if (array.level >= 1) { |
ec1b28fd N |
424 | if (sra) |
425 | array.major_version = sra->array.major_version; | |
3d4064cc | 426 | if (array.major_version != 0 && |
6ee5c05a | 427 | (larray_size >= 0xFFFFFFFFULL|| array.size == 0)) { |
5737086e JS |
428 | unsigned long long dsize; |
429 | ||
430 | dsize = get_component_size(fd); | |
6ee5c05a | 431 | if (dsize > 0) |
65884368 | 432 | printf(" Used Dev Size : %llu%s\n", |
a1236192 N |
433 | dsize/2, |
434 | human_size((long long)dsize<<9)); | |
6ee5c05a | 435 | else |
65884368 | 436 | printf(" Used Dev Size : unknown\n"); |
6ee5c05a | 437 | } else |
65884368 | 438 | printf(" Used Dev Size : %lu%s\n", |
9f7f28ee | 439 | (unsigned long)array.size, |
5737086e JS |
440 | human_size((unsigned long long) |
441 | array.size << 10)); | |
3d4064cc | 442 | } |
c69b251b | 443 | if (array.raid_disks) |
65884368 AP |
444 | printf(" Raid Devices : %d\n", array.raid_disks); |
445 | printf(" Total Devices : %d\n", array.nr_disks); | |
ca3b6696 | 446 | if (!container && |
c69b251b N |
447 | ((sra == NULL && array.major_version == 0) || |
448 | (sra && sra->array.major_version == 0))) | |
65884368 | 449 | printf(" Preferred Minor : %d\n", array.md_minor); |
142cb9e1 | 450 | if (sra == NULL || sra->array.major_version >= 0) |
65884368 | 451 | printf(" Persistence : Superblock is %spersistent\n", |
5737086e | 452 | array.not_persistent ? "not " : ""); |
cd29a5c8 | 453 | printf("\n"); |
4027ddca | 454 | /* Only try GET_BITMAP_FILE for 0.90.01 and later */ |
901d5ee6 | 455 | if (ioctl(fd, GET_BITMAP_FILE, &bmf) == 0 && bmf.pathname[0]) { |
65884368 | 456 | printf(" Intent Bitmap : %s\n", bmf.pathname); |
8fac0577 NB |
457 | printf("\n"); |
458 | } else if (array.state & (1<<MD_SB_BITMAP_PRESENT)) | |
65884368 | 459 | printf(" Intent Bitmap : Internal\n\n"); |
cd29a5c8 | 460 | atime = array.utime; |
c69b251b | 461 | if (atime) |
65884368 | 462 | printf(" Update Time : %.24s\n", ctime(&atime)); |
d998adc3 | 463 | if (array.raid_disks) { |
ca3b6696 N |
464 | static char *sync_action[] = { |
465 | ", recovering", ", resyncing", | |
466 | ", reshaping", ", checking" }; | |
d998adc3 N |
467 | char *st; |
468 | if (avail_disks == array.raid_disks) | |
469 | st = ""; | |
470 | else if (!enough(array.level, array.raid_disks, | |
de5a472e | 471 | array.layout, 1, avail)) |
d998adc3 N |
472 | st = ", FAILED"; |
473 | else | |
474 | st = ", degraded"; | |
475 | ||
65884368 | 476 | printf(" State : %s%s%s%s%s%s \n", |
5737086e JS |
477 | (array.state & (1 << MD_SB_CLEAN)) ? |
478 | "clean" : "active", st, | |
479 | (!e || (e->percent < 0 && | |
480 | e->percent != RESYNC_PENDING && | |
481 | e->percent != RESYNC_DELAYED)) ? | |
482 | "" : sync_action[e->resync], | |
2d3603ba | 483 | larray_size ? "": ", Not Started", |
5737086e JS |
484 | (e && e->percent == RESYNC_DELAYED) ? |
485 | " (DELAYED)": "", | |
486 | (e && e->percent == RESYNC_PENDING) ? | |
487 | " (PENDING)": ""); | |
e6fc80a8 | 488 | } else if (inactive) { |
65884368 | 489 | printf(" State : inactive\n"); |
d998adc3 | 490 | } |
c69b251b | 491 | if (array.raid_disks) |
65884368 | 492 | printf(" Active Devices : %d\n", array.active_disks); |
e6fc80a8 | 493 | if (array.working_disks > 0) |
5737086e JS |
494 | printf(" Working Devices : %d\n", |
495 | array.working_disks); | |
c69b251b | 496 | if (array.raid_disks) { |
65884368 AP |
497 | printf(" Failed Devices : %d\n", array.failed_disks); |
498 | printf(" Spare Devices : %d\n", array.spare_disks); | |
c69b251b | 499 | } |
cd29a5c8 NB |
500 | printf("\n"); |
501 | if (array.level == 5) { | |
4df01ff5 | 502 | str = map_num(r5layout, array.layout); |
5737086e JS |
503 | printf(" Layout : %s\n", |
504 | str ? str : "-unknown-"); | |
cd29a5c8 | 505 | } |
fe77a154 | 506 | if (array.level == 6) { |
4df01ff5 | 507 | str = map_num(r6layout, array.layout); |
5737086e JS |
508 | printf(" Layout : %s\n", |
509 | str ? str : "-unknown-"); | |
fe77a154 | 510 | } |
e5329c37 | 511 | if (array.level == 10) { |
65884368 | 512 | printf(" Layout :"); |
e4965ef8 N |
513 | print_r10_layout(array.layout); |
514 | printf("\n"); | |
e5329c37 | 515 | } |
cd29a5c8 NB |
516 | switch (array.level) { |
517 | case 0: | |
518 | case 4: | |
519 | case 5: | |
e5329c37 NB |
520 | case 10: |
521 | case 6: | |
142cb9e1 | 522 | if (array.chunk_size) |
65884368 | 523 | printf(" Chunk Size : %dK\n\n", |
142cb9e1 | 524 | array.chunk_size/1024); |
cd29a5c8 NB |
525 | break; |
526 | case -1: | |
65884368 AP |
527 | printf(" Rounding : %dK\n\n", |
528 | array.chunk_size/1024); | |
cd29a5c8 | 529 | break; |
5737086e JS |
530 | default: |
531 | break; | |
cd29a5c8 | 532 | } |
aba69144 | 533 | |
65884368 | 534 | if (array.raid_disks) { |
5737086e JS |
535 | struct mdinfo *mdi; |
536 | ||
537 | mdi = sysfs_read(fd, NULL, GET_CONSISTENCY_POLICY); | |
65884368 AP |
538 | if (mdi) { |
539 | char *policy = map_num(consistency_policies, | |
540 | mdi->consistency_policy); | |
541 | sysfs_free(mdi); | |
542 | if (policy) | |
543 | printf("Consistency Policy : %s\n\n", | |
544 | policy); | |
545 | } | |
546 | } | |
547 | ||
e5329c37 | 548 | if (e && e->percent >= 0) { |
ca3b6696 | 549 | static char *sync_action[] = { |
5737086e | 550 | "Rebuild", "Resync", "Reshape", "Check"}; |
65884368 AP |
551 | printf(" %7s Status : %d%% complete\n", |
552 | sync_action[e->resync], e->percent); | |
e5329c37 | 553 | } |
dd0781e5 NB |
554 | free_mdstat(ms); |
555 | ||
db428d7a | 556 | if ((st && st->sb) && (info && info->reshape_active)) { |
bed256c2 NB |
557 | #if 0 |
558 | This is pretty boring | |
65884368 | 559 | printf(" Reshape pos'n : %llu%s\n", |
5737086e JS |
560 | (unsigned long long) info->reshape_progress << 9, |
561 | human_size((unsigned long long) | |
562 | info->reshape_progress << 9)); | |
bed256c2 | 563 | #endif |
c281a804 | 564 | if (info->delta_disks != 0) |
65884368 | 565 | printf(" Delta Devices : %d, (%d->%d)\n", |
ca3b6696 N |
566 | info->delta_disks, |
567 | array.raid_disks - info->delta_disks, | |
568 | array.raid_disks); | |
a1f976a0 | 569 | if (info->new_level != array.level) { |
4df01ff5 | 570 | str = map_num(pers, info->new_level); |
5737086e JS |
571 | printf(" New Level : %s\n", |
572 | str ? str : "-unknown-"); | |
bed256c2 | 573 | } |
a1f976a0 N |
574 | if (info->new_level != array.level || |
575 | info->new_layout != array.layout) { | |
576 | if (info->new_level == 5) { | |
5737086e JS |
577 | str = map_num(r5layout, |
578 | info->new_layout); | |
65884368 | 579 | printf(" New Layout : %s\n", |
5737086e | 580 | str ? str : "-unknown-"); |
bed256c2 | 581 | } |
a1f976a0 | 582 | if (info->new_level == 6) { |
5737086e JS |
583 | str = map_num(r6layout, |
584 | info->new_layout); | |
65884368 | 585 | printf(" New Layout : %s\n", |
5737086e | 586 | str ? str : "-unknown-"); |
dab54dcb | 587 | } |
a1f976a0 | 588 | if (info->new_level == 10) { |
65884368 | 589 | printf(" New Layout : near=%d, %s=%d\n", |
5737086e JS |
590 | info->new_layout & 255, |
591 | (info->new_layout & 0x10000) ? | |
592 | "offset" : "far", | |
593 | (info->new_layout >> 8) & 255); | |
bed256c2 NB |
594 | } |
595 | } | |
a1f976a0 | 596 | if (info->new_chunk != array.chunk_size) |
65884368 AP |
597 | printf(" New Chunksize : %dK\n", |
598 | info->new_chunk/1024); | |
bed256c2 NB |
599 | printf("\n"); |
600 | } else if (e && e->percent >= 0) | |
601 | printf("\n"); | |
3da92f27 | 602 | if (st && st->sb) |
ef898ce6 | 603 | st->ss->detail_super(st, c->homehost); |
e5329c37 | 604 | |
5737086e JS |
605 | if (array.raid_disks == 0 && sra && |
606 | sra->array.major_version == -1 && | |
607 | sra->array.minor_version == -2 && | |
608 | sra->text_version[0] != '/') { | |
c69b251b N |
609 | /* This looks like a container. Find any active arrays |
610 | * That claim to be a member. | |
611 | */ | |
612 | DIR *dir = opendir("/sys/block"); | |
613 | struct dirent *de; | |
614 | ||
65884368 | 615 | printf(" Member Arrays :"); |
c69b251b N |
616 | |
617 | while (dir && (de = readdir(dir)) != NULL) { | |
ff9239ee | 618 | char path[287]; |
c69b251b N |
619 | char vbuf[1024]; |
620 | int nlen = strlen(sra->sys_name); | |
13db17bd | 621 | dev_t devid; |
c69b251b N |
622 | if (de->d_name[0] == '.') |
623 | continue; | |
5737086e JS |
624 | sprintf(path, |
625 | "/sys/block/%s/md/metadata_version", | |
c69b251b | 626 | de->d_name); |
193b6c0b | 627 | if (load_sys(path, vbuf, sizeof(vbuf)) < 0) |
c69b251b | 628 | continue; |
5737086e JS |
629 | if (strncmp(vbuf, "external:", 9) || |
630 | !is_subarray(vbuf + 9) || | |
631 | strncmp(vbuf + 10, sra->sys_name, nlen) || | |
632 | vbuf[10 + nlen] != '/') | |
c69b251b | 633 | continue; |
4dd2df09 | 634 | devid = devnm2devid(de->d_name); |
5737086e JS |
635 | printf(" %s", |
636 | map_dev_preferred(major(devid), | |
637 | minor(devid), 1, | |
638 | c->prefer)); | |
c69b251b N |
639 | } |
640 | if (dir) | |
641 | closedir(dir); | |
642 | printf("\n\n"); | |
643 | } | |
644 | ||
645 | if (array.raid_disks) | |
646 | printf(" Number Major Minor RaidDevice State\n"); | |
647 | else | |
648 | printf(" Number Major Minor RaidDevice\n"); | |
cd29a5c8 | 649 | } |
a1f976a0 | 650 | free(info); |
b0c63f32 | 651 | |
5737086e | 652 | for (d = 0; d < max_disks * 2; d++) { |
b0c63f32 NB |
653 | char *dv; |
654 | mdu_disk_info_t disk = disks[d]; | |
655 | ||
5737086e JS |
656 | if (d >= array.raid_disks * 2 && |
657 | disk.major == 0 && disk.minor == 0) | |
24c7bc84 | 658 | continue; |
5737086e | 659 | if ((d & 1) && disk.major == 0 && disk.minor == 0) |
e0d19036 | 660 | continue; |
ef898ce6 | 661 | if (!c->brief) { |
5737086e JS |
662 | if (d == array.raid_disks*2) |
663 | printf("\n"); | |
e652d1aa | 664 | if (disk.number < 0 && disk.raid_disk < 0) |
e6fc80a8 N |
665 | printf(" - %5d %5d - ", |
666 | disk.major, disk.minor); | |
5737086e JS |
667 | else if (disk.raid_disk < 0 || |
668 | disk.state & (1 << MD_DISK_JOURNAL)) | |
aba69144 | 669 | printf(" %5d %5d %5d - ", |
e5329c37 | 670 | disk.number, disk.major, disk.minor); |
78a5dc03 N |
671 | else if (disk.number < 0) |
672 | printf(" - %5d %5d %5d ", | |
673 | disk.major, disk.minor, disk.raid_disk); | |
e5329c37 | 674 | else |
aba69144 | 675 | printf(" %5d %5d %5d %5d ", |
5737086e JS |
676 | disk.number, disk.major, disk.minor, |
677 | disk.raid_disk); | |
c69b251b | 678 | } |
ef898ce6 | 679 | if (!c->brief && array.raid_disks) { |
5737086e | 680 | if (disk.state & (1 << MD_DISK_FAULTY)) { |
aba69144 | 681 | printf(" faulty"); |
e5329c37 NB |
682 | if (disk.raid_disk < array.raid_disks && |
683 | disk.raid_disk >= 0) | |
684 | failed++; | |
685 | } | |
5737086e JS |
686 | if (disk.state & (1 << MD_DISK_ACTIVE)) |
687 | printf(" active"); | |
688 | if (disk.state & (1 << MD_DISK_SYNC)) { | |
2c096ebe | 689 | printf(" sync"); |
5737086e JS |
690 | if (array.level == 10 && |
691 | (array.layout & ~0x1FFFF) == 0) { | |
2c096ebe N |
692 | int nc = array.layout & 0xff; |
693 | int fc = (array.layout >> 8) & 0xff; | |
694 | int copies = nc*fc; | |
5737086e JS |
695 | if (fc == 1 && |
696 | array.raid_disks % copies == 0 && | |
697 | copies <= 26) { | |
698 | /* We can divide the devices | |
699 | into 'sets' */ | |
700 | int set; | |
701 | set = disk.raid_disk % copies; | |
2c096ebe N |
702 | printf(" set-%c", set + 'A'); |
703 | } | |
704 | } | |
705 | } | |
5737086e JS |
706 | if (disk.state & (1 << MD_DISK_REMOVED)) |
707 | printf(" removed"); | |
708 | if (disk.state & (1 << MD_DISK_WRITEMOSTLY)) | |
709 | printf(" writemostly"); | |
710 | if (disk.state & (1 << MD_DISK_FAILFAST)) | |
711 | printf(" failfast"); | |
712 | if (disk.state & (1 << MD_DISK_JOURNAL)) | |
713 | printf(" journal"); | |
b0c63f32 | 714 | if ((disk.state & |
71ec7076 | 715 | ((1<<MD_DISK_ACTIVE)|(1<<MD_DISK_SYNC) |
ed94976d | 716 | |(1<<MD_DISK_REMOVED)|(1<<MD_DISK_FAULTY)|(1<<MD_DISK_JOURNAL))) |
b0c63f32 NB |
717 | == 0) { |
718 | printf(" spare"); | |
5e13ef71 JS |
719 | if (disk.raid_disk < array.raid_disks && |
720 | disk.raid_disk >= 0) | |
721 | printf(" rebuilding"); | |
e5329c37 | 722 | } |
feb716e9 | 723 | } |
5737086e JS |
724 | if (disk.state == 0) |
725 | spares++; | |
726 | dv = map_dev_preferred(disk.major, disk.minor, 0, c->prefer); | |
ca3b6696 | 727 | if (dv != NULL) { |
b76dc299 MW |
728 | if (c->brief) |
729 | n_devices = add_device(dv, &devices, | |
5737086e | 730 | &max_devices, n_devices); |
b76dc299 | 731 | else |
d013a55e | 732 | printf(" %s", dv); |
82b27616 | 733 | } |
5737086e JS |
734 | if (!c->brief) |
735 | printf("\n"); | |
64c4757e | 736 | } |
5737086e JS |
737 | if (spares && c->brief && array.raid_disks) |
738 | printf(" spares=%d", spares); | |
ef898ce6 | 739 | if (c->brief && st && st->sb) |
3da92f27 | 740 | st->ss->brief_detail_super(st); |
db428d7a LD |
741 | if (st) |
742 | st->ss->free_super(st); | |
4b1ac34b | 743 | |
41a663b2 | 744 | if (c->brief && c->verbose > 0 && devices) { |
745 | qsort(devices, n_devices, sizeof(*devices), cmpstringp); | |
746 | printf("\n devices=%s", devices[0]); | |
747 | for (d = 1; d < n_devices; d++) | |
748 | printf(",%s", devices[d]); | |
749 | } | |
ef898ce6 N |
750 | if (c->brief) |
751 | printf("\n"); | |
752 | if (c->test && | |
5737086e | 753 | !enough(array.level, array.raid_disks, array.layout, 1, avail)) |
a77be586 NB |
754 | rv = 2; |
755 | ||
0eb26465 | 756 | free(disks); |
a328c097 | 757 | out: |
e5329c37 | 758 | close(fd); |
4725bc31 | 759 | free(subarray); |
d0673517 | 760 | free(avail); |
41a663b2 | 761 | for (d = 0; d < n_devices; d++) |
762 | free(devices[d]); | |
763 | free(devices); | |
5454b6f3 | 764 | sysfs_free(sra); |
feb716e9 | 765 | return rv; |
64c4757e | 766 | } |
4cce4069 | 767 | |
9eafa1de | 768 | int Detail_Platform(struct superswitch *ss, int scan, int verbose, int export, char *controller_path) |
4cce4069 DW |
769 | { |
770 | /* display platform capabilities for the given metadata format | |
771 | * 'scan' in this context means iterate over all metadata types | |
772 | */ | |
773 | int i; | |
774 | int err = 1; | |
775 | ||
e50cf220 | 776 | if (ss && export && ss->export_detail_platform) |
9eafa1de | 777 | err = ss->export_detail_platform(verbose, controller_path); |
e50cf220 | 778 | else if (ss && ss->detail_platform) |
9eafa1de | 779 | err = ss->detail_platform(verbose, 0, controller_path); |
4cce4069 | 780 | else if (ss) { |
ba728be7 | 781 | if (verbose > 0) |
e7b84f9d | 782 | pr_err("%s metadata is platform independent\n", |
4cce4069 DW |
783 | ss->name ? : "[no name]"); |
784 | } else if (!scan) { | |
ba728be7 | 785 | if (verbose > 0) |
e7b84f9d | 786 | pr_err("specify a metadata type or --scan\n"); |
4cce4069 DW |
787 | } |
788 | ||
789 | if (!scan) | |
790 | return err; | |
791 | ||
9590cb42 | 792 | err = 0; |
4cce4069 DW |
793 | for (i = 0; superlist[i]; i++) { |
794 | struct superswitch *meta = superlist[i]; | |
795 | ||
796 | if (meta == ss) | |
797 | continue; | |
ba728be7 | 798 | if (verbose > 0) |
e7b84f9d | 799 | pr_err("checking metadata %s\n", |
4cce4069 DW |
800 | meta->name ? : "[no name]"); |
801 | if (!meta->detail_platform) { | |
ba728be7 | 802 | if (verbose > 0) |
e7b84f9d | 803 | pr_err("%s metadata is platform independent\n", |
4cce4069 | 804 | meta->name ? : "[no name]"); |
e50cf220 | 805 | } else if (export && meta->export_detail_platform) { |
9eafa1de | 806 | err |= meta->export_detail_platform(verbose, controller_path); |
4cce4069 | 807 | } else |
9eafa1de | 808 | err |= meta->detail_platform(verbose, 0, controller_path); |
4cce4069 DW |
809 | } |
810 | ||
811 | return err; | |
812 | } |