]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * mdadm - manage Linux "md" devices aka RAID arrays. | |
3 | * | |
4 | * Copyright (C) 2001-2013 Neil Brown <neilb@suse.de> | |
5 | * | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License as published by | |
9 | * the Free Software Foundation; either version 2 of the License, or | |
10 | * (at your option) any later version. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | * GNU General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License | |
18 | * along with this program; if not, write to the Free Software | |
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
20 | * | |
21 | * Author: Neil Brown | |
22 | * Email: <neilb@suse.de> | |
23 | */ | |
24 | ||
25 | #include "mdadm.h" | |
26 | #include "md_p.h" | |
27 | #include "md_u.h" | |
28 | #include <ctype.h> | |
29 | #include <dirent.h> | |
30 | ||
31 | static int cmpstringp(const void *p1, const void *p2) | |
32 | { | |
33 | return strcmp(* (char * const *) p1, * (char * const *) p2); | |
34 | } | |
35 | ||
36 | static int add_device(const char *dev, char ***p_devices, | |
37 | int *p_max_devices, int n_devices) | |
38 | { | |
39 | if (n_devices + 1 >= *p_max_devices) { | |
40 | *p_max_devices += 16; | |
41 | *p_devices = xrealloc(*p_devices, *p_max_devices * | |
42 | sizeof(**p_devices)); | |
43 | if (!*p_devices) { | |
44 | *p_max_devices = 0; | |
45 | return 0; | |
46 | } | |
47 | }; | |
48 | (*p_devices)[n_devices] = xstrdup(dev); | |
49 | return n_devices + 1; | |
50 | } | |
51 | ||
52 | /** | |
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) | |
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 (st->ss->export_detail_super) | |
292 | st->ss->export_detail_super(st); | |
293 | } | |
294 | if (!c->no_devices && sra) { | |
295 | struct mdinfo *mdi; | |
296 | for (mdi = sra->devs; mdi; mdi = mdi->next) { | |
297 | char *path; | |
298 | char *sysdev = xstrdup(mdi->sys_name); | |
299 | char *cp; | |
300 | ||
301 | path = map_dev(mdi->disk.major, | |
302 | mdi->disk.minor, 0); | |
303 | for (cp = sysdev; *cp; cp++) | |
304 | if (!isalnum(*cp)) | |
305 | *cp = '_'; | |
306 | ||
307 | if (mdi->disk.raid_disk >= 0) | |
308 | printf("MD_DEVICE_%s_ROLE=%d\n", | |
309 | sysdev, | |
310 | mdi->disk.raid_disk); | |
311 | else | |
312 | printf("MD_DEVICE_%s_ROLE=spare\n", | |
313 | sysdev); | |
314 | if (path) | |
315 | printf("MD_DEVICE_%s_DEV=%s\n", | |
316 | sysdev, path); | |
317 | free(sysdev); | |
318 | } | |
319 | } | |
320 | goto out; | |
321 | } | |
322 | ||
323 | disks = xmalloc(max_disks * 2 * sizeof(mdu_disk_info_t)); | |
324 | for (d = 0; d < max_disks * 2; d++) { | |
325 | disks[d].state = (1 << MD_DISK_REMOVED); | |
326 | disks[d].major = disks[d].minor = 0; | |
327 | disks[d].number = -1; | |
328 | disks[d].raid_disk = d / 2; | |
329 | } | |
330 | ||
331 | next = array.raid_disks * 2; | |
332 | if (inactive) { | |
333 | struct mdinfo *mdi; | |
334 | for (mdi = sra->devs; mdi; mdi = mdi->next) { | |
335 | disks[next++] = mdi->disk; | |
336 | disks[next - 1].number = -1; | |
337 | } | |
338 | } else for (d = 0; d < max_disks; d++) { | |
339 | mdu_disk_info_t disk; | |
340 | disk.number = d; | |
341 | if (md_get_disk_info(fd, &disk) < 0) { | |
342 | if (d < array.raid_disks) | |
343 | pr_err("cannot get device detail for device %d: %s\n", | |
344 | d, strerror(errno)); | |
345 | continue; | |
346 | } | |
347 | if (disk.major == 0 && disk.minor == 0) | |
348 | continue; | |
349 | if (disk.raid_disk >= 0 && disk.raid_disk < array.raid_disks && | |
350 | disks[disk.raid_disk * 2].state == (1 << MD_DISK_REMOVED) && | |
351 | ((disk.state & (1 << MD_DISK_JOURNAL)) == 0)) | |
352 | disks[disk.raid_disk * 2] = disk; | |
353 | else if (disk.raid_disk >= 0 && | |
354 | disk.raid_disk < array.raid_disks && | |
355 | disks[disk.raid_disk * 2 + 1].state == | |
356 | (1 << MD_DISK_REMOVED) && | |
357 | !(disk.state & (1 << MD_DISK_JOURNAL))) | |
358 | disks[disk.raid_disk * 2 + 1] = disk; | |
359 | else if (next < max_disks * 2) | |
360 | disks[next++] = disk; | |
361 | } | |
362 | ||
363 | avail = xcalloc(array.raid_disks, 1); | |
364 | ||
365 | for (d = 0; d < array.raid_disks; d++) { | |
366 | char dv[PATH_MAX], dv_rep[PATH_MAX]; | |
367 | snprintf(dv, PATH_MAX, "/sys/dev/block/%d:%d", | |
368 | disks[d*2].major, disks[d*2].minor); | |
369 | snprintf(dv_rep, PATH_MAX, "/sys/dev/block/%d:%d", | |
370 | disks[d*2+1].major, disks[d*2+1].minor); | |
371 | ||
372 | if ((is_dev_alive(dv) && (disks[d*2].state & (1<<MD_DISK_SYNC))) || | |
373 | (is_dev_alive(dv_rep) && (disks[d*2+1].state & (1<<MD_DISK_SYNC)))) { | |
374 | avail_disks ++; | |
375 | avail[d] = 1; | |
376 | } else | |
377 | rv |= !! c->test; | |
378 | } | |
379 | ||
380 | if (c->brief) { | |
381 | mdu_bitmap_file_t bmf; | |
382 | if (inactive && !is_container) | |
383 | printf("INACTIVE-ARRAY %s", dev); | |
384 | else | |
385 | printf("ARRAY %s", dev); | |
386 | if (c->verbose > 0) { | |
387 | if (array.raid_disks) | |
388 | printf(" level=%s num-devices=%d", | |
389 | str ? str : "-unknown-", | |
390 | array.raid_disks); | |
391 | else if (is_container) | |
392 | printf(" level=container num-devices=%d", | |
393 | array.nr_disks); | |
394 | else | |
395 | printf(" num-devices=%d", array.nr_disks); | |
396 | } | |
397 | if (container) { | |
398 | printf(" container=%s", container); | |
399 | printf(" member=%s", member); | |
400 | } else { | |
401 | if (sra && sra->array.major_version < 0) | |
402 | printf(" metadata=%s", sra->text_version); | |
403 | else | |
404 | printf(" metadata=%d.%d", array.major_version, | |
405 | array.minor_version); | |
406 | } | |
407 | ||
408 | /* Only try GET_BITMAP_FILE for 0.90.01 and later */ | |
409 | if (ioctl(fd, GET_BITMAP_FILE, &bmf) == 0 && bmf.pathname[0]) { | |
410 | printf(" bitmap=%s", bmf.pathname); | |
411 | } | |
412 | } else { | |
413 | mdu_bitmap_file_t bmf; | |
414 | unsigned long long larray_size; | |
415 | struct mdstat_ent *ms = mdstat_read(0, 0); | |
416 | struct mdstat_ent *e; | |
417 | char *devnm; | |
418 | ||
419 | devnm = stat2devnm(&stb); | |
420 | for (e = ms; e; e = e->next) | |
421 | if (strcmp(e->devnm, devnm) == 0) | |
422 | break; | |
423 | if (!get_dev_size(fd, NULL, &larray_size)) | |
424 | larray_size = 0; | |
425 | ||
426 | printf("%s:\n", dev); | |
427 | ||
428 | if (container) | |
429 | printf(" Container : %s, member %s\n", | |
430 | container, member); | |
431 | else { | |
432 | if (sra && sra->array.major_version < 0) | |
433 | printf(" Version : %s\n", | |
434 | sra->text_version); | |
435 | else | |
436 | printf(" Version : %d.%d\n", | |
437 | array.major_version, | |
438 | array.minor_version); | |
439 | } | |
440 | ||
441 | atime = array.ctime; | |
442 | if (atime) | |
443 | printf(" Creation Time : %.24s\n", ctime(&atime)); | |
444 | if (is_container) | |
445 | str = "container"; | |
446 | if (str) | |
447 | printf(" Raid Level : %s\n", str); | |
448 | if (larray_size) | |
449 | printf(" Array Size : %llu%s\n", | |
450 | (larray_size >> 10), | |
451 | human_size(larray_size)); | |
452 | if (array.level >= 1) { | |
453 | if (sra) | |
454 | array.major_version = sra->array.major_version; | |
455 | if (array.major_version != 0 && | |
456 | (larray_size >= 0xFFFFFFFFULL|| array.size == 0)) { | |
457 | unsigned long long dsize; | |
458 | ||
459 | dsize = get_component_size(fd); | |
460 | if (dsize > 0) | |
461 | printf(" Used Dev Size : %llu%s\n", | |
462 | dsize/2, | |
463 | human_size((long long)dsize<<9)); | |
464 | else | |
465 | printf(" Used Dev Size : unknown\n"); | |
466 | } else | |
467 | printf(" Used Dev Size : %lu%s\n", | |
468 | (unsigned long)array.size, | |
469 | human_size((unsigned long long) | |
470 | array.size << 10)); | |
471 | } | |
472 | if (array.raid_disks) | |
473 | printf(" Raid Devices : %d\n", array.raid_disks); | |
474 | printf(" Total Devices : %d\n", array.nr_disks); | |
475 | if (!container && | |
476 | ((sra == NULL && array.major_version == 0) || | |
477 | (sra && sra->array.major_version == 0))) | |
478 | printf(" Preferred Minor : %d\n", array.md_minor); | |
479 | if (sra == NULL || sra->array.major_version >= 0) | |
480 | printf(" Persistence : Superblock is %spersistent\n", | |
481 | array.not_persistent ? "not " : ""); | |
482 | printf("\n"); | |
483 | /* Only try GET_BITMAP_FILE for 0.90.01 and later */ | |
484 | if (ioctl(fd, GET_BITMAP_FILE, &bmf) == 0 && bmf.pathname[0]) { | |
485 | printf(" Intent Bitmap : %s\n", bmf.pathname); | |
486 | printf("\n"); | |
487 | } else if (array.state & (1<<MD_SB_CLUSTERED)) | |
488 | printf(" Intent Bitmap : Internal(Clustered)\n\n"); | |
489 | else if (array.state & (1<<MD_SB_BITMAP_PRESENT)) | |
490 | printf(" Intent Bitmap : Internal\n\n"); | |
491 | atime = array.utime; | |
492 | if (atime) | |
493 | printf(" Update Time : %.24s\n", ctime(&atime)); | |
494 | if (array.raid_disks) { | |
495 | static char *sync_action[] = { | |
496 | ", recovering", ", resyncing", | |
497 | ", reshaping", ", checking" }; | |
498 | char *st; | |
499 | if (avail_disks == array.raid_disks) | |
500 | st = ""; | |
501 | else if (!enough(array.level, array.raid_disks, | |
502 | array.layout, 1, avail)) | |
503 | st = ", FAILED"; | |
504 | else | |
505 | st = ", degraded"; | |
506 | ||
507 | if (array.state & (1 << MD_SB_CLEAN)) { | |
508 | if ((array.level == 0) || | |
509 | (array.level == LEVEL_LINEAR)) | |
510 | arrayst = map_num_s(sysfs_array_states, | |
511 | sra->array_state); | |
512 | else | |
513 | arrayst = "clean"; | |
514 | } else { | |
515 | arrayst = "active"; | |
516 | if (array.state & (1<<MD_SB_CLUSTERED)) { | |
517 | for (d = 0; d < max_disks * 2; d++) { | |
518 | char *dv; | |
519 | mdu_disk_info_t disk = disks[d]; | |
520 | ||
521 | /* only check first valid disk in cluster env */ | |
522 | if ((disk.state & (MD_DISK_SYNC | MD_DISK_ACTIVE)) | |
523 | && (disk.major | disk.minor)) { | |
524 | dv = map_dev_preferred(disk.major, disk.minor, 0, | |
525 | c->prefer); | |
526 | if (!dv) | |
527 | continue; | |
528 | arrayst = IsBitmapDirty(dv) ? "active" : "clean"; | |
529 | break; | |
530 | } | |
531 | } | |
532 | } | |
533 | } | |
534 | ||
535 | printf(" State : %s%s%s%s%s%s%s \n", | |
536 | arrayst, st, | |
537 | (!e || (e->percent < 0 && | |
538 | e->percent != RESYNC_PENDING && | |
539 | e->percent != RESYNC_DELAYED && | |
540 | e->percent != RESYNC_REMOTE)) ? | |
541 | "" : sync_action[e->resync], | |
542 | larray_size ? "": ", Not Started", | |
543 | (e && e->percent == RESYNC_DELAYED) ? | |
544 | " (DELAYED)": "", | |
545 | (e && e->percent == RESYNC_PENDING) ? | |
546 | " (PENDING)": "", | |
547 | (e && e->percent == RESYNC_REMOTE) ? | |
548 | " (REMOTE)": ""); | |
549 | } else if (inactive && !is_container) { | |
550 | printf(" State : inactive\n"); | |
551 | } | |
552 | if (array.raid_disks) | |
553 | printf(" Active Devices : %d\n", array.active_disks); | |
554 | if (array.working_disks > 0) | |
555 | printf(" Working Devices : %d\n", | |
556 | array.working_disks); | |
557 | if (array.raid_disks) { | |
558 | printf(" Failed Devices : %d\n", array.failed_disks); | |
559 | if (!external) | |
560 | printf(" Spare Devices : %d\n", array.spare_disks); | |
561 | } | |
562 | printf("\n"); | |
563 | if (array.level == 5) { | |
564 | str = map_num(r5layout, array.layout); | |
565 | printf(" Layout : %s\n", | |
566 | str ? str : "-unknown-"); | |
567 | } | |
568 | if (array.level == 0 && array.layout) { | |
569 | str = map_num(r0layout, array.layout); | |
570 | printf(" Layout : %s\n", | |
571 | str ? str : "-unknown-"); | |
572 | } | |
573 | if (array.level == 6) { | |
574 | str = map_num(r6layout, array.layout); | |
575 | printf(" Layout : %s\n", | |
576 | str ? str : "-unknown-"); | |
577 | } | |
578 | if (array.level == 10) { | |
579 | printf(" Layout :"); | |
580 | print_r10_layout(array.layout); | |
581 | printf("\n"); | |
582 | } | |
583 | switch (array.level) { | |
584 | case 0: | |
585 | case 4: | |
586 | case 5: | |
587 | case 10: | |
588 | case 6: | |
589 | if (array.chunk_size) | |
590 | printf(" Chunk Size : %dK\n\n", | |
591 | array.chunk_size/1024); | |
592 | break; | |
593 | case -1: | |
594 | printf(" Rounding : %dK\n\n", | |
595 | array.chunk_size/1024); | |
596 | break; | |
597 | default: | |
598 | break; | |
599 | } | |
600 | ||
601 | if (array.raid_disks) { | |
602 | struct mdinfo *mdi; | |
603 | ||
604 | mdi = sysfs_read(fd, NULL, GET_CONSISTENCY_POLICY); | |
605 | if (mdi) { | |
606 | char *policy = map_num(consistency_policies, | |
607 | mdi->consistency_policy); | |
608 | sysfs_free(mdi); | |
609 | if (policy) | |
610 | printf("Consistency Policy : %s\n\n", | |
611 | policy); | |
612 | } | |
613 | } | |
614 | ||
615 | if (e && e->percent >= 0) { | |
616 | static char *sync_action[] = { | |
617 | "Rebuild", "Resync", "Reshape", "Check"}; | |
618 | printf(" %7s Status : %d%% complete\n", | |
619 | sync_action[e->resync], e->percent); | |
620 | } | |
621 | ||
622 | if ((st && st->sb) && (info && info->reshape_active)) { | |
623 | if (info->delta_disks != 0) | |
624 | printf(" Delta Devices : %d, (%d->%d)\n", | |
625 | info->delta_disks, | |
626 | array.raid_disks - info->delta_disks, | |
627 | array.raid_disks); | |
628 | if (info->new_level != array.level) { | |
629 | str = map_num(pers, info->new_level); | |
630 | printf(" New Level : %s\n", | |
631 | str ? str : "-unknown-"); | |
632 | } | |
633 | if (info->new_level != array.level || | |
634 | info->new_layout != array.layout) { | |
635 | if (info->new_level == 5) { | |
636 | str = map_num(r5layout, | |
637 | info->new_layout); | |
638 | printf(" New Layout : %s\n", | |
639 | str ? str : "-unknown-"); | |
640 | } | |
641 | if (info->new_level == 6) { | |
642 | str = map_num(r6layout, | |
643 | info->new_layout); | |
644 | printf(" New Layout : %s\n", | |
645 | str ? str : "-unknown-"); | |
646 | } | |
647 | if (info->new_level == 10) { | |
648 | printf(" New Layout : near=%d, %s=%d\n", | |
649 | info->new_layout & 255, | |
650 | (info->new_layout & 0x10000) ? | |
651 | "offset" : "far", | |
652 | (info->new_layout >> 8) & 255); | |
653 | } | |
654 | } | |
655 | if (info->new_chunk != array.chunk_size) | |
656 | printf(" New Chunksize : %dK\n", | |
657 | info->new_chunk/1024); | |
658 | printf("\n"); | |
659 | } else if (e && e->percent >= 0) | |
660 | printf("\n"); | |
661 | free_mdstat(ms); | |
662 | ||
663 | if (st && st->sb) | |
664 | st->ss->detail_super(st, c->homehost, subarray); | |
665 | ||
666 | if (array.raid_disks == 0 && sra && | |
667 | sra->array.major_version == -1 && | |
668 | sra->array.minor_version == -2 && | |
669 | sra->text_version[0] != '/') { | |
670 | /* This looks like a container. Find any active arrays | |
671 | * That claim to be a member. | |
672 | */ | |
673 | DIR *dir = opendir("/sys/block"); | |
674 | struct dirent *de; | |
675 | ||
676 | printf(" Member Arrays :"); | |
677 | ||
678 | while (dir && (de = readdir(dir)) != NULL) { | |
679 | char path[287]; | |
680 | char vbuf[1024]; | |
681 | int nlen = strlen(sra->sys_name); | |
682 | dev_t devid; | |
683 | if (de->d_name[0] == '.') | |
684 | continue; | |
685 | sprintf(path, | |
686 | "/sys/block/%s/md/metadata_version", | |
687 | de->d_name); | |
688 | if (load_sys(path, vbuf, sizeof(vbuf)) < 0) | |
689 | continue; | |
690 | if (strncmp(vbuf, "external:", 9) || | |
691 | !is_subarray(vbuf + 9) || | |
692 | strncmp(vbuf + 10, sra->sys_name, nlen) || | |
693 | vbuf[10 + nlen] != '/') | |
694 | continue; | |
695 | devid = devnm2devid(de->d_name); | |
696 | printf(" %s", | |
697 | map_dev_preferred(major(devid), | |
698 | minor(devid), 1, | |
699 | c->prefer)); | |
700 | } | |
701 | if (dir) | |
702 | closedir(dir); | |
703 | printf("\n\n"); | |
704 | } | |
705 | ||
706 | if (!c->no_devices) { | |
707 | if (array.raid_disks) | |
708 | printf(" Number Major Minor RaidDevice State\n"); | |
709 | else | |
710 | printf(" Number Major Minor RaidDevice\n"); | |
711 | } | |
712 | } | |
713 | ||
714 | /* if --no_devices specified, not print component devices info */ | |
715 | if (c->no_devices) | |
716 | goto skip_devices_state; | |
717 | ||
718 | for (d = 0; d < max_disks * 2; d++) { | |
719 | char *dv; | |
720 | mdu_disk_info_t disk = disks[d]; | |
721 | ||
722 | if (d >= array.raid_disks * 2 && | |
723 | disk.major == 0 && disk.minor == 0) | |
724 | continue; | |
725 | if ((d & 1) && disk.major == 0 && disk.minor == 0) | |
726 | continue; | |
727 | if (!c->brief) { | |
728 | if (d == array.raid_disks*2) | |
729 | printf("\n"); | |
730 | if (disk.number < 0 && disk.raid_disk < 0) | |
731 | printf(" - %5d %5d - ", | |
732 | disk.major, disk.minor); | |
733 | else if (disk.raid_disk < 0 || | |
734 | disk.state & (1 << MD_DISK_JOURNAL)) | |
735 | printf(" %5d %5d %5d - ", | |
736 | disk.number, disk.major, disk.minor); | |
737 | else if (disk.number < 0) | |
738 | printf(" - %5d %5d %5d ", | |
739 | disk.major, disk.minor, disk.raid_disk); | |
740 | else | |
741 | printf(" %5d %5d %5d %5d ", | |
742 | disk.number, disk.major, disk.minor, | |
743 | disk.raid_disk); | |
744 | } | |
745 | if (!c->brief && array.raid_disks) { | |
746 | if (disk.state & (1 << MD_DISK_FAULTY)) { | |
747 | printf(" faulty"); | |
748 | if (disk.raid_disk < array.raid_disks && | |
749 | disk.raid_disk >= 0) | |
750 | failed++; | |
751 | } | |
752 | if (disk.state & (1 << MD_DISK_ACTIVE)) | |
753 | printf(" active"); | |
754 | if (disk.state & (1 << MD_DISK_SYNC)) { | |
755 | printf(" sync"); | |
756 | if (array.level == 10 && | |
757 | (array.layout & ~0x1FFFF) == 0) { | |
758 | int nc = array.layout & 0xff; | |
759 | int fc = (array.layout >> 8) & 0xff; | |
760 | int copies = nc*fc; | |
761 | if (fc == 1 && | |
762 | array.raid_disks % copies == 0 && | |
763 | copies <= 26) { | |
764 | /* We can divide the devices | |
765 | into 'sets' */ | |
766 | int set; | |
767 | set = disk.raid_disk % copies; | |
768 | printf(" set-%c", set + 'A'); | |
769 | } | |
770 | } | |
771 | } | |
772 | if (disk.state & (1 << MD_DISK_REMOVED)) | |
773 | printf(" removed"); | |
774 | if (disk.state & (1 << MD_DISK_WRITEMOSTLY)) | |
775 | printf(" writemostly"); | |
776 | if (disk.state & (1 << MD_DISK_FAILFAST)) | |
777 | printf(" failfast"); | |
778 | if (disk.state & (1 << MD_DISK_JOURNAL)) | |
779 | printf(" journal"); | |
780 | if ((disk.state & | |
781 | ((1 << MD_DISK_ACTIVE) | (1 << MD_DISK_SYNC) | | |
782 | (1 << MD_DISK_REMOVED) | (1 << MD_DISK_FAULTY) | | |
783 | (1 << MD_DISK_JOURNAL))) == 0) { | |
784 | printf(" spare"); | |
785 | if (disk.raid_disk < array.raid_disks && | |
786 | disk.raid_disk >= 0) | |
787 | printf(" rebuilding"); | |
788 | } | |
789 | } | |
790 | if (disk.state == 0) | |
791 | spares++; | |
792 | dv = map_dev_preferred(disk.major, disk.minor, 0, c->prefer); | |
793 | if (dv != NULL) { | |
794 | if (c->brief) | |
795 | n_devices = add_device(dv, &devices, | |
796 | &max_devices, n_devices); | |
797 | else | |
798 | printf(" %s", dv); | |
799 | } else if (disk.major | disk.minor) | |
800 | printf(" missing"); | |
801 | if (!c->brief) | |
802 | printf("\n"); | |
803 | } | |
804 | ||
805 | skip_devices_state: | |
806 | if (spares && c->brief && array.raid_disks) | |
807 | printf(" spares=%d", spares); | |
808 | if (c->brief && st && st->sb) | |
809 | st->ss->brief_detail_super(st, subarray); | |
810 | if (st) | |
811 | st->ss->free_super(st); | |
812 | ||
813 | if (c->brief && c->verbose > 0 && devices) { | |
814 | qsort(devices, n_devices, sizeof(*devices), cmpstringp); | |
815 | printf("\n devices=%s", devices[0]); | |
816 | for (d = 1; d < n_devices; d++) | |
817 | printf(",%s", devices[d]); | |
818 | } | |
819 | if (c->brief) | |
820 | printf("\n"); | |
821 | if (c->test && | |
822 | !enough(array.level, array.raid_disks, array.layout, 1, avail)) | |
823 | rv = 2; | |
824 | ||
825 | out: | |
826 | free(info); | |
827 | free(disks); | |
828 | close(fd); | |
829 | free(subarray); | |
830 | free(avail); | |
831 | if (devices) | |
832 | for (d = 0; d < n_devices; d++) | |
833 | free(devices[d]); | |
834 | free(devices); | |
835 | sysfs_free(sra); | |
836 | free(st); | |
837 | return rv; | |
838 | } | |
839 | ||
840 | int Detail_Platform(struct superswitch *ss, int scan, int verbose, int export, char *controller_path) | |
841 | { | |
842 | /* display platform capabilities for the given metadata format | |
843 | * 'scan' in this context means iterate over all metadata types | |
844 | */ | |
845 | int i; | |
846 | int err = 1; | |
847 | ||
848 | if (ss && export && ss->export_detail_platform) | |
849 | err = ss->export_detail_platform(verbose, controller_path); | |
850 | else if (ss && ss->detail_platform) | |
851 | err = ss->detail_platform(verbose, 0, controller_path); | |
852 | else if (ss) { | |
853 | if (verbose > 0) | |
854 | pr_err("%s metadata is platform independent\n", | |
855 | ss->name ? : "[no name]"); | |
856 | } else if (!scan) { | |
857 | if (verbose > 0) | |
858 | pr_err("specify a metadata type or --scan\n"); | |
859 | } | |
860 | ||
861 | if (!scan) | |
862 | return err; | |
863 | ||
864 | err = 0; | |
865 | for (i = 0; superlist[i]; i++) { | |
866 | struct superswitch *meta = superlist[i]; | |
867 | ||
868 | if (meta == ss) | |
869 | continue; | |
870 | if (verbose > 0) | |
871 | pr_err("checking metadata %s\n", | |
872 | meta->name ? : "[no name]"); | |
873 | if (!meta->detail_platform) { | |
874 | if (verbose > 0) | |
875 | pr_err("%s metadata is platform independent\n", | |
876 | meta->name ? : "[no name]"); | |
877 | } else if (export && meta->export_detail_platform) { | |
878 | err |= meta->export_detail_platform(verbose, controller_path); | |
879 | } else | |
880 | err |= meta->detail_platform(verbose, 0, controller_path); | |
881 | } | |
882 | ||
883 | return err; | |
884 | } |