]>
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 | ||
84 | if (fd < 0) { | |
85 | pr_err("cannot open %s: %s\n", | |
86 | dev, strerror(errno)); | |
87 | return rv; | |
88 | } | |
89 | sra = sysfs_read(fd, NULL, GET_VERSION | GET_DEVS | GET_ARRAY_STATE); | |
90 | if (!sra) { | |
91 | pr_err("%s does not appear to be an md device\n", dev); | |
92 | close(fd); | |
93 | return rv; | |
94 | } | |
95 | external = (sra != NULL && sra->array.major_version == -1 && | |
96 | sra->array.minor_version == -2); | |
97 | inactive = (sra->array_state == ARRAY_ACTIVE || | |
98 | sra->array_state == ARRAY_CLEAR); | |
99 | st = super_by_fd(fd, &subarray); | |
100 | if (md_get_array_info(fd, &array) && errno == ENODEV) { | |
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 | } | |
109 | array = sra->array; | |
110 | } else { | |
111 | pr_err("cannot get array detail for %s: %s\n", | |
112 | dev, strerror(errno)); | |
113 | close(fd); | |
114 | return rv; | |
115 | } | |
116 | ||
117 | if (fstat(fd, &stb) != 0 && !S_ISBLK(stb.st_mode)) | |
118 | stb.st_rdev = 0; | |
119 | rv = 0; | |
120 | ||
121 | if (st) | |
122 | max_disks = st->max_devs; | |
123 | ||
124 | if (subarray) { | |
125 | /* This is a subarray of some container. | |
126 | * We want the name of the container, and the member | |
127 | */ | |
128 | dev_t devid = devnm2devid(st->container_devnm); | |
129 | int cfd, err; | |
130 | ||
131 | member = subarray; | |
132 | container = map_dev_preferred(major(devid), minor(devid), | |
133 | 1, c->prefer); | |
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 | } | |
141 | } | |
142 | ||
143 | /* try to load a superblock. Try sra->devs first, then try ioctl */ | |
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++)){ | |
148 | mdu_disk_info_t disk; | |
149 | char *dv; | |
150 | int fd2; | |
151 | int err; | |
152 | ||
153 | if (subdev) | |
154 | disk = subdev->disk; | |
155 | else { | |
156 | disk.number = d; | |
157 | if (md_get_disk_info(fd, &disk) < 0) | |
158 | continue; | |
159 | if (d >= array.raid_disks && | |
160 | disk.major == 0 && disk.minor == 0) | |
161 | continue; | |
162 | } | |
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; | |
183 | if (info) | |
184 | free(info); | |
185 | if (subarray) | |
186 | info = st->ss->container_content(st, subarray); | |
187 | else { | |
188 | info = xmalloc(sizeof(*info)); | |
189 | st->ss->getinfo_super(st, info, NULL); | |
190 | } | |
191 | if (!info) | |
192 | continue; | |
193 | ||
194 | if (array.raid_disks != 0 && /* container */ | |
195 | (info->array.ctime != array.ctime || | |
196 | info->array.level != array.level)) { | |
197 | st->ss->free_super(st); | |
198 | continue; | |
199 | } | |
200 | /* some formats (imsm) have free-floating-spares | |
201 | * with a uuid of uuid_zero, they don't | |
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 | */ | |
208 | if (memcmp(uuid_zero, | |
209 | info->uuid, | |
210 | sizeof(uuid_zero)) == 0) { | |
211 | st->ss->free_super(st); | |
212 | continue; | |
213 | } | |
214 | break; | |
215 | } | |
216 | ||
217 | /* Ok, we have some info to print... */ | |
218 | str = map_num(pers, array.level); | |
219 | ||
220 | if (c->export) { | |
221 | if (array.raid_disks) { | |
222 | if (str) | |
223 | printf("MD_LEVEL=%s\n", str); | |
224 | printf("MD_DEVICES=%d\n", array.raid_disks); | |
225 | } else { | |
226 | if (!inactive) | |
227 | printf("MD_LEVEL=container\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 | |
237 | printf("MD_METADATA=%d.%d\n", | |
238 | array.major_version, | |
239 | array.minor_version); | |
240 | } | |
241 | ||
242 | if (st && st->sb && info) { | |
243 | char nbuf[64]; | |
244 | struct map_ent *mp, *map = NULL; | |
245 | ||
246 | fname_from_uuid(st, info, nbuf, ':'); | |
247 | printf("MD_UUID=%s\n", nbuf + 5); | |
248 | mp = map_by_uuid(&map, info->uuid); | |
249 | if (mp && mp->path && | |
250 | strncmp(mp->path, "/dev/md/", 8) == 0) { | |
251 | printf("MD_DEVNAME="); | |
252 | print_escape(mp->path + 8); | |
253 | putchar('\n'); | |
254 | } | |
255 | ||
256 | if (st->ss->export_detail_super) | |
257 | st->ss->export_detail_super(st); | |
258 | } else { | |
259 | struct map_ent *mp, *map = NULL; | |
260 | char nbuf[64]; | |
261 | mp = map_by_devnm(&map, fd2devnm(fd)); | |
262 | if (mp) { | |
263 | __fname_from_uuid(mp->uuid, 0, nbuf, ':'); | |
264 | printf("MD_UUID=%s\n", nbuf+5); | |
265 | } | |
266 | if (mp && mp->path && | |
267 | strncmp(mp->path, "/dev/md/", 8) == 0) { | |
268 | printf("MD_DEVNAME="); | |
269 | print_escape(mp->path+8); | |
270 | putchar('\n'); | |
271 | } | |
272 | } | |
273 | if (sra) { | |
274 | struct mdinfo *mdi; | |
275 | for (mdi = sra->devs; mdi; mdi = mdi->next) { | |
276 | char *path; | |
277 | char *sysdev = xstrdup(mdi->sys_name + 1); | |
278 | char *cp; | |
279 | ||
280 | path = map_dev(mdi->disk.major, | |
281 | mdi->disk.minor, 0); | |
282 | for (cp = sysdev; *cp; cp++) | |
283 | if (!isalnum(*cp)) | |
284 | *cp = '_'; | |
285 | ||
286 | if (mdi->disk.raid_disk >= 0) | |
287 | printf("MD_DEVICE_%s_ROLE=%d\n", | |
288 | sysdev, | |
289 | mdi->disk.raid_disk); | |
290 | else | |
291 | printf("MD_DEVICE_%s_ROLE=spare\n", | |
292 | sysdev); | |
293 | if (path) | |
294 | printf("MD_DEVICE_%s_DEV=%s\n", | |
295 | sysdev, path); | |
296 | } | |
297 | } | |
298 | goto out; | |
299 | } | |
300 | ||
301 | disks = xmalloc(max_disks * 2 * sizeof(mdu_disk_info_t)); | |
302 | for (d = 0; d < max_disks * 2; d++) { | |
303 | disks[d].state = (1 << MD_DISK_REMOVED); | |
304 | disks[d].major = disks[d].minor = 0; | |
305 | disks[d].number = -1; | |
306 | disks[d].raid_disk = d / 2; | |
307 | } | |
308 | ||
309 | next = array.raid_disks * 2; | |
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; | |
315 | disks[next - 1].number = -1; | |
316 | } | |
317 | } else for (d = 0; d < max_disks; d++) { | |
318 | mdu_disk_info_t disk; | |
319 | disk.number = d; | |
320 | if (md_get_disk_info(fd, &disk) < 0) { | |
321 | if (d < array.raid_disks) | |
322 | pr_err("cannot get device detail for device %d: %s\n", | |
323 | d, strerror(errno)); | |
324 | continue; | |
325 | } | |
326 | if (disk.major == 0 && disk.minor == 0) | |
327 | continue; | |
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) | |
339 | disks[next++] = disk; | |
340 | } | |
341 | ||
342 | avail = xcalloc(array.raid_disks, 1); | |
343 | ||
344 | for (d = 0; d < array.raid_disks; d++) { | |
345 | ||
346 | if ((disks[d*2].state & (1<<MD_DISK_SYNC)) || | |
347 | (disks[d*2+1].state & (1<<MD_DISK_SYNC))) { | |
348 | avail_disks ++; | |
349 | avail[d] = 1; | |
350 | } else | |
351 | rv |= !! c->test; | |
352 | } | |
353 | ||
354 | if (c->brief) { | |
355 | mdu_bitmap_file_t bmf; | |
356 | printf("%sARRAY %s", inactive ? "INACTIVE-":"", dev); | |
357 | if (c->verbose > 0) { | |
358 | if (array.raid_disks) | |
359 | printf(" level=%s num-devices=%d", | |
360 | str ? str : "-unknown-", | |
361 | array.raid_disks); | |
362 | else if (!inactive) | |
363 | printf(" level=container num-devices=%d", | |
364 | array.nr_disks); | |
365 | else | |
366 | printf(" num-devices=%d", array.nr_disks); | |
367 | } | |
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 | |
375 | printf(" metadata=%d.%d", array.major_version, | |
376 | array.minor_version); | |
377 | } | |
378 | ||
379 | /* Only try GET_BITMAP_FILE for 0.90.01 and later */ | |
380 | if (ioctl(fd, GET_BITMAP_FILE, &bmf) == 0 && bmf.pathname[0]) { | |
381 | printf(" bitmap=%s", bmf.pathname); | |
382 | } | |
383 | } else { | |
384 | mdu_bitmap_file_t bmf; | |
385 | unsigned long long larray_size; | |
386 | struct mdstat_ent *ms = mdstat_read(0, 0); | |
387 | struct mdstat_ent *e; | |
388 | char *devnm; | |
389 | ||
390 | devnm = stat2devnm(&stb); | |
391 | for (e = ms; e; e = e->next) | |
392 | if (strcmp(e->devnm, devnm) == 0) | |
393 | break; | |
394 | if (!get_dev_size(fd, NULL, &larray_size)) | |
395 | larray_size = 0; | |
396 | ||
397 | printf("%s:\n", dev); | |
398 | ||
399 | if (container) | |
400 | printf(" Container : %s, member %s\n", | |
401 | container, member); | |
402 | else { | |
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); | |
410 | } | |
411 | ||
412 | atime = array.ctime; | |
413 | if (atime) | |
414 | printf(" Creation Time : %.24s\n", ctime(&atime)); | |
415 | if (array.raid_disks == 0 && external) | |
416 | str = "container"; | |
417 | if (str) | |
418 | printf(" Raid Level : %s\n", str); | |
419 | if (larray_size) | |
420 | printf(" Array Size : %llu%s\n", | |
421 | (larray_size >> 10), | |
422 | human_size(larray_size)); | |
423 | if (array.level >= 1) { | |
424 | if (sra) | |
425 | array.major_version = sra->array.major_version; | |
426 | if (array.major_version != 0 && | |
427 | (larray_size >= 0xFFFFFFFFULL|| array.size == 0)) { | |
428 | unsigned long long dsize; | |
429 | ||
430 | dsize = get_component_size(fd); | |
431 | if (dsize > 0) | |
432 | printf(" Used Dev Size : %llu%s\n", | |
433 | dsize/2, | |
434 | human_size((long long)dsize<<9)); | |
435 | else | |
436 | printf(" Used Dev Size : unknown\n"); | |
437 | } else | |
438 | printf(" Used Dev Size : %lu%s\n", | |
439 | (unsigned long)array.size, | |
440 | human_size((unsigned long long) | |
441 | array.size << 10)); | |
442 | } | |
443 | if (array.raid_disks) | |
444 | printf(" Raid Devices : %d\n", array.raid_disks); | |
445 | printf(" Total Devices : %d\n", array.nr_disks); | |
446 | if (!container && | |
447 | ((sra == NULL && array.major_version == 0) || | |
448 | (sra && sra->array.major_version == 0))) | |
449 | printf(" Preferred Minor : %d\n", array.md_minor); | |
450 | if (sra == NULL || sra->array.major_version >= 0) | |
451 | printf(" Persistence : Superblock is %spersistent\n", | |
452 | array.not_persistent ? "not " : ""); | |
453 | printf("\n"); | |
454 | /* Only try GET_BITMAP_FILE for 0.90.01 and later */ | |
455 | if (ioctl(fd, GET_BITMAP_FILE, &bmf) == 0 && bmf.pathname[0]) { | |
456 | printf(" Intent Bitmap : %s\n", bmf.pathname); | |
457 | printf("\n"); | |
458 | } else if (array.state & (1<<MD_SB_BITMAP_PRESENT)) | |
459 | printf(" Intent Bitmap : Internal\n\n"); | |
460 | atime = array.utime; | |
461 | if (atime) | |
462 | printf(" Update Time : %.24s\n", ctime(&atime)); | |
463 | if (array.raid_disks) { | |
464 | static char *sync_action[] = { | |
465 | ", recovering", ", resyncing", | |
466 | ", reshaping", ", checking" }; | |
467 | char *st; | |
468 | if (avail_disks == array.raid_disks) | |
469 | st = ""; | |
470 | else if (!enough(array.level, array.raid_disks, | |
471 | array.layout, 1, avail)) | |
472 | st = ", FAILED"; | |
473 | else | |
474 | st = ", degraded"; | |
475 | ||
476 | printf(" State : %s%s%s%s%s%s \n", | |
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], | |
483 | larray_size ? "": ", Not Started", | |
484 | (e && e->percent == RESYNC_DELAYED) ? | |
485 | " (DELAYED)": "", | |
486 | (e && e->percent == RESYNC_PENDING) ? | |
487 | " (PENDING)": ""); | |
488 | } else if (inactive) { | |
489 | printf(" State : inactive\n"); | |
490 | } | |
491 | if (array.raid_disks) | |
492 | printf(" Active Devices : %d\n", array.active_disks); | |
493 | if (array.working_disks > 0) | |
494 | printf(" Working Devices : %d\n", | |
495 | array.working_disks); | |
496 | if (array.raid_disks) { | |
497 | printf(" Failed Devices : %d\n", array.failed_disks); | |
498 | printf(" Spare Devices : %d\n", array.spare_disks); | |
499 | } | |
500 | printf("\n"); | |
501 | if (array.level == 5) { | |
502 | str = map_num(r5layout, array.layout); | |
503 | printf(" Layout : %s\n", | |
504 | str ? str : "-unknown-"); | |
505 | } | |
506 | if (array.level == 6) { | |
507 | str = map_num(r6layout, array.layout); | |
508 | printf(" Layout : %s\n", | |
509 | str ? str : "-unknown-"); | |
510 | } | |
511 | if (array.level == 10) { | |
512 | printf(" Layout :"); | |
513 | print_r10_layout(array.layout); | |
514 | printf("\n"); | |
515 | } | |
516 | switch (array.level) { | |
517 | case 0: | |
518 | case 4: | |
519 | case 5: | |
520 | case 10: | |
521 | case 6: | |
522 | if (array.chunk_size) | |
523 | printf(" Chunk Size : %dK\n\n", | |
524 | array.chunk_size/1024); | |
525 | break; | |
526 | case -1: | |
527 | printf(" Rounding : %dK\n\n", | |
528 | array.chunk_size/1024); | |
529 | break; | |
530 | default: | |
531 | break; | |
532 | } | |
533 | ||
534 | if (array.raid_disks) { | |
535 | struct mdinfo *mdi; | |
536 | ||
537 | mdi = sysfs_read(fd, NULL, GET_CONSISTENCY_POLICY); | |
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 | ||
548 | if (e && e->percent >= 0) { | |
549 | static char *sync_action[] = { | |
550 | "Rebuild", "Resync", "Reshape", "Check"}; | |
551 | printf(" %7s Status : %d%% complete\n", | |
552 | sync_action[e->resync], e->percent); | |
553 | } | |
554 | free_mdstat(ms); | |
555 | ||
556 | if ((st && st->sb) && (info && info->reshape_active)) { | |
557 | #if 0 | |
558 | This is pretty boring | |
559 | printf(" Reshape pos'n : %llu%s\n", | |
560 | (unsigned long long) info->reshape_progress << 9, | |
561 | human_size((unsigned long long) | |
562 | info->reshape_progress << 9)); | |
563 | #endif | |
564 | if (info->delta_disks != 0) | |
565 | printf(" Delta Devices : %d, (%d->%d)\n", | |
566 | info->delta_disks, | |
567 | array.raid_disks - info->delta_disks, | |
568 | array.raid_disks); | |
569 | if (info->new_level != array.level) { | |
570 | str = map_num(pers, info->new_level); | |
571 | printf(" New Level : %s\n", | |
572 | str ? str : "-unknown-"); | |
573 | } | |
574 | if (info->new_level != array.level || | |
575 | info->new_layout != array.layout) { | |
576 | if (info->new_level == 5) { | |
577 | str = map_num(r5layout, | |
578 | info->new_layout); | |
579 | printf(" New Layout : %s\n", | |
580 | str ? str : "-unknown-"); | |
581 | } | |
582 | if (info->new_level == 6) { | |
583 | str = map_num(r6layout, | |
584 | info->new_layout); | |
585 | printf(" New Layout : %s\n", | |
586 | str ? str : "-unknown-"); | |
587 | } | |
588 | if (info->new_level == 10) { | |
589 | printf(" New Layout : near=%d, %s=%d\n", | |
590 | info->new_layout & 255, | |
591 | (info->new_layout & 0x10000) ? | |
592 | "offset" : "far", | |
593 | (info->new_layout >> 8) & 255); | |
594 | } | |
595 | } | |
596 | if (info->new_chunk != array.chunk_size) | |
597 | printf(" New Chunksize : %dK\n", | |
598 | info->new_chunk/1024); | |
599 | printf("\n"); | |
600 | } else if (e && e->percent >= 0) | |
601 | printf("\n"); | |
602 | if (st && st->sb) | |
603 | st->ss->detail_super(st, c->homehost); | |
604 | ||
605 | if (array.raid_disks == 0 && sra && | |
606 | sra->array.major_version == -1 && | |
607 | sra->array.minor_version == -2 && | |
608 | sra->text_version[0] != '/') { | |
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 | ||
615 | printf(" Member Arrays :"); | |
616 | ||
617 | while (dir && (de = readdir(dir)) != NULL) { | |
618 | char path[287]; | |
619 | char vbuf[1024]; | |
620 | int nlen = strlen(sra->sys_name); | |
621 | dev_t devid; | |
622 | if (de->d_name[0] == '.') | |
623 | continue; | |
624 | sprintf(path, | |
625 | "/sys/block/%s/md/metadata_version", | |
626 | de->d_name); | |
627 | if (load_sys(path, vbuf, sizeof(vbuf)) < 0) | |
628 | continue; | |
629 | if (strncmp(vbuf, "external:", 9) || | |
630 | !is_subarray(vbuf + 9) || | |
631 | strncmp(vbuf + 10, sra->sys_name, nlen) || | |
632 | vbuf[10 + nlen] != '/') | |
633 | continue; | |
634 | devid = devnm2devid(de->d_name); | |
635 | printf(" %s", | |
636 | map_dev_preferred(major(devid), | |
637 | minor(devid), 1, | |
638 | c->prefer)); | |
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"); | |
649 | } | |
650 | free(info); | |
651 | ||
652 | for (d = 0; d < max_disks * 2; d++) { | |
653 | char *dv; | |
654 | mdu_disk_info_t disk = disks[d]; | |
655 | ||
656 | if (d >= array.raid_disks * 2 && | |
657 | disk.major == 0 && disk.minor == 0) | |
658 | continue; | |
659 | if ((d & 1) && disk.major == 0 && disk.minor == 0) | |
660 | continue; | |
661 | if (!c->brief) { | |
662 | if (d == array.raid_disks*2) | |
663 | printf("\n"); | |
664 | if (disk.number < 0 && disk.raid_disk < 0) | |
665 | printf(" - %5d %5d - ", | |
666 | disk.major, disk.minor); | |
667 | else if (disk.raid_disk < 0 || | |
668 | disk.state & (1 << MD_DISK_JOURNAL)) | |
669 | printf(" %5d %5d %5d - ", | |
670 | disk.number, disk.major, disk.minor); | |
671 | else if (disk.number < 0) | |
672 | printf(" - %5d %5d %5d ", | |
673 | disk.major, disk.minor, disk.raid_disk); | |
674 | else | |
675 | printf(" %5d %5d %5d %5d ", | |
676 | disk.number, disk.major, disk.minor, | |
677 | disk.raid_disk); | |
678 | } | |
679 | if (!c->brief && array.raid_disks) { | |
680 | if (disk.state & (1 << MD_DISK_FAULTY)) { | |
681 | printf(" faulty"); | |
682 | if (disk.raid_disk < array.raid_disks && | |
683 | disk.raid_disk >= 0) | |
684 | failed++; | |
685 | } | |
686 | if (disk.state & (1 << MD_DISK_ACTIVE)) | |
687 | printf(" active"); | |
688 | if (disk.state & (1 << MD_DISK_SYNC)) { | |
689 | printf(" sync"); | |
690 | if (array.level == 10 && | |
691 | (array.layout & ~0x1FFFF) == 0) { | |
692 | int nc = array.layout & 0xff; | |
693 | int fc = (array.layout >> 8) & 0xff; | |
694 | int copies = nc*fc; | |
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; | |
702 | printf(" set-%c", set + 'A'); | |
703 | } | |
704 | } | |
705 | } | |
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"); | |
714 | if ((disk.state & | |
715 | ((1<<MD_DISK_ACTIVE)|(1<<MD_DISK_SYNC) | |
716 | |(1<<MD_DISK_REMOVED)|(1<<MD_DISK_FAULTY)|(1<<MD_DISK_JOURNAL))) | |
717 | == 0) { | |
718 | printf(" spare"); | |
719 | if (disk.raid_disk < array.raid_disks && | |
720 | disk.raid_disk >= 0) | |
721 | printf(" rebuilding"); | |
722 | } | |
723 | } | |
724 | if (disk.state == 0) | |
725 | spares++; | |
726 | dv = map_dev_preferred(disk.major, disk.minor, 0, c->prefer); | |
727 | if (dv != NULL) { | |
728 | if (c->brief) | |
729 | n_devices = add_device(dv, &devices, | |
730 | &max_devices, n_devices); | |
731 | else | |
732 | printf(" %s", dv); | |
733 | } | |
734 | if (!c->brief) | |
735 | printf("\n"); | |
736 | } | |
737 | if (spares && c->brief && array.raid_disks) | |
738 | printf(" spares=%d", spares); | |
739 | if (c->brief && st && st->sb) | |
740 | st->ss->brief_detail_super(st); | |
741 | if (st) | |
742 | st->ss->free_super(st); | |
743 | ||
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 | } | |
750 | if (c->brief) | |
751 | printf("\n"); | |
752 | if (c->test && | |
753 | !enough(array.level, array.raid_disks, array.layout, 1, avail)) | |
754 | rv = 2; | |
755 | ||
756 | free(disks); | |
757 | out: | |
758 | close(fd); | |
759 | free(subarray); | |
760 | free(avail); | |
761 | for (d = 0; d < n_devices; d++) | |
762 | free(devices[d]); | |
763 | free(devices); | |
764 | sysfs_free(sra); | |
765 | return rv; | |
766 | } | |
767 | ||
768 | int Detail_Platform(struct superswitch *ss, int scan, int verbose, int export, char *controller_path) | |
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 | ||
776 | if (ss && export && ss->export_detail_platform) | |
777 | err = ss->export_detail_platform(verbose, controller_path); | |
778 | else if (ss && ss->detail_platform) | |
779 | err = ss->detail_platform(verbose, 0, controller_path); | |
780 | else if (ss) { | |
781 | if (verbose > 0) | |
782 | pr_err("%s metadata is platform independent\n", | |
783 | ss->name ? : "[no name]"); | |
784 | } else if (!scan) { | |
785 | if (verbose > 0) | |
786 | pr_err("specify a metadata type or --scan\n"); | |
787 | } | |
788 | ||
789 | if (!scan) | |
790 | return err; | |
791 | ||
792 | err = 0; | |
793 | for (i = 0; superlist[i]; i++) { | |
794 | struct superswitch *meta = superlist[i]; | |
795 | ||
796 | if (meta == ss) | |
797 | continue; | |
798 | if (verbose > 0) | |
799 | pr_err("checking metadata %s\n", | |
800 | meta->name ? : "[no name]"); | |
801 | if (!meta->detail_platform) { | |
802 | if (verbose > 0) | |
803 | pr_err("%s metadata is platform independent\n", | |
804 | meta->name ? : "[no name]"); | |
805 | } else if (export && meta->export_detail_platform) { | |
806 | err |= meta->export_detail_platform(verbose, controller_path); | |
807 | } else | |
808 | err |= meta->detail_platform(verbose, 0, controller_path); | |
809 | } | |
810 | ||
811 | return err; | |
812 | } |