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