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