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