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