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